public void AddUsableEffectHandler(UsableEffectHandler 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(EffectBase), typeof(Character), typeof(BasePlayerItem) }); if (constructor == null) { throw new System.Exception("No valid constructors found !"); } foreach (EffectsEnum current in from entry in array select entry.Effect) { this.m_usablesEffectHandler.Add(current, constructor.CreateDelegate <EffectManager.UsableEffectConstructor>()); if (!this.m_effectsHandlers.ContainsKey(current)) { this.m_effectsHandlers.Add(current, new System.Collections.Generic.List <System.Type>()); } this.m_effectsHandlers[current].Add(type); } }
public void AddSpellCastHandler(System.Type handler, SpellTemplate spell) { System.Reflection.ConstructorInfo constructor = handler.GetConstructor(new System.Type[] { typeof(FightActor), typeof(Spell), typeof(Cell), typeof(bool) }); if (constructor == null) { throw new System.Exception(string.Format("Handler {0} : No valid constructor found !", handler.Name)); } this.m_spellsCastHandler.Add(spell.Id, constructor.CreateDelegate <SpellManager.SpellCastConstructor>()); }
private void InitializeEffectHandlers() { foreach (System.Type current in from entry in System.Reflection.Assembly.GetExecutingAssembly().GetTypes() where entry.IsSubclassOf(typeof(EffectHandler)) && !entry.IsAbstract select entry) { if (current.GetCustomAttribute <DefaultEffectHandlerAttribute>() == null) { EffectHandlerAttribute[] array = current.GetCustomAttributes <EffectHandlerAttribute>().ToArray <EffectHandlerAttribute>(); if (array.Length == 0) { EffectManager.logger.Error("EffectHandler '{0}' has no EffectHandlerAttribute", current.Name); } else { foreach (EffectsEnum current2 in array.Select((EffectHandlerAttribute entry) => entry.Effect)) { if (current.IsSubclassOf(typeof(ItemEffectHandler))) { System.Reflection.ConstructorInfo constructor = current.GetConstructor(new System.Type[] { typeof(EffectBase), typeof(Character), typeof(BasePlayerItem) }); this.m_itemsEffectHandler.Add(current2, constructor.CreateDelegate <EffectManager.ItemEffectConstructor>()); System.Reflection.ConstructorInfo constructor2 = current.GetConstructor(new System.Type[] { typeof(EffectBase), typeof(Character), typeof(ItemSetTemplate), typeof(bool) }); if (constructor2 != null) { this.m_itemsSetEffectHandler.Add(current2, constructor2.CreateDelegate <EffectManager.ItemSetEffectConstructor>()); } } else { if (current.IsSubclassOf(typeof(UsableEffectHandler))) { System.Reflection.ConstructorInfo constructor = current.GetConstructor(new System.Type[] { typeof(EffectBase), typeof(Character), typeof(BasePlayerItem) }); this.m_usablesEffectHandler.Add(current2, constructor.CreateDelegate <EffectManager.UsableEffectConstructor>()); } else { if (current.IsSubclassOf(typeof(SpellEffectHandler))) { System.Reflection.ConstructorInfo constructor = current.GetConstructor(new System.Type[] { typeof(EffectDice), typeof(FightActor), typeof(Stump.Server.WorldServer.Game.Spells.Spell), typeof(Cell), typeof(bool) }); this.m_spellsEffectHandler.Add(current2, constructor.CreateDelegate <EffectManager.SpellEffectConstructor>()); } } } if (!this.m_effectsHandlers.ContainsKey(current2)) { this.m_effectsHandlers.Add(current2, new System.Collections.Generic.List <System.Type>()); } this.m_effectsHandlers[current2].Add(current); } } } } }