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() { 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; } 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; } 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.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.moveHelper.Stop(); pathCounter = 0; return; } if (this.targetPlayer.entityId == this.OwnerID) { if (!this.theEntity.HasAnyTags(FastTags.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); } } this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, 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.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; } private Vector3 GetMoveToLocation(float maxDist) { Vector3 vector = this.targetPlayer.position; vector += this.entityPlayerVel * 6f; vector = this.targetPlayer.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.targetPlayer.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.targetPlayer = null; } private EntityPlayer targetPlayer; private Vector3 entityPlayerVel; private Vector3 entityPlayerPos; private int relocateTicks; private int OwnerID = 0; private int pathCounter; private Vector2 seekPosOffset; }