forked from mudzereli/mudsort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SortFlag.cs
430 lines (421 loc) · 18.4 KB
/
SortFlag.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
using System;
using System.Collections;
using Decal.Adapter.Wrappers;
using System.Collections.Generic;
namespace mudsort
{
public class SortFlag
{
public static SortedList sortedFlagList = new SortedList(new AlphanumComparator());
public static SortFlag OBJECT_CLASS = new SortFlag("ObjectClass",0x29D1,"OC", "OC");
public static SortFlag CALCED_TOTAL_RATINGS = new SortFlag("CalcedTotalRatings", 0x29D1, "TR", "TR");
public static SortFlag BUFFED_WEAPON_DAMAGE = new SortFlag("BuffedWeaponDamage", 0x29D1, "BW", "BW");
public static SortFlag BUFFED_ELEMENTAL_DAMAGE = new SortFlag("BuffedElementalDamage", 0x29D1, "BE", "BE");
public static SortFlag BUFFED_MELEE_DEFENSE = new SortFlag("BuffedMeleeDefense", 0x29D1, "BD", "BD");
public static SortFlag BUFFED_ATTACK_BONUS = new SortFlag("BuffedAttackBonus", 0x29D1, "BA", "BA");
public static SortFlag BUFFED_ARMOR_LEVEL = new SortFlag("BuffedArmorLevel", 0x29D1, "BP", "BP");
public static SortFlag BUFFED_MANA_CONVERSION = new SortFlag("BuffedManaConversion", 0x29D1, "BM", "BM");
public static SortFlag TOTAL_MISSILE_DAMAGE = new SortFlag("TotalMissileDamage", 0x29D1, "TM", "TM");
public static SortFlag TOTAL_SUMMON_DAMAGE = new SortFlag("TotalSummonDamage", 0x29D1, "TS", "TS");
public String name;
public String code;
public Object key;
public bool descending = false;
public int keyIcon;
public static ArrayList CommonFlags = new ArrayList();
static SortFlag() {
try
{
CommonFlags.Add("ObjectClass");
CommonFlags.Add("EquipableSlots");
CommonFlags.Add("Coverage");
CommonFlags.Add("ArmorLevel");
CommonFlags.Add("AttackBonus");
CommonFlags.Add("DamageBonus");
CommonFlags.Add("ElementalDmgBonus");
CommonFlags.Add("MinLevelRestrict");
CommonFlags.Add("Material");
CommonFlags.Add("Name");
CommonFlags.Add("ActivationReqSkillId");
CommonFlags.Add("ArmorSet");
CommonFlags.Add("Attuned");
CommonFlags.Add("Bonded");
CommonFlags.Add("Burden");
CommonFlags.Add("CurrentMana");
CommonFlags.Add("DamageType");
CommonFlags.Add("Heritage");
CommonFlags.Add("Icon");
CommonFlags.Add("MaxDamage");
CommonFlags.Add("RareId");
CommonFlags.Add("SkilLevelReq");
CommonFlags.Add("SlayerSpecies");
CommonFlags.Add("StackCount");
CommonFlags.Add("Value");
CommonFlags.Add("WieldReqAttribute");
CommonFlags.Add("WieldReqType");
CommonFlags.Add("WieldReqValue");
CommonFlags.Add("Workmanship");
CommonFlags.Add("MeleeDefenseBonus");
CommonFlags.Add("Variance");
ArrayList codes = new ArrayList();
codes.Add(OBJECT_CLASS.code);
codes.Add(CALCED_TOTAL_RATINGS.code);
codes.Add(BUFFED_WEAPON_DAMAGE.code);
codes.Add(BUFFED_ELEMENTAL_DAMAGE.code);
codes.Add(BUFFED_MELEE_DEFENSE.code);
codes.Add(BUFFED_ATTACK_BONUS.code);
codes.Add(BUFFED_ARMOR_LEVEL.code);
codes.Add(BUFFED_MANA_CONVERSION.code);
codes.Add(TOTAL_MISSILE_DAMAGE.code);
codes.Add(TOTAL_SUMMON_DAMAGE.code);
ArrayList enums = new ArrayList();
enums.AddRange(Enum.GetValues(typeof(MSStringValueKey)));
enums.AddRange(Enum.GetValues(typeof(MSLongValueKey)));
enums.AddRange(Enum.GetValues(typeof(MSDoubleValueKey)));
enums.AddRange(Enum.GetValues(typeof(MSBoolValueKey)));
foreach (var key in enums)
{
String name = key.ToString();
// set up code
String code = "";
foreach (Char c in name)
{
if ("ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(c.ToString()))
{
code = code + c;
if (code.Length == 2)
{
if (codes.Contains(code))
{
code = code.Substring(0, 1);
}
else
{
break;
}
}
}
}
if (code.Length < 2)
{
foreach (Char c in name)
{
if ("bcdfghjklmnpqrstvwxyz".Contains(c.ToString()))
{
code = code + c;
}
if (code.Length == 2)
{
if (codes.Contains(code.ToUpper()))
{
code = code.Substring(0, 1);
}
else
{
break;
}
}
}
code = code.ToUpper();
}
if (code.Length < 2)
{
code = name.Substring(0, 2);
code = code.ToUpper();
}
int keyIcon = 0x29D1;
if (key is MSStringValueKey)
{
keyIcon = 0x29CC;
}
else if (key is MSLongValueKey)
{
keyIcon = 0x29CD;
}
else if (key is MSDoubleValueKey)
{
keyIcon = 0x29CE;
}
else if (key is MSBoolValueKey)
{
keyIcon = 0x29CF;
}
if (!codes.Contains(code) && !sortedFlagList.ContainsKey(keyIcon + name))
{
codes.Add(code);
new SortFlag(name, keyIcon, code, key);
}
else
{
Util.Log("duplicate code entry : " + code);
}
}
}
catch (Exception e) { Util.LogError(e); }
}
public SortFlag(String name, int keyIcon, String code, Object key)
{
this.name = name;
this.code = code;
this.key = key;
this.keyIcon = keyIcon;
sortedFlagList.Add(keyIcon + name, this);
}
public static SortFlag decode(String decode)
{
//Util.WriteToChat("[MudSort] decoding string: " + decode);
foreach (SortFlag flag in sortedFlagList.Values)
{
if (decode.Length >= 2 && flag.code.Equals(decode.Substring(0,2)))
{
return flag;
}
}
return null;
}
public String valueOf(WorldObject obj)
{
if (key is MSDoubleValueKey)
{
return (((int) ((Double) directValueOf(obj) * 10000)).ToString());
}
else if (this == BUFFED_ELEMENTAL_DAMAGE || this == BUFFED_ATTACK_BONUS || this == BUFFED_MANA_CONVERSION || this == BUFFED_MELEE_DEFENSE)
{
return (((int) ((Double) directValueOf(obj) * 10000)).ToString());
}
else
{
return directValueOf(obj).ToString();
}
}
public Object directValueOf(WorldObject obj)
{
if (this == OBJECT_CLASS)
{
return obj.ObjectClass;
}
else if (this == CALCED_TOTAL_RATINGS)
{
return obj.Values((LongValueKey)MSLongValueKey.DamRating)
+ obj.Values((LongValueKey)MSLongValueKey.DamResistRating)
+ obj.Values((LongValueKey)MSLongValueKey.CritRating)
+ obj.Values((LongValueKey)MSLongValueKey.CritResist)
+ obj.Values((LongValueKey)MSLongValueKey.CritDamRating)
+ obj.Values((LongValueKey)MSLongValueKey.CritDamResistRating)
+ obj.Values((LongValueKey)MSLongValueKey.HealBoostRating)
+ obj.Values((LongValueKey)MSLongValueKey.VitalityRating);
}
else if (this == BUFFED_WEAPON_DAMAGE)
{
int val = obj.Values((LongValueKey)MSLongValueKey.MaxDamage);
if (obj.SpellCount > 0)
{
for (int i = 0; i < obj.SpellCount; i++)
{
int spellID = obj.Spell(i);
switch (spellID)
{
case 2453: val = val + 2; break;
case 2486: val = val + 2; break;
case 2487: val = val + 2; break;
case 2598: val = val + 2; break;
case 3828: val = val + 3; break;
case 2454: val = val + 4; break;
case 2586: val = val + 4; break;
case 2629: val = val + 5; break;
case 2452: val = val + 6; break;
case 4661: val = val + 7; break;
case 6089: val = val + 10; break;
}
}
}
return val;
}
else if (this == BUFFED_ARMOR_LEVEL)
{
int val = obj.Values((LongValueKey)MSLongValueKey.ArmorLevel);
if (obj.SpellCount > 0)
{
for (int i = 0; i < obj.SpellCount; i++)
{
int spellID = obj.Spell(i);
switch (spellID)
{
case 2604: val = val + 20; break;
case 2592: val = val + 40; break;
case 4667: val = val + 60; break;
case 2349: val = val + 170; break;
case 2948: val = val + 220; break;
}
}
}
return val;
}
else if (this == BUFFED_ELEMENTAL_DAMAGE)
{
double val = obj.Values((DoubleValueKey)MSDoubleValueKey.ElementalDamageVersusMonsters);
if (obj.SpellCount > 0)
{
for (int i = 0;i < obj.SpellCount;i++)
{
int spellID = obj.Spell(i);
switch (spellID)
{
case 3251: val = val + 0.01; break;
case 6035: val = val + 0.01; break;
case 2352: val = val + 0.02; break;
case 3250: val = val + 0.03; break;
case 4670: val = val + 0.05; break;
case 6098: val = val + 0.07; break;
}
}
}
return val;
}
else if (this == BUFFED_MELEE_DEFENSE)
{
double val = obj.Values((DoubleValueKey)MSDoubleValueKey.MeleeDefenseBonus);
if (obj.SpellCount > 0)
{
for (int i = 0; i < obj.SpellCount; i++)
{
int spellID = obj.Spell(i);
switch (spellID)
{
case 2600: val = val + 0.03; break;
case 3985: val = val + 0.04; break;
case 2588: val = val + 0.05; break;
case 4663: val = val + 0.07; break;
case 2488: val = val + 0.08; break;
case 6091: val = val + 0.09; break;
}
}
}
return val;
}
else if (this == BUFFED_ATTACK_BONUS)
{
double val = obj.Values((DoubleValueKey)MSDoubleValueKey.AttackBonus);
if (obj.SpellCount > 0)
{
for (int i = 0; i < obj.SpellCount; i++)
{
int spellID = obj.Spell(i);
switch (spellID)
{
case 2438: val = val + 0.01; break;
case 2439: val = val + 0.03; break;
case 2603: val = val + 0.03; break;
case 3984: val = val + 0.04; break;
case 2437: val = val + 0.05; break;
case 2591: val = val + 0.05; break;
case 2630: val = val + 0.06; break;
case 4666: val = val + 0.07; break;
case 6094: val = val + 0.09; break;
}
}
}
return val;
}
else if (this == BUFFED_MANA_CONVERSION)
{
double val = obj.Values((DoubleValueKey)MSDoubleValueKey.ManaCBonus);
if (obj.SpellCount > 0)
{
for (int i = 0; i < obj.SpellCount; i++)
{
int spellID = obj.Spell(i);
switch (spellID)
{
case 3201: val = val * 1.05; break;
case 3199: val = val * 1.1; break;
case 3202: val = val * 1.15; break;
case 3200: val = val * 1.2; break;
case 6086: val = val * 1.25; break;
case 6087: val = val * 1.3; break;
}
}
}
return val;
}
else if (this == TOTAL_MISSILE_DAMAGE)
{
double baseMod = obj.Values((DoubleValueKey)MSDoubleValueKey.DamageBonus);
if (baseMod == 0)
return 0;
int elementalDMG = obj.Values((LongValueKey)MSLongValueKey.ElementalDmgBonus);
int cantripDMG = 0;
int baseDMG = (int)((baseMod - 1) * 100 / 3);
if (obj.SpellCount > 0)
{
for (int i = 0; i < obj.SpellCount; i++)
{
int spellID = obj.Spell(i);
switch (spellID)
{
case 2453: cantripDMG = cantripDMG + 2; break;
case 2486: cantripDMG = cantripDMG + 2; break;
case 2487: cantripDMG = cantripDMG + 2; break;
case 2598: cantripDMG = cantripDMG + 2; break;
case 3828: cantripDMG = cantripDMG + 3; break;
case 2454: cantripDMG = cantripDMG + 4; break;
case 2586: cantripDMG = cantripDMG + 4; break;
case 2629: cantripDMG = cantripDMG + 5; break;
case 2452: cantripDMG = cantripDMG + 6; break;
case 4661: cantripDMG = cantripDMG + 7; break;
case 6089: cantripDMG = cantripDMG + 10; break;
}
}
}
return baseDMG + elementalDMG + cantripDMG;
}
else if (this == TOTAL_SUMMON_DAMAGE)
{
//((MaxDam + MinDam)/2 * DamageRating * (1 - Crit Rate)) + (MaxDam * 2 [CritMod] * TotalCritDamageRating * CritRate)
int maxDMG = 100;
int minDMG = 25;
int ratingDMG = obj.Values((LongValueKey)MSLongValueKey.DamRating);
int ratingCRIT = obj.Values((LongValueKey)MSLongValueKey.CritRating);
int ratingCRITDAM = obj.Values((LongValueKey)MSLongValueKey.CritDamRating);
double avgDMG = (maxDMG + minDMG) / 2.0; // Fix integer division
double DamageRating = 1 + (ratingDMG / 100.0); // Fix integer division
double CritRating = (ratingCRIT + 10) / 100.0; // Fix integer division
double CritMod = (100 + ratingDMG + ratingCRITDAM) / 100.0; // Fix integer division
double formulaCalc = (avgDMG * DamageRating * (1 - CritRating)) + (maxDMG * 2 * CritMod * CritRating);
return (int)formulaCalc;
}
else if (key is MSStringValueKey)
{
return obj.Values((StringValueKey)key);
}
else if (key is MSLongValueKey)
{
return obj.Values((LongValueKey)key);
}
else if (key is MSDoubleValueKey)
{
return obj.Values((DoubleValueKey)key);
}
else if (key is MSBoolValueKey)
{
return obj.Values((BoolValueKey)key);
}
else
{
return obj;
}
}
public String propertyDumpSelection()
{
WorldObject obj = Globals.Core.WorldFilter[Globals.Core.Actions.CurrentSelection];
String props = obj.Values(StringValueKey.Name) + " : " + name.ToString() + " : " + directValueOf(obj);
Util.WriteToChat(props);
//Util.WriteToChat("============================================");
//for (int i = 0;i <= obj.SpellCount;i++)
//{
// Util.WriteToChat("Spell: "+obj.Spell(i).ToString());
//}
return props;
}
}
}