forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combat-trainer.lic
5331 lines (4453 loc) · 209 KB
/
combat-trainer.lic
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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#combat-trainer
=end
custom_require.call(%w[common common-arcana common-healing common-items common-summoning common-theurgy common-moonmage common-travel equipmanager events spellmonitor])
class SetupProcess
def initialize(settings, equipment_manager)
@equipment_manager = equipment_manager
echo('New SetupProcess') if $debug_mode_ct
@stance_override = settings.stance_override
echo(" @stance_override: #{@stance_override}") if $debug_mode_ct
@priority_defense = settings.priority_defense
echo(" @priority_defense: #{@priority_defense}") if $debug_mode_ct
@priority_weapons = settings.priority_weapons
echo(" @priority_weapons: #{@priority_weapons}") if $debug_mode_ct
@cycle_armors = settings.cycle_armors
echo(" @cycle_armors: #{@cycle_armors}") if $debug_mode_ct
@cycle_armors_time = settings.cycle_armors_time
echo(" @cycle_armors_time: #{@cycle_armors_time}") if $debug_mode_ct
@armor_hysteresis = settings.cycle_armors_hysteresis
echo(" @armor_hysteresis: #{@armor_hysteresis}") if $debug_mode_ct
@last_cycle_time = Time.now - @cycle_armors_time
@combat_training_abilities_target = settings.combat_training_abilities_target
echo(" @combat_training_abilities_target: #{@combat_training_abilities_target}") if $debug_mode_ct
@cycle_regalia = settings.cycle_armors_regalia
echo(" @cycle_regalia: #{@cycle_regalia}") if $debug_mode_ct
@default_armor = settings.default_armor_type
echo(" @default_armor: #{@default_armor}") if $debug_mode_ct
@ignore_weapon_mindstate = settings.combat_trainer_ignore_weapon_mindstate
echo(" @ignore_weapon_mindstate: #{@ignore_weapon_mindstate}") if $debug_mode_ct
@gearsets = settings.gear_sets
validate_regalia(settings)
end
def execute(game_state)
return true if game_state.done_cleaning_up?
if game_state.stowing?
echo('SetupProcess::clean_up') if $debug_mode_ct
DRC.retreat
if game_state.summoned_info(game_state.weapon_skill)
if DRStats.moon_mage?
DRCMM.wear_moon_weapon?
else
DRCS.break_summoned_weapon(game_state.weapon_name)
end
else
@equipment_manager.stow_weapon(game_state.weapon_name)
game_state.sheath_whirlwind_offhand
end
game_state.next_clean_up_step
return true
end
was_retreating = game_state.retreating?
game_state.update_room_npcs
if game_state.dancing?
game_state.dance
elsif game_state.retreating?
determine_next_to_train(game_state, game_state.retreat_weapons, false)
else
determine_next_to_train(game_state, game_state.weapon_training, was_retreating)
end
if game_state.parrying
# If parrying, determine your next stance (e.g. evasion or shield)
# then switch to your new weapon. This ensures you have a weapon in hand
# to parry with while you're stanced to parry.
check_stance(game_state)
check_weapon(game_state)
else
# And vice versa, if you're not parrying but you might stance to that next
# then ensure you have a weapon in hand then choose an appropriate stance.
# This also ensures the stance you choose respects any weapon-stance overrides.
check_weapon(game_state)
check_stance(game_state)
end
@cycle_regalia ? check_regalia_swap(game_state) : check_armor_swap(game_state)
false
end
private
def armor_hysteresis?
return false unless @armor_hysteresis
return false if @cycle_armors.keys.any? { |skill| DRSkill.getxp(skill) < 25 }
all_swap_pieces = @cycle_armors.keys.map { |armortype| @cycle_armors[armortype] }.flatten
if @cycle_armors.keys.all? { |skill| DRSkill.getxp(skill) > 32 }
if @last_worn_type != @default_armor && @cycle_armors.keys.include?(@default_armor)
@equipment_manager.worn_items(all_swap_pieces).each { |item| @equipment_manager.remove_item(item) }
@equipment_manager.wear_items(@equipment_manager.desc_to_items(@cycle_armors[@default_armor]))
@last_worn_type = @default_armor
end
end
true
end
def regalia_hysteresis?(game_state)
return false unless @armor_hysteresis
# Override hysteresis logic if regalia is about to expire.
return false if @cycle_regalia.any? { |skill| DRSkill.getxp(skill) < 22 } || game_state.last_regalia_type.nil? || Flags['ct-regalia-expired']
if @cycle_regalia.all? { |skill| DRSkill.getxp(skill) > 24 } && game_state.last_regalia_type != @default_armor
return false if Time.now - @last_cycle_time < @cycle_armors_time
game_state.swap_regalia_type = @cycle_regalia.include?(@default_armor) ? @default_armor : @cycle_regalia.max_by { |skill| DRSkill.getrank(skill) } # If no default type declared, go by the highest rank.
end
true
end
def check_armor_swap(game_state)
return if armor_hysteresis?
return if Time.now - @last_cycle_time < @cycle_armors_time
return if game_state.loaded
armor_types = @cycle_armors.map { |skill, _| skill }
next_armor_type = game_state.sort_by_rate_then_rank(armor_types).first
return if next_armor_type == @last_worn_type
return if DRSkill.getxp(next_armor_type) >= @combat_training_abilities_target
@last_cycle_time = Time.now
game_state.sheath_whirlwind_offhand
if @last_worn_type
@equipment_manager.desc_to_items(@cycle_armors[@last_worn_type]).each { |item| @equipment_manager.remove_item(item) }
else
all_swap_pieces = @cycle_armors.map { |_, pieces| pieces }.flatten
@equipment_manager.worn_items(all_swap_pieces).each { |item| @equipment_manager.remove_item(item) }
end
@equipment_manager.wear_items(@equipment_manager.desc_to_items(@cycle_armors[next_armor_type]))
@last_worn_type = next_armor_type
game_state.wield_whirlwind_offhand
end
def check_regalia_swap(game_state)
return if regalia_hysteresis?(game_state)
return if Time.now - @last_cycle_time < @cycle_armors_time && !Flags['ct-regalia-expired']
# if CT is done with regalia (usually starlight depleted) don't process anymore until it starts to expire naturally, then close it down.
if game_state.regalia_cancel
regalia_shutdown(game_state) if Flags['ct-regalia-expired']
return
end
armor_types = @cycle_regalia
next_armor_type = game_state.sort_by_rate_then_rank(armor_types).first
return unless Flags['ct-regalia-expired'] || next_armor_type != @last_worn_type
return unless Flags['ct-regalia-expired'] || game_state.last_regalia_type.nil? || DRSkill.getxp(next_armor_type) < @combat_training_abilities_target
@last_cycle_time = Time.now
game_state.swap_regalia_type = next_armor_type # Mark for SpellProcess casting in check_regalia
end
def determine_next_to_train(game_state, weapon_training, ending_ranged)
return unless game_state.skill_done? || !weapon_training[game_state.weapon_skill] || ending_ranged
unless @ignore_weapon_mindstate
# check if all weapons are maxed exp to prevent rapid cycling
if weapon_training.reject { |skill, _| DRSkill.getxp(skill) == 34 }.empty?
echo 'all weapons locked, not switching' if $debug_mode_ct
return
end
end
echo('new skill needed for training') if $debug_mode_ct
game_state.reset_action_count
# If you're training with summoned moon weapons but you haven't cast the moonblade spell yet
# then skip those weapon skills and train something else while we wait for moonblade spell to be cast.
if DRStats.moon_mage? && !game_state.summoned_weapons.empty? && DRCMM.moon_used_to_summon_weapon.nil?
echo('skipping summoned weapons because no moonblade available') if $debug_mode_ct
weapon_training = weapon_training.reject { |skill, _| game_state.summoned_info(skill) }
end
# Exclude current skill so that a new one is selected.
new_weapon_skills = weapon_training.keys.reject { |skill| skill == game_state.weapon_skill }
new_weapon_skill = game_state.sort_by_rate_then_rank(new_weapon_skills, @priority_weapons).first
# Update weapon skill to train next, if a new one was chosen.
# If you're training exactly one weapon then won't change.
game_state.update_weapon_info(new_weapon_skill) if new_weapon_skill
game_state.update_target_weapon_skill
end
def last_stance
Flags['last-stance'][0] =~ /(\d+)%.* (\d+)%.* (\d+)%.* (\d+)/
{ 'EVASION' => Regexp.last_match(1).to_i, 'PARRY' => Regexp.last_match(2).to_i, 'SHIELD' => Regexp.last_match(3).to_i, 'SPARE' => Regexp.last_match(4).to_i }
end
def build_stance_string(vals)
"stance set #{vals['EVASION']} #{vals['PARRY']} #{vals['SHIELD']}"
end
def check_stance(game_state, override = nil)
return if @override_done && !game_state.reset_stance
if @stance_override
game_state.reset_stance = false
pause
waitrt?
DRC.bput("stance set #{@stance_override}", 'Setting your')
@override_done = true
return
end
vals = { 'EVASION' => 0, 'PARRY' => 0, 'SHIELD' => 0, 'SPARE' => 0 }
skill_map = { 'Parry Ability' => 'Parry', 'Shield Usage' => 'Shield' }
previous = last_stance
points = override || previous.values.inject(&:+)
priority = if game_state.current_weapon_stance
if game_state.strict_weapon_stance
# Player wants their weapon stance strictly adhered to, no change.
game_state.current_weapon_stance
else
# Player has a preference for the first two stances for this weapon
# and is open to having them dynamically prioritized to optimize learning.
game_state.sort_by_rate_then_rank(game_state.current_weapon_stance[0..1]) + [game_state.current_weapon_stance.last]
end
elsif @priority_defense
# Player does not have a weapon specific stance but does want
# a preferred defense to always be 100%.
rest = ['Evasion', 'Parry Ability', 'Shield Usage'] - [@priority_defense]
[@priority_defense] + game_state.sort_by_rate_then_rank(rest)
else
# Player is a gambler and wants combat-trainer to dynamically
# prioritize the stances with the lowest learning rates/ranks.
game_state.sort_by_rate_then_rank(['Evasion', 'Parry Ability', 'Shield Usage'])
end
game_state.parrying = priority.index('Parry Ability') < 2
priority.each do |skill|
skill = skill_map[skill] if skill_map[skill]
vals[skill.upcase] = points >= 100 ? 100 : points
points -= vals[skill.upcase]
end
return if vals == previous
return unless /maximum number of points \((\d+)/ =~ DRC.bput(build_stance_string(vals), 'Setting your Evasion stance to', 'is above your maximum number of points \(\d+')
check_stance(game_state, Regexp.last_match(1).to_i)
end
def check_weapon(game_state)
return if @last_seen_weapon_skill == game_state.weapon_skill
@last_seen_weapon_skill = game_state.weapon_skill
echo("checking weapons as #{game_state.last_weapon_skill.inspect}!=#{game_state.weapon_skill}") if $debug_mode_ct
last_summoned = game_state.summoned_info(game_state.last_weapon_skill)
next_summoned = game_state.summoned_info(game_state.weapon_skill)
# Clean up the previous weapon
if !last_summoned
@equipment_manager.stow_weapon(game_state.last_weapon_name)
game_state.sheath_whirlwind_offhand
elsif !next_summoned && !DRStats.moon_mage?
DRCS.break_summoned_weapon(game_state.last_weapon_name)
elsif !next_summoned && DRStats.moon_mage?
DRCMM.wear_moon_weapon?
end
# Reset state that was specific to the prior weapon.
# This prevents, for example, attempting to do a powershot maneuver
# as soon as you equip another ranged weapon before you've had
# a chance to load it because the game_state thinks you're still holding a loaded weapon.
game_state.loaded = false
@firing_check = 0
# Prepare the next weapon
if next_summoned
game_state.prepare_summoned_weapon(last_summoned)
else
DRC.bput('aim stop', "But you're not aiming", 'You stop concentrating', 'You are already') if game_state.aimed_skill?
game_state.wield_weapon
if game_state.whirlwind_trainable?
game_state.currently_whirlwinding = true
determine_whirlwind_weapon(game_state)
echo("Combat-Trainer:: Whirlwinding with -=== MAIN: #{game_state.weapon_skill} OFF: #{game_state.whirlwind_offhand_skill} ===-") if $debug_mode_ct
else
game_state.currently_whirlwinding = false
end
end
# Invoke Focus
return unless game_state.weapon_skill == 'Targeted Magic' && game_state.weapon_name
DRC.bput("invoke #{game_state.weapon_name}", 'You')
waitrt?
end
def determine_whirlwind_weapon(game_state)
return if game_state.twohanded_weapon_skill?
offhand_skill = game_state.determine_whirlwind_weapon_skill
game_state.update_whirlwind_weapon_info(offhand_skill)
game_state.wield_whirlwind_offhand
end
def validate_regalia(settings)
return unless @cycle_regalia
if @cycle_armors
DRC.message 'ERROR - Regalia cycling and armorswap cycling at the same time not currently supported! Removing Regalia from combat-training!'
@cycle_regalia = nil
end
if settings.gear_sets['regalia'].empty? || settings.gear_sets['regalia'].nil?
DRC.message "ERROR - Regalia cycling requires a gear_set named 'regalia' that will be worn immediately before casting. Removing Regalia from combat-training!"
@cycle_regalia = nil
end
# reset swap clock if you start CT already wearing a regalia.
@last_cycle_time = Time.now unless DRCA.parse_regalia.empty?
end
def regalia_shutdown(game_state)
DRCA.shatter_regalia?
game_state.last_regalia_type = nil
game_state.swap_regalia_type = nil
game_state.regalia_cancel = nil
@cycle_regalia = nil
Flags.reset('ct-regalia-expired')
@equipment_manager.wear_equipment_set?('standard')
@equipment_manager.wield_weapon?(game_state.weapon_name, game_state.weapon_skill) if @gearsets['standard'].include?(game_state.weapon_name) # The above will put away worn weapons
end
end
class LootProcess
def initialize(settings, equipment_manager)
@equipment_manager = equipment_manager
echo('New LootProcess') if $debug_mode_ct
skinning = settings.skinning
@skin = skinning['skin'] || false
echo(" @skin: #{@skin}") if $debug_mode_ct
@dissect = skinning['dissect'] || false
echo(" @dissect: #{@dissect}") if $debug_mode_ct
@dissect_priority = skinning['dissect_priority']
echo(" @dissect_priority: #{@dissect_priority}") if $debug_mode_ct
@dissect_for_thanatology = skinning['dissect_for_thanatology'] || false
echo(" @dissect_for_thanatology: #{@dissect_for_thanatology}") if $debug_mode_ct
@dissect_retry_once = skinning['dissect_retry_once'] || false
echo(" @dissect_retry_once: #{@dissect_retry_once}") if $debug_mode_ct
@dissect_cycle_skills = []
@dissect_cycle_skills.append("Thanatology") if @dissect_for_thanatology
@dissect_cycle_skills.append("First Aid") if @dissect
@dissect_cycle_skills.append("Skinning") if @skin
echo(" @dissect_cycle_skills: #{@dissect_cycle_skills}") if $debug_mode_ct
# Setting to determine whether to always arrange, regardless of skinning, or dissecting
# Depending on the creature level, and the character's skinning skill, simply arranging will teach skinning
# Defaulting to true to keep existing behaviour.
@arrange_for_dissect = skinning['arrange_for_dissect'].nil? ? true : skinning['arrange_for_dissect']
echo(" @arrange_for_dissect: #{@arrange_for_dissect}") if $debug_mode_ct
@arrange_all = skinning['arrange_all'] || false
echo(" @arrange_all: #{@arrange_all}") if $debug_mode_ct
@arrange_count = if @arrange_all
1
else
skinning['arrange_count'] || 0
end
echo(" @arrange_count: #{@arrange_count}") if $debug_mode_ct
@tie_bundle = skinning['tie_bundle'] || false
echo(" @tie_bundle: #{@tie_bundle}") if $debug_mode_ct
@arrange_types = skinning['arrange_types'] || {}
echo(" @arrange_types: #{@arrange_types}") if $debug_mode_ct
@lootables = settings.lootables
echo(" @lootables: #{@lootables}") if $debug_mode_ct
thanatology = settings.thanatology
@ritual_type = thanatology['ritual_type'].downcase
echo(" @ritual_type: #{@ritual_type}") if $debug_mode_ct
@cycle_rituals = @ritual_type == 'cycle'
echo(" @cycle_rituals: #{@cycle_rituals}") if $debug_mode_ct
@dissect_and_butcher = settings.dissect_and_butcher
echo(" @dissect_and_butcher: #{@dissect_and_butcher}") if $debug_mode_ct
@rituals = get_data('spells').rituals
echo(" @rituals: #{@rituals}") if $debug_mode_ct
@redeemed = settings.necro_redeemed
echo(" @redeemed: #{@redeemed}") if $debug_mode_ct
@force_rituals = settings.necro_force_rituals
echo(" @force_rituals: #{@force_rituals}") if $debug_mode_ct
@last_ritual = nil
echo(" @last_ritual: #{@last_ritual}") if $debug_mode_ct
@necro_heal = thanatology['heal'] || false
echo(" @necro_heal: #{@necro_heal}") if $debug_mode_ct
@necro_store = thanatology['store'] || false
echo(" @necro_store: #{@necro_store}") if $debug_mode_ct
@necro_container = thanatology['harvest_container']
echo(" @necro_container: #{@necro_container}") if $debug_mode_ct
@current_harvest_count = DRC.rummage('C material', @necro_container).size if @necro_container
echo(" @current_harvest_count: #{@current_harvest_count}") if $debug_mode_ct
@necro_count = thanatology['harvest_count'] || 0
echo(" @necro_count: #{@necro_count}") if $debug_mode_ct
@make_zombie = settings.zombie['make']
echo(" @make_zombie: #{@make_zombie}") if $debug_mode_ct
@wound_level_threshold = settings.necromancer_healing['wound_level_threshold'] || 1
echo(" @wound_level_threshold: #{@wound_level_threshold}") if $debug_mode_ct
@gem_nouns = get_data('items').gem_nouns
echo(" @gem_nouns: #{@gem_nouns}") if $debug_mode_ct
@tie_pouch = settings.tie_gem_pouches
echo(" @tie_pouch: #{@tie_pouch}") if $debug_mode_ct
@spare_gem_pouch_container = settings.spare_gem_pouch_container
echo(" @spare_gem_pouch_container: #{@spare_gem_pouch_container}") if $debug_mode_ct
@full_pouch_container = settings.full_pouch_container
echo(" @full_pouch_container: #{@full_pouch_container}") if $debug_mode_ct
@gem_pouch_adjective = settings.gem_pouch_adjective
echo(" @gem_pouch_adjective: #{@gem_pouch_adjective}") if $debug_mode_ct
@gem_pouch_noun = settings.gem_pouch_noun
echo(" @gem_pouch_noun: #{@gem_pouch_noun}") if $debug_mode_ct
@autoloot_container = settings.autoloot_container
echo(" @autoloot_container: #{@autoloot_container}") if $debug_mode_ct
@autoloot_gems = settings.autoloot_gems
echo(" @autoloot_gems: #{@autoloot_gems}") if $debug_mode_ct
@autoloot_fill_gem_pouch_delay = settings.autoloot_fill_gem_pouch_delay
echo(" @autoloot_fill_gem_pouch_delay: #{@autoloot_fill_gem_pouch_delay}") if $debug_mode_ct
@autoloot_fill_gem_pouch_timer = Time.now
echo(" @autoloot_fill_gem_pouch_timer: #{@autoloot_fill_gem_pouch_timer}") if $debug_mode_ct
@loot_delay = settings.loot_delay
echo(" @loot_delay: #{@loot_delay}") if $debug_mode_ct
@loot_timer = Time.now - @loot_delay
echo(" @loot_timer: #{@loot_timer}") if $debug_mode_ct
@loot_bodies = settings.loot_bodies
echo(" @loot_bodies: #{@loot_bodies}") if $debug_mode_ct
@loot_specials = settings.loot_specials
echo(" @loot_specials: #{@loot_specials}") if $debug_mode_ct
@custom_loot_type = settings.custom_loot_type
echo(" @custom_loot_type: #{@custom_loot_type}") if $debug_mode_ct
@dump_junk = settings.dump_junk
echo(" @dump_junk: #{@dump_junk}") if $debug_mode_ct
@dump_timer = Time.now - 300
@dump_item_count = settings.dump_item_count
@last_rites = settings.last_rites
echo(" @last_rites: #{@last_rites}") if $debug_mode_ct
@last_rites_timer = Time.now - 600
if settings.box_loot_limit
@box_nouns = get_data('items').box_nouns
@box_loot_limit = settings.box_loot_limit
@current_box_count = DRCI.count_all_boxes(settings)
echo(" @current_box_count: #{@current_box_count}") if $debug_mode_ct
echo(" @box_loot_limit: #{@box_loot_limit}") if $debug_mode_ct
end
Flags.add('using-corpse', 'begins arranging', 'completes arranging', 'kneels down briefly and draws a knife', 'cruelly into the body and carving out a chunk', 'makes additional cuts, purposeful but seemingly at random')
Flags.add('pouch-full', 'You think the .* is too full to fit another gem into', /You'd better tie it up before putting/)
Flags.add('container-full', 'There isn\'t any more room')
end
def execute(game_state)
if (Time.now - @dump_timer > 300) && @dump_junk && DRRoom.room_objs.count >= @dump_item_count
fput 'DUMP JUNK'
@dump_timer = Time.now
end
fill_pouch_with_autolooter(game_state) if @autoloot_container && @autoloot_gems
game_state.mob_died = false
dispose_body(game_state)
stow_lootables(game_state)
if (game_state.mob_died || game_state.npcs.empty?) && game_state.finish_killing?
15.times do
break unless Flags['using-corpse']
break if DRRoom.dead_npcs.empty?
pause
end
stow_lootables(game_state)
echo('LootProcess::clean_up') if $debug_mode_ct
game_state.next_clean_up_step
end
return true if game_state.finish_spell_casting? || game_state.stowing?
false
end
def fill_pouch_with_autolooter(game_state)
return unless (Time.now - @autoloot_fill_gem_pouch_timer) > @autoloot_fill_gem_pouch_delay
return unless (DRC.left_hand.nil? || game_state.currently_whirlwinding)
game_state.sheath_whirlwind_offhand if game_state.currently_whirlwinding
DRCI.fill_gem_pouch_with_container(
@gem_pouch_adjective,
@gem_pouch_noun,
@autoloot_container,
@full_pouch_container,
@spare_gem_pouch_container,
@tie_pouch
)
@autoloot_fill_gem_pouch_timer = Time.now
game_state.wield_whirlwind_offhand if game_state.currently_whirlwinding
end
def stow_loot(item, game_state)
Flags.reset('pouch-full')
Flags.reset('container-full')
special = @loot_specials.find { |x| x['name'] == item }
if special && DRCI.get_item_unsafe(item)
return if DRCI.put_away_item?(item, special['bag'])
end
case DRC.bput("stow #{item}", 'You pick up', 'You put', 'You get', 'You need a free hand', 'needs to be tended to be removed', 'There isn\'t any more room', 'You just can\'t', 'push you over the item limit', 'You stop as you realize the .* is not yours', 'Stow what', 'already in your inventory', 'The .* is not designed to carry anything', 'rapidly decays away', 'cracks and rots away')
when 'already in your inventory'
if @gem_nouns.include?(item)
DRC.bput('stow gem', 'You pick up', 'You get', 'You need a free hand', 'You just can\'t', 'push you over the item limit', 'You stop as you realize the .* is not yours', 'Stow what', 'already in your inventory')
elsif @box_nouns.include?(item)
item_reg = item.split.join('.*')
return stow_loot(DRRoom.room_objs.grep(/\b#{item_reg}$/).first.split.last(2).join(' '), game_state)
else
DRC.bput("stow other #{item}", 'You pick up', 'You put', 'You get', 'You need a free hand', 'needs to be tended to be removed', 'There isn\'t any more room', 'You just can\'t', 'push you over the item limit', 'You stop as you realize the .* is not yours', 'Stow what', 'already in your inventory', 'The .* is not designed to carry anything', 'rapidly decays away', 'cracks and rots away')
end
when 'You pick up', 'You get'
@current_box_count += 1 if @box_loot_limit && @box_nouns.include?(item)
end
pause 0.25
if Flags['container-full']
DRC.bput("drop #{item}", 'You drop')
game_state.unlootable(item)
end
return unless Flags['pouch-full']
DRC.bput("drop my #{item}", 'You drop', 'What were')
unless @spare_gem_pouch_container
game_state.unlootable(item)
return
end
DRC.bput("remove my #{@gem_pouch_adjective} #{@gem_pouch_noun}", 'You remove')
if @full_pouch_container
case DRC.bput("put my #{@gem_pouch_adjective} #{@gem_pouch_noun} in my #{@full_pouch_container}", 'You put', 'too heavy to go in there')
when 'too heavy to go in there'
DRC.bput("stow my #{@gem_pouch_adjective} #{@gem_pouch_noun}", 'You put')
end
else
DRC.bput("stow my #{@gem_pouch_adjective} #{@gem_pouch_noun}", 'You put')
end
DRC.bput("get #{@gem_pouch_adjective} #{@gem_pouch_noun} from my #{@spare_gem_pouch_container}", 'You get a')
DRC.bput("wear my #{@gem_pouch_adjective} #{@gem_pouch_noun}", 'You attach')
DRC.bput('stow gem', 'You pick up', 'You get', 'You need a free hand', 'You just can\'t', 'push you over the item limit', 'You stop as you realize the .* is not yours', 'Stow what', 'already in your inventory')
if @tie_pouch
DRC.bput("tie my #{@gem_pouch_noun}", 'You tie')
else
DRC.bput("close my #{@gem_pouch_noun}", 'You close')
end
end
def stow_lootables(game_state)
return unless @loot_bodies
pair = [DRC.left_hand, DRC.right_hand]
tried_loot = false
items_to_loot = []
@lootables
.select { |item| game_state.lootable?(item) }
.reject { |item| @box_nouns.include?(item) && @box_loot_limit && at_box_limit? }
.each do |item|
item_reg = item.split.join('.*')
matches = DRRoom.room_objs.grep(/\b#{item_reg}$/)
tried_loot ||= !matches.empty?
matches.each { |_| items_to_loot.push(item); }
end
if items_to_loot.any?
game_state.sheath_whirlwind_offhand
items_to_loot.each { |item| stow_loot(item, game_state) }
game_state.wield_whirlwind_offhand
end
return unless tried_loot
pause 1
if DRC.left_hand != pair.first || DRC.right_hand != pair.last
# Mitigating a race condition when wand-watcher or another script pauses
# combat-trainer while it's looting, then resumes in the middle of this function.
# Occassionally, the thread hasn't updated the left_hand/right_hand variables
# to know what's currently in your hand and will trash what's in your hand!
# Do a glance to force the variables to be refreshed before we take action.
DRC.bput('glance', 'You glance .*')
end
if DRC.left_hand != pair.first && !@equipment_manager.is_listed_item?(DRC.left_hand)
DRC.message("Out of room, failed to store: #{DRC.left_hand}")
game_state.unlootable(DRC.left_hand_noun.downcase)
DRCI.dispose_trash(DRC.left_hand)
end
if DRC.right_hand != pair.last && !@equipment_manager.is_listed_item?(DRC.right_hand)
DRC.message("Out of room, failed to store: #{DRC.right_hand}")
game_state.unlootable(DRC.right_hand_noun.downcase)
DRCI.dispose_trash(DRC.right_hand)
end
end
def at_box_limit?
return false unless @box_loot_limit
@current_box_count >= @box_loot_limit
end
def should_perform_ritual?(game_state)
return false unless DRStats.necromancer?
return false unless @ritual_type
return false if game_state.necro_casting?
return true if @force_rituals
return true if @ritual_type == 'cycle'
return true if @ritual_type == 'butcher' && DRSkill.getxp('Thanatology') < 32
return true if @ritual_type == 'dissect' && DRSkill.getxp('First Aid') < 32
return true if @ritual_type == 'harvest' && DRSkill.getxp('Skinning') < 32
return true if DRSkill.getxp('Thanatology') < 32
false
end
def determine_next_ritual
return unless @cycle_rituals
next_ritual = if DRSkill.getxp('Skinning') > 31 && DRSkill.getxp('First Aid') > 31 && DRSkill.getxp('Thanatology') > 31
if @dissect_and_butcher
'butcher'
else
'dissect'
end
elsif DRSkill.getxp('Skinning') < DRSkill.getxp('First Aid')
'harvest'
elsif @dissect_and_butcher
'butcher'
else
'dissect'
end
next_ritual
end
def check_rituals?(game_state)
return true unless DRStats.necromancer?
mob_noun = DRRoom.dead_npcs.first
return true if game_state.construct?(mob_noun)
echo " should_perform_ritual? #{should_perform_ritual?(game_state)}" if $debug_mode_ct
if @last_ritual.nil?
if @necro_heal && !game_state.necro_casting?
game_state.wounds = DRCH.check_health['wounds']
echo "Severity to Wounds: #{game_state.wounds}" if $debug_mode_ct
echo "wound_level_threshold: #{@wound_level_threshold}" if $debug_mode_ct
unless game_state.wounds.empty?
if @wound_level_threshold <= game_state.wounds.keys.max
do_necro_ritual(mob_noun, 'consume', game_state)
return false
end
end
end
if @make_zombie && !game_state.necro_casting? && !game_state.cfb_active?
echo 'Making zombie' if $debug_mode_ct
do_necro_ritual(mob_noun, 'arise', game_state)
return false
end
ritual = if @redeemed
'dissect'
elsif @current_harvest_count < @necro_count
'harvest'
elsif @cycle_rituals
determine_next_ritual
elsif @ritual_type.eql?('dissect') && @dissect_and_butcher
'butcher'
else
@ritual_type
end
do_necro_ritual(mob_noun, ritual, game_state) if should_perform_ritual?(game_state)
end
return false if %w[consume harvest dissect].include?(@last_ritual)
true
end
def do_necro_ritual(mob_noun, ritual, game_state)
return unless DRStats.necromancer?
return unless ritual
return if game_state.construct?(mob_noun)
echo "Attempting necromancer ritual #{ritual} on #{mob_noun}" if $debug_mode_ct
if ritual.eql?('butcher')
butcher_corpse(mob_noun, ritual, game_state)
@last_ritual = ritual
echo "Last ritual performed: #{@last_ritual}" if $debug_mode_ct
return
end
do_necro_ritual(mob_noun, 'preserve', game_state) if %w[consume harvest arise].include?(ritual)
perform_message = "perform #{ritual} on #{mob_noun}"
result = DRC.bput(perform_message, @rituals['arise'], @rituals['preserve'], @rituals['dissect'], @rituals['harvest'], @rituals['consume'], @rituals['construct'], @rituals['failures'])
echo result if $debug_mode_ct
case result
when @rituals['arise']
echo 'Detected arise messaging' if $debug_mode_ct
game_state.prepare_cfb = true if @make_zombie
@last_ritual = ritual
when @rituals['preserve'], @rituals['dissect']
echo 'Detected preserve or dissect messaging' if $debug_mode_ct
@last_ritual = ritual
when @rituals['consume']
echo 'Detected consume messaging' if $debug_mode_ct
@last_ritual = ritual
game_state.prepare_consume = true if @necro_heal
when @rituals['harvest']
echo 'Detected harvest messaging' if $debug_mode_ct
@last_ritual = ritual
waitrt?
necro_harvest_check
when @rituals['construct']
echo 'Detected an attempt to do ritual on a construct' if $debug_mode_ct
game_state.construct(mob_noun)
when *@rituals['failures']
echo 'Failure detected' if $debug_mode_ct
end
echo "Last ritual performed: #{@last_ritual}" if $debug_mode_ct
end
def butcher_corpse(mob_noun, ritual, game_state)
return unless ritual.eql?('butcher')
echo "Butchering the #{mob_noun}'s corpse!" if $debug_mode_ct
echo ' Only butchering it once!' if $debug_mode_ct && @dissect_and_butcher && !@ritual_type.eql?('butcher')
@equipment_manager.stow_weapon(game_state.weapon_name)
loop do
result = DRC.bput("perform #{ritual} on #{mob_noun}", @rituals['butcher'], @rituals['failures'])
break if result.empty? || @rituals['failures'].any? { |msg| result.include?(msg) }
DRC.bput("drop my #{DRC.right_hand}", 'You drop', 'You discard', 'Please rephrase')
break if @dissect_and_butcher && !@ritual_type.eql?('butcher')
end
do_necro_ritual(mob_noun, 'dissect', game_state) if @dissect_and_butcher && !@ritual_type.eql?('butcher')
@equipment_manager.wield_weapon?(game_state.weapon_name, game_state.weapon_skill)
end
def necro_harvest_check
unless @necro_store
echo 'Store material: false, dropping harvested material' if $debug_mode_ct
DRC.bput('drop material', 'you discard it')
return
end
quality = DRC.bput('glance', 'You glance down.*')
if quality['great'] || quality['excellent'] || quality['perfect'] || quality['flawless']
echo 'Harvested high quality material.' if $debug_mode_ct
else
DRC.bput('drop material', 'you discard it')
echo 'Dropped low quality material.' if $debug_mode_ct
return
end
echo 'Store material: true, checking count of stored material' if $debug_mode_ct
if @current_harvest_count >= @necro_count
DRC.bput('drop material', 'you discard it')
echo 'Already full on stored material, dropping harvested material.' if $debug_mode_ct
return
end
result = DRC.bput("put material in my #{@necro_container}", 'You put')
@current_harvest_count += 1 if result =~ /^You put/
end
def dispose_body(game_state)
return unless @loot_bodies
if DRRoom.dead_npcs.empty?
Flags.reset('using-corpse')
@last_ritual = nil
return
end
return if Time.now - @loot_timer < @loot_delay
game_state.mob_died = true
waitrt?
return if Flags['using-corpse']
if (Time.now - @last_rites_timer > 600) && @last_rites && game_state.blessed_room
DRC.bput("pray #{DRRoom.dead_npcs.first}", 'You beseech your god for mercy', 'You pray fervently', 'You continue praying for guidance', 'Quietly touching your lips with the tips of your fingers', 'murmur a brief prayer for')
waitrt?
fput "recite Meraud, power the holy fires that unleash my righteous vengeance;Chadatru, guide my sword to swing in justice;Everild, give me the power to conquer my enemies;Truffenyi, let me not lose sight of compassion and mercy;Else, I will become like those I despise;Urrem'tier, receive into your fetid grasp these wicked souls;May the Tamsine's realms never know their evil ways again;May all the Immortals guide your faithful soldier #{checkname}."
waitrt?
@last_rites_timer = Time.now
return
end
game_state.sheath_whirlwind_offhand
echo("DRRoom.dead_npcs.first is: #{DRRoom.dead_npcs.first}") if $debug_mode_ct
skin_or_dissect(DRRoom.dead_npcs.first, game_state) if check_rituals?(game_state)
game_state.wield_whirlwind_offhand
unless game_state.necro_casting?
while DRC.bput("loot #{@custom_loot_type}".strip, 'You search', 'I could not find what you were referring to', 'and get ready to search it') == 'and get ready to search it'
pause
waitrt?
end
@last_ritual = nil
end
@loot_timer = Time.now
end
def arrange_mob(mob_noun, game_state)
return unless @skin
return unless @arrange_count > 0
return unless game_state.skinnable?(mob_noun)
return if game_state.necro_casting?
arranges = 0
type = @arrange_types[mob_noun] || 'skin'
arrange_message = @arrange_all ? "arrange all for #{type}" : "arrange for #{type}"
while arranges < @arrange_count
arranges += 1
case DRC.bput(arrange_message, 'You begin to arrange', 'You continue arranging', 'You make a mistake', 'You complete arranging', 'That creature cannot', 'That has already been arranged', 'Arrange what', 'cannot be skinned', 'You make a serious mistake in the arranging process', 'The .* is currently being arranged to produce')
when 'You complete arranging', 'That has already been arranged', 'You make a serious mistake in the arranging process', 'Arrange what'
break
when 'cannot be skinned'
game_state.unskinnable(mob_noun)
break
when 'That creature cannot'
arranges = 0
arrange_message = @arrange_all ? 'arrange all' : 'arrange'
end
end
end
def skin_or_dissect(mob_noun, game_state)
return unless (game_state.dissectable?(mob_noun) || game_state.skinnable?(mob_noun))
return unless (@dissect || @skin)
already_arranged = false
if @dissect && game_state.dissectable?(mob_noun)
if @arrange_for_dissect
arrange_mob(mob_noun, game_state)
already_arranged = true
end
if game_state.skinnable?(mob_noun)
skill_to_train = game_state.sort_by_rate_then_rank(@dissect_cycle_skills, @dissect_priority).first
else
skill_to_train = 'First Aid'
end
if skill_to_train == 'First Aid' || skill_to_train == 'Thanatology'
unless dissected?(mob_noun, game_state)
arrange_mob(mob_noun, game_state) unless already_arranged
check_skinning(mob_noun, game_state) if @skin
end
elsif skill_to_train == 'Skinning'
arrange_mob(mob_noun, game_state) unless already_arranged
check_skinning(mob_noun, game_state) if @skin
end
elsif @skin && game_state.skinnable?(mob_noun)
arrange_mob(mob_noun, game_state) unless already_arranged
check_skinning(mob_noun, game_state)
else
return
end
end
def dissected?(mob_noun, game_state)
return unless game_state.dissectable?(mob_noun)
if @dissect_for_thanatology
return false if (DRSkill.getxp('Thanatology') == 34 && DRSkill.getxp('First Aid') == 34)
else
return false if DRSkill.getxp('First Aid') == 34
end
case DRC.bput("dissect #{mob_noun}",
/You'll gain no insights from this attempt/,
/You succeed in dissecting the corpse/,
'What exactly are you trying to dissect',
"You'll learn nothing",
'While likely a fascinating study',
'You cannot dissect',
'would probably object',
"should be left alone.",
"That'd be a waste of time.",
'A skinned creature is worthless',
'You do not yet possess the knowledge',
'This ritual may only be performed on a corpse',
/You learn something/i,
'A failed or completed ritual has rendered',
'You realize after a few seconds')
when /You succeed in dissecting the corpse/, /You learn something/i
return true
when /You'll gain no insights from this attempt/
waitrt?
fput("dissect")
return false
when 'This ritual may only be performed on a corpse', 'A failed or completed ritual has rendered', 'You realize after a few seconds'
return false
when 'While likely a fascinating study', "That'd be a waste of time.", 'You do not yet possess the knowledge'
game_state.undissectable(mob_noun)
return false
when 'would probably object', "should be left alone."
dissected?('', game_state)
end
return false
end
def check_skinning(mob_noun, game_state)
return unless game_state.skinnable?(mob_noun)
if game_state.need_bundle
case DRC.bput('tap my bundle', 'You tap a \w+ bundle that you are wearing', 'I could not find what you were referring to', 'You tap a tight bundle inside')
when /lumpy/
if @tie_bundle
DRC.bput('tie my bundle', 'TIE the bundle again')
DRC.bput('tie my bundle', 'you tie the bundle')
DRC.bput('adjust my bundle', 'You adjust')
end
game_state.need_bundle = false
when /tight/
game_state.need_bundle = false
end
end
snap = [DRC.left_hand, DRC.right_hand]
case DRC.bput('skin', 'roundtime', 'skin what', 'cannot be skinned', 'carrying far too many items', 'need a more appropriate weapon', 'need to have a bladed instrument to skin', 'You must have one hand free to skin')
when 'You must have one hand free to skin'
temp_item = DRC.left_hand
if DRCI.lower_item?(temp_item)
check_skinning(mob_noun, game_state)
DRCI.get_item?(temp_item)
end
when 'need a more appropriate weapon', 'need to have a bladed instrument to skin'
DRC.message('BUY A SKINNING KNIFE')
@skin = false
return
when 'cannot be skinned', 'carrying far too many items'
game_state.unskinnable(mob_noun)
return
end
pause 1
waitrt?
if game_state.need_bundle && snap != [DRC.left_hand, DRC.right_hand]
stored_moon = false
if DRStats.moon_mage? && DRCMM.wear_moon_weapon?
stored_moon = true