Repository navigation
Expand file tree
/
Copy pathmain.lua
More file actions
703 lines (652 loc) · 24.2 KB
/
Copy pathmain.lua
File metadata and controls
703 lines (652 loc) · 24.2 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
-- Exp Share: an OPTIONS row that turns party-wide experience on in
-- five flavors. GEN 1 mirrors the Exp. All key item -- the fighters
-- split half of the exp (and stat exp), and the whole party splits the
-- other half, re-divided by the party count (the participant-division
-- bug included, engine/battle/experience.asm). GEN 5+ mirrors the
-- modern Exp. Share -- the fighters keep the full amount split between
-- them, and every alive bench mon gets half a fighter's share.
-- BALANCED is the GEN 5+ split with a level gate: a bench mon only
-- gains exp while it is below the active fighter's level, so the bench
-- trails the party instead of racing ahead of it. AVERAGE is the same
-- gate measured against the party's average level instead.
-- Shared recipients get ONE "EXP is shared amongst the party" line
-- instead of a per-mon "X gained N EXP. Points!" message.
--
-- CUSTOM keeps the fighters at their full participant share and lets the
-- bench receive 10%..100% of that amount. PERCENT SLOT (ALL / 1..6)
-- selects whether PERCENT edits the global value or one party slot.
--
-- SINGLE EXP SHARE (ALL / 1..6) still scopes those shared recipients
-- to one party slot: set to a slot number, the shared exp
-- goes only to the mon in that slot instead of the whole bench. ALL
-- (the default) keeps the party-wide behaviour above.
local ORDER = { "off", "gen1", "gen5", "balanced", "average", "custom" }
local ORDER_INDEX = {}
for i, mode in ipairs(ORDER) do ORDER_INDEX[mode] = i end
local LABELS = { off = "OFF", gen1 = "GEN 1", gen5 = "GEN 5+",
balanced = "BALANCED", average = "AVERAGE", custom = "CUSTOM" }
local SHARE_TEXT = "EXP is shared\namongst the party!"
local SLOT_ORDER = { "all", "1", "2", "3", "4", "5", "6" }
local SLOT_INDEX = {}
for i, slot in ipairs(SLOT_ORDER) do SLOT_INDEX[slot] = i end
local SLOT_LABELS = { all = "ALL", ["1"] = "1", ["2"] = "2", ["3"] = "3",
["4"] = "4", ["5"] = "5", ["6"] = "6" }
local JINGLE_ORDER = { "level_up", "item" }
local JINGLE_INDEX = { level_up = 1, item = 2, default = 1 }
local JINGLE_LABELS = { level_up = "LEVEL UP", item = "ITEM", default = "LEVEL UP" }
local PERCENT_ORDER = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }
local PERCENT_INDEX = {}
for i, percent in ipairs(PERCENT_ORDER) do PERCENT_INDEX[percent] = i end
local api = {
lastOptions = nil,
}
-- the save behind a battle ctx on either generation: Gen 1's BattleState
-- carries the live game (battle.game.save); Gen 2's Battle carries the save
-- itself (battle.save) with battle.party aliasing save.party.
local function saveOf(battle)
if not battle then return nil end
return battle.save or (battle.game and battle.game.save)
end
local function partyOf(battle)
local save = saveOf(battle)
return (battle and battle.party) or (save and save.party) or {}
end
local function optionsOf(battle)
local save = saveOf(battle)
return save and save.options
end
local function modeFromOptions(options)
local mode = options and options.expShare
if mode == "gen1" or mode == "gen5" or mode == "balanced"
or mode == "average" or mode == "custom" then
return mode
end
return "off"
end
local function slotFromOptions(options)
local slot = tonumber(options and options.expShareSingle)
if slot and slot >= 1 and slot <= 6 then return slot end
return nil
end
local function jingleFromOptions(options)
local jingle = options and options.expShareJingle
if jingle == "item" or jingle == true then
return "item"
end
return "level_up"
end
-- the share line: Gen 1's BattleState:sayNext, Gen 2's Battle:emit
local function sayShare(battle, text)
if not battle then return end
if battle.sayNext then
battle:sayNext(text)
else
battle:emit({ kind = "message", text = text })
end
end
-- normalized mode: nil / garbage -> "off"
function api.modeOf(game)
return modeFromOptions(game and game.save and game.save.options)
end
-- the row's step body: LEFT/RIGHT cycle OFF -> GEN 1 -> GEN 5+ ->
-- BALANCED -> AVERAGE -> CUSTOM -> OFF. Returns nil when there is no save (the
-- launcher's stub games), so the row stays inert there like every other
-- options row.
function api.cycle(game, dir)
local options = game and game.save and game.save.options
if not options then return nil end
-- modeOf normalizes, so the ladder position is a direct lookup; the
-- modulo is the same wrap the engine's own ladder rows use
local i = ORDER_INDEX[api.modeOf(game)]
local nextMode = ORDER[((i - 1 + (dir or 1)) % #ORDER) + 1]
options.expShare = nextMode
if game.writeOptions then
game:writeOptions()
elseif game.persistOptions then
game:persistOptions()
end
return nextMode
end
function api.labelOf(game)
return LABELS[api.modeOf(game)]
end
-- SINGLE EXP SHARE: nil (missing / "all" / garbage) means the shared exp
-- reaches the whole party; a number 1-6 scopes it to that party slot.
function api.slotOf(game)
return slotFromOptions(game and game.save and game.save.options)
end
-- the row's step body: LEFT/RIGHT cycle ALL -> 1 -> 2 -> ... -> 6 -> ALL.
-- Returns nil when there is no save, like api.cycle.
function api.cycleSlot(game, dir)
local options = game and game.save and game.save.options
if not options then return nil end
local i = SLOT_INDEX[options.expShareSingle] or 1
local nextSlot = SLOT_ORDER[((i - 1 + (dir or 1)) % #SLOT_ORDER) + 1]
options.expShareSingle = nextSlot
if game.writeOptions then
game:writeOptions()
elseif game.persistOptions then
game:persistOptions()
end
return nextSlot
end
function api.slotLabel(game)
local options = game and game.save and game.save.options
return SLOT_LABELS[options and options.expShareSingle] or "ALL"
end
local function writeOptions(game)
if game.writeOptions then
game:writeOptions()
elseif game.persistOptions then
game:persistOptions()
end
end
local function normalizePercent(value)
local percent = tonumber(value)
if percent and PERCENT_INDEX[percent] then return percent end
return 100
end
local function percentSlotFromOptions(options)
local slot = options and options.expSharePercentSlot
if slot == nil or slot == "all" then return nil end
local number = tonumber(slot)
if number and number % 1 == 0 and number >= 1 and number <= 6 then
return number
end
return nil
end
local function percentKey(slot)
return "expSharePercent" .. tostring(slot)
end
local function percentForOptions(options, slot)
if type(options) ~= "table" then return 100 end
if slot then
local override = normalizePercent(options[percentKey(slot)])
if options[percentKey(slot)] ~= nil then return override end
end
return normalizePercent(options.expSharePercent)
end
-- PERCENT uses the global value when PERCENT SLOT is ALL, or the selected
-- party-slot override when it names a slot. Missing/invalid saved values
-- fall back to the safe 100% default.
function api.percentSlotOf(game)
return percentSlotFromOptions(game and game.save and game.save.options)
end
function api.percentForSlot(game, slot)
local options = game and game.save and game.save.options
return percentForOptions(options, tonumber(slot))
end
function api.percentOf(game)
local options = game and game.save and game.save.options
return percentForOptions(options, percentSlotFromOptions(options))
end
function api.percentLabel(game)
return tostring(api.percentOf(game)) .. "%"
end
function api.percentSlotLabel(game)
local options = game and game.save and game.save.options
local slot = percentSlotFromOptions(options)
return slot and tostring(slot) or "ALL"
end
-- Cycle the global percentage or the selected slot's percentage, depending
-- on PERCENT SLOT. Each value is an integer multiple of ten.
function api.cyclePercent(game, dir)
local options = game and game.save and game.save.options
if not options then return nil end
local current = api.percentOf(game)
local i = PERCENT_INDEX[current] or #PERCENT_ORDER
local nextPercent = PERCENT_ORDER[((i - 1 + (dir or 1)) % #PERCENT_ORDER) + 1]
local slot = percentSlotFromOptions(options)
if slot then
options[percentKey(slot)] = nextPercent
else
options.expSharePercent = nextPercent
end
writeOptions(game)
return nextPercent
end
function api.cyclePercentSlot(game, dir)
local options = game and game.save and game.save.options
if not options then return nil end
local current = tostring(options.expSharePercentSlot or "all")
local i = SLOT_INDEX[current] or 1
local nextSlot = SLOT_ORDER[((i - 1 + (dir or 1)) % #SLOT_ORDER) + 1]
options.expSharePercentSlot = nextSlot
writeOptions(game)
return nextSlot
end
local function optionsFrom(target)
if type(target) ~= "table" then return nil end
if target.save and target.save.options then return target.save.options end
if target.options then return target.options end
if target.expShareJingle ~= nil or target.expShare ~= nil or target.expShareSingle ~= nil then
return target
end
return nil
end
-- LEVEL UP JINGLE: "level_up" (default fanfare) vs "item" (short item pickup chime).
function api.jingleOf(game)
local options = optionsFrom(game) or api.lastOptions
if not options and package.loaded["src.core.SaveData"] then
pcall(function() options = require("src.core.SaveData").loadOptions() end)
end
return jingleFromOptions(options)
end
function api.cycleJingle(game, dir)
local options = game and game.save and game.save.options
if not options then return nil end
local i = JINGLE_INDEX[api.jingleOf(game)] or 1
local nextJingle = JINGLE_ORDER[((i - 1 + (dir or 1)) % #JINGLE_ORDER) + 1]
options.expShareJingle = nextJingle
api.lastOptions = options
if game.writeOptions then
game:writeOptions()
elseif game.persistOptions then
game:persistOptions()
end
return nextJingle
end
function api.jingleLabel(game)
return JINGLE_LABELS[api.jingleOf(game)] or "LEVEL UP"
end
function api.shouldRedirectJingle(gameOrData)
return api.jingleOf(gameOrData) == "item"
end
-- GEN 1 (Exp. All): participants split half the exp; the whole party
-- splits the other half, with the halved-and-participant-divided base
-- divided again by the party count -- the vanilla
-- DivideExpDataByNumMonsGainingExp behavior with the EXP.ALL item held.
-- applyShare(mon, split, announce): split is the number of shares the
-- mon's base exp/stat exp is divided by; announce true prints the
-- individual gain line, nil stays silent (the share line covers it).
-- The share line announces the party pass before any of its silent
-- level-up messages queue.
function api.awardGen1(ctx)
local battle = ctx.battle
local party = partyOf(battle)
local slot = slotFromOptions(optionsOf(battle))
local single = slot and party[slot]
local p = math.max(1, ctx.participants)
local fought = {}
for _, mon in ipairs(ctx.alive) do fought[mon] = true end
for _, mon in ipairs(ctx.alive) do
ctx.applyShare(mon, p * 2, true)
end
-- the party pass: every alive party mon, or just the designated slot
-- when SINGLE EXP SHARE names one (an out-of-range slot means nobody)
local recipients = {}
for _, mon in ipairs(party) do
if mon.hp > 0 and (not slot or mon == single) then
recipients[#recipients + 1] = mon
end
end
local line = false
for _, mon in ipairs(recipients) do
if not fought[mon] then line = true break end
end
if line then sayShare(battle, SHARE_TEXT) end
for _, mon in ipairs(recipients) do
ctx.applyShare(mon, p * #party * 2, nil)
end
end
-- the shared GEN 5+ split: fighters keep the full exp split between
-- them; every alive bench mon that passes `gate` gets half a fighter's
-- share unless `benchSplit` supplies a custom divisor. The bench gains
-- are silent -- one share line replaces the per-mon messages, and it lands
-- after the fighters' own gains but before the bench level-ups.
local function awardModern(ctx, gate, benchSplit)
local battle = ctx.battle
local party = partyOf(battle)
local slot = slotFromOptions(optionsOf(battle))
local single = slot and party[slot]
local p = math.max(1, ctx.participants)
local fought = {}
for _, mon in ipairs(ctx.alive) do fought[mon] = true end
local bench = {}
for _, mon in ipairs(party) do
if mon.hp > 0 and not fought[mon] and (not gate or gate(mon))
and (not slot or mon == single) then
bench[#bench + 1] = mon
end
end
for _, mon in ipairs(ctx.alive) do
ctx.applyShare(mon, p, true)
end
if #bench > 0 then sayShare(battle, SHARE_TEXT) end
for _, mon in ipairs(bench) do
local split = benchSplit and benchSplit(mon, p) or p * 2
ctx.applyShare(mon, split, nil)
end
end
-- GEN 5+: no gate -- every alive bench mon gets the half share.
function api.awardGen5(ctx)
return awardModern(ctx, nil)
end
-- BALANCED: the GEN 5+ split with the level gate -- a bench mon only
-- gains exp while it is below the active fighter's level. A bench mon
-- at or above the mon you are using gets nothing until the fighter
-- levels past it, so the bench trails the party instead of out-leveling
-- the mons that actually fight.
function api.awardBalanced(ctx)
local battle = ctx.battle
-- Gen 1 wraps the party mon in a battler (battle.player.mon); Gen 2's
-- battle.player IS the party mon. Either way the mon carries `.level`.
local active = battle.player and (battle.player.mon or battle.player)
local capLevel = active and active.level or 100
return awardModern(ctx, function(mon)
return mon.level < capLevel
end)
end
-- AVERAGE: the GEN 5+ split with the gate set to the party's average
-- level -- a bench mon only gains exp while it is below that average
-- (whole party, fainted included), so the bench trails the party's
-- middle instead of the lead fighter.
function api.awardAverage(ctx)
local battle = ctx.battle
local party = partyOf(battle)
local total = 0
for _, mon in ipairs(party) do
total = total + (mon.level or 1)
end
local capLevel = #party > 0 and math.floor(total / #party) or 100
return awardModern(ctx, function(mon)
return mon.level < capLevel
end)
end
-- CUSTOM: participants receive the full share based on the number of
-- participants. Each alive bench mon receives the configured percentage of
-- that same one-participant share; at 100%, the divisor is identical to the
-- fighters' divisor. The engine floors the resulting EXP/stat EXP values in
-- its normal applyShare path.
function api.awardCustom(ctx)
local battle = ctx.battle
local party = partyOf(battle)
local options = optionsOf(battle)
return awardModern(ctx, nil, function(mon, participants)
local slot
for i, candidate in ipairs(party) do
if candidate == mon then slot = i break end
end
local percent = percentForOptions(options, slot)
return participants * 100 / percent
end)
end
local CUSTOM_ROW_IDS = {
exp_share_percent_slot = true,
exp_share_percent = true,
}
local function customOptionRows()
return {
{
id = "exp_share_percent_slot",
label = "PERCENT SLOT",
value = function(g) return api.percentSlotLabel(g) end,
step = function(g, dir)
return api.cyclePercentSlot(g, dir) ~= nil
end,
},
{
id = "exp_share_percent",
label = "PERCENT",
value = function(g) return api.percentLabel(g) end,
step = function(g, dir)
return api.cyclePercent(g, dir) ~= nil
end,
},
}
end
-- OptionsMenu builds one mutable rows list for the lifetime of the screen.
-- Keep that list synchronized when the user changes EXP SHARE to/from CUSTOM
-- instead of waiting for the menu to be reopened.
local function syncCustomOptionRows(rows, game)
local custom = modeFromOptions(game and game.save and game.save.options) == "custom"
local seen = {}
for i = #rows, 1, -1 do
local id = rows[i].id
if CUSTOM_ROW_IDS[id] then
seen[id] = true
if not custom then table.remove(rows, i) end
end
end
if not custom then return end
local insertAt = #rows + 1
for i, row in ipairs(rows) do
if row.id == "exp_share" then insertAt = i + 1 break end
end
for _, row in ipairs(customOptionRows()) do
if not seen[row.id] then
table.insert(rows, insertAt, row)
insertAt = insertAt + 1
end
end
end
return function(mod)
local Sound = require("src.core.Sound")
if Sound then
Sound._expShareApi = api
if not Sound._expShareWrapped then
Sound._expShareWrapped = true
local rawResolve = Sound.resolve
Sound.resolve = function(data, name)
local curApi = Sound._expShareApi or api
if curApi.shouldRedirectJingle(data) then
if name == "Level_Up" then
local sfx = data and data.audio and data.audio.sfx
if sfx and sfx["Get_Item1"] then
return "Get_Item1"
elseif sfx and sfx["Sfx_Item"] then
return "Sfx_Item"
end
return "Get_Item1"
elseif name == "Sfx_DexFanfare5079" then
local sfx = data and data.audio and data.audio.sfx
if sfx and sfx["Sfx_Item"] then
return "Sfx_Item"
elseif sfx and sfx["Get_Item1"] then
return "Get_Item1"
end
return "Sfx_Item"
end
end
if rawResolve then
return rawResolve(data, name)
end
return name
end
local rawPlay = Sound.play
Sound.play = function(data, name)
local curApi = Sound._expShareApi or api
if curApi.shouldRedirectJingle(data) then
if name == "Level_Up" then
local sfx = data and data.audio and data.audio.sfx
if sfx and sfx["Get_Item1"] then
name = "Get_Item1"
elseif sfx and sfx["Sfx_Item"] then
name = "Sfx_Item"
else
name = "Get_Item1"
end
elseif name == "Sfx_DexFanfare5079" then
local sfx = data and data.audio and data.audio.sfx
if sfx and sfx["Sfx_Item"] then
name = "Sfx_Item"
elseif sfx and sfx["Get_Item1"] then
name = "Get_Item1"
else
name = "Sfx_Item"
end
end
end
if rawPlay then
return rawPlay(data, name)
end
end
local rawPlayStereo = Sound.playStereo
Sound.playStereo = function(data, name)
local curApi = Sound._expShareApi or api
if curApi.shouldRedirectJingle(data) then
if name == "Level_Up" then
local sfx = data and data.audio and data.audio.sfx
if sfx and sfx["Get_Item1"] then
name = "Get_Item1"
elseif sfx and sfx["Sfx_Item"] then
name = "Sfx_Item"
else
name = "Get_Item1"
end
elseif name == "Sfx_DexFanfare5079" then
local sfx = data and data.audio and data.audio.sfx
if sfx and sfx["Sfx_Item"] then
name = "Sfx_Item"
elseif sfx and sfx["Get_Item1"] then
name = "Get_Item1"
else
name = "Sfx_Item"
end
end
end
if rawPlayStereo then
return rawPlayStereo(data, name)
end
end
local rawDucks = Sound.ducksMusic
Sound.ducksMusic = function(data, name)
local curApi = Sound._expShareApi or api
if curApi.shouldRedirectJingle(data) then
if name == "Level_Up" then
local sfx = data and data.audio and data.audio.sfx
if sfx and sfx["Get_Item1"] then
name = "Get_Item1"
elseif sfx and sfx["Sfx_Item"] then
name = "Sfx_Item"
else
name = "Get_Item1"
end
elseif name == "Sfx_DexFanfare5079" then
local sfx = data and data.audio and data.audio.sfx
if sfx and sfx["Sfx_Item"] then
name = "Sfx_Item"
elseif sfx and sfx["Get_Item1"] then
name = "Get_Item1"
else
name = "Sfx_Item"
end
end
end
if rawDucks then
return rawDucks(data, name)
end
return false
end
local rawIsPlaying = Sound.isPlaying
Sound.isPlaying = function(name)
local curApi = Sound._expShareApi or api
if curApi.shouldRedirectJingle() then
if name == "Level_Up" then
return (rawIsPlaying and (rawIsPlaying("Get_Item1") or rawIsPlaying("Sfx_Item"))) or (rawIsPlaying and rawIsPlaying(name)) or false
elseif name == "Sfx_DexFanfare5079" then
return (rawIsPlaying and (rawIsPlaying("Sfx_Item") or rawIsPlaying("Get_Item1"))) or (rawIsPlaying and rawIsPlaying(name)) or false
end
end
if rawIsPlaying then
return rawIsPlaying(name)
end
return false
end
local rawStop = Sound.stop
Sound.stop = function(name)
local curApi = Sound._expShareApi or api
if curApi.shouldRedirectJingle() then
if name == "Level_Up" then
if rawStop then rawStop("Get_Item1") rawStop("Sfx_Item") end
elseif name == "Sfx_DexFanfare5079" then
if rawStop then rawStop("Sfx_Item") rawStop("Get_Item1") end
end
end
if rawStop then
rawStop(name)
end
end
end
end
mod.events:on("game.ready", function(ev)
if ev and ev.game and ev.game.save and ev.game.save.options then
api.lastOptions = ev.game.save.options
end
end)
-- the OPTIONS row; next() first keeps every other mod's rows
mod.hooks:wrap("ui.options.rows", function(next, game, rows)
if game and game.save and game.save.options then
api.lastOptions = game.save.options
end
local out = next(game, rows)
if type(out) ~= "table" then return out end
out[#out + 1] = {
id = "exp_share",
label = "EXP SHARE",
value = function(g) return api.labelOf(g) end,
step = function(g, dir)
local nextMode = api.cycle(g, dir)
if nextMode ~= nil then syncCustomOptionRows(out, g) end
return nextMode ~= nil
end,
}
syncCustomOptionRows(out, game)
out[#out + 1] = {
id = "exp_share_single",
label = "SINGLE EXP SHARE",
value = function(g) return api.slotLabel(g) end,
step = function(g, dir)
return api.cycleSlot(g, dir) ~= nil
end,
}
out[#out + 1] = {
id = "exp_share_jingle",
label = "LEVEL UP JINGLE",
value = function(g) return api.jingleLabel(g) end,
step = function(g, dir)
return api.cycleJingle(g, dir) ~= nil
end,
}
return out
end)
-- battle.exp_award: OFF defers to the vanilla participant/EXP.ALL
-- split; GEN 1, GEN 5+, BALANCED, AVERAGE and CUSTOM replace it. ctx is the
-- engine's { battle, participants, alive, applyShare }. Priority 90 runs
-- this wrap before Crystal 251's priority-80 wrap so exp_share wins when
-- active; in OFF mode we defer through nextFn, which falls through to
-- Crystal's wrap so Crystal still owns EXP when exp_share is disabled.
mod.hooks:wrap("battle.exp_award", function(nextFn, ctx)
local opts = optionsOf(ctx.battle)
if opts then api.lastOptions = opts end
local mode = modeFromOptions(opts)
if mode == "gen1" then return api.awardGen1(ctx) end
if mode == "gen5" then return api.awardGen5(ctx) end
if mode == "balanced" then return api.awardBalanced(ctx) end
if mode == "average" then return api.awardAverage(ctx) end
if mode == "custom" then return api.awardCustom(ctx) end
return nextFn(ctx)
end, 90)
mod.exports.modeOf = api.modeOf
mod.exports.cycle = api.cycle
mod.exports.labelOf = api.labelOf
mod.exports.slotOf = api.slotOf
mod.exports.cycleSlot = api.cycleSlot
mod.exports.slotLabel = api.slotLabel
mod.exports.percentSlotOf = api.percentSlotOf
mod.exports.percentForSlot = api.percentForSlot
mod.exports.percentOf = api.percentOf
mod.exports.percentLabel = api.percentLabel
mod.exports.percentSlotLabel = api.percentSlotLabel
mod.exports.cyclePercent = api.cyclePercent
mod.exports.cyclePercentSlot = api.cyclePercentSlot
mod.exports.jingleOf = api.jingleOf
mod.exports.cycleJingle = api.cycleJingle
mod.exports.jingleLabel = api.jingleLabel
mod.exports.shouldRedirectJingle = api.shouldRedirectJingle
mod.exports.awardGen1 = api.awardGen1
mod.exports.awardGen5 = api.awardGen5
mod.exports.awardBalanced = api.awardBalanced
mod.exports.awardAverage = api.awardAverage
mod.exports.awardCustom = api.awardCustom
end