public void RemoveBuff(IBuff b) { lock (_buffsLock) { if (b.BuffAddType == BuffAddType.STACKS_AND_OVERLAPS && b.StackCount > 1) { b.DecrementStackCount(); RemoveBuff(b.Name); BuffList.Remove(b); RemoveBuffSlot(b); var tempbuffs = GetBuffsWithName(b.Name); tempbuffs.ForEach(tempbuff => tempbuff.SetStacks(b.StackCount)); BuffSlots[b.Slot] = tempbuffs[0]; Buffs.Add(b.Name, tempbuffs[0]); var newestBuff = tempbuffs[tempbuffs.Count - 1]; if (!b.IsHidden) { if (b.BuffType == BuffType.COUNTER) { _game.PacketNotifier.NotifyNPC_BuffUpdateNumCounter(Buffs[b.Name]); } else { if (b.StackCount == 1) { _game.PacketNotifier.NotifyNPC_BuffUpdateCount(newestBuff, b.Duration - newestBuff.TimeElapsed, newestBuff.TimeElapsed); } else { _game.PacketNotifier.NotifyNPC_BuffUpdateCountGroup(this, tempbuffs, b.Duration - newestBuff.TimeElapsed, newestBuff.TimeElapsed); } } } } else { BuffList.RemoveAll(buff => buff.Elapsed()); RemoveBuff(b.Name); RemoveBuffSlot(b); if (!b.IsHidden) { _game.PacketNotifier.NotifyNPC_BuffRemove2(b); } } } }
/// <summary> /// Remove a buff and its effects from the agent /// </summary> public void RemoveBuff(Buff buff) { BuffList.Remove(buff); }
public void AddBuff(IBuff b) { lock (_buffsLock) { if (!Buffs.ContainsKey(b.Name)) { if (HasBuff(b.Name)) { var buff = GetBuffsWithName(b.Name)[0]; Buffs.Add(b.Name, buff); return; } Buffs.Add(b.Name, b); BuffList.Add(b); if (!b.IsHidden) { _game.PacketNotifier.NotifyNPC_BuffAdd2(b); } b.ActivateBuff(); } else if (b.BuffAddType == BuffAddType.REPLACE_EXISTING) { var prevbuff = Buffs[b.Name]; prevbuff.DeactivateBuff(); RemoveBuff(b.Name); BuffList.Remove(prevbuff); RemoveBuffSlot(b); BuffSlots[prevbuff.Slot] = b; b.SetSlot(prevbuff.Slot); Buffs.Add(b.Name, b); BuffList.Add(b); if (!b.IsHidden) { _game.PacketNotifier.NotifyNPC_BuffReplace(b); } b.ActivateBuff(); } else if (b.BuffAddType == BuffAddType.RENEW_EXISTING) { Buffs[b.Name].ResetTimeElapsed(); if (!b.IsHidden) { _game.PacketNotifier.NotifyNPC_BuffReplace(Buffs[b.Name]); } RemoveStatModifier(Buffs[b.Name].GetStatsModifier()); // TODO: Replace with a better method that unloads -> reloads all data of a script Buffs[b.Name].ActivateBuff(); } else if (b.BuffAddType == BuffAddType.STACKS_AND_OVERLAPS) { if (Buffs[b.Name].StackCount >= Buffs[b.Name].MaxStacks) { var tempbuffs = GetBuffsWithName(b.Name); var oldestbuff = tempbuffs[0]; oldestbuff.DeactivateBuff(); RemoveBuff(b.Name); BuffList.Remove(oldestbuff); RemoveBuffSlot(oldestbuff); tempbuffs = GetBuffsWithName(b.Name); BuffSlots[oldestbuff.Slot] = tempbuffs[0]; Buffs.Add(oldestbuff.Name, tempbuffs[0]); BuffList.Add(b); if (!b.IsHidden) { if (Buffs[b.Name].BuffType == BuffType.COUNTER) { _game.PacketNotifier.NotifyNPC_BuffUpdateNumCounter(Buffs[b.Name]); } else { _game.PacketNotifier.NotifyNPC_BuffUpdateCount(b, b.Duration, b.TimeElapsed); } } b.ActivateBuff(); return; } BuffList.Add(b); Buffs[b.Name].IncrementStackCount(); GetBuffsWithName(b.Name).ForEach(buff => buff.SetStacks(Buffs[b.Name].StackCount)); if (!b.IsHidden) { if (b.BuffType == BuffType.COUNTER) { _game.PacketNotifier.NotifyNPC_BuffUpdateNumCounter(Buffs[b.Name]); } else { _game.PacketNotifier.NotifyNPC_BuffUpdateCount(b, b.Duration, b.TimeElapsed); } } b.ActivateBuff(); } else if (Buffs[b.Name].BuffAddType == BuffAddType.STACKS_AND_RENEWS) { RemoveBuffSlot(b); Buffs[b.Name].ResetTimeElapsed(); Buffs[b.Name].IncrementStackCount(); if (!b.IsHidden) { if (Buffs[b.Name].BuffType == BuffType.COUNTER) { _game.PacketNotifier.NotifyNPC_BuffUpdateNumCounter(Buffs[b.Name]); } else { _game.PacketNotifier.NotifyNPC_BuffUpdateCount(Buffs[b.Name], Buffs[b.Name].Duration, Buffs[b.Name].TimeElapsed); } } RemoveStatModifier(Buffs[b.Name].GetStatsModifier()); // TODO: Replace with a better method that unloads -> reloads all data of a script Buffs[b.Name].ActivateBuff(); } } }
public virtual void OnTurn() { //Console.WriteLine("NubiaMobile :: Tour"); m_turn++; if (m_turn > 1000) { m_turn = 0; } if (IsRenverse) { mTourRenverse--; if (mTourRenverse == 0) { Emote("*Se relève*"); SendMessage("Vous n'êtes plus renversé"); } else { ExposeToOpportunite(); } } NubiaBlessure toRemov = null; foreach (NubiaBlessure blessure in BlessureList) { blessure.OnTurn(this); if (blessure.TimeEnd <= DateTime.Now) { toRemov = blessure; break; } } if (toRemov != null) { BlessureList.Remove(toRemov); } List <AbstractBaseBuff> buffRemoveList = new List <AbstractBaseBuff>(); foreach (AbstractBaseBuff buff in BuffList) { if (Alive) { buff.OnTurn(); } if (buff.Turn < 1) { buffRemoveList.Add(buff); } } foreach (AbstractBaseBuff debuff in DebuffList) { if (debuff == null) { continue; } if (Alive) { debuff.OnTurn(); } if (debuff.Turn < 1) { buffRemoveList.Add(debuff); } } while (buffRemoveList.Count > 0) { AbstractBaseBuff r = buffRemoveList[0]; Console.WriteLine("Remove: " + r.Name); if (r.IsDebuff) { DebuffList.Remove(r as BaseDebuff); } else { BuffList.Remove(r); } buffRemoveList.RemoveAt(0); } }