/// <summary> /// Restores all of the tokens to their default / healthy state. /// </summary> static public void HealTokens(TokenCountDictionary counts) { void RestoreAllToDefault(Token token) { if (token is not HealthToken ht || ht.Damage == 0) { return; } int num = counts[token]; counts.Adjust(ht.Healthy, num); counts.Adjust(token, -num); } void HealGroup(TokenClass group) { foreach (var token in counts.OfType(group).ToArray()) { RestoreAllToDefault(token); } } HealGroup(Invader.City); HealGroup(Invader.Town); HealGroup(TokenType.Dahan); }
static public bool Has(this TokenCountDictionary counts, TokenClass inv) => counts.OfType(inv).Any();
static public int Sum(this TokenCountDictionary counts, TokenClass generic) => counts.OfType(generic).Sum(k => counts[k]);