namespace ODMO.Commons.Models.Digimon
{
public sealed partial class DigimonBuffListModel
{
///
/// Returns true if the digimon haves any active buff.
///
public bool HasActiveBuffs => ActiveBuffs.Any(x => x.Duration > 0);
///
/// Returns digimon'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(DigimonBuffModel buff)
{
if (Buffs.Any(x => x.BuffId == buff.BuffId))
return;
Buffs.Add(buff);
}
///
/// 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 bool Remove(int buffId)
{
return Buffs.RemoveAll(x => x.BuffId == buffId) > 0;
}
public DigimonBuffModel TamerBaseSkill()
{
return Buffs.FirstOrDefault(x => x.SkillId / 1000000 == 8 && x.Duration == 0);
}
public DigimonBuffModel ActiveTamerSkill()
{
return Buffs.FirstOrDefault(x => x.SkillId / 1000000 == 8 && x.Cooldown >= 0);
}
///
/// Updates the target buff in buff list.
///
/// The buff to be updated.
public void Update(DigimonBuffModel buff) => Buffs.FirstOrDefault(x => x.Id == buff.Id)?.IncreaseDuration(buff.Duration);
public bool HaveActiveSkill(int skillId)
{
var targetSkill = Buffs.FirstOrDefault(x => x.SkillId == skillId);
return targetSkill != null;
}
///
/// Serializes buffs list.
///
public byte[] ToArray()
{
byte[] buffer;
using (MemoryStream m = new())
{
foreach (var buff in Buffs)
m.Write(buff.ToArray(), 0, 12);
buffer = m.ToArray();
}
return buffer;
}
}
}