Files
LuaCsForBarotraumaEP/Subsurface/Source/Characters/AICharacter.cs
juanjp600 af220dbc2a Removed Fill/ReadNetworkData
These functions needed to be replaced because they rely heavily on reliability.

Instead, new functions called (Write/Read)Data(Server/Client) will be added. 

Separating client and server code into completely separate functions will help ensure that proper security checks are performed.
2016-08-29 20:02:46 -03:00

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) 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)
{
base.DrawFront(spriteBatch);
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;
}
}
}