private EntityGroupDependencies GetGroups <T>(string groupName, string[] dependencies) where T : Entity { var deps = new EntityGroupDependencies(); if (dependencies == null) { return(deps); } IDictionary <string, IReadOnlySet <int> > entityGroups; switch (typeof(T).Name) { case "Item": entityGroups = this.ItemGroups; break; case "NPC": entityGroups = this.NPCGroups; break; case "Projectile": entityGroups = this.ProjGroups; break; default: throw new NotImplementedException("Invalid Entity type " + typeof(T).Name); } foreach (string dependency in dependencies) { if (!entityGroups.ContainsKey(dependency)) { if (this._AlreadyRequeued.Contains(groupName)) { throw new ModHelpersException("Entity group " + groupName + " could not find dependency " + dependency + "."); } this._AlreadyRequeued.Add(groupName); return(deps); } deps[dependency] = entityGroups[dependency]; } return(deps); }
private bool ComputeGroupMatch <T>(IList <T> entityPool, EntityGroupMatcherDefinition <T> matcher, out ISet <int> entityIdsOfGroup) where T : Entity { entityIdsOfGroup = new HashSet <int>(); EntityGroupDependencies deps = this.GetGroups <T>(matcher.GroupName, matcher.GroupDependencies); for (int i = 1; i < entityPool.Count; i++) { try { lock (EntityGroups.MyLock) { if (matcher.Matcher.MatcherFunc(entityPool[i], deps)) { entityIdsOfGroup.Add(i); } } } catch (Exception) { LogHelpers.Alert("Compute fail for '" + matcher.GroupName + "' with ent (" + i + ") " + (entityPool[i] == null ? "null" : entityPool[i].ToString())); } } return(true); }