Conflicts: Subsurface/Properties/AssemblyInfo.cs Subsurface/Source/Characters/Character.cs Subsurface/Source/GUI/GUI.cs Subsurface/Source/GameMain.cs Subsurface/Source/GameSettings.cs Subsurface/Source/Items/CharacterInventory.cs Subsurface/Source/Items/Components/ItemComponent.cs Subsurface/Source/Items/Components/Machines/Pump.cs Subsurface/Source/Items/Components/Machines/Radar.cs Subsurface/Source/Items/Components/Machines/Steering.cs Subsurface/Source/Items/Components/Power/PowerContainer.cs Subsurface/Source/Items/Inventory.cs Subsurface/Source/Items/Item.cs Subsurface/Source/Items/ItemSpawner.cs Subsurface/Source/Map/Levels/WaterRenderer.cs Subsurface/Source/Map/LinkedSubmarine.cs Subsurface/Source/Map/Map/Map.cs Subsurface/Source/Map/Structure.cs Subsurface/Source/Map/Submarine.cs Subsurface/Source/Map/WayPoint.cs Subsurface/Source/Networking/GameClient.cs Subsurface/Source/Networking/GameServer.cs Subsurface/Source/Physics/PhysicsBody.cs Subsurface/Source/Screens/GameScreen.cs
91 lines
2.7 KiB
C#
91 lines
2.7 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|