public bool AddBuff(Actor user, Actor target, Buff buff) { buff.User = user; buff.Target = target; buff.World = target.World; // try to load in power sno from class attribute first, then try parent class (if there is one) Type buffType = buff.GetType(); int powerSNO = ImplementsPowerSNO.GetPowerSNOForClass(buffType); if (powerSNO != -1) { buff.PowerSNO = powerSNO; } else if (buffType.IsNested) { powerSNO = ImplementsPowerSNO.GetPowerSNOForClass(buffType.DeclaringType); if (powerSNO != -1) { buff.PowerSNO = powerSNO; } } buff.Init(); return(_AddBuff(buff)); }
private bool _AddBuff(Buff buff) { // look up or create a buff list for the target, then add/stack the buff according to its class type. // the logic is a bit more complex that it seems necessary because we ensure the buff appears in the // active buff list before calling Apply(), if Apply() fails we undo adding it. This allows buffs to // recursively add/stack more of their own buff type without worrying about overwriting existing buffs. if (_buffs.ContainsKey(buff.Target)) { Type buffType = buff.GetType(); Buff existingBuff = _buffs[buff.Target].FirstOrDefault(b => b != null && b.GetType() == buffType); if (existingBuff != null) { if (existingBuff.Stack(buff)) { return(true); } // buff is non-stacking, just add normally } _buffs[buff.Target].Add(buff); if (buff.Apply()) { return(true); } else { _buffs[buff.Target].Remove(buff); return(false); } } else { var keyBuffs = new List <Buff>(); keyBuffs.Add(buff); _buffs[buff.Target] = keyBuffs; if (buff.Apply()) { return(true); } else { _buffs.Remove(buff.Target); return(false); } } }