forked from elanthia-online/dr-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cast.lic
724 lines (638 loc) · 26.2 KB
/
cast.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
# quiet
=begin
A highly configurable helper to cast spells.
THE BASICS
----------
You can cast a spell using its abbreviation or using part of its name:
* `,cast bs` will cast Blood Staunching.
* So will `,cast blood`.
* But be careful: `,cast bl` will cast Blessing of the Fae.
The spell name/abbreviation is always expected to be the first argument
supplied.
You can configure the (total!) amount of mana to be used in the cast, as well
as the target to cast at:
* `,cast ip krenze` will cast Ice Patch at Krenze, using min prep (or an
amount of mana you have saved as default, see below).
* `,cast ags 50` will cast Aggressive Stance using 50 mana at the default
target (which for a buff is yourself).
* `,cast gz 30 troll` will cast Gar Zeng using 30 mana at a troll.
* `,cast hw 15 head` will cast Heal Wounds using 15 mana on your head.
* `,cast griz 40 engaged` will cast Grizzly Claws using 40 mana at engaged.
You can also use `discern` in place of a mana amount, and the script will use
`discern` to figure out how much mana to use (including honoring whatever
`prep_scaling_factor` you have configured). Ex:
* `,cast heal discern` will discern the Heal spell and then cast at some
fraction of the discerned max prep.
You can use `-d` or `-debug` to turn on debug logging for this run.
OTHER PARAMETERS
----------------
Besides total mana and target, the following parameters can be used:
* `charge`: charges some of the mana for the cast into cambrinth. This uses
the same settings as `buff`, including whatever default you've set for
`cambrinth_num_charges`. Set it as either `-c??` or `-charge=??`.
You can specify a number, which is the number of charge actions to spread
across. For example:
* `,cast ts 67 -charge=4` will cast Tenebrous Sense by preparing at 14 mana
then charging 14, 13, 13, 13 to cambrinth.
* `,cast cr 80 -c2` will cast Calculated Rage by preparing at 30 mana (the
min spell prep) and charging 25, 25 to cambrinth.
You can also give a number of seconds in which case the script will
optimize for the largest number of small charges that can fit within that
amount of time. For example, if you have 825 ranks of Arcana:
* `,cast lw 80 -charge=9s` will cast Lay Ward by preparing at 27 mana then
charging 27, 26 to cambrinth, which can be done in 9 seconds: 4 seconds
per charge and 1 second to invoke.
* `,cast lw 80 -charge=8s` will cast Lay Ward by preparing at 40 mana then
charging 40 to cambrinth, which can be done in 6 seconds: 5 seconds for
the charge and 1 second to invoke.
This makes it easy to spread charges as efficiently as possible over
however long you're willing to wait before casting.
* `prep_time`: accepts a number of seconds to wait before casting the spell,
rather than waiting for it to be fully prepared. Set this as either `-p??`
or `-prep_time=??`. For example:
* `,cast vh 40 -p8` will cast Vitality Healing at 40 mana after 8 seconds.
* `runestone`: accepts the name of a runestone or other similar item to use
instead of preparing normally. Set this as either `-r=??` or
`-runestone=??`. You can't use any spaces, so if you need an adjective then
give it as `adjective.noun`, e.g.:
* `,cast athl 40 -c2 -r=selenite.runestone` will cast Athleticism at 40
mana using a selenite runestone. Runestones can only be prepped at 20
mana, so cambrinth will be charged for 10, 10.
* `symbiosis`: whether or not to use your currently researched symbiosis when
casting. Set this as either `-s` or `-symbiosis`, and UNset it as either
`-!s` or `-!symbiosis`.
* `force`: bypass checks like mana thresholds and recast timers. Always cast.
Set as `-force`/`-f` or unset as `-!force`/`-!f`
* `wait`: if fatigue, attunement, or concentration are below configured
thresholds, then wait until they have recovered and then cast. By default,
the cast will simply fail. Set as `-wait`/`-w` or unset as `-!wait`/`-!w`
SAVING DEFAULT PARAMETERS
-------------------------
For ease of use, you can save a given set of parameters as the default for
that spell, then just reference the spell on future casts. Even when you have
saved parameters, you can still override them per-cast.
To do this, add the flag `-save` -- instead of casting, the default values
will be saved to UserVars. For example:
* `,cast nb 42 -c2 engaged -save` will set Nissa's Binding to be cast with 42
mana, 2 cambrinth charges, and cast at engaged enemies. Afterward:
* `,cast nb` will cast the spell with those parameters.
* `,cast nb 30` will cast the spell at 30 total mana, but still using the 2
cambrinth charges and the target of engaged.
SAVING ALIASES
--------------
You can also save an alias for a certain configuration, rather than the spell
default. This allows you to have multiple configurations for the same spell,
for example to have a full and snap cast version.
To do this, use `-save=??` and give the alias a name. For example:
* `,cast inno 100 -c20s -save` will set the defaults for Innocence to use 100
mana and charge over 20 seconds.
* `,cast inno 5 -c0 -p0 -save=innos` will create an alias `innos` to cast at
5 mana, no charges, cast after 0 seconds. Afterward...
* `,cast inno` will cast with the default 100-mana config, `,cast innos`
will cast with the 5-mana snap-cast alias.
Aliases can use any alphanumeric characters or underscores (_) but cannot
contain spaces. When referencing them they must be exact: if you save an
alias `snap_gaf`, then `,cast snap_g` will NOT be enough to cast it.
CLEARING SAVED PARAMETERS
-------------------------
To clear saved parameters or aliases, use the `-clear` flag.
* `,cast innos -clear` will clear config for the `innos` alias.
* `,cast bs -clear` will clear the default config for Blood Staunching.
TEST RUNS
---------
Rather than casting the spell, you can use the flag `-test` to see an output
of how the given spell WOULD be cast. For example:
```
> ,cast non 76 Kethrai -c20s -test
CAST: test results, not casting.
Spell name: Nonchalance
Abbreviation: NON
Total mana: 76
Prep mana: 8
Cambrinth: [[8, 8, 8, 8, 8, 7, 7, 7, 7]]
Est. charge time: 19 sec
Cast verb: cast kethrai
```
EXPORTING YAML
--------------
You can export a spell's configuration to YAML format suitable for including
in a waggle_set. For example:
```
> ,cast foc -yaml
CAST: YAML config for foc below.
---
spell_data:
foc: &foc
Fountain of Creation:
cambrinth: [[14, 14, 14, 13]]
# Example of use in a waggle set:
waggle_sets:
buff:
<<: *foc
```
This shows a recommended format for how to include the chosen spell in a
waggle set using YAML anchors. The anchor definition must come BEFORE it is
referenced elsewhere in the file.
YAML SETTINGS USED
------------------
`ritual_focus` -- Focus to use for ritual spells. Won't cast rituals without.
`prep_scaling_factor` -- Number from 0-1 to multiply by discerned max prep.
`cambrinth_num_charges` -- Default number of camb charges if not specified.
`cast_attunement_threshold` -- Don't cast unless attunement is above this
`cast_concentration_threshold` -- Don't cast unless concentration is above this
`cast_fatigue_threshold` -- Don't cast unless fatigue is above this
`cast_threshold_delay` -- How many seconds between checks when waiting
`cambrinth_items` -- An array of cambrinth items, each with:
`cambrinth_items[].name` -- Adjective + noun of the item
`cambrinth_items[].cap` -- Mana capacity
`cambrinth_items[].stored` -- True: must be held, false: worn
OR
`cambrinth` -- Adjective + noun of single camb item
`cambrinth_cap` -- Mana capacity
`stored_cambrinth` -- True: must be held, false: worn
TODO
----
Features that are not currently present include:
* Lots of refactoring cause thing's huge
* Ability to harness as well as or instead of charging camb
* Predicting extra invoke time when using multiple camb items
* Honoring recast timers
* Guild-specific casting features (segue, barrage, etc)
* Using config in YAML rather than relying on UserVars
* Ability to export ALL saved params to waggle YAML instead of one at a time
* Any automated/unit tests
* Testing by any guilds other than Empath
* Testing with use of sorcery
* Testing with spell tattoos
author: Kethrai ([email protected])
game: Dragonrealms
version: 0.3
changelog:
0.3 (2023-07-01):
Support for attunement/concentration/fatigue thresholds
0.2 (2023-07-01):
Disallow aliases that exactly match a canonical abbreviation
0.1 (2023-06-30):
Initial release
=end
custom_require.call(%w[common common-arcana events spellmonitor])
class Cast
def initialize
arg_definitions = [[
{ name: "abbrev", regex: /^\w+$/i, optional: false,
description: "Spell name, abbreviation, or alias to cast" },
{ name: "total_mana", regex: /^(\d+|discern)$/i, optional: true,
description: "How much TOTAL mana to use -- or 'discern'" },
{ name: "target", regex: /^[a-z.]+$/i, optional: true,
description: "What target to CAST at" },
{ name: "-charge=??", regex: /^-c(?:harge=)?\d+s?$/i, optional: true,
description: "Number of charges OR budget in seconds for charging" },
{ name: "-prep_time=??", regex: /^-p(?:rep_time=)?\d+s?$/i, optional: true,
description: "How many seconds to prep before casting" },
{ name: "-runestone=??", regex: /^-r(?:unestone)?=[a-z.]+$/i, optional: true,
description: "Invoke this runestone (or similar item) to prep" },
{ name: "-symbiosis", regex: /^-!?s(?:ymbiosis)?$/i, optional: true,
description: "Prepare (or not) with your currently studied symbiosis" },
{ name: "-force", regex: /^-f(?:orce)?$/i, optional: true,
description: "Force the cast even if checks should prevent it" },
{ name: "-wait", regex: /^-w(?:ait)?$/i, optional: true,
description: "If below attune/conc/fatigue thresholds, wait to cast" },
{ name: "-MODE", regex: /^-(?:save(=\w+)?|test|clear|yaml)$/i, optional: true,
description: "Options: -save[=??], -test, -clear, -yaml (see documentation)" },
{ name: "-debug", regex: /^-d(ebug)?$/i, optional: true,
description: "Output debug messages" },
]]
args = parse_args(arg_definitions)
@debug = !!args["-debug"]
@abbrev = args["abbrev"].downcase
@mode =
case args["-MODE"]
when /^-save(=\w+)?$/i
@alias = Regexp.last_match(1).downcase
:save
when "-test", "-clear", "-yaml"
args["-MODE"].delete_prefix("-").to_sym
else
:cast
end
if @mode != :save && UserVars.cast_data["=#{@abbrev}"]
logd "Found an alias named #{@abbrev} and will use that."
@alias = "=#{@abbrev}"
@abbrev = UserVars.cast_data[@alias]["abbrev"]
end
logd "ARGS --", {
mode: @mode,
abbrev: @abbrev,
alias: @alias,
debug: @debug,
}
@spell_name, @canonical_spell_data = get_canonical_spell_data
@spell_data = @canonical_spell_data.clone
@abbrev = @spell_data["abbrev"].downcase
@min_prep_mana = @spell_data["mana"]
if @mode == :clear
clear_parameters!
exit
end
@settings = get_settings
@ritual_focus = @settings.ritual_focus
@prep_scaling_factor = @settings.prep_scaling_factor || 1.0
@camb_items = normalize_camb(@settings)
@attunement_threshold = @settings.cast_attunement_threshold&.to_i || 0
@concentration_threshold = @settings.cast_concentration_threshold || 0
@fatigue_threshold = @settings.cast_fatigue_threshold || 0
@threshold_delay = @settings.cast_threshold_delay || 15
logd "SETTINGS --", {
ritual_focus: @ritual_focus,
prep_scaling_factor: @prep_scaling_factor,
camb_items: @camb_items,
attunement_threshold: @attunement_threshold,
concentration_threshold: @concentration_threshold,
fatigue_threshold: @fatigue_threshold,
threshold_delay: @threshold_delay,
}, 20
@declared_params = declared_params(args)
@params = merge_params(@declared_params, saved_params, default_params(@settings))
@total_mana = @params["total_mana"]
@charge = @params["charge"]
@prep_time = @params["prep_time"]
@target = @params["target"]
@symbiosis = !!@params["symbiosis"]
@runestone = @params["runestone"]
@force = @params["force"]
@wait = @params["wait"]
logd "PARAMS --", {
total_mana: @total_mana.nil? ? "(will discern)" : @total_mana,
charge: @charge,
prep_time: @prep_time.nil? ? "(when fully prepared)" : @prep_time,
target: @target,
symbiosis: @symbiosis,
runestone: @runestone,
force: @force,
wait: @wait,
}
@arcana_ranks = DRSkill.getmodrank("Arcana")
end
def cast!
optimize_mana_and_cambrinth!
cast_lifecycle_lambda = set_target! if @target
set_focus! if @spell_data["ritual"]
set_prep_time! if @prep_time
set_symbiosis! if @symbiosis
set_runestone! if @runestone
logd "Spell data is now:", @spell_data
case @mode
when :save
save_parameters!
when :test
test_cast
when :yaml
export_yaml
when :cast
if @force
respond "CAST: WARNING: forcing cast and bypassing validation checks."
else
validate_focus
validate_thresholds
end
# DRCA's cast_spell? method doesn't reliably report success and failure -- rituals always
# appear to fail, for example. Also, failing to cast with a runestone because it's spent
# counts as a success. So we will manually look for failures.
Flags.add("cast-spell-failure",
"Currently lacking the skill to complete the pattern",
"backfires",
"Something is interfering with the spell",
"There is nothing else to face",
"You strain, but are too mentally fatigued",
"Well, that was fun.")
DRCA.cast_spell?(@spell_data, @settings, false, cast_lifecycle_lambda)
success = !Flags["cast-spell-failure"]
Flags.delete("cast-spell-failure")
respond "CAST: #{@spell_name} at #{@total_mana} mana. #{if success then "Succeeded!" else "Failed!" end}"
end
end
private
def logd(headline, fields = {}, label_padding = 12)
return unless @debug
field_rows = fields.map do |label, value|
"#{label.to_s.rjust(label_padding)}: #{value}"
end
echo [headline].concat(field_rows).join("\n")
end
def report(headline, fields = {}, label_padding = 12)
shown_fields = fields.reject { |_, v| v.nil? }
field_rows = shown_fields.map do |label, value|
"#{label.to_s.rjust(label_padding)}: #{value}"
end
respond [headline].concat(field_rows).join("\n")
end
# Aliases get namespaced with the `=` prefix. Otherwise favor the canonical spell name.
def spell_key
@alias || @spell_name
end
def normalize_camb(settings)
if settings.cambrinth_items[0]['name']
settings.cambrinth_items
elsif settings.cambrinth
[{ "name" => settings.cambrinth, "cap" => settings.cambrinth_cap, "stored" => settings.stored_cambrinth }]
else
[]
end
end
def get_canonical_spell_data
spell_data = get_data("spells").spell_data
logd "Looking for canonical spell data for abbrev #{@abbrev}"
name, data = spell_data.find { |_, props| props["abbrev"].downcase == @abbrev }
unless name
logd "Spell not found by abbrev, looking for spell with name starting with #{@abbrev}"
name, data = spell_data.find { |canonical_name, _| canonical_name.downcase.start_with?(@abbrev) }
end
if name
logd "Canonical data for #{name}:", data
else
respond "CAST: ERROR: can't find any spell matching #{@abbrev}!"
exit
end
[name, data]
end
def merge_params(declared, saved, default)
logd "merge_params: declared parameters are...", declared
logd "merge_params: saved parameters are...", saved
logd "merge_params: default parameters are...", default
keys = %w{total_mana charge prep_time target symbiosis runestone force wait}
Hash[*keys.flat_map do |key|
value = declared[key] || saved[key] || default[key]
[key, value]
end]
end
def declared_params(args)
params = {}
case args["total_mana"]
when "discern"
params["total_mana"] = discern_total_mana!
when /^\d+$/
params["total_mana"] = args["total_mana"].to_i
end
case args["-charge=??"]
when /^-c(?:harge=)?(\d+s?)$/i
params["charge"] = Regexp.last_match(1).downcase
end
case args["-prep_time=??"]
when /^-p(?:rep_time=)?(\d+)s?$/i
params["prep_time"] = Regexp.last_match(1).to_i
end
case args["-runestone=??"]
when /^-r(?:unestone)?=([a-z.]+)$/i
params["runestone"] = Regexp.last_match(1).downcase
end
params["target"] = args["target"] if args["target"]
params["symbiosis"] = !args["-symbiosis"].start_with?("-!") if args["-symbiosis"]
params["force"] = !args["-force"].start_with?("-!") if args["-force"]
params["wait"] = !args["-wait"].start_with?("-!") if args["-wait"]
params
end
def saved_params
UserVars.cast_data = {} if UserVars.cast_data.nil?
saved_data = UserVars.cast_data[spell_key]
if saved_data
logd "Found saved data for #{spell_key}:", saved_data
saved_data
else
logd "No saved data for #{spell_key}"
{}
end
end
def default_params(settings)
{
"charge" => "#{settings.cambrinth_num_charges || 0}",
"total_mana" => 1
}
end
def discern_total_mana!
logd "Discerning to figure out total mana"
DRC.retreat
case DRC.bput("discern #{@abbrev}",
/^The spell requires at minimum.*for a total of (\d+)/,
/^You don't think you are able to cast this spell/,
/^You have no idea how to cast that spell/,
/^You don't seem to be able to move to do that/)
when /^The spell requires at minimum.*for a total of (\d+)/
discern_max = Regexp.last_match(1).to_i
logd "Theoretical max according to discern: #{discern_max}"
if @prep_scaling_factor
safe_max = (discern_max * @prep_scaling_factor).floor
logd "Scaled by prep_scaling_factor #{@prep_scaling_factor} to #{safe_max}"
return safe_max
else
return discern_max
end
else
logd "Probably can't cast this spell, will only try with 1 mana"
return 1
end
end
def set_focus!
logd "Using ritual_focus of #{@ritual_focus}."
@spell_data["focus"] = @ritual_focus
end
def distribute_num_charges(num_charges = @charge.to_i)
# Runestones are always prepped at 20 mana and can't be changed.
prep_mana = @runestone ? 20 : [@min_prep_mana, (@total_mana * 1.0 / (num_charges + 1)).ceil].max
rest = @total_mana - prep_mana
charge_values = []
charges_left = num_charges
while rest > 0
next_charge = (rest * 1.0 / charges_left).ceil
charge_values << next_charge
rest -= next_charge
charges_left -= 1
end
[prep_mana, charge_values]
end
def optimize_charge_time
charge_time_budget_secs = @charge.delete_suffix("s").to_i
min_charges = 0
max_charges = 10
max_charges.downto(min_charges).each do |num_charges|
prep_mana, charge_values = distribute_num_charges(num_charges)
charge_time = calculate_charge_time(charge_values)
return [prep_mana, charge_values] if charge_time <= charge_time_budget_secs
end
end
def calculate_charge_time(charges)
if charges.empty?
0
else
1 + charges.map { |c| 2 + (c / (5 + (@arcana_ranks / 100).floor)).floor }.sum
end
end
def optimize_mana_and_cambrinth!
logd "Calculating how to prep and charge cambrinth"
if @spell_data["ritual"] || @spell_data["cyclic"]
logd "Never using cambrinth for initial cast of cyclic or for ritual spells"
@spell_data["mana"] = @total_mana
@spell_data["cambrinth"] = nil
return
end
if @charge.end_with?("s")
prep_mana, charge_values = optimize_charge_time
else
prep_mana, charge_values = distribute_num_charges
end
logd "Optimized prep and charges:", {
"Prep mana" => prep_mana,
"Cambrinth charges" => charge_values,
"Expected charge time" => calculate_charge_time(charge_values),
}
# Create an array of arrays representing amounts to charge in each cambrinth item.
cambrinth = Array.new(@camb_items.length) { [] }
camb_index = 0
already_charged = 0
until charge_values.empty? do
charge_value = charge_values.shift
camb_cap = @camb_items[camb_index]["cap"]
camb_name = @camb_items[camb_index]["name"]
if (charge_value + already_charged) <= camb_cap
logd "Will charge #{charge_value} to #{camb_name}"
cambrinth[camb_index] << charge_value
already_charged += charge_value
elsif camb_index < @camb_items.length - 1
logd "Cannot fit #{charge_value} more mana in #{camb_name}, moving to the next."
charge_values.unshift(charge_value)
already_charged = 0
camb_index += 1
else
remainder = charge_value + charge_values.sum
prep_mana += remainder
logd "Ran out of room in all cambrinth items, will add the remaining #{remainder} to base prep (now #{prep_mana})."
break
end
end
# Clean up any empty arrays at the end (which may be all of them, if we're doing no charging)
cambrinth = cambrinth.reverse.drop_while { |c| c.empty? }.reverse
@spell_data["mana"] = prep_mana
@spell_data["cambrinth"] = cambrinth
end
def set_target!
cast_lifecycle_lambda = nil
if @spell_data["skill"] == "Targeted Magic" then
# DRCA doesn't have any way to prepare the spell as "target [abbrev] [prep] at [target]" and instead
# will always "target [abbrev] [prep]", so we need to face the desired target before preparing.
logd "Will face #{@target} before preparing."
cast_lifecycle_lambda = lambda do |hook, _data, _settings|
if hook == "pre-prep" then
DRC.bput "face #{@target}", "You are already facing", "You turn to face", "Face what?", "What's the point"
end
end
else
logd "Will cast at #{@target}."
@spell_data["cast"] = "cast #{@target}"
end
cast_lifecycle_lambda
end
def set_prep_time!
logd "Will cast after #{@prep_time} seconds."
@spell_data["prep_time"] = @prep_time
end
def set_symbiosis!
logd "Will use currently researched symbiosis."
@spell_data["symbiosis"] = true
end
def set_runestone!
logd "Will use runestone #{@runestone}."
@spell_data["runestone_name"] = @runestone
@spell_data["prep"] = "invoke"
end
def validate_focus
if @spell_data["ritual"] && !@ritual_focus
respond "CAST: ERROR: will not cast a ritual spell without a ritual focus! " +
"See 'ritual_focus' in your YAML settings, or -force to cast."
exit
end
end
def thresholds_ok?
DRStats.mana >= @attunement_threshold &&
DRStats.concentration >= @concentration_threshold &&
DRStats.fatigue >= @fatigue_threshold
end
def threshold_status
[
thresholds_ok? ? "Thresholds OK: " : "Below thresholds: ",
"attunement #{DRStats.mana}/#{@attunement_threshold}, ",
"concentration #{DRStats.concentration}/#{@concentration_threshold}, ",
"fatigue #{DRStats.fatigue}/#{@fatigue_threshold}"
].join("")
end
def validate_thresholds
return if thresholds_ok?
if @wait
respond "CAST: WARNING: #{threshold_status}. Waiting until it's possible to cast."
loop do
respond "CAST: #{threshold_status}"
pause [@threshold_delay, 1].max # Juuuuust in case threshold_delay is set way too low
break if thresholds_ok?
end
else
respond "CAST: Cast failed. #{threshold_status}. Use -force or -wait to cast."
exit
end
end
def validate_alias
trimmed_alias = @alias.delete_prefix("=")
spell_data = get_data("spells").spell_data
logd "Checking that there are no spells with abbrev #{trimmed_alias}"
name, _ = spell_data.find { |_, props| props["abbrev"].downcase == trimmed_alias }
if name
respond "CAST: ERROR: Cannot use #{trimmed_alias} as an alias, matches the abbreviation of #{name}."
exit
end
end
def save_parameters!
validate_alias if @alias
UserVars.cast_data = {} if UserVars.cast_data.nil?
# If an alias was given, save with that exact string rather than the canonical spell key
key = @alias || spell_key
save_params = @declared_params.merge({ "abbrev" => @abbrev })
UserVars.cast_data[key] = save_params
report "CAST: saving as default parameters for #{key}.",
(save_params.transform_keys { |k| k.gsub(/_/, " ").capitalize })
test_cast
end
def clear_parameters!
UserVars.cast_data = {} if UserVars.cast_data.nil?
UserVars.cast_data.delete(spell_key)
respond "CAST -- deleting saved parameters for #{spell_key}"
test_cast
end
def test_cast
resolved_total_mana = (@spell_data["mana"] || 0) + (@spell_data["cambrinth"] || [0]).flatten.sum
charge_time = calculate_charge_time((@spell_data["cambrinth"] || []).flatten)
report "CAST: test results, not casting.", {
"Spell name" => @spell_name,
"Total mana" => resolved_total_mana,
"Charge time" => "#{charge_time} sec",
}.merge(@spell_data.transform_keys { |k| k.gsub(/_/, " ").capitalize })
end
def export_yaml
filtered_data = @spell_data.filter { |k, v| v != @canonical_spell_data[k] }
# If this is an aliased spell config, then use the alias to identify it. Allows having multiple
# configurations of the same spell for different waggle sets.
anchor = @alias ? @alias.delete_prefix("=") : @abbrev
yaml = <<~YAMLHEADER
CAST: YAML config for #{anchor} below.
---
spell_data:
#{anchor}: &#{anchor}
#{@spell_name}:
YAMLHEADER
yaml += filtered_data.map { |k, v| " #{k}: #{v}" }.join("\n")
yaml += <<~YAMLFOOTER
# Example of use in a waggle set:
waggle_sets:
buff:
<<: *#{anchor}
YAMLFOOTER
respond yaml
end
end
Cast.new.cast!