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