-- Listed offensive player getters and target selectors use their owned caster's enemy. -- Arena fighters use the opposing team; companions read their private AI blackboard. -- Ownership follows the current avatar on every call, including shared action templates. -- Player abilities, follow actions and native story phases keep their original targets. -- Silver-haired Zuo Shang's particle swords expose per-component user target parameters. -- Other listed particle attacks use effect_instance_aim's private collections and systems; -- this module never writes the world's material or Niagara player-position collection. local U=require('ue_observe') local Retry=require('lookup_retry') local Aim={} local STATICS='/Script/Engine.GameplayStatics:' Aim.paths={character=STATICS..'GetPlayerCharacter',pawn=STATICS..'GetPlayerPawn', force='/Script/PBZAbilityTargetRuntime.PBZPlayerAbilityTargetLibrary:ShouldForcePlayerAbilityTarget', lock='/MagCombatAbilities/Abilities/BP_ActionAbilityBase.BP_ActionAbilityBase_C:Request Lock Target', bullet='/SGameCombatSystem/Bullet/TargetSelector/BP_BulletTargetSelector_LockTarget.BP_BulletTargetSelector_LockTarget_C:SelectTarget', bulletAbility='/PBZCombatAsset/Prototypes/Bullet/TargetSelector/BP_BulletTargetSelector_FromAbility.BP_BulletTargetSelector_FromAbility_C:SelectTarget'} local INPUT_LIBRARY='/Script/ProjectPBZ.PBZBlueprintFunctionLibrary:' Aim.paths.walkInputAdd=INPUT_LIBRARY..'AddInputModeTag' Aim.paths.walkInputRemove=INPUT_LIBRARY..'RemoveInputModeTag' local ORDER={'character','pawn','force','lock','bullet','bulletAbility','walkInputAdd','walkInputRemove'} local LABEL={character='取玩家角色',pawn='取玩家Pawn',force='强制锁玩家',lock='锁定落在玩家',bullet='子弹目标',bulletAbility='子弹目标(招式)',flying='飞行中目标', walkInputAdd='拦截NPC输入限制',walkInputRemove='隔离NPC输入恢复'} -- 左殇's flying weapons: the target the bullet actually holds once it starts (ABulletActorBase.CurrentTarget), and where it ends. local FLYING_DIR='/PBZCombatAsset/ActorData/Mobs/054_ZuoShang/Weapon/' local FLYING={} local CASTERS={BP_Monster_ZuoShang_C=true,BP_Monster_ZuoShang_Ending_C=true,BP_Monster_ZuoShang_P2_C=true, BP_Monster_ZuoShang_P2_Stand_C=true} for _,name in ipairs({'FlyingSword','FlyingSpear','FlyingHammer_Big','FlyingGun'})do local class='BP_Bullet_ZuoShang_'..name local start,finish=name..'Start',name..'End' Aim.paths[start]=FLYING_DIR..class..'.'..class..'_C:Received_PostStart' Aim.paths[finish]=FLYING_DIR..class..'.'..class..'_C:Received_Deactivate' FLYING[start]='start';FLYING[finish]='finish' ORDER[#ORDER+1]=start;ORDER[#ORDER+1]=finish LABEL[start]=name..'起飞';LABEL[finish]=name..'结束' end local UNHOOK_SECONDS,LINES,SUMMARY_SECONDS=10,12,10 Aim.paths.menghuaHit='/Script/SGameCombatSystem.BulletAttackModule:DealDamageToAvatar' local DEPTH=8 local STEPS={'Pawn','BulletOwnerAvatar','Owner','Instigator','Source Ability'} local UNLISTED_LINES,BULLET_LINES,FLIGHT_LINES,FLIGHT_PER_KIND=40,60,240,3 -- Particle bullets that aim through their effect: bullet data -> the effect's user switch and position. local EFFECT_AIMS={BD_ZuoShang_Skill_19={use='UE_UseTestTargetPos',pos='UE_TestTargetPos',system='NS_ZuoShang_SwordShooting_001'}} Aim.effectAims=EFFECT_AIMS Aim.paths.launch='/PBZDeflectSystem/Actions/GAA_DelayDeflectProjectileBullet.GAA_DelayDeflectProjectileBullet_C:Go go go' ORDER[#ORDER+1]='launch';LABEL.launch='特效目标' local RAIN_END={rainFinished=true,rainDeactivated=true} for _,entry in ipairs({{'rainFinished','OnParticleSystemFinished'},{'rainDeactivated','OnParticleDeactivated'}})do Aim.paths[entry[1]]='/Script/PBZCombatAsset.PBZ_ParticleBullet:'..entry[2] ORDER[#ORDER+1]=entry[1];LABEL[entry[1]]=entry[2] end local PARTICLE_CLASS,EFFECT_MS,EFFECT_SECONDS,READY,RUNNING='PBZ_ParticleBullet',50,15,1,2 -- Skill 19 launches five particle emitters at 0.62 s and its action ends at 3.97 s. local RAIN_SCANS={[1]=true,[2]=true,[3]=true,[8]=true,[14]=true,[20]=true,[30]=true,[50]=true,[80]=true} local RAIN_AGAIN=5 -- seconds within which a second start is the same cast (the skill runs 3.97 s, cools down 80 s) -- Skills whose bullet data plays an effect that reads CharRootPos and traces hits along its particles (read offline). local EFFECT_SKILLS={ GA_ZuoShang_P2_Skill_17_C=true, -- 龙体左殇 BD_ZuoShang_P2_SwordRain_Burst GA_MengHua_CA_03_C=true, -- 梦华 BD_MengHua_CA_03 GA_LengTu_CA_02_C=true, -- 冷荼 BD_LengTu_CA_02 GA_HuaShan_JianOu_CriticalArt_C=true, -- 华山剑偶 BulletData_HuaShan_JianOu_CriticalArt_01 GA_YingMei_RedShadowBoneBlade_Attack_MaskBuff_C=true, -- 影魅 mask rings GA_YingMei_RedShadowBoneBlade_Skill_Sword_2Hit_A_C=true, GA_YingMei_Cyan_Attack_MaskBuff_C=true, } Aim.effectSkills=EFFECT_SKILLS Aim.paths.skillStart='/MagCombatAbilities/Abilities/BP_ActionAbilityBase_Simple.BP_ActionAbilityBase_Simple_C:K2_ActivateAbility' ORDER[#ORDER+1]='skillStart';LABEL.skillStart='私有特效' Aim.paths.iceSpawn=STATICS..'BeginDeferredActorSpawnFromClass' ORDER[#ORDER+1]='iceSpawn';LABEL.iceSpawn='冰柱施法归属' local ICE_CLASS='BP_QiShu_Bing_Icicle_C' local ICE_SPAWNERS={BP_QiShu_Bing_IcicleSpawner_C=true,BP_Qishu_Bing_SpawnIcicle_C=true} local ICE_CASTERS={BP_Monster_QiShu_Bing_C=true,BP_Monster_Scavenger_C=true,BP_Monster_Scavenger_P2_C=true} local WARNING_SKILLS={GA_MBoss_Skill_02_C4_C=true,GA_HookMan_HorseCart_Skill_06_C=true} -- Attacks that aim at or lock onto the player (the call's world context is an object of the class or a subclass). local AIMS={} for _,name in ipairs({ 'BP_ZuoShang_Bullet_SpinningBlade_C','BP_ZuoShang_GroundWeapon_Base_C', -- 左殇: spinning blade's contact, ground weapons turn 'BP_Bullet_Eye_C','BP_Bullet_EyeDelay_C','BP_Bullet_EyeSP1_C','BP_Bullet_EyeSP3_C', -- 独眼弓客's laser eyes 'BP_Bullet_EyeSP3_01_C','BP_Bullet_EyeSP3_02_C','BP_Bullet_EyeSP3_03_C','BP_Bullet_EyeSP3_04_C','BP_Bullet_EyeSP4_C', 'BP_Bullet_EyeSP4_L_C','BP_Bullet_EyeSP5_L_C','BP_Bullet_EyeSP5_L_01_C','BP_Bullet_EyeSP5_R_C','BP_Bullet_EyeSP5_R_01_C', 'GA_ChiLian_P2_Skill_04_C', -- 献祭之蛇 'GA_MoTian_Skill_08_C', -- 魔渊 'GA_XianZhe_EnterCombat_C','GA_XianZhe_Skill_01_C','GA_XianZhe_Skill_07_C', -- 贤者 'GA_ZuoShang_P2_Skill_23_C','BP_Monster_ZuoShang_P2_C','BP_ZuoShang_P2_DragonPillarBullet_C', -- 龙体左殇, dragon pillars 'BP_Bullet_LengTu_BigHand_FallingHand_C', -- 冷荼's falling hand 'GA_MengHua_IceShield_Passive_C', -- 梦华's ice shield faces it 'GA_XuKong_Skill_04_C', -- 虚空 'GA_DangHui_SwitchSelf_C', -- 荡秽's swap dodge 'GAA_ForceLockTarget_C', -- the shared "force lock target" action 'BP_YuBi_CA02_Arena_C', -- boundary actor and ASC cache 'BP_Bullet_LengTu_StickyWire_C', -- rope user skeletal-mesh target 'BP_QiShu_Bing_Icicle_C', -- in-range frost victim comparison and application })do AIMS[name]=true end Aim.aims=AIMS -- This action runs at the beginning, every tick, and at the end. Its actor states belong on the caster. -- PBZ's input library still uses the local controller's NBInputComponent regardless of the imposer. local FORCE_WALK='GAA_ForcePlayerWalk_C' local WALK_LEASE_SECONDS=15 local WALK_HOOKS={character=true,walkInputAdd=true,walkInputRemove=true} local function addr(object) return U.key(object) end local function className(object) if not U.valid(object) then return '?' end local ok,class=pcall(function()return object:GetClass()end) if not ok or not U.valid(class) then return '?' end local named,name=pcall(function()return class:GetFName():ToString()end) return named and type(name)=='string' and name or '?' end function Aim.new(options) local log=options.log or function()end local clock=options.clock or os.clock local self={alive=true,state='idle',redirected=0,passed=0,message='没有进行中的战斗',counts={},window={}} for _,name in ipairs(ORDER)do self.counts[name]=0;self.window[name]=0 end self.counts.flying=0;self.window.flying=0 local hooks={} local fighters={} -- owned arena fighters and companions; stand sources cannot be targets local companions={} local teams={} local roster={} -- unit address -> full object identity and flying-weapon capability local walkOwners,walkActions={},{} local emptyActor local seenLines,lines={},0 local quietSince,summaryAt,passedWindow=nil,nil,0 local uninstallAt=0 local probe=nil -- a class let through during the install check only local listed={} -- class name -> whether it or a parent class is listed (左殇's knives run the base's code) local function aims(object,cls) if listed[cls]~=nil then return listed[cls] end local found=false local okClass,class=pcall(function()return object:GetClass()end) for _=1,8 do if not okClass or not U.valid(class) then break end local okName,name=pcall(function()return class:GetFName():ToString()end) if okName and AIMS[name] then found=true;break end okClass,class=pcall(function()return class:GetSuperStruct()end) end listed[cls]=found return found end local function say(text)log('[PlayerAim] '..text)end local retry=Retry.new({clock=clock,log=say}) local flyingWanted=false local iceWanted=false local flyingClasses={} local iceClasses={} local function iceCaster(actor) local leaf=className(actor) if iceClasses[leaf]~=nil then return iceClasses[leaf]end local got,cls=pcall(function()return actor:GetClass()end) local found=false for _=1,16 do if not got or not U.valid(cls)then break end local named,name=pcall(function()return cls:GetFName():ToString()end) if named and ICE_CASTERS[name]then found=true;break end got,cls=pcall(function()return cls:GetSuperStruct()end) end iceClasses[leaf]=found;return found end local function flyingCaster(actor) local leaf=className(actor) if flyingClasses[leaf]~=nil then return flyingClasses[leaf] end local ok,cls=pcall(function()return actor:GetClass()end) if not ok or not U.valid(cls) then return false end local found=false for _=1,16 do if not U.valid(cls) then break end local named,name=pcall(function()return cls:GetFName():ToString()end) if named and CASTERS[name] then found=true;break end local got,parent=pcall(function()return cls:GetSuperStruct()end) cls=got and parent or nil end flyingClasses[leaf]=found return found end -- One step from an object toward the unit it acts for: an action's or ability's own avatar first (an action may -- be a shared template whose outer is its class), then the fields, then the outer. local function step(object) local cls=className(object) local getter=(cls:find('^GA_') or cls:find('^SubGA_')) and 'GetAvatarActorFromActorInfo' or (cls:find('^GAA_') or cls:find('^GAAction_') or cls:find('^LGAAction')) and 'GetAvatarActor' if getter then local ok,avatar=pcall(function()return object[getter](object)end) avatar=ok and U.unwrap(avatar) or nil if U.valid(avatar) and addr(avatar)~=addr(object) then return avatar end end for _,field in ipairs(STEPS)do local value=U.field(object,field) if U.valid(value) then return value end end local ok,outer=pcall(function()return object:GetOuter()end) return ok and U.valid(outer) and outer or nil end local function unitOf(object) if not U.valid(object) then return nil end local okPlayer,player=pcall(function()return options.player and options.player()end) local playerKey=okPlayer and U.key(player) local current,visited=object,{} for _=1,DEPTH do local key=addr(current) if not key or key==playerKey or visited[key] then break end visited[key]=true if fighters[key] then return key end current=step(current) if not current then break end end return nil end local function opponentOf(key,castTarget,castName) if companions[key] then return options.companionTargetOf(companions[key],castTarget,castName)end return options.opponentOf(key) end local function phaseAimOpponent(key,current) if not options.phaseAimOpponent or not U.valid(current) then return end local ok,target=pcall(options.phaseAimOpponent,key,current) if ok and U.valid(target) then return target end end -- A companion's enemy of a moment ago (companion_target.lua lastEnemy), for a skill lock taken while its AI -- target key is empty; nil for blue and red, whose opponent is the arena's. local function lastEnemyOf(key) if companions[key] and type(options.companionLastEnemyOf)=='function' then return options.companionLastEnemyOf(companions[key]) end return nil end local function isPlayerActor(actor) local ok,player=pcall(function()return options.player and options.player()end) return ok and U.valid(player) and addr(player)==addr(actor) end local function sameTeam(source,target) return source==target or teams[source]~=nil and teams[source]==teams[target] end function self:ownerOf(object)return unitOf(object)end function self:hasSources()return self.alive and next(fighters)~=nil end function self:targetOf(key) if not fighters[key] then return nil end local ok,target=pcall(opponentOf,key) return ok and U.valid(target) and target or nil end -- A native story pair owns its own targets until its scoped phase finishes. local phaseErrors=0 local function phaseResult(ok,value) if not ok and phaseErrors<8 then phaseErrors=phaseErrors+1;say('阶段归属读回未确认,保留原生目标 '..tostring(value)) end return not ok or value==true end local function phaseBusy(unit) if not unit then return false end if options.phaseBusyKey then local ok,value=pcall(options.phaseBusyKey,unit) return phaseResult(ok,value) end if not options.phaseBusy then return false end local ok,actor=pcall(function()return options.actorOf and options.actorOf(unit)end) if not ok or not U.valid(actor) then return true end local called,value=pcall(options.phaseBusy,actor) return phaseResult(called,value) end function self:canRedirect(key)return self.alive and fighters[key]~=nil and not phaseBusy(key)end local iceLines=0 local function iceSpawn(_,context,actorClass,_,_,ownerParam) if not self.alive or not next(fighters) then return nil end local spawner=U.unwrap(context) if not ICE_SPAWNERS[className(spawner)] then return nil end local cls=U.unwrap(actorClass) if not U.valid(cls) then return nil end local named,name=pcall(function()return cls:GetFName():ToString()end) if not named or name~=ICE_CLASS or U.valid(U.unwrap(ownerParam)) then return nil end local kind=U.kind(ownerParam) if kind~='RemoteUnrealParam' and kind~='LocalUnrealParam' then return nil end local source=unitOf(U.field(spawner,'Source Ability')) if not source or phaseBusy(source) or options.paused and options.paused() then return nil end local got,actor=pcall(function()return options.actorOf and options.actorOf(source)end) local targeted,target=pcall(opponentOf,source) if not got or U.key(actor)~=source or not targeted or not U.valid(target) then return nil end if options.world then local known,world=pcall(options.world) if not known or not U.inWorld(spawner,world) or not U.inWorld(actor,world) then return nil end end local wrote=pcall(function()ownerParam:set(actor)end) local good=U.key(U.unwrap(ownerParam))==source if good then self.redirected=self.redirected+1 self.counts.iceSpawn=self.counts.iceSpawn+1;self.window.iceSpawn=self.window.iceSpawn+1 end if iceLines<8 then iceLines=iceLines+1 say('冰柱延迟生成保留施法归属:源='..className(actor)..';Owner参数写入='..tostring(wrote)..';读回='..tostring(good)) end return nil end -- A caller outside the list that acts for a fighting unit keeps the player; it is named once in the log, so a skill -- that still goes for the player can be found. A few tries per class, since the first object may act for nobody. local unlistedTries,unlistedLines={},0 -- Set further down: a get-player call made by a sword-rain skill starts the search for its emitters as well. local rainByCall local function noteUnlisted(object,cls,name) local tries=unlistedTries[cls] or 0 if tries>=3 or unlistedLines>=UNLISTED_LINES then return end unlistedTries[cls]=tries+1 if unitOf(object) then unlistedTries[cls]=3;unlistedLines=unlistedLines+1 say('没改写的取玩家调用 调用方='..cls..' 函数='..LABEL[name]) end end -- This cue reads Pawn 0 only for a faction check before spawning its own particles. -- Pass a confirmed NPC opponent for that one visual check when the player is neutral or friendly. local function attackFlashPawn(object,index) local flash=options.attackFlash if not flash or U.unwrap(index)~=0 then return end local color=flash:colorFor(object) if not color then return end local ok,avatar=pcall(function()return object:GetAvatarActor()end) avatar=ok and U.unwrap(avatar) or nil local unit=U.key(avatar) if not unit or fighters[unit]~=true or phaseBusy(unit) then return end if options.paused and options.paused() then return end local named,identity=pcall(function()return avatar:GetFullName()end) if not named or type(identity)~='string' or not roster[unit] or roster[unit].name~=identity then return end local player=options.player() local playerKey=U.key(player) if not playerKey or playerKey==unit then return end local relation=options.readRelation(avatar,player) if relation~=0 and relation~=1 then return end local okTarget,target=pcall(opponentOf,unit) if not okTarget then return end local targetKey=U.key(target) if not targetKey or targetKey==playerKey or sameTeam(unit,targetKey) or not U.npcPath(target) then return end if options.readRelation(avatar,target)~=2 then return end if not seenLines['attackFlash.'..color] then seenLines['attackFlash.'..color]=true say('补显示'..(color=='red' and '红光' or '蓝光')..';对玩家关系读回='..relation..';对手关系读回=2;特效由原生动作播放') end return target end local function fullName(object) local ok,name=pcall(function()return object:GetFullName()end) if ok and type(name)=='string' then return name end end local function emptyWalkActor() if emptyActor==nil then local ok,value=pcall(options.invalid or CreateInvalidObject) if ok and value~=nil and not U.valid(value) then emptyActor=value end end return emptyActor end local function noteWalk(key,text) if seenLines[key] then return end seenLines[key]=true say(text) end local function walkOwner(action) local actionKey=U.key(action) local actionName=actionKey and fullName(action) if not actionName then return end local lease=walkActions[actionKey] local now=clock() local read,avatar=pcall(function()return action:GetAvatarActor()end) avatar=read and U.unwrap(avatar) or nil local ownerKey=U.key(avatar) local ownerName=ownerKey and fullName(avatar) if ownerKey and isPlayerActor(avatar) then walkActions[actionKey]=nil return end local world=options.world and options.world() local worldKey=U.key(world) if options.world and not worldKey then return end if lease and (lease.actionName~=actionName or lease.worldKey~=worldKey or now>lease.expires) then walkActions[actionKey]=nil lease=nil end if ownerKey then if not ownerName or (worldKey and not U.inWorld(avatar,world)) then return end local named=walkOwners[ownerKey] local stillSame=lease and lease.ownerKey==ownerKey and lease.ownerName==ownerName if named==ownerName or stillSame then if stillSame then lease.expires=now+WALK_LEASE_SECONDS else walkActions[actionKey]={actionName=actionName,ownerKey=ownerKey,ownerName=ownerName, actor=avatar,worldKey=worldKey,expires=now+WALK_LEASE_SECONDS} end return true,avatar end -- A shared action now running for a different valid caster keeps its original behavior. walkActions[actionKey]=nil elseif lease then local actor=lease.actor if U.key(actor)==lease.ownerKey and fullName(actor)==lease.ownerName and (not worldKey or U.inWorld(actor,world)) and not isPlayerActor(actor) then return true,actor end return true end end local function forceWalkCharacter(action,index) if U.unwrap(index)~=0 then return end local owned,actor=walkOwner(action) if not owned then return end local inputHooksReady=hooks.walkInputAdd and hooks.walkInputRemove local answer=inputHooksReady and actor or emptyWalkActor() if answer==nil then noteWalk('walk-empty-failed','强制慢走隔离对象未读回,保留原生查找') return end self.redirected=self.redirected+1 self.counts.character=self.counts.character+1;self.window.character=self.window.character+1 if actor and inputHooksReady then noteWalk('walk-caster','改写 取玩家角色 调用方='..FORCE_WALK..' → 施法者自己 '..className(actor)..'(不作用于玩家)') elseif actor then noteWalk('walk-hook-unavailable','强制慢走输入挂钩未确认,原生玩家角色查询改为空对象') else noteWalk('walk-actor-cleared','强制慢走原施法者已离场,原生玩家角色查询改为空对象') end return answer end local function inputTagName(tag) local value=U.struct(U.unwrap(tag),'TagName') if type(value)=='string' then return value end local ok,name=pcall(function()return value:ToString()end) if ok and type(name)=='string' then return name end end local function walkInput(name,context,tag,imposer) if not self.alive or not (next(walkOwners) or next(walkActions)) then return end local action=U.unwrap(context) if className(action)~=FORCE_WALK then return end if name=='walkInputRemove' then imposer,tag=tag,U.field(action,'InputTag') end if inputTagName(tag)~='InputType.OnlyMove' or not walkOwner(action) then return end local empty=emptyWalkActor() if empty==nil then noteWalk('walk-input-unavailable','强制慢走输入隔离未读回:原生空对象不可用') return end local writable=U.kind(imposer) if writable~='RemoteUnrealParam' and writable~='LocalUnrealParam' then noteWalk('walk-input-param','强制慢走输入隔离未读回:Imposer 不可写') return end local wrote=pcall(function()imposer:set(empty)end) local read,value=pcall(function()return imposer:get()end) local blocked=wrote and read and not U.valid(value) if blocked then self.counts[name]=self.counts[name]+1;self.window[name]=self.window[name]+1 end noteWalk('walk-'..name..'-'..tostring(blocked),LABEL[name]..' InputType.OnlyMove Imposer 空对象读回='..tostring(blocked)) end local dragonReads=0 local function callback(name) return function(_,context,index) if not self.alive then return nil end if name=='character' and options.boundaryCharacter then local answer=options.boundaryCharacter(context,index) if answer~=nil then return answer end end local lookForWalk=name=='character' and (next(walkOwners) or next(walkActions)) if not lookForWalk and not next(fighters) then return nil end local object=U.unwrap(context) if not U.valid(object) then return nil end local cls=className(object) if lookForWalk and cls==FORCE_WALK then return forceWalkCharacter(object,index) end if not next(fighters) then return nil end if name=='pawn' and cls=='GAAction_WeaponParticle_BlueRedEye_C' then return attackFlashPawn(object,index) end if options.formationPlayerLookup and ((name=='character' and cls=='GA_HuaShan_Troop_Healing_C') or (name=='pawn' and cls=='GA_HuaShan_RedTroop_BigBro_Skill_08_01_C')) and U.unwrap(index)==0 then local answer=options.formationPlayerLookup(object) if answer~=nil then return answer end end local unit local warning=name=='pawn' and cls=='GAAction_ParticleOnPlayer_C' if warning then -- This shared action is redirected only for inspected offensive telegraphs. local got,ability=pcall(function()return object:GetAbility()end) ability=got and U.unwrap(ability) or nil if not U.valid(ability) or not WARNING_SKILLS[className(ability)] then return nil end local found,avatar=pcall(function()return object:GetAvatarActor()end) local key=found and U.key(U.unwrap(avatar)) if key and fighters[key]==true then unit=key end else if cls~=probe and not aims(object,cls) then if name=='pawn' and rainByCall then rainByCall(object,cls) end noteUnlisted(object,cls,name);return nil end unit=unitOf(object) end if not unit or phaseBusy(unit) or (options.paused and options.paused()) then self.passed=self.passed+1;passedWindow=passedWindow+1;return nil end local ok,target=pcall(opponentOf,unit) if not ok or not U.valid(target) then self.passed=self.passed+1;passedWindow=passedWindow+1;return nil end if warning and not U.npcPath(target) then return nil end if cls=='BP_ZuoShang_P2_DragonPillarBullet_C' and name=='pawn' and dragonReads<20 and className(target)=='BP_Monster_MoTian_C' then dragonReads=dragonReads+1 local mesh=U.field(target,'Mesh') local animOk,anim=false,nil if U.valid(mesh) then animOk,anim=pcall(function()return mesh:GetAnimInstance()end) end local playing,montage=false,nil if animOk and U.valid(anim) then playing,montage=pcall(function()return anim:GetCurrentActiveMontage()end) end local asc=U.field(target,'AbilitySystemComponent') local function count(tag) if not U.valid(asc) then return '?' end local ok,n=pcall(function()return asc:GetGameplayTagCount({TagName=FName(tag)})end) return ok and tonumber(U.unwrap(n)) or '?' end local identified,motion=false,nil if playing and U.valid(montage) then identified,motion=pcall(function()return montage:GetFullName()end) end say('龙柱起飞 魔渊实例='..tostring(U.key(target))..' 当前动作='..tostring(identified and motion or '无读回') ..' 动作中='..count('Ability.Action')..' 破防='..count('CharacterState.Stand.Break')) end if cls==probe and not AIMS[cls] then return target end self.redirected=self.redirected+1 self.counts[name]=self.counts[name]+1;self.window[name]=self.window[name]+1 local where=className(object) if lines %s%s 写入=%s%s 读回=%s',className(ability),beforeOwner,className(target),remembered and '(AI 目标暂时为空,用刚才的敌人)' or '',tostring(okSet),okSet and '' or '('..tostring(err)..')',good and '生效' or '没生效')) end return good end -- Any skill: the ability's own lock (BP_ActionAbilityBase.Request Lock Target; a blueprint hook's callback runs after the -- function) came out on the player, for one of this mod's fighting units. The stored lock and the answer go to its -- opponent, and the skill is named, so the log shows which skills were doing it. local function isPlayer(actor) if className(actor):find('^BP_RenewalPlayer') then return true end local ok,player=pcall(function()return options.player and options.player()end) return ok and U.valid(player) and addr(player)==addr(actor) end local lockLines={} local function relock(context,_,_,out) if not self.alive or not next(fighters) then return nil end local ability=U.unwrap(context) if not U.valid(ability) then return nil end local lock=U.field(ability,'Lock Target') local comp=lock and U.struct(lock,'Component') if not U.valid(comp) then return nil end local okOwner,owner=pcall(function()return comp:GetOwner()end) if not okOwner or not U.valid(owner) then return nil end local onStand=fighters[U.key(owner)]=='stand' local unit=unitOf(ability) if not unit or phaseBusy(unit) or (options.paused and options.paused()) then return nil end local onAlly=sameTeam(unit,U.key(owner)) local phaseTarget=phaseAimOpponent(unit,owner) if not phaseTarget and not onStand and not onAlly and not isPlayer(owner) then return nil end local okTarget,target=true,phaseTarget if not target then okTarget,target=pcall(opponentOf,unit) end if not okTarget or not U.valid(target) then okTarget,target=pcall(lastEnemyOf,unit) end if not okTarget or not U.valid(target) then return nil end local root=U.field(target,'RootComponent') if not U.valid(root) then return nil end local okSet=pcall(function()ability['Lock Target']={Component=root,SocketName=FName('None')} end) local okOut=out~=nil and pcall(function()out:set({Component=root,SocketName=FName('None')})end) self.redirected=self.redirected+1 self.counts.lock=self.counts.lock+1;self.window.lock=self.window.lock+1 local where=className(ability) if (lockLines[where] or 0)<2 then lockLines[where]=(lockLines[where] or 0)+1 local back=U.field(ability,'Lock Target') say(string.format('招式的锁定落在%s,改成对手 招式=%s -> %s 写入=%s 返回值=%s 读回=%s 累计=%d',phaseTarget and '上桩烈焰' or onStand and '替身' or onAlly and '友方' or '玩家',where,className(target),tostring(okSet),tostring(okOut), addr(back and U.struct(back,'Component'))==addr(root) and '生效' or '没生效',self.counts.lock)) end return nil end -- Where a bullet gets its target: its data's selector, called natively (UBulletTargetSelectorBase.SelectTarget), which -- fills the Target out parameter. 左殇's flying swords hover (BulletMovementData_Rotation), home for 0.2 s toward that -- target, then fly straight, so it decides where they all go. A bullet of a fighting unit aimed at anything but another -- fighting unit goes to the unit's opponent, and each skill is named once with what it had, on the player or not. local bulletLines,bulletSeen=0,{} local function retarget(route,_,avatar,_,ability,_,_,out) if not self.alive or not next(fighters) then return nil end local owner=U.unwrap(avatar) if not U.valid(owner) then return nil end local key=U.key(owner) if not key or not fighters[key] or phaseBusy(key) or (options.paused and options.paused()) then return nil end local okTarget,target=pcall(opponentOf,key) if not okTarget or not U.valid(target) then okTarget,target=pcall(lastEnemyOf,key) if not okTarget then target=nil end end local current=out and U.unwrap(out) local comp=current and U.struct(current,'Component') local had='空' if U.valid(comp) then local okOwner,hit=pcall(function()return comp:GetOwner()end) if okOwner and U.valid(hit) then had=className(hit) local intended=companions[key] and U.key(target) if intended and U.key(hit)==intended then return nil end if companions[key] and not U.valid(target) and isPlayer(hit) then return false end local phaseTarget=phaseAimOpponent(key,hit) if phaseTarget then target=phaseTarget elseif fighters[U.key(hit)]==true and not sameTeam(key,U.key(hit)) then local where=U.valid(U.unwrap(ability)) and className(U.unwrap(ability)) or '?' if not bulletSeen['ok'..where] and bulletLines %s 写入=%s 读回=%s 累计=%d',where,had,className(target),tostring(okSet), verified and '生效' or '失败,本次选敌作废',self.counts[route])) end return verified end -- Once a flying weapon starts: a target that is not a fighting unit becomes the opponent, on the bullet itself. When it -- ends: where it is against the player, its target and its caster, which says what it really flew at. local function place(actor) if not U.valid(actor) then return nil end local ok,at=pcall(function()return actor:K2_GetActorLocation()end) return ok and at or nil end local function metres(a,b) local okA,ax,ay,az=pcall(function()return a.X,a.Y,a.Z end) local okB,bx,by,bz=pcall(function()return b.X,b.Y,b.Z end) if not okA or not okB or type(ax)~='number' or type(bx)~='number' then return '?' end return string.format('%.1fm',math.sqrt((ax-bx)^2+(ay-by)^2+(az-bz)^2)/100) end local function holderOf(bullet) local field=U.field(bullet,'CurrentTarget') local comp=field and U.struct(field,'Component') if not U.valid(comp) then return nil,nil end local ok,hit=pcall(function()return comp:GetOwner()end) return comp,ok and U.valid(hit) and hit or nil end local flightLines,flightSeen=0,{} local function flight(kind,context) if not self.alive or not next(fighters) then return nil end local bullet=U.unwrap(context) if not U.valid(bullet) then return nil end local owner=U.field(bullet,'BulletOwnerAvatar') local key=U.valid(owner) and U.key(owner) if not key or not fighters[key] or phaseBusy(key) then return nil end local okTarget,target=pcall(opponentOf,key) target=okTarget and U.valid(target) and target or nil local _,hit=holderOf(bullet) local phaseTarget=kind=='start' and phaseAimOpponent(key,hit) if phaseTarget then target=phaseTarget end local note='' if kind=='start' and target and (phaseTarget or not (hit and fighters[U.key(hit)]==true and not sameTeam(key,U.key(hit)))) and not (options.paused and options.paused()) then local root=U.field(target,'RootComponent') if U.valid(root) then local had=hit and className(hit) or '空' local okSet=pcall(function()bullet.CurrentTarget={Component=root,SocketName=FName('None')} end) local comp=holderOf(bullet) self.redirected=self.redirected+1 self.counts.flying=self.counts.flying+1;self.window.flying=self.window.flying+1 note=string.format(' 原目标=%s 改成对手 写入=%s 读回=%s',had,tostring(okSet),addr(comp)==addr(root) and '生效' or '没生效') end end local source=U.field(bullet,'BulletSourceAbility') source=U.valid(source) and className(source) or '?' -- A few lines per bullet class and skill: one busy skill must not use up the log for the rest of the fight. local line=className(bullet)..'|'..source..'|'..kind flightSeen[line]=(flightSeen[line] or 0)+1 if flightSeen[line]>FLIGHT_PER_KIND or flightLines>=FLIGHT_LINES then return nil end flightLines=flightLines+1 local at=place(bullet) local okPlayer,player=pcall(function()return options.player and options.player()end) local _,now=holderOf(bullet) say(string.format('%s %s 招式=%s 当前目标=%s 距玩家=%s 距对手=%s 距施法者=%s%s',className(bullet),kind=='start' and '起飞' or '结束', source,now and className(now) or '空', okPlayer and U.valid(player) and metres(at,place(player)) or '?',target and metres(at,place(target)) or '?',metres(at,place(owner)),note)) return nil end -- One call with a unit as the world context: the hook must answer with its opponent, not the player. local function selfCheck() local lib=options.statics and options.statics() local unit for key in pairs(fighters)do unit=key;break end local actor=unit and options.actorOf and options.actorOf(unit) if not U.valid(lib) or not U.valid(actor) then say('自检跳过:函数库或参战单位不可用');return end local okWant,wanted=pcall(opponentOf,unit) probe=className(actor) local ok,got=pcall(function()return lib:GetPlayerCharacter(actor,0)end) probe=nil got=ok and U.unwrap(got) or nil local same=okWant and U.valid(wanted) and addr(got)==addr(wanted) say(string.format('自检(临时放行该单位的类):以 %s 为上下文取玩家角色 → %s;应为对手 %s;改写生效=%s%s',className(actor), U.valid(got) and className(got) or '空',okWant and U.valid(wanted) and className(wanted) or '无',tostring(same), ok and '' or ' 错误='..tostring(got))) end local effects,rainSearch,effectLoop={},{},nil local effectGeneration,effectCancelAt=0,0 local function nameOf(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 stopEffectLoop(force) if not effectLoop then return end if not force then if clock()80 then -- A cast whose emitters were not all found: what the searches saw (the rain then keeps the game's own target). if request.cast and request.left>0 then local s=request.seen or {} sayEffect(string.format('剑雨发射器没找全:还差%d个;搜索%d轮(读不到列表%d轮) 属于施法者的特效子弹=%d 其中在运行=%d 数据对得上=%d 组件对得上=%d 缺组件=%d 系统不符=%d 归属不符=%d 多组件=%d%s%s%s', request.left,s.scans or 0,s.empty or 0,s.owned or 0,s.live or 0,s.data or 0,s.adopted or 0,s.component or 0,s.system or 0,s.ownership or 0,s.ambiguous or 0,request.rejected or '', request.otherData and(' 见到别的数据='..tostring(request.otherData))or'', not fighters[owner] and' 施法者已不在名单'or phaseBusy(owner)and' 施法者在转阶段'or'')) end rainSearch[owner]=nil elseif RAIN_SCANS[request.tick] then search=true end end local frame={} if search then scanEffects(frame) end local now,spots=clock(),{} local paused=options.paused and options.paused() for key,item in pairs(effects)do local status=statusOf(item.bullet) if (status==RUNNING or status==READY) and now-item.since whether it or a parent is in EFFECT_SKILLS local function skillKind(ability,name) if effectSkillClass[name]==nil then -- A skill's subclasses play the same effect (GA_ZuoShang_P2_Skill_17_NoCD, ..._Sword_2Hit_A_FastCancel). local found=false local okClass,class=pcall(function()return ability:GetClass()end) for _=1,8 do if not okClass or not U.valid(class) then break end local okName,parent=pcall(function()return class:GetFName():ToString()end) if okName and parent=='GA_ZuoShang_Skill_19_C' then found='rain';break end if okName and EFFECT_SKILLS[parent] then found=true;break end okClass,class=pcall(function()return class:GetSuperStruct()end) end effectSkillClass[name]=found end return effectSkillClass[name] end -- One cast of the rain, whichever of its two starts is seen first: the skill's own activation (a blueprint hook on -- the base class's K2_ActivateAbility) or the first GetPlayerPawn the skill makes (a native hook, seen in a -- tester's log for this very skill while no emitter was ever found). RAIN_AGAIN keeps one cast from starting twice. local rainStarted={} local function startRain(unit,name,how) local now=clock() if rainSearch[unit] and rainSearch[unit].cast and rainStarted[unit] and now-rainStarted[unit]0 then return end pendingHits[key]=nil if sample.nested or sample.entry~=entry then return end local after=options.hp(target) say('梦华随从弹体伤害调用 弹体='..sample.data..' 施法者='..caster..' 受击者='..sample.target ..'('..targetKey..') HP='..tostring(sample.hp)..' -> '..tostring(after)) return end if sample then sample.depth=sample.depth+1;sample.nested=true;return end if entry.hitCount>=48 then return end local data=nameOf(U.field(module,'BulletData')) local receiver=className(target) local kind=data..'/'..receiver local count=entry.hitKinds[kind] or 0 if count>=2 then return end entry.hitCount=entry.hitCount+1;entry.hitKinds[kind]=count+1 pendingHits[key]={entry=entry,data=data,target=receiver,hp=options.hp(target),depth=1} end local function syncHitProbe(now) local name='menghuaHit' local path=Aim.paths[name] pendingHits={} if menghuaHits and not hooks[name] and retry:ready(path) then local ok,pre,post=pcall(RegisterHook,path,function(...)sampleHit(false,...)end,function(...)sampleHit(true,...)end) local installed=ok and type(pre)=='number' and type(post)=='number' retry:result(path,installed) if installed then hooks[name]={pre=pre,post=post} end elseif not menghuaHits and hooks[name] and now>=removeHitAt then removeHitAt=now+1 local h=hooks[name];local ok,result=pcall(UnregisterHook,path,h.pre,h.post) if ok and result~=false then hooks[name]=nil end end end -- A blueprint that is not loaded yet (a selector comes in with the first bullet data) is tried again while the fight runs. local function needed(name) local walkReady=WALK_HOOKS[name] and (next(walkOwners) or next(walkActions)) return (walkReady or next(fighters)~=nil) and not hooks[name] and (not FLYING[name] or flyingWanted) and (name~='iceSpawn' or iceWanted) and (not RAIN_END[name] or next(rainSearch) or next(effects)) end register=function(name) if not needed(name) then return end local path=Aim.paths[name] if not retry:ready(path) or not retry:ready(path..':register') then return end local okFind,found=pcall(StaticFindObject,path) retry:result(path,okFind and U.valid(found)) if not okFind or not U.valid(found) then return end local handler=name=='force' and forced or name=='lock' and relock or (name=='bullet' or name=='bulletAbility') and function(...)return retarget(name,...)end or name=='launch' and launched or name=='skillStart' and skillStarted or RAIN_END[name] and retireParticle or name=='iceSpawn' and iceSpawn or (name=='walkInputAdd' or name=='walkInputRemove') and function(_,...)walkInput(name,...)end or FLYING[name] and function(context) self.counts[name]=self.counts[name]+1;self.window[name]=self.window[name]+1 return flight(FLYING[name],context) end or callback(name) local ok,pre,post=pcall(RegisterHook,path,handler,function()end) local registered=ok and type(pre)=='number' and type(post)=='number' retry:result(path..':register',registered,not registered and tostring(pre) or nil) if registered then hooks[name]={pre=pre,post=post};say('挂钩注册ID读回 '..name..' pre='..pre..' post='..post) end end local function armWalkHooks() register('character') register('walkInputAdd') register('walkInputRemove') end local function canOwnWalk(member) return member.team=='blue' or member.team=='red' or (member.team=='companion' and type(options.companionTargetOf)=='function') end -- The controller publishes summoned actors before finishing their spawn or starting AI. -- Keep these three guards ready for native opening moves even when the duel has not ticked. function self:prepareWalk(members) if not self.alive then return end local current={} for _,member in ipairs(members)do if canOwnWalk(member) then local key=U.key(member.actor) if key then current[key]=fullName(member.actor) end end end walkOwners=current if next(walkOwners) then armWalkHooks() end end local function install() for _,fn in ipairs({'StaticFindObject','RegisterHook','UnregisterHook'})do if type(_G[fn])~='function' then self.state='failed';self.message='缺少 '..fn;say(self.message);return end end for _,name in ipairs(ORDER)do register(name) end if next(hooks) then self.state='running';self.message='参战单位与随从的攻击取当前敌人' selfCheck() else self.state='failed';self.message='取玩家函数挂钩失败' end end local function uninstall(reason,force,restore) if not next(hooks) and not effectLoop and not next(effects) then return end if not force then if clock()lease.expires or options.world and lease.worldKey~=worldKey then walkActions[key]=nil end end fighters=units if added then retry:reset() end if next(fighters) then quietSince=nil if self.state=='idle' then install() else for _,name in ipairs(ORDER)do register(name) end end else if next(walkOwners) or next(walkActions) then armWalkHooks() end if next(walkActions) or options.boundaryPending and options.boundaryPending() then quietSince=nil -- A force-walk or native field can finish after the roster changes. elseif next(hooks) and (not next(walkOwners) or self.state~='idle') then quietSince=quietSince or now if now-quietSince>=UNHOOK_SECONDS then uninstall('战斗已结束') end end end if menghuaHits or hooks.menghuaHit then syncHitProbe(now) end summaryAt=summaryAt or now if now-summaryAt>=SUMMARY_SECONDS then if next(hooks) then local parts={} for _,name in ipairs(ORDER)do parts[#parts+1]=LABEL[name]..'='..self.window[name];self.window[name]=0 end parts[#parts+1]=LABEL.flying..'='..self.window.flying;self.window.flying=0 say(string.format('近 %.0f 秒:改写 %s 其他调用照旧=%d',now-summaryAt,table.concat(parts,' '),passedWindow)) passedWindow=0 end summaryAt=now end end function self:status()return {state=self.state,redirected=self.redirected,passed=self.passed,message=self.message}end function self:silence(reason,onGameThread) self.alive=false;walkOwners,walkActions={},{} uninstall(reason or 'Mod卸载',true,onGameThread==true) end return self end return Aim