private void Finallize() { LastScan?.Clear(); CachedEnemyMinionsWithAction?.Clear(); CachedAllyMinionsWithAction?.Clear(); CachedCombinedMinionsWithAction?.Clear(); CachedCombinedAttackableMinionsWithAction?.Clear(); CachedMinionsWithAction?.Clear(); CachedMonstersWithAction?.Clear(); }
internal IEnumerable <Obj_AI_Minion> GetMinions(CachedEntityType type, Func <Obj_AI_Minion, bool> predicate) { if (type < CachedEntityType.EnemyMinion) { throw new Exception($"Invalid type passed. {type} is not supported by Obj_AI_Minion."); } switch (type) { case CachedEntityType.EnemyMinion: { if (IsDisposing) { return(EntityManager.MinionsAndMonsters.EnemyMinions.Where(predicate)); } float lastScan; if (LastScan.TryGetValue(type, out lastScan)) { if (CachedEnemyMinionsWithAction == null) { CachedEnemyMinionsWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } if (Game.Time * 1000 - LastScan[type] < RefreshRate) { IEnumerable <Obj_AI_Minion> output; if (CachedEnemyMinionsWithAction.TryGetValue(predicate, out output)) { return(CachedEnemyMinionsWithAction[predicate]); } } CachedEnemyMinionsWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } else { if (CachedEnemyMinionsWithAction == null) { CachedEnemyMinionsWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } CachedEnemyMinionsWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } return(CachedEnemyMinionsWithAction[predicate]); } case CachedEntityType.AllyMinion: { if (IsDisposing) { return(EntityManager.MinionsAndMonsters.AlliedMinions.Where(predicate)); } float lastScan; if (LastScan.TryGetValue(type, out lastScan)) { if (CachedAllyMinionsWithAction == null) { CachedAllyMinionsWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } if (Game.Time * 1000 - LastScan[type] < RefreshRate) { IEnumerable <Obj_AI_Minion> output; if (CachedAllyMinionsWithAction.TryGetValue(predicate, out output)) { return(CachedAllyMinionsWithAction[predicate]); } } CachedAllyMinionsWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } else { if (CachedAllyMinionsWithAction == null) { CachedAllyMinionsWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } CachedAllyMinionsWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } return(CachedAllyMinionsWithAction[predicate]); } case CachedEntityType.Minions: { if (IsDisposing) { return(EntityManager.MinionsAndMonsters.Minions.Where(predicate)); } float lastScan; if (LastScan.TryGetValue(type, out lastScan)) { if (CachedMinionsWithAction == null) { CachedMinionsWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } if (Game.Time * 1000 - LastScan[type] < RefreshRate) { IEnumerable <Obj_AI_Minion> output; if (CachedMinionsWithAction.TryGetValue(predicate, out output)) { return(CachedMinionsWithAction[predicate]); } } CachedMinionsWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } else { if (CachedMinionsWithAction == null) { CachedMinionsWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } CachedMinionsWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } return(CachedMinionsWithAction[predicate]); } case CachedEntityType.CombinedAttackableMinions: { if (IsDisposing) { return(EntityManager.MinionsAndMonsters.CombinedAttackable.Where(predicate)); } float lastScan; if (LastScan.TryGetValue(type, out lastScan)) { if (CachedCombinedAttackableMinionsWithAction == null) { CachedCombinedAttackableMinionsWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } if (Game.Time * 1000 - LastScan[type] < RefreshRate) { IEnumerable <Obj_AI_Minion> output; if (CachedCombinedAttackableMinionsWithAction.TryGetValue(predicate, out output)) { return(CachedCombinedAttackableMinionsWithAction[predicate]); } } CachedCombinedAttackableMinionsWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } else { if (CachedCombinedAttackableMinionsWithAction == null) { CachedCombinedAttackableMinionsWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } CachedCombinedAttackableMinionsWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } return(CachedCombinedAttackableMinionsWithAction[predicate]); } case CachedEntityType.CombinedMinions: { if (IsDisposing) { return(EntityManager.MinionsAndMonsters.Combined.Where(predicate)); } float lastScan; if (LastScan.TryGetValue(type, out lastScan)) { if (CachedCombinedMinionsWithAction == null) { CachedCombinedMinionsWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } if (Game.Time * 1000 - LastScan[type] < RefreshRate) { IEnumerable <Obj_AI_Minion> output; if (CachedCombinedMinionsWithAction.TryGetValue(predicate, out output)) { return(CachedCombinedMinionsWithAction[predicate]); } } CachedCombinedMinionsWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } else { if (CachedCombinedMinionsWithAction == null) { CachedCombinedMinionsWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } CachedCombinedMinionsWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } return(CachedCombinedMinionsWithAction[predicate]); } case CachedEntityType.Monsters: { if (IsDisposing) { return(EntityManager.MinionsAndMonsters.Monsters.Where(predicate)); } float lastScan; if (LastScan.TryGetValue(type, out lastScan)) { if (CachedMonstersWithAction == null) { CachedMonstersWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } if (Game.Time * 1000 - LastScan[type] < RefreshRate) { IEnumerable <Obj_AI_Minion> output; if (CachedMonstersWithAction.TryGetValue(predicate, out output)) { return(CachedMonstersWithAction[predicate]); } } CachedMonstersWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } else { if (CachedMonstersWithAction == null) { CachedMonstersWithAction = new Dictionary <Func <Obj_AI_Minion, bool>, IEnumerable <Obj_AI_Minion> >(); } CachedMonstersWithAction[predicate] = GetMinions(type).Where(predicate); LastScan[type] = Game.Time * 1000; } return(CachedMonstersWithAction[predicate]); } } return(null); }