using GamePath; using System.Collections.Generic; public class EAIApproachAndAttackTargetZombieRebirth : EAIBase { public struct TargetClass { public Type type; public float chaseTimeMax; } public const float cSleeperChaseTime = 90f; public List targetClasses; public float chaseTimeMax; public bool hasHome; public bool isGoingHome; public float homeTimeout; public EntityAlive entityTarget; public Vector3 entityTargetPos; public Vector3 entityTargetVel; public int attackTimeout; public int pathCounter; public Vector2 seekPosOffset; public bool isTargetToEat; public bool isEating; public EAIBlockingTargetTask blockTargetTask; public int relocateTicks; public int eatCount; public override void Init(EntityAlive _theEntity) { base.Init(_theEntity); MutexBits = 3; executeDelay = 0.1f; } public override void SetData(DictionarySave data) { base.SetData(data); targetClasses = new List(); string str; if (!data.TryGetValue("class", out str)) return; string[] strArray = str.Split(',', StringSplitOptions.None); for (int index = 0; index < strArray.Length; index += 2) { EAIApproachAndAttackTargetZombieRebirth.TargetClass targetClass = new EAIApproachAndAttackTargetZombieRebirth.TargetClass(); targetClass.type = EntityFactory.GetEntityType(strArray[index]); targetClass.chaseTimeMax = 0.0f; if (index + 1 < strArray.Length) targetClass.chaseTimeMax = StringParsers.ParseFloat(strArray[index + 1]); targetClasses.Add(targetClass); if (targetClass.type == typeof(EntityEnemyAnimal)) { targetClass.type = typeof(EntityAnimalSnake); targetClasses.Add(targetClass); } } } public void SetTargetOnlyPlayers() { targetClasses.Clear(); targetClasses.Add(new EAIApproachAndAttackTargetZombieRebirth.TargetClass() { type = typeof(EntityPlayer) }); } public override bool CanExecute() { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute START"); if (RebirthUtilities.canAttack(theEntity)) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 1"); return false; } //if (entityTarget != null) //{ //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute BEFORE entityTarget: " + entityTarget.EntityClass.entityClassName); //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute BEFORE theEntity.GetAttackTarget(): " + theEntity.GetAttackTarget()); //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute BEFORE theEntity.GetRevengeTarget(): " + theEntity.GetRevengeTarget()); //} entityTarget = theEntity.GetAttackTarget(); if (entityTarget == null) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 2"); return false; } //else //{ //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute AFTER entityTarget: " + entityTarget.EntityClass.entityClassName); //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute AFTER theEntity.GetAttackTarget(): " + theEntity.GetAttackTarget()); //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute AFTER theEntity.GetRevengeTarget(): " + theEntity.GetRevengeTarget()); //} bool bMindControlled = theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier1") || theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier2") || theEntity.Buffs.HasBuff("FuriousRamsayRangedMindControlBuffTier3"); if (bMindControlled) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 3"); if (entityTarget != null) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 4"); if (entityTarget is EntityPlayer || (entityTarget is EntityNPCRebirth && (entityTarget.HasAnyTags(FastTags.Parse("survivor")) || entityTarget.HasAnyTags(FastTags.Parse("ally"))))) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 5"); return false; } } } string rebirthFeralSense = RebirthVariables.customFeralSense; int currentDay = GameUtils.WorldTimeToDays(GameManager.Instance.World.worldTime); bool randomValid = rebirthFeralSense == "random" && currentDay == RebirthManager.nextFeralSenseDay; if (randomValid && GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 1) { randomValid = false; } if (randomValid && !GameManager.Instance.World.IsDaytime() && RebirthManager.nextFeralSensePeriod == 2) { randomValid = false; } bool isValidFeralSense = (rebirthFeralSense == "always") || (GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "dayonly") || (!GameManager.Instance.World.IsDaytime() && rebirthFeralSense == "nightonly") || randomValid; string rebirthPOISense = RebirthVariables.customPOISense; bool POISense = (rebirthPOISense == "always") || (GameManager.Instance.World.IsDaytime() && rebirthPOISense == "dayonly") || (!GameManager.Instance.World.IsDaytime() && rebirthPOISense == "nightonly"); bool persist = theEntity.HasAnyTags(FastTags.Parse("event")) || isValidFeralSense || (theEntity.IsSleeper && POISense); if (persist && !bMindControlled) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 6"); if (!theEntity.GetRevengeTarget()) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 7"); EntityPlayer closestPlayer = null; float num = 200 * 200; float num2 = float.MaxValue; for (int i = theEntity.world.Players.list.Count - 1; i >= 0; i--) { EntityPlayer entityPlayer = theEntity.world.Players.list[i]; if (!entityPlayer.IsDead() && entityPlayer.Spawned && !entityPlayer.IsSpectator) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 8"); //Log.Out("FOUND PLAYER: " + entityPlayer.EntityName); float distanceSq = entityPlayer.GetDistanceSq(theEntity.position); if (distanceSq < num2 && distanceSq <= num) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 9"); num2 = distanceSq; closestPlayer = entityPlayer; } } } if (closestPlayer != null) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 10"); theEntity.SetAttackTarget(closestPlayer, 200); entityTarget = closestPlayer; //Log.Out("CanExecute GOT CLOSEST PLAYER"); } else { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 11"); entityTarget = theEntity.GetAttackTarget(); //Log.Out("CanExecute NO CLOSEST PLAYER"); } } else { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 12"); entityTarget = theEntity.GetRevengeTarget(); } } Type type = entityTarget.GetType(); for (int i = 0; i < targetClasses.Count; i++) { EAIApproachAndAttackTargetZombieRebirth.TargetClass targetClass = targetClasses[i]; if (targetClass.type != null && targetClass.type.IsAssignableFrom(type)) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-CanExecute 13"); chaseTimeMax = targetClass.chaseTimeMax; if (persist) { chaseTimeMax = 1000; } return true; } } return false; } public override void Start() { entityTargetPos = entityTarget.position; entityTargetVel = Vector3.zero; isTargetToEat = entityTarget.IsDead() && !(entityTarget is EntityZombie); isEating = false; theEntity.IsEating = false; homeTimeout = (theEntity.IsSleeper ? cSleeperChaseTime : 0f); //Log.Out("Start, homeTimeout" + homeTimeout); hasHome = (homeTimeout > 0f); isGoingHome = false; if (theEntity.ChaseReturnLocation == Vector3.zero) { theEntity.ChaseReturnLocation = (theEntity.IsSleeper ? theEntity.SleeperSpawnPosition : theEntity.position); } pathCounter = 0; relocateTicks = 0; attackTimeout = 5; } public override bool Continue() { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Continue START"); if (RebirthUtilities.canAttack(theEntity)) { return false; } EntityAlive attackTarget = theEntity.GetAttackTarget(); if (isGoingHome) { return !attackTarget && theEntity.ChaseReturnLocation != Vector3.zero; } return attackTarget && !(attackTarget != entityTarget) && attackTarget.IsDead() == isTargetToEat; } public override void Reset() { theEntity.IsEating = false; theEntity.moveHelper.Stop(); if (blockTargetTask != null) { blockTargetTask.canExecute = false; } } /*public override void Update() { if (hasHome && !isTargetToEat) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 1"); if (isGoingHome) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 2"); Vector3 vector = theEntity.ChaseReturnLocation - theEntity.position; float y = vector.y; vector.y = 0f; if (vector.sqrMagnitude <= 0.16000001132488251 && Utils.FastAbs(y) < 2f) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 3"); Vector3 chaseReturnLocation = theEntity.ChaseReturnLocation; chaseReturnLocation.y = theEntity.position.y; theEntity.SetPosition(chaseReturnLocation, true); theEntity.ChaseReturnLocation = Vector3.zero; if (theEntity.IsSleeper) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 4"); theEntity.ResumeSleeperPose(); } return; } int num = pathCounter - 1; pathCounter = num; if (num <= 0 && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId)) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 5"); pathCounter = 60; float moveSpeed = theEntity.GetMoveSpeedAggro() * 0.8f; theEntity.FindPath(theEntity.ChaseReturnLocation, moveSpeed, false, this); } return; } else { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 6"); homeTimeout -= 0.05f; if (homeTimeout <= 0f) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 7"); if (blockTargetTask == null) { List targetTasks = manager.GetTargetTasks(); if (targetTasks != null) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 8"); blockTargetTask = targetTasks[0]; } } if (blockTargetTask != null) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 9"); blockTargetTask.canExecute = true; } ////Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update REMOVE ATTACK TARGET"); theEntity.attackTarget = (EntityAlive) null; theEntity.SetLookPosition(Vector3.zero); theEntity.PlayGiveUpSound(); pathCounter = 0; isGoingHome = true; return; } } } if (entityTarget == null) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 10"); return; } else { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update entityTarget: " + entityTarget.EntityClass.entityClassName); } if (relocateTicks > 0) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 11"); if (!theEntity.navigator.noPathAndNotPlanningOne()) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 12"); relocateTicks--; theEntity.moveHelper.SetFocusPos(entityTarget.position); return; } relocateTicks = 0; } Vector3 vector2 = entityTarget.position; if (isTargetToEat) { vector2 = entityTarget.getBellyPosition(); } Vector3 a = vector2 - entityTargetPos; if (a.sqrMagnitude < 1f) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 13"); entityTargetVel = entityTargetVel * 0.7f + a * 0.3f; } entityTargetPos = vector2; attackTimeout--; if (isEating) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 14"); if (theEntity.bodyDamage.HasLimbs) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 15"); theEntity.RotateTo(vector2.x, vector2.y, vector2.z, 30f, 30f); } if (attackTimeout <= 0) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update 16"); attackTimeout = 25 + base.GetRandom(10); if ((eatCount & 1) == 0) { theEntity.PlayOneShot("eat_player", false); entityTarget.DamageEntity(DamageSource.eat, 35, false, 1f); } Vector3 pos = new Vector3(0f, 0.04f, 0.08f); ParticleEffect pe = new ParticleEffect("blood_eat", pos, 1f, Color.white, null, theEntity.entityId, ParticleEffect.Attachment.Head); GameManager.Instance.SpawnParticleEffectServer(pe, theEntity.entityId, false, false); eatCount++; } return; } theEntity.moveHelper.CalcIfUnreachablePos(); float num2; float num3; if (!isTargetToEat) { ItemValue holdingItemItemValue = theEntity.inventory.holdingItemItemValue; int holdingItemIdx = theEntity.inventory.holdingItemIdx; ItemAction itemAction = holdingItemItemValue.ItemClass.Actions[holdingItemIdx]; num2 = 1.095f; if (itemAction != null) { num2 = itemAction.Range; if (num2 == 0f) { num2 = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f); } } num3 = Utils.FastMax(0.7f, num2 - 0.35f); } else { num2 = theEntity.GetHeight() * 0.9f; num3 = num2 - 0.05f; } float num4 = num3 * num3; float num5 = 4f; if (theEntity.IsFeral) { num5 = 8f; } num5 = base.RandomFloat * num5; float targetXZDistanceSq = GetTargetXZDistanceSq(num5); float num6 = vector2.y - theEntity.position.y; float num7 = Utils.FastAbs(num6); bool flag = targetXZDistanceSq <= num4 && num7 < 1f; if (!flag) { if (num7 < 3f && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId)) { PathEntity path = theEntity.navigator.getPath(); if (path != null && path.NodeCountRemaining() <= 2) { pathCounter = 0; } } int num = pathCounter - 1; pathCounter = num; if (num <= 0 && theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId)) { pathCounter = 6 + base.GetRandom(10); Vector3 moveToLocation = GetMoveToLocation(num3); if (moveToLocation.y - theEntity.position.y < -8f) { pathCounter += 40; if (base.RandomFloat < 0.2f) { seekPosOffset.x = seekPosOffset.x + (base.RandomFloat * 0.6f - 0.3f); seekPosOffset.y = seekPosOffset.y + (base.RandomFloat * 0.6f - 0.3f); } moveToLocation.x += seekPosOffset.x; moveToLocation.z += seekPosOffset.y; } else { float numDistance = 0; try { numDistance = Mathf.Abs(theEntity.inventory.GetBareHandItem().Actions[0].Range - entityTarget.inventory.GetBareHandItem().Actions[0].Range); } catch (Exception) { //Log.Out("============================ ERROR =================================="); //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update ENTITY NAME: " + theEntity.EntityClass.entityClassName); //Log.Out("============================ ERROR =================================="); } float num8 = (moveToLocation - theEntity.position).magnitude - 5f; float numDifference = num8 - numDistance; if (numDistance <= 0) { num8 = 0; } if (num8 > 0f) { if (num8 > 60f) { num8 = 60f; } pathCounter += (int)(num8 / 20f * 20f); } } theEntity.FindPath(moveToLocation, theEntity.GetMoveSpeedAggro(), false, this); } } if (theEntity.Climbing) { return; } bool flag2 = theEntity.CanSee(entityTarget); theEntity.SetLookPosition((flag2 && !theEntity.IsBreakingBlocks) ? entityTarget.getHeadPosition() : Vector3.zero); if (!flag) { if (theEntity.navigator.noPathAndNotPlanningOne() && pathCounter > 0 && num6 < 2.1f) { Vector3 moveToLocation2 = GetMoveToLocation(num3); theEntity.moveHelper.SetMoveTo(moveToLocation2, true); } } else { theEntity.moveHelper.Stop(); pathCounter = 0; } float num9 = isTargetToEat ? num2 : (num2 - 0.1f); float num10 = num9 * num9; if (targetXZDistanceSq > num10 || num7 >= 1.25f) { return; } theEntity.IsBreakingBlocks = false; theEntity.IsBreakingDoors = false; if (theEntity.bodyDamage.HasLimbs && !theEntity.Electrocuted) { theEntity.RotateTo(vector2.x, vector2.y, vector2.z, 30f, 30f); } if (isTargetToEat) { isEating = true; theEntity.IsEating = true; attackTimeout = 20; eatCount = 0; return; } if (theEntity.GetDamagedTarget() == entityTarget || (entityTarget != null && entityTarget.GetDamagedTarget() == theEntity)) { homeTimeout = (theEntity.IsSleeper ? 90f : chaseTimeMax); if (blockTargetTask != null) { blockTargetTask.canExecute = false; } theEntity.ClearDamagedTarget(); if (entityTarget) { entityTarget.ClearDamagedTarget(); } } if (attackTimeout > 0) { return; } if (manager.groupCircle > 0f) { Entity targetIfAttackedNow = theEntity.GetTargetIfAttackedNow(); if (targetIfAttackedNow != entityTarget && (!entityTarget.AttachedToEntity || entityTarget.AttachedToEntity != targetIfAttackedNow)) { if (targetIfAttackedNow != null) { relocateTicks = 46; Vector3 vector3 = (theEntity.position - vector2).normalized * (num9 + 1.1f); float num11 = base.RandomFloat * 28f + 18f; if (base.RandomFloat < 0.5f) { num11 = -num11; } vector3 = Quaternion.Euler(0f, num11, 0f) * vector3; Vector3 targetPos = vector2 + vector3; theEntity.FindPath(targetPos, theEntity.GetMoveSpeedAggro(), false, this); } return; } } theEntity.SleeperSupressLivingSounds = false; if (theEntity.Attack(false)) { attackTimeout = theEntity.GetAttackTimeoutTicks(); theEntity.Attack(true); } }*/ public override void Update() { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-Update START"); if (hasHome && !isTargetToEat) { if (isGoingHome) { Vector3 vector3 = theEntity.ChaseReturnLocation - theEntity.position; float y = vector3.y; vector3.y = 0.0f; if (vector3.sqrMagnitude <= 0.16000001f && Utils.FastAbs(y) < 2.0f) { Vector3 chaseReturnLocation = theEntity.ChaseReturnLocation; chaseReturnLocation.y = theEntity.position.y; theEntity.SetPosition(chaseReturnLocation); theEntity.ChaseReturnLocation = Vector3.zero; if (theEntity.IsSleeper) theEntity.ResumeSleeperPose(); } else if (--pathCounter <= 0 || !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId)) { pathCounter = 60; theEntity.FindPath(theEntity.ChaseReturnLocation, theEntity.GetMoveSpeedAggro() * 0.8f, false, this); } return; } homeTimeout -= 0.05f; if (homeTimeout <= 0.0f && hasHome) { if (blockTargetTask == null) { List targetTasks = manager.GetTargetTasks(); if (targetTasks != null) blockTargetTask = targetTasks[0]; } if (blockTargetTask != null) blockTargetTask.canExecute = true; theEntity.SetAttackTarget((EntityAlive)null, 0); theEntity.SetLookPosition(Vector3.zero); theEntity.PlayGiveUpSound(); pathCounter = 0; isGoingHome = true; return; } } // NEW CODE - in the event they were attacking a turned zombie that turned back bool shouldAttack = RebirthUtilities.VerifyFactionStanding(theEntity, entityTarget); if (!shouldAttack) { theEntity.attackTarget = (EntityAlive) null; theEntity.SetRevengeTarget((EntityAlive) null); return; } // NEW CODE if (entityTarget == null) return; if (relocateTicks > 0) { if (theEntity.navigator.noPathAndNotPlanningOne()) { relocateTicks = 0; } else { --relocateTicks; theEntity.moveHelper.SetFocusPos(entityTarget.position); return; } } Vector3 vector3_1 = entityTarget.position; if (isTargetToEat) vector3_1 = entityTarget.getBellyPosition(); Vector3 vector3_2 = vector3_1 - entityTargetPos; if (vector3_2.sqrMagnitude < 1.0f) entityTargetVel = entityTargetVel * 0.7f + vector3_2 * 0.3f; entityTargetPos = vector3_1; --attackTimeout; if (isEating) { if (theEntity.bodyDamage.HasLimbs) theEntity.RotateTo(vector3_1.x, vector3_1.y, vector3_1.z, 8f, 5f); if (attackTimeout > 0) return; attackTimeout = 25 + GetRandom(10); if ((eatCount & 1) == 0) { theEntity.PlayOneShot("eat_player"); entityTarget.DamageEntity(DamageSource.eat, 35, false, 1f); } ParticleEffect _pe = new ParticleEffect("blood_eat", new Vector3(0.0f, 0.04f, 0.08f), 1f, Color.white, string.Empty, theEntity.entityId, ParticleEffect.Attachment.Head); GameManager.Instance.SpawnParticleEffectServer(_pe, theEntity.entityId, false, false); ++eatCount; } else { theEntity.moveHelper.CalcIfUnreachablePos(); float num1; float maxDist; if (!isTargetToEat) { ItemValue holdingItemItemValue = theEntity.inventory.holdingItemItemValue; int holdingItemIdx = theEntity.inventory.holdingItemIdx; ItemAction action = holdingItemItemValue.ItemClass.Actions[holdingItemIdx]; num1 = 1.095f; if (action != null) { num1 = action.Range; if (num1 == 0.0f) num1 = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue); } maxDist = Utils.FastMax(0.7f, num1 - 0.35f); } else { num1 = theEntity.GetHeight() * 0.9f; maxDist = num1 - 0.05f; } float num2 = maxDist * maxDist; float num3 = 4f; if (theEntity.IsFeral) num3 = 8f; float targetXzDistanceSq = GetTargetXZDistanceSq(RandomFloat * num3); float _x = vector3_1.y - theEntity.position.y; float num4 = Utils.FastAbs(_x); bool flag = targetXzDistanceSq <= num2 && num4 < 1.0f; if (!flag) { if (num4 < 3.0f && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId)) { PathEntity path = theEntity.navigator.getPath(); if (path != null && path.NodeCountRemaining() <= 2) pathCounter = 0; } if (--pathCounter <= 0 && theEntity.CanNavigatePath() && !PathFinderThread.Instance.IsCalculatingPath(theEntity.entityId)) { pathCounter = 6 + GetRandom(10); Vector3 moveToLocation = GetMoveToLocation(maxDist); if (moveToLocation.y - theEntity.position.y < -8.0f) { pathCounter += 40; if (RandomFloat < 0.2f) { seekPosOffset.x += RandomFloat * 0.6f - 0.3f; seekPosOffset.y += RandomFloat * 0.6f - 0.3f; } moveToLocation.x += seekPosOffset.x; moveToLocation.z += seekPosOffset.y; } else { float num5 = (moveToLocation - theEntity.position).magnitude - 5f; if (num5 > 0.0f) { if (num5 > 60.0f) num5 = 60f; pathCounter += (int)(num5 / 20.0f * 20.0f); } } theEntity.FindPath(moveToLocation, theEntity.GetMoveSpeedAggro(), true, this); } } if (theEntity.Climbing) return; theEntity.SetLookPosition(!theEntity.CanSee(entityTarget) || theEntity.IsBreakingBlocks ? Vector3.zero : entityTarget.getHeadPosition()); if (!flag) { if (theEntity.navigator.noPathAndNotPlanningOne() && pathCounter > 0 && _x < 2.1f) theEntity.moveHelper.SetMoveTo(GetMoveToLocation(maxDist), true); } else { theEntity.moveHelper.Stop(); pathCounter = 0; } float num6 = isTargetToEat ? num1 : num1 - 0.1f; float num7 = num6 * num6; if ((targetXzDistanceSq > num7 ? 0 : (num4 < 1.25f ? 1 : 0)) == 0) { RebirthUtilities.CheckForOpenDoor(theEntity); return; } theEntity.IsBreakingBlocks = false; theEntity.IsBreakingDoors = false; if (theEntity.bodyDamage.HasLimbs && !theEntity.Electrocuted) theEntity.RotateTo(vector3_1.x, vector3_1.y, vector3_1.z, 30f, 30f); if (isTargetToEat) { isEating = true; theEntity.IsEating = true; attackTimeout = 20; eatCount = 0; } else { if ((theEntity.GetDamagedTarget() == entityTarget ? 1 : (!(entityTarget != null) ? 0 : (entityTarget.GetDamagedTarget() == theEntity ? 1 : 0))) != 0) { homeTimeout = theEntity.IsSleeper ? cSleeperChaseTime : 0;// chaseTimeMax; if (blockTargetTask != null) blockTargetTask.canExecute = false; theEntity.ClearDamagedTarget(); if (entityTarget) entityTarget.ClearDamagedTarget(); } if (attackTimeout > 0) return; if (manager.groupCircle > 0.0f) { Entity targetIfAttackedNow = theEntity.GetTargetIfAttackedNow(); if (targetIfAttackedNow != entityTarget && (!(bool)entityTarget.AttachedToEntity || entityTarget.AttachedToEntity != targetIfAttackedNow)) { if (!(targetIfAttackedNow != null)) return; relocateTicks = 46; Vector3 vector3_3 = (theEntity.position - vector3_1).normalized * (num6 + 1.1f); float y = RandomFloat * 28.0f + 18.0f; if (RandomFloat < 0.5f) y = -y; Vector3 vector3_4 = Quaternion.Euler(0.0f, y, 0.0f) * vector3_3; theEntity.FindPath(vector3_1 + vector3_4, theEntity.GetMoveSpeedAggro(), true, (EAIBase)this); return; } } theEntity.SleeperSupressLivingSounds = false; if (!theEntity.Attack(false)) return; attackTimeout = theEntity.GetAttackTimeoutTicks(); theEntity.Attack(true); } } } private float GetTargetXZDistanceSq(float estimatedTicks) { Vector3 vector = entityTarget.position; vector += entityTargetVel * estimatedTicks; if (isTargetToEat) { vector = entityTarget.getBellyPosition(); } Vector3 vector2 = theEntity.position + theEntity.motion * estimatedTicks - vector; vector2.y = 0f; return vector2.sqrMagnitude; } /*private Vector3 GetMoveToLocation(float maxDist) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation entityTarget: " + entityTarget.EntityClass.entityClassName); Vector3 vector = entityTarget.position; vector += entityTargetVel * 6f; if (isTargetToEat) { vector = entityTarget.getBellyPosition(); } vector = entityTarget.world.FindSupportingBlockPos(vector); if (maxDist > 0f) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 1"); Vector3 vector2 = new Vector3(theEntity.position.x, vector.y, theEntity.position.z); Vector3 vector3 = vector - vector2; float magnitude = vector3.magnitude; if (magnitude < 3f) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 2"); if (magnitude <= maxDist) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 3"); float num = vector.y - theEntity.position.y; if (num < -3f || num > 1.5f) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 4"); return vector; } return vector2; } else { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 5"); vector3 *= maxDist / magnitude; Vector3 vector4 = vector - vector3; vector4.y += 0.51f; Vector3i pos = World.worldToBlockPos(vector4); BlockValue block = entityTarget.world.GetBlock(pos); Block block2 = block.Block; if (block2.PathType <= 0) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 6"); RaycastHit raycastHit; if (Physics.Raycast(vector4 - Origin.position, Vector3.down, out raycastHit, 1.02f, 1082195968)) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 7"); vector4.y = raycastHit.point.y + Origin.position.y; return vector4; } if (block2.IsElevator((int)block.rotation)) { //Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 8"); vector4.y = vector.y; return vector4; } } } } } //Log.Out("EAIApproachAndAttackTargetZombieRebirth-GetMoveToLocation 9"); return vector; }*/ public Vector3 GetMoveToLocation(float maxDist) { Vector3 pos = entityTarget.position + entityTargetVel * 6f; if (isTargetToEat) pos = entityTarget.getBellyPosition(); Vector3 supportingBlockPos = entityTarget.world.FindSupportingBlockPos(pos); if (maxDist > 0.0f) { Vector3 vector3_1 = new Vector3(theEntity.position.x, supportingBlockPos.y, theEntity.position.z); Vector3 vector3_2 = supportingBlockPos - vector3_1; float magnitude = vector3_2.magnitude; if (magnitude < 3.0f) { if (magnitude <= maxDist) { float num = supportingBlockPos.y - theEntity.position.y; return num < -3.0f || num > 1.5f ? supportingBlockPos : vector3_1; } Vector3 vector3_3 = vector3_2 * (maxDist / magnitude); Vector3 _worldPos = supportingBlockPos - vector3_3; _worldPos.y += 0.51f; BlockValue block1 = entityTarget.world.GetBlock(World.worldToBlockPos(_worldPos)); Block block2 = block1.Block; if (block2.PathType <= 0) { RaycastHit hitInfo; if (Physics.Raycast(_worldPos - Origin.position, Vector3.down, out hitInfo, 1.02f, 1082195968)) { _worldPos.y = hitInfo.point.y + Origin.position.y; return _worldPos; } if (block2.IsElevator((int)block1.rotation)) { _worldPos.y = supportingBlockPos.y; return _worldPos; } } } } return supportingBlockPos; } public override string ToString() { ItemValue holdingItemItemValue = theEntity.inventory.holdingItemItemValue; int holdingItemIdx = theEntity.inventory.holdingItemIdx; ItemAction itemAction = holdingItemItemValue.ItemClass.Actions[holdingItemIdx]; float num = 1.095f; if (!isTargetToEat && itemAction != null) { num = itemAction.Range; if (num == 0f) { num = EffectManager.GetItemValue(PassiveEffects.MaxRange, holdingItemItemValue, 0f); } } float value = isTargetToEat ? num : (num - 0.1f); float targetXZDistanceSq = GetTargetXZDistanceSq(0f); return string.Format("{0}, {1}{2}{3}{4}{5} dist {6} rng {7} timeout {8}", new object[] { base.ToString(), entityTarget ? entityTarget.EntityName : "", theEntity.CanSee(entityTarget) ? "(see)" : "", theEntity.navigator.noPathAndNotPlanningOne() ? "(-path)" : (theEntity.navigator.noPath() ? "(!path)" : ""), isTargetToEat ? "(eat)" : "", isGoingHome ? "(Going home)" : "", Mathf.Sqrt(targetXZDistanceSq).ToCultureInvariantString("0.000"), value.ToCultureInvariantString("0.000"), homeTimeout.ToCultureInvariantString("0.00") }); } }