mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -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
|
|
@ -2232,13 +2232,6 @@ public class ComputerPlayer extends PlayerImpl {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignDamage(int damage, List<UUID> targets, String singleTargetName, UUID attackerId, Ability source, Game game) {
|
||||
log.debug("assignDamage");
|
||||
//TODO: improve this
|
||||
game.getPermanent(targets.get(0)).damage(damage, attackerId, source, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO: add AI support with outcome and replace random with min/max
|
||||
public int getAmount(int min, int max, String message, Game game) {
|
||||
|
|
@ -2254,11 +2247,11 @@ public class ComputerPlayer 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) {
|
||||
log.debug("getMultiAmount");
|
||||
|
||||
int needCount = messages.size();
|
||||
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(messages, min, max);
|
||||
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(messages, totalMin, totalMax);
|
||||
if (needCount == 0) {
|
||||
return defaultList;
|
||||
}
|
||||
|
|
@ -2273,7 +2266,7 @@ public class ComputerPlayer extends PlayerImpl {
|
|||
// GOOD effect
|
||||
// values must be stable, so AI must able to simulate it and choose correct actions
|
||||
// fill max values as much as possible
|
||||
return MultiAmountType.prepareMaxValues(messages, min, max);
|
||||
return MultiAmountType.prepareMaxValues(messages, totalMin, totalMax);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -390,38 +390,6 @@ public final class SimulatedPlayerMCTS extends MCTSPlayer {
|
|||
return super.chooseBlockerOrder(blockers, combatGroup, blockerOrder, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignDamage(int damage, List<UUID> targets, String singleTargetName, UUID attackerId, Ability source, Game game) {
|
||||
if (this.isHuman()) {
|
||||
int remainingDamage = damage;
|
||||
UUID targetId;
|
||||
int amount;
|
||||
while (remainingDamage > 0) {
|
||||
if (targets.size() == 1) {
|
||||
targetId = targets.get(0);
|
||||
amount = remainingDamage;
|
||||
} else {
|
||||
targetId = targets.get(RandomUtil.nextInt(targets.size()));
|
||||
amount = RandomUtil.nextInt(damage + 1);
|
||||
}
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent != null) {
|
||||
permanent.damage(amount, attackerId, source, game, false, true);
|
||||
remainingDamage -= amount;
|
||||
} else {
|
||||
Player player = game.getPlayer(targetId);
|
||||
if (player != null) {
|
||||
player.damage(amount, attackerId, source, game);
|
||||
remainingDamage -= amount;
|
||||
}
|
||||
}
|
||||
targets.remove(targetId);
|
||||
}
|
||||
} else {
|
||||
super.assignDamage(damage, targets, singleTargetName, attackerId, source, game);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount(int min, int max, String message, Game game) {
|
||||
if (this.isHuman()) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ import mage.target.Target;
|
|||
import mage.target.TargetAmount;
|
||||
import mage.target.TargetCard;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.common.TargetAnyTarget;
|
||||
import mage.target.common.TargetAttackingCreature;
|
||||
import mage.target.common.TargetDefender;
|
||||
import mage.target.targetpointer.TargetPointer;
|
||||
|
|
@ -1140,7 +1139,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
}
|
||||
|
||||
// ask and assign new amount
|
||||
List<Integer> targetValues = getMultiAmount(outcome, targetNames, 1, amountTotal, multiAmountType, game);
|
||||
List<Integer> targetValues = getMultiAmount(outcome, targetNames, 1, amountTotal, amountTotal, multiAmountType, game);
|
||||
for (int i = 0; i < targetValues.size(); i++) {
|
||||
int newAmount = targetValues.get(i);
|
||||
UUID targetId = targets.get(i);
|
||||
|
|
@ -1916,7 +1915,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
// check if enough attackers are declared
|
||||
// check if players have to be attacked
|
||||
Set<UUID> playersToAttackIfAble = new HashSet<>();
|
||||
|
||||
|
||||
// or if active player must attack with anything
|
||||
boolean mustAttack = false;
|
||||
|
||||
|
|
@ -1927,7 +1926,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
if (playerToAttack != null) {
|
||||
playersToAttackIfAble.add(playerToAttack);
|
||||
}
|
||||
if (effect.mustAttack(game)){
|
||||
if (effect.mustAttack(game)) {
|
||||
mustAttack = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1967,10 +1966,10 @@ public class HumanPlayer extends PlayerImpl {
|
|||
}
|
||||
}
|
||||
|
||||
if (mustAttack && game.getCombat().getAttackers().isEmpty()){
|
||||
if (mustAttack && game.getCombat().getAttackers().isEmpty()) {
|
||||
// no attackers, but required to attack with something -- check if anything can attack
|
||||
for (Permanent attacker : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, getId(), game)) {
|
||||
if (attacker.canAttackInPrinciple(null, game)){
|
||||
if (attacker.canAttackInPrinciple(null, game)) {
|
||||
game.informPlayer(this, "You are forced to attack with at least one creature, e.g. " + attacker.getIdName() + ".");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -2206,33 +2205,6 @@ public class HumanPlayer extends PlayerImpl {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assignDamage(int damage, java.util.List<UUID> targets, String singleTargetName, UUID attackerId, Ability source, Game game) {
|
||||
int remainingDamage = damage;
|
||||
while (remainingDamage > 0 && canRespond()) {
|
||||
Target target = new TargetAnyTarget();
|
||||
target.withNotTarget(true);
|
||||
if (singleTargetName != null) {
|
||||
target.withTargetName(singleTargetName);
|
||||
}
|
||||
this.choose(Outcome.Damage, target, source, game);
|
||||
if (targets.isEmpty() || targets.contains(target.getFirstTarget())) {
|
||||
int damageAmount = this.getAmount(0, remainingDamage, "Select amount", game);
|
||||
Permanent permanent = game.getPermanent(target.getFirstTarget());
|
||||
if (permanent != null) {
|
||||
permanent.damage(damageAmount, attackerId, source, game, false, true);
|
||||
remainingDamage -= damageAmount;
|
||||
} else {
|
||||
Player player = game.getPlayer(target.getFirstTarget());
|
||||
if (player != null) {
|
||||
player.damage(damageAmount, attackerId, source, game);
|
||||
remainingDamage -= damageAmount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount(int min, int max, String message, Game game) {
|
||||
if (gameInCheckPlayableState(game)) {
|
||||
|
|
@ -2262,15 +2234,16 @@ public class HumanPlayer extends PlayerImpl {
|
|||
public List<Integer> getMultiAmountWithIndividualConstraints(
|
||||
Outcome outcome,
|
||||
List<MultiAmountMessage> messages,
|
||||
int min,
|
||||
int max,
|
||||
int totalMin,
|
||||
int totalMax,
|
||||
MultiAmountType type,
|
||||
Game game
|
||||
) {
|
||||
int needCount = messages.size();
|
||||
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(messages, min, max);
|
||||
if (needCount == 0 || (needCount == 1 && min == max)
|
||||
List<Integer> defaultList = MultiAmountType.prepareDefaltValues(messages, totalMin, totalMax);
|
||||
if (needCount == 0 || (needCount == 1 && totalMin == totalMax)
|
||||
|| messages.stream().map(m -> m.min == m.max).reduce(true, Boolean::logicalAnd)) {
|
||||
// nothing to choose
|
||||
return defaultList;
|
||||
}
|
||||
|
||||
|
|
@ -2288,19 +2261,19 @@ public class HumanPlayer extends PlayerImpl {
|
|||
if (type.isCanCancel()) {
|
||||
options.put("canCancel", true);
|
||||
}
|
||||
game.fireGetMultiAmountEvent(playerId, messages, min, max, options);
|
||||
game.fireGetMultiAmountEvent(playerId, messages, totalMin, totalMax, options);
|
||||
}
|
||||
waitForResponse(game);
|
||||
|
||||
// waiting correct values only
|
||||
if (response.getString() != null) {
|
||||
answer = MultiAmountType.parseAnswer(response.getString(), messages, min, max, false);
|
||||
if (MultiAmountType.isGoodValues(answer, messages, min, max)) {
|
||||
answer = MultiAmountType.parseAnswer(response.getString(), messages, totalMin, totalMax, false);
|
||||
if (MultiAmountType.isGoodValues(answer, messages, totalMin, totalMax)) {
|
||||
break;
|
||||
} else {
|
||||
// it's not normal: can be cheater or a wrong GUI checks
|
||||
answer = null;
|
||||
logger.error(String.format("GUI return wrong MultiAmountType values: %d %d %d - %s", needCount, min, max, response.getString()));
|
||||
logger.error(String.format("GUI return wrong MultiAmountType values: %d %d %d - %s", needCount, totalMin, totalMax, response.getString()));
|
||||
game.informPlayer(this, "Error, you must enter correct values.");
|
||||
}
|
||||
} else if (type.isCanCancel() && response.getBoolean() != null) {
|
||||
|
|
@ -2594,8 +2567,8 @@ public class HumanPlayer extends PlayerImpl {
|
|||
modeText = Character.toUpperCase(modeText.charAt(0)) + modeText.substring(1);
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (mode.getPawPrintValue() > 0){
|
||||
for (int i = 0; i < mode.getPawPrintValue(); ++i){
|
||||
if (mode.getPawPrintValue() > 0) {
|
||||
for (int i = 0; i < mode.getPawPrintValue(); ++i) {
|
||||
sb.append("{P}");
|
||||
}
|
||||
sb.append(": ");
|
||||
|
|
@ -2617,7 +2590,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
|
||||
// prepare dialog
|
||||
String message;
|
||||
if (modes.getMaxPawPrints() == 0){
|
||||
if (modes.getMaxPawPrints() == 0) {
|
||||
message = "Choose mode (selected " + modes.getSelectedModes().size() + " of " + modes.getMaxModes(game, source)
|
||||
+ ", min " + modes.getMinModes() + ")";
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue