/// <summary> /// Checks elements available, and commits them (like the 'Any' element) /// </summary> public virtual async Task <bool> HasElements(ElementCounts subset) { // For normal spirits without Prepared Elements, this is the same as Could Have Elements if (Elements.Contains(subset)) { return(true); } int wildCount = Elements[Element.Any]; if (wildCount == 0) { return(false); } // We have some wild cards var missing = subset.Except(Elements); if (missing.Count > wildCount) { return(false); } if (await this.UserSelectsFirstText("Activate: " + subset.BuildElementString() + "?", $"Yes, use {missing.Count} 'Any' elments", "No thanks")) { foreach (var p in missing) { Elements[p.Key] += p.Value; } Elements[Element.Any] -= missing.Count; return(true); } return(false); }
protected ElementCounts actionElements; // null unless we are in the middle of an action public override async Task <bool> HasElements(ElementCounts subset) { if (actionElements == null) { actionElements = Elements.Clone(); } if (actionElements.Contains(subset)) { return(true); } // Check if we have prepared element markers to fill the missing elements if (PreparedElements.Any()) { var missing = subset.Except(actionElements); if (PreparedElements.Contains(missing) && await this.UserSelectsFirstText($"Meet elemental threshold:" + subset.BuildElementString(), "Yes, use prepared elements", "No, I'll pass.")) { foreach (var pair in missing) { PreparedElements[pair.Key] -= pair.Value; actionElements[pair.Key] += pair.Value; // assign to this action so next check recognizes them } return(true); } } return(false); }
/// <summary> /// Checks all elements that are available to spirit. /// </summary> public virtual bool CouldHaveElements(ElementCounts subset) { // For normal spirits without Prepared Elements, this is only the normal Elements int wildCount = Elements[Element.Any]; return(wildCount == 0 ? Elements.Contains(subset) // no 'wild-card' elements, Elements must contain subset : subset.Except(Elements).Count <= wildCount); // Find missing elements and count if they are less than our 'wild-card' elements }