2 using System.Collections.Generic;
14 namespace Loot.Caching
28 public sealed
partial class ModifierCachePlayer :
ModPlayer 30 private static bool IsMouseUsable(Item item) => item.damage > 0;
46 _oldSelectedItem = player.selectedItem;
48 _oldEquips =
new Item[8];
49 _oldVanityEquips =
new Item[8];
50 _forceEquipUpdate =
false;
51 _oldCheatSheetEquips =
new Item[6];
52 _modifierEffects =
new List<Type>();
53 _detachList =
new List<(Item, Modifier)>();
54 _attachList =
new List<(Item, Modifier)>();
63 var tempList =
new List<ModifierEffect>();
64 foreach (var delegationTuple
in list)
66 var effectsAttribute =
67 delegationTuple.modifier
71 if (effectsAttribute == null)
continue;
72 tempList.AddRange(effectsAttribute.Effects
73 .Select(modDelegatorPlayer.GetEffect)
74 .Where(modEffect => modEffect != null && conditionFunc.Invoke(modEffect)));
95 var detachEffects = GetModifierEffectsForDelegations(_detachList, modDelegatorPlayer, (e) => e.IsBeingDelegated && !_modifierEffects.Contains(e.GetType()));
96 var attachEffects = GetModifierEffectsForDelegations(_attachList, modDelegatorPlayer, (e) => !e.IsBeingDelegated);
98 var orderedDetachList = OrderDelegationList(_detachList, modDelegatorPlayer)
99 .Where(x => x.effect.IsBeingDelegated && !_modifierEffects.Contains(x.effect.GetType()))
100 .GroupBy(x => x.methodInfo)
101 .Select(x => x.First())
104 var orderedAttachList = OrderDelegationList(_attachList, modDelegatorPlayer)
105 .Where(x => !x.effect.IsBeingDelegated)
106 .GroupBy(x => x.methodInfo)
107 .Select(x => x.First())
111 foreach (var effect
in detachEffects.Distinct())
113 modDelegatorPlayer.ResetEffectsEvent -= effect.ResetEffects;
114 effect._DetachDelegations(modDelegatorPlayer);
115 effect.IsBeingDelegated =
false;
119 foreach (var effect
in attachEffects.Distinct())
121 modDelegatorPlayer.ResetEffectsEvent += effect.ResetEffects;
122 effect.AttachDelegations(modDelegatorPlayer);
123 effect.IsBeingDelegated =
true;
127 foreach (var (methodInfo, effect) in orderedDetachList)
130 attr.
Detach(modDelegatorPlayer, methodInfo, effect);
134 foreach (var (methodInfo, effect) in orderedAttachList)
137 attr.
Attach(modDelegatorPlayer, methodInfo, effect);
148 var delegationEntries =
new List<(MethodInfo, ModifierEffect)>();
149 var effects = GetModifierEffectsForDelegations(list, modDelegatorPlayer, e =>
true);
151 foreach (var modEffect
in effects)
154 => (tuple.Item1, modEffect);
156 var delegatedMethods = modEffect
158 .GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)
159 .Where(x => x.GetCustomAttributes(typeof(
AutoDelegation),
false).Length > 0)
163 delegationEntries.AddRange(
166 .OrderByDescending(x => x.attribute.DelegationLevel)
169 delegationEntries.AddRange(
171 .Where(x => x.attribute == null)
174 delegationEntries.AddRange(
177 .OrderByDescending(x => x.attribute.DelegationLevel)
181 return delegationEntries;
187 if (_oldEquips.Length != 8 + player.extraAccessorySlots)
190 _forceEquipUpdate =
true;
191 Array.Resize(ref _oldEquips, 8 + player.extraAccessorySlots);
194 if (_oldVanityEquips.Length != 8 + player.extraAccessorySlots)
197 _forceEquipUpdate =
true;
198 Array.Resize(ref _oldVanityEquips, 8 + player.extraAccessorySlots);
205 if (ModSupportTunneler.GetModSupport<CheatSheetSupport>().ModIsLoaded)
207 UpdateCheatSheetCache();
212 if (!UpdateMouseItemCache())
214 UpdateHeldItemCache();
217 CacheModifierEffects();
220 _forceEquipUpdate =
false;
227 _detachList.Add((item, modifier));
233 _attachList.Add((item, modifier));
238 if (!_forceEquipUpdate && Ready)
241 _modifierEffects.Clear();
243 for (
int i = 0; i < 8 + player.extraAccessorySlots; i++)
245 var equip = player.armor[i];
246 if (equip != null && !equip.IsAir)
248 CacheItemModifierEffects(equip);
253 for (
int k = 13; k < 18 + player.extraAccessorySlots; k++)
255 var equip = player.armor[k];
260 CacheItemModifierEffects(equip);
264 if (Main.mouseItem != null && !Main.mouseItem.IsAir && Main.mouseItem.IsWeapon())
266 CacheItemModifierEffects(Main.mouseItem);
268 else if (player.HeldItem != null && !player.HeldItem.IsAir && player.HeldItem.IsWeapon())
270 CacheItemModifierEffects(player.HeldItem);
277 foreach (var modifier
in mods)
279 var effectsAttribute = modifier
283 if (effectsAttribute == null)
287 foreach (Type effect
in effectsAttribute.Effects)
289 var modEffect = modDelegatorPlayer.
GetEffect(effect);
290 if (modEffect != null && !_modifierEffects.Contains(modEffect.GetType()))
292 _modifierEffects.Add(modEffect.GetType());
Defines a modifier, which is an unloaded GlobalItem Making it a GlobalItem gives easy access to all h...
void AddAttachItem(Item item, Modifier modifier)
ModifierEffect GetEffect(Type type)
This attribute may be used to skip usage of AttachDelegations and DetachDelegations Which is a cumber...
List<(Item, Modifier)> _detachList
void UpdateAttachments()
This method handles updating all delegations First, it will perform 'manual' detachments calling Modi...
A ModifierEffect signifies the effect of a modifier on a player It should house the implementation...
void AddDetachItem(Item item, Modifier modifier)
void CacheModifierEffects()
void Detach(ModifierDelegatorPlayer delegatorPlayer, MethodInfo method, ModifierEffect effect)
IEnumerable< ModifierEffect > GetModifierEffectsForDelegations(IEnumerable<(Item item, Modifier modifier)> list, ModifierDelegatorPlayer modDelegatorPlayer, Func< ModifierEffect, bool > conditionFunc)
This method will return a list of ModifierEffects based on Modifiers passed to it ...
Can detect if an item was activated via cheats
DelegationPrioritization
Specify when you want your delegation to happen in the chain
void Attach(ModifierDelegatorPlayer delegatorPlayer, MethodInfo method, ModifierEffect effect)
Defines an item that may be modified by modifiers from mods
static ModifierDelegatorPlayer GetPlayer(Player player)
override void Initialize()
override void PostUpdate()
static List< Modifier > GetActivePool(Item item)
static LootModItem GetInfo(Item item)
IEnumerable<(MethodInfo methodInfo, ModifierEffect effect)> OrderDelegationList(IEnumerable<(Item item, Modifier modifier)> list, ModifierDelegatorPlayer modDelegatorPlayer)
This method orders delegation entries following the rules of DelegationPrioritizationAttribute which ...
void CacheItemModifierEffects(Item item)
List<(Item, Modifier)> _attachList
Item[] _oldCheatSheetEquips
static CheatedItemHackGlobalItem GetInfo(Item item)
bool IsActivated
Keeps track of if the particular item was activated ('delegated') Specific usecase see CursedEffect a...
This attribute is used to set a custom prioritization for a delegation It allows you to customize at ...
bool IsCheated
Keeps track of if the item was activated (by another mod) In this case activated means giving its reg...
Holds player-entity data and handles it
List< Type > _modifierEffects
This attribute is used to attach a certain Modifier to given ModifierEffects (can be attached to more...