using GamePath; using System.Collections.Generic; using System.Globalization; public class EAIApproachAndAttackTargetFatZombieRebirth : EAIBase { public override void Init(EntityAlive _theEntity) { base.Init(_theEntity); this.MutexBits = 3; this.executeDelay = 0.1f; } public override void SetData(DictionarySave data) { base.SetData(data); this.targetClasses = new List(); string text; if (data.TryGetValue("class", out text)) { string[] array = text.Split(new char[] { ',' }); for (int i = 0; i < array.Length; i += 2) { EAIApproachAndAttackTargetFatZombieRebirth.TargetClass item = default(EAIApproachAndAttackTargetFatZombieRebirth.TargetClass); item.type = EntityFactory.GetEntityType(array[i]); item.maxChaseTime = 0f; if (i + 1 < array.Length) { item.maxChaseTime = StringParsers.ParseFloat(array[i + 1], 0, -1, NumberStyles.Any); } this.targetClasses.Add(item); } } } public override bool CanExecute() { if (RebirthUtilities.canAttack(theEntity)) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-CanExecute 1"); return false; } this.entityTarget = this.theEntity.GetAttackTarget(); if (this.entityTarget == null) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-CanExecute 2"); return false; } Type type = this.entityTarget.GetType(); for (int i = 0; i < this.targetClasses.Count; i++) { EAIApproachAndAttackTargetFatZombieRebirth.TargetClass targetClass = this.targetClasses[i]; if (targetClass.type != null && targetClass.type.IsAssignableFrom(type)) { this.maxChaseTime = targetClass.maxChaseTime; //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-CanExecute 3"); return true; } } //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-CanExecute 4"); return false; } public override void Start() { this.entityTargetPos = this.entityTarget.position; this.entityTargetVel = Vector3.zero; this.isTargetToEat = this.entityTarget.IsDead() && !(this.entityTarget is EntityZombie); this.isEating = false; this.theEntity.IsEating = false; this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.maxChaseTime); //Log.Out("Start, homeTimeout" + homeTimeout); ulong worldTime = GameManager.Instance.World.worldTime; ValueTuple valueTuple = GameUtils.WorldTimeToElements(worldTime); int numDay = valueTuple.Item1; homeTimeout = numDay + 100; if (homeTimeout > 200) { homeTimeout = 200; } ////Log.Out("Start, homeTimeout" + homeTimeout); this.hasHome = (this.homeTimeout > 0f); this.isGoingHome = false; if (this.theEntity.ChaseReturnLocation == Vector3.zero) { this.theEntity.ChaseReturnLocation = (this.theEntity.IsSleeper ? this.theEntity.SleeperSpawnPosition : this.theEntity.position); } this.pathCounter = 0; this.relocateTicks = 0; if (this.isTargetToEat) { Vector3 moveToLocation = this.GetMoveToLocation(0f); this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this); } this.attackTimeout = 5; } public override bool Continue() { if (RebirthUtilities.canAttack(theEntity)) { return false; } EntityAlive attackTarget = this.theEntity.GetAttackTarget(); if (this.isGoingHome) { return !attackTarget && this.theEntity.ChaseReturnLocation != Vector3.zero; } return attackTarget && !(attackTarget != this.entityTarget) && attackTarget.IsDead() == this.isTargetToEat; } public override void Reset() { this.theEntity.IsEating = false; this.theEntity.navigator.clearPath(); if (this.blockTargetTask != null) { this.blockTargetTask.canExecute = false; } } public override void Update() { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update START"); if (this.hasHome && !this.isTargetToEat) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 1"); if (this.isGoingHome) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 2"); Vector3 vector = this.theEntity.ChaseReturnLocation - this.theEntity.position; float y = vector.y; vector.y = 0f; if (vector.sqrMagnitude <= 0.16000001f && Utils.FastAbs(y) < 2f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 3"); Vector3 chaseReturnLocation = this.theEntity.ChaseReturnLocation; chaseReturnLocation.y = this.theEntity.position.y; this.theEntity.SetPosition(chaseReturnLocation, true); this.theEntity.ChaseReturnLocation = Vector3.zero; if (this.theEntity.IsSleeper) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 4"); this.theEntity.ResumeSleeperPose(); } return; } int num = this.pathCounter - 1; this.pathCounter = num; if (num <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 5"); this.pathCounter = 60; float moveSpeed = this.theEntity.GetMoveSpeedAggro() * 0.8f; this.theEntity.FindPath(this.theEntity.ChaseReturnLocation, moveSpeed, true, this); } //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 6"); return; } else { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 7"); this.homeTimeout -= 0.05f; if (this.homeTimeout <= 0f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 8"); if (this.blockTargetTask == null) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 9"); List targetTasks = this.manager.GetTargetTasks(); if (targetTasks != null) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 10"); this.blockTargetTask = targetTasks[0]; } } if (this.blockTargetTask != null) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 11"); this.blockTargetTask.canExecute = true; } this.theEntity.attackTarget = (EntityAlive) null; this.theEntity.SetLookPosition(Vector3.zero); this.theEntity.PlayGiveUpSound(); this.pathCounter = 0; this.isGoingHome = true; //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 12"); return; } } } if (this.entityTarget == null) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 13"); return; } if (this.relocateTicks > 0) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 14"); if (!this.theEntity.navigator.noPathAndNotPlanningOne()) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 15"); this.relocateTicks--; this.theEntity.moveHelper.SetFocusPos(this.entityTarget.position); return; } this.relocateTicks = 0; } Vector3 position = this.entityTarget.position; Vector3 a = position - this.entityTargetPos; if (a.sqrMagnitude < 1f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 16"); this.entityTargetVel = this.entityTargetVel * 0.7f + a * 0.3f; } this.entityTargetPos = position; this.attackTimeout--; if (this.isEating) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 17"); if (this.theEntity.bodyDamage.HasLimbs) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 18"); this.theEntity.RotateTo(position.x, position.y, position.z, 30f, 30f); } if (this.attackTimeout <= 0) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 19"); this.theEntity.PlayOneShot("eat_player", false); this.attackTimeout = 60 + base.GetRandom(20); } return; } this.theEntity.moveHelper.CalcIfUnreachablePos(); ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[0]; float num2 = 1.095f; if (!this.isTargetToEat) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 20"); num2 = ((itemAction != null) ? Utils.FastMax(0.5f, itemAction.Range - 0.35f) : 0.5f); } float num3 = num2 * num2; float estimatedTicks = 1f + base.RandomFloat * 10f; float targetXZDistanceSq = this.GetTargetXZDistanceSq(estimatedTicks); float num4 = position.y - this.theEntity.position.y; float num5 = Utils.FastAbs(num4); bool flag = targetXZDistanceSq <= num3 && num5 < 1f; if (!flag && !this.isTargetToEat) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 21"); if (num5 < 3f && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 22"); PathEntity path = this.theEntity.navigator.getPath(); if (path != null && path.NodeCountRemaining() <= 2) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 23"); this.pathCounter = 0; } } int num = this.pathCounter - 1; this.pathCounter = num; if (num <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 24"); this.pathCounter = 6 + base.GetRandom(10); Vector3 moveToLocation = this.GetMoveToLocation(num2); if (moveToLocation.y - this.theEntity.position.y < -8f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 25"); this.pathCounter += 40; if (base.RandomFloat < 0.2f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 26"); 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("EAIApproachAndAttackTargetFatZombieRebirth-Update 27"); float num6 = (moveToLocation - this.theEntity.position).magnitude - 5f; if (num6 > 0f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 28"); if (num6 > 60f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 29"); num6 = 60f; } this.pathCounter += (int)(num6 / 20f * 20f); } } this.theEntity.FindPath(moveToLocation, this.theEntity.GetMoveSpeedAggro(), true, this); } } if (this.theEntity.Climbing) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 30"); return; } bool flag2 = this.theEntity.CanSee(this.entityTarget); this.theEntity.SetLookPosition((flag2 && !this.theEntity.IsBreakingBlocks) ? this.entityTarget.getHeadPosition() : Vector3.zero); if (!flag) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 31"); if (this.theEntity.navigator.noPathAndNotPlanningOne() && num4 < 2.1f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 32"); Vector3 moveToLocation2 = this.GetMoveToLocation(num2); this.theEntity.moveHelper.SetMoveTo(moveToLocation2, true); } } else { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 33"); this.theEntity.navigator.clearPath(); this.theEntity.moveHelper.Stop(); this.pathCounter = 0; } float num7 = this.isTargetToEat ? 1.095f : ((itemAction != null) ? (itemAction.Range - 0.1f) : 0f); float num8 = num7 * num7; if (targetXZDistanceSq > num8 || num5 >= 1.25f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 34"); return; } this.theEntity.IsBreakingBlocks = false; this.theEntity.IsBreakingDoors = false; if (this.theEntity.bodyDamage.HasLimbs) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 35"); this.theEntity.RotateTo(position.x, position.y, position.z, 30f, 30f); } if (this.isTargetToEat) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 36"); this.isEating = true; this.theEntity.IsEating = true; this.attackTimeout = 0; return; } if (this.theEntity.GetDamagedTarget() == this.entityTarget || (this.entityTarget != null && this.entityTarget.GetDamagedTarget() == this.theEntity)) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 37"); this.homeTimeout = (this.theEntity.IsSleeper ? 90f : this.maxChaseTime); //Log.Out("Update A, homeTimeout" + homeTimeout); if (this.blockTargetTask != null) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 38"); this.blockTargetTask.canExecute = false; } this.theEntity.ClearDamagedTarget(); if (this.entityTarget) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 39"); this.entityTarget.ClearDamagedTarget(); } } if (this.attackTimeout > 0 && !(this.entityTarget is EntityVehicle && !(this.entityTarget is EntityBicycle)) && !(this.entityTarget.Health == 0)) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 40"); return; } if (this.manager.groupCircle > 0f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 41"); Entity targetIfAttackedNow = this.theEntity.GetTargetIfAttackedNow(); if (targetIfAttackedNow != this.entityTarget && (!this.entityTarget.AttachedToEntity || this.entityTarget.AttachedToEntity != targetIfAttackedNow)) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 42"); if (targetIfAttackedNow != null) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 43"); this.relocateTicks = 46; Vector3 vector2 = (this.theEntity.position - position).normalized * (num7 + 1.1f); float num9 = base.RandomFloat * 28f + 18f; if (base.RandomFloat < 0.5f) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 44"); num9 = -num9; } vector2 = Quaternion.Euler(0f, num9, 0f) * vector2; Vector3 targetPos = position + vector2; this.theEntity.FindPath(targetPos, this.theEntity.GetMoveSpeedAggro(), true, this); } return; } } this.theEntity.SleeperSupressLivingSounds = false; if (this.entityTarget is EntityVehicle) { EntityZombieSDX entityZombieSDX = (EntityZombieSDX)this.theEntity; //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 45"); //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update entityZombieSDX.bLastAttackReleased: " + entityZombieSDX.bLastAttackReleased); itemAction.ExecuteAction(this.theEntity.inventory.holdingItemData.actionData[1], !entityZombieSDX.bLastAttackReleased); entityZombieSDX.bLastAttackReleased = !entityZombieSDX.bLastAttackReleased; return; } if (this.theEntity.Attack(false)) { //Log.Out("EAIApproachAndAttackTargetFatZombieRebirth-Update 46"); this.attackTimeout = this.theEntity.GetAttackTimeoutTicks(); this.theEntity.Attack(true); } } private float GetTargetXZDistanceSq(float estimatedTicks) { Vector3 vector = this.entityTarget.position; vector += this.entityTargetVel * estimatedTicks; if (this.isTargetToEat) { EModelBase emodel = this.entityTarget.emodel; if (emodel && emodel.bipedPelvisTransform) { vector = emodel.bipedPelvisTransform.position + Origin.position; } } 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.entityTargetVel * 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 string ToString() { ItemAction itemAction = this.theEntity.inventory.holdingItem.Actions[0]; float value = (itemAction != null) ? (itemAction.Range - 0.1f) : 0f; float targetXZDistanceSq = this.GetTargetXZDistanceSq(0f); return string.Format("{0}, {1}{2}{3}{4}{5} dist {6} rng {7} timeout {8}", new object[] { base.ToString(), this.entityTarget ? this.entityTarget.EntityName : "", this.theEntity.CanSee(this.entityTarget) ? "(see)" : "", this.theEntity.navigator.noPathAndNotPlanningOne() ? "(-path)" : (this.theEntity.navigator.noPath() ? "(!path)" : ""), this.isTargetToEat ? "(eat)" : "", this.isGoingHome ? "(home)" : "", Mathf.Sqrt(targetXZDistanceSq).ToCultureInvariantString("0.000"), value.ToCultureInvariantString("0.000"), this.homeTimeout.ToCultureInvariantString("0.00") }); } private const float cSleeperChaseTime = 90f; private List targetClasses; private float maxChaseTime; private bool hasHome; private bool isGoingHome; private float homeTimeout; private EntityAlive entityTarget; private Vector3 entityTargetPos; private Vector3 entityTargetVel; private int attackTimeout; private int pathCounter; private Vector2 seekPosOffset; private bool isTargetToEat; private bool isEating; private EAIBlockingTargetTask blockTargetTask; private int relocateTicks; private struct TargetClass { public Type type; public float maxChaseTime; } }