First Commit
[esp.git] / src / net / encode / wurmesp / Unit.java
1 /*
2 * Decompiled with CFR 0.151.
3 *
4 * Could not load the following classes:
5 * com.wurmonline.client.renderer.Color
6 * com.wurmonline.client.renderer.PickRenderer
7 * com.wurmonline.client.renderer.PickRenderer$CustomPickFillDepthRender
8 * com.wurmonline.client.renderer.PickRenderer$CustomPickFillRender
9 * com.wurmonline.client.renderer.PickRenderer$CustomPickOutlineRender
10 * com.wurmonline.client.renderer.PickableUnit
11 * com.wurmonline.client.renderer.backend.Primitive$BlendMode
12 * com.wurmonline.client.renderer.backend.Primitive$TestFunc
13 * com.wurmonline.client.renderer.backend.Queue
14 * com.wurmonline.client.renderer.backend.RenderState
15 */
16 package net.encode.wurmesp;
17
18 import com.wurmonline.client.game.World;
19 import com.wurmonline.client.renderer.Color;
20 import com.wurmonline.client.renderer.PickRenderer;
21 import com.wurmonline.client.renderer.PickableUnit;
22 import com.wurmonline.client.renderer.WorldRender;
23 import com.wurmonline.client.renderer.backend.Primitive;
24 import com.wurmonline.client.renderer.backend.Queue;
25 import com.wurmonline.client.renderer.backend.RenderState;
26 import net.encode.wurmesp.util.ReUtils;
27
28 public class Unit {
29 private World world;
30 private long id;
31 private String modelName;
32 private String hoverName;
33 private PickableUnit pickableUnit;
34 private float[] color = new float[]{0.0f, 0.0f, 0.0f};
35 private float[] conditionedcolor = new float[]{0.0f, 0.0f, 0.0f};
36 private String condition;
37 public static float[] colorPlayers = new float[]{0.0f, 0.0f, 0.0f};
38 public static float[] colorPlayersEnemy = new float[]{0.0f, 0.0f, 0.0f};
39 public static float[] colorMobs = new float[]{0.0f, 0.0f, 0.0f};
40 public static float[] colorMobsAggro = new float[]{0.0f, 0.0f, 0.0f};
41 public static float[] colorSpecials = new float[]{0.0f, 0.0f, 0.0f};
42 public static float[] colorSpotted = new float[]{0.0f, 0.0f, 0.0f};
43 public static float[] colorUniques = new float[]{0.0f, 0.0f, 0.0f};
44 public static float[] colorAlert = new float[]{0.0f, 0.0f, 0.0f};
45 public static float[] colorAngry = new float[]{0.0f, 0.0f, 0.0f};
46 public static float[] colorChampion = new float[]{0.0f, 0.0f, 0.0f};
47 public static float[] colorDiseased = new float[]{0.0f, 0.0f, 0.0f};
48 public static float[] colorFierce = new float[]{0.0f, 0.0f, 0.0f};
49 public static float[] colorGreenish = new float[]{0.0f, 0.0f, 0.0f};
50 public static float[] colorHardened = new float[]{0.0f, 0.0f, 0.0f};
51 public static float[] colorLurking = new float[]{0.0f, 0.0f, 0.0f};
52 public static float[] colorRaging = new float[]{0.0f, 0.0f, 0.0f};
53 public static float[] colorScared = new float[]{0.0f, 0.0f, 0.0f};
54 public static float[] colorSlow = new float[]{0.0f, 0.0f, 0.0f};
55 public static float[] colorSly = new float[]{0.0f, 0.0f, 0.0f};
56 public static String[] aggroMOBS;
57 public static String[] uniqueMOBS;
58 public static String[] specialITEMS;
59 public static String[] spottedITEMS;
60 public static String[] conditionedMOBS;
61
62 public Unit(World world, long id, PickableUnit pickableUnit, String modelName, String hoverName) {
63 this.world = world;
64 this.id = id;
65 this.pickableUnit = pickableUnit;
66 this.modelName = modelName;
67 this.hoverName = hoverName;
68 this.determineColor();
69 }
70
71 public long getId() {
72 return this.id;
73 }
74
75 public PickableUnit getPickableUnit() {
76 return this.pickableUnit;
77 }
78
79 public float[] getColor() {
80 return this.color;
81 }
82
83 public float[] getConditionedColor() {
84 return this.conditionedcolor;
85 }
86
87 public String getHoverName() {
88 return this.hoverName;
89 }
90
91 public String getModelName() {
92 return this.modelName;
93 }
94
95 public boolean isPlayer() {
96 return this.getModelName().contains("model.creature.humanoid.human.player") && !this.getModelName().contains("zombie");
97 }
98
99 public boolean isEnemyPlayer() {
100 return this.getModelName().contains("ENEMY");
101 }
102
103 public boolean isMob() {
104 return this.getModelName().contains("model.creature") && !this.getModelName().contains("humanoid.human");
105 }
106
107 public boolean isAggroMob() {
108 for (String mob : aggroMOBS) {
109 if (!this.getHoverName().contains(mob)) continue;
110 return true;
111 }
112 return false;
113 }
114
115 public boolean isChampion() {
116 return this.getHoverName().contains("champion");
117 }
118
119 public boolean isConditioned() {
120 for (String condition : conditionedMOBS) {
121 if (!this.getHoverName().contains(condition)) continue;
122 this.condition = condition;
123 return true;
124 }
125 return false;
126 }
127
128 public boolean isUnique() {
129 for (String mob : uniqueMOBS) {
130 if (!this.getHoverName().contains(mob)) continue;
131 return true;
132 }
133 return false;
134 }
135
136 public boolean isSpecial() {
137 for (String item : specialITEMS) {
138 if (this.getHoverName().contains(item)) {
139 return true;
140 }
141 if (!this.getModelName().contains(WurmEspMod.search)) continue;
142 return true;
143 }
144 return false;
145 }
146
147 public boolean isSpotted() {
148 for (String item : spottedITEMS) {
149 if (this.getHoverName().contains(item)) {
150 return true;
151 }
152 if (!this.getModelName().contains(WurmEspMod.search)) continue;
153 return true;
154 }
155 if (WurmEspMod.searchType == WurmEspMod.SEARCHTYPE.HOVER) {
156 if (this.getHoverName().contains(WurmEspMod.search)) {
157 return true;
158 }
159 } else if (WurmEspMod.searchType == WurmEspMod.SEARCHTYPE.MODEL) {
160 if (this.getModelName().contains(WurmEspMod.search)) {
161 return true;
162 }
163 } else if (WurmEspMod.searchType == WurmEspMod.SEARCHTYPE.BOTH) {
164 if (this.getHoverName().contains(WurmEspMod.search)) {
165 return true;
166 }
167 if (this.getModelName().contains(WurmEspMod.search)) {
168 return true;
169 }
170 }
171 return false;
172 }
173
174 private void determineColor() {
175 if (this.isPlayer()) {
176 this.color = !this.isEnemyPlayer() ? colorPlayers : colorPlayersEnemy;
177 } else if (this.isUnique()) {
178 this.color = colorUniques;
179 } else if (this.isAggroMob()) {
180 this.color = colorMobsAggro;
181 } else if (this.isMob()) {
182 this.color = colorMobs;
183 } else if (this.isSpecial()) {
184 this.color = colorSpecials;
185 } else if (this.isSpotted()) {
186 this.color = colorSpotted;
187 }
188 if (this.isConditioned()) {
189 float[] color = new float[]{0.0f, 0.0f, 0.0f};
190 switch (this.condition) {
191 case "alert": {
192 color = colorAlert;
193 break;
194 }
195 case "angry": {
196 color = colorAngry;
197 break;
198 }
199 case "champion": {
200 color = colorChampion;
201 break;
202 }
203 case "diseased": {
204 color = colorDiseased;
205 break;
206 }
207 case "fierce": {
208 color = colorFierce;
209 break;
210 }
211 case "greenish": {
212 color = colorGreenish;
213 break;
214 }
215 case "hardened": {
216 color = colorHardened;
217 break;
218 }
219 case "lurking": {
220 color = colorLurking;
221 break;
222 }
223 case "raging": {
224 color = colorRaging;
225 break;
226 }
227 case "scared": {
228 color = colorScared;
229 break;
230 }
231 case "slow": {
232 color = colorSlow;
233 break;
234 }
235 case "sly": {
236 color = colorSly;
237 }
238 }
239 this.conditionedcolor = color;
240 }
241 }
242
243 public void renderUnit(Queue queue, boolean showconditioned) {
244 if (this.pickableUnit == null) {
245 return;
246 }
247 float br = 3.5f;
248 RenderState renderStateFill = new RenderState();
249 RenderState renderStateFillDepth = new RenderState();
250 RenderState renderStateOutline = new RenderState();
251 Color color = new Color();
252 if (this.isConditioned() && showconditioned) {
253 color.set(this.conditionedcolor[0], this.conditionedcolor[1], this.conditionedcolor[2]);
254 } else {
255 color.set(this.color[0], this.color[1], this.color[2]);
256 }
257 renderStateFill.alphaval = color.a = br;
258 color.a *= this.pickableUnit.getOutlineColor().a;
259
260 WorldRender worldRenderer = (WorldRender)ReUtils.getField(this.world, "worldRenderer");
261 PickRenderer.CustomPickFillRender customPickFill = (PickRenderer.CustomPickFillRender)ReUtils.getField(worldRenderer, "customPickFill");
262 PickRenderer.CustomPickFillDepthRender customPickFillDepth = (PickRenderer.CustomPickFillDepthRender)ReUtils.getField(worldRenderer, "customPickFillDepth");
263 PickRenderer.CustomPickOutlineRender customPickOutline = (PickRenderer.CustomPickOutlineRender)ReUtils.getField(worldRenderer, "customPickOutline");
264 renderStateFill.twosided = false;
265 renderStateFill.depthtest = Primitive.TestFunc.ALWAYS;
266 renderStateFill.depthwrite = true;
267 renderStateFill.customstate = customPickFill;
268 this.pickableUnit.renderPicked(queue, renderStateFill, color);
269 renderStateOutline.alphaval = color.a = br * 0.25f;
270 color.a *= this.pickableUnit.getOutlineColor().a;
271 renderStateOutline.twosided = false;
272 renderStateOutline.depthtest = Primitive.TestFunc.LESS;
273 renderStateOutline.depthwrite = false;
274 renderStateOutline.blendmode = Primitive.BlendMode.ALPHABLEND;
275 renderStateOutline.customstate = customPickOutline;
276 this.pickableUnit.renderPicked(queue, renderStateOutline, color);
277 renderStateFillDepth.customstate = customPickFillDepth;
278 renderStateFillDepth.depthtest = Primitive.TestFunc.ALWAYS;
279 this.pickableUnit.renderPicked(queue, renderStateFillDepth, color);
280 }
281 }
282