public override async Task <ElementCounts> SelectInnateToActivate(IEnumerable <IDrawableInnateOption> innateOptions) { var elementOptions = innateOptions.Select(x => x.Elements); // Init the elements that are active for this action only. if (actionElements == null) { actionElements = Elements.Clone(); } var highestAlreadyMatch = innateOptions .OrderByDescending(e => e.Elements.Total) .FirstOrDefault(x => actionElements.Contains(x.Elements)); var canMeetWithPrepared = innateOptions // .Elements .Where(x => !actionElements.Contains(x.Elements) && PreparedElements.Contains(x.Elements.Except(actionElements))) .ToArray(); // If we can't extend with prepared, just return what we can if (canMeetWithPrepared.Length > 0) { // if we CAN meet something with Prepared, return string prompt = highestAlreadyMatch != null ? "Extend element threshold? (current: " + highestAlreadyMatch.Elements.BuildElementString() + ")" : "Meet element threshold?"; // Select which Extened we want to meet. var options = canMeetWithPrepared .OrderBy(e => e.Elements.Total) // smallest first .ToList(); if (highestAlreadyMatch != null) { options.Insert(0, highestAlreadyMatch); } Present present = highestAlreadyMatch != null ? Present.Always : Present.Done; IDrawableInnateOption extendedOption = await this.Select <IDrawableInnateOption>(prompt, options.ToArray(), present); if (extendedOption != null) { // Apply necessary prepared elements to the action Elements. var preparedElementsToConsume = extendedOption.Elements.Except(actionElements); foreach (var consumeEl in preparedElementsToConsume) { PreparedElements[consumeEl.Key] -= consumeEl.Value; actionElements[consumeEl.Key] += consumeEl.Value; } return(extendedOption.Elements); } } return(highestAlreadyMatch?.Elements); }
WrappingText_InnateOptions CalcInnateOptionLayout(IDrawableInnateOption option, int originalX, int originalY, int width, Graphics graphics) { int x = originalX; int y = originalY; var wrappingText = new WrappingText_InnateOptions { GroupOption = option, }; string elementString = option.Elements.BuildElementString(); string description = option.Description; // Elements using var boldFont = BuildBoldFont(); // !! CalcWrappingString(wrappingText.tokens, wrappingText.boldTexts, elementString, boldFont, ref x, ref y, originalX, width, graphics); // Text using var font = BuildFont(); // !! CalcWrappingString(wrappingText.tokens, wrappingText.regularTexts, description, font, ref x, ref y, originalX, width, graphics); y += rowHeight; wrappingText.Bounds = new Rectangle(originalX, originalY, width, y - originalY); return(wrappingText); }