forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombat-trainer.lic
More file actions
6184 lines (5188 loc) · 248 KB
/
combat-trainer.lic
File metadata and controls
6184 lines (5188 loc) · 248 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
=begin
Documentation: https://elanthipedia.play.net/Lich_script_repository#combat-trainer
=end
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
@offhand_trainables = settings.combat_trainer_offhand_trainables
echo(" @offhand_trainables: #{@offhand_trainables}") if $debug_mode_ct
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?(game_state)
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)
game_state.sheath_whirlwind_offhand
@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
game_state.wield_whirlwind_offhand
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?(game_state)
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)
# No weapons configured: nothing to equip or train. The character will
# dance (bob/weave/circle) for defensive skills only.
unless weapon_training&.any?
unless @no_weapons_warned
@no_weapons_warned = true
DRC.message('*** combat-trainer: No weapons configured in weapon_training.')
DRC.message('*** combat-trainer: Attacks are disabled. Only defensive dance actions (bob/weave/circle) will be used.')
DRC.message('*** combat-trainer: Add entries to weapon_training in your YAML if you want to train weapon skills.')
end
return
end
return unless game_state.skill_done? || !weapon_training[game_state.weapon_skill] || ending_ranged
# skip_all_weapon_max_check is a kludge for a transient condition from blacklisting a skill with
# all remaining skills at 34
unless @ignore_weapon_mindstate || game_state.skip_all_weapon_max_check
# All weapons at 34: stay on current weapon to prevent rapid cycling.
# If no weapon is equipped yet (script startup with all capped), fall
# through to weapon selection so one gets picked (5b becomes 5a).
if weapon_training.reject { |skill, _| DRSkill.getxp(skill) == 34 }.empty?
locked_skills = weapon_training.keys.join(', ')
if game_state.weapon_skill
unless @all_locked_warned
@all_locked_warned = true
DRC.message("*** combat-trainer: All weapon_training skills mindlocked (#{weapon_training.size}): #{locked_skills}")
if weapon_training.size > 1
DRC.message('*** combat-trainer: Set combat_trainer_ignore_weapon_mindstate: true to cycle weapons by action count instead.')
end
end
return
else
unless @all_locked_selecting_warned
@all_locked_selecting_warned = true
DRC.message("*** combat-trainer: All weapon_training skills mindlocked (#{weapon_training.size}): #{locked_skills}")
DRC.message('*** combat-trainer: Selecting initial weapon to begin attacking.')
if weapon_training.size > 1
DRC.message('*** combat-trainer: Set combat_trainer_ignore_weapon_mindstate: true to cycle weapons by action count instead.')
end
end
end
end
end
# With ignore_weapon_mindstate, skill_done? only triggers on action count.
# Notify the user once when all weapons reach 34 that cycling continues by action count.
if @ignore_weapon_mindstate && !@ignore_mindstate_warned
if weapon_training.reject { |skill, _| DRSkill.getxp(skill) == 34 }.empty?
@ignore_mindstate_warned = true
locked_skills = weapon_training.keys.join(', ')
DRC.message("*** combat-trainer: All weapon_training skills mindlocked (#{weapon_training.size}): #{locked_skills} -- ignore_weapon_mindstate is active.")
DRC.message('*** combat-trainer: Cycling weapons by combat_trainer_action_count only.')
end
end
game_state.skip_all_weapon_max_check = false
echo('new skill needed for training') if $debug_mode_ct
# reset counters for game_state.skill_done? after decision to switch to new skill
# as counts for previous weapon is now invalid
game_state.reset_action_count
game_state.last_exp = -1
game_state.last_action_count = 0
# 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 }
# optional & advanced feature:
# offhand_trainables is used to preference bows first, and aiming_trainables in mainhand last, to indirectly force
# aiming_trainables to be used in the offhand rather than pushing out the training for mainhand only weapons.
# It is only active when focus_threshold is active, after all the mindstates are off zero and have a drain buffer.
# There are three selection pools, one for bows, one for mainhand and one for aiming_trainables in mainhand, and skill is chosen
# preferentially in that order
# Each selection pool has a threshold that is needed to "break out" of a selection pool. e.g. when all bow weapons are > 30
# the code will move onto the mainhand selection pool.
# 30 is a magic number and there are multiple factors determining what would be an optimal value, which may not practically
# exist for the wide range of CT use cases.
if @offhand_trainables && game_state.focus_threshold_active
# define what mainhand and offhand skills look like
mainhand_skills = $melee_skills + $thrown_skills + $martial_skills - game_state.aiming_trainables
offhand_skills = game_state.aiming_trainables + ['Offhand Weapon']
# create selection pools of bow/mainhand/offhand groupings
bow_selection_pool = new_weapon_skills.select { |skill| $aim_skills.include?(skill) && DRSkill.getxp(skill) < 30 }
mainhand_selection_pool = new_weapon_skills.select { |skill| mainhand_skills.include?(skill) && DRSkill.getxp(skill) < 30 }
offhand_selection_pool = new_weapon_skills.select { |skill| offhand_skills.include?(skill) && DRSkill.getxp(skill) < 30 }
echo("bow_selection_pool #{bow_selection_pool}") if $debug_mode_ct
echo("mainhand_selection_pool #{mainhand_selection_pool}") if $debug_mode_ct
echo("offhand_selection_pool #{offhand_selection_pool}") if $debug_mode_ct
if bow_selection_pool.length > 0
# choose a bow from this restricted pool (i.e. preferencing bow)
new_weapon_skill = game_state.sort_by_rate_then_rank(bow_selection_pool).first
elsif mainhand_selection_pool.length > 0
# choose a mainhander from this restricted pool (once bows are done)
new_weapon_skill = game_state.sort_by_rate_then_rank(mainhand_selection_pool).first
elsif offhand_selection_pool.length > 0
# choose an offhand weapon (wielded in the main hand) from this restricted pool
new_weapon_skill = game_state.sort_by_rate_then_rank(offhand_selection_pool).first
else
# use normal selection method as a default when everything is above 30 as maintenance
new_weapon_skill = game_state.sort_by_rate_then_rank(new_weapon_skills, @priority_weapons).first
end
else
# normal selection method
new_weapon_skill = game_state.sort_by_rate_then_rank(new_weapon_skills, @priority_weapons).first
end
# 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
flag_result = Flags['last-stance']
return { 'EVASION' => 0, 'PARRY' => 0, 'SHIELD' => 0, 'SPARE' => 0 } unless flag_result
flag_result[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
return unless DRCI.get_item?(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
@worn_trashcan = settings.worn_trashcan
echo(" @worn_trashcan: #{@worn_trashcan}") if $debug_mode_ct
@worn_trashcan_verb = settings.worn_trashcan_verb
echo(" @worn_trashcan_verb: #{@worn_trashcan_verb}") if $debug_mode_ct
@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 requires CF and/or devour to make it a reality, so condition it based on that
@necro_heal = (thanatology['heal'] && (settings.necromancer_healing['Consumed Flesh'] || settings.necromancer_healing['Devour'])) || 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
@make_bonebug = settings.bonebug['make']
echo(" @make_bonebug: #{@make_bonebug}") if $debug_mode_ct
@necro_corpse_priority = settings.necro_corpse_priority
echo(" @necro_corpse_priority: #{@necro_corpse_priority}") 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')
Flags.add('pouch-needs-tie', /You'd better tie it up before putting/)
Flags.add('container-full', 'There isn\'t any more room')
Flags.add('ct-successful-skin', '^You carefully fit .* into your bundle')
end
def execute(game_state)
if DRRoom.room_objs.include?("junk")
@dump_item_count -= 3
end
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
# catch that game state thinks you need a bundle, but you've successfully skinned something this means that likely you have a marked bundle already made
if game_state.need_bundle && Flags['ct-successful-skin']
if @tie_bundle
lowered_item = nil
if DRC.right_hand && DRC.left_hand
lowered_item = DRC.left_hand
DRCI.lower_item?(lowered_item)
end
DRC.bput('tie my bundle', 'TIE the bundle again', 'But this bundle has already been tied off')
if DRC.bput('tie my bundle', 'you tie the bundle', 'But this bundle has already been tied off', 'You don\'t seem to be able to do that right now') =~ /you tie the bundle|already been tied off/
until /You adjust your .* bundle so that you can more easily/ =~ DRC.bput('adjust my bundle', /^You adjust your .*/, /You'll need a free hand for that/)
if DRC.right_hand && DRC.left_hand
DRCI.lower_item?(DRC.left_hand)
until /You adjust your .* bundle so that you can more easily/ =~ DRC.bput('adjust my bundle', /^You adjust your .*/)
end
fput 'lift'
fput 'bundle'
break
end
end
game_state.need_bundle = false
end
DRCI.get_item?(lowered_item) if lowered_item
else
game_state.need_bundle = false
end
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('pouch-needs-tie')
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 open', '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', 'That can\'t be picked up')
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 open', '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', 'That can\'t be picked up')
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
# Pouch just needs tying -- tie it and re-stow the gem
if Flags['pouch-needs-tie']
DRCI.tie_gem_pouch?(@gem_pouch_adjective, @gem_pouch_noun)
in_hand = [GameObj.right_hand, GameObj.left_hand].find { |hand| hand&.noun == item.split.last }
stow_target = in_hand ? "my #{in_hand.noun}" : item
DRC.bput("stow #{stow_target}", 'You pick up', 'You put', 'You open', 'You get', 'You need a free hand', "You just can't", 'push you over the item limit', 'Stow what', 'already in your inventory')
return
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
unless DRCI.swap_out_full_gempouch?(
@gem_pouch_adjective,
@gem_pouch_noun,
@full_pouch_container,
@spare_gem_pouch_container,
@tie_pouch
)
game_state.unlootable(item)
return
end
# Pick up the dropped gem
DRC.bput('stow gem', 'You pick up', 'You get', 'You need a free hand', "You just can't", 'push you over the item limit', 'Stow what', 'already in your inventory')
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_corpse_priority == 'pet'
echo "Prioritizing pet creation over healing" if $debug_mode_ct
check_necro_pet(mob_noun, game_state)
check_necro_heal(mob_noun, game_state)
elsif @necro_corpse_priority == 'heal' || !@necro_corpse_priority
echo "Prioritizing healing over pet creation" if $debug_mode_ct
check_necro_heal(mob_noun, game_state)
check_necro_pet(mob_noun, game_state)
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 check_necro_heal(mob_noun, game_state)
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 devour is active, stop a (second) consume from being requested - has previously caused problem downstream with consume
# flag set but no CF/devour cast to clear hence blocking looting (and potentially other necro_casting defs)
# the check for !devour will also disallow concurrent use of devour and CF but that is not currently supported in CT @ 2/2/2025
if @wound_level_threshold <= game_state.wounds.keys.max && !DRSpells.active_spells['Devour']
do_necro_ritual(mob_noun, 'consume', game_state)
return false
end
end
end
end
def check_necro_pet(mob_noun, game_state)
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
if @make_bonebug && !game_state.necro_casting? && !game_state.cfw_active?
echo 'Making bone bug' if $debug_mode_ct
do_necro_ritual(mob_noun, 'arise', game_state)
return false
end
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)
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_nr = true if @make_zombie && !game_state.cfb_active?
game_state.prepare_cfb = true if @make_zombie && !game_state.cfb_active?
game_state.prepare_cfw = true if @make_bonebug && !game_state.cfw_active?
@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'], @rituals['construct'])
game_state.construct(mob_noun) if result.include?(@rituals['construct'])
@last_ritual = 'butcher' if result.include?(@rituals['butcher'])
break if result.empty? || @rituals['failures'].any? { |msg| result.include?(msg) || result.include?(@rituals['construct']) }
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', 'material doesn\'t seem to fit')
@current_harvest_count += 1 if result =~ /^You put/
DRC.bput('drop material', 'you discard it') if result =~ /^material doesn't seem to fit/
end
def dispose_body(game_state)
return unless @loot_bodies