-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathloot.java
More file actions
executable file
·2640 lines (2605 loc) · 115 KB
/
Copy pathloot.java
File metadata and controls
executable file
·2640 lines (2605 loc) · 115 KB
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package script.library;
import script.*;
import java.util.Enumeration;
import java.util.Vector;
public class loot extends script.base_script
{
public loot()
{
}
public static final int COL_LOOT_MULTIPLIER_ON = 1;
public static final String TBL_CREATURES = "datatables/mob/creatures.iff";
public static final String TBL_COMPONENT_DATA = "datatables/loot/component_data.iff";
public static final String VAR_DENY_LOOT = "denyLoot";
public static final String VAR_LOOT_QUALITY = "loot.loot_quality";
public static final String CHRONICLES_LOOT_TOGGLE_OBJVAR = "chroniclesLoot_toggledOff";
public static final String TBL_EXCLUSION = "datatables/loot/exclusion.iff";
public static final String COL_TEMPLATE = "TEMPLATE";
public static final String COL_EXCLUDE = "EXCLUDE";
public static final String DATA_ITEM = "dataItem";
public static final String DATA_ITEM_FACTION = DATA_ITEM + ".faction";
public static final String DATA_ITEM_VALUE = DATA_ITEM + ".value";
public static final String TBL_DATA_ITEM_VALUE = "datatables/data_item/redeem_value.iff";
public static final String ENCODED_DISK = "object/tangible/encoded_disk/encoded_disk_base.iff";
public static final String SPECIAL_LOOT = "datatables/loot/npc_special_loot.iff";
public static final String COLLECTIBLE_LOOT = "datatables/loot/npc_collectible_loot.iff";
public static final String CASH_ITEM_TEMPLATE = "object/tangible/item/loot_cash.iff";
public static final String MEATLUMP_LUMP = "item_meatlump_lump_01_01";
public static final String MEATLUMP_LOOT_TABLE = "datatables/loot/dungeon/meatlump_dungeon_container_loot.iff";
public static final String CREATURES_TABLE = "datatables/mob/creatures.iff";
public static final String COLLECTIONS_LOOT_TABLE = "datatables/loot/loot_items/collectible/collection_loot.iff";
public static final String COLLECTIONS_PVP_RANK_TABLE = "datatables/loot/loot_items/collectible/collection_pvp_rank.iff";
public static final String COLLECTIONS_PVP_LOOT_TABLE = "datatables/loot/loot_items/collectible/collection_pvp_loot.iff";
public static final int MIN_CREATURE_LEVEL = 1;
public static final int MAX_CREATURE_LEVEL = 85;
public static final float MAX_ALLOWED_WEAPON_INTENSITY = 0.90f;
public static final float MIN_ALLOWED_WEAPON_INTENSITY = 0.35f;
public static final int BASE_CHANCE_FOR_CASH = 40;
public static final int BASE_CHANCE_FOR_RESOURCES = 40;
public static final int BASE_CHANCE_FOR_ENZYME = 25;
public static final string_id SID_REWARD_ITEM = new string_id("collection", "reward_item");
public static final int COLLECTION_PVP_ROLL = 80;
public static final String FORAGE_LOGGING_CATEGORY = "foraging";
public static final boolean FORAGE_LOGGING_ON = false;
public static final int RARE_COMPONENT_DIVISOR = 10;
public static final int SUPER_RARE_COMPONENT_DIVISOR = 5;
public static final int WORM_ROLL_INT = 80;
public static final int ENZYME = 0;
public static final int WORM = 1;
public static final int COMPONENT = 2;
public static final int TREASURE = 3;
public static final int BAIT = 99;
public static final int NOTHING = 98;
public static final int FORAGE_BASE_ONE = 14;
public static final int FORAGE_BASE_TWO = 28;
public static final int PLAYER_DEFAULT_FORAGE_CHANCE = 0;
public static final int DEFAULT_ENZYME_CHANCE = 40;
public static final int DEFAULT_WORM_CHANCE = 40;
public static final int DEFAULT_TREASURE_CHANCE = 0;
public static final int DEFAULT_COMPONENT_CHANCE = 40;
public static final float ENZYME_MODIFIER = 0.0f;
public static final float TREASURE_MODIFIER = 0.0f;
public static final float PLAYER_DEFAULT_FIND_MODIFIER = 0.0f;
public static final float LUCKY_FIND_MODIFIER = 6.0f;
public static final String FORAGING_RARE_TABLE = "datatables/foraging/forage_global_rare.iff";
public static final String FORAGING_ENEMY_TABLE = "datatables/foraging/forage_enemy.iff";
public static final String FORAGING_LOOT_ROLL_TABLE = "datatables/foraging/foraging_loot_roll.iff";
public static final String LOOT_LOW_COL = "low";
public static final String LOOT_HIGH_COL = "high";
public static final String LOOT_ENZYME = "enzyme";
public static final String LOOT_COMPONENT = "component";
public static final String LOOT_WORM = "worm";
public static final String LOOT_BAIT = "bait";
public static final String LOOT_TREASURE = "treasure";
public static final String FORAGE_ENEMY_SCRIPT = "creature.foraging_enemy";
public static final String FORAGING_STF = "player/player_utility";
public static final string_id FOUND_TREASURE = new string_id("player/player_utility", "forage_found_treasure");
public static final string_id TREASURE_BONUS_ROLL = new string_id("player/player_utility", "treasure_buff_extra_roll");
public static final string_id TREASURE_BONUS = new string_id("player/player_utility", "treasure_map_buff_bonus");
public static final string_id SID_FULL_INVENTORY = new string_id("player/player_utility", "forage_full_inventory");
public static final string_id FOUND_NOTHING = new string_id("player/player_utility", "forage_found_nothing");
public static final string_id FOUND_SOMETHING = new string_id("player/player_utility", "forage_found_something");
public static final string_id FOUND_WORM = new string_id("player/player_utility", "forage_found_worm");
public static final string_id FOUND_COMPONENT = new string_id("player/player_utility", "forage_found_component");
public static final string_id FOUND_ENZYME = new string_id("player/player_utility", "forage_found_enzyme");
public static final string_id ENZYME_BONUS_ROLL = new string_id("player/player_utility", "enzyme_buff_extra_roll");
public static final string_id ENZYME_BONUS = new string_id("player/player_utility", "truffle_pig_buff_bonus");
public static final string_id FORAGE_BONUS = new string_id("player/player_utility", "ice_cream_buff_bonus");
public static final string_id LUCK_BONUS = new string_id("player/player_utility", "luck_buff_bonus");
public static final String[] COMPONENT_PLANETS =
{
"corellia",
"dantooine",
"dathomir",
"endor",
"naboo",
"tatooine",
"yavin4"
};
public static final String[] CHEST_TYPES = {
"rare",
"exceptional",
"legendary"
};
private static final String CHEST_BASE = "rare_loot_chest_quality_";
private static final String RLS_EFFECT = "appearance/pt_rare_chest.prt";
private static final String RLS_SOUND = "sound/rare_loot_chest.snd";
public static boolean addLoot(obj_id target) throws InterruptedException
{
if (!isIdValid(target))
{
return false;
}
if (hasObjVar(target, VAR_DENY_LOOT))
{
return false;
}
boolean hasLoot = false;
obj_id inv = utils.getInventoryContainer(target);
if (inv == null)
{
return false;
}
String mobType = ai_lib.getCreatureName(target);
if (mobType == null || mobType.length() < 1)
{
String err = "WARNING: loot::addLoot(" + target + ") returning false because getCreatureName failed. Template=" + getTemplateName(target) + ", IsAuthoritative=" + target.isAuthoritative() + ". Stack Trace as follows:";
CustomerServiceLog("creatureNameErrors", err);
debugServerConsoleMsg(target, err);
Thread.dumpStack();
return false;
}
if (!hasObjVar(target, "storytellerid"))
{
int cash = getNpcMoney(target);
if (addCashAsLoot(target, cash))
{
hasLoot = true;
}
}
hasLoot |= setupLootItems(target);
hasLoot |= addCollectionLoot(target);
hasLoot |= addRareLoot(target);
int niche = ai_lib.aiGetNiche(mobType);
if (niche == NICHE_MONSTER || niche == NICHE_HERBIVORE || niche == NICHE_CARNIVORE || niche == NICHE_PREDATOR)
{
int[] hasResource = corpse.hasResource(mobType);
if (hasResource != null && hasResource.length > 0)
{
setObjVar(target, corpse.VAR_HAS_RESOURCE, hasResource);
}
if (isInTutorialArea(target))
{
return false;
}
hasLoot |= addBeastEnzymes(target);
}
return hasLoot;
}
public static int getCashForLevel(String mobType, int level) throws InterruptedException
{
if (mobType == null || mobType.equals("") || level < 1)
{
return 0;
}
int lbound = dataTableGetInt(TBL_CREATURES, mobType, "minCash");
int ubound = dataTableGetInt(TBL_CREATURES, mobType, "maxCash");
if (ubound == 0)
{
return 0;
}
if (lbound > 0 && ubound > 0)
{
return rand(lbound, ubound);
}
int minCash = level;
if (lbound > 0 && minCash < lbound)
{
minCash = lbound;
}
int maxCash = level * 17;
if (ubound > 0 && maxCash > ubound)
{
maxCash = ubound;
}
return rand(minCash, maxCash);
}
public static boolean addResourceLoot(obj_id target) throws InterruptedException
{
if (rand(1, 100) > BASE_CHANCE_FOR_RESOURCES)
{
return false;
}
String mobType = ai_lib.getCreatureName(target);
int niche = ai_lib.aiGetNiche(mobType);
if (niche != NICHE_MONSTER && niche != NICHE_HERBIVORE && niche != NICHE_CARNIVORE && niche != NICHE_PREDATOR)
{
return false;
}
int[] hasResource = corpse.hasResource(mobType);
if (hasResource == null || hasResource.length == 0)
{
return false;
}
obj_id inv = utils.getInventoryContainer(target);
dictionary resourceData = corpse.getRandomHarvestCorpseResources(obj_id.NULL_ID, target);
java.util.Enumeration keys = resourceData.keys();
int finalAmount = 0;
while (keys.hasMoreElements())
{
String resourceType = (String)(keys.nextElement());
int amt = resourceData.getInt(resourceType);
if (amt <= 0)
{
continue;
}
String sceneName = getCurrentSceneName();
String rsrcMapTable = "datatables/creature_resource/resource_scene_map.iff";
String correctedPlanetName = dataTableGetString(rsrcMapTable, sceneName, 1);
if (correctedPlanetName == null || correctedPlanetName.equals(""))
{
correctedPlanetName = "tatooine";
}
resourceType = resourceType + "_" + correctedPlanetName;
int useDistMap = dataTableGetInt(rsrcMapTable, sceneName, "useDistributionMap");
location worldLoc = getWorldLocation(target);
if (useDistMap == 0)
{
worldLoc.area = correctedPlanetName;
}
finalAmount += corpse.extractCorpseResource(resourceType, amt, worldLoc, obj_id.NULL_ID, inv, 1);
}
return (finalAmount > 0);
}
public static int getCalculatedAttribute(int minVal, int maxVal, int creatureLevel, int minDropLevel, int maxDropLevel) throws InterruptedException
{
return Math.round(getCalculatedAttribute((float)minVal, maxVal, creatureLevel, minDropLevel, maxDropLevel));
}
public static float getCalculatedAttribute(float minVal, float maxVal, int creatureLevel, int minDropLevel, int maxDropLevel) throws InterruptedException
{
float rank = (float)(creatureLevel - minDropLevel) / (maxDropLevel - minDropLevel);
if (rank < -1.0f)
{
rank = -1.0f;
}
else if (rank > 2.0f)
{
rank = 2.0f;
}
float rslt = random.distributedRand(minVal, maxVal, rank);
LOG("loot", "getCalculatedAttribute: -> returning " + rslt);
return rslt;
}
public static int getCalculatedAttribute(int minVal, int maxVal, int creatureLevel) throws InterruptedException
{
return getCalculatedAttribute(minVal, maxVal, creatureLevel, MIN_CREATURE_LEVEL, MAX_CREATURE_LEVEL);
}
public static float getCalculatedAttribute(float minVal, float maxVal, int creatureLevel) throws InterruptedException
{
return getCalculatedAttribute(minVal, maxVal, creatureLevel, MIN_CREATURE_LEVEL, MAX_CREATURE_LEVEL);
}
public static int getRowIndexForComponent(String componentTemplate) throws InterruptedException
{
if (componentTemplate == null || componentTemplate.equals(""))
{
return -1;
}
return dataTableSearchColumnForString(componentTemplate, "template", TBL_COMPONENT_DATA);
}
public static dictionary getComponentData(obj_id component) throws InterruptedException
{
return getComponentData(getTemplateName(component));
}
public static dictionary getComponentData(String componentTemplate) throws InterruptedException
{
int startRow = getRowIndexForComponent(componentTemplate);
if (startRow < 0)
{
return null;
}
dictionary dat = new dictionary();
int totalRows = dataTableGetNumRows(TBL_COMPONENT_DATA);
if (totalRows < startRow + 1)
{
trace.log("loot", "loot::getComponentData: -> Gave starting row of " + startRow + ", but " + TBL_COMPONENT_DATA + " only has " + totalRows + " rows.", null, trace.TL_ERROR_LOG);
return null;
}
String templateString = "";
for (int i = startRow; i < totalRows; i++)
{
templateString = dataTableGetString(TBL_COMPONENT_DATA, i, "template");
if (!templateString.equals(componentTemplate) && !templateString.equals(""))
{
trace.log("loot", "loot::getComponentData: -> Done fetching data for this object. Stopped at data table row " + i);
break;
}
dat.put(dataTableGetString(TBL_COMPONENT_DATA, i, "stringArg"), new float[]
{
dataTableGetFloat(TBL_COMPONENT_DATA, i, "min"),
dataTableGetFloat(TBL_COMPONENT_DATA, i, "max")
});
}
trace.log("loot", "loot:getComponentData: -> Component data has " + dat.size() + " elements.");
return dat;
}
public static boolean redeemFactionCoupon(obj_id redeemer, obj_id player, obj_id coupon) throws InterruptedException
{
if ((redeemer == null) || (player == null) || (coupon == null))
{
return false;
}
if (!isFactionalDataItem(coupon))
{
return false;
}
String rFaction = getStringObjVar(redeemer, "faction");
if ((rFaction == null) || (rFaction.equals("")))
{
return false;
}
int val = getFactionCouponValue(redeemer, coupon);
if (val < 0)
{
return false;
}
factions.awardFactionStanding(player, rFaction, val);
return destroyObject(coupon);
}
public static int getFactionCouponValue(obj_id redeemer, obj_id coupon) throws InterruptedException
{
if ((redeemer == null) || (coupon == null))
{
return -1;
}
if (!isFactionalDataItem(coupon))
{
return -1;
}
if (!hasObjVar(redeemer, factions.FACTION))
{
return -1;
}
String rFaction = getStringObjVar(redeemer, factions.FACTION);
String cFaction = getStringObjVar(coupon, DATA_ITEM_FACTION);
int base_value = getIntObjVar(coupon, DATA_ITEM_VALUE);
if (!dataTableOpen(TBL_DATA_ITEM_VALUE))
{
return -1;
}
float multiplier = utils.dataTableGetFloat(TBL_DATA_ITEM_VALUE, rFaction, cFaction);
if (multiplier < 0)
{
return -1;
}
int point_value = (int)(base_value * multiplier);
return point_value;
}
public static boolean isFactionalDataItem(obj_id item) throws InterruptedException
{
if ((item == null) || (item == obj_id.NULL_ID))
{
return false;
}
return getGameObjectType(item) == GOT_data_fictional;
}
public static obj_id[] getFactionalDataItems(obj_id target, String faction) throws InterruptedException
{
if ((target == null) || (target == obj_id.NULL_ID))
{
return null;
}
Vector ret = new Vector();
ret.setSize(0);
obj_id dp = utils.getDatapad(target);
if ((dp == null) || (dp == obj_id.NULL_ID))
{
return null;
}
else
{
obj_id[] contents = getContents(dp);
if ((contents == null) || (contents.length == 0))
{
return null;
}
else
{
for (obj_id item : contents) {
if (isFactionalDataItem(item)) {
if (faction.equals("")) {
ret = utils.addElement(ret, item);
} else {
String ifac = getStringObjVar(item, DATA_ITEM_FACTION);
if (ifac != null) {
if (ifac.equals(faction)) {
ret = utils.addElement(ret, item);
}
}
}
}
}
}
}
if ((ret == null) || (ret.size() == 0))
{
return null;
}
else
{
obj_id[] _ret = new obj_id[0];
if (ret != null)
{
_ret = new obj_id[ret.size()];
ret.toArray(_ret);
}
return _ret;
}
}
public static obj_id[] getFactionalDataItems(obj_id target) throws InterruptedException
{
return getFactionalDataItems(target, "");
}
public static boolean randomizeWeapon(obj_id weapon, int creatureLevel) throws InterruptedException
{
if (!isIdValid(weapon))
{
return false;
}
float percentOfMax = getCalculatedAttribute(MIN_ALLOWED_WEAPON_INTENSITY, MAX_ALLOWED_WEAPON_INTENSITY, creatureLevel);
dictionary weaponCraftingData = weapons.getWeaponDat(weapon);
if (weaponCraftingData == null)
{
return false;
}
weapons.setWeaponAttributes(weapon, weaponCraftingData, percentOfMax);
return true;
}
public static boolean randomizeArmor(obj_id item, int level) throws InterruptedException
{
LOG("loot", "loot:randomizeArmor: -> Randomizing " + item);
if (!isIdValid(item))
{
return false;
}
String template = getTemplateName(item);
int armorCat = armor.getArmorCategoryByTemplate(template);
if (armorCat < 0 || armorCat > AC_max)
{
return false;
}
if (!armor.setArmorDataPercent(item, getCalculatedAttribute(0, AL_max - 1, level), armorCat, getCalculatedAttribute(0.4f, 0.9f, level), getCalculatedAttribute(0.4f, 1.0f, level)))
{
return false;
}
if (armorCat == 0)
{
armor.setArmorSpecialProtectionPercent(item, armor.DATATABLE_RECON_LAYER, 1.0f);
}
if (armorCat == 2)
{
armor.setArmorSpecialProtectionPercent(item, armor.DATATABLE_ASSAULT_LAYER, 1.0f);
}
if (!armor.isValidArmor(item))
{
LOG("loot", "loot:randomizeArmor: -> Not valid armor.");
return false;
}
return true;
}
public static boolean randomizeMedicine(obj_id item, int level) throws InterruptedException
{
if (!isIdValid(item))
{
return false;
}
if (hasObjVar(item, consumable.VAR_CONSUMABLE_MODS))
{
attrib_mod[] am = getAttribModArrayObjVar(item, consumable.VAR_CONSUMABLE_MODS);
attrib_mod[] am_new = new attrib_mod[am.length];
for (int i = 0; i < am.length; i++)
{
int attrib = am[i].getAttribute();
int val = am[i].getValue();
float duration = am[i].getDuration();
float atk = am[i].getAttack();
float decay = am[i].getDecay();
attrib_mod tmp;
if (healing.isBuffMedicine(item))
{
tmp = new attrib_mod(attrib, getCalculatedAttribute(600, 900, level), getCalculatedAttribute(9000, 12000, level), atk, decay);
}
else
{
tmp = new attrib_mod(attrib, getCalculatedAttribute(150, 400, level), duration, atk, decay);
}
am_new[i] = tmp;
}
if (am_new.length == 0)
{
return false;
}
setObjVar(item, consumable.VAR_CONSUMABLE_MODS, am_new);
}
if (healing.isCureDotMedicine(item) || healing.isApplyDotMedicine(item))
{
setObjVar(item, healing.VAR_HEALING_DOT_POWER, getCalculatedAttribute(40, 100, level));
if (healing.isApplyDotMedicine(item))
{
int potency = healing.getDotPotency(item);
setObjVar(item, healing.VAR_HEALING_DOT_POTENCY, getCalculatedAttribute(70, 150, level));
int duration = healing.getDotDuration(item);
setObjVar(item, healing.VAR_HEALING_DOT_DURATION, getCalculatedAttribute(400, 800, level));
}
}
setCount(item, getCalculatedAttribute(5, 25, level));
return true;
}
public static float[] validateComponentVals(float[] dat) throws InterruptedException
{
float[] defaultVal = new float[]
{
0.0f,
0.0f
};
if (dat == null)
{
return defaultVal;
}
switch (dat.length)
{
case 1:
return new float[]
{
dat[0],
dat[0]
};
case 2:
return dat;
}
return defaultVal;
}
public static boolean randomizeComponent(obj_id item, int level, obj_id container) throws InterruptedException
{
if (!isIdValid(item))
{
return false;
}
if (!isIdValid(container))
{
return false;
}
String template = getTemplateName(item);
dictionary componentData = getComponentData(template);
if (componentData == null)
{
return false;
}
int minToDrop = 1;
int maxToDrop = 1;
float[] fVals = null;
int minCreatureLevelDrop = MIN_CREATURE_LEVEL;
int maxCreatureLevelDrop = MAX_CREATURE_LEVEL;
if (componentData.containsKey("level"))
{
fVals = validateComponentVals(componentData.getFloatArray("level"));
minCreatureLevelDrop = (int)fVals[0];
maxCreatureLevelDrop = (int)fVals[1];
componentData.remove("level");
}
Enumeration keys = componentData.keys();
boolean hasAttribBonus = false;
int[] attribBonus = null;
while (keys.hasMoreElements())
{
String key = (String)keys.nextElement();
fVals = validateComponentVals(componentData.getFloatArray(key));
key = key.trim();
LOG("loot", "loot::randomizeComponent: -> processing key '" + key + "' where data[0]=" + fVals[0] + ", data[1]=" + fVals[1]);
if (key.equals("amount"))
{
LOG("loot", "loot::randomizeComponent: -> Grabbing amount from dataset");
minToDrop = (int)fVals[0];
maxToDrop = (int)fVals[1];
}
else if (key.startsWith("attribute.bonus."))
{
String strAttrib = key.substring(key.length() - 1);
int intAttrib = utils.stringToInt(strAttrib);
LOG("loot", "loot:randomizeComponent: -> Processing Attributes : " + intAttrib);
if (intAttrib < 0 || intAttrib >= NUM_ATTRIBUTES)
{
LOG("loot", "loot:randomizeComponent: -> IntAttrib Out of Range : " + intAttrib);
continue;
}
if (attribBonus == null)
{
attribBonus = new int[NUM_ATTRIBUTES];
}
attribBonus[intAttrib] = getCalculatedAttribute((int)fVals[0], (int)fVals[1], level, minCreatureLevelDrop, maxCreatureLevelDrop);
hasAttribBonus = true;
}
else if (key.startsWith("combat_critical"))
{
int val = rand((int)fVals[0], (int)fVals[1]);
LOG("loot", "loot:randomizeComponent: -> Not an attribute modifier or armor modifier : " + key);
setObjVar(item, craftinglib.COMPONENT_ATTRIBUTE_OBJVAR_NAME + "." + key, val);
LOG("loot", "loot:randomizeComponent: -> setting objvar : " + craftinglib.COMPONENT_ATTRIBUTE_OBJVAR_NAME + "." + key);
}
else
{
float val = getCalculatedAttribute(fVals[0], fVals[1], level, minCreatureLevelDrop, maxCreatureLevelDrop);
if (key.equals("armorCategory") || key.equals("armorLevel"))
{
setObjVar(item, craftinglib.COMPONENT_ATTRIBUTE_OBJVAR_NAME + "." + key, (int)val);
int armorCat = armor.getArmorCategory(item);
if (armorCat == 0)
{
armor.setArmorSpecialProtectionPercent(item, armor.DATATABLE_RECON_LAYER, 1.0f);
}
if (armorCat == 2)
{
armor.setArmorSpecialProtectionPercent(item, armor.DATATABLE_ASSAULT_LAYER, 1.0f);
}
}
else
{
setObjVar(item, craftinglib.COMPONENT_ATTRIBUTE_OBJVAR_NAME + "." + key, key.equals("attackSpeed") || key.equals("attackCost") ? val * -1 : val);
}
}
}
if (hasAttribBonus && attribBonus != null && attribBonus.length == NUM_ATTRIBUTES)
{
LOG("loot", "loot:randomizeComponent: -> Calling Set Attributes : " + attribBonus.toString());
for (int i = 0; i < attribBonus.length; i++)
{
LOG("loot", "loot:randomizeComponent: -> Attribute " + i + " = " + attribBonus[i]);
}
setAttributeBonuses(item, attribBonus);
}
LOG("loot", "loot:randomizeComponent: -> Amount to drop : " + minToDrop + "/" + maxToDrop);
setCraftedId(item, container);
setCrafter(item, container);
int numDropped = 1;
if (minToDrop <= maxToDrop)
{
numDropped = rand(minToDrop, maxToDrop);
}
LOG("loot", "loot:randomizeComponent: -> Dropping " + numDropped + " " + template);
if (numDropped > 1)
{
setObjVar(item, "unstack.serialNumber", container);
setCount(item, numDropped);
attachScript(item, "object.onewayunstack");
}
return true;
}
public static String getCreatureType(String name) throws InterruptedException
{
return dataTableGetString("datatables/mob/creatures.iff", name, "lootList");
}
public static int getAdjustedCreatureLevel(obj_id target, String name) throws InterruptedException
{
int level = getLevel(target);
int difficultyClass = dataTableGetInt("datatables/mob/creatures.iff", name, "difficultyClass");
if (difficultyClass > 0)
{
float levelMod = 0.4f * difficultyClass;
level += (int)(level * levelMod);
}
return level;
}
public static boolean generateTheftLootRare(obj_id container, obj_id mark, int maxItems, obj_id thief) throws InterruptedException
{
String name = getCreatureName(mark);
String type = getCreatureType(name);
if (type == null || type.equals("none"))
{
return false;
}
String strTreasureTable = "treasure/treasure_";
String treasureLevel = "1_10";
int intLevel = getIntObjVar(mark, "intCombatDifficulty");
if (intLevel <= 10)
{
treasureLevel = "1_10";
}
else if (intLevel <= 20)
{
treasureLevel = "11_20";
}
else if (intLevel <= 30)
{
treasureLevel = "21_30";
}
else if (intLevel <= 40)
{
treasureLevel = "31_40";
}
else if (intLevel <= 50)
{
treasureLevel = "41_50";
}
else if (intLevel <= 60)
{
treasureLevel = "51_60";
}
else if (intLevel <= 70)
{
treasureLevel = "61_70";
}
else if (intLevel <= 80)
{
treasureLevel = "71_80";
}
else if (intLevel <= 90)
{
treasureLevel = "81_90";
}
else
{
return false;
}
String strTable = strTreasureTable + treasureLevel;
utils.setScriptVar(container, "theft_in_progress", 1);
return makeLootInContainer(container, strTable, 1, intLevel);
}
public static boolean generateTheftLoot(obj_id container, obj_id mark, float chanceMod, int maxItems) throws InterruptedException
{
String name = getCreatureName(mark);
String type = getCreatureType(name);
if (type == null || type.equals("none"))
{
return false;
}
int level = getAdjustedCreatureLevel(mark, name);
String strTable = getStringObjVar(mark, "loot.lootTable");
int intLevel = getIntObjVar(mark, "intCombatDifficulty");
utils.setScriptVar(container, "theft_in_progress", 1);
return makeLootInContainer(container, strTable, 1, intLevel);
}
public static int getNpcMoney(obj_id target) throws InterruptedException
{
String mobType = ai_lib.getCreatureName(target);
if (mobType == null)
{
return -1;
}
int niche = ai_lib.aiGetNiche(target);
if (niche != NICHE_NPC)
{
return -1;
}
int level = ai_lib.getLevel(target);
int cash = getCashForLevel(mobType, level);
if (cash < 1)
{
cash = rand(1, 10);
cash = cash * level;
}
return cash;
}
public static boolean addCashAsLoot(obj_id target, int cash) throws InterruptedException
{
if (cash < 1)
{
return false;
}
obj_id inv = utils.getInventoryContainer(target);
if (inv == null)
{
return false;
}
obj_id cashItem = createObject(CASH_ITEM_TEMPLATE, inv, "");
if (!isIdValid(cashItem))
{
return false;
}
setObjVar(cashItem, "loot.cashAmount", cash);
setName(cashItem, formatCashAmount(cash));
return true;
}
public static String formatCashAmount(int cash) throws InterruptedException
{
final java.text.DecimalFormat CASH_NAME_FORMAT = new java.text.DecimalFormat("#,### cr");
return CASH_NAME_FORMAT.format(cash);
}
public static boolean isCashLootItem(obj_id item) throws InterruptedException
{
String template = getTemplateName(item);
if (template.equals(CASH_ITEM_TEMPLATE))
{
return hasObjVar(item, "loot.cashAmount");
}
return false;
}
public static boolean doGroupLooting(obj_id corpseId, obj_id transferer, obj_id item) throws InterruptedException
{
obj_id leader = group.getLeader(transferer);
obj_id team = getGroupObject(transferer);
int groupLootType = getGroupLootRule(team);
obj_id[] objMembersWhoExist = utils.getLocalGroupMemberIds(team);
obj_id corpseInv = utils.getInventoryContainer(corpseId);
obj_id[] contents = getContents(corpseInv);
int numContents = contents.length;
if (objMembersWhoExist == null)
{
return false;
}
if (groupLootType == 0)
{
setGroupLootRule(team, group.FREE_FOR_ALL);
return true;
}
if (groupLootType == 1)
{
obj_id master = getGroupMasterLooterId(team);
String masterName = getEncodedName(master);
if (transferer != master)
{
prose_package pp = new prose_package();
string_id masterMsg = new string_id(group.GROUP_STF, "master_only");
pp = prose.setStringId(pp, masterMsg);
pp = prose.setTO(pp, masterName);
sendSystemMessageProse(transferer, pp);
return false;
}
}
if (groupLootType == 2)
{
if (hasObjVar(corpseId, "autoLootComplete"))
{
return true;
}
int numWindows = 0;
if (hasObjVar(corpseId, "numWindowsOpen"))
{
numWindows = getIntObjVar(corpseId, "numWindowsOpen");
}
else
{
for (obj_id objMemberWhoExists : objMembersWhoExist) {
if (numContents > 0 && !(numContents == 1 && isCashLootItem(contents[0]))) {
openLotteryWindow(objMemberWhoExists, corpseInv);
} else if (numContents == 1 && isCashLootItem(contents[0])) {
return true;
} else {
string_id emptyCorpse = new string_id(group.GROUP_STF, "corpse_empty");
sendSystemMessage(objMemberWhoExists, emptyCorpse);
lootAiCorpse(transferer, corpseId);
return false;
}
}
numWindows = objMembersWhoExist.length;
setObjVar(corpseId, "numWindowsOpen", numWindows);
}
if (numWindows > 0)
{
dictionary lotto = new dictionary();
lotto.put("player", transferer);
lotto.put("corpseInv", corpseInv);
messageTo(corpseId, "fireLotteryPulse", lotto, 2, true);
return false;
}
}
if (groupLootType == 3)
{
return true;
}
return true;
}
public static boolean doGroupLootAllCheck(obj_id player, obj_id corpseId) throws InterruptedException
{
if (player != null && corpseId != null)
{
obj_id leader = group.getLeader(player);
obj_id team = group.getGroupObject(leader);
int lootType = getGroupLootRule(team);
obj_id[] objMembersWhoExist = utils.getLocalGroupMemberIds(team);
if (objMembersWhoExist == null)
{
return true;
}
int number = objMembersWhoExist.length;
if (number < 1)
{
return true;
}
obj_id corpseInv = utils.getInventoryContainer(corpseId);
if (corpseInv == null)
{
return false;
}
obj_id[] contents = getContents(corpseInv);
if (contents == null)
{
return false;
}
int numContents = contents.length;
if (lootType == 0)
{
setGroupLootRule(team, group.FREE_FOR_ALL);
return true;
}
if (lootType == 1)
{
obj_id master = getGroupMasterLooterId(team);
String masterName = getEncodedName(master);
if (master == player)
{
return true;
}
else if (!isIdValid(master))
{
return true;
}
else
{
prose_package pp = new prose_package();
string_id masterMsg = new string_id(group.GROUP_STF, "master_only");
pp = prose.setStringId(pp, masterMsg);
pp = prose.setTO(pp, masterName);
sendSystemMessageProse(player, pp);
return false;
}
}
else if (lootType == 2)
{
if (hasObjVar(corpseId, "autoLootComplete"))
{
return true;
}
if (hasObjVar(corpseId, "numWindowsOpen"))
{
return false;
}
for (obj_id objMemberWhoExists : objMembersWhoExist) {
if (numContents > 0 && !(numContents == 1 && isCashLootItem(contents[0]))) {
openLotteryWindow(objMemberWhoExists, corpseInv);
} else if (numContents == 1 && isCashLootItem(contents[0])) {
return true;
} else {
string_id emptyCorpse = new string_id(group.GROUP_STF, "corpse_empty");
sendSystemMessage(objMemberWhoExists, emptyCorpse);
lootAiCorpse(player, corpseId);
return false;
}
}
setObjVar(corpseId, "numWindowsOpen", objMembersWhoExist.length);
dictionary lotto = new dictionary();
lotto.put("player", player);
lotto.put("corpseInv", corpseInv);
messageTo(corpseId, "fireLotteryPulse", lotto, 2, true);
return false;
}
else if (lootType == 3)
{
return true;
}
else
{
string_id cantLoot = new string_id(group.GROUP_STF, "no_loot_group");
sendSystemMessage(player, cantLoot);
return false;
}
}
return false;
}
public static void sendGroupLootSystemMessage(obj_id item, obj_id winner, String stf, String message) throws InterruptedException
{
sendGroupLootSystemMessage(item, winner, stf, message, false);
}
public static void sendGroupLootSystemMessage(obj_id item, obj_id winner, String stf, String message, boolean skipWinner) throws InterruptedException
{
if (group.isGrouped(winner)) {
obj_id team = getGroupObject(winner);
obj_id[] objMembersWhoExist = utils.getLocalGroupMemberIds(team);
prose_package pp = new prose_package();
string_id lootMsg = new string_id(stf, message);
pp = prose.setStringId(pp, lootMsg);
pp = prose.setTO(pp, item);
pp = prose.setTT(pp, winner);
if(objMembersWhoExist != null) {
if (!skipWinner) {
for (obj_id objMemberWhoExists : objMembersWhoExist) {
sendSystemMessageProse(objMemberWhoExists, pp);
}
} else {
for (obj_id objMemberWhoExists : objMembersWhoExist) {
if (objMemberWhoExists != winner) {
sendSystemMessageProse(objMemberWhoExists, pp);
}
}
}
}
}
}