-- Pure Lua controller tests; no UE4SS globals or game objects are used. local Arena = dofile(arg[1] or "Mods/PhantomGladiator/Scripts/arena_controller.lua") local function fixture(overrides) local trace, actors, transforms, synced = {}, {}, {}, {} local player, world, cls = { name = "player", alive = true }, { alive = true }, { alive = true } local catalog = { selectedPath = "/Catalog/BP_Test.BP_Test_C" } function catalog:registerPath(path) trace[#trace + 1] = "register"; return { path = path } end function catalog:select(path) self.selectedPath = path; trace[#trace + 1] = "select"; return { path = path } end function catalog:refresh(npcs) assert(next(npcs) == nil); trace[#trace + 1] = "refresh"; return {} end function catalog:resolveSelected() trace[#trace + 1] = "resolve"; return cls end function catalog:selected() return { path = self.selectedPath } end local options = { catalog = catalog, log = function() end, canSpawn = function() return true end, -- Explicit fixture permission, not a production fallback. valid = function(object) return object ~= nil and object.alive == true end, name = function(actor) assert(actor.alive); return actor.name end, hp = function(actor) assert(actor.alive); return actor.hp or 400 end, combatReady = function(actor) assert(actor.alive); return true end, getPlayer = function() return player end, getWorld = function(p) assert(p == player and p.alive); return world end, getLocation = function(p) assert(p == player and p.alive); return { X = 0, Y = 0, Z = 100 } end, getForward = function(p) assert(p == player and p.alive); return { X = 2, Y = 0, Z = 0 } end, spawnClass = function(c, transform, w) assert(c == cls and w == world and cls.alive and world.alive) trace[#trace + 1] = "spawn" transforms[#transforms + 1] = transform local actor = { alive = true, name = "unit" .. (#actors + 1) } actors[#actors + 1] = actor return actor end, onUnitsChanged = function(units) trace[#trace + 1] = "sync" synced = units end, activate = function(actor) assert(actor.alive) local found = false for _, unit in ipairs(synced) do if unit.actor == actor then found = true end end assert(found, "ownership must be synchronized before activation") trace[#trace + 1] = "activate" return true end, setRelation = function(a, b, relation) assert(a.alive and b.alive) trace[#trace + 1] = { "relation", a, b, relation } return true end, forceAttack = function(a, b) assert(a.alive and b.alive and a ~= b) trace[#trace + 1] = { "attack", a, b } return true end, restore = function() trace[#trace + 1] = "restore"; return true end, destroy = function(actor) trace[#trace + 1] = "destroy"; actor.alive = false end, onBattleStarted = function(a, b) trace[#trace + 1] = { "observe", a, b } end, } for key, value in pairs(overrides or {}) do options[key] = value end return { arena = Arena.new(options), options = options, catalog = catalog, player = player, world = world, cls = cls, trace = trace, actors = actors, transforms = transforms, synced = function() return synced end } end local function stageCount(fixtureValue, stage) local count = 0 for _, event in ipairs(fixtureValue.trace) do if event == stage or (type(event) == "table" and event[1] == stage) then count = count + 1 end end return count end if arg[2]=='fixture'then return fixture,stageCount end local f = fixture() do local h=fixture({now=function()return 10 end}) assert(h.arena:spawn(nil,'blue',2).ok and h.arena:spawn(nil,'red',1).ok and h.arena:spawn(nil,'companion',1).ok) local first,second,red,companion=table.unpack(h.actors) local helper={alive=true,name='helper'} assert(h.arena:adoptSummon(helper,first,'/Game/Helper.Helper_C','fixture').ok) local rows=h.arena:status(true).roster assert(#rows==3 and rows[1].ordinal==1 and rows[2].ordinal==2 and rows[2].hp==400) assert(not h.arena:removeRosterUnit(nil).ok and helper.alive and companion.alive) local own=h.options.destroy h.options.destroy=function(actor)if actor~=helper then own(actor) end end assert(not h.arena:removeRosterUnit(rows[1].id).ok and first.alive and helper.alive) h.options.destroy=own assert(h.arena:removeRosterUnit(rows[1].id).ok and not first.alive and not helper.alive) assert(second.alive and red.alive and companion.alive and not h.arena:removeRosterUnit(rows[1].id).ok) assert(h.arena:spawn(nil,'blue',1).ok and h.arena:status(true).roster[3].ordinal==3) assert(h.arena:start().ok and not h.arena:status().roster_editable) assert(not h.arena:removeRosterUnit(rows[2].id).ok and second.alive) red.hp=0 assert(h.arena:status().winner=='blue' and h.arena:status().roster_editable) assert(h.arena:removeRosterUnit(rows[2].id).ok and not second.alive and companion.alive) local final=h.arena:status(true).roster[2] assert(h.arena:removeRosterUnit(final.id).ok and h.arena:status().winner=='blue') assert(stageCount(h,'restore')==0) print('PASS targeted roster removal, helper ownership, stable duplicate numbering and completed result') end do local h=fixture() assert(h.arena:spawn(nil,'red',1).ok) local row=h.arena:status(true).roster[1] local actor=h.actors[1] actor.name='recycled' assert(not h.arena:removeRosterUnit(row.id).ok and actor.alive) actor.name='unit1' local newWorld={alive=true} h.options.getWorld=function()return newWorld end assert(#h.arena:status(true).roster==0 and not h.arena:removeRosterUnit(row.id).ok and actor.alive) print('PASS targeted roster removal rejects actor reuse and another world') end local warningSpawn=fixture({activate=function()return true,'activated','数值未统一,已回滚到原生值' end}) assert(warningSpawn.arena:spawn(nil,'blue',1).ok) local warningResult=warningSpawn.arena:spawn(nil,'red',1) assert(warningResult.ok and warningResult.message:find('数值未统一',1,true)) assert(warningSpawn.arena:status().state~='cleanup_pending' and warningSpawn.arena:start().ok, 'a safely rolled-back optional stat change must not remove HUDs or block normal combat') local prepared=fixture() assert(prepared.arena:spawn(nil,'blue',1).ok and prepared.arena:spawn(nil,'red',1).ok) prepared.options.prepareBattle=function(members) assert(#members==2 and stageCount(prepared,'attack')==0 and stageCount(prepared,'relation')==0) return false end assert(not prepared.arena:start().ok and stageCount(prepared,'attack')==0,'unconfirmed preparation cannot request combat') prepared.options.prepareBattle=function()return true end assert(prepared.arena:start().ok and stageCount(prepared,'attack')==2) do local teams=fixture() assert(teams.arena:spawn(nil,'blue',2).ok and teams.arena:spawn(nil,'red',2).ok) local blueAid,blueFighter,redAid,redFighter=table.unpack(teams.actors) blueAid.storyAid=true redAid.storyAid=true local storyPrepared={} teams.options.isStoryTeamActor=function(actor)return actor.storyAid==true end teams.options.prepareStoryTeamActor=function(actor) assert(actor.storyAid) storyPrepared[actor]=true return true end assert(teams.arena:start().ok) assert(storyPrepared[blueAid] and storyPrepared[redAid], 'direct story aids must be prepared before starting the assigned fight') local relations,targets={},{} for _,event in ipairs(teams.trace)do if type(event)=='table' then if event[1]=='relation' then relations[event[2].name..event[3].name]=event[4] end if event[1]=='attack' then targets[event[2]]=event[3] end end end assert(relations[blueAid.name..blueFighter.name]==0 and relations[redAid.name..redFighter.name]==0, 'direct story aids need an explicit Friendly relationship with same-team units') assert(relations[blueAid.name..redAid.name]==2 and targets[blueAid]==redAid and targets[redAid]==blueAid, 'opposing direct story aids must be assigned to attack one another') assert(teams.arena:spawn(nil,'blue',1).ok) local newcomer=teams.actors[5] newcomer.storyAid=true teams.arena:tickReinforcements() assert(storyPrepared[newcomer],'direct story aid reinforcement must receive the same preparation') for _,event in ipairs(teams.trace)do if type(event)=='table' and event[1]=='attack' and event[2]==newcomer then assert(event[3]==redAid or event[3]==redFighter,'reinforcement may attack only the opposite team') targets[newcomer]=event[3] end end assert(targets[newcomer]) end do local group=fixture({maxUnits=0}) assert(group.arena:spawn(nil,'blue',1).ok and group.arena:spawn(nil,'red',1).ok and group.arena:start().ok) for i=1,24 do assert(group.arena:spawn(nil,i%2==0 and 'blue' or 'red',1).ok) end local pairsSeen,peak={},0 local original=group.options.setRelation group.options.setRelation=function(a,b,r) local key=a.name