372 lines
13 KiB
C#
372 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 EAIMoveToTargetCompanion : EAITarget
|
|
{
|
|
public override void Init(EntityAlive _theEntity)
|
|
{
|
|
base.Init(_theEntity, 25f, true);
|
|
this.MutexBits = 1;
|
|
}
|
|
|
|
public override void Start()
|
|
{
|
|
this.relocateTicks = 0;
|
|
this.pathCounter = 0;
|
|
base.Start();
|
|
}
|
|
|
|
public bool NPCEAICanProceed()
|
|
{
|
|
bool result = true;
|
|
|
|
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
|
|
|
if (this.OwnerID == 0)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-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("EAIMoveToTargetCompanion-NPCEAICanProceed 1");
|
|
return false;
|
|
}
|
|
|
|
EntityUtilities.CheckDistanceToLeader(this.theEntity, this.targetPlayer);
|
|
|
|
this.entityTarget = this.theEntity.GetAttackTarget();
|
|
|
|
if (this.entityTarget == null)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2a");
|
|
return false;
|
|
}
|
|
|
|
if (this.targetPlayer != null && !this.targetPlayer.CanEntityBeSeen(this.entityTarget) && !this.theEntity.CanEntityBeSeen(this.entityTarget))
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2b");
|
|
return false;
|
|
}
|
|
|
|
if (this.theEntity.CanEntityBeSeen(this.entityTarget))
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 2c");
|
|
return false;
|
|
}
|
|
|
|
if (this.theEntity.emodel.IsRagdollActive)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 3");
|
|
return false;
|
|
}
|
|
|
|
if (this.theEntity.sleepingOrWakingUp || this.theEntity.bodyDamage.CurrentStun != EnumEntityStunType.None || (this.theEntity.Jumping && !this.theEntity.isSwimming))
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-NPCEAICanProceed 4");
|
|
return false;
|
|
}
|
|
|
|
if (this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Follow &&
|
|
this.theEntity.Buffs.GetCustomVar("CurrentOrder") != (int)EntityUtilities.Orders.Guard)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-CanExecute IS NOT FOLLOWING");
|
|
return false;
|
|
}
|
|
|
|
bool stopAttacking = this.theEntity.Buffs.HasBuff("FuriousRamsayBuffPauseAttack") ||
|
|
this.theEntity.Buffs.HasBuff("buffNPCModStopAttacking") ||
|
|
this.theEntity.Buffs.HasBuff("FuriousRamsayStandStill");
|
|
|
|
if (stopAttacking)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-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("EAIMoveToTargetCompanion-NPCEAICanProceed 6");
|
|
return false;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public override bool CanExecute()
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-CanExecute START");
|
|
|
|
if (!NPCEAICanProceed())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (this.targetPlayer == null)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-CanExecute 2");
|
|
this.OwnerID = (int)this.theEntity.Buffs.GetCustomVar("$Leader");
|
|
|
|
if (this.OwnerID > 0)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-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("EAIMoveToTargetCompanion-CanExecute this.theEntity.GetAttackTarget: " + this.theEntity.GetAttackTarget().EntityClass.entityClassName);
|
|
return false;
|
|
}
|
|
|
|
public override bool Continue()
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Continue START");
|
|
if (!NPCEAICanProceed())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (pathCounter == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update START");
|
|
|
|
if (!NPCEAICanProceed())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this.targetPlayer == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
EntityUtilities.CheckForClosedDoor(this.theEntity);
|
|
|
|
if (this.relocateTicks > 0)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update 2");
|
|
if (!this.theEntity.navigator.noPathAndNotPlanningOne())
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update 3");
|
|
this.relocateTicks--;
|
|
this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position);
|
|
return;
|
|
}
|
|
this.relocateTicks = 0;
|
|
}
|
|
|
|
Vector3 vector2 = this.entityTarget.position;
|
|
|
|
Vector3 a = theEntity.position - vector2;
|
|
|
|
//Log.Out("EAIMoveToTargetCompanion-Update entityTargetPosn: " + vector2);
|
|
//Log.Out("EAIMoveToTargetCompanion-Update a: " + a);
|
|
//Log.Out("EAIMoveToTargetCompanion-Update a.sqrMagnitude: " + a.sqrMagnitude);
|
|
//Log.Out("EAIMoveToTargetCompanion-Update this.OwnerID: " + this.theEntity.Buffs.GetCustomVar("$Leader"));
|
|
|
|
//Log.Out("EAIMoveToTargetCompanion-Update SetLookPosition");
|
|
theEntity.SetLookPosition(vector2);
|
|
theEntity.RotateTo(vector2.x, vector2.y + 2, vector2.z, 8f, 8f);
|
|
|
|
if (a.sqrMagnitude < 1f)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-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("EAIMoveToTargetCompanion-Update 9");
|
|
if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId))
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update 10");
|
|
PathEntity path = this.theEntity.navigator.getPath();
|
|
if (path != null && path.NodeCountRemaining() <= 2)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-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("EAIMoveToTargetCompanion-Update 12");
|
|
this.pathCounter = 6 + base.GetRandom(10);
|
|
Vector3 moveToLocation = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 5);
|
|
if (moveToLocation.y - this.theEntity.position.y < -8f)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update 13");
|
|
this.pathCounter += 40;
|
|
if (base.RandomFloat < 0.2f)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-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("EAIMoveToTargetCompanion-Update 15");
|
|
float num8 = (moveToLocation - this.theEntity.position).magnitude - 5f;
|
|
if (num8 > 0f)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update 16");
|
|
if (num8 > 60f)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update 17");
|
|
num8 = 60f;
|
|
}
|
|
this.pathCounter += (int)(num8 / 20f * 20f);
|
|
}
|
|
}
|
|
this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this);
|
|
}
|
|
}
|
|
if (this.theEntity.Climbing)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update 18");
|
|
return;
|
|
}
|
|
if (!flag)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update 20");
|
|
if (this.theEntity.navigator.noPathAndNotPlanningOne() && this.pathCounter > 0 && num6 < 2.1f)
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update 21");
|
|
Vector3 moveToLocation2 = EntityUtilities.GetMoveToLocation(this.theEntity, this.entityTarget.position, 5);
|
|
this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("EAIMoveToTargetCompanion-Update 22");
|
|
this.theEntity.moveHelper.Stop();
|
|
this.pathCounter = 0;
|
|
}
|
|
}
|
|
|
|
private float GetTargetXZDistanceSq(float estimatedTicks)
|
|
{
|
|
Vector3 vector = this.entityTarget.position;
|
|
vector += this.entityPlayerVel * estimatedTicks;
|
|
Vector3 vector2 = this.theEntity.position + this.theEntity.motion * estimatedTicks - vector;
|
|
vector2.y = 0f;
|
|
return vector2.sqrMagnitude;
|
|
}
|
|
|
|
private Vector3 GetMoveToLocation(float maxDist)
|
|
{
|
|
Vector3 vector = this.entityTarget.position;
|
|
vector += this.entityPlayerVel * 6f;
|
|
vector = this.entityTarget.world.FindSupportingBlockPos(vector);
|
|
if (maxDist > 0f)
|
|
{
|
|
Vector3 vector2 = new Vector3(this.theEntity.position.x, vector.y, this.theEntity.position.z);
|
|
Vector3 vector3 = vector - vector2;
|
|
float magnitude = vector3.magnitude;
|
|
if (magnitude < 3f)
|
|
{
|
|
if (magnitude <= maxDist)
|
|
{
|
|
float num = vector.y - this.theEntity.position.y;
|
|
if (num < -3f || num > 1.5f)
|
|
{
|
|
return vector;
|
|
}
|
|
return vector2;
|
|
}
|
|
else
|
|
{
|
|
vector3 *= maxDist / magnitude;
|
|
Vector3 vector4 = vector - vector3;
|
|
vector4.y += 0.51f;
|
|
Vector3i pos = World.worldToBlockPos(vector4);
|
|
BlockValue block = this.entityTarget.world.GetBlock(pos);
|
|
Block block2 = block.Block;
|
|
if (block2.PathType <= 0)
|
|
{
|
|
RaycastHit raycastHit;
|
|
if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968))
|
|
{
|
|
vector4.y = raycastHit.point.y + Origin.position.y;
|
|
return vector4;
|
|
}
|
|
if (block2.IsElevator((int)block.rotation))
|
|
{
|
|
vector4.y = vector.y;
|
|
return vector4;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return vector;
|
|
}
|
|
|
|
public override void Reset()
|
|
{
|
|
this.entityTarget = null;
|
|
this.targetPlayer = null;
|
|
}
|
|
|
|
private EntityPlayer targetPlayer;
|
|
private EntityAlive entityTarget;
|
|
private Vector3 entityPlayerVel;
|
|
private Vector3 entityPlayerPos;
|
|
private int relocateTicks;
|
|
private int OwnerID = 0;
|
|
private int pathCounter;
|
|
private Vector2 seekPosOffset;
|
|
}
|