public static int MobileNotoriety(Mobile a, Mobile b) { if (_NotorietyParent == null) { _NotorietyParent = NotorietyHandlers.MobileNotoriety; } if (a == null || a.Deleted || b == null || b.Deleted) { return(_NotorietyParent(a, b)); } foreach (var handler in _NameHandlers.Where(e => e.Handler != null) .OrderByDescending(e => e.Priority) .Select(e => e.Handler)) { bool handled; var result = handler(a, b, out handled); if (handled) { if (result <= Bubble) { break; } return(result); } } return(_NotorietyParent(a, b)); }
public static void CSDispose() { Notoriety.Handler = _NotorietyParent ?? NotorietyHandlers.MobileNotoriety; Mobile.AllowBeneficialHandler = _BeneficialParent ?? NotorietyHandlers.Mobile_AllowBeneficial; Mobile.AllowHarmfulHandler = _HarmfulParent ?? NotorietyHandlers.Mobile_AllowHarmful; _NotorietyParent = null; _BeneficialParent = null; _HarmfulParent = null; }
protected NotorietyHandlerChain() { // Store the original handlers in some read only private variables // so we can call them later if need be. _notorietyHandlerSuccessor = Notoriety.Handler; _allowBeneficialHandlerSuccessor = Mobile.AllowBeneficialHandler; _allowHarmfulHandlerSuccessor = Mobile.AllowHarmfulHandler; // Set the current handlers to our new chain handlers. Notoriety.Handler = HandleNotoriety; Mobile.AllowBeneficialHandler = AllowBeneficial; Mobile.AllowHarmfulHandler = AllowHarmful; }
public static int MobileNotoriety(Mobile a, IDamageable b) { if (b is Mobile) { return(MobileNotoriety(a, (Mobile)b)); } if (_NotorietyParent == null) { _NotorietyParent = NotorietyHandlers.MobileNotoriety; } return(_NotorietyParent(a, b)); }
private static void CSInvoke() { if (_NotorietyParent == null && Notoriety.Handler != MobileNotoriety) { _NotorietyParent = Notoriety.Handler ?? NotorietyHandlers.MobileNotoriety; } if (_BeneficialParent == null && Mobile.AllowBeneficialHandler != AllowBeneficial) { _BeneficialParent = Mobile.AllowBeneficialHandler ?? NotorietyHandlers.Mobile_AllowBeneficial; } if (_HarmfulParent == null && Mobile.AllowHarmfulHandler != AllowHarmful) { _HarmfulParent = Mobile.AllowHarmfulHandler ?? NotorietyHandlers.Mobile_AllowHarmful; } Notoriety.Handler = MobileNotoriety; Mobile.AllowBeneficialHandler = AllowBeneficial; Mobile.AllowHarmfulHandler = AllowHarmful; }
public NotorietyEntry(int priority, NotorietyHandler <T> handler) { Priority = priority; Handler = handler; }
public static void UnregisterHarmfulHandler(NotorietyHandler <bool> handler) { _HarmfulHandlers.RemoveAll(e => e.Handler == handler); }
public static void RegisterHarmfulHandler(NotorietyHandler <bool> handler, int priority = 0) { UnregisterHarmfulHandler(handler); _HarmfulHandlers.Add(new NotorietyEntry <bool>(priority, handler)); }
public static void UnregisterBeneficialHandler(NotorietyHandler <bool> handler) { _BeneficialHandlers.RemoveAll(e => e.Handler == handler); }
public static void UnregisterNameHandler(NotorietyHandler <int> handler) { _NameHandlers.RemoveAll(e => e.Handler == handler); }
public static void RegisterNameHandler(NotorietyHandler <int> handler, int priority = 0) { UnregisterNameHandler(handler); _NameHandlers.Add(new NotorietyEntry <int>(priority, handler)); }
public static void Disable() { Notoriety.Handler = _NotorietyParent ?? NotorietyHandlers.MobileNotoriety; Mobile.AllowBeneficialHandler = _BeneficialParent ?? NotorietyHandlers.Mobile_AllowBeneficial; Mobile.AllowHarmfulHandler = _HarmfulParent ?? NotorietyHandlers.Mobile_AllowHarmful; _NotorietyParent = null; _BeneficialParent = null; _HarmfulParent = null; }
public static void Enable() { if (_NotorietyParent == null && Notoriety.Handler != MobileNotoriety) { _NotorietyParent = Notoriety.Handler ?? NotorietyHandlers.MobileNotoriety; } if (_BeneficialParent == null && Mobile.AllowBeneficialHandler != AllowBeneficial) { _BeneficialParent = Mobile.AllowBeneficialHandler ?? NotorietyHandlers.Mobile_AllowBeneficial; } if (_HarmfulParent == null && Mobile.AllowHarmfulHandler != AllowHarmful) { _HarmfulParent = Mobile.AllowHarmfulHandler ?? NotorietyHandlers.Mobile_AllowHarmful; } Notoriety.Handler = MobileNotoriety; Mobile.AllowBeneficialHandler = AllowBeneficial; Mobile.AllowHarmfulHandler = AllowHarmful; }
public static void Initialize() { NotoHandler = new NotorietyHandler(Handle_Notoriety); }