2 using System.Collections.Generic;
8 namespace Loot.Api.Attributes
17 [AttributeUsage(AttributeTargets.Method)]
22 public IEnumerable<string> DelegationTypes =>
new List<string>(_delegationTypes);
26 _delegationTypes =
new List<string>(GetTargetNames(types));
31 _delegationTypes =
new List<string>(
32 GetTargetNames(targets
36 private IEnumerable<string> GetTargetNames(IEnumerable<string> names)
37 => names.Select(GetFilteredName);
41 if (name.StartsWith(
"On")) name = name.Substring(2);
42 if (!name.EndsWith(
"Event")) name = $
"{name}Event";
48 foreach (
string type
in _delegationTypes)
50 EventInfo evt = delegatorPlayer.GetType().GetEvent(type, BindingFlags.Instance | BindingFlags.Public);
55 Delegate handler = Delegate.CreateDelegate(evt.EventHandlerType, effect, method);
56 evt.AddEventHandler(delegatorPlayer, handler);
60 Loot.Logger.Error(
"An error just occurred. Please share this error log with the mod author.", e);
68 foreach (
string type
in _delegationTypes)
70 EventInfo evt = delegatorPlayer.GetType().GetEvent(type, BindingFlags.Instance | BindingFlags.Public);
75 Delegate handler = Delegate.CreateDelegate(evt.EventHandlerType, effect, method);
76 evt.RemoveEventHandler(delegatorPlayer, handler);
80 Loot.Logger.Error(
"An error just occurred. Please share this error log with the mod author.", e);
This attribute may be used to skip usage of AttachDelegations and DetachDelegations Which is a cumber...
string GetFilteredName(string name)
A ModifierEffect signifies the effect of a modifier on a player It should house the implementation...
void Detach(ModifierDelegatorPlayer delegatorPlayer, MethodInfo method, ModifierEffect effect)
readonly IEnumerable< string > _delegationTypes
void Attach(ModifierDelegatorPlayer delegatorPlayer, MethodInfo method, ModifierEffect effect)
AutoDelegation(params string[] types)
DelegationTarget
Defines a target that can be used in conjunction with AutoDelegation for identifying the target event...
Holds player-entity data and handles it
AutoDelegation(params DelegationTarget[] targets)