using ODMO.Commons.Models.Digimon;
namespace ODMO.Commons.Models.Character
{
public sealed partial class CharacterBuffListModel
{
///
/// Returns true if the character haves any active buff.
///
public bool HasActiveBuffs => ActiveBuffs.Any(x => x.Duration > 0);
///
/// Returns character's active buffs list.
///
public List ActiveBuffs => Buffs.Where(x => x.BuffId > 0).ToList();
///
/// Adds a new buff to the list.
///
/// The new buff.
public void Add(CharacterBuffModel buff)
{
if (Buffs.Any(x => x.BuffId == buff.BuffId)) return;
Buffs.Add(buff);
}
public CharacterBuffModel ActiveTamerSkill()
{
return Buffs.FirstOrDefault(x => x.SkillId / 1000000 == 8 && x.Cooldown >= 0);
}
///
/// Removes an active buff from the list.
///
/// The target buff id.
public bool ForceExpired(int buffId)
{
var BuffToExpired = Buffs.FirstOrDefault(x => x.BuffId == buffId);
if(BuffToExpired == null)
return false;
BuffToExpired.SetDuration(-1);
BuffToExpired.SetEndDate(DateTime.Now.AddMinutes(1));
return true;
}
public void RemoveAll()
{
Buffs.Clear();
}
///
/// Removes an active buff from the list.
///
/// The target buff id.
public bool Remove(int buffId)
{
return Buffs.RemoveAll(x => x.BuffId == buffId) > 0;
}
///
/// Updates the target buff in buff list.
///
/// The buff to be updated.
public void Update(CharacterBuffModel buff) => Buffs.FirstOrDefault(x => x.Id == buff.Id)?.IncreaseDuration(buff.Duration);
///
/// Serializes buffs list.
///
public byte[] ToArray()
{
byte[] buffer = Array.Empty();
using (MemoryStream m = new())
{
foreach (var buff in Buffs)
m.Write(buff.ToArray(), 0, 12);
buffer = m.ToArray();
}
return buffer;
}
}
}