forked from External/mage
Reworked cost adjuster logic for better support of X and cost modification effects:
Improves: * refactor: split CostAdjuster logic in multiple parts - prepare X, prepare cost, increase cost, reduce cost; * refactor: improved VariableManaCost to support min/max values, playable and AI calculations, test framework; * refactor: improved EarlyTargetCost to support mana costs too (related to #13023); * refactor: migrated some cards with CostAdjuster and X to EarlyTargetCost (Knollspine Invocation, etc - related to #13023); * refactor: added shared code for "As an additional cost to cast this spell, discard X creature cards"; * refactor: added shared code for "X is the converted mana cost of the exiled card"; * tests: added dozens tests with cost adjusters; Bug fixes: * game: fixed that some cards with CostAdjuster ignore min/max limits for X (allow to choose any X, example: Scorched Earth, Open The Way); * game: fixed that some cards ask to announce already defined X values (example: Bargaining Table); * game: fixed that some cards with CostAdjuster do not support combo with other cost modification effects; * game, gui: fixed missing game logs about predefined X values; * game, gui: fixed wrong X icon for predefined X values; Test framework: * test framework: added X min/max check for wrong values; * test framework: added X min/max info in miss X value announce; * test framework: added check to find duplicated effect bugs (see assertNoDuplicatedEffects); Cards: * Open The Way - fixed that it allow to choose any X without limits (close #12810); * Unbound Flourishing - improved combo support for activated abilities with predefined X mana costs like Bargaining Table;
This commit is contained in:
parent
13a832ae00
commit
bae3089abb
100 changed files with 1519 additions and 449 deletions
|
|
@ -1079,6 +1079,53 @@ public final class CardUtil {
|
|||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static Set<UUID> getAllPossibleTargets(Cost cost, Game game, Ability source) {
|
||||
return cost.getTargets()
|
||||
.stream()
|
||||
.map(t -> t.possibleTargets(source.getControllerId(), source, game))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Distribute values between min and max and make sure that the values will be evenly distributed
|
||||
* Use it to limit possible values list like mana options
|
||||
*/
|
||||
public static List<Integer> distributeValues(int count, int min, int max) {
|
||||
List<Integer> res = new ArrayList<>();
|
||||
if (count <= 0 || min > max) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (min == max) {
|
||||
res.add(min);
|
||||
return res;
|
||||
}
|
||||
|
||||
int range = max - min + 1;
|
||||
|
||||
// low possible amount
|
||||
if (range <= count) {
|
||||
for (int i = 0; i < range; i++) {
|
||||
res.add(min + i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// big possible amount, so skip some values
|
||||
double step = (double) (max - min) / (count - 1);
|
||||
for (int i = 0; i < count; i++) {
|
||||
res.add(min + (int) Math.round(i * step));
|
||||
}
|
||||
// make sure first and last elements are good
|
||||
res.set(0, min);
|
||||
if (res.size() > 1) {
|
||||
res.set(res.size() - 1, max);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* For finding the spell or ability on the stack for "becomes the target" triggers.
|
||||
*
|
||||
|
|
@ -1908,6 +1955,10 @@ public final class CardUtil {
|
|||
return defaultValue;
|
||||
}
|
||||
|
||||
public static int getSourceCostsTagX(Game game, Ability source, int defaultValue) {
|
||||
return getSourceCostsTag(game, source, "X", defaultValue);
|
||||
}
|
||||
|
||||
public static String addCostVerb(String text) {
|
||||
if (costWords.stream().anyMatch(text.toLowerCase(Locale.ENGLISH)::startsWith)) {
|
||||
return text;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue