2316 lines
142 KiB
Lua
2316 lines
142 KiB
Lua
-- 怪对怪处决(实验,v0.37.7). The player executes a unit through its execution component:
|
||
-- PlayExactExecution({ExecutionAbility=<executor side>, ExecutedAbility=<target side>}, target, StartTime)
|
||
-- and each side plays its own montage: the target its being-executed one on its own skeleton, the executor one made
|
||
-- for the player's skeleton (Hun_Skin_Skeleton). The pair is the target config's TargetExecutionAnims (60 configs:
|
||
-- 魔渊, 金面/铁面, 鬼差, 暴徒, 人偶, 大头娃娃, 武轩/浊碧 …) or, for 彭猛 and 毕峰, the one their own finishing skill
|
||
-- starts. Every NPC has the same component (BP_RenewalNPC 'Execution Component'), so in a fight the nearest enemy makes
|
||
-- that call when the target could be executed by the player: it carries CharacterState.CanWeakExecute.Weak (broken)
|
||
-- or .LowHealth (under its execution threshold), which GA_CommonUtilitiesPassive sets through GE_CanWeakExecute /
|
||
-- GE_CanLowHealthExecute; or it is a boss that has sat on its health lock for a second.
|
||
-- The executor turns to face the target first (the game warps the player that way). Its body cannot play the player's
|
||
-- montage, so it borrows one: a hidden component with the player's mesh plays the clip inside that montage, and the
|
||
-- executor's meshes follow that component's bones by name (SetLeaderPoseComponent; 176 of the game's character
|
||
-- skeletons share the player's core bone names). The primary mesh keeps TickPose enabled for its native montage
|
||
-- and root-motion warping. Other parts retain their prior tick policy; original policies are restored at the end.
|
||
-- Proportions differ, so it clips. The executor's clip plays to its
|
||
-- end even when the target falls earlier; then the borrowed body goes. A minion (config Difficulty Tag Mob, Standard
|
||
-- or Elite, the app's 小怪) still standing is ended with GE_Kill, as an execution ends it for the player; a boss
|
||
-- (MiniBoss … UltimateBoss) is left standing, it may have another phase, and can be executed again later, except one
|
||
-- executed on its health lock: that lock comes off and GE_Kill ends it. One execution at a time;
|
||
-- every step is logged with what it read back. Found offline (audit-tools), see REVERSE_ENGINEERING v0.37.7.
|
||
-- A lock is the config's own *LockHealth* effect, a pair's, or any Health_Min floor at most 1% of the unit's health:
|
||
-- 火流星:磷火意识 gets GE_LockHealth from its blueprint. Its execution is the player's QTE (GA_GuiChai_Red_P2_CA_04: a
|
||
-- dodge prompt at the lock, then heavy attack mashed through the execution), which another monster cannot press, so
|
||
-- the mod presses for it: the game's GameplayEvent.QTE.HuoLiuXing goes to the player's ability system, where the
|
||
-- executed side listens, every GAP seconds; the executor's ability and borrowed body play a hit each time and their
|
||
-- finale once the executed side has moved to its own.
|
||
-- 随从处决 BOSS (the app switch, companion_executions.lua): outside the arena's teams, a boss on a companion's hatred list,
|
||
-- summoned with no team or of the map, can be executed the same way by the nearest companion. Minions stay the player's.
|
||
-- 随从处决小怪 (a second app switch, same file): a minion on a companion's hatred list that the player could execute is
|
||
-- executed by the nearest companion too, with the minion's own pair; one the player has taken stays the player's.
|
||
-- A minion with no pair of its own is finished with the Hun's generic pair (hun_execution_pairs.lua), the executor
|
||
-- borrowing the player's body for it as it does for a boss's pair, when the minion's skeleton is that pair's.
|
||
-- 随从魂 (a Hun body summoned as a companion) finishes what the player could finish, whatever that switch says: a
|
||
-- minion as well as a boss on a companion's hatred list. For a minion it takes the pair of the weapon it holds now,
|
||
-- then the generic pair, then the minion's own (Look.STEPS.companionWeaponFirst=false: the minion's own first, as
|
||
-- before); a boss keeps its own pair (made for the player's skeleton, which the Hun body shares, so it plays on the
|
||
-- Hun's own mesh; it carries the boss's lock handling), and one with none gets the weapon's, then the generic one.
|
||
-- 随从魂谁都能处决: when no pair was made for the foe's skeleton (and the foe's own pair, if it has one, cannot be
|
||
-- used), the Hun still plays the first pair of its weapon, or the generic one. The foe's half is then the game's to
|
||
-- play on a skeleton it was not made for; when the foe shows no being-executed montage in 1.5 s the run goes on all
|
||
-- the same: the foe's AI is paused where it stands, the Hun's clip plays out, and the end is the usual one (a minion
|
||
-- dies, a boss stays unless it was on its lock). Off with Look.STEPS.companionAnyone=false.
|
||
-- A target the player is executing or has executed stays the player's. Off with Look.STEPS.companionExecutions=false.
|
||
local U=require('ue_observe')
|
||
local Stats=require('character_stats')
|
||
local PoseProbe=require('execution_pose_probe')
|
||
local Chain=require('execution_chain')
|
||
local CopyPose=require('execution_copy_pose')
|
||
local Playback=require('execution_playback')
|
||
local Opportunities=require('execution_opportunities')
|
||
local Rules=require('execution_rules')
|
||
local Exec={}
|
||
|
||
local MOBS='/PBZCombatAsset/ActorData/Mobs/'
|
||
local GE_LOCK='/PBZCombatAsset/Prototypes/GameplayEffects/GE_LockHealth.GE_LockHealth_C'
|
||
-- Bosses whose pair is started from their own skill, not listed in their config. start: the StartTime the skill
|
||
-- passes; locks: the lock effects it removes, with unlock='start' when it removes them as the execution starts.
|
||
local Lion=require('lion_challenge')
|
||
local LAST_LION_CLASS=Lion.CUB
|
||
local LION_EXEC='GA_Hun_BEx_HouHouHou_01_C'
|
||
local LION_VICTIM='GA_Hun_BEd_HouHouHou_01_C'
|
||
local LION_FLOOR_FRACTION=0.01
|
||
local PAIRS={
|
||
BP_Monster_GuiChai_Red_P2={
|
||
execution=MOBS..'075_GuiChai_Red_P2/Ability/GA_GuiChai_Red_P2_BEx_01.GA_GuiChai_Red_P2_BEx_01_C',
|
||
executed=MOBS..'075_GuiChai_Red_P2/Ability/GA_GuiChai_Red_P2_BEd_01.GA_GuiChai_Red_P2_BEd_01_C',
|
||
start=0.1,locks={GE_LOCK},unlock='start'},
|
||
BP_Monster_PengMeng_Axe={
|
||
execution=MOBS..'044_PengMeng/Ability/Axe/Abilities/CA/GA_Hun_BEx_Common_PengMeng_V2.GA_Hun_BEx_Common_PengMeng_V2_C',
|
||
executed=MOBS..'044_PengMeng/Ability/Axe/Abilities/CA/GA_Hun_BEd_Common_PengMeng.GA_Hun_BEd_Common_PengMeng_C'},
|
||
BP_Monster_GreatBladeMan={
|
||
execution=MOBS..'008_GreatBladeMan/Ability/Abilities/GA_Hun_BEx_Common_BladeMan.GA_Hun_BEx_Common_BladeMan_C',
|
||
executed='/PBZCombatAsset/ActorData/Players/Hun/Abilities/Common/ExE/GA_Hun_BDEd_Common_AttackBladeMan_01.GA_Hun_BDEd_Common_AttackBladeMan_01_C'},
|
||
}
|
||
local TYPES={'Execution.Type.Custom.HorseCartCombat','Execution.Type.CombatRider','Execution.Type.Combat','Execution.Type.Custom.JiangJun'}
|
||
local GENERALS={'CharacterType.JiangJun'}
|
||
local CONTEXTUAL={['Execution.Type.CombatRider']=true,['Execution.Type.Custom.HorseCartCombat']=true}
|
||
-- The player could execute it now (GA_CommonUtilitiesPassive).
|
||
local EXECUTABLE={'CharacterState.CanWeakExecute.Weak','CharacterState.CanWeakExecute.LowHealth'}
|
||
local GE_KILL='/Game/PBZContent/Blueprint/Ability/GameplayEffects/GE_Kill.GE_Kill_C'
|
||
local PROLOGUE_FINAL_LOCK=MOBS..'054_ZuoShang/AIConfig/GE_ZuoShang_MinHealth_04.GE_ZuoShang_MinHealth_04_C'
|
||
-- Locks applied outside configs (blueprints, skills, AI scripts, summons); taken off too when they are loaded.
|
||
local GENERIC_LOCKS={GE_LOCK,'/PBZCombatAsset/Prototypes/GameplayEffects/GE_LockHealthButCanExecuted.GE_LockHealthButCanExecuted_C'}
|
||
local DEATH_LOCK=0.01 -- a floor of unknown source counts as a lock up to this share of Health_Max (not a phase)
|
||
local ABILITY_LIBRARY='/Script/GameplayAbilities.Default__AbilitySystemBlueprintLibrary'
|
||
-- The executor's own AI kept choosing moves during the first test (魔渊 started attacks 1.1 s in and his capsule
|
||
-- wandered from 2 m to 14 m off the boss while his body played the execution), so its brain is paused meanwhile.
|
||
local AI_LIBRARY='/Script/SGameAI.Default__SGameAIFunctionLibrary'
|
||
local PAUSE_REASON='PhantomGladiator execution'
|
||
local MESH_CLASS='/Script/Engine.SkeletalMeshComponent'
|
||
-- Both original victim montages use this sequence. The start plays for 0.9 s at 0.6x,
|
||
-- then the finish montage jumps to source 0.4 at 3x and continues from 0.7 at 1.5x.
|
||
local GUILLOTINE_GRAB={clip='/HuaShira/Characters/EliteBoss/MBoss/Anim/Hun_EXD_ByMBoss.Hun_EXD_ByMBoss',
|
||
rate=0.6000000238418579,same_skeleton=true}
|
||
local GUILLOTINE_POSES={
|
||
{limit=0.54},
|
||
{from=0.4,rate=3,limit=0.7},
|
||
{from=0.7,rate=1.5,limit=6.233333},
|
||
{from=6.233333,rate=0},
|
||
}
|
||
-- A victim on Hun_Skin_Skeleton (the Hun body) plays the original victim montages on its own anim instance: the start
|
||
-- (0.6x inside the montage) held at the 0.9 s catch point, then the finish (its two rates are in the montage).
|
||
local GUILLOTINE_SELF={start='/PBZCombatAsset/ActorData/Players/Hun/Montage/Execution/Hun_EXD_ByMBoss_Start_Montage.Hun_EXD_ByMBoss_Start_Montage',
|
||
finish='/PBZCombatAsset/ActorData/Players/Hun/Montage/Execution/Hun_EXD_ByMBoss_Montage.Hun_EXD_ByMBoss_Montage',
|
||
skeleton='Hun_Skin_Skeleton',catch=0.9,finishLength=3.788884}
|
||
-- An executor whose own mesh is on its clip's skeleton plays the execution on that mesh; when its montage has not
|
||
-- shown up this long after the call, it borrows a body as any other executor does, for the rest of the battle.
|
||
local DIRECT_WAIT=0.3
|
||
local GUILLOTINE_PAUSE='PhantomGladiator guillotine'
|
||
local GUILLOTINE_TIMEOUT=12 -- game seconds, longer than the original victim sequence
|
||
local MOVE_NONE=0
|
||
local IDENTITY={Rotation={X=0,Y=0,Z=0,W=1},Translation={X=0,Y=0,Z=0},Scale3D={X=1,Y=1,Z=1}}
|
||
-- Skinned parts that can follow a body: meshes, and Chaos cloth (魔渊's hair CA_Motian_Hair01 and three cloth pieces,
|
||
-- 彭猛's cape). The first build left the cloth on the body while the body followed the borrowed skeleton, and the
|
||
-- hair and cloth were left floating after the execution.
|
||
local MESH_KINDS={'SkeletalMeshComponent','ChaosClothComponent'}
|
||
local RESET_PHYSICS=2 -- ETeleportType::ResetPhysics
|
||
local SNAP=2 -- EAttachmentRule::SnapToTarget
|
||
local TICK_REFRESH=0 -- EVisibilityBasedAnimTickOption::AlwaysTickPoseAndRefreshBones (hidden, still posed)
|
||
local KEEP_ROOT_MOTION=0 -- ERootMotionMode::NoRootMotionExtraction: the borrowed body moves as the montage does
|
||
local HOLD=1.0 -- seconds on the floor before an execution starts
|
||
local REACH=600 -- cm: the executor is the nearest enemy within this (the game's Combat point: 500)
|
||
local LOCK_REACH=2000 -- a locked boss waits for no one else, so its executor may come from further away
|
||
local TAIL=0.3 -- the run ends this long after the executor's clip
|
||
local AGAIN=15 -- seconds before a boss that survived an execution can be executed again
|
||
-- 雷当, 献祭之蛇's second phase and 冷荼 lock at the end of their fight with no pair to be executed by: in their own fight
|
||
-- a level script ends them, here nothing would and the fight could not finish. After this long on the death lock they are
|
||
-- ended the way that script does it (SpawnerToDieNS: the lock off, GE_Kill), unless they are out of reach by design.
|
||
local STUCK_SECONDS=20
|
||
local GAP=0.5 -- seconds between the presses the mod makes in a QTE execution
|
||
local PRESSES=30 -- presses before it stops waiting for the executed side's finale and plays it itself
|
||
local THRESHOLDS={'FirstThreshold','SecondThreshold','ThirdThreshold'}
|
||
local LOG_CAP=160
|
||
|
||
local function short(object)
|
||
if not U.valid(object) then return '?' end
|
||
local ok,name=pcall(function()return object:GetFName():ToString()end)
|
||
return ok and type(name)=='string' and name or '?'
|
||
end
|
||
local function className(actor)
|
||
if not U.valid(actor) then return '?' end
|
||
local ok,cls=pcall(function()return actor:GetClass()end)
|
||
return ok and (short(cls):gsub('_C$','')) or '?'
|
||
end
|
||
local function fmt(v)return type(v)=='number' and string.format('%.1f',v) or tostring(v) end
|
||
-- A TWeakObjectPtr property may come back as the object or as a wrapper with Get().
|
||
local function weak(value)
|
||
value=U.unwrap(value)
|
||
if U.key(value) then return value end
|
||
local ok,object=pcall(function()return value:Get()end)
|
||
return ok and U.valid(object) and object or nil
|
||
end
|
||
local function tickPoseOf(component)
|
||
local value=U.field(component,'bFollowerShouldTickPose')
|
||
if type(value)=='boolean' then return value end
|
||
if value==0 or value==1 then return value==1 end
|
||
end
|
||
|
||
function Exec.new(options)
|
||
local log=options.log or function()end
|
||
local stats=options.attributes or Stats.new()
|
||
local find=options.staticFind or function(path)return StaticFindObject(path)end
|
||
local load=options.loadAsset or function(path)return LoadAsset(path)end
|
||
local findAll=options.findAll or FindAllOf
|
||
local name=options.fname or FName
|
||
local now=options.now
|
||
local function paused()return options.paused and options.paused()==true end
|
||
local function inNativeExecution(actor)
|
||
if not options.nativeExecution then return false end
|
||
local ok,value=pcall(options.nativeExecution,actor)
|
||
return not ok or value~=false
|
||
end
|
||
local function phaseBusy(actor)
|
||
if not options.phaseBusy then return false end
|
||
local ok,value=pcall(options.phaseBusy,actor)
|
||
return not ok or value~=false
|
||
end
|
||
local data=options.data or require('execution_data')
|
||
-- The Hun body's switches (hun_look.lua) and its weapon's generic pairs (hun_execution_pairs.lua).
|
||
local hunSteps=options.hunSteps or require('hun_look').STEPS
|
||
local hunPairs=options.hunPairs or require('hun_execution_pairs')
|
||
local isHun=options.isHun
|
||
local directFailed={} -- executor key -> true: its own-mesh execution did not show, it borrows for this battle
|
||
local dataFold={};for key,value in pairs(data)do dataFold[key:lower()]=value end
|
||
local function animationData(key)return data[key] or dataFold[key:lower()]end
|
||
local poseProbe=PoseProbe.new({log=log,now=now,fname=name,staticFind=find})
|
||
local chain=Chain.new({log=log,fname=name,staticFind=find,loadAsset=load,findAll=findAll,getPlayer=options.getPlayer,getWorld=options.getWorld,
|
||
members=options.members,isImmortal=options.isImmortal,registerHook=options.registerHook,unregisterHook=options.unregisterHook,
|
||
health=function(actor)local value=stats:read(actor,'Health');return value and value.current end})
|
||
local self={enabled=options.enabled~=false,started=0,finished=0,failures=0,kills=0,message=''}
|
||
local policy=require('execution_policy').new({configured=options.executionPolicyConfigured,rule=options.executionPolicy,log=log,random=options.executionRandom,world=options.getWorld})
|
||
local units={} -- actor key -> {state='none'|'nopair'|'nodata'|'ready'|'done', pair, locks, timing, since, waited}
|
||
local humanoidLines=0
|
||
local tagRead=nil -- how the executable tags read back the first time, logged once
|
||
local active=nil
|
||
local grabPoses,pendingGrabControls={},{}
|
||
local finish
|
||
local callingNative=false
|
||
local pendingBodies={}
|
||
local lines=0
|
||
local function say(m)if lines<LOG_CAP then lines=lines+1;log('[Execution] '..m)end end
|
||
local function call(object,method,...)
|
||
if not U.valid(object) then return false,'对象无效' end
|
||
local n,args=select('#',...),{...}
|
||
return pcall(function()return object[method](object,table.unpack(args,1,n))end)
|
||
end
|
||
local function object(path)
|
||
local ok,found=pcall(find,path)
|
||
if ok and U.valid(found) then return found,'已加载' end
|
||
local loaded,value=pcall(load,path)
|
||
if loaded and U.valid(value) then return value,'LoadAsset' end
|
||
ok,found=pcall(find,path)
|
||
if ok and U.valid(found) then return found,'LoadAsset 后找到' end
|
||
return nil,'找不到'
|
||
end
|
||
local function read(actor,field)local v=stats:read(actor,field);return v and v.current or nil end
|
||
local function montageOf(actor)
|
||
local mesh=U.field(actor,'Mesh')
|
||
local ok,anim=call(mesh,'GetAnimInstance')
|
||
anim=ok and U.unwrap(anim) or nil
|
||
local got,montage=call(anim,'GetCurrentActiveMontage')
|
||
montage=got and U.unwrap(montage) or nil
|
||
return U.valid(montage) and short(montage) or nil
|
||
end
|
||
local function distance(a,b)
|
||
local okA,pa=pcall(options.getLocation,a);local okB,pb=pcall(options.getLocation,b)
|
||
if not okA or not okB or not pa or not pb then return nil end
|
||
local dx,dy,dz=pa.X-pb.X,pa.Y-pb.Y,pa.Z-pb.Z
|
||
return math.sqrt(dx*dx+dy*dy+dz*dz)
|
||
end
|
||
|
||
-- A unit's lock effects (its config's passive *LockHealth* effects) and its execution pair, with the executor's clip,
|
||
-- lengths and camera from execution_data.lua.
|
||
local function tagsMatch(actor,container,required)
|
||
for _,t in ipairs(U.array(U.struct(container,'GameplayTags')) or U.array(container) or {}) do
|
||
local ok,n=pcall(function()return t:ToString()end)
|
||
local gameTag=type(t)=='string' and {TagName=name(t)} or (U.struct(t,'TagName') and t or {TagName=ok and name(n) or t})
|
||
local got,count=call(U.field(actor,'AbilitySystemComponent'),'GetGameplayTagCount',gameTag)
|
||
count=got and U.unwrap(count) or nil
|
||
if type(count)~='number' or (required and count<=0) or (not required and count>0) then return false end
|
||
end
|
||
return true
|
||
end
|
||
local function ruleAllows(actor,rule,role,knownLionFloor)
|
||
if not rule then return true end
|
||
if not tagsMatch(actor,rule[role..'_required'],true) or not tagsMatch(actor,rule[role..'_ignored'],false) then return false end
|
||
if role=='target' and not knownLionFloor and #(rule.any_target or {})>0 then
|
||
for _,t in ipairs(rule.any_target)do if tagsMatch(actor,{t},true)then return true end end
|
||
return false
|
||
end
|
||
return true
|
||
end
|
||
local function inspect(actor,checkConditions,locked,knownLionFloor)
|
||
local info={state='none',locks={}}
|
||
local config=U.field(actor,'Actor Config')
|
||
if not U.valid(config) then return info end
|
||
local actorClass=className(actor)
|
||
info.prologue=actorClass=='BP_Monster_ZuoShang'
|
||
local rank=U.struct(U.field(config,'Difficulty Tag'),'TagName')
|
||
local okRank,text=pcall(function()return rank:ToString()end)
|
||
info.rank=okRank and type(text)=='string' and text:gsub('^CharacterType%.Difficulty%.','') or '?'
|
||
info.boss=info.rank:find('Boss$')~=nil
|
||
info.mob=info.rank=='Mob' or info.rank=='Standard' or info.rank=='Elite'
|
||
for _,ge in ipairs(U.array(U.field(config,'Passive GameplayEffects')) or {}) do
|
||
if U.valid(ge) and short(ge):find('LockHealth',1,true) then info.locks[#info.locks+1]=ge end
|
||
end
|
||
local execution,executed,source,missing
|
||
local entries=U.array(U.field(config,'TargetExecutionAnims')) or {}
|
||
for _,wanted in ipairs(TYPES) do
|
||
for _,entry in ipairs(entries) do
|
||
local tag=U.struct(U.struct(entry,'ExecutionType'),'TagName')
|
||
local ok,text=pcall(function()return tag:ToString()end)
|
||
local a,b=U.struct(entry,'ExecutionAbility'),U.struct(entry,'ExecutedAbility')
|
||
local eligible=true
|
||
if checkConditions and ok and text==wanted then
|
||
eligible=tagsMatch(actor,U.struct(entry,'TargetRequiredTags'),true) and tagsMatch(actor,U.struct(entry,'TargetIgnoredTags'),false)
|
||
if knownLionFloor then
|
||
eligible=eligible and wanted=='Execution.Type.Combat' and short(a)==LION_EXEC and short(b)==LION_VICTIM
|
||
end
|
||
if locked and wanted=='Execution.Type.Combat' then
|
||
-- A death floor can supply the opening, but cannot change a general's execution channel.
|
||
eligible=eligible and tagsMatch(actor,GENERALS,false)
|
||
else
|
||
eligible=eligible and ruleAllows(actor,Rules[wanted],'target',knownLionFloor)
|
||
end
|
||
if CONTEXTUAL[wanted] then
|
||
local readType,hasType=call(U.field(actor,'Execution Component'),'HasExecutionType',{TagName=name(wanted)})
|
||
eligible=eligible and readType and U.unwrap(hasType)==true
|
||
-- These points are serialized even for an unmounted spearman. The rider/cart actions
|
||
-- dereference the current vehicle, so a static point alone is not a mounted opportunity.
|
||
if wanted=='Execution.Type.CombatRider' then
|
||
local driver=U.field(actor,'BP_SGameDriverComponent')
|
||
if not U.valid(driver) then local got,found=call(actor,'GetDriverComponent');driver=got and U.unwrap(found) end
|
||
eligible=eligible and U.valid(U.field(driver,'DrivingVehicle'))
|
||
end
|
||
end
|
||
end
|
||
if ok and text==wanted and U.valid(a) and U.valid(b) and eligible then
|
||
if animationData(short(a)) then execution,executed,source=a,b,'配置 TargetExecutionAnims '..text;info.executionType=text;break end
|
||
missing=missing or a
|
||
end
|
||
end
|
||
if execution then break end
|
||
end
|
||
if not execution and missing and not PAIRS[actorClass] then info.state='nodata';info.pair={execution=missing};return info end
|
||
local known=not execution and PAIRS[actorClass] or nil
|
||
if known then
|
||
local why1,why2
|
||
execution,why1=object(known.execution);executed,why2=object(known.executed)
|
||
source='BOSS 自己的收尾技能(执行方 '..why1..',被处决方 '..why2..')'
|
||
for _,path in ipairs(known.locks or {}) do
|
||
local ge=object(path)
|
||
if ge then info.locks[#info.locks+1]=ge end
|
||
end
|
||
end
|
||
if not (U.valid(execution) and U.valid(executed)) then info.state='nopair';return info end
|
||
-- A move that writes story progress (story_writes.lua) only when that progress is already there.
|
||
if options.storyAllows then
|
||
local allowed,why=options.storyAllows(execution)
|
||
if not allowed then info.state='story';info.storyWhy=why;info.pair={execution=execution,executed=executed,source=source};return info end
|
||
end
|
||
info.timing=animationData(short(execution))
|
||
if not info.timing then info.state='nodata';info.pair={execution=execution};return info end
|
||
info.state='ready'
|
||
info.pair={execution=execution,executed=executed,source=source,start=known and known.start,unlock=known and known.unlock,type=info.executionType}
|
||
if info.executionType and info.executionType~='Execution.Type.Combat' then
|
||
for _,point in ipairs(U.array(U.field(config,'Execution Target Points')) or {})do
|
||
local tagName=U.struct(U.struct(point,'ExecutionTag'),'TagName')
|
||
local got,text=pcall(function()return tagName:ToString()end)
|
||
if type(tagName)=='string' then got,text=true,tagName end
|
||
local radius=U.struct(point,'Radius')
|
||
if got and text==info.executionType and type(radius)=='number' and radius>0 then
|
||
info.pair.reach=math.min(1000,math.max(info.pair.reach or 0,radius))
|
||
end
|
||
end
|
||
end
|
||
-- A pair taken from the boss's own skill is its finisher (彭猛's last segment kills whatever its health): the
|
||
-- skill starts it on the lock, so that lock is its only trigger, not a break or a low-health mark.
|
||
info.lockOnly=known~=nil
|
||
return info
|
||
end
|
||
-- Sitting on a health lock: a Health_Min floor, the unit's known lock or one low enough to be a death lock.
|
||
local function onLock(actor,unit,hp)
|
||
local floor=read(actor,'Health_Min')
|
||
if not floor or floor<=0 or hp>floor+1+floor*0.01 then return false end
|
||
return #unit.locks>0 or floor<=DEATH_LOCK*(read(actor,'Health_Max') or 0)+1
|
||
end
|
||
-- The verified wave applies GE_LockHealthButCanExecuted, which captures 1% of the
|
||
-- summoner's Health_Max. The separate native Weak tag uses 20% of the cub's own health.
|
||
local function lastLionFloor(actor,hp,owner)
|
||
local floor=read(actor,'Health_Min')
|
||
if type(floor)~='number' or not (floor>0 and floor<math.huge) then return false,floor end
|
||
local tolerance=math.max(0.01,floor*0.000001)
|
||
if not (math.abs(hp-floor)<=tolerance) then return false,floor end
|
||
local ownerMax=U.valid(owner) and read(owner,'Health_Max')
|
||
if type(ownerMax)~='number' or not (ownerMax>0 and ownerMax<math.huge) then return false,floor,nil,true end
|
||
local expected=ownerMax*LION_FLOOR_FRACTION
|
||
return math.abs(floor-expected)<=tolerance,floor,expected,true
|
||
end
|
||
-- CharacterState.CanWeakExecute.* the player's execution prompt waits for, read with GetGameplayTagCount.
|
||
local function executable(actor)
|
||
local asc=U.field(actor,'AbilitySystemComponent')
|
||
for _,tag in ipairs(EXECUTABLE) do
|
||
local ok,count=call(asc,'GetGameplayTagCount',{TagName=name(tag)})
|
||
count=ok and U.unwrap(count) or nil
|
||
if not tagRead then
|
||
tagRead=true
|
||
say('读处决标签 '..tag..' 单位='..className(actor)..' 调用='..tostring(ok)..' 读回='..tostring(count))
|
||
end
|
||
if type(count)=='number' and count>0 then return tag end
|
||
end
|
||
end
|
||
local function isHumanoid(actor)
|
||
local ok,bone=call(U.field(actor,'Mesh'),'GetBoneIndex',name('pelvis'))
|
||
bone=ok and U.unwrap(bone) or nil
|
||
local yes=type(bone)=='number' and bone>=0
|
||
if humanoidLines<6 then
|
||
humanoidLines=humanoidLines+1
|
||
say('检查当前身体 '..className(actor)..' pelvis读回='..tostring(bone)..' 人形='..tostring(yes))
|
||
end
|
||
return yes
|
||
end
|
||
-- The profile's outgoing thresholds cap mod-initiated finishers, including weapon-pair fallbacks.
|
||
local function healthWindow(target)
|
||
local hp,max=read(target,'Health'),read(target,'Health_Max')
|
||
local ok,count=call(U.field(target,'AbilitySystemComponent'),'GetGameplayTagCount',{TagName=name('CharacterState.Stand.Break')})
|
||
count=ok and U.unwrap(count)
|
||
if type(hp)~='number' or not (hp>0 and hp<math.huge) or type(max)~='number'
|
||
or not (max>0 and max<math.huge) or type(count)~='number' or not (count>=0) then return false end
|
||
return hp/max,count>0
|
||
end
|
||
local function hunWithinLimit(actor,ratio,broken)
|
||
local profile=options.hunProfile and options.hunProfile(actor)
|
||
local field=broken and 'ExecutionExecutorBreakHealthThreshold' or 'ExecutionExecutorNormalHealthThreshold'
|
||
local limit=profile and profile.attributes and profile.attributes[field]
|
||
if limit==nil then limit=broken and 0.20 or 0.10 end
|
||
return ratio and type(limit)=='number' and limit>0 and limit<math.huge and ratio<=math.min(1,limit),limit
|
||
end
|
||
-- The nearest living enemy within reach; a locked boss takes anyone, any other target a humanoid only.
|
||
-- team: the target's arena team, or nil for a companion's foe, which only companions go for.
|
||
-- A helper the other side's boss brought out (member.aid, arena_controller.lua) does not finish anyone.
|
||
-- only: when given, a member it returns false for is not considered (the Hun weapon pairs take Hun bodies only).
|
||
local function opponent(target,team,reach,anyone,executionType,isMob,only)
|
||
local best,bestDistance,denied
|
||
local ratio,broken
|
||
for _,member in ipairs(options.members() or {}) do
|
||
local other=member.actor
|
||
local against
|
||
if team then against=(member.team=='blue' or member.team=='red') and member.team~=team
|
||
else against=member.team=='companion' and (not options.companionCanAct or options.companionCanAct(other)) end
|
||
if against and only and not only(other) then against=false end
|
||
if against and not member.reserve and not member.aid and U.valid(other) and not phaseBusy(other)
|
||
and not (options.onPole and options.onPole(other)) then
|
||
local hp=read(other,'Health')
|
||
local d=hp and hp>0 and distance(target,other)
|
||
if d and d<=reach and (not bestDistance or d<bestDistance) and (anyone or isHumanoid(other))
|
||
and (anyone or ruleAllows(other,Rules[executionType],'executor')) then
|
||
local eligible=true
|
||
if isHun and isHun(other) then
|
||
if ratio==nil then ratio,broken=healthWindow(target) end
|
||
local limit
|
||
eligible,limit=hunWithinLimit(other,ratio,broken)
|
||
if not eligible then
|
||
local record=units[U.key(target)]
|
||
if record and not record.hunLimitLogged then
|
||
record.hunLimitLogged=true
|
||
say('魂暂缓自动处决 执行方='..className(other)..' 目标='..className(target)..' 剩余血量比例='..tostring(ratio)
|
||
..' 破防='..tostring(broken)..' 配置上限='..tostring(limit))
|
||
end
|
||
end
|
||
end
|
||
if eligible then
|
||
if policy:allow(other,target,isMob)then best,bestDistance=other,d else denied=true end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
return best,bestDistance,denied
|
||
end
|
||
-- The executor faces its target before the call, as the game warps the player to; read back.
|
||
local function face(executor,target)
|
||
local okA,a=call(executor,'K2_GetActorLocation');local okB,b=call(target,'K2_GetActorLocation')
|
||
a,b=okA and U.unwrap(a),okB and U.unwrap(b)
|
||
local ax,ay,bx,by=U.struct(a,'X'),U.struct(a,'Y'),U.struct(b,'X'),U.struct(b,'Y')
|
||
if type(ax)~='number' or type(bx)~='number' or (ax==bx and ay==by) then return nil,'读不到双方位置,没转向' end
|
||
local yaw=math.deg(math.atan(by-ay,bx-ax))
|
||
local ok,err=call(executor,'K2_SetActorRotation',{Pitch=0,Yaw=yaw,Roll=0},false)
|
||
local okR,rotation=call(executor,'K2_GetActorRotation')
|
||
local after=okR and U.struct(U.unwrap(rotation),'Yaw')
|
||
local diff=type(after)=='number' and math.abs((after-yaw+180)%360-180) or nil
|
||
return yaw,string.format('转向目标 朝向=%.0f 调用=%s 读回=%s%s',yaw,tostring(ok),type(after)=='number' and string.format('%.0f',after) or '?',
|
||
ok and ((diff and diff<=2) and '' or '(没转过去)') or '('..tostring(err)..')')
|
||
end
|
||
|
||
-- Every skinned part the executor owns, with whom it follows.
|
||
local function partsOf(actor)
|
||
local list,owner,seen={},U.key(actor),{}
|
||
for _,kind in ipairs(MESH_KINDS) do
|
||
local ok,all=pcall(findAll,kind)
|
||
for _,comp in ipairs(ok and U.array(all) or {}) do
|
||
local key=U.key(comp)
|
||
if key and not seen[key] then
|
||
seen[key]=true
|
||
local got,o=call(comp,'GetOwner')
|
||
if got and U.key(U.unwrap(o))==owner then
|
||
list[#list+1]={comp=comp,cloth=kind=='ChaosClothComponent',leader=weak(U.field(comp,'LeaderPoseComponent')),
|
||
tickPose=tickPoseOf(comp)}
|
||
end
|
||
end
|
||
end
|
||
end
|
||
return list
|
||
end
|
||
-- The executor's Mesh and the parts that follow it.
|
||
local function meshesOf(actor,main)
|
||
local list={{comp=main,leader=weak(U.field(main,'LeaderPoseComponent')),tickPose=tickPoseOf(main)}}
|
||
for _,part in ipairs(partsOf(actor)) do
|
||
if U.key(part.comp)~=U.key(main) and part.leader and U.key(part.leader)==U.key(main) then list[#list+1]=part end
|
||
end
|
||
return list
|
||
end
|
||
-- Cloth and physics start over from the pose they now follow, instead of stretching from the old one.
|
||
local function settle(parts)
|
||
local cloth,meshes=0,0
|
||
for _,part in ipairs(parts) do
|
||
if part.cloth then
|
||
if call(part.comp,'ForceNextUpdateTeleportAndReset') then cloth=cloth+1 end
|
||
else
|
||
local a=call(part.comp,'ResetAnimInstanceDynamics',RESET_PHYSICS)
|
||
local b=call(part.comp,'ForceClothNextUpdateTeleportAndReset')
|
||
if a and b then meshes=meshes+1 end
|
||
end
|
||
end
|
||
return string.format('重置布料=%d 重置模型物理=%d',cloth,meshes)
|
||
end
|
||
local function bodyGone(body)
|
||
if not U.valid(body.comp) then return true end
|
||
local ok,dying=call(body.comp,'IsBeingDestroyed')
|
||
return ok and U.unwrap(dying)==true
|
||
end
|
||
|
||
local function fullNameOf(object)
|
||
local ok,value=call(object,'GetFullName')
|
||
value=ok and U.unwrap(value)
|
||
return type(value)=='string' and value or nil
|
||
end
|
||
|
||
local function sameExecutor(body)
|
||
return body.executorKey~=nil and U.key(body.executor)==body.executorKey
|
||
and (not body.executorName or fullNameOf(body.executor)==body.executorName)
|
||
end
|
||
|
||
local function ownsComponent(body,part)
|
||
if not part.key or U.key(part.comp)~=part.key then return false end
|
||
local ok,owner=call(part.comp,'GetOwner')
|
||
return ok and U.key(U.unwrap(owner))==body.executorKey and body.executorKey~=nil
|
||
and (not part.fullName or fullNameOf(part.comp)==part.fullName)
|
||
end
|
||
|
||
local function hideBody(comp)
|
||
call(comp,'SetVisibility',false,false)
|
||
call(comp,'SetHiddenInGame',true,false)
|
||
local ok,visible=call(comp,'IsVisible')
|
||
local hidden=U.field(comp,'bHiddenInGame')
|
||
return (ok and U.unwrap(visible)==false) or hidden==true or hidden==1
|
||
end
|
||
|
||
local function disposeBody(body)
|
||
if bodyGone(body) then pendingBodies[body.key]=nil;return true end
|
||
if not sameExecutor(body) or not ownsComponent(body,body) then return false end
|
||
-- This is the temporary pose driver. When the game cannot hide it, drop its
|
||
-- render asset before retrying removal. No NPC mesh or shared asset is edited.
|
||
if not hideBody(body.comp) then call(body.comp,'SetSkeletalMeshAsset',nil) end
|
||
call(body.comp,'K2_DestroyComponent',body.comp)
|
||
local gone=bodyGone(body)
|
||
if gone then pendingBodies[body.key]=nil
|
||
else
|
||
body.destroyAttempts=(body.destroyAttempts or 0)+1
|
||
body.destroyRetry=body.destroyAttempts<3 and now()+0.75*body.destroyAttempts or nil
|
||
pendingBodies[body.key]=body
|
||
end
|
||
return gone
|
||
end
|
||
|
||
local function borrowBody(executor,timing,legacy)
|
||
if not timing then return nil,'这对技能没有登记执行方动画' end
|
||
local mesh=U.field(executor,'Mesh')
|
||
if not U.valid(mesh) then return nil,'执行方没有 Mesh' end
|
||
local okBone,bone=call(mesh,'GetBoneIndex',name('pelvis'))
|
||
if not okBone or type(U.unwrap(bone))~='number' or U.unwrap(bone)<0 then return nil,'执行方不是人形骨架(没有 pelvis)' end
|
||
local montage,how=object(timing.clip)
|
||
if not montage then return nil,'执行方动画'..how end
|
||
local player=options.getPlayer and options.getPlayer() or nil
|
||
local okAsset,asset=call(U.field(player,'Mesh'),'GetSkeletalMeshAsset')
|
||
asset=okAsset and U.unwrap(asset) or nil
|
||
if not U.valid(asset) then return nil,'读不到玩家的模型' end
|
||
local skeleton=U.field(asset,'Skeleton')
|
||
if timing.same_skeleton then
|
||
local expected=U.key(U.field(montage,'Skeleton'))
|
||
if not expected or U.key(skeleton)~=expected then return nil,'被抓动画与借用骨架不匹配' end
|
||
end
|
||
local cls=object(MESH_CLASS)
|
||
if not cls then return nil,'找不到 SkeletalMeshComponent 类' end
|
||
local okAdd,comp=call(executor,'AddComponentByClass',cls,true,IDENTITY,false)
|
||
comp=okAdd and U.unwrap(comp) or nil
|
||
if not U.valid(comp) then return nil,'加组件失败: '..tostring(comp) end
|
||
local body={comp=comp,followers={},executor=executor,executorKey=U.key(executor),executorName=fullNameOf(executor),
|
||
main=mesh,key=U.key(comp),fullName=fullNameOf(comp)}
|
||
if not ownsComponent(body,body) then return nil,'借用组件归属未确认' end
|
||
local steps={}
|
||
local function step(label,ok,err)steps[#steps+1]=label..'='..tostring(ok)..(ok and '' or '('..tostring(err)..')')end
|
||
if not legacy and not hideBody(comp) then
|
||
body.restored=true
|
||
disposeBody(body)
|
||
return nil,'不能确认借用组件已隐藏'
|
||
end
|
||
step('挂到执行方模型',call(comp,'K2_AttachToComponent',mesh,name('None'),SNAP,SNAP,SNAP,false))
|
||
step('换玩家模型',call(comp,'SetSkeletalMeshAsset',asset))
|
||
step('隐藏时照样算骨骼',pcall(function()comp.VisibilityBasedAnimTickOption=TICK_REFRESH end))
|
||
if legacy then
|
||
step('兼容旧版隐藏调用',call(comp,'SetVisibility',false,false))
|
||
else
|
||
local hidden=hideBody(comp)
|
||
step('隐藏读回',hidden)
|
||
if not hidden then
|
||
body.restored=true
|
||
disposeBody(body)
|
||
return nil,'借用组件配置后显隐未确认'
|
||
end
|
||
end
|
||
step('播动画',call(comp,'PlayAnimation',montage,timing.loop==true))
|
||
if (timing.clip_from or 0)~=0 then
|
||
local set=call(comp,'SetPosition',timing.clip_from,false)
|
||
local got,at=call(comp,'GetPosition');at=got and U.unwrap(at)
|
||
local verified=set and type(at)=='number' and math.abs(at-timing.clip_from)<0.002
|
||
step('片段起点',verified,'读回='..tostring(at))
|
||
if not verified then return body,'动画片段起点写后读回失败' end
|
||
end
|
||
if (timing.rate or 1)~=1 then
|
||
local set=call(comp,'SetPlayRate',timing.rate)
|
||
local got,rate=call(comp,'GetPlayRate');rate=got and U.unwrap(rate)
|
||
local verified=set and rate==timing.rate
|
||
step('片段速率',verified,'读回='..tostring(rate))
|
||
if not verified then return body,'动画片段速率写后读回失败' end
|
||
end
|
||
local okAnim,anim=call(comp,'GetAnimInstance');anim=okAnim and U.unwrap(anim) or nil
|
||
local rootMotion=timing.ignoreRootMotion and 1 or KEEP_ROOT_MOTION
|
||
step('根运动模式',call(anim,'SetRootMotionMode',rootMotion))
|
||
if timing.ignoreRootMotion and tonumber((U.field(anim,'RootMotionMode')))~=rootMotion then
|
||
return body,'桩上动画根运动模式未读回'
|
||
end
|
||
for _,part in ipairs(meshesOf(executor,mesh)) do
|
||
-- Its rendered pose follows the player skeleton, but the primary mesh must still tick its native
|
||
-- montage so CharacterMovement/MotionWarping can advance. false froze it at 0 / StartTime in logs.
|
||
local primary=U.key(part.comp)==U.key(mesh)
|
||
local wantTick=primary or part.tickPose==true
|
||
local ok,err=call(part.comp,'SetLeaderPoseComponent',comp,true,wantTick)
|
||
local leader=weak(U.field(part.comp,'LeaderPoseComponent'))
|
||
local verified=ok and leader~=nil and U.key(leader)==U.key(comp)
|
||
body.followers[#body.followers+1]={comp=part.comp,key=U.key(part.comp),fullName=fullNameOf(part.comp),
|
||
leader=part.leader,cloth=part.cloth,verified=verified,tickPose=part.tickPose}
|
||
step('跟随['..short(part.comp)..(part.cloth and '(布料)' or '')..']',verified,
|
||
not ok and err or (leader==nil and '调用成功,读回不可读' or '读回不是借来的骨架'))
|
||
if primary then
|
||
local actual=tickPoseOf(part.comp)
|
||
step('原生动画更新',actual==true,'请求=true 读回='..tostring(actual))
|
||
say('主网格保留 TickPose:原值='..tostring(part.tickPose)..' 请求=true 读回='..tostring(actual))
|
||
end
|
||
end
|
||
body.copyFollowers=CopyPose.follow(partsOf(executor),mesh,comp,log)
|
||
for _,part in ipairs(body.copyFollowers) do
|
||
part.key,part.fullName=U.key(part.comp),fullNameOf(part.comp)
|
||
end
|
||
if #body.copyFollowers>0 then say('独立CopyPose部件改接数='..#body.copyFollowers..';执行方='..className(executor)) end
|
||
local followed=0;for _,f in ipairs(body.followers)do if f.verified then followed=followed+1 end end
|
||
local okPlaying,playing=call(comp,'IsPlaying')
|
||
say(string.format('借身体 执行方=%s 玩家模型=%s 骨架=%s 动画=%s(%s) 跟随=%d/%d 播放中=%s;%s;%s',className(executor),short(asset),short(skeleton),
|
||
short(montage),how,followed,#body.followers,tostring(okPlaying and U.unwrap(playing)),table.concat(steps,' '),settle(body.followers)))
|
||
if followed==0 then return body,'执行方的模型没有跟上借来的骨架' end
|
||
return body
|
||
end
|
||
local function returnBody(body)
|
||
if not body then return '没有借身体' end
|
||
local gone=bodyGone(body)
|
||
if not sameExecutor(body) or (not gone and not ownsComponent(body,body)) then
|
||
pendingBodies[body.key]=nil
|
||
return '借用组件或执行方归属已变化'
|
||
end
|
||
if body.restored then return '移除借来的骨架='..tostring(disposeBody(body)) end
|
||
if not gone then hideBody(body.comp) end
|
||
local back=0
|
||
for _,f in ipairs(body.followers) do
|
||
if ownsComponent(body,f) then
|
||
local leaderKey=U.key(weak(U.field(f.comp,'LeaderPoseComponent')))
|
||
local originalKey=U.key(f.leader)
|
||
-- The engine may have cleared an already removed leader. Restore our snapshot
|
||
-- in that case, but keep a distinct leader that another system has assigned.
|
||
if not leaderKey or leaderKey==body.key or leaderKey==originalKey then
|
||
local original=originalKey and f.leader or nil
|
||
local ok=call(f.comp,'SetLeaderPoseComponent',original,true,f.tickPose==true)
|
||
local leader=weak(U.field(f.comp,'LeaderPoseComponent'))
|
||
local actualTick=tickPoseOf(f.comp)
|
||
local tickRestored=f.tickPose==nil or actualTick==f.tickPose
|
||
if U.key(f.comp)==U.key(body.main) then
|
||
say('恢复主网格 TickPose:原值='..tostring(f.tickPose)..' 读回='..tostring(actualTick)..' 验证='..tostring(tickRestored))
|
||
end
|
||
if ok and tickRestored and U.key(leader)==originalKey then back=back+1 end
|
||
end
|
||
end
|
||
end
|
||
-- Anything still on the borrowed skeleton (the engine may hand a follower's followers to the new leader)
|
||
-- goes back to the executor's Mesh before that skeleton is removed.
|
||
local swept,parts=0,U.valid(body.executor) and partsOf(body.executor) or {}
|
||
for _,part in ipairs(parts) do
|
||
if not gone and part.leader and U.key(part.leader)==body.key and U.valid(body.main) then
|
||
if call(part.comp,'SetLeaderPoseComponent',body.main,true,false) then swept=swept+1 end
|
||
end
|
||
end
|
||
for _,part in ipairs(body.copyFollowers or {}) do
|
||
if not part.restored then
|
||
if not ownsComponent(body,part) then part.restored=true
|
||
else
|
||
local ok,parent=call(part.comp,'GetAttachParent')
|
||
local key=ok and U.key(U.unwrap(parent))
|
||
if key and key~=body.key and key~=U.key(part.parent) then part.restored=true end
|
||
end
|
||
end
|
||
end
|
||
if not CopyPose.restore(body.copyFollowers,log) then
|
||
pendingBodies[body.key]=body
|
||
return string.format('还原跟随=%d/%d;独立面部附着未恢复,保留借用骨架,等待停止/清场重试',back,#body.followers)
|
||
end
|
||
body.restored=true
|
||
local destroyed=disposeBody(body)
|
||
local settled=U.valid(body.executor) and settle(partsOf(body.executor)) or '执行方已失效'
|
||
return string.format('还原跟随=%d/%d 补回=%d 移除借来的骨架=%s %s',back,#body.followers,swept,tostring(destroyed),settled)
|
||
end
|
||
|
||
-- The skeleton of an actor's own Mesh asset, or nil.
|
||
local function meshSkeleton(actor)
|
||
local ok,asset=call(U.field(actor,'Mesh'),'GetSkeletalMeshAsset')
|
||
asset=ok and U.unwrap(asset) or nil
|
||
local skeleton=U.field(asset,'Skeleton')
|
||
return U.valid(skeleton) and skeleton or nil
|
||
end
|
||
-- An executor whose own mesh is on the skeleton of its clip (the Hun body) needs no borrowed body: the native
|
||
-- ability plays the montage on that mesh. Returns a text for the log when it applies, nil otherwise.
|
||
local function directBody(executor,timing)
|
||
if hunSteps.directExecution==false or not timing or not timing.clip then return nil end
|
||
if directFailed[U.key(executor) or ''] then return nil end
|
||
local skeleton=meshSkeleton(executor)
|
||
if not skeleton then return nil end
|
||
local clip=object(timing.clip)
|
||
local expected=clip and U.field(clip,'Skeleton')
|
||
if not U.valid(expected) or U.key(expected)~=U.key(skeleton) then return nil end
|
||
return string.format('执行方=%s 网格骨架=%s 动画=%s 骨架=%s',className(executor),short(skeleton),short(clip),short(expected))
|
||
end
|
||
-- 荒行子's C4 victim montages straight on a Hun body's own anim instance. Returns the hold, or nil and why
|
||
-- (nil and nil: not a Hun-skeleton victim, the borrowed body is used without a word).
|
||
local function playGuillotineOnSelf(actor)
|
||
if hunSteps.guillotineSelf==false then return nil end
|
||
local skeleton=meshSkeleton(actor)
|
||
if short(skeleton)~=GUILLOTINE_SELF.skeleton then return nil end
|
||
local start,finishMontage=object(GUILLOTINE_SELF.start),object(GUILLOTINE_SELF.finish)
|
||
if not start or not finishMontage then return nil,'受害方蒙太奇没载入' end
|
||
if U.key(U.field(start,'Skeleton'))~=U.key(skeleton) then return nil,'蒙太奇骨架与受害方网格骨架不同' end
|
||
local okAnim,anim=call(U.field(actor,'Mesh'),'GetAnimInstance');anim=okAnim and U.unwrap(anim) or nil
|
||
if not U.valid(anim) then return nil,'受害方没有动画实例' end
|
||
local played,err=call(anim,'Montage_Play',start,1.0,0,0.0,true)
|
||
local _,current=call(anim,'GetCurrentActiveMontage');current=U.unwrap(current)
|
||
local _,playing=call(anim,'Montage_IsPlaying',start)
|
||
local _,position=call(anim,'Montage_GetPosition',start)
|
||
position=U.unwrap(position)
|
||
local detail=string.format('受害方=%s 本体播放=%s 读回蒙太奇=%s 播放中=%s 位置=%s',className(actor),tostring(played),
|
||
U.valid(current) and short(current) or '无',tostring(U.unwrap(playing)),fmt(position))
|
||
if played and U.valid(current) and U.key(current)==U.key(start) and U.unwrap(playing)==true then
|
||
return {anim=anim,start=start,finish=finishMontage},detail
|
||
end
|
||
call(anim,'Montage_Stop',0.0,start)
|
||
return nil,detail..(played and '' or '('..tostring(err)..')')
|
||
end
|
||
-- Ends the start montage of a hold that never reached its finish (released early); a finish is left to play out.
|
||
local function stopSelfPlay(pose)
|
||
local own=pose.self
|
||
if pose.finishingAt then return '本体收尾蒙太奇保留' end
|
||
local stopped=call(own.anim,'Montage_Stop',0.2,own.start)
|
||
local _,playing=call(own.anim,'Montage_IsPlaying',own.start)
|
||
local _,rate=call(own.anim,'Montage_GetPlayRate',own.start)
|
||
return string.format('本体起手蒙太奇停止=%s 读回播放中=%s 速率=%s',tostring(stopped),tostring(U.unwrap(playing)),tostring(U.unwrap(rate)))
|
||
end
|
||
|
||
-- Temporary presentation for the pole controller. Combat, targeting and input remain on the NPC.
|
||
function self:borrowPolePose(actor,clip,looping)
|
||
if active or next(grabPoses) or next(pendingBodies) then return nil end
|
||
local mesh=U.field(actor,'Mesh')
|
||
if not U.valid(mesh) or U.valid(weak(U.field(mesh,'LeaderPoseComponent'))) then return nil end
|
||
local body,why=borrowBody(actor,{clip=clip,same_skeleton=true,loop=looping,ignoreRootMotion=true})
|
||
if not body then return nil end
|
||
if why or U.key(weak(U.field(body.main,'LeaderPoseComponent')))~=body.key then
|
||
returnBody(body)
|
||
return nil
|
||
end
|
||
local pose={}
|
||
function pose:position()
|
||
if not body or U.key(weak(U.field(body.main,'LeaderPoseComponent')))~=body.key then return nil end
|
||
local ok,value=call(body.comp,'GetPosition')
|
||
return ok and type(value)=='number' and value or nil
|
||
end
|
||
function pose:play(nextClip,loop)
|
||
if not body or U.key(weak(U.field(body.main,'LeaderPoseComponent')))~=body.key then return false end
|
||
local asset=object(nextClip)
|
||
local _,mesh=call(body.comp,'GetSkeletalMeshAsset')
|
||
local expected=U.key(U.field(mesh,'Skeleton'))
|
||
if not expected or U.key(U.field(asset,'Skeleton'))~=expected then return false end
|
||
if not call(body.comp,'PlayAnimation',asset,loop==true) then return false end
|
||
local _,anim=call(body.comp,'GetAnimInstance')
|
||
-- The capsule follows the swept jump. Extract the animation's root without moving the mesh twice.
|
||
call(anim,'SetRootMotionMode',1)
|
||
local read=U.struct(U.field(body.comp,'AnimationData'),'AnimToPlay')
|
||
return U.key(read)==U.key(asset) and tonumber((U.field(anim,'RootMotionMode')))==1
|
||
and select(2,call(body.comp,'IsPlaying'))==true
|
||
end
|
||
function pose:stop()
|
||
if not body then return true end
|
||
returnBody(body)
|
||
if pendingBodies[body.key] then return false end
|
||
body=nil
|
||
return true
|
||
end
|
||
return pose
|
||
end
|
||
|
||
local function brainPaused(brain)
|
||
local ok,paused=call(brain,'IsPaused')
|
||
if not ok then return nil end
|
||
paused=U.unwrap(paused)
|
||
if type(paused)=='boolean' then return paused end
|
||
end
|
||
local function setBrainPause(brain,on,reason)
|
||
local okLib,lib=pcall(find,AI_LIBRARY)
|
||
local ok,err=call(okLib and lib or nil,on and 'PauseLogic' or 'ResumeLogic',brain,reason)
|
||
local paused=brainPaused(brain)
|
||
return ok and paused==on,string.format('%s=%s 读回暂停=%s%s',on and '暂停AI' or '恢复AI',
|
||
tostring(ok),tostring(paused),ok and '' or '('..tostring(err)..')')
|
||
end
|
||
local function holdAI(actor,on)
|
||
local brain=U.field(U.field(actor,'Controller'),'BrainComponent')
|
||
if not U.valid(brain) then return false,'读不到 AI 大脑' end
|
||
return setBrainPause(brain,on,PAUSE_REASON)
|
||
end
|
||
local function moveMode(component)
|
||
return tonumber((U.field(component,'MovementMode'))),tonumber((U.field(component,'CustomMovementMode')))
|
||
end
|
||
local function hitState(component)
|
||
local ok,state=call(component,'GetCurrentHitState')
|
||
local tag=ok and U.struct(state,'TagName')
|
||
if type(tag)=='string' then return tag end
|
||
local named,text=pcall(function()return tag:ToString()end)
|
||
return named and text or nil
|
||
end
|
||
local function restoreGrabControl(control)
|
||
local outcomes={}
|
||
if control.changedMode then
|
||
if not U.valid(control.movement) then
|
||
control.changedMode=false
|
||
else
|
||
local mode=moveMode(control.movement)
|
||
if mode and mode~=MOVE_NONE then
|
||
control.changedMode=false
|
||
outcomes[#outcomes+1]='移动已由游戏更新='..mode
|
||
else
|
||
local set=call(control.movement,'SetMovementMode',control.mode,control.custom)
|
||
local after,custom=moveMode(control.movement)
|
||
control.changedMode=not (after==control.mode and custom==control.custom)
|
||
outcomes[#outcomes+1]='恢复移动='..tostring(set)..' 读回='..tostring(after)..'/'..tostring(custom)
|
||
end
|
||
end
|
||
end
|
||
if control.changedHitState then
|
||
local current=hitState(control.hitreact)
|
||
if not U.valid(control.hitreact) or (current and current~='CharacterState.Hitreact.State.Custom') then
|
||
control.changedHitState=false
|
||
elseif current then
|
||
call(control.hitreact,'ChangeHitState',{TagName=name(control.hitState)},nil,false)
|
||
control.changedHitState=hitState(control.hitreact)~=control.hitState
|
||
end
|
||
outcomes[#outcomes+1]='恢复受击状态='..tostring(not control.changedHitState)
|
||
end
|
||
if control.changedPause then
|
||
local hp=U.valid(control.actor) and read(control.actor,'Health')
|
||
if not U.valid(control.brain) or (type(hp)=='number' and hp<=0) or brainPaused(control.brain)==false then
|
||
control.changedPause=false
|
||
else
|
||
local resumed,detail=setBrainPause(control.brain,false,GUILLOTINE_PAUSE)
|
||
control.changedPause=not resumed
|
||
outcomes[#outcomes+1]=detail
|
||
end
|
||
end
|
||
local restored=not control.changedMode and not control.changedPause and not control.changedHitState
|
||
pendingGrabControls[control.movementKey]=not restored and control or nil
|
||
return restored,#outcomes>0 and table.concat(outcomes,';') or '控制状态已恢复'
|
||
end
|
||
local function grabControlHeld(actor,control)
|
||
return U.key(U.field(actor,'CharacterMovement'))==control.movementKey
|
||
and U.key(U.field(U.field(actor,'Controller'),'BrainComponent'))==control.brainKey
|
||
and brainPaused(control.brain)==true and moveMode(control.movement)==MOVE_NONE
|
||
end
|
||
local function beginGrabControl(actor)
|
||
local brain=U.field(U.field(actor,'Controller'),'BrainComponent')
|
||
local movement=U.field(actor,'CharacterMovement')
|
||
local brainKey,movementKey=U.key(brain),U.key(movement)
|
||
local paused,mode,custom=brainPaused(brain),moveMode(movement)
|
||
if not brainKey or not movementKey or paused==nil or mode==nil or custom==nil then
|
||
return nil,'读不到目标的 AI 暂停或移动模式'
|
||
end
|
||
local control={actor=actor,brain=brain,brainKey=brainKey,movement=movement,movementKey=movementKey,mode=mode,custom=custom}
|
||
if not paused then
|
||
control.changedPause=true
|
||
local ok,why=setBrainPause(brain,true,GUILLOTINE_PAUSE)
|
||
if not ok then
|
||
local _,restored=restoreGrabControl(control)
|
||
return nil,why..';'..restored
|
||
end
|
||
end
|
||
if mode~=MOVE_NONE then
|
||
control.changedMode=true
|
||
call(movement,'SetMovementMode',MOVE_NONE,0)
|
||
end
|
||
local hitreact=U.field(actor,'Hitreact Component')
|
||
local oldHit=hitState(hitreact)
|
||
if oldHit and oldHit~='CharacterState.Hitreact.State.Custom' then
|
||
control.hitreact,control.hitState,control.changedHitState=hitreact,oldHit,true
|
||
call(hitreact,'ChangeHitState',{TagName=name('CharacterState.Hitreact.State.Custom')},nil,false)
|
||
local afterHit=hitState(hitreact)
|
||
say('血滴子原版受击状态 '..className(actor)..' '..oldHit..' -> '..tostring(afterHit))
|
||
if afterHit~='CharacterState.Hitreact.State.Custom' then
|
||
restoreGrabControl(control)
|
||
return nil,'原版自定义受击状态未读回'
|
||
end
|
||
end
|
||
if not grabControlHeld(actor,control) then
|
||
local _,restored=restoreGrabControl(control)
|
||
return nil,'定身未读回;'..restored
|
||
end
|
||
say('血滴子控制开始 '..className(actor)..' 读回暂停=true 移动=0 原移动='..mode..'/'..custom)
|
||
return control
|
||
end
|
||
local function stopGrabAction(actor)
|
||
-- A paused brain does not cancel a strike that was already animating.
|
||
local asc=U.field(actor,'AbilitySystemComponent')
|
||
local ability=weak(U.struct(U.field(asc,'LocalAnimMontageInfo'),'AnimatingAbility'))
|
||
if U.field(ability,'bIsActive')~=true then return true end
|
||
local tags=U.array(U.struct(U.field(ability,'AbilityTags'),'GameplayTags'))
|
||
for _,tag in ipairs(tags or {})do
|
||
local tagName=U.struct(tag,'TagName')
|
||
local ok,text=pcall(function()return tagName:ToString()end)
|
||
if ok and type(text)=='string' and (text=='Ability.Action' or text:sub(1,15)=='Ability.Action.') then
|
||
local got,avatar=call(ability,'GetAvatarActorFromActorInfo')
|
||
if not got or U.key(U.unwrap(avatar))~=U.key(actor) then return false end
|
||
local cancelled=call(ability,'K2_CancelAbility')
|
||
local inactive=not U.valid(ability) or U.field(ability,'bIsActive')==false
|
||
say('血滴子中止目标出招 '..short(ability)..' 调用='..tostring(cancelled)..' 读回结束='..tostring(inactive))
|
||
return cancelled and inactive
|
||
end
|
||
end
|
||
return true
|
||
end
|
||
|
||
local function closeOneGrab(pose,why,restore)
|
||
grabPoses[pose.targetKey]=nil
|
||
if pose.handle then pcall(pose.cancel,pose.handle) end
|
||
if not restore then return false,'未在游戏线程恢复控制' end
|
||
local bodyBack=pose.body and returnBody(pose.body) or pose.self and stopSelfPlay(pose) or '沿用原骨架'
|
||
local restored,detail=restoreGrabControl(pose.control)
|
||
say(string.format('血滴子控制结束(%s)片段读回=%.3f;%s;%s',tostring(why or '停止'),pose.position,bodyBack,detail))
|
||
return restored and (not pose.body or pendingBodies[pose.body.key]==nil),detail
|
||
end
|
||
local function closeGrabPose(why,restore,actor)
|
||
if actor then
|
||
local key=U.key(actor)
|
||
local pose=key and grabPoses[key]
|
||
if not pose then
|
||
for _,other in pairs(grabPoses)do if other.actor==actor then pose=other;break end end
|
||
end
|
||
if pose then return closeOneGrab(pose,why,restore) end
|
||
for _,control in pairs(pendingGrabControls)do
|
||
if control.actor==actor then return restore and restoreGrabControl(control) end
|
||
end
|
||
return true
|
||
end
|
||
local complete=true
|
||
for _,pose in pairs(grabPoses)do if not closeOneGrab(pose,why,restore) then complete=false end end
|
||
if restore then
|
||
for _,control in pairs(pendingGrabControls)do if not restoreGrabControl(control) then complete=false end end
|
||
end
|
||
return complete
|
||
end
|
||
|
||
function self:stopGrabPose(why,actor)
|
||
return closeGrabPose(why,true,actor)
|
||
end
|
||
local function validGrabTarget(stillValid)
|
||
local ok,valid=pcall(stillValid)
|
||
return ok and valid==true
|
||
end
|
||
function self:guillotineHeld(actor)
|
||
local pose=grabPoses[U.key(actor)]
|
||
if not pose or not validGrabTarget(pose.stillValid) then return false,false end
|
||
local hp=read(actor,'Health')
|
||
local deathVisual=pose.finishingAt~=nil and type(hp)=='number' and hp<=0
|
||
if not deathVisual and not grabControlHeld(actor,pose.control) then return false,false end
|
||
if pose.body and (not U.valid(pose.body.comp)
|
||
or U.key(weak(U.field(pose.body.main,'LeaderPoseComponent')))~=pose.body.key) then return false,false end
|
||
if pose.self and not U.valid(pose.self.anim) then return false,false end
|
||
return true,pose.stage==#GUILLOTINE_POSES
|
||
end
|
||
local function advanceGrabPose(pose)
|
||
local stage=GUILLOTINE_POSES[pose.stage+1]
|
||
if pose.self then
|
||
-- The finish montage carries both of its segments and rates; play it in place of the start.
|
||
local own=pose.self
|
||
local played=call(own.anim,'Montage_Play',own.finish,1.0,0,0.0,true)
|
||
local _,current=call(own.anim,'GetCurrentActiveMontage');current=U.unwrap(current)
|
||
local _,position=call(own.anim,'Montage_GetPosition',own.finish)
|
||
local verified=played and U.valid(current) and U.key(current)==U.key(own.finish)
|
||
say(string.format('铡刀本体后半段 播放=%s 读回蒙太奇=%s 位置=%s 验证=%s',tostring(played),U.valid(current) and short(current) or '无',
|
||
fmt(U.unwrap(position)),tostring(verified)))
|
||
if not verified then return false end
|
||
pose.stage=pose.stage+1
|
||
return true
|
||
end
|
||
if not pose.body then pose.stage=pose.stage+1;return true end
|
||
local comp=pose.body.comp
|
||
local moved=call(comp,'SetPosition',stage.from,false)
|
||
local rated=call(comp,'SetPlayRate',stage.rate)
|
||
local gotPosition,position=call(comp,'GetPosition')
|
||
local gotRate,rate=call(comp,'GetPlayRate')
|
||
position=gotPosition and U.unwrap(position)
|
||
rate=gotRate and U.unwrap(rate)
|
||
if not moved or not rated or type(position)~='number' or position~=position
|
||
or math.abs(position-stage.from)>0.002 or rate~=stage.rate then return false end
|
||
pose.position=position
|
||
pose.stage=pose.stage+1
|
||
say(string.format('血滴子受击片段=%d 读回位置=%.3f 速率=%s',pose.stage,position,tostring(rate)))
|
||
return true
|
||
end
|
||
function self:finishGuillotineHold(actor)
|
||
local pose=grabPoses[U.key(actor)]
|
||
if not pose then return false,'受抓控制未读回' end
|
||
if pose.finishingAt then return true end
|
||
pose.finishingAt=now()
|
||
if not self:guillotineHeld(actor) then pose.finishingAt=nil;return false,'受抓收尾状态未读回' end
|
||
if not advanceGrabPose(pose) then pose.finishingAt=nil;return false,'原版后半段起点或速率未读回' end
|
||
return true,'原版受抓收尾已启动'
|
||
end
|
||
function self:startGuillotineHold(actor,stillValid)
|
||
if phaseBusy(actor) then return false,'原生阶段正在配对,保留当前动作' end
|
||
local targetKey=U.key(actor)
|
||
local conflict=active and (U.key(active.executor)==targetKey or U.key(active.boss)==targetKey)
|
||
if not targetKey or conflict or grabPoses[targetKey] or next(pendingBodies) then return false,'目标已有抓取或处决' end
|
||
local loop=options.loop or LoopInGameThreadWithDelay
|
||
local cancel=options.cancel or CancelDelayedAction
|
||
if type(loop)~='function' or type(cancel)~='function' or not validGrabTarget(stillValid) then return false,'目标或游戏线程计时器未就绪' end
|
||
local started=now()
|
||
if type(started)~='number' then return false,'抓取时间未读回' end
|
||
local control,why=beginGrabControl(actor)
|
||
if not control then return false,why end
|
||
if not stopGrabAction(actor) then
|
||
restoreGrabControl(control)
|
||
return false,'目标当前招式未确认已中断'
|
||
end
|
||
local own,selfWhy=playGuillotineOnSelf(actor)
|
||
if not own and selfWhy then say('铡刀本体播放没成,退回借身体:'..selfWhy) end
|
||
local body,bodyWhy
|
||
if not own then
|
||
body,bodyWhy=borrowBody(actor,GUILLOTINE_GRAB)
|
||
if body then
|
||
local _,playing=call(body.comp,'IsPlaying')
|
||
if bodyWhy or U.key(weak(U.field(body.main,'LeaderPoseComponent')))~=body.key or playing~=true then
|
||
returnBody(body)
|
||
body=nil
|
||
end
|
||
end
|
||
end
|
||
local pose={actor=actor,body=body,self=own,control=control,cancel=cancel,started=started,position=0,stage=1,
|
||
targetKey=targetKey,stillValid=stillValid}
|
||
grabPoses[targetKey]=pose
|
||
local ok,handle=pcall(loop,16,function()
|
||
if grabPoses[targetKey]~=pose then return end
|
||
if not self:guillotineHeld(actor) then closeOneGrab(pose,'目标或控制状态变化',true);return end
|
||
local time=now()
|
||
if type(time)~='number' or time<pose.started or time-pose.started>=GUILLOTINE_TIMEOUT then
|
||
closeOneGrab(pose,'抓取更新超时',true);return
|
||
end
|
||
if own then
|
||
if pose.stage==1 then
|
||
local read,position=call(own.anim,'Montage_GetPosition',own.start)
|
||
position=read and U.unwrap(position)
|
||
if type(position)~='number' or position~=position then closeOneGrab(pose,'本体动画位置未读回',true);return end
|
||
pose.position=position
|
||
-- The original start montage waits for the 0.9 s native commit before its finish montage.
|
||
if not pose.waiting and position>=GUILLOTINE_SELF.catch then
|
||
call(own.anim,'Montage_SetPlayRate',own.start,0)
|
||
local _,rate=call(own.anim,'Montage_GetPlayRate',own.start)
|
||
if U.unwrap(rate)~=0 then closeOneGrab(pose,'本体起手等待帧未读回',true);return end
|
||
pose.waiting=true
|
||
say(string.format('铡刀本体起手停在 位置=%.3f 速率读回=0',position))
|
||
end
|
||
elseif pose.finishingAt and time-pose.finishingAt>=GUILLOTINE_SELF.finishLength then
|
||
pose.stage=#GUILLOTINE_POSES
|
||
end
|
||
return
|
||
end
|
||
if not body then
|
||
if pose.finishingAt and time-pose.finishingAt>=3.788884 then pose.stage=#GUILLOTINE_POSES end
|
||
return
|
||
end
|
||
local read,position=call(body.comp,'GetPosition')
|
||
if not read or type(position)~='number' or position~=position then closeOneGrab(pose,'动画位置未读回',true);return end
|
||
pose.position=position
|
||
if pose.stage==1 then
|
||
-- The original start montage waits for the 0.9 s native commit before its finish montage.
|
||
if not pose.waiting and position>=0.54 then
|
||
call(body.comp,'SetPosition',0.54,false)
|
||
call(body.comp,'SetPlayRate',0)
|
||
local _,heldPosition=call(body.comp,'GetPosition')
|
||
local _,heldRate=call(body.comp,'GetPlayRate')
|
||
if type(heldPosition)~='number' or math.abs(heldPosition-0.54)>0.002 or heldRate~=0 then
|
||
closeOneGrab(pose,'起手等待帧未读回',true)
|
||
return
|
||
end
|
||
pose.waiting=true
|
||
end
|
||
else
|
||
local stage=GUILLOTINE_POSES[pose.stage]
|
||
if stage.limit and position>=stage.limit-0.001 and not advanceGrabPose(pose) then
|
||
closeOneGrab(pose,'下一段动画未读回',true)
|
||
end
|
||
end
|
||
end)
|
||
if not ok or handle==nil or handle==false then
|
||
closeOneGrab(pose,'动画任务未登记',true)
|
||
return false,'动画任务未登记'
|
||
end
|
||
if grabPoses[targetKey]~=pose then pcall(cancel,handle);return false,'目标在接管时离场' end
|
||
pose.handle=handle
|
||
say('血滴子受抓开始 '..className(actor)..' 控制读回=true 原版动画='..tostring(body~=nil or own~=nil)..(own and ' 本体播放' or '')..' '..tostring(bodyWhy or ''))
|
||
if own then return true,selfWhy end
|
||
return true
|
||
end
|
||
|
||
local function ascOf(actor)
|
||
local asc=U.field(actor,'AbilitySystemComponent')
|
||
if U.valid(asc) then return asc end
|
||
local okLib,lib=pcall(find,ABILITY_LIBRARY)
|
||
local got,found=call(okLib and lib or nil,'GetAbilitySystemComponent',actor)
|
||
return got and U.unwrap(found) or nil
|
||
end
|
||
local troopFloor='/PBZCombatAsset/ActorData/Mobs/035_HuaShan/GameplayEffects/GE_HuaShan_Troop_MinHealth.GE_HuaShan_Troop_MinHealth_C'
|
||
local function hasTroopProtection(actor)
|
||
local id=className(actor)
|
||
if id~='BP_Monster_HuaShan_Blue' and id~='BP_Monster_HuaShan_JianOu' then return false end
|
||
local ok,effect=pcall(find,troopFloor)
|
||
if not ok or not U.valid(effect) then return false end
|
||
local read,count=call(ascOf(actor),'GetGameplayEffectCount',effect,nil,true)
|
||
count=read and U.unwrap(count)
|
||
return type(count)~='number' or count>0
|
||
end
|
||
-- The unit's own lock effects, then the generic ones that are loaded, each removed once; read back as Health_Min.
|
||
local function unlock(actor,info)
|
||
local asc=ascOf(actor)
|
||
local list,seen,removed={},{},{}
|
||
for _,ge in ipairs(info.locks) do list[#list+1]=ge end
|
||
for _,path in ipairs(GENERIC_LOCKS) do
|
||
local ok,ge=pcall(find,path)
|
||
if ok and U.valid(ge) then list[#list+1]=ge end
|
||
end
|
||
for _,ge in ipairs(list) do
|
||
local key=U.key(ge)
|
||
if key and not seen[key] then
|
||
seen[key]=true
|
||
removed[#removed+1]=short(ge)..'='..tostring((call(asc,'RemoveActiveGameplayEffectBySourceEffect',ge,nil,-1)))
|
||
end
|
||
end
|
||
return asc,removed,read(actor,'Health_Min')
|
||
end
|
||
-- Removing a final floor may succeed even when GE_Kill does not. Keep that narrow
|
||
-- completion request until health confirms death, with live identity and phase checks.
|
||
local companionFoes
|
||
local function finisherTeam(target)
|
||
local key=U.key(target)
|
||
if not key then return nil end
|
||
local members=options.members() or {}
|
||
for _,m in ipairs(members)do
|
||
if U.key(m.actor)==key and not m.stand and not m.reserve and not m.aid
|
||
and (m.team=='red' or m.team=='blue') then return m.team end
|
||
end
|
||
for _,foe in ipairs(companionFoes(members))do if foe.key==key then return 'companion-foe' end end
|
||
end
|
||
local function finalDeath(target,unit,t,mode,team)
|
||
-- Temporary execution and squad effects can be low enough to resemble a death floor.
|
||
if paused() or inNativeExecution(target) or hasTroopProtection(target) then return nil end
|
||
if options.immune and options.immune(target,'lethal') then return nil end
|
||
local hp,floor,max=read(target,'Health'),read(target,'Health_Min'),read(target,'Health_Max')
|
||
local r=unit.finalDeath
|
||
if r and r.mode~=mode then return nil end
|
||
local key=U.key(target)
|
||
local named,identity=call(target,'GetFullName')
|
||
local worldKey=options.getWorld and U.key(options.getWorld())or nil
|
||
local finite=function(n)return type(n)=='number'and n==n and n~=math.huge and n~=-math.huge end
|
||
if not named or type(identity)~='string' or options.getWorld and not worldKey then return nil end
|
||
if r and (r.key~=key or identity~=r.name or r.world~=worldKey)then
|
||
unit.finalDeath=nil;return nil
|
||
end
|
||
if not finite(hp)or not finite(floor)or max~=nil and(not finite(max)or max<0)then return nil end
|
||
max=max or 0
|
||
local ceiling=r and r.floorLimit or DEATH_LOCK*max+1
|
||
if r and (hp>r.limit or floor>ceiling)then unit.finalDeath=nil;return nil end
|
||
if r and hp<=0 then
|
||
unit.finalDeath=nil;unit.state='done'
|
||
if r.attempted then self.kills=self.kills+1 end
|
||
return nil
|
||
end
|
||
if hp<=0 or floor>ceiling then return nil end
|
||
if not r then
|
||
r={key=key,name=named and identity or nil,world=worldKey,limit=floor+1+floor*.01,nextAt=0,mode=mode,team=team}
|
||
unit.finalDeath=r
|
||
end
|
||
if t<r.nextAt then return nil end
|
||
r.nextAt=t+1
|
||
local function authorized()
|
||
if units[key]~=unit or unit.finalDeath~=r or phaseBusy(target) or inNativeExecution(target)
|
||
or hasTroopProtection(target) or options.immune and options.immune(target,'lethal')
|
||
or options.isImmortal and options.isImmortal(r.team) then return false end
|
||
if mode=='finish' or mode=='denied' then
|
||
if finisherTeam(target)~=r.team or (r.team~='companion-foe' and options.fighting and not options.fighting()) then return false end
|
||
if mode=='denied' then
|
||
local executor,_,denied=opponent(target,r.team,LOCK_REACH,true,'Execution.Type.Combat',true)
|
||
if executor or not denied then unit.finalDeath=nil;return false end
|
||
end
|
||
end
|
||
return true
|
||
end
|
||
if not authorized() then return nil end
|
||
local asc,removed,after
|
||
if floor>0 then asc,removed,after=unlock(target,unit)
|
||
else asc,removed,after=ascOf(target),{},floor end
|
||
local currentHP=read(target,'Health')
|
||
if not finite(after)or after>ceiling or not finite(currentHP)or currentHP<=0 or currentHP>r.limit or phaseBusy(target)then return nil end
|
||
local ge=object(GE_KILL)
|
||
local checked,currentName=call(target,'GetFullName')
|
||
if U.key(target)~=r.key or r.name and(not checked or currentName~=r.name)
|
||
or options.getWorld and U.key(options.getWorld())~=r.world then return nil end
|
||
local stillMember=r.team=='companion-foe' and finisherTeam(target)==r.team
|
||
if not stillMember then
|
||
for _,member in ipairs(options.members()or{})do
|
||
if U.key(member.actor)==r.key and member.team==r.team and not member.stand
|
||
and not(r.mode=='stuck'and member.untargetable)then stillMember=true;break end
|
||
end
|
||
end
|
||
local liveHP,liveFloor=read(target,'Health'),read(target,'Health_Min')
|
||
if not authorized() or not stillMember or not finite(liveHP)or liveHP<=0 or liveHP>r.limit
|
||
or not finite(liveFloor)or liveFloor>ceiling or phaseBusy(target)
|
||
or options.isImmortal and options.isImmortal(r.team)
|
||
or r.mode=='stuck'and options.fighting and not options.fighting()
|
||
or r.mode=='card'and options.killOnLock and not options.killOnLock(target)then return nil end
|
||
local applied,err=false,'没有 GE_Kill'
|
||
if ge then
|
||
applied,err=call(asc,'BP_ApplyGameplayEffectToSelf',ge,0.0,{})
|
||
r.attempted=r.attempted or applied
|
||
end
|
||
local remaining=read(target,'Health')
|
||
if r.attempted and units[key]==unit and unit.finalDeath==r and finite(remaining)and remaining<=0 then
|
||
unit.finalDeath=nil;unit.state='done';self.kills=self.kills+1
|
||
end
|
||
return {removed=removed,after=after,applied=applied,err=err,hp=remaining}
|
||
end
|
||
-- The prologue's grab can leave its final 4% floor active in the arena. Release only that effect after a stall.
|
||
local function releasePrologueFloor(actor,unit,t)
|
||
local hp,floor,max=read(actor,'Health'),read(actor,'Health_Min'),read(actor,'Health_Max')
|
||
if not hp or hp<=0 or not floor or floor<=0 or not max or max<=0
|
||
or math.abs(floor-max*0.04)>0.1 or math.abs(hp-floor)>0.1 then
|
||
unit.prologueSince=nil
|
||
return
|
||
end
|
||
unit.prologueSince=unit.prologueSince or t
|
||
if t-unit.prologueSince<STUCK_SECONDS then return end
|
||
if options.nativeExecution and options.nativeExecution(actor)~=false then return end
|
||
unit.prologueSince=t
|
||
local effect=object(PROLOGUE_FINAL_LOCK)
|
||
local asc=ascOf(actor)
|
||
local got,before=false,nil
|
||
if U.valid(effect) then got,before=call(asc,'GetGameplayEffectCount',effect,nil,true) end
|
||
before=got and U.unwrap(before) or nil
|
||
local removed,afterCount=false,nil
|
||
if type(before)=='number' and before>0 then
|
||
removed=call(asc,'RemoveActiveGameplayEffectBySourceEffect',effect,nil,-1)
|
||
if U.valid(effect) then
|
||
local checked,count=call(asc,'GetGameplayEffectCount',effect,nil,true)
|
||
afterCount=checked and U.unwrap(count) or nil
|
||
end
|
||
end
|
||
local afterFloor=read(actor,'Health_Min')
|
||
local verified=afterCount==0 and afterFloor~=nil and afterFloor<floor-0.1
|
||
log(string.format('[Execution] 序章左殇 4%% 血线停滞 %d 秒:效果=%s 移除调用=%s 效果读回=%s 血量下限=%s→%s HP读回=%s 验证=%s',
|
||
STUCK_SECONDS,tostring(before),tostring(removed),tostring(afterCount),fmt(floor),fmt(afterFloor),fmt(read(actor,'Health')),tostring(verified)))
|
||
end
|
||
-- An actor's active instance of an (instanced) ability class.
|
||
local function abilityOn(actor,cls)
|
||
if not U.valid(actor) then return nil end
|
||
local ok,all=pcall(findAll,cls)
|
||
for _,ability in ipairs(ok and U.array(all) or {}) do
|
||
local got,avatar=call(ability,'GetAvatarActorFromActorInfo')
|
||
if got and U.key(U.unwrap(avatar))==U.key(actor) and U.field(ability,'bIsActive')~=false then return ability end
|
||
end
|
||
end
|
||
|
||
local function executionInfo(actor)
|
||
local info=U.field(U.field(actor,'Execution Component'),'CurrentExecutionInfo')
|
||
if info==nil then return '读不到' end
|
||
local target=weak(U.struct(info,'Target'));local executor=weak(U.struct(info,'Executor'))
|
||
return string.format('执行方=%s 目标=%s 是目标=%s',className(executor),className(target),tostring(U.struct(info,'IsTarget')))
|
||
end
|
||
|
||
-- A QTE execution's presses (see the header): own and theirs are the executor's and the executed side's ability.
|
||
local function setupMash(executor,boss,info)
|
||
local stages=info.timing.stages
|
||
local m={spec=info.timing.mash,stages=stages,cameras=info.timing.cameras,presses=0,next=stages.open.length,clips={},thresholds={},
|
||
ownClass=short(info.pair.execution),theirClass=short(info.pair.executed)}
|
||
m.own,m.theirs=abilityOn(executor,m.ownClass),abilityOn(boss,m.theirClass)
|
||
local loaded={}
|
||
for _,key in ipairs({'hit','finale'}) do
|
||
local clip,how=object(stages[key].clip)
|
||
m.clips[key]=clip;loaded[#loaded+1]=key..'='..how
|
||
end
|
||
for i,field in ipairs(THRESHOLDS) do
|
||
local v=U.field(m.own,field)
|
||
if type(v)~='number' then v=U.field(m.theirs,field) end
|
||
m.thresholds[i]=type(v)=='number' and v or nil
|
||
end
|
||
say(string.format('QTE 处决由 Mod 代按:%.2fs 起每 %.1f 秒一下,%s 发给玩家的能力系统(被处决方在那儿听);执行方技能=%s 被处决方技能=%s 门槛=%s/%s/%s 动画[%s]',
|
||
m.next,GAP,m.spec.event,m.own and '找到' or '没找到',m.theirs and '找到' or '没找到',tostring(m.thresholds[1]),
|
||
tostring(m.thresholds[2]),tostring(m.thresholds[3]),table.concat(loaded,' ')))
|
||
return m
|
||
end
|
||
-- The hit the executor plays on press c, picked as the executed side picks its own (GA_GuiChai_Red_P2_BEd_01).
|
||
local function hitTimeline(m,c)
|
||
local hit,th=m.spec.hit,m.thresholds
|
||
if not (th[1] and th[2] and th[3]) then return hit[1] end
|
||
if c<th[1] then return hit[1] elseif c<th[2] then return hit[2] end
|
||
if not m.transition then m.transition=true;return hit[3] end
|
||
return hit[4]
|
||
end
|
||
-- The executor's ability plays a timeline, its borrowed body that stage's clip and the camera that stage's track.
|
||
local function stage(run,key,timeline)
|
||
poseProbe:sample('before:'..timeline)
|
||
local m=run.mash
|
||
local played=m.own~=nil and (call(m.own,'PlayTimelineByName',name(timeline),1.0,0.0,0.0))
|
||
local swapped=run.body~=nil and m.clips[key]~=nil and (call(run.body.comp,'PlayAnimation',m.clips[key],false))
|
||
poseProbe:sample('after-call:'..timeline)
|
||
-- Each hit timeline has its own camera track.
|
||
local track=(m.cameras and m.cameras[timeline]) or m.stages[key].camera
|
||
if options.camera and options.camera.stage and track then
|
||
local ok,err=pcall(options.camera.stage,options.camera,track,timeline)
|
||
if not ok then say('处决镜头换段出错:'..tostring(err)) end
|
||
end
|
||
return string.format('执行方技能 %s=%s 借来的骨架换动画=%s',timeline,tostring(played),tostring(swapped))
|
||
end
|
||
local function press(run,t)
|
||
local m=run.mash
|
||
m.presses=m.presses+1;m.next=t+GAP
|
||
-- The abilities may only be live a frame after the call.
|
||
local late=''
|
||
if not m.own then m.own=abilityOn(run.executor,m.ownClass);if m.own then late=late..' 执行方技能这时才找到' end end
|
||
if not m.theirs then m.theirs=abilityOn(run.boss,m.theirClass);if m.theirs then late=late..' 被处决方技能这时才找到' end end
|
||
for i,field in ipairs(THRESHOLDS) do
|
||
if not m.thresholds[i] then
|
||
local v=U.field(m.own,field)
|
||
if type(v)~='number' then v=U.field(m.theirs,field) end
|
||
m.thresholds[i]=type(v)=='number' and v or nil
|
||
end
|
||
end
|
||
local key,timeline,line
|
||
if run.fell then
|
||
key,timeline,line='finale',m.spec.finale,string.format('目标已倒下,执行方直接收尾 %.1fs',t)
|
||
else
|
||
local before=U.field(m.theirs,'ClickCount')
|
||
local okLib,lib=pcall(find,ABILITY_LIBRARY)
|
||
local player=options.getPlayer and options.getPlayer() or nil
|
||
local tag={TagName=name(m.spec.event)}
|
||
local sent,err=call(okLib and lib or nil,'SendGameplayEventToActor',player,tag,{EventTag=tag,Instigator=run.executor,Target=run.boss})
|
||
local after=U.field(m.theirs,'ClickCount')
|
||
local counted=type(before)=='number' and type(after)=='number' and after>before
|
||
local montage=montageOf(run.boss)
|
||
local finale=counted and (montage==m.spec.executed_finale or (m.thresholds[3]~=nil and after>=m.thresholds[3]))
|
||
local direct=''
|
||
if not counted then
|
||
-- The event did not reach it: its timeline is played directly, picked by the mod's own count.
|
||
local th=m.thresholds[3]
|
||
local last=m.presses>=PRESSES or (th and m.presses>=th)
|
||
local own=last and m.spec.finale or hitTimeline(m,m.presses)
|
||
finale=last
|
||
direct=string.format(';事件没算上,被处决方直接播 %s=%s',own,tostring((call(m.theirs,'PlayTimelineByName',name(own),1.0,0.0,0.0))))
|
||
timeline=own
|
||
elseif m.presses>=PRESSES and not finale then
|
||
finale=true
|
||
direct=string.format(';按满 %d 下还没进结局,被处决方直接播 %s=%s',PRESSES,m.spec.finale,
|
||
tostring((call(m.theirs,'PlayTimelineByName',name(m.spec.finale),1.0,0.0,0.0))))
|
||
end
|
||
key=finale and 'finale' or 'hit'
|
||
timeline=finale and m.spec.finale or timeline or hitTimeline(m,after)
|
||
line=string.format('代按第 %d 下 %.1fs:事件=%s%s 被处决方计数 %s→%s 目标动作=%s%s%s',m.presses,t,tostring(sent),
|
||
sent and '' or '('..tostring(err)..')',tostring(before),tostring(after),tostring(montage),direct,late)
|
||
end
|
||
local played=stage(run,key,timeline)
|
||
if key=='finale' then
|
||
m.finale=t;run.length=t+m.stages.finale.length+TAIL
|
||
say(string.format('%s;进结局,%s,%.1fs 后结束',line,played,m.stages.finale.length+TAIL))
|
||
elseif m.presses<=3 or m.presses%5==0 then
|
||
say(line..';'..played)
|
||
end
|
||
end
|
||
-- An ability the run left active is cancelled, read back.
|
||
local function release(run)
|
||
local m=run.mash
|
||
local own=(m and m.own) or run.own or abilityOn(run.executor,short(run.info.pair.execution))
|
||
local theirs=(m and m.theirs) or run.theirs or abilityOn(run.boss,short(run.info.pair.executed))
|
||
local parts={}
|
||
for _,side in ipairs({{'执行方',own,run.executor},{'被处决方',theirs,run.boss}}) do
|
||
local ability=side[2]
|
||
local got,avatar=call(ability,'GetAvatarActorFromActorInfo')
|
||
if U.valid(ability) and U.valid(side[3]) and got and U.key(U.unwrap(avatar))==U.key(side[3]) and U.field(ability,'bIsActive')~=false then
|
||
local ok=call(ability,'K2_CancelAbility')
|
||
parts[#parts+1]=string.format('%s技能还在,取消=%s 读回仍在=%s',side[1],tostring(ok),tostring(U.field(ability,'bIsActive')))
|
||
end
|
||
end
|
||
if m then return string.format(';QTE 代按 %d 下 %s%s',m.presses,m.finale and '进了结局' or '没进结局',#parts>0 and ','..table.concat(parts,',') or '') end
|
||
return #parts>0 and ';本次普通处决收尾 '..table.concat(parts,',') or ''
|
||
end
|
||
|
||
local function showCamera(run,timing,continuing)
|
||
if not options.camera then return end
|
||
local shown,err=pcall(options.camera.begin,options.camera,{executor=run.executor,target=run.boss,
|
||
ability=short(run.info.pair.execution),body=run.body and run.body.comp or nil,yaw=run.yaw,camera=timing.camera,
|
||
clip_from=timing.clip_from or 0,rate=timing.rate or 1,timeline_start=timing.start or 0,continuing=continuing})
|
||
if not shown then say('处决镜头出错:'..tostring(err)) end
|
||
end
|
||
local function start(executor,boss,info,d,reason,adopted)
|
||
if phaseBusy(executor) or phaseBusy(boss) then return false end
|
||
local lionPickup
|
||
if short(info.pair.execution)==LION_EXEC then
|
||
local enabled
|
||
if options.hunPoleHead then enabled=options.hunPoleHead(executor) end
|
||
if enabled==false then return false end
|
||
lionPickup=options.lionPickup and options.lionPickup(executor,boss)
|
||
if (enabled==true or info.requireLionPickup) and not lionPickup then return false end
|
||
end
|
||
local unit=units[U.key(boss)]
|
||
local previousState=unit and unit.state
|
||
if unit and not adopted then unit.state='playing' end
|
||
self.started=self.started+1
|
||
local hp,floor=read(boss,'Health'),read(boss,'Health_Min')
|
||
local finishPermit
|
||
if not info.requireLionPickup and (info.mob or info.boss and reason=='卡在锁血线') then
|
||
local named,identity=call(boss,'GetFullName')
|
||
local team=finisherTeam(boss)
|
||
if team and named and type(identity)=='string' and type(hp)=='number' and type(floor)=='number' then
|
||
local key=U.key(boss)
|
||
if not unit then unit=inspect(boss);units[key]=unit end
|
||
finishPermit={mode='finish',actor=boss,key=key,name=identity,team=team,
|
||
world=options.getWorld and U.key(options.getWorld()),limit=hp+0.01,floorLimit=floor+0.01,nextAt=0}
|
||
if options.getWorld and not finishPermit.world then finishPermit=nil end
|
||
end
|
||
end
|
||
local yaw,turned
|
||
if adopted then
|
||
local got,rotation=call(executor,'K2_GetActorRotation')
|
||
yaw=got and U.struct(U.unwrap(rotation),'Yaw') or 0;turned='沿用原生处决朝向'
|
||
else yaw,turned=face(executor,boss) end
|
||
say(string.format('开始(%s)目标=%s HP=%s 底线=%s 执行方=%s 距离=%.1fm 技能对=%s / %s 来源=%s;%s',reason,className(boss),fmt(hp),fmt(floor),
|
||
className(executor),(d or 0)/100,short(info.pair.execution),short(info.pair.executed),info.pair.source,turned))
|
||
local wantPlayback=info.timing.dynamic or (adopted and not info.timing.mash and info.timing.montage~=nil)
|
||
local body,why,legacy
|
||
if type(options.legacyBorrowedAppearance)=='function' then
|
||
local ok,enabled=pcall(options.legacyBorrowedAppearance)
|
||
if ok and enabled==true then
|
||
local side,other=finisherTeam(executor),finisherTeam(boss)
|
||
legacy=(side=='blue' and other=='red') or (side=='red' and other=='blue')
|
||
end
|
||
end
|
||
local direct=not wantPlayback and directBody(executor,info.timing) or nil
|
||
if direct then say('同骨架,直接用本体(不借身体,不算失败):'..direct)
|
||
elseif not wantPlayback then body,why=borrowBody(executor,info.timing,legacy) end
|
||
poseProbe:begin(executor,boss,body and body.comp or nil)
|
||
if why then say('借身体没成,执行方原地站着:'..why) end
|
||
local executorBefore=direct and montageOf(executor) or nil
|
||
local paused,held
|
||
if adopted and adopted.paused then paused,held=true,'沿用上段由Mod持有的AI暂停'
|
||
else
|
||
local got,wasPaused=call(U.field(U.field(executor,'Controller'),'BrainComponent'),'IsPaused')
|
||
if got and U.unwrap(wasPaused)==true then paused,held=false,'AI原本已暂停,结束时保留原状态'
|
||
else paused,held=holdAI(executor,true) end
|
||
end
|
||
local before=montageOf(boss)
|
||
local component=U.field(executor,'Execution Component')
|
||
chain:begin(executor,boss,info.pair.execution)
|
||
local ok,err=true,'接到原生调用,只接管表现,不重复播放技能'
|
||
if not adopted then
|
||
callingNative=true
|
||
ok,err=call(component,'PlayExactExecution',{ExecutionAbility=info.pair.execution,ExecutedAbility=info.pair.executed},boss,info.pair.start or 0.0)
|
||
callingNative=false
|
||
end
|
||
poseProbe:sample('after-PlayExactExecution')
|
||
say(string.format('调用 PlayExactExecution=%s %s;%s;执行方组件:%s;目标组件:%s;目标动作=%s 执行方动作=%s',tostring(ok),ok and '' or tostring(err),
|
||
held,executionInfo(executor),executionInfo(boss),tostring(montageOf(boss)),tostring(montageOf(executor))))
|
||
if not ok then
|
||
if lionPickup then options.lionPickupEnded(executor,false) end
|
||
self.failures=self.failures+1
|
||
chain:stop('PlayExactExecution failed')
|
||
poseProbe:stop('PlayExactExecution failed')
|
||
local resumed=paused and select(2,holdAI(executor,false)) or '没有暂停 AI'
|
||
if unit and unit.state=='playing' then unit.state=previousState;unit.again=now()+AGAIN end
|
||
say('没能开始:'..returnBody(body)..';'..resumed);self.message='调用失败';return false
|
||
end
|
||
-- The executor's clip plays to its end, past the target's fall: the game's execution does too.
|
||
local offset=info.counterTime or 0
|
||
local length=math.max(0,(info.timing.executor or 120)-offset)+TAIL
|
||
if offset>0 and body then
|
||
local position=(info.timing.clip_from or 0)+math.max(0,offset-(info.timing.start or 0))*(info.timing.rate or 1)
|
||
call(body.comp,'SetPosition',position,false)
|
||
end
|
||
local after=montageOf(boss)
|
||
if not info.fieldLionHead and info.pair.unlock=='start' then
|
||
local _,removed,floor=unlock(boss,info)
|
||
say(string.format('照它自己的技能,处决一开始就去锁血[%s] 读回底线=%s',table.concat(removed,' '),fmt(floor)))
|
||
end
|
||
local mash=info.timing.mash and setupMash(executor,boss,info) or nil
|
||
if mash then length=mash.next+PRESSES*GAP+info.timing.stages.finale.length+TAIL end
|
||
active={executor=executor,boss=boss,info=info,body=body,t0=now(),length=length,before=before,mash=mash,yaw=yaw,
|
||
finishPermit=finishPermit,unitAtStart=unit,previousState=previousState,
|
||
dynamic=wantPlayback,adopted=adopted~=nil,lionPickup=lionPickup,legacyBorrow=legacy,
|
||
own=abilityOn(executor,short(info.pair.execution)),theirs=abilityOn(boss,short(info.pair.executed)),
|
||
montage=after~=before and after or nil,gone=nil,samples=0,paused=paused,byLock=reason=='卡在锁血线',
|
||
direct=direct~=nil,executorBefore=executorBefore}
|
||
if adopted and after and not active.montage then
|
||
local readMontage,native=call(active.theirs,'GetCurrentMontage')
|
||
if readMontage and U.valid(U.unwrap(native)) and short(U.unwrap(native))==after then active.montage=after end
|
||
end
|
||
self.message='处决中:'..className(executor)..' → '..className(boss)
|
||
local run=active
|
||
if run.direct then
|
||
local expected=info.timing.montage and info.timing.montage:match('%.([^%.]+)$') or nil
|
||
run.directExpected=expected
|
||
local seen=montageOf(executor)
|
||
if seen and (expected and seen==expected or not expected and seen~=executorBefore) then
|
||
run.directSeen=true
|
||
say('同骨架直播读回 执行方动作='..seen..' 期望='..tostring(expected)..' 用时=0.0s')
|
||
end
|
||
end
|
||
if run.dynamic then
|
||
local variants=info.timing.variants or {[info.timing.montage:match('%.([^%.]+)$')]=info.timing}
|
||
run.playback=Playback.start({actor=executor,variants=variants,now=now,loop=options.loop,cancel=options.cancel,
|
||
ability=function()run.own=run.own or abilityOn(executor,short(info.pair.execution));return run.own end,
|
||
onVariant=function(def,key,position)
|
||
if not run.body and (run.direct or not run.directChecked) then
|
||
run.directChecked=true
|
||
local same=directBody(executor,def)
|
||
if same then
|
||
run.direct,run.directSeen=true,true
|
||
say(string.format('同骨架,直接用本体(动态分支,不借身体):%s 读回原生蒙太奇=%s 原生位置=%.3f',same,key,position))
|
||
showCamera(run,def,adopted and adopted.continuing)
|
||
return true
|
||
end
|
||
end
|
||
if not run.body then
|
||
local b,problem=borrowBody(executor,def,run.legacyBorrow);run.body=b
|
||
if problem then return false,problem end
|
||
showCamera(run,def,adopted and adopted.continuing)
|
||
else
|
||
local clip=object(def.clip)
|
||
if not clip or not call(run.body.comp,'PlayAnimation',clip,false) then return false,'切换片段失败' end
|
||
local got,anim=call(run.body.comp,'GetAnimInstance')
|
||
call(got and U.unwrap(anim),'SetRootMotionMode',KEEP_ROOT_MOTION)
|
||
showCamera(run,def,true)
|
||
end
|
||
local set=call(run.body.comp,'SetPlayRate',0)
|
||
local got,rate=call(run.body.comp,'GetPlayRate');rate=got and U.unwrap(rate)
|
||
if not set or rate~=0 then return false,'未能交给原生时间驱动:'..tostring(rate) end
|
||
say(string.format('动态分支 读回原生蒙太奇=%s 时间轴=%s 原生位置=%.3f 片段起点=%.3f',key,def.timeline,position,def.clip_from or 0))
|
||
return true
|
||
end,
|
||
onPosition=function(desired,position,def)
|
||
-- On its own mesh the native montage is the animation; there is no borrowed clip to place.
|
||
if run.direct and not run.body then return true end
|
||
local ok=call(run.body and run.body.comp,'SetPosition',desired,false)
|
||
local got,actual=call(run.body and run.body.comp,'GetPosition');actual=got and U.unwrap(actual)
|
||
return ok and type(actual)=='number' and math.abs(actual-desired)<0.003,'要求='..desired..' 读回='..tostring(actual)
|
||
end,
|
||
onEnd=function(why,failed)if active==run then finish(why,failed) end end})
|
||
else
|
||
if adopted and run.body and U.valid(run.own) then
|
||
local gm,montage=call(run.own,'GetCurrentMontage')
|
||
local ga,anim=call(U.field(executor,'Mesh'),'GetAnimInstance')
|
||
montage=gm and U.unwrap(montage)
|
||
local gp,position=false,nil
|
||
if U.valid(montage) then gp,position=call(ga and U.unwrap(anim),'Montage_GetPosition',montage) end
|
||
position=gp and U.unwrap(position)
|
||
if type(position)=='number' and position>=0 then
|
||
call(run.body.comp,'SetPosition',(info.timing.clip_from or 0)+position*(info.timing.rate or 1),false)
|
||
run.length=math.max(0,info.timing.executor-position)+TAIL
|
||
end
|
||
end
|
||
showCamera(run,info.timing,adopted and adopted.continuing)
|
||
end
|
||
end
|
||
local function endCamera(why)
|
||
if not options.camera then return end
|
||
local ok,err=pcall(options.camera.finish,options.camera,why)
|
||
if not ok then say('处决镜头收尾出错:'..tostring(err)) end
|
||
end
|
||
|
||
-- keep: the boss never started its side, so it is not ended either (no bare "down at the lock").
|
||
local function resume(run)
|
||
if not run.paused then return '没有暂停 AI' end
|
||
if not U.valid(run.executor) then return '执行方已失效,不恢复 AI' end
|
||
return select(2,holdAI(run.executor,false))
|
||
end
|
||
finish=function(why,keep,handoff)
|
||
local run=active;active=nil
|
||
if run.playback then run.playback:stop() end
|
||
poseProbe:stop(why)
|
||
if not handoff then endCamera(why) end
|
||
chain:closeTasks()
|
||
local released=not handoff and release(run) or ';旧技能由原生切换处理'
|
||
chain:stop(why)
|
||
local back=returnBody(run.body)..';'..(handoff and 'AI暂停交给下一段' or resume(run))..released
|
||
if run.targetPaused then
|
||
run.targetPaused=nil
|
||
back=back..';目标'..(U.valid(run.boss) and select(2,holdAI(run.boss,false)) or '已失效,不恢复 AI')
|
||
end
|
||
local boss=run.boss
|
||
local hp=U.valid(boss) and read(boss,'Health') or nil
|
||
if run.unitAtStart and run.unitAtStart.state=='playing' then
|
||
run.unitAtStart.state=hp and hp<=0 and 'done' or run.previousState
|
||
run.unitAtStart.again=now()+AGAIN
|
||
end
|
||
local kill='目标已倒下或失效'
|
||
if handoff then
|
||
kill='转交原生下一段,不对旧目标额外判死'
|
||
elseif keep then
|
||
self.failures=self.failures+1
|
||
kill=#run.info.locks>0 and '没有处决起来,保留锁血' or '没有处决起来'
|
||
elseif hp and hp>0 and options.immune and options.immune(boss,'lethal') then
|
||
kill='魂的方案免疫强制致死,生命读回 '..fmt(hp)
|
||
local unit=units[U.key(boss)]
|
||
if unit and not run.adopted then unit.state=run.info.hunPair and run.previousState or 'ready';unit.again=now()+AGAIN end
|
||
elseif hp and hp>0 and run.info.boss and not run.byLock then
|
||
-- A boss may have another phase: it stays, and may be executed again a little later.
|
||
local unit=units[U.key(boss)]
|
||
-- A Hun weapon pair is not the target's own: a target with none goes back to having none, for the Hun to try again.
|
||
if unit and not run.adopted then unit.state=run.info.hunPair and run.previousState or 'ready';unit.since=nil;unit.waited=nil;unit.again=now()+AGAIN end
|
||
if run.adopted then kill='原生BOSS处决结束,保留后续阶段 HP='..fmt(hp)
|
||
else kill=string.format('BOSS(%s)处决完还站着,不强制判死,%d 秒后可再被处决 HP=%s',run.info.rank,AGAIN,fmt(hp)) end
|
||
elseif run.info.requireLionPickup and (hp==nil or hp>0) then
|
||
kill='狮头处决保留原生结算;HP读回='..fmt(hp)
|
||
elseif (hp==nil or hp>0) and (run.info.mob or run.info.boss and run.byLock) then
|
||
local permit,unit=run.finishPermit,run.unitAtStart
|
||
kill='处决动画结束;强制收尾条件未确认'
|
||
if permit and units[permit.key]==unit and not phaseBusy(boss) and finisherTeam(boss)==permit.team then
|
||
unit.finalDeath=permit
|
||
local result=finalDeath(boss,unit,now(),'finish',permit.team)
|
||
if result then
|
||
kill=string.format('%s(%s):去锁血[%s] 读回底线=%s;GE_Kill=%s 读回HP=%s',run.info.boss and '锁血 BOSS 收尾' or '小怪处决完还站着,判死',
|
||
run.info.rank,table.concat(result.removed,' '),fmt(result.after),tostring(result.applied),fmt(result.hp))
|
||
end
|
||
end
|
||
elseif hp and hp>0 then
|
||
kill='角色类型未确认,保留原生结果 HP='..fmt(hp)
|
||
end
|
||
if run.lionPickup then
|
||
local remaining=U.valid(boss) and read(boss,'Health')
|
||
local completed=not keep and not handoff and run.montage~=nil and (run.fell~=nil or type(remaining)=='number' and remaining<=0)
|
||
options.lionPickupEnded(run.executor,completed)
|
||
end
|
||
self.finished=self.finished+1
|
||
say(string.format('结束(%s)用时=%.1fs;%s;%s',why,now()-run.t0,back,kill))
|
||
self.message='上次处决:'..className(run.executor)..' → '..className(boss)..'('..why..')'
|
||
end
|
||
|
||
local function watch()
|
||
local run=active
|
||
local t=now()-run.t0
|
||
chain:tick()
|
||
poseProbe:sample('tick')
|
||
if not U.valid(run.executor) then finish('执行方失效',true);return end
|
||
if run.direct and not run.directSeen and not run.dynamic then
|
||
local seen=montageOf(run.executor)
|
||
local expected=run.directExpected
|
||
if seen and (expected and seen==expected or not expected and seen~=run.executorBefore) then
|
||
run.directSeen=true
|
||
say(string.format('同骨架直播读回 执行方动作=%s 期望=%s 用时=%.1fs',seen,tostring(expected),t))
|
||
elseif t>=DIRECT_WAIT then
|
||
-- Its own mesh did not take the clip: this executor borrows a body from now on, this battle included.
|
||
directFailed[U.key(run.executor) or '']=true
|
||
run.direct=false
|
||
local b,problem=borrowBody(run.executor,run.info.timing,run.legacyBorrow)
|
||
run.body=b
|
||
local placed='未借到'
|
||
if b then
|
||
local at=(run.info.timing.clip_from or 0)+(t+(run.info.counterTime or 0))*(run.info.timing.rate or 1)
|
||
local set=call(b.comp,'SetPosition',at,false)
|
||
local got,actual=call(b.comp,'GetPosition');actual=got and U.unwrap(actual)
|
||
placed=string.format('片段位置 要求=%.2f 读回=%s 调用=%s',at,fmt(actual),tostring(set))
|
||
end
|
||
say(string.format('同骨架直播失败,改回借身体:执行方=%s %.1fs 内执行方动作=%s 期望=%s;借身体=%s %s',className(run.executor),t,
|
||
tostring(seen),tostring(expected),b and (problem and '有问题:'..problem or '成功') or '失败:'..tostring(problem),placed))
|
||
end
|
||
end
|
||
local hp=U.valid(run.boss) and read(run.boss,'Health') or nil
|
||
local montage=U.valid(run.boss) and montageOf(run.boss) or nil
|
||
if not run.montage and montage and montage~=run.before then run.montage=montage end
|
||
run.samples=run.samples+1
|
||
if run.samples<=3 and run.body then CopyPose.sample(run.body.copyFollowers,run.body.comp,log,name) end
|
||
if run.samples<=3 or run.samples%4==0 then
|
||
local playing=run.body and select(2,call(run.body.comp,'IsPlaying'))
|
||
local d=distance(run.executor,run.boss)
|
||
say(string.format('进行中 %.1fs 目标HP=%s 目标动作=%s 执行方动作=%s 借来的骨架播放中=%s 距离=%s',t,fmt(hp),tostring(montage),
|
||
tostring(montageOf(run.executor)),tostring(playing and U.unwrap(playing)),d and string.format('%.1fm',d/100) or '?'))
|
||
end
|
||
if hp and hp<=0 and not run.fell then run.fell=t;say(string.format('目标在 %.1fs 倒下,执行方的动作继续播完',t)) end
|
||
if run.lionPickup and not run.headSeen and options.lionHeadSeen then run.headSeen=options.lionHeadSeen(run.executor) end
|
||
if run.lionPickup and run.fell and t>=2.8 and t<4.2 then
|
||
local _,anim=call(U.field(run.executor,'Mesh'),'GetAnimInstance')
|
||
local _,current=call(anim,'GetCurrentActiveMontage')
|
||
if short(current)=='HouHouHou_GEx_01_R_Montage' then
|
||
local _,position=call(anim,'Montage_GetPosition',current)
|
||
if type(position)=='number' and position>=3.052 and position<4.1 and options.lionPickupReady(run.executor) then
|
||
finish('狮头到手,衔接跳桩')
|
||
return
|
||
end
|
||
end
|
||
end
|
||
if run.mash and not run.mash.finale and t>=run.mash.next then press(run,t) end
|
||
if t>=1.5 and not run.montage and not run.fell then
|
||
if not run.info.foreign then finish('目标没有播被处决动作',true);return end
|
||
-- A pair that was not made for this skeleton: the executor's half plays out; the target is held where it is.
|
||
if not run.foreignHeld then
|
||
run.foreignHeld=true
|
||
local got,was=call(U.field(U.field(run.boss,'Controller'),'BrainComponent'),'IsPaused')
|
||
local held='AI原本已暂停,结束时保留原状态'
|
||
if not (got and U.unwrap(was)==true) then run.targetPaused,held=holdAI(run.boss,true) end
|
||
say(string.format('处决对不是给目标骨架做的,%.1fs 内目标没有播被处决动作:执行方照常播完,目标原地停住(%s),结束时照常收尾',t,tostring(held)))
|
||
end
|
||
end
|
||
if not run.dynamic and t>=run.length then finish(run.fell and '播完,目标已倒下' or '播完');return end
|
||
end
|
||
|
||
local function adoptNative(event)
|
||
if phaseBusy(event.executor) or phaseBusy(event.target) then return end
|
||
if next(pendingBodies) or not (U.valid(event.executor) and U.valid(event.target)) then return end
|
||
local timing=animationData(short(event.execution))
|
||
if not timing then return end
|
||
self:stopGrabPose('转入原生处决',event.executor)
|
||
self:stopGrabPose('转入原生处决',event.target)
|
||
if next(pendingGrabControls) or next(pendingBodies) then return end
|
||
local continuing,paused=false,false
|
||
if active then
|
||
if U.key(active.executor)==U.key(event.executor) and U.key(active.boss)==U.key(event.target)
|
||
and U.key(active.info.pair.execution)==U.key(event.execution) then return end
|
||
if U.key(active.executor)~=U.key(event.executor) then
|
||
say('另一对原生处决已开始,当前表现未结束,暂不接管:'..short(event.execution));return
|
||
end
|
||
continuing=true;paused=active.paused
|
||
finish('衔接原生下一段',false,true)
|
||
if next(pendingBodies) then return end
|
||
end
|
||
local info=inspect(event.target)
|
||
info.timing=timing
|
||
info.pair={execution=event.execution,executed=event.executed,start=event.start,source=event.source or '原生PlayExactExecution读回'}
|
||
start(event.executor,event.target,info,distance(event.executor,event.target),'原生反制/连携',
|
||
{continuing=continuing,paused=paused})
|
||
end
|
||
local function counterEligible(actor,boss,kind)
|
||
if not self.enabled or paused() or next(pendingBodies) or next(pendingGrabControls) or phaseBusy(actor) or phaseBusy(boss) then return false end
|
||
local ak,bk=U.key(actor),U.key(boss)
|
||
if grabPoses[ak] or grabPoses[bk] then return false end
|
||
if active then
|
||
local ex,ed=U.key(active.executor),U.key(active.boss)
|
||
if ex==ak or ed==ak or ex==bk or ed==bk then return false end
|
||
end
|
||
local a,b
|
||
for _,member in ipairs(options.members() or {})do
|
||
if not member.stand and not member.reserve and not member.aid then
|
||
local key=U.key(member.actor)
|
||
if key==ak then a=member.team elseif key==bk then b=member.team end
|
||
end
|
||
end
|
||
if a=='companion' or b=='companion' then
|
||
local companion=a=='companion' and actor or boss
|
||
if kind~='blade' or not (options.companions and options.companions() or isHun and isHun(companion)) then return false end
|
||
elseif not options.fighting or not options.fighting() then return false
|
||
elseif (a~='blue' and a~='red') or b~=(a=='blue' and 'red' or 'blue') then return false end
|
||
if b and options.isImmortal and options.isImmortal(b) or options.immune and options.immune(boss,'execution') then return false end
|
||
if isHun and isHun(actor) then
|
||
if kind=='jade' and options.hunProfile then
|
||
local profile=options.hunProfile(actor)
|
||
local chance=profile and profile.ai and profile.ai.counter_chance
|
||
if chance and chance<1 then return false end -- Hun's own defense controller owns this choice.
|
||
end
|
||
if not hunWithinLimit(actor,healthWindow(boss)) then return false end
|
||
end
|
||
return true
|
||
end
|
||
local counters=require('arena_counter_windows').new({world=options.getWorld,player=options.getPlayer,now=now,
|
||
fname=name,hp=function(actor)return read(actor,'Health')end,location=options.getLocation,
|
||
assigned=options.assignedOpponent or function()return nil end,eligible=counterEligible,log=log,
|
||
loop=options.loop,cancel=options.cancel,
|
||
bladeCounter=function(actor,boss,time)
|
||
local known=PAIRS.BP_Monster_GreatBladeMan
|
||
local ex,ed=object(known.execution),object(known.executed)
|
||
local timing=ex and animationData(short(ex))
|
||
if not timing or not ed or not counterEligible(actor,boss,'blade') then return false end
|
||
if active then
|
||
-- The other pair owns the borrowed mesh and camera. This NPC still has its own gameplay component.
|
||
callingNative=true
|
||
local ok=call(U.field(actor,'Execution Component'),'PlayExactExecution',{ExecutionAbility=ex,ExecutedAbility=ed},boss,time)
|
||
callingNative=false
|
||
if not ok then return false end
|
||
else
|
||
local info=inspect(boss)
|
||
info.pair={execution=ex,executed=ed,start=time,type='Execution.Type.Combat',source='毕峰终结反制'}
|
||
info.timing=timing;info.counterTime=time
|
||
if start(actor,boss,info,distance(actor,boss),'毕峰原生终结窗口')==false then return false end
|
||
end
|
||
local actual=U.field(U.field(actor,'Execution Component'),'CurrentExecutionInfo')
|
||
return U.key(weak(U.struct(actual,'Executor')))==U.key(actor) and U.key(weak(U.struct(actual,'Target')))==U.key(boss)
|
||
end})
|
||
local opportunities=Opportunities.new({log=log,counterWindows=counters,inGameThread=options.inGameThread,
|
||
grabReadback=function(actor,target)
|
||
return string.format('执行方HP=%s/%s 锁血底线=%s 对手HP=%s',fmt(read(actor,'Health')),
|
||
fmt(read(actor,'Health_Max')),fmt(read(actor,'Health_Min')),fmt(read(target,'Health')))
|
||
end,staticFind=find,loadAsset=load,members=options.members,getPlayer=options.getPlayer,
|
||
registerHook=options.registerHook,unregisterHook=options.unregisterHook,defer=options.defer,cancel=options.cancel,
|
||
fighting=options.fighting or function()return true end,internal=function()return callingNative end,
|
||
available=function(executor)return self.enabled and next(pendingBodies)==nil
|
||
and (not executor or not active or U.key(active.executor)==U.key(executor))end,data=animationData,adopt=adoptNative})
|
||
|
||
local function noteLionWait(target,unit,fieldLion,why,hp,floor,expected,nativeTag)
|
||
if fieldLion or unit.lastLionWait==why or (unit.lastLionLines or 0)>=4 then return end
|
||
unit.lastLionWait=why;unit.lastLionLines=(unit.lastLionLines or 0)+1
|
||
local mesh=U.field(target,'Mesh')
|
||
local visibleRead,visible=call(mesh,'IsVisible')
|
||
say(string.format('最后一只小狮子等待:%s;HP=%s/%s 底线=%s 所属烈焰原生底线=%s 原生可处决标签=%s Actor隐藏=%s Mesh隐藏=%s Mesh可见=%s',
|
||
why,fmt(hp),fmt(read(target,'Health_Max')),fmt(floor),fmt(expected),tostring(nativeTag),fmt(U.field(target,'bHidden')),
|
||
fmt(U.field(mesh,'bHiddenInGame')),fmt(visibleRead and U.unwrap(visible))))
|
||
end
|
||
|
||
-- Starts an execution of the target if it can be executed now and someone is there to do it; true once it has.
|
||
-- only: as opponent()'s, the executors this attempt may take (a companion Hun's own attempts take Hun bodies only).
|
||
local function tryExecute(target,unit,t,team,only,lionOwner,fieldLion)
|
||
if options.immune and options.immune(target,'execution') then return false end
|
||
if phaseBusy(target) then return false end
|
||
if options.onPole and options.onPole(target) then return false end
|
||
local hp=read(target,'Health')
|
||
if not hp or hp<=0 then return false end
|
||
if lionOwner and not tagsMatch(target,{Lion.LAST},true) then return false end
|
||
local locked=not lionOwner and onLock(target,unit,hp)
|
||
local knownLionFloor,floor,expected,atFloor
|
||
if lionOwner then knownLionFloor,floor,expected,atFloor=lastLionFloor(target,hp,lionOwner) end
|
||
if locked or knownLionFloor then unit.since=unit.since or t else unit.since=nil end
|
||
local reason=locked and t-unit.since>=HOLD and '卡在锁血线'
|
||
or knownLionFloor and t-unit.since>=HOLD and '最后一只小狮子原版锁血'
|
||
local nativeTag
|
||
if (lionOwner or not reason) and not unit.lockOnly then nativeTag=executable(target) end
|
||
reason=reason or nativeTag
|
||
if not reason and not unit.lockOnly then
|
||
for _,tag in ipairs({'CharacterState.CanRiderExecute','CharacterState.Stand.Break','CharacterState.CanWeakExecute'})do
|
||
if tagsMatch(target,{tag},true)then reason=tag;break end
|
||
end
|
||
end
|
||
if not reason then
|
||
if lionOwner and atFloor and not knownLionFloor then
|
||
noteLionWait(target,unit,fieldLion,'未读回原版处决窗口或所属烈焰的底线',hp,floor,expected,nativeTag)
|
||
end
|
||
return false
|
||
end
|
||
if inNativeExecution(target) or (locked or knownLionFloor) and hasTroopProtection(target) then unit.since=nil;return false end
|
||
local selected=inspect(target,true,locked,knownLionFloor)
|
||
if selected.state=='story' then
|
||
unit.state='story';unit.storyWhy=selected.storyWhy
|
||
say('处决会改剧情,不用它:'..className(target)..' '..short(selected.pair.execution)..' '..tostring(selected.storyWhy))
|
||
return false
|
||
end
|
||
local executor,d,denied
|
||
if lionOwner then
|
||
if selected.state~='ready' or short(selected.pair.execution)~=LION_EXEC or short(selected.pair.executed)~=LION_VICTIM then
|
||
noteLionWait(target,unit,fieldLion,'原生技能对或角色状态未确认',hp,floor,expected,nativeTag)
|
||
return false
|
||
end
|
||
selected.requireLionPickup=true
|
||
selected.fieldLionHead=fieldLion==true
|
||
local function mayTakeHead(actor)
|
||
return (not only or only(actor)) and (not options.hunPoleHead or options.hunPoleHead(actor)~=false)
|
||
and not inNativeExecution(actor)
|
||
end
|
||
local function pick(eligible)
|
||
return opponent(target,team,REACH,false,selected.pair.type,selected.mob,eligible)
|
||
end
|
||
if selected.fieldLionHead then
|
||
executor,d=pick(function(actor)
|
||
return mayTakeHead(actor) and options.fieldLionTarget(actor,target)==true
|
||
end)
|
||
else
|
||
local targetKey,ownerKey=U.key(target),U.key(lionOwner)
|
||
local function currentOpponent(actor)
|
||
return options.assignedOpponent and U.key(options.assignedOpponent(actor))
|
||
end
|
||
executor,d=pick(function(actor)
|
||
return mayTakeHead(actor) and currentOpponent(actor)==targetKey
|
||
end)
|
||
if not executor then
|
||
-- A missed retarget must not strand this wave. Only an unassigned enemy or one
|
||
-- still assigned to its own on-pole boss may borrow the verified cub's opportunity.
|
||
executor,d=pick(function(actor)
|
||
if not mayTakeHead(actor) then return false end
|
||
local assigned=currentOpponent(actor)
|
||
if assigned and assigned~=ownerKey then return false end
|
||
local readRelation,relation=call(U.field(actor,'Faction Component'),'GetFactionRelation',target)
|
||
return readRelation and tonumber(U.unwrap(relation))==2
|
||
end)
|
||
end
|
||
end
|
||
if not executor then
|
||
noteLionWait(target,unit,fieldLion,'附近没有符合条件的已分配或已确认敌对执行者',hp,floor,expected,nativeTag)
|
||
return false
|
||
end
|
||
local started=start(executor,target,selected,d,reason)~=false
|
||
if not started then noteLionWait(target,unit,fieldLion,'狮头接取或原生处决未确认',hp,floor,expected,nativeTag) end
|
||
return started
|
||
end
|
||
if selected.state=='ready' then
|
||
-- A generic Weak tag must never claim a lion head without its wave's ticket.
|
||
if short(selected.pair.execution)==LION_EXEC then return false end
|
||
local reach=locked and LOCK_REACH or selected.pair.reach or REACH
|
||
executor,d,denied=opponent(target,team,reach,locked,selected.pair.type,selected.mob,only)
|
||
end
|
||
if executor then return start(executor,target,selected,d,reason)~=false end
|
||
-- A denied finisher cannot leave a minion immortal at its final death floor.
|
||
if not lionOwner and denied and selected.mob and locked and t-(unit.since or t)>=HOLD and t>=(unit.policyRetry or 0)then
|
||
local floor,max=read(target,'Health_Min'),read(target,'Health_Max')
|
||
if floor and max and floor<=DEATH_LOCK*max+1 and hp<=floor+1 then
|
||
unit.policyRetry=t+1
|
||
local result=finalDeath(target,unit,t,'denied',team)
|
||
if result then
|
||
say('小怪末端锁血免动画收尾:调用='..tostring(result.applied)..';HP读回='..tostring(result.hp))
|
||
return true
|
||
end
|
||
end
|
||
end
|
||
if selected.state~='ready' and not unit.conditionWait then unit.conditionWait=true;say('有处决数据,当前原生标签/骑乘条件未满足:'..className(target)) end
|
||
if locked and selected.state=='ready' and not unit.waited then unit.waited=true;say('卡在锁血线,附近 20 米内没有符合处决条件的对手:'..className(target)) end
|
||
return false
|
||
end
|
||
-- 1-4: a target with no pair of its own, and a Hun body the nearest enemy that could execute it. The Hun weapon's
|
||
-- generic pairs are taken only when the target's mesh skeleton is the skeleton of the pair's executed montage;
|
||
-- each target is checked once for each weapon and the result logged.
|
||
-- generic (the companions' way): the pairs of the weapon the executor holds first, then the generic ones (绝影's),
|
||
-- so a weapon with no pair for this skeleton still finishes, and an executor that is no Hun body gets the generic
|
||
-- ones. Without it (the arena) a Hun holding a weapon uses that weapon's pairs only, as before.
|
||
-- foreign (a companion Hun only): with no pair for this skeleton, the first pair whose abilities load is taken
|
||
-- all the same, marked info.foreign.
|
||
local function hunPairFor(target,unit,executor,generic,foreign)
|
||
local config=options.hunWeapon and options.hunWeapon(executor)
|
||
local skeleton=meshSkeleton(target)
|
||
local key=U.key(skeleton) or (foreign and '读不到') or nil
|
||
if not key then return end
|
||
if unit.hunSkeleton~=key then unit.hunSkeleton,unit.hunSets=key,{} end
|
||
local name=(config or '')..(generic and '+通用' or '')
|
||
local set=unit.hunSets[name]
|
||
if not set then
|
||
set={};unit.hunSets[name]=set
|
||
local lists={}
|
||
if config then lists[1]={entries=require('hun_weapon_execution_data').forConfig(config) or {},from='手持武器',source='魂手持武器的处决对'} end
|
||
if not config or generic then lists[#lists+1]={entries=hunPairs,from='通用',source='魂武器通用处决对'} end
|
||
local seen={}
|
||
for _,list in ipairs(lists)do
|
||
for _,entry in ipairs(list.entries)do
|
||
if not seen[entry.execution] then
|
||
seen[entry.execution]=true
|
||
local victim=object(entry.victim)
|
||
local wanted=victim and U.field(victim,'Skeleton')
|
||
local adopt=skeleton~=nil and U.valid(wanted) and U.key(wanted)==U.key(skeleton)
|
||
local execution,executed
|
||
if adopt then execution,executed=object(entry.execution),object(entry.executed);adopt=execution~=nil and executed~=nil end
|
||
say(string.format('魂武器处决对 目标=%s 目标骨架=%s 受害方骨架=%s(%s) 技能对=%s 采用=%s 来自=%s',className(target),skeleton and short(skeleton) or '读不到',
|
||
U.valid(wanted) and short(wanted) or '读不到',entry.victim_skeleton,entry.execution:match('%.([^%.]+)$'),tostring(adopt),list.from))
|
||
if adopt then
|
||
set[#set+1]={rule=entry,info={state='ready',locks=unit.locks,rank=unit.rank,boss=unit.boss,mob=unit.mob,timing=entry.timing,hunPair=true,
|
||
pair={execution=execution,executed=executed,source=list.source,type='Execution.Type.Combat'}}}
|
||
else
|
||
set.rest=set.rest or {};set.rest[#set.rest+1]={entry=entry,source=list.source}
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
for _,pair in ipairs(set)do
|
||
local rule=pair.rule
|
||
if tagsMatch(executor,rule.executor_required,true) and tagsMatch(executor,rule.executor_ignored,false)
|
||
and tagsMatch(target,rule.target_required,true) and tagsMatch(target,rule.target_ignored,false) then return pair.info end
|
||
end
|
||
if not foreign then return end
|
||
-- No pair for this skeleton. The pairs made for other skeletons, in the same order, the first whose abilities
|
||
-- load and whose executor tags hold; the target's tag rules are for the bodies the pair was made for.
|
||
if not set.foreign then
|
||
set.foreign={}
|
||
for _,item in ipairs(set.rest or {})do
|
||
local entry=item.entry
|
||
local execution,executed=object(entry.execution),object(entry.executed)
|
||
if execution and executed then
|
||
set.foreign[#set.foreign+1]={rule=entry,info={state='ready',locks=unit.locks,rank=unit.rank,boss=unit.boss,mob=unit.mob,timing=entry.timing,hunPair=true,foreign=true,
|
||
pair={execution=execution,executed=executed,source=item.source..'(不是给目标骨架做的)',type='Execution.Type.Combat'}}}
|
||
end
|
||
end
|
||
say(string.format('魂处决对里没有给 %s 的骨架(%s)做的:随从魂照样处决,可用 %d 对,受害方动作由游戏在它身上播,播不出就原地停住',className(target),
|
||
skeleton and short(skeleton) or '读不到',#set.foreign))
|
||
end
|
||
for _,pair in ipairs(set.foreign)do
|
||
local rule=pair.rule
|
||
if tagsMatch(executor,rule.executor_required,true) and tagsMatch(executor,rule.executor_ignored,false) then return pair.info end
|
||
end
|
||
end
|
||
-- only: the executors this attempt may take (opponent()'s); generic, foreign: as hunPairFor's.
|
||
local function tryHunPair(target,unit,t,team,only,generic,foreign)
|
||
if options.immune and options.immune(target,'execution') then return false end
|
||
if phaseBusy(target) or (options.onPole and options.onPole(target)) then return false end
|
||
local hp=read(target,'Health')
|
||
if not hp or hp<=0 then return false end
|
||
local locked=onLock(target,unit,hp)
|
||
if locked then unit.hunSince=unit.hunSince or t else unit.hunSince=nil end
|
||
local reason=locked and t-unit.hunSince>=HOLD and '卡在锁血线' or (not unit.lockOnly and executable(target))
|
||
if not reason and not unit.lockOnly and tagsMatch(target,{'CharacterState.Stand.Break'},true) then reason='CharacterState.Stand.Break' end
|
||
if not reason or not tagsMatch(target,GENERALS,false) then return false end
|
||
if inNativeExecution(target) or locked and hasTroopProtection(target) then unit.hunSince=nil;return false end
|
||
local executor,d=opponent(target,team,locked and LOCK_REACH or REACH,false,'Execution.Type.Combat',unit.mob,only)
|
||
if not executor then return false end
|
||
local info=hunPairFor(target,unit,executor,generic,foreign)
|
||
if not info then return false end
|
||
return start(executor,target,info,d,reason..',魂武器处决对')~=false
|
||
end
|
||
-- What the companions are after, while the switch is on: anything on their hatred lists but the player and the arena's
|
||
-- own units. A unit summoned with no team is summoned to be fought, so it counts.
|
||
local function hunCompanionHere(members)
|
||
if not isHun or hunSteps.companionExecutions==false then return false end
|
||
for _,member in ipairs(members)do
|
||
if member.team=='companion' and not member.reserve and isHun(member.actor) then return true end
|
||
end
|
||
return false
|
||
end
|
||
-- Returns the foes, whether the 随从处决 BOSS switch is on, whether a companion Hun is there, and whether the
|
||
-- 随从处决小怪 switch is on.
|
||
companionFoes=function(members)
|
||
local switch=options.companions and options.companions() and true or false
|
||
local hun=hunCompanionHere(members)
|
||
local minions=options.companionMinions and options.companionMinions() and true or false
|
||
if not switch and not hun and not minions then return {},false,false,false end
|
||
local skip,seen,foes={},{},{}
|
||
local playerKey=U.key(options.getPlayer and options.getPlayer())
|
||
if playerKey then skip[playerKey]=true end
|
||
for _,member in ipairs(members)do
|
||
local key=member.team~='neutral' and U.key(member.actor)
|
||
if key then skip[key]=true end
|
||
end
|
||
for _,member in ipairs(members)do
|
||
if member.team=='companion' and not member.reserve and (not options.companionCanAct or options.companionCanAct(member.actor)) then
|
||
local list=U.field(U.field(member.actor,'BP_PBZHatredManagerComponent'),'HatredList')
|
||
for _,enemy in ipairs(U.array(list) or {})do
|
||
local key=U.key(enemy)
|
||
if key and not skip[key] and not seen[key] then seen[key]=true;foes[#foes+1]={actor=enemy,key=key} end
|
||
end
|
||
end
|
||
end
|
||
return foes,switch,hun,minions
|
||
end
|
||
-- The player has this one (the game keeps the last executor on the target's component): it stays the player's.
|
||
local function theirExecutorIsPlayer(target)
|
||
local info=U.field(U.field(target,'Execution Component'),'CurrentExecutionInfo')
|
||
local executor=weak(U.struct(info,'Executor'))
|
||
local playerKey=U.key(options.getPlayer and options.getPlayer())
|
||
return playerKey~=nil and U.key(executor)==playerKey
|
||
end
|
||
local function considerFoes(foes,t,switch,hun,minions)
|
||
for _,foe in ipairs(foes)do
|
||
local unit=units[foe.key]
|
||
if not unit then
|
||
unit=inspect(foe.actor);unit.foe=true;units[foe.key]=unit
|
||
if unit.boss and options.isStand and options.isStand(foe.actor) then unit.state='none' end
|
||
if unit.boss and unit.state=='ready' then
|
||
say(string.format('随从处决登记 %s(%s):锁血效果=%d 个 技能对=%s / %s(%s)',className(foe.actor),unit.rank,#unit.locks,
|
||
short(unit.pair.execution),short(unit.pair.executed),unit.pair.source))
|
||
elseif unit.boss then
|
||
say('随从处决:这个 BOSS 没有能用的处决动作,不处决:'..className(foe.actor)..' 状态='..unit.state)
|
||
end
|
||
end
|
||
if switch and unit.boss and unit.state=='ready' and not (unit.again and t<unit.again) then
|
||
if theirExecutorIsPlayer(foe.actor) then
|
||
if not unit.playerHeld then unit.playerHeld=true;say('玩家处决过或正在处决,随从不抢:'..className(foe.actor)) end
|
||
elseif tryExecute(foe.actor,unit,t,nil) then return end
|
||
end
|
||
local free=not unit.finalDeath and not (unit.again and t<unit.again)
|
||
local open=(unit.state=='ready' or unit.state=='nopair') and free
|
||
-- A companion Hun: any foe the player could finish, minions too; never one the player has taken. A minion
|
||
-- gets the pair of the weapon the Hun holds, then the generic one, then its own; a boss its own first.
|
||
-- Last, for anyone but a boss that has its own pair: a pair that was not made for the foe's skeleton.
|
||
if hun and free and (unit.state=='ready' or unit.state=='nopair' or unit.state=='nodata') and not theirExecutorIsPlayer(foe.actor) then
|
||
local own=unit.state=='ready'
|
||
if hunSteps.weaponPairs~=false and (not own or not unit.boss and hunSteps.companionWeaponFirst~=false)
|
||
and tryHunPair(foe.actor,unit,t,nil,isHun,true) then return end
|
||
if own and unit.state=='ready' and tryExecute(foe.actor,unit,t,nil,isHun) then return end
|
||
if hunSteps.weaponPairs~=false and hunSteps.companionAnyone~=false and not (own and unit.boss)
|
||
and (unit.state=='ready' or unit.state=='nopair' or unit.state=='nodata') and tryHunPair(foe.actor,unit,t,nil,isHun,true,true) then return end
|
||
end
|
||
-- 随从处决小怪: a minion, by the nearest companion; never one the player has taken. Its own pair, or with none
|
||
-- the Hun's generic pair, which the executor borrows the player's body for.
|
||
if minions and not unit.boss and open and (unit.state=='ready' or unit.state=='nopair') and not theirExecutorIsPlayer(foe.actor) then
|
||
if unit.state=='ready' then
|
||
if tryExecute(foe.actor,unit,t,nil) then return end
|
||
elseif hunSteps.weaponPairs~=false and tryHunPair(foe.actor,unit,t,nil,nil,true) then return end
|
||
end
|
||
end
|
||
end
|
||
-- 打到死 (a unit's card, unit_rules.lua): a unit on its death lock dies there, without waiting for anyone. Any team: the
|
||
-- same lock stops the player and the companions. The way a level script ends it (SpawnerToDieNS): the lock off, GE_Kill.
|
||
local function endLocks(members,t)
|
||
if not options.killOnLock then return end
|
||
for _,member in ipairs(members)do
|
||
local target=member.actor
|
||
local key=U.key(target)
|
||
if key and not member.stand and not phaseBusy(target) and options.killOnLock(target) and not (options.isImmortal and options.isImmortal(member.team)) then
|
||
local unit=units[key]
|
||
if not unit then unit=inspect(target);units[key]=unit end
|
||
local hp=read(target,'Health')
|
||
if unit.state~='done' and (unit.finalDeath or hp and hp>0 and onLock(target,unit,hp)
|
||
and (read(target,'Health_Min') or 0)<=DEATH_LOCK*(read(target,'Health_Max') or 0)+1)then
|
||
local result=finalDeath(target,unit,t,'card',member.team)
|
||
if result then
|
||
say(string.format('到锁血线直接打死(卡面设置)%s:去锁血[%s] 读回底线=%s;GE_Kill=%s%s 读回HP=%s',className(target),table.concat(result.removed,' '),
|
||
fmt(result.after),tostring(result.applied),result.applied and '' or '('..tostring(result.err)..')',fmt(result.hp)))
|
||
end
|
||
end
|
||
end
|
||
end
|
||
end
|
||
function self:tick()
|
||
if paused() then return end
|
||
local members=options.members() or {}
|
||
local policyFight
|
||
if options.executionPolicyConfigured and options.executionPolicyConfigured()==true then policyFight=not options.fighting or options.fighting()==true end
|
||
policy:sync(members,policyFight==true)
|
||
local present={}
|
||
for _,member in ipairs(members)do
|
||
local key=U.key(member.actor)
|
||
if key then present[key]=member end
|
||
end
|
||
local foes,foeSwitch,foeHun,foeMinions=companionFoes(members)
|
||
local fieldCubs=options.fieldLastCubs and options.fieldLionTarget and options.fieldLastCubs() or {}
|
||
local fieldKeys={}
|
||
for _,cub in ipairs(fieldCubs)do fieldKeys[cub.key]=true;present[cub.key]=true end
|
||
for i=#foes,1,-1 do
|
||
local foe=foes[i]
|
||
if fieldKeys[foe.key] then table.remove(foes,i) else present[foe.key]=true end
|
||
end
|
||
local finishing
|
||
for key,unit in pairs(units)do
|
||
if not present[key] then
|
||
units[key]=nil
|
||
if not unit.foe then say('单位已离场,清除处决判断 读回=不在当前名单') end
|
||
elseif unit.finalDeath and unit.finalDeath.mode=='card'and options.killOnLock then
|
||
local member=present[key]
|
||
if type(member)=='table'and not options.killOnLock(member.actor)then unit.finalDeath=nil end
|
||
elseif unit.finalDeath and (unit.finalDeath.mode=='finish' or unit.finalDeath.mode=='denied') then
|
||
finishing=finishing or {}
|
||
finishing[#finishing+1]=unit
|
||
end
|
||
end
|
||
for _,control in pairs(pendingGrabControls)do
|
||
local restored,detail=restoreGrabControl(control)
|
||
if not restored then self.message='血滴子控制恢复待重试';return end
|
||
say('血滴子控制恢复重试读回=true;'..detail)
|
||
end
|
||
for key,body in pairs(pendingBodies) do
|
||
if not sameExecutor(body) then pendingBodies[key]=nil
|
||
elseif bodyGone(body) then
|
||
if body.restored then pendingBodies[key]=nil
|
||
elseif not body.goneRetried then
|
||
body.goneRetried=true
|
||
say('借用骨架失效后恢复附着:'..returnBody(body))
|
||
end
|
||
elseif not ownsComponent(body,body) then pendingBodies[key]=nil
|
||
elseif body.restored and body.destroyRetry and now()>=body.destroyRetry then
|
||
say('重试移除借用骨架,读回='..tostring(disposeBody(body)))
|
||
end
|
||
end
|
||
if not self.enabled then return end
|
||
if next(grabPoses) then
|
||
if active then watch() end
|
||
return
|
||
end
|
||
chain:auditExisting()
|
||
opportunities:tick(members,(foeSwitch or foeHun) and #foes>0 and foes or nil)
|
||
if active then watch();return end
|
||
if next(pendingBodies) then self.message='借用骨架清理待确认,请停止/清场';return end
|
||
local t=now()
|
||
for _,unit in ipairs(finishing or {})do
|
||
local r=unit.finalDeath
|
||
if r and (r.mode=='finish' or r.mode=='denied') then
|
||
local member=present[r.key]
|
||
local target=r.actor or (type(member)=='table' and member.actor)
|
||
if not target or finisherTeam(target)~=r.team or phaseBusy(target)
|
||
or options.isImmortal and options.isImmortal(r.team) then unit.finalDeath=nil
|
||
elseif finalDeath(target,unit,t,r.mode,r.team) then return end
|
||
end
|
||
end
|
||
endLocks(members,t)
|
||
-- The last cub's paired execution advances this phase. Do not spend it on a generic companion finisher.
|
||
for _,cub in ipairs(fieldCubs)do
|
||
local target=cub.actor
|
||
if U.valid(cub.owner) and not theirExecutorIsPlayer(target) then
|
||
local unit=units[cub.key]
|
||
if not unit then unit=inspect(target);unit.foe=true;units[cub.key]=unit end
|
||
if unit.state=='ready' and not unit.finalDeath and not (unit.again and t<unit.again)
|
||
and tryExecute(target,unit,t,nil,nil,cub.owner,true) then return end
|
||
end
|
||
end
|
||
if options.fighting and(policyFight==false or policyFight==nil and not options.fighting())then
|
||
for _,unit in pairs(units) do unit.prologueSince=nil end
|
||
considerFoes(foes,t,foeSwitch,foeHun,foeMinions);return
|
||
end
|
||
-- Whether a Hun body is in the fight; only then are targets with no pair looked at for its weapon pairs.
|
||
local lastCubs,ordered
|
||
if options.lastLionOwner then
|
||
for _,m in ipairs(members)do
|
||
local ownerKey=m.class_path==LAST_LION_CLASS and not m.reserve and not m.stand and not m.aid
|
||
and not m.untargetable and U.key(m.summoner)
|
||
local owner=ownerKey and options.lastLionOwner(m.actor)
|
||
if ownerKey and ownerKey==U.key(owner) then
|
||
lastCubs=lastCubs or {};ordered=ordered or {}
|
||
lastCubs[m]=owner;ordered[#ordered+1]=m
|
||
end
|
||
end
|
||
if ordered then
|
||
for _,m in ipairs(members)do if not lastCubs[m] then ordered[#ordered+1]=m end end
|
||
members=ordered
|
||
end
|
||
end
|
||
local hunHere=false
|
||
if isHun and hunSteps.weaponPairs~=false then
|
||
for _,member in ipairs(members)do
|
||
if (member.team=='blue' or member.team=='red') and isHun(member.actor) then hunHere=true;break end
|
||
end
|
||
end
|
||
for _,member in ipairs(members) do
|
||
local target=member.actor
|
||
local key=U.key(target)
|
||
-- A helper the other side's boss brought out is left to that boss's script, not finished here.
|
||
if key and (member.team=='blue' or member.team=='red') and not member.aid and not phaseBusy(target) then
|
||
local unit=units[key]
|
||
if not unit then
|
||
unit=inspect(target);units[key]=unit
|
||
if unit.state=='nopair' and #unit.locks>0 then say('锁血但没有成对的处决动作,不处决:'..className(target)) end
|
||
if unit.state=='nodata' then say('有处决动作但没有执行方动作数据,不处决:'..className(target)..' '..short(unit.pair.execution)) end
|
||
if unit.state=='story' then say('处决会改剧情,不用它:'..className(target)..' '..short(unit.pair.execution)..' '..tostring(unit.storyWhy)) end
|
||
if unit.state=='ready' then say(string.format('登记 %s(%s):锁血效果=%d 个 技能对=%s / %s(%s)',className(target),unit.rank,#unit.locks,
|
||
short(unit.pair.execution),short(unit.pair.executed),unit.pair.source)) end
|
||
end
|
||
local immortal=options.isImmortal and options.isImmortal(member.team)
|
||
if unit.prologue then
|
||
if not (immortal or member.stand or member.reserve or member.untargetable) then
|
||
releasePrologueFloor(target,unit,t)
|
||
else
|
||
unit.prologueSince=nil
|
||
end
|
||
end
|
||
if unit.state~='ready' and unit.state~='done' and not immortal then
|
||
local hp=read(target,'Health')
|
||
if unit.finalDeath or hp and hp>0 and onLock(target,unit,hp) then
|
||
if not unit.stuck then
|
||
unit.stuck=t
|
||
say(string.format('卡在锁血线,但它没有能用的处决动作,不处决(也不按倒下算):%s HP=%s 底线=%s',className(target),fmt(hp),
|
||
fmt(read(target,'Health_Min'))))
|
||
end
|
||
local floor=read(target,'Health_Min') or 0
|
||
if unit.boss and not member.untargetable and t-unit.stuck>=STUCK_SECONDS and floor<=DEATH_LOCK*(read(target,'Health_Max') or 0)+1 then
|
||
local result=finalDeath(target,unit,t,'stuck',member.team)
|
||
if result then
|
||
say(string.format('卡在锁血线 %d 秒,没有处决动作,按倒下收尾(%s)%s:去锁血[%s] 读回底线=%s;GE_Kill=%s%s 读回HP=%s',STUCK_SECONDS,unit.rank,className(target),
|
||
table.concat(result.removed,' '),fmt(result.after),tostring(result.applied),result.applied and '' or '('..tostring(result.err)..')',fmt(result.hp)))
|
||
end
|
||
end
|
||
else
|
||
unit.stuck=nil
|
||
end
|
||
end
|
||
if unit.state=='ready' and not unit.finalDeath and not (unit.again and t<unit.again) and not immortal and tryExecute(target,unit,t,member.team,nil,lastCubs and lastCubs[member]) then return end
|
||
if hunHere and not (lastCubs and lastCubs[member]) and unit.state=='nopair' and not unit.finalDeath and not (unit.again and t<unit.again) and not immortal
|
||
and not member.stand and tryHunPair(target,unit,t,member.team,isHun) then return end
|
||
end
|
||
end
|
||
considerFoes(foes,t,foeSwitch,foeHun,foeMinions)
|
||
end
|
||
-- F4 / stop: give the body back; the boss is left as it is.
|
||
function self:stop(why,arenaOnly)
|
||
if not arenaOnly then self:stopGrabPose(why) end
|
||
if arenaOnly and active and active.info.fieldLionHead then return end
|
||
opportunities:stop(why)
|
||
if active then
|
||
local run=active;active=nil
|
||
if run.playback then run.playback:stop() end
|
||
poseProbe:stop(why)
|
||
endCamera(why)
|
||
chain:closeTasks()
|
||
local released=release(run)
|
||
chain:stop(why)
|
||
if run.lionPickup and options.lionPickupEnded then options.lionPickupEnded(run.executor,false) end
|
||
say('中止('..tostring(why)..'):'..returnBody(run.body)..';'..resume(run)..released)
|
||
else
|
||
chain:stop(why)
|
||
end
|
||
local retry={};for _,body in pairs(pendingBodies)do retry[#retry+1]=body end
|
||
for _,body in ipairs(retry)do say('重试身体恢复:'..returnBody(body)) end
|
||
units={}
|
||
directFailed={}
|
||
end
|
||
function self:silence()
|
||
closeGrabPose('Mod 卸载',type(IsInGameThread)=='function' and IsInGameThread())
|
||
chain:silence()
|
||
opportunities:silence()
|
||
if active and active.playback then active.playback:stop() end
|
||
end
|
||
function self:executing(actor)
|
||
local key=U.key(actor)
|
||
return key~=nil and active~=nil and U.key(active.executor)==key
|
||
end
|
||
function self:participant(actor)
|
||
if not active then return false end
|
||
local key=U.key(actor)
|
||
return key~=nil and (key==U.key(active.executor) or key==U.key(active.boss))
|
||
end
|
||
function self:status()
|
||
return {enabled=self.enabled,active=active~=nil,started=self.started,finished=self.finished,failures=self.failures,
|
||
kills=self.kills,message=self.message}
|
||
end
|
||
return self
|
||
end
|
||
return Exec
|