Files
zzz_REBIRTH__Utils/Scripts/EAI/NPCs/V2/EAIFollowLeaderCompanion.cs
2025-06-04 16:44:53 +09:30

379 lines
13 KiB
C#

using GamePath;
using System.Collections.Generic;
using System.Globalization;
using System.Xml;
using UnityEngine.Scripting;
using static BlendCycleTimer;
using static EntityDrone;
[Preserve]
public class EAIFollowLeaderCompanion : EAITarget
{
public override void Init(EntityAlive _theEntity)
{
base.Init(_theEntity, 25f, true);
this.MutexBits = 1;
}
public override void Start()
{
this.entityPlayerVel = Vector3.zero;
this.relocateTicks = 0;
this.pathCounter = 0;
this.theEntity.ConditionalTriggerSleeperWakeUp();
base.Start();
}
public bool NPCEAICanProceed()
{
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed START");
bool result = true;
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
if (this.OwnerID == 0)
{
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 0");
return false;
}
if (this.theEntity.Buffs.GetCustomVar("onMission") == 1f ||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Respawn") == 1f ||
this.theEntity.Buffs.GetCustomVar("$FR_NPC_Hidden") == 1f
)
{
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 1");
return false;
}
if (this.theEntity.GetAttackTarget() != null)
{
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 1a");
return false;
}
if (this.theEntity.Buffs.GetCustomVar("$IsBackingUp") == 1f)
{
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 2");
return false;
}
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
if (this.theEntity.emodel.IsRagdollActive)
{
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 3");
return false;
}
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
{
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 4");
return false;
}
if (this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Follow)
{
//Log.Out("EAIFollowLeaderCompanion-CanExecute IS NOT FOLLOWING");
return false;
}
/*bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");*/
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
if (stopAttacking)
{
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 5");
this.theEntity.SetRevengeTarget(null);
this.theEntity.SetAttackTarget(null, 0);
return false;
}
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None)
{
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed 6");
return false;
}
//Log.Out("EAIFollowLeaderCompanion-NPCEAICanProceed result: " + result);
return result;
}
public override bool CanExecute()
{
//Log.Out("EAIFollowLeaderCompanion-CanExecute START");
if (!NPCEAICanProceed())
{
return false;
}
if (this.targetPlayer == null)
{
//Log.Out("EAIFollowLeaderCompanion-CanExecute 2");
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
if (this.OwnerID > 0)
{
//Log.Out("EAIFollowLeaderCompanion-CanExecute this.OwnerID: " + this.OwnerID);
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
if (entityPlayer != null)
{
this.targetPlayer = entityPlayer;
return true;
}
}
return false;
}
//Log.Out("EAIFollowLeaderCompanion-CanExecute this.theEntity.GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
return false;
}
public override bool Continue()
{
//Log.Out("EAIFollowLeaderCompanion-Continue START");
if (!NPCEAICanProceed())
{
return false;
}
if (pathCounter == 0)
{
return false;
}
return true;
}
public override void Update()
{
//Log.Out("EAIFollowLeaderCompanion-Update START");
if (!NPCEAICanProceed())
{
return;
}
if (this.targetPlayer == null)
{
//Log.Out("EAIFollowLeaderCompanion-Update 2");
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
if (this.OwnerID > 0)
{
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.OwnerID);
EntityPlayer entityPlayer = (EntityPlayer)this.theEntity.world.GetEntity(this.OwnerID);
if (entityPlayer != null)
{
this.targetPlayer = entityPlayer;
//Log.Out("EAIFollowLeaderCompanion-Update FOUND OWNER");
}
}
}
EntityUtilities.CheckForClosedDoor(this.theEntity);
if (this.relocateTicks > 0)
{
//Log.Out("EAIFollowLeaderCompanion-Update 2");
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
{
//Log.Out("EAIFollowLeaderCompanion-Update 3");
this.relocateTicks--;
this.theEntity.moveHelper.SetFocusPos(this.targetPlayer.position);
return;
}
this.relocateTicks = 0;
}
Vector3 vector2 = this.targetPlayer.position;
Vector3 a = theEntity.position - vector2;
//Log.Out("EAIFollowLeaderCompanion-Update entityTargetPosn: " + vector2);
//Log.Out("EAIFollowLeaderCompanion-Update a: " + a);
//Log.Out("EAIFollowLeaderCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
//Log.Out("EAIFollowLeaderCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
float magnitude = 30f;
bool isClient = SingletonMonoBehaviour<ConnectionManager>.Instance.IsClient;
if (isClient)
{
magnitude = 3f;
}
//Log.Out("EAIFollowLeaderCompanion-Update magnitude: " + magnitude);
if (this.targetPlayer.entityId == this.OwnerID && a.sqrMagnitude < magnitude)
{
//Log.Out("EAIFollowLeaderCompanion-Update Entity is too close. Ending pathing.");
//this.theEntity.navigator?.clearPath();
this.theEntity.moveHelper.Stop();
pathCounter = 0;
return;
}
if (this.targetPlayer.entityId == this.OwnerID)
{
if (!this.theEntity.HasAnyTags(FastTags<TagGroup.Global>.Parse("allyanimal")))
{
this.theEntity.Crouching = this.targetPlayer.Crouching;
}
//Log.Out("EAIFollowLeaderCompanion-Update theEntity.moveHelper.BlockedTime: " + theEntity.moveHelper.BlockedTime);
if (theEntity.moveHelper.BlockedTime > 3f)
{
EntityAliveV2 npc = this.theEntity as EntityAliveV2;
if (npc != null)
{
npc.TeleportToPlayer(this.targetPlayer, false);
}
}
}
//Log.Out("EAIFollowLeaderCompanion-Update SetLookPosition");
theEntity.SetLookPosition(vector2);
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
if (a.sqrMagnitude < 1f)
{
//Log.Out("EAIFollowLeaderCompanion-Update 6");
this.entityPlayerVel = this.entityPlayerVel * 0.7f + a * 0.3f;
}
this.entityPlayerPos = vector2;
this.theEntity.moveHelper.CalcIfUnreachablePos();
float num2;
float num3;
num2 = 1.095f;
num3 = Utils.FastMax(0.7f, num2 - 0.35f);
float num4 = num3 * num3;
float num5 = 4f;
if (this.theEntity.IsFeral)
{
num5 = 8f;
}
num5 = base.RandomFloat * num5;
float targetXZDistanceSq = this.GetTargetXZDistanceSq(num5);
float num6 = vector2.y - this.theEntity.position.y;
float num7 = Utils.FastAbs(num6);
bool flag = targetXZDistanceSq <= num4 && num7 < 1f;
if (!flag)
{
//Log.Out("EAIFollowLeaderCompanion-Update 9");
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
{
//Log.Out("EAIFollowLeaderCompanion-Update 10");
PathEntity path = this.theEntity.navigator.getPath();
if (path != null && path.NodeCountRemaining() <= 2)
{
//Log.Out("EAIFollowLeaderCompanion-Update 11");
this.pathCounter = 0;
}
}
int num = this.pathCounter - 1;
this.pathCounter = num;
if (num <= 0 && this.theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
{
//Log.Out("EAIFollowLeaderCompanion-Update 12");
this.pathCounter = 6 + base.GetRandom(10);
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.targetPlayer.position,5);
if (moveToLocation.y - this.theEntity.position.y < -8f)
{
//Log.Out("EAIFollowLeaderCompanion-Update 13");
this.pathCounter += 40;
if (base.RandomFloat < 0.2f)
{
//Log.Out("EAIFollowLeaderCompanion-Update 14");
this.seekPosOffset.x = this.seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f);
this.seekPosOffset.y = this.seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f);
}
moveToLocation.x += this.seekPosOffset.x;
moveToLocation.z += this.seekPosOffset.y;
}
else
{
//Log.Out("EAIFollowLeaderCompanion-Update 15");
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
if (num8 > 0f)
{
//Log.Out("EAIFollowLeaderCompanion-Update 16");
if (num8 > 60f)
{
//Log.Out("EAIFollowLeaderCompanion-Update 17");
num8 = 60f;
}
this.pathCounter += (int)(num8 / 20f * 20f);
}
}
//Log.Out("EAIFollowLeaderCompanion-Update $IsBackingUp: " + this.theEntity.Buffs.GetCustomVar("$IsBackingUp"));
//this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), false, this);
}
}
if (this.theEntity.Climbing)
{
//Log.Out("EAIFollowLeaderCompanion-Update 18");
return;
}
/*if (!flag)
{
//Log.Out("EAIFollowLeaderCompanion-Update 20");
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && num6 < 2.1f)
{
//Log.Out("EAIFollowLeaderCompanion-Update 21");
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.targetPlayer.position);
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
}
}
else
{
//Log.Out("EAIFollowLeaderCompanion-Update 22");
//this.theEntity.navigator?.clearPath();
this.theEntity.moveHelper.Stop();
this.pathCounter = 0;
}*/
}
private float GetTargetXZDistanceSq(float estimatedTicks)
{
Vector3 vector = this.targetPlayer.position;
vector += this.entityPlayerVel * estimatedTicks;
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
vector2.y = 0f;
return vector2.sqrMagnitude;
}
public override void Reset()
{
this.targetPlayer = null;
}
private EntityPlayer targetPlayer;
private Vector3 entityPlayerVel;
private Vector3 entityPlayerPos;
private int relocateTicks;
private int OwnerID = 0;
private int pathCounter;
private Vector2 seekPosOffset;
}