public void WormAI() { if (!PreWormAI()) { return; } if (timer++ > maxTime) { timer = 0; } if (timer % 300 == 0) { SyncNPC(true); } npc.rotation = npc.velocity.ToRotation(); npc.noGravity = chaseThroughAir; if (attack && PreAttack()) { Attacking(); if (npc.Hitbox.Intersects(target().Hitbox) || target().dead || !target().active) { attack = false; } chase = target().Center; if (timer % 30 == 0) { SyncNPC(chase.X, chase.Y); } } else { if (timer % 120 == 0) { chase = ArchaeaNPC.FindAny(npc, 400); SyncNPC(chase.X, chase.Y); } } if (npc.Hitbox.Intersects(target().Hitbox)) { chase = ArchaeaNPC.FindAny(npc, 400); SyncNPC(chase.X, chase.Y); attack = false; } if (StartDigging()) { Digging(); float acceleration = attack ? this.acceleration : 0.1f; float angle = npc.AngleTo(chase); float cos = (float)(acceleration * Math.Cos(angle)); float sine = (float)(acceleration * Math.Sin(angle)); npc.velocity += new Vector2(cos, sine); ArchaeaNPC.VelocityClamp(ref npc.velocity, speedClamp * -1, speedClamp); } if (npc.velocity.X < 0f && npc.oldVelocity.X >= 0f || npc.velocity.X > 0f && npc.oldVelocity.X <= 0f || npc.velocity.Y < 0f && npc.oldVelocity.Y >= 0f || npc.velocity.Y > 0f && npc.oldVelocity.Y <= 0f) { SyncNPC(); } }
internal void SkyAI() { if (timer++ > 900) { SyncNPC(true); timer = 0; } if (timer % 300 == 0 && timer != 0) { fade = true; } findNewTarget = target() == null || !target().active || target().dead; if (!findNewTarget) { MaintainProximity(300f); } if (fade) { if (npc.alpha < 255 && PreFadeOut()) { npc.alpha += 255 / 60; } else if (timer % 90 == 0) { if (!findNewTarget) { npc.position = ArchaeaNPC.FindAny(npc, target(), false, 300); SyncNPC(); } fade = false; } } else { if (npc.alpha > 0) { npc.alpha -= 255 / 60; } } if (!fade && npc.alpha == 0) { if (timer % 150 == 0) { if (!findNewTarget) { if (!attack) { move = ArchaeaNPC.FindAny(npc, target(), false, 300); SyncNPC(move.X, move.Y); } else if (PreAttack()) { move = target().Center; SyncNPC(move.X, move.Y); } } } if (move != Vector2.Zero && (npc.position.X > move.X || npc.position.X < move.X || npc.position.Y > move.Y || npc.position.Y < move.Y)) { float angle = npc.AngleTo(move); float cos = (float)(0.25f * Math.Cos(angle)); float sine = (float)(0.25f * Math.Sin(angle)); npc.velocity += new Vector2(cos, sine); ArchaeaNPC.VelocityClamp(ref npc.velocity, -3f, 3f); if (npc.velocity.X < 0f && npc.oldVelocity.X >= 0f || npc.velocity.X > 0f && npc.oldVelocity.X <= 0f || npc.velocity.Y < 0f && npc.oldVelocity.Y >= 0f || npc.velocity.Y > 0f && npc.oldVelocity.Y <= 0f) { SyncNPC(); } } } }