public void AddSpellEffectHandler(SpellEffectHandler handler) { var type = handler.GetType(); if (type.GetCustomAttribute <DefaultEffectHandlerAttribute>() != null) { throw new Exception("Default handler cannot be added"); } var attributes = type.GetCustomAttributes <EffectHandlerAttribute>().ToArray(); if (attributes.Length == 0) { throw new Exception(string.Format("EffectHandler '{0}' has no EffectHandlerAttribute", type.Name)); } var ctor = type.GetConstructor(new[] { typeof(EffectDice), typeof(FightActor), typeof(SpellCastHandler), typeof(Cell), typeof(bool) }); if (ctor == null) { throw new Exception("No valid constructors found !"); } foreach (var effect in attributes.Select(entry => entry.Effect)) { m_spellsEffectHandler.Add(effect, ctor.CreateDelegate <SpellEffectConstructor>()); if (!m_effectsHandlers.ContainsKey(effect)) { m_effectsHandlers.Add(effect, new List <Type>()); } m_effectsHandlers[effect].Add(type); } }
public void AddSpellEffectHandler(SpellEffectHandler handler) { System.Type type = handler.GetType(); if (type.GetCustomAttribute <DefaultEffectHandlerAttribute>() != null) { throw new System.Exception("Default handler cannot be added"); } EffectHandlerAttribute[] array = type.GetCustomAttributes <EffectHandlerAttribute>().ToArray <EffectHandlerAttribute>(); if (array.Length == 0) { throw new System.Exception(string.Format("EffectHandler '{0}' has no EffectHandlerAttribute", type.Name)); } System.Reflection.ConstructorInfo constructor = type.GetConstructor(new System.Type[] { typeof(EffectDice), typeof(FightActor), typeof(Stump.Server.WorldServer.Game.Spells.Spell), typeof(Cell), typeof(bool) }); if (constructor == null) { throw new System.Exception("No valid constructors found !"); } foreach (EffectsEnum current in from entry in array select entry.Effect) { this.m_spellsEffectHandler.Add(current, constructor.CreateDelegate <EffectManager.SpellEffectConstructor>()); if (!this.m_effectsHandlers.ContainsKey(current)) { this.m_effectsHandlers.Add(current, new System.Collections.Generic.List <System.Type>()); } this.m_effectsHandlers[current].Add(type); } }