forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combat-trainer.lic
executable file
·2243 lines (1857 loc) · 76.3 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-travel drinfomon equipmanager events spellmonitor))
class SetupProcess
include DRC
include DRCS
include DRCT
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
@cycle_armors = settings.cycle_armors
echo(" @cycle_armors: #{@cycle_armors}") if $debug_mode_ct
@last_cycle_time = Time.now - 125
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
retreat
if game_state.summoned_info(game_state.weapon_skill)
if DRStats.moon_mage?
bput('wear moon', 'telekinetic')
else
break_summoned_weapon(game_state.weapon_name)
end
else
@equipment_manager.stow_weapon(game_state.weapon_name)
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
check_stance(game_state)
check_weapon(game_state)
else
check_weapon(game_state)
check_stance(game_state)
end
check_armor_swap(game_state)
false
end
private
def check_armor_swap(game_state)
return if Time.now - @last_cycle_time < 120
return if game_state.loaded
armor_types = @cycle_armors.map { |skill, _| skill }
next_armor_type = armor_types.min_by { |skill| [DRSkill.getxp(skill), DRSkill.getrank(skill)] }
return if next_armor_type == @last_worn_type
@last_cycle_time = Time.now
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
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
echo('new skill needed for training') if $debug_mode_ct
game_state.reset_action_count
if DRStats.moon_mage? && 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
new_weapon_skill = weapon_training.min_by { |skill, _| [DRSkill.getxp(skill), DRSkill.getrank(skill)] }.first
game_state.update_weapon_info(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
if @stance_override
pause
waitrt?
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.nil?
result = ['Evasion', 'Parry Ability', 'Shield Usage'].sort_by { |skill| [DRSkill.getxp(skill), skill] }
result.rotate! if @priority_defense == result.last
result
else
game_state.current_weapon_stance[0..1].sort_by { |skill| [DRSkill.getxp(skill), skill] } + [game_state.current_weapon_stance.last]
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+)/ =~ 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)
elsif !next_summoned && !DRStats.moon_mage?
break_summoned_weapon(game_state.last_weapon_name)
elsif !next_summoned && DRStats.moon_mage?
if right_hand =~ /moon/ || left_hand =~ /moon/
bput('wear moon', 'telekinetic')
end
end
# Prepare the next weapon
if next_summoned
game_state.prepare_summoned_weapon(last_summoned)
else
@equipment_manager.wield_weapon(game_state.weapon_name, game_state.weapon_skill)
end
end
end
class LootProcess
include DRC
include DRCI
include DRCS
include DRCH
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
@arrange_all = skinning['arrange_all'] || false
echo(" @arrange_all: #{@arrange_all}") if $debug_mode_ct
@arrange_count = skinning['arrange_count'] || 0
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
@rituals = get_data('spells').rituals
echo(" @rituals: #{@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
@gem_nouns = get_data('items').gem_nouns
echo(" @gem_nouns: #{@gem_nouns}") 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
@gem_pouch_adjective = settings.gem_pouch_adjective
echo(" @gem_pouch_adjective: #{@gem_pouch_adjective}") if $debug_mode_ct
@loot_delay = 5 # in seconds
@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
@last_rites = settings.last_rites
echo(" @last_rites: #{@last_rites}") if $debug_mode_ct
@last_rites_timer = Time.now - 600
end
def execute(game_state)
if (Time.now - @dump_timer > 300) && @dump_junk && DRRoom.room_objs.count >= 13
fput 'DUMP JUNK'
@dump_timer = Time.now
end
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?
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 stow_loot(item, game_state)
Flags.add('pouch-full', 'You think the .* pouch is too full to fit another gem into', 'You\'d better tie it up before putting')
special = @loot_specials.find { |x| x['name'] == item }
if special
if 'already in your inventory' == bput("get #{item}", 'You pick up', 'There isn\'t any more room', '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')
bput("get other #{item}", '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')
end
pause 0.25
bput("put #{item} in my #{special['bag']}", 'you put')
return
end
if 'already in your inventory' == bput("stow #{item}", 'You pick up', 'You get', 'You need a free hand', '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')
if @gem_nouns.include?(item)
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')
else
bput("stow other #{item}", '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')
end
end
pause 0.25
return unless Flags['pouch-full']
bput("drop my #{item}", 'You drop', 'What were')
unless @spare_gem_pouch_container
game_state.unlootable(item)
return
end
bput("remove my #{@gem_pouch_adjective} pouch", 'You remove')
bput("stow my #{@gem_pouch_adjective} pouch", 'You put')
bput("get #{@gem_pouch_adjective} pouch from my #{@spare_gem_pouch_container}", 'You get a')
bput('wear my pouch', 'You attach')
bput("stow #{item}", 'You pick')
if Flags['pouch-full'].first =~ /tie it up/
fput('close my pouch')
else
bput('tie my pouch', 'You tie')
end
end
def stow_lootables(game_state)
return unless @loot_bodies
pair = [left_hand, right_hand]
tried_loot = false
@lootables
.select { |item| game_state.lootable?(item) }
.each do |item|
item_reg = item.split.join('.*')
matches = DRRoom.room_objs.grep(/\b#{item_reg}$/)
tried_loot ||= !matches.empty?
matches.each { |_| stow_loot(item, game_state); }
end
return unless tried_loot
pause 1
if left_hand != pair.first && !@equipment_manager.is_listed_item?(left_hand)
echo("out of room, failed to store #{left_hand}")
game_state.unlootable(GameObj.left_hand.noun.downcase)
dispose_trash(left_hand)
end
if right_hand != pair.last && !@equipment_manager.is_listed_item?(right_hand)
echo("out of room, failed to store #{right_hand}")
game_state.unlootable(GameObj.right_hand.noun.downcase)
dispose_trash(right_hand)
end
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)
if @last_ritual.nil?
if @necro_heal
game_state.wounds = check_health
echo "Severity to Wounds: #{game_state.wounds}" if $debug_mode_ct
do_necro_ritual(mob_noun, 'consume', game_state) unless game_state.wounds.empty?
end
do_necro_ritual(mob_noun, @ritual_type, game_state) unless game_state.prepare_consume || (DRSkill.getxp('Thanatology') > 30 && @skin)
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
do_necro_ritual(mob_noun, 'preserve', game_state) if %w(consume harvest arise).include?(ritual)
perform_message = "perform #{ritual} on #{mob_noun}"
result = bput(perform_message, @rituals['preserve'], @rituals['dissect'], @rituals['harvest'], @rituals['consume'], @rituals['construct'], @rituals['failures'])
echo result if $debug_mode_ct
case result
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?
bput('drop material', 'you discard it')
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 dispose_body(game_state)
return unless @loot_bodies
if DRRoom.dead_npcs.empty?
@last_ritual = nil
return
end
return if Time.now - @loot_timer < @loot_delay
game_state.mob_died = true
if (Time.now - @last_rites_timer > 600) && @last_rites && game_state.blessed_room
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 its safe travels beyond this life')
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
arrange_mob(DRRoom.dead_npcs.first, game_state)
check_skinning(DRRoom.dead_npcs.first, game_state) if check_rituals?(game_state)
unless game_state.casting_consume || game_state.prepare_consume
while 'and get ready to search it' == bput("loot #{@custom_loot_type}".strip, 'You search', 'I could not find what you were referring to', '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.casting_consume || game_state.prepare_consume
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 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')
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
waitrt?
end
end
def check_skinning(mob_noun, game_state)
return unless @skin
return unless game_state.skinnable?(mob_noun)
pause 0.25
waitrt?
if game_state.need_bundle
case bput('tap my bundle', 'You tap a \w+ bundle that you are wearing', 'I could not find what you were referring to')
when /lumpy/
if @tie_bundle
bput('tie bundle', 'TIE the bundle again')
bput('tie bundle', 'you tie the bundle')
bput('adjust bundle', 'You adjust')
end
game_state.need_bundle = false
when /tight/
game_state.need_bundle = false
end
end
snap = [left_hand, right_hand]
case bput('skin', 'roundtime', 'skin what', 'cannot be skinned', 'carrying far too many items', 'need a more appropriate weapon')
when 'carrying far too many items'
waitrt?
fput 'get skin from bundle'
fput 'drop skin'
fput 'skin'
when 'need a more appropriate weapon'
echo('BUY A SKINNING KNIFE')
@skin = false
return
when 'cannot be skinned'
game_state.unskinnable(mob_noun)
return
end
pause 1
waitrt?
if game_state.need_bundle && snap != [left_hand, right_hand]
stored_moon = false
if DRStats.moon_mage? && 'suspend' == bput('wear moon', 'suspend', 'already telekinetic', 'wear what')
stored_moon = true
elsif summoned = game_state.summoned_info(game_state.weapon_skill)
break_summoned_weapon(game_state.weapon_name)
else
@equipment_manager.stow_weapon(game_state.weapon_name)
end
if 'You get' == bput('get bundling rope', 'You get', 'What were you referring to', 'You need a free hand')
fput('bundle')
fput('wear bundle')
if @tie_bundle
bput('tie bundle', 'TIE the bundle again')
bput('tie bundle', 'you tie the bundle')
bput('adjust bundle', 'You adjust')
end
else
dispose_trash(left_hand) if snap.first != left_hand && !@equipment_manager.is_listed_item?(left_hand)
dispose_trash(right_hand) if snap.last != right_hand && !@equipment_manager.is_listed_item?(right_hand)
end
game_state.need_bundle = false
unless stored_moon && 'you grab' == bput('get moon', 'you grab', 'What were')
if summoned
game_state.prepare_summoned_weapon(false)
else
@equipment_manager.wield_weapon(game_state.weapon_name, game_state.weapon_skill)
end
end
end
dispose_trash(left_hand) if snap.first != left_hand && !@equipment_manager.is_listed_item?(left_hand)
dispose_trash(right_hand) if snap.last != right_hand && !@equipment_manager.is_listed_item?(right_hand)
end
end
class SafetyProcess
include DRC
include DRCH
include DRCT
def initialize
echo('New SafetyProcess') if $debug_mode_ct
Flags.add('ct-engaged', 'closes to pole weapon range on you', 'closes to melee range on you')
Flags.add('ct-lodged', 'You feel an agonizing pain from the .* lodged in your (.*)\.')
end
def execute(game_state)
custom_require.call('tendme') if bleeding? && !Script.running?('tendme')
fput 'exit' if health < 40
fix_standing
tend_lodged
game_state.danger = in_danger?(game_state.danger)
keep_away if !game_state.danger && game_state.retreating?
end
private
def tend_lodged
return unless Flags['ct-lodged']
bind_wound(Flags['ct-lodged'].last)
Flags.reset('ct-lodged')
end
def keep_away
return unless Flags['ct-engaged']
Flags.reset('ct-engaged')
retreat
end
def in_danger?(danger)
return false if health >= 75
unless danger
Flags.reset('ct-engaged')
retreat
end
keep_away
true
end
end
class SpellProcess
include DRC
include DRCA
include DRCS
include DRCH
include DRCT
$weapon_buffs = ['Ignite', 'Rutilor\'s Edge', 'Resonance']
def initialize(settings, equipment_manager)
@equipment_manager = equipment_manager
echo('New SpellProcess') if $debug_mode_ct
@buff_spells = settings.buff_spells
echo(" @buff_spells: #{@buff_spells}") if $debug_mode_ct
@offensive_spells = settings.offensive_spells
echo(" @offensive_spells: #{@offensive_spells}") if $debug_mode_ct
@training_spells = settings.combat_spell_training
echo(" @training_spells: #{@training_spells}") if $debug_mode_ct
@offensive_spell_cycle = settings.offensive_spell_cycle
echo(" @offensive_spell_cycle: #{@offensive_spell_cycle}") if $debug_mode_ct
@necromancer_healing = settings.necromancer_healing
echo(" @necromancer_healing: #{@necromancer_healing}") if $debug_mode_ct
@empath_spells = settings.empath_healing
echo(" @empath_spells: #{@empath_spells}") if $debug_mode_ct
@osrel_timer = Time.now - 1000
echo(" @osrel_timer: #{@osrel_timer}") if $debug_mode_ct
@osrel_amount = settings.osrel_amount
echo(" @osrel_amount: #{@osrel_amount}") if $debug_mode_ct
@osrel_no_harness = settings.osrel_no_harness
echo(" @osrel_no_harness: #{@osrel_no_harness}") if $debug_mode_ct
@cast_only_to_train = settings.cast_only_to_train
echo(" @cast_only_to_train: #{@cast_only_to_train}") if $debug_mode_ct
@offensive_spell_mana_threshold = settings.offensive_spell_mana_threshold
echo(" @offensive_spell_mana_threshold: #{@offensive_spell_mana_threshold}") if $debug_mode_ct
@training_spell_mana_threshold = settings.training_spell_mana_threshold
echo(" @training_spell_mana_threshold: #{@training_spell_mana_threshold}") if $debug_mode_ct
@buff_spell_mana_threshold = settings.buff_spell_mana_threshold
echo(" @buff_spell_mana_threshold: #{@buff_spell_mana_threshold}") if $debug_mode_ct
@cambrinth = settings.cambrinth
echo(" @cambrinth: #{@cambrinth}") if $debug_mode_ct
@cambrinth_cap = settings.cambrinth_cap
echo(" @cambrinth_cap: #{@cambrinth_cap}") if $debug_mode_ct
@dedicated_camb_use = settings.dedicated_camb_use
echo(" @dedicated_camb_use: #{@dedicated_camb_use}") if $debug_mode_ct
@stored_cambrinth = settings.stored_cambrinth
echo(" @stored_cambrinth: #{@stored_cambrinth}") if $debug_mode_ct
@perc_health_timer = Time.now
Flags.add('ct-spelllost', 'Your pattern dissipates with the loss of your target')
Flags.add('ct-need-bless', ' passes through the .* with no effect')
@offensive_spells
.select { |spell| spell['expire'] }
.each { |spell| add_spell_flag(spell['abbrev'], spell['expire']) }
@buff_spells
.values
.select { |data| data['expire'] }
.each { |data| add_spell_flag(data['abbrev'], data['expire']) }
@training_cast_timer = Time.now + 45
@training_cyclic_timer = Time.now + 45
@spell_timers = {}
@wounds = {}
@tk_ammo = settings.tk_ammo
@tk_spell = @offensive_spells.find { |spell| spell['abbrev'] =~ /tkt|tks/i }
return unless @tk_ammo
fput("get #{@tk_ammo}")
fput("drop #{@tk_ammo}")
end
def add_spell_flag(name, expire)
Flags.add("ct-#{name}", expire)
Flags["ct-#{name}"] = true
end
def execute(game_state)
return true if game_state.stowing?
check_timer(game_state)
if Flags['ct-spelllost']
game_state.casting = false
Flags.reset('ct-spelllost')
end
check_osrel(game_state)
if game_state.mob_died
@offensive_spells
.select { |spell| spell['expire'] }
.reject { |spell| spell['cyclic'] }
.reject { |spell| spell['heavy'] }
.each { |spell| Flags["ct-#{spell['abbrev']}"] = true }
end
check_slivers(game_state)
check_consume(game_state)
check_bless(game_state)
check_ignite(game_state)
check_rutilors_edge(game_state)
check_health(game_state)
check_buffs(game_state)
check_training(game_state)
check_offensive(game_state)
check_current(game_state)
if game_state.finish_spell_casting? && !game_state.casting
echo('SpellProcess::clean_up') if $debug_mode_ct
game_state.next_clean_up_step
release_cyclics
if @tk_ammo
waitrt?
pause
fput("stow #{@tk_ammo}")
end
return true
end
false
end
private
def check_slivers(game_state)
return if game_state.casting
return if @tk_ammo
return unless @tk_spell
return if DRSpells.slivers
return if UserVars.moons['visible'].empty?
fput('pre moonblade')
if DRSkill.getrank('Lunar Magic') < 300
pause 3
elsif DRSkill.getrank('Lunar Magic') < 400
pause 2
else
pause
end
fput("cast #{UserVars.moons['visible'].first}")
fput('break moonblade')
end
def check_osrel(game_state)
return if game_state.casting
return unless @osrel_amount && DRSpells.active_spells['Osrel Meraud']
return unless Time.now - @osrel_timer > 300
@osrel_timer = Time.now
infuse_om(!@osrel_no_harness, @osrel_amount)
end
def check_timer(game_state)
return if game_state.cast_timer.nil? || (Time.now - game_state.cast_timer) <= 70
game_state.cast_timer = nil
fput('release spell') if game_state.casting
game_state.casting = false
end
def check_bless(game_state)
return if game_state.casting
return unless @buff_spells['Bless']
return unless Flags['ct-need-bless']
Flags.reset('ct-need-bless')
prepare?('Bless', 1)
cast?("cast #{right_hand || left_hand}")
end
def check_ignite(game_state)
# Ignite must be released before it can be recast
# Rutilor's Edge and Resonance do not have this problem
return if @last_seen_weapon_buff_name == game_state.weapon_name
return unless DRSpells.active_spells['Ignite']
# Release the spell on the character
bput('release ignite', 'The warm feeling in your hand goes away', 'Release what')
# Wait for the spell on the weapon to be released (it can take a second or two to pulse)
pause 1
end
def check_rutilors_edge(game_state)
# Rutilor's Edge does not need to be released before it can be recast
# But releasing allows the buff logic to detect it should be recast
return if @last_seen_weapon_buff_name == game_state.weapon_name
return unless DRSpells.active_spells['Rutilor\'s Edge']
# Release the spell on the character
bput('release rue', 'You sense the Rutilor\'s Edge spell fade away', 'Release what')
# Wait for the spell on the weapon to be released (it can take a second or two to pulse)
pause 1
end
def ready_to_cast?(game_state)
Flags['ct-spellcast'] || (@prep_time && Time.now - game_state.cast_timer >= @prep_time)
end
def check_current(game_state)
return unless game_state.casting
return if game_state.check_charging? && game_state.check_charging?
cast_spell(game_state) if ready_to_cast?(game_state)
end
def check_invoke
return unless @should_invoke
find_cambrinth(@cambrinth, @stored_cambrinth, @cambrinth_cap)
@should_invoke = nil
invoke(@cambrinth, @dedicated_camb_use)
stow_cambrinth(@cambrinth, @stored_cambrinth, @cambrinth_cap)
end
def cast_spell(game_state)
check_invoke
if game_state.casting_weapon_buff
@custom_cast = "cast my #{game_state.weapon_name}"
@last_seen_weapon_buff_name = game_state.weapon_name
end
if game_state.casting_consume
if @necromancer_healing.key?('Consume Flesh') && !@necromancer_healing.key?('Devour')
@custom_cast = "cast #{game_state.wounds[game_state.wounds.keys.max].first}"
end
end
hide? if XMLData.prepared_spell == 'Vivisection' && game_state.use_stealth_attack?
cast?(@custom_cast, @symbiosis, @before, @after)
@custom_cast = nil
@symbiosis = nil
@before = nil
@after = nil
game_state.casting = false
game_state.cast_timer = nil
game_state.casting_weapon_buff = false
game_state.casting_consume = false if game_state.casting_consume
if game_state.casting_moonblade
if left_hand =~ /moon/ || game_state.brawling? || game_state.offhand?
# The moonblade was summoned or refreshed while training something else
bput('wear moon', 'telekinetic')
end
game_state.casting_moonblade = false
end
Flags.reset("ct-#{@reset_expire}") if @reset_expire
return unless @command
pause 0.5 until DRRoom.npcs.include?('warrior')
fput("command #{@command}")
@command = nil
end
def check_spell_timer(data)
Time.now - (@spell_timers[data['abbrev']] || Time.at(0)) >= data['recast_every']
end
def check_buff_conditions?(name, game_state)
return false if $weapon_buffs.include?(name) && (game_state.aimed_skill? || game_state.brawling?)
# Resonance does not show up in Active Spells, so we need to track the last weapon on which it was cast to avoid recasting it continuously
# Ignite and Rutilor's Edge do not have this problem
return false if name == 'Resonance' && @last_seen_weapon_buff_name == game_state.weapon_name
true
end
def check_training(game_state)
return if game_state.casting
return unless @training_spells
return if mana < @training_spell_mana_threshold
needs_training = %w(Warding Utility Augmentation)
.select { |skill| @training_spells[skill] }
.select { |skill| DRSkill.getxp(skill) < 31 }
.select { |skill| Time.now > (@training_spells[skill]['cyclic'] ? @training_cyclic_timer : @training_cast_timer) }
.sort_by { |skill| DRSkill.getxp(skill) }.first
return unless needs_training
data = @training_spells[needs_training]
@training_cast_timer = Time.now + 45
if data['cyclic']
@training_cyclic_timer = Time.now + 325
elsif @training_cyclic_timer < @training_cast_timer
@training_cyclic_timer = @training_cast_timer
end
prepare_spell(data, game_state)
end
def check_buffs(game_state)
return if game_state.casting
return if mana < @buff_spell_mana_threshold
recastable_buffs = @buff_spells
.select { |_name, data| data['recast'] || data['recast_every'] || data['expire'] }
.select { |_name, data| data['expire'] ? Flags["ct-#{data['abbrev']}"] : true }
.select { |name, _data| check_buff_conditions?(name, game_state) }
name, data = recastable_buffs.find do |name, data|
if data['recast_every']
check_spell_timer(data)
elsif data['expire']
true
else
!DRSpells.active_spells[name] || DRSpells.active_spells[name].to_i <= data['recast']
end
end
echo("found buff missing: #{name}") if $debug_mode_ct && name
game_state.casting_weapon_buff = $weapon_buffs.include?(name)
if data['ritual']
cast_ritual(data, game_state)
else
prepare_spell(data, game_state)
end
end
def check_health(game_state)
return if game_state.casting
return unless DRStats.empath?
return if health > 95 && @wounds.empty?
if DRSpells.active_spells['Regeneration']
if @empath_spells['VH'] && health <= 95
data = { 'abbrev' => 'vh', 'mana' => @empath_spells['VH'].first, 'cambrinth' => @empath_spells['VH'][1..-1] }
prepare_spell(data, game_state)
end
return
end
if Time.now - @perc_health_timer > 30 && @empath_spells['FOC'] || @empath_spells['HEAL']
@perc_health_timer = Time.now
@wounds = check_perc_health
end
echo('Healing') if $debug_mode_ct
if @wounds.any?
if @empath_spells['FOC']
data = { 'abbrev' => 'foc', 'mana' => @empath_spells['FOC'].first, 'cambrinth' => @empath_spells['FOC'][1..-1] }
elsif @empath_spells['HEAL']
data = { 'abbrev' => 'heal', 'mana' => @empath_spells['HEAL'].first, 'cambrinth' => @empath_spells['HEAL'][1..-1] }
end
@wounds = {}
prepare_spell(data, game_state) if data
elsif @empath_spells['VH']
data = { 'abbrev' => 'vh', 'mana' => @empath_spells['VH'].first, 'cambrinth' => @empath_spells['VH'][1..-1] }
prepare_spell(data, game_state)
end
end
def check_consume(game_state)
return unless DRStats.necromancer?
return unless @necromancer_healing
return if game_state.casting
return unless game_state.prepare_consume
echo "@necromancer_healing.key?('Consume Flesh'): #{@necromancer_healing.key?('Consume Flesh')}" if $debug_mode_ct
echo "@necromancer_healing.key?('Devour'): #{@necromancer_healing.key?('Devour')}" if $debug_mode_ct
data = @necromancer_healing['Devour'] || @necromancer_healing['Consume Flesh']
game_state.casting_consume = true
game_state.prepare_consume = false
prepare_spell(data, game_state)
end
def check_offensive(game_state)
return if game_state.casting
return if game_state.npcs.empty?
return if mana < @offensive_spell_mana_threshold
ready_spells = @offensive_spells
.select { |spell| spell['target_enemy'] ? game_state.npcs.include?(spell['target_enemy']) : true }
.select { |spell| spell['min_threshold'] ? game_state.npcs.length >= spell['min_threshold'] : true }
.select { |spell| spell['max_threshold'] ? game_state.npcs.length <= spell['max_threshold'] : true }
.select { |spell| spell['expire'] ? Flags["ct-#{spell['abbrev']}"] : true }
.select { |spell| game_state.dancing? ? spell['harmless'] : true }
.select { |spell| spell['recast_every'] ? check_spell_timer(spell) : true }
.select { |spell| @cast_only_to_train ? DRSkill.getxp(spell['skill']) <= 32 : true }
.select { |spell| spell['cast_only_to_train'] ? DRSkill.getxp(spell['skill']) <= 32 : true }
.select { |spell| spell['cyclic'] ? !DRSpells.active_spells[spell['name']] : true }
.select { |spell| spell['night'] ? UserVars.sun['night'] : true }
.select { |spell| spell['day'] ? UserVars.sun['day'] : true }
.select { |spell| spell['slivers'] ? DRSpells.slivers : true }
data = if @offensive_spell_cycle.empty?
ready_spells.min_by { |spell| DRSkill.getxp(spell['skill']) }
else
name = @offensive_spell_cycle.find { |spell_name| ready_spells.find { |spell| spell['name'] == spell_name } }
@offensive_spell_cycle.rotate!
ready_spells.find { |spell| spell['name'] == name }
end
prepare_spell(data, game_state)
Flags.reset('ct-spelllost')
end
def cast_ritual(data, game_state)
if summoned = game_state.summoned_info(game_state.weapon_skill)
break_summoned_weapon(game_state.weapon_name)
else
@equipment_manager.stow_weapon(game_state.weapon_name)
end
check_invoke
ritual(data)
if summoned
game_state.prepare_summoned_weapon(false)
else
@equipment_manager.wield_weapon(game_state.weapon_name, game_state.weapon_skill)
end
end
def prepare_spell(data, game_state)
return unless data
game_state.cast_timer = Time.now
@prep_time = data['prep_time']
echo("prepare spell: #{data}") if $debug_mode_ct
if data['target_enemy']
echo(" Target found: #{data['target_enemy']}") if $debug_mode_ct
fput("face #{data['target_enemy']}")
end
release_cyclics if data['cyclic']
command = 'pre'
command = data['prep'] if data['prep']
command = data['prep_type'] if data['prep_type']
@spell_timers[data['abbrev']] = Time.now if data['recast_every']
if data['moon']
unless Script.running? 'moonwatch'
echo 'moonwatch is not running. Starting it now'
UserVars.moons = {}
custom_require.call('moonwatch')
echo "Run `;e autostart('moonwatch')` to avoid this in the future"