using System;
using System.Collections.Generic;
using System.Linq;
using ACE.Server.WorldObjects;
namespace ACE.Server.Entity
{
///
/// An attackable objects keeps track of its damage sources
///
public class AttackDamage
{
public WorldObject Source;
public uint Amount;
public DateTime Time;
public bool IsCritical;
///
/// Constructs a new attack damage
///
/// The attacker or source of damage
/// The amount of hit damage
/// Flag indicates critical hit
public AttackDamage(WorldObject source, uint amount, bool criticalHit)
{
Source = source;
Amount = amount;
Time = DateTime.UtcNow;
IsCritical = criticalHit;
}
///
/// Returns the total damage from the source attacker
///
/// The list of attacks performed on a target
/// The attacker to add up the damage for
public static ulong GetTotalDamage(List attacks, WorldObject source)
{
return (ulong)attacks.Where(a => a.Source == source).Sum(a => a.Amount);
}
///
/// Returns TRUE if last attack was critical hit
///
/// The list of attacks performed on a target
public static bool LastHitCritical(List attacks)
{
var lastHit = attacks.LastOrDefault();
if (lastHit != null)
return lastHit.IsCritical;
else
return false;
}
///
/// Returns the top damager on creature death
///
public static WorldObject GetTopDamager(List attacks)
{
// build the attack list
return new AttackList(attacks).TopDamager;
}
}
}