using Lidgren.Network; using Microsoft.Xna.Framework; using Barotrauma.Networking; using System; using System.Collections.Generic; using System.Linq; using System.Text; using FarseerPhysics; namespace Barotrauma { class AICharacter : Character { const float AttackBackPriority = 1.0f; private AIController aiController; public override AIController AIController { get { return aiController; } } public AICharacter(string file, Vector2 position, CharacterInfo characterInfo = null, bool isNetworkPlayer = false) : base(file, position, characterInfo, isNetworkPlayer) { soundTimer = Rand.Range(0.0f, soundInterval); } public void SetAI(AIController aiController) { this.aiController = aiController; } public override void Update(Camera cam, float deltaTime) { if (!Enabled) return; base.Update(cam, deltaTime); float dist = Vector2.Distance(cam.WorldViewCenter, WorldPosition); if (dist > 8000.0f) { AnimController.SimplePhysicsEnabled = true; } else if (dist < 7000.0f) { AnimController.SimplePhysicsEnabled = false; } if (isDead || health <= 0.0f) return; if (Controlled == this || !aiController.Enabled) return; if (soundTimer > 0) { soundTimer -= deltaTime; } else { PlaySound((aiController == null) ? AIController.AiState.None : aiController.State); soundTimer = soundInterval; } aiController.Update(deltaTime); } public override void DrawFront(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch,Camera cam) { base.DrawFront(spriteBatch,cam); if (GameMain.DebugDraw && !isDead) aiController.DebugDraw(spriteBatch); } public override void AddDamage(CauseOfDeath causeOfDeath, float amount, IDamageable attacker) { base.AddDamage(causeOfDeath, amount, attacker); if (attacker!=null) aiController.OnAttacked(attacker, amount); } public override AttackResult AddDamage(IDamageable attacker, Vector2 worldPosition, Attack attack, float deltaTime, bool playSound = false) { AttackResult result = base.AddDamage(attacker, worldPosition, attack, deltaTime, playSound); aiController.OnAttacked(attacker, (result.Damage + result.Bleeding) / Math.Max(health,1.0f)); return result; } } }