Pass data through to ItemEffects.partyAction for Gen 2 pack items

Both call sites -- Game2:usePartyItem (the field pack) and
BattleState:useItem (the battle pack) -- asked ItemEffects.partyAction
for an item's family with no `data` argument, even though every other
call in the same functions (useOnMon, usePpItem, applyPartyItem) passed
it through correctly. partyAction resolves through recordFor, which
reads data.gen2ItemEffects when given a dataset and falls back to the
module's own built-in RECORDS table when not -- so with no data, a
mod's own item_effects record was invisible and every mod-defined Gen 2
field or battle item resolved to a nil action, falling straight through
to "isn't going to help here" / "isn't going to help here" without ever
opening the party picker.

Both now pass the live dataset (self.data on Game2, self.game.data on
the battle screen) the same way their sibling calls already did.
This commit is contained in:
sanjinpepic
2026-08-16 20:28:38 +02:00
parent c23f85cba9
commit d03d2af5f8
4 changed files with 92 additions and 3 deletions
+36
View File
@@ -102,6 +102,24 @@ local DATA = {
TM01 = { id = "TM01", name = "TM01", pocket = "TM_HM", index = 191,
fieldMenu = "ITEMMENU_PARTY", battleMenu = "ITEMMENU_NOUSE",
teaches = "SWIFT" },
-- a mod's own field item, whose action lives only in gen2ItemEffects
-- below -- ItemEffects.RECORDS (the module's built-in table) has never
-- heard of it, so resolving it at all requires the merged dataset (#8)
MOD_ITEM = { id = "MOD_ITEM", name = "MOD ITEM", pocket = "ITEM",
index = 250, fieldMenu = "ITEMMENU_PARTY", battleMenu = "ITEMMENU_PARTY" },
},
gen2ItemEffects = {
MOD_ITEM = {
action = "heal", field = true, needsTarget = true,
use = function(ctx)
local mon = ctx.mon
if mon.hp >= mon.maxHp then
return { used = false, text = "It won't have\nany effect." }
end
mon.hp = math.min(mon.maxHp, mon.hp + 5)
return { used = true, text = "MOD ITEM used!" }
end,
},
},
gen2MenuGfx = {},
gen2Icons = {
@@ -461,6 +479,24 @@ do
eq(host.save.inventory.HP_UP, nil, "and the HP UP was spent")
end
do
-- #8 regression: Game2:usePartyItem asked ItemEffects.partyAction for the
-- item's family with no `data` argument, so it could only ever see
-- RECORDS -- the module's own built-ins. A mod's field item, whose
-- action exists only in the merged gen2ItemEffects table, resolved to a
-- nil action and fell straight through to the "isn't going to help here"
-- refusal instead of opening the party list at all.
local mon = fixtureMon(12, { hp = 10 })
local host = newHost({ MOD_ITEM = 1 }, { mon })
host:useFieldItem("MOD_ITEM")
local party = host.stack:top()
check(party ~= nil and party.prompt ~= nil,
"a mod's own gen2ItemEffects record opens the party list")
drive(host, function() return host.stack:top() ~= party end)
eq(mon.hp, 15, "the mod item's own use() ran through the real menu")
eq(host.save.inventory.MOD_ITEM, nil, "and the mod item was spent")
end
do
local mon = fixtureMon(12, { statExp = {
hp = 25600, attack = 0, defense = 0, speed = 0, special = 0 } })