mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 12:31:59 -08:00
refactor: removed outdated Player::assignDamage by multi amount dialog, fixed getMultiAmount to work with min values, added additional checks
This commit is contained in:
parent
86fc0028c1
commit
2d9ac4e732
12 changed files with 50 additions and 127 deletions
|
|
@ -104,7 +104,7 @@ public class AddConditionalManaOfAnyColorEffect extends ManaEffect {
|
|||
manaStrings.add("B");
|
||||
manaStrings.add("R");
|
||||
manaStrings.add("G");
|
||||
List<Integer> choices = controller.getMultiAmount(this.outcome, manaStrings, 0, value, MultiAmountType.MANA, game);
|
||||
List<Integer> choices = controller.getMultiAmount(this.outcome, manaStrings, 0, value, value, MultiAmountType.MANA, game);
|
||||
Mana mana = new Mana(choices.get(0), choices.get(1), choices.get(2), choices.get(3), choices.get(4), 0, 0, 0);
|
||||
return manaBuilder.setMana(mana, source, game).build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ public class AddManaInAnyCombinationEffect extends ManaEffect {
|
|||
|
||||
// Ask player for color distribution
|
||||
int manaAmount = amount.calculate(game, source, this);
|
||||
List<Integer> manaList = player.getMultiAmount(this.outcome, manaStrings, 0, manaAmount, MultiAmountType.MANA, game);
|
||||
List<Integer> manaList = player.getMultiAmount(this.outcome, manaStrings, 0, manaAmount, manaAmount, MultiAmountType.MANA, game);
|
||||
|
||||
// Convert choices to mana
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ public class DynamicManaEffect extends ManaEffect {
|
|||
manaStrings.add("B");
|
||||
manaStrings.add("R");
|
||||
manaStrings.add("G");
|
||||
List<Integer> choices = controller.getMultiAmount(this.outcome, manaStrings, 0, count, MultiAmountType.MANA, game);
|
||||
List<Integer> choices = controller.getMultiAmount(this.outcome, manaStrings, 0, count, count, MultiAmountType.MANA, game);
|
||||
computedMana.add(new Mana(choices.get(0), choices.get(1), choices.get(2), choices.get(3), choices.get(4), 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ public enum MultiAmountType {
|
|||
return res;
|
||||
}
|
||||
|
||||
public static boolean isGoodValues(List<Integer> values, List<MultiAmountMessage> constraints, int min, int max) {
|
||||
public static boolean isGoodValues(List<Integer> values, List<MultiAmountMessage> constraints, int totalMin, int totalMax) {
|
||||
if (values.size() != constraints.size()) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ public enum MultiAmountType {
|
|||
currentSum += value;
|
||||
}
|
||||
|
||||
return currentSum >= min && currentSum <= max;
|
||||
return currentSum >= totalMin && currentSum <= totalMax;
|
||||
}
|
||||
|
||||
public static List<Integer> parseAnswer(String answerToParse, List<MultiAmountMessage> constraints, int min,
|
||||
|
|
|
|||
|
|
@ -413,7 +413,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
/**
|
||||
* Draw cards. If you call it in replace events then use method with event param instead (for appliedEffects)
|
||||
*
|
||||
* @param num cards to draw
|
||||
* @param num cards to draw
|
||||
* @param source can be null for game default draws (non effects, example: start of the turn)
|
||||
* @return number of cards drawn, including as a result of replacement effects
|
||||
*/
|
||||
|
|
@ -422,7 +422,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
/**
|
||||
* Draw cards with applied effects, for replaceEvent
|
||||
*
|
||||
* @param num cards to draw
|
||||
* @param num cards to draw
|
||||
* @param source can be null for game default draws (non effects, example: start of the turn)
|
||||
* @param event original draw event in replacement code
|
||||
* @return number of cards drawn, including as a result of replacement effects
|
||||
|
|
@ -760,26 +760,28 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
*/
|
||||
UUID chooseBlockerOrder(List<Permanent> blockers, CombatGroup combatGroup, List<UUID> blockerOrder, Game game);
|
||||
|
||||
void assignDamage(int damage, List<UUID> targets, String singleTargetName, UUID attackerId, Ability source, Game game);
|
||||
|
||||
int getAmount(int min, int max, String message, Game game);
|
||||
|
||||
/**
|
||||
* Player distributes amount among multiple options
|
||||
*
|
||||
* @param outcome AI hint
|
||||
* @param messages List of options to distribute amount among
|
||||
* @param min Minimum value per option
|
||||
* @param max Total amount to be distributed
|
||||
* @param type MultiAmountType enum to set dialog options such as title and header
|
||||
* @param game Game
|
||||
* @param outcome AI hint
|
||||
* @param messages List of options to distribute amount among
|
||||
* @param optionMin Minimum value per option
|
||||
* @param totalMin Minimum total amount to be distributed
|
||||
* @param totalMax Total amount to be distributed
|
||||
* @param type MultiAmountType enum to set dialog options such as title and header
|
||||
* @param game Game
|
||||
* @return List of integers with size equal to messages.size(). The sum of the integers is equal to max.
|
||||
*/
|
||||
default List<Integer> getMultiAmount(Outcome outcome, List<String> messages, int min, int max, MultiAmountType type, Game game) {
|
||||
default List<Integer> getMultiAmount(Outcome outcome, List<String> messages, int optionMin, int totalMin, int totalMax, MultiAmountType type, Game game) {
|
||||
if (optionMin > totalMax || optionMin * messages.size() > totalMin) {
|
||||
throw new IllegalArgumentException(String.format("Wrong code usage: getMultiAmount found bad option min/max values: %d/%d", optionMin, totalMax));
|
||||
}
|
||||
List<MultiAmountMessage> constraints = messages.stream()
|
||||
.map(s -> new MultiAmountMessage(s, min, max))
|
||||
.map(s -> new MultiAmountMessage(s, optionMin, totalMax))
|
||||
.collect(Collectors.toList());
|
||||
return getMultiAmountWithIndividualConstraints(outcome, constraints, min, max, type, game);
|
||||
return getMultiAmountWithIndividualConstraints(outcome, constraints, totalMin, totalMax, type, game);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -787,13 +789,13 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
*
|
||||
* @param outcome AI hint
|
||||
* @param messages List of options to distribute amount among. Each option has a constraint on the min, max chosen for it
|
||||
* @param min Total minimum amount to be distributed
|
||||
* @param max Total amount to be distributed
|
||||
* @param totalMin Total minimum amount to be distributed
|
||||
* @param totalMax Total amount to be distributed
|
||||
* @param type MultiAmountType enum to set dialog options such as title and header
|
||||
* @param game Game
|
||||
* @return List of integers with size equal to messages.size(). The sum of the integers is equal to max.
|
||||
*/
|
||||
List<Integer> getMultiAmountWithIndividualConstraints(Outcome outcome, List<MultiAmountMessage> messages, int min, int max, MultiAmountType type, Game game);
|
||||
List<Integer> getMultiAmountWithIndividualConstraints(Outcome outcome, List<MultiAmountMessage> messages, int totalMin, int totalMax, MultiAmountType type, Game game);
|
||||
|
||||
void sideboard(Match match, Deck deck);
|
||||
|
||||
|
|
|
|||
|
|
@ -200,11 +200,6 @@ public class StubPlayer extends PlayerImpl {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignDamage(int damage, List<UUID> targets, String singleTargetName, UUID attackerId, Ability source, Game game) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount(int min, int max, String message, Game game) {
|
||||
return 0;
|
||||
|
|
@ -212,7 +207,7 @@ public class StubPlayer extends PlayerImpl {
|
|||
|
||||
@Override
|
||||
public List<Integer> getMultiAmountWithIndividualConstraints(Outcome outcome, List<MultiAmountMessage> messages,
|
||||
int min, int max, MultiAmountType type, Game game) {
|
||||
int totalMin, int totalMax, MultiAmountType type, Game game) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue