local U=require('ue_observe') local P=require('companion_profile') local Stats=require('character_stats') local Native={} local function call(obj,method,...) if not U.valid(obj) then return nil end local ok,v=pcall(function(...)return obj[method](obj,...)end,...);if ok then return U.unwrap(v) end end local function id(actor) local key=U.key(actor);local name=key and call(actor,'GetFullName') if type(name)=='string' then return key,name end end local function finite(n)return type(n)=='number' and n==n and math.abs(n)0 or attackers and attackers>0 if not combat and (r.pose or r.waiting) then local attackersOfPlayer=U.arraySize(U.field(U.field(o.player(),'BP_PBZHatredManagerComponent'),'BeHatredList')) combat=attackersOfPlayer and attackersOfPlayer>0 end local safe=not o.blocked(actor) and U.field(ai,'bAIStarted')==true local canSwitch if checkAction~=false then canSwitch=safe and o.actionBusy(actor)==false end return {hp=hp,max=max,target=target,attackers=attackers,combat=combat==true, known=known==true and hates~=nil and attackers~=nil and (idle or combat==true),safe=safe,canSwitch=canSwitch} end local function writeValue(actor,field,value) local ok=attrs:writeBase(actor,field,value) return ok and Stats.close(attrs:nativeValue(actor,field),value) end local function stopPose(r) local pose=r.pose if not pose then return true end if same(call(U.field(r.actor,'Mesh'),'GetAnimInstance'),pose.anim) and call(pose.anim,'Montage_IsPlaying',pose.montage)==true then call(pose.anim,'Montage_Stop',0,pose.montage) if call(pose.anim,'Montage_IsPlaying',pose.montage)~=false then return false end end r.pose=nil;return true end local function resume(r) local lease=r.lease if not lease then return true end local controller=U.field(r.actor,'Controller') local brain=U.field(controller,'BrainComponent') if not U.valid(lease) then r.lease=nil;return true end if not same(U.field(controller,'Pawn'),r.actor) or not same(U.field(brain,'AIOwner'),controller) then return false end if same(brain,lease) then local paused=call(brain,'IsPaused') if paused==nil then return false end if paused then call(lib(),'ResumeLogic',brain,'PhantomGladiator companion command ended') if call(brain,'IsPaused')~=false then return false end end end r.lease=nil;return true end local function restoreTargetable(r) if not r.hatred then return true end local hm=U.field(r.actor,'BP_PBZHatredManagerComponent') if U.valid(r.hatred) then if not same(call(hm,'GetOwner'),r.actor) then return false end if same(hm,r.hatred) then local current=U.field(hm,'CanBeHatredNow') if type(current)~='boolean' then return false end if not current then pcall(function()hm.CanBeHatredNow=true end) if U.field(hm,'CanBeHatredNow')~=true then return false end end end end r.hatred=nil;return true end function self.release(r) local pose,brain,aggro=stopPose(r),resume(r),restoreTargetable(r) return pose and brain and aggro end -- A pause owned by this module can outlast the target blackboard that led to it. local function releaseUnused(r) if r.p.targetable~=0 then restoreTargetable(r) end if r.p.behavior=='active' and not r.pose and not r.waiting then return resume(r) end return true end local function behave(r,v) local actor,player=r.actor,nil local aggroReady=true if r.p.targetable==0 then local hm=U.field(actor,'BP_PBZHatredManagerComponent') if same(call(hm,'GetOwner'),actor) and U.field(hm,'CanBeHatredNow')==true then pcall(function()hm.CanBeHatredNow=false end) if U.field(hm,'CanBeHatredNow')==false then r.hatred=hm end end aggroReady=U.field(hm,'CanBeHatredNow')==false else aggroReady=restoreTargetable(r) end local assist=false if r.p.behavior=='assist' then player=o.player() local theirs=U.field(player,'BP_PBZHatredManagerComponent') local attacked=U.arraySize(U.field(theirs,'BeHatredList')) local attackers=v.attackers if r.lastHP and v.hp0 or attackers and attackers>0 or o.now()<(r.defendUntil or 0) end r.lastHP=v.hp;r.defending=assist==true if v.combat then r.waiting=nil end local hold=r.waiting or r.pose or r.p.behavior=='peace' or r.p.behavior=='assist' and not assist if not hold then return resume(r) and aggroReady end local controller=U.field(actor,'Controller');local brain=U.field(controller,'BrainComponent') if not same(U.field(controller,'Pawn'),actor) or not same(U.field(brain,'AIOwner'),controller) then return false end local paused=call(brain,'IsPaused') if r.lease and (not same(brain,r.lease) or paused==false) then r.lease=nil end if not r.lease then if paused~=false or call(brain,'IsRunning')~=true then return false end call(lib(),'PauseLogic',brain,'PhantomGladiator companion command') if call(brain,'IsPaused')~=true then return false end r.lease=brain call(controller,'StopMovement') end if r.waiting or r.pose or o.now()<(r.nextMove or 0) then return aggroReady end player=player or o.player() if not U.valid(player) then return false end local here,there=vec(o.location(actor)),vec(o.location(player)) if here and there then if o.keepFollowing and not v.combat then o.keepFollowing(actor,player) end local gap=(here.X-there.X)^2+(here.Y-there.Y)^2+(here.Z-there.Z)^2 if gap>(r.p.distance*100)^2 and call(controller,'GetMoveStatus')~=3 then call(StaticFindObject('/Script/AIModule.Default__AIBlueprintHelperLibrary'),'SimpleMoveToActor',controller,player) elseif gap<=(r.p.distance*100)^2 and call(controller,'GetMoveStatus')==3 then call(controller,'StopMovement') end r.nextMove=o.now()+1 end return aggroReady end function self.transfer(r,world,why,initial) local v=sample(r) if not v or not v.safe or not v.canSwitch or not v.known or v.hp<=0 or v.combat~=initial.combat or not own(r.actor,world) or not P.phase(U.npcPath(r.actor)) then return nil,'原形态当前不可切换' end local at,facing=vec(o.location(r.actor)),rotation(r.actor) if not at or not facing then return nil,'位置或朝向未确认' end local transfer={old=r.actor,world=world,wasCombat=v.combat,target=v.target,at=at,resources={}, transform={Translation=at,Rotation=facing,Scale3D={X=1,Y=1,Z=1}}} for _,field in ipairs({'Health','Shachi'})do local value,limit=attrs:read(r.actor,field),attrs:read(r.actor,field..'_Max') if not value or not limit or limit.current<=0 or value.current<0 or value.current>limit.current+.001 then return nil,'生命或杀气无法换算' end transfer.resources[field]={ratio=math.min(1,value.current/limit.current),original=value.current,max=limit.current} end return transfer end function self.commitReady(r,new,x,world) if not same(world,o.world()) or not own(new,world) then return false end local v=sample(r) if not v or not v.safe or not v.canSwitch or not v.known or v.combat~=x.wasCombat or (v.target or x.target) and not same(v.target,x.target) then return false end for _,field in ipairs({'Health','Shachi'})do local entry=attrs:read(r.actor,field) if not entry or not Stats.close(entry.current,x.resources[field].original) then return false end end return true end function self.restore(r,new,x,why,world) local fresh=sample(r);local here=vec(o.location(new));local old=vec(o.location(r.actor)) if not here or not old or not same(world,x.world) or not same(world,o.world()) or not own(new,world) or not fresh or not fresh.safe or not fresh.canSwitch or not fresh.known or fresh.hp<=0 or fresh.combat~=x.wasCombat then return false,'战斗状态已改变' end local function close(p)return (p.X-x.at.X)^2+(p.Y-x.at.Y)^2+(p.Z-x.at.Z)^2<=150^2 end if not close(here) or not close(old) then return false,'转换时位置发生变化' end local face=rotation(new);local before=x.transform.Rotation if not face or math.abs(face.X*before.X+face.Y*before.Y+face.Z*before.Z+face.W*before.W)<.99 then return false,'新形态朝向未确认' end for _,field in ipairs({'Health','Shachi'})do local a=x.resources[field];local value=attrs:read(r.actor,field);local oldMax=attrs:read(r.actor,field..'_Max') local max=attrs:read(new,field..'_Max') if not max or not oldMax or not value or not Stats.close(value.current,a.original) or not Stats.close(oldMax.current,a.max) or max.current<=0 or not writeValue(new,field,max.current*a.ratio) then return false,'转换资源读回失败 '..field end end if x.target then if not same(x.target,fresh.target) or not own(x.target,world) or same(x.target,o.player()) or call(U.field(new,'Faction Component'),'GetFactionRelation',x.target)~=2 then return false,'转换时敌人发生变化' end local ai=o.ai(new);local ok=pcall(function()ai:ForceIntoCombat(x.target)end) if not ok then return false,'无法交接当前目标' end local list=U.array(U.field(U.field(new,'BP_PBZHatredManagerComponent'),'HatredList')) local held=false;for _,target in ipairs(list or {})do if same(target,x.target) then held=true end end if not held then return false,'目标仇恨尚未读回' end end return true end function self.pose(r) if r.pose then local ok=stopPose(r);return {ok=ok,message=ok and '已结束合影动作' or '动作取消未确认'} end local name=r.phase==2 and 'MuXiaoKui_P2' or 'MuXiaoKui' local base='/HuaShira/Characters/EliteBoss/'..name..'/' local path=base..'Anim/'..name..'_ShowPose.'..name..'_ShowPose' local mesh=U.field(r.actor,'Mesh');local anim=call(mesh,'GetAnimInstance') local loaded,asset=pcall(LoadAsset,path) local skeleton=call(call(mesh,'GetSkeletalMeshAsset'),'GetSkeleton') if not loaded or not U.valid(asset) or not same(U.field(asset,'Skeleton'),skeleton) or call(anim,'IsAnyMontagePlaying')~=false then return {ok=false,message='当前骨骼或动作不支持合影'} end call(anim,'PlaySlotAnimationAsDynamicMontage',asset,FName('DefaultSlot'),.15,.15,1,1,-1,0) local m=call(anim,'GetCurrentActiveMontage') if not U.valid(m) or call(anim,'DynamicMontage_IsPlayingFrom',asset)~=true then return {ok=false,message='合影动作未读回'} end r.pose={anim=anim,montage=m};return {ok=true,message='已播放当前形态的展示动作'} end local nextPreference,lastPreference,turn,preferenceLogs=0,0,0,0 local function prefer(members,candidates,now) if now0 and not o.blocked(candidate) and call(U.field(enemy,'Faction Component'),'GetFactionRelation',candidate)==2 then local at=vec(o.location(candidate)) if at then local d=(here.X-at.X)^2+(here.Y-at.Y)^2+(here.Z-at.Z)^2 if d