Merge branch 'master' into feature/implement-harmonize-ability

This commit is contained in:
theelk801 2025-03-31 09:15:25 -04:00
commit 970699de59
54 changed files with 1327 additions and 511 deletions

View file

@ -16,24 +16,30 @@ import mage.util.CardUtil;
public class PayMoreToCastAsThoughtItHadFlashAbility extends SpellAbility {
private final Cost costsToAdd;
private final String rule;
public PayMoreToCastAsThoughtItHadFlashAbility(Card card, Cost costsToAdd) {
this(card, costsToAdd, null);
}
public PayMoreToCastAsThoughtItHadFlashAbility(Card card, Cost costsToAdd, String rule) {
super(card.getSpellAbility().getManaCosts().copy(), card.getName(), Zone.HAND, SpellAbilityType.BASE_ALTERNATE);
this.costsToAdd = costsToAdd;
this.rule = rule;
this.timing = TimingRule.INSTANT;
this.setRuleAtTheTop(true);
if(costsToAdd instanceof ManaCosts<?>) {
if (costsToAdd instanceof ManaCosts<?>) {
ManaCosts<ManaCost> manaCosts = (ManaCosts<ManaCost>) costsToAdd;
CardUtil.increaseCost(this, manaCosts);
}
else {
} else {
this.addCost(costsToAdd);
}
}
protected PayMoreToCastAsThoughtItHadFlashAbility(final PayMoreToCastAsThoughtItHadFlashAbility ability) {
super(ability);
this.rule = ability.rule;
this.costsToAdd = ability.costsToAdd;
}
@ -46,8 +52,12 @@ public class PayMoreToCastAsThoughtItHadFlashAbility extends SpellAbility {
public String getRule(boolean all) {
return getRule();
}
@Override
public String getRule() {
if (rule != null && !rule.isEmpty()) {
return rule;
}
if (costsToAdd instanceof ManaCosts) {
return "You may cast {this} as though it had flash if you pay " + costsToAdd.getText() + " more to cast it. <i>(You may cast it any time you could cast an instant.)</i>";
} else {
@ -55,4 +65,4 @@ public class PayMoreToCastAsThoughtItHadFlashAbility extends SpellAbility {
}
}
}
}

View file

@ -8,23 +8,24 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public enum MultiAmountType {
public class MultiAmountType {
MANA("Add mana", "Distribute mana among colors"),
DAMAGE("Assign damage", "Assign damage among targets"),
P1P1("Add +1/+1 counters", "Distribute +1/+1 counters among creatures"),
COUNTERS("Choose counters", "Move counters"),
CHEAT_LANDS("Choose lands", "Add lands to your battlefield", true);
public static final MultiAmountType MANA = new MultiAmountType("Add mana", "Distribute mana among colors");
public static final MultiAmountType DAMAGE = new MultiAmountType("Assign damage", "Assign damage among targets");
public static final MultiAmountType P1P1 = new MultiAmountType("Add +1/+1 counters", "Distribute +1/+1 counters among creatures");
public static final MultiAmountType COUNTERS = new MultiAmountType("Choose counters", "Move counters");
public static final MultiAmountType CHEAT_LANDS = new MultiAmountType("Choose lands", "Add lands to your battlefield", true);
private final String title;
private final String header;
private final boolean canCancel; // choice dialog will return null instead default values
MultiAmountType(String title, String header) {
public MultiAmountType(String title, String header) {
this(title, header, false);
}
MultiAmountType(String title, String header, boolean canCancel) {
public MultiAmountType(String title, String header, boolean canCancel) {
this.title = title;
this.header = header;
this.canCancel = canCancel;
@ -42,7 +43,7 @@ public enum MultiAmountType {
return canCancel;
}
public static List<Integer> prepareDefaltValues(List<MultiAmountMessage> constraints, int min, int max) {
public static List<Integer> prepareDefaultValues(List<MultiAmountMessage> constraints, int min, int max) {
// default values must be assigned from first to last by minimum values
List<Integer> res = constraints.stream().map(m -> m.defaultValue > Integer.MIN_VALUE ? m.defaultValue : Math.min(0, max))
.collect(Collectors.toList());
@ -50,7 +51,7 @@ public enum MultiAmountType {
return res;
}
int total = res.stream().mapToInt(x -> x).sum();;
int total = res.stream().mapToInt(x -> x).sum();
// Fill values until we reach the overall minimum. Do this by filling values up until either their max or however much is leftover, starting with the first option.
if (min > 0 && total < min) {
@ -174,7 +175,7 @@ public enum MultiAmountType {
// data check
if (returnDefaultOnError && !isGoodValues(res, constraints, min, max)) {
// on broken data - return default
return prepareDefaltValues(constraints, min, max);
return prepareDefaultValues(constraints, min, max);
}
return res;

View file

@ -60,7 +60,7 @@ public class Combat implements Serializable, Copyable<Combat> {
protected List<CombatGroup> groups = new ArrayList<>();
protected List<CombatGroup> formerGroups = new ArrayList<>();
protected Map<UUID, CombatGroup> blockingGroups = new HashMap<>();
protected Map<UUID, CombatGroup> blockingGroups = new LinkedHashMap<>();
// all possible defenders (players, planeswalkers or battle)
protected Set<UUID> defenders = new HashSet<>();
// how many creatures attack defending player
@ -200,7 +200,7 @@ public class Combat implements Serializable, Copyable<Combat> {
StringBuilder sb = new StringBuilder();
sb.append(attackingPlayerId).append(defenders);
for (CombatGroup group : groups) {
sb.append(group.defenderId).append(group.attackers).append(group.attackerOrder).append(group.blockers).append(group.blockerOrder);
sb.append(group.defenderId).append(group.attackers).append(group.blockers);
}
return sb.toString();
}
@ -785,7 +785,7 @@ public class Combat implements Serializable, Copyable<Combat> {
if (attackerExists) {
if (!group.getBlockers().isEmpty()) {
sb.append("blocked by ");
for (UUID blockingCreatureId : group.getBlockerOrder()) {
for (UUID blockingCreatureId : group.getBlockers()) {
Permanent blockingCreature = game.getPermanent(blockingCreatureId);
if (blockingCreature != null) {
sb.append(blockingCreature.getLogName()).append(" (");
@ -1799,24 +1799,11 @@ public class Combat implements Serializable, Copyable<Combat> {
return playerDefenders;
}
public void damageAssignmentOrder(Game game) {
for (CombatGroup group : groups) {
group.pickBlockerOrder(attackingPlayerId, game);
}
for (Map.Entry<UUID, CombatGroup> blockingGroup : blockingGroups.entrySet()) {
Permanent blocker = game.getPermanent(blockingGroup.getKey());
if (blocker != null) {
blockingGroup.getValue().pickAttackerOrder(blocker.getControllerId(), game);
}
}
}
@SuppressWarnings("deprecation")
public void removeAttacker(UUID attackerId, Game game) {
for (CombatGroup group : groups) {
if (group.attackers.contains(attackerId)) {
group.attackers.remove(attackerId);
group.attackerOrder.remove(attackerId);
for (Set<UUID> attackingCreatures : numberCreaturesDefenderAttackedBy.values()) {
attackingCreatures.remove(attackerId);
}
@ -1869,7 +1856,6 @@ public class Combat implements Serializable, Copyable<Combat> {
}
for (CombatGroup group : groupsToCheck) {
group.blockers.remove(blockerId);
group.blockerOrder.remove(blockerId);
if (group.blockers.isEmpty()) {
group.blocked = false;
}
@ -1885,11 +1871,9 @@ public class Combat implements Serializable, Copyable<Combat> {
if (blockGroup.blockers.contains(blockerId)) {
for (UUID attackerId : group.getAttackers()) {
blockGroup.attackers.remove(attackerId);
blockGroup.attackerOrder.remove(attackerId);
}
if (creature.getBlocking() == 0) {
blockGroup.blockers.remove(blockerId);
blockGroup.attackerOrder.clear();
}
}
if (blockGroup.blockers.isEmpty()) {
@ -1914,7 +1898,6 @@ public class Combat implements Serializable, Copyable<Combat> {
for (CombatGroup group : groups) {
if (group.blockers.contains(blockerId)) {
group.blockers.remove(blockerId);
group.blockerOrder.remove(blockerId);
if (group.blockers.isEmpty()) {
group.blocked = false;
}
@ -1924,7 +1907,6 @@ public class Combat implements Serializable, Copyable<Combat> {
for (CombatGroup group : getBlockingGroups()) {
if (group.blockers.contains(blockerId)) {
group.blockers.remove(blockerId);
group.attackerOrder.clear();
}
if (group.blockers.isEmpty()) {
canRemove = true;

View file

@ -6,6 +6,7 @@ import mage.abilities.common.ControllerDivideCombatDamageAbility;
import mage.abilities.common.DamageAsThoughNotBlockedAbility;
import mage.abilities.keyword.*;
import mage.constants.AsThoughEffectType;
import mage.constants.MultiAmountType;
import mage.constants.Outcome;
import mage.filter.StaticFilters;
import mage.game.Game;
@ -15,6 +16,7 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.Copyable;
import mage.util.MultiAmountMessage;
import mage.watchers.common.FirstStrikeWatcher;
import java.io.Serializable;
@ -29,8 +31,6 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
protected List<UUID> attackers = new ArrayList<>();
protected List<UUID> formerAttackers = new ArrayList<>();
protected List<UUID> blockers = new ArrayList<>();
protected List<UUID> blockerOrder = new ArrayList<>();
protected List<UUID> attackerOrder = new ArrayList<>();
protected Map<UUID, UUID> players = new HashMap<>();
protected boolean blocked;
protected UUID defenderId; // planeswalker, player, or battle id, can be null after remove from combat (e.g. due damage)
@ -52,8 +52,6 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
this.attackers.addAll(group.attackers);
this.formerAttackers.addAll(group.formerAttackers);
this.blockers.addAll(group.blockers);
this.blockerOrder.addAll(group.blockerOrder);
this.attackerOrder.addAll(group.attackerOrder);
this.players.putAll(group.players);
this.blocked = group.blocked;
this.defenderId = group.defenderId;
@ -91,10 +89,6 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
return blockers;
}
public List<UUID> getBlockerOrder() {
return blockerOrder;
}
private static boolean hasFirstOrDoubleStrike(Permanent perm) {
return hasFirstStrike(perm) || hasDoubleStrike(perm);
}
@ -175,7 +169,6 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
if (attacker != null && !assignsDefendingPlayerAndOrDefendingCreaturesDividedDamage(attacker, attacker.getControllerId(), first, game, true)) {
if (blockers.isEmpty()) {
unblockedDamage(first, game);
return;
} else {
Player player = game.getPlayer(defenderAssignsCombatDamage(game) ? defendingPlayerId : attacker.getControllerId());
if ((attacker.getAbilities().containsKey(DamageAsThoughNotBlockedAbility.getInstance().getId()) &&
@ -186,11 +179,7 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
blocked = false;
unblockedDamage(first, game);
}
if (blockers.size() == 1) {
singleBlockerDamage(player, first, game);
} else {
multiBlockerDamage(player, first, game);
}
blockerDamage(player, first, game);
}
}
}
@ -206,9 +195,7 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
}
}
if (attackers.size() != 1) {
multiAttackerDamage(first, game);
// } else {
// singleAttackerDamage(first, game);
attackerDamage(first, game);
}
}
}
@ -269,51 +256,16 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
}
}
}
private void singleBlockerDamage(Player player, boolean first, Game game) {
Permanent blocker = game.getPermanent(blockers.get(0));
Permanent attacker = game.getPermanent(attackers.get(0));
if (blocker != null && attacker != null) {
int blockerDamage = getDamageValueFromPermanent(blocker, game); // must be set before attacker damage marking because of effects like Test of Faith
if (blocked && dealsDamageThisStep(attacker, first, game)) {
int damage = getDamageValueFromPermanent(attacker, game);
if (hasTrample(attacker)) {
int lethalDamage = getLethalDamage(blocker, attacker, game);
if (lethalDamage >= damage) {
blocker.markDamage(damage, attacker.getId(), null, game, true, true);
} else {
int damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + blocker.getName(), game);
blocker.markDamage(damageAssigned, attacker.getId(), null, game, true, true);
damage -= damageAssigned;
if (damage > 0) {
defenderDamage(attacker, damage, game, false);
}
}
} else {
blocker.markDamage(damage, attacker.getId(), null, game, true, true);
}
}
if (dealsDamageThisStep(blocker, first, game)) {
if (checkSoleBlockerAfter(blocker, game)) { // blocking several creatures handled separately
if (!assignsDefendingPlayerAndOrDefendingCreaturesDividedDamage(blocker, blocker.getControllerId(), first, game, false)) {
attacker.markDamage(blockerDamage, blocker.getId(), null, game, true, true);
}
}
}
}
}
private void multiBlockerDamage(Player player, boolean first, Game game) {
private void blockerDamage(Player player, boolean first, Game game) {
Permanent attacker = game.getPermanent(attackers.get(0));
if (attacker == null) {
return;
}
boolean oldRuleDamage = (Objects.equals(player.getId(), defendingPlayerId));
int damage = getDamageValueFromPermanent(attacker, game);
if (dealsDamageThisStep(attacker, first, game)) {
// must be set before attacker damage marking because of effects like Test of Faith
Map<UUID, Integer> blockerPower = new HashMap<>();
for (UUID blockerId : blockerOrder) {
for (UUID blockerId : blockers) {
Permanent blocker = game.getPermanent(blockerId);
if (dealsDamageThisStep(blocker, first, game)) {
if (checkSoleBlockerAfter(blocker, game)) { // blocking several creatures handled separately
@ -322,42 +274,62 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
}
}
Map<UUID, Integer> assigned = new HashMap<>();
List<MultiAmountMessage> damageDivision = new ArrayList<>();
List<UUID> blockersCopy = new ArrayList<>(blockers);
if (blocked) {
boolean excessDamageToDefender = true;
for (UUID blockerId : new ArrayList<>(blockerOrder)) { // prevent ConcurrentModificationException
int remainingDamage = damage;
for (UUID blockerId : blockers) {
Permanent blocker = game.getPermanent(blockerId);
if (blocker != null) {
int lethalDamage = getLethalDamage(blocker, attacker, game);
if (lethalDamage >= damage) {
if (!oldRuleDamage) {
assigned.put(blockerId, damage);
damage = 0;
break;
} else if (damage == 0) {
break;
}
}
int damageAssigned = 0;
if (!oldRuleDamage) {
damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + blocker.getName(), game);
} else {
damageAssigned = player.getAmount(0, damage, "Assign damage to " + blocker.getName(), game);
if (damageAssigned < lethalDamage) {
excessDamageToDefender = false; // all blockers need to have lethal damage assigned before it can trample over to the defender
}
}
assigned.put(blockerId, damageAssigned);
damage -= damageAssigned;
int defaultDamage = Math.min(remainingDamage, blocker.getLethalDamage(attacker.getId(), game));
remainingDamage -= defaultDamage;
String message = String.format("%s, P/T: %d/%d",
blocker.getLogName(),
blocker.getPower().getValue(),
blocker.getToughness().getValue());
damageDivision.add(new MultiAmountMessage(message, 0, damage, defaultDamage));
}
}
if (damage > 0 && hasTrample(attacker) && excessDamageToDefender) {
defenderDamage(attacker, damage, game, false);
} else if (!blockerOrder.isEmpty()) {
// Assign the damage left to first blocker
assigned.put(blockerOrder.get(0), assigned.get(blockerOrder.get(0)) == null ? 0 : assigned.get(blockerOrder.get(0)) + damage);
List<Integer> amounts;
if (hasTrample(attacker)){
if (remainingDamage > 0 || damageDivision.size() > 1) {
MultiAmountType dialogue = new MultiAmountType("Assign combat damage (with trample)",
String.format("Assign combat damage among creatures blocking %s, P/T: %d/%d (Unassigned damage tramples through)",
attacker.getLogName(), attacker.getPower().getValue(), attacker.getToughness().getValue()));
amounts = player.getMultiAmountWithIndividualConstraints(Outcome.Damage, damageDivision, damage - remainingDamage, damage, dialogue, game);
} else {
amounts = new ArrayList<>();
if (damageDivision.size() == 1) { // Assign all damage to one blocker
amounts.add(damage);
}
}
int trampleDamage = damage - (amounts.stream().mapToInt(x -> x).sum());
if (trampleDamage > 0) {
defenderDamage(attacker, trampleDamage, game, false);
}
} else {
if (remainingDamage > 0){
damageDivision.get(0).defaultValue += remainingDamage;
}
if (damageDivision.size() > 1) {
MultiAmountType dialogue = new MultiAmountType("Assign combat damage",
String.format("Assign combat damage among creatures blocking %s, P/T: %d/%d",
attacker.getLogName(), attacker.getPower().getValue(), attacker.getToughness().getValue()));
amounts = player.getMultiAmountWithIndividualConstraints(Outcome.Damage, damageDivision, damage, damage, dialogue, game);
} else {
amounts = new LinkedList<>();
if (damageDivision.size() == 1) { // Assign all damage to one blocker
amounts.add(damage);
}
}
}
if (!damageDivision.isEmpty()){
for (int i=0; i<blockersCopy.size(); i++) {
assigned.put(blockersCopy.get(i), amounts.get(i));
}
}
}
for (UUID blockerId : blockerOrder) {
for (UUID blockerId : blockers) {
Integer power = blockerPower.get(blockerId);
if (power != null) {
// might be missing canDamage condition?
@ -374,7 +346,7 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
}
}
} else {
for (UUID blockerId : blockerOrder) {
for (UUID blockerId : blockers) {
Permanent blocker = game.getPermanent(blockerId);
if (dealsDamageThisStep(blocker, first, game)) {
if (!assignsDefendingPlayerAndOrDefendingCreaturesDividedDamage(blocker, blocker.getControllerId(), first, game, false)) {
@ -395,7 +367,7 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
if (dealsDamageThisStep(attacker, first, game)) {
// must be set before attacker damage marking because of effects like Test of Faith
Map<UUID, Integer> blockerPower = new HashMap<>();
for (UUID blockerId : blockerOrder) {
for (UUID blockerId : blockers) {
Permanent blocker = game.getPermanent(blockerId);
if (dealsDamageThisStep(blocker, first, game)) {
if (checkSoleBlockerAfter(blocker, game)) { // blocking several creatures handled separately
@ -422,7 +394,7 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
}
}
if (isAttacking) {
for (UUID blockerId : blockerOrder) {
for (UUID blockerId : blockers) {
Integer power = blockerPower.get(blockerId);
if (power != null) {
// might be missing canDamage condition?
@ -439,7 +411,7 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
}
} else {
if (isAttacking) {
for (UUID blockerId : blockerOrder) {
for (UUID blockerId : blockers) {
Permanent blocker = game.getPermanent(blockerId);
if (dealsDamageThisStep(blocker, first, game)) {
if (!assignsDefendingPlayerAndOrDefendingCreaturesDividedDamage(blocker, blocker.getControllerId(), first, game, false)) {
@ -473,81 +445,62 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
/**
* Damages attacking creatures by a creature that blocked several ones
* Damages only attackers as blocker was damage in
* {@link #singleBlockerDamage}.
* {@link #blockerDamage}.
* <p>
* Handles abilities like "{this} an block any number of creatures.".
* <p>
* Blocker damage for blockers blocking single creatures is handled in the
* single/multi blocker methods, so this shouldn't be used anymore.
*
* @param first
* @param game
* @deprecated
*/
@Deprecated
private void singleAttackerDamage(boolean first, Game game) {
Permanent blocker = game.getPermanent(blockers.get(0));
Permanent attacker = game.getPermanent(attackers.get(0));
if (blocker != null && attacker != null) {
if (dealsDamageThisStep(blocker, first, game)) {
int damage = getDamageValueFromPermanent(blocker, game);
attacker.markDamage(damage, blocker.getId(), null, game, true, true);
}
}
}
/**
* Damages attacking creatures by a creature that blocked several ones
* Damages only attackers as blocker was damage in either
* {@link #singleBlockerDamage} or {@link #multiBlockerDamage}.
* <p>
* Handles abilities like "{this} an block any number of creatures.".
* Handles abilities like "{this} can block any number of creatures.".
*
* @param first
* @param game
*/
private void multiAttackerDamage(boolean first, Game game) {
private void attackerDamage(boolean first, Game game) {
Permanent blocker = game.getPermanent(blockers.get(0));
if (blocker == null) {
return;
}
boolean oldRuleDamage = attackerAssignsCombatDamage(game); // handles banding
Player player = game.getPlayer(oldRuleDamage ? game.getCombat().getAttackingPlayerId() : blocker.getControllerId());
//Handle Banding
Player player = game.getPlayer(attackerAssignsCombatDamage(game) ? game.getCombat().getAttackingPlayerId() : blocker.getControllerId());
int damage = getDamageValueFromPermanent(blocker, game);
if (dealsDamageThisStep(blocker, first, game)) {
Map<UUID, Integer> assigned = new HashMap<>();
for (UUID attackerId : attackerOrder) {
List<MultiAmountMessage> damageDivision = new ArrayList<>();
List<UUID> attackersCopy = new ArrayList<>(attackers);
int remainingDamage = damage;
for (UUID attackerId : attackers) {
Permanent attacker = game.getPermanent(attackerId);
if (attacker != null) {
int lethalDamage = getLethalDamage(attacker, blocker, game);
if (lethalDamage >= damage) {
if (!oldRuleDamage) {
assigned.put(attackerId, damage);
damage = 0;
break;
} else if (damage == 0) {
break;
}
}
int damageAssigned = 0;
if (!oldRuleDamage) {
damageAssigned = player.getAmount(lethalDamage, damage, "Assign damage to " + attacker.getName(), game);
} else {
damageAssigned = player.getAmount(0, damage, "Assign damage to " + attacker.getName(), game);
}
assigned.put(attackerId, damageAssigned);
damage -= damageAssigned;
int defaultDamage = Math.min(remainingDamage, attacker.getLethalDamage(blocker.getId(), game));
remainingDamage -= defaultDamage;
String message = String.format("%s, P/T: %d/%d",
attacker.getLogName(),
attacker.getPower().getValue(),
attacker.getToughness().getValue());
damageDivision.add(new MultiAmountMessage(message, 0, damage, defaultDamage));
}
}
if (damage > 0) {
// Assign the damage left to first attacker
assigned.put(attackerOrder.get(0), assigned.get(attackerOrder.get(0)) + damage);
List<Integer> amounts;
if (remainingDamage > 0){
damageDivision.get(0).defaultValue += remainingDamage;
}
if (damageDivision.size() > 1) {
MultiAmountType dialogue = new MultiAmountType("Assign blocker combat damage",
String.format("Assign combat damage among creatures blocked by %s, P/T: %d/%d",
blocker.getLogName(), blocker.getPower().getValue(), blocker.getToughness().getValue()));
amounts = player.getMultiAmountWithIndividualConstraints(Outcome.Damage, damageDivision, damage, damage, dialogue, game);
} else {
amounts = new LinkedList<>();
amounts.add(damage);
}
if (!damageDivision.isEmpty()){
for (int i=0; i<attackersCopy.size(); i++) {
assigned.put(attackersCopy.get(i), amounts.get(i));
}
}
for (Map.Entry<UUID, Integer> entry : assigned.entrySet()) {
Permanent attacker = game.getPermanent(entry.getKey());
attacker.markDamage(entry.getValue(), blocker.getId(), null, game, true, true);
if (attacker != null) {
attacker.markDamage(entry.getValue(), blocker.getId(), null, game, true, true);
}
}
}
}
@ -632,74 +585,11 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
if (blockerId != null && blocker != null) {
blocker.setBlocking(blocker.getBlocking() + 1);
blockers.add(blockerId);
blockerOrder.add(blockerId);
this.blocked = true;
this.players.put(blockerId, playerId);
}
}
public void pickBlockerOrder(UUID playerId, Game game) {
if (blockers.isEmpty()) {
return;
}
Player player = game.getPlayer(playerId); // game.getPlayer(defenderAssignsCombatDamage(game) ? defendingPlayerId : playerId); // this was incorrect because defenderAssignsCombatDamage might be false by the time damage is dealt
List<UUID> blockerList = new ArrayList<>(blockers);
blockerOrder.clear();
while (player.canRespond()) {
if (blockerList.size() == 1) {
blockerOrder.add(blockerList.get(0));
break;
} else {
List<Permanent> blockerPerms = new ArrayList<>();
for (UUID blockerId : blockerList) {
blockerPerms.add(game.getPermanent(blockerId));
}
UUID blockerId = player.chooseBlockerOrder(blockerPerms, this, blockerOrder, game);
blockerOrder.add(blockerId);
blockerList.remove(blockerId);
}
}
if (!game.isSimulation() && blockerOrder.size() > 1) {
logDamageAssignmentOrder("Creatures blocking ", attackers, blockerOrder, game);
}
}
public void pickAttackerOrder(UUID playerId, Game game) {
Player player = game.getPlayer(playerId);
if (attackers.isEmpty() || player == null) {
return;
}
List<UUID> attackerList = new ArrayList<>(attackers);
List<UUID> newAttackerOrder = new ArrayList<>();
while (true) {
if (attackerList.size() == 1) {
newAttackerOrder.add(attackerList.get(0));
break;
} else {
List<Permanent> attackerPerms = new ArrayList<>();
for (UUID attackerId : attackerList) {
attackerPerms.add(game.getPermanent(attackerId));
}
UUID attackerId = player.chooseAttackerOrder(attackerPerms, game);
if (attackerId == null) {
break;
}
newAttackerOrder.add(attackerId);
attackerList.remove(attackerId);
}
}
if (attackerOrder.isEmpty() || newAttackerOrder.size() == attackerOrder.size()) {
attackerOrder.clear();
attackerOrder.addAll(newAttackerOrder);
if (!game.isSimulation() && attackerOrder.size() > 1) {
logDamageAssignmentOrder("Creatures blocked by ", blockers, attackerOrder, game);
}
} else {
game.informPlayers(player.getLogName() + " try to skip choose attacker order");
}
}
private void logDamageAssignmentOrder(String prefix, List<UUID> assignedFor, List<UUID> assignedOrder, Game game) {
StringBuilder sb = new StringBuilder(prefix);
boolean first = true;
@ -746,12 +636,9 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
formerAttackers.add(creatureId);
attackers.remove(creatureId);
result = true;
attackerOrder.remove(creatureId);
} else if (blockers.contains(creatureId)) {
blockers.remove(creatureId);
result = true;
//20100423 - 509.2a
blockerOrder.remove(creatureId);
}
return result;
}
@ -825,7 +712,6 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
game.getCombat().removeBlocker(blockerId, game);
}
blockers.clear();
blockerOrder.clear();
if (!game.isSimulation()) {
game.informPlayers(attacker.getLogName() + " can't be blocked except by " + attacker.getMinBlockedBy() + " or more creatures. Blockers discarded.");
}
@ -844,7 +730,6 @@ public class CombatGroup implements Serializable, Copyable<CombatGroup> {
game.getCombat().removeBlocker(blockerId, game);
}
blockers.clear();
blockerOrder.clear();
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(attacker.getLogName())
.append(" can't be blocked by more than ").append(attacker.getMaxBlockedBy())

View file

@ -1,12 +1,12 @@
package mage.game.turn;
import java.util.UUID;
import mage.constants.PhaseStep;
import mage.game.Game;
import mage.game.events.GameEvent.EventType;
import java.util.UUID;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -37,7 +37,6 @@ public class DeclareBlockersStep extends Step {
game.getCombat().selectBlockers(game);
if (!game.isPaused() && !game.executingRollback()) {
game.getCombat().acceptBlockers(game);
game.getCombat().damageAssignmentOrder(game);
}
}
@ -46,7 +45,6 @@ public class DeclareBlockersStep extends Step {
super.resumeBeginStep(game, activePlayerId);
game.getCombat().resumeSelectBlockers(game);
game.getCombat().acceptBlockers(game);
game.getCombat().damageAssignmentOrder(game);
}
@Override

View file

@ -23,7 +23,6 @@ import mage.filter.FilterCard;
import mage.filter.FilterMana;
import mage.filter.FilterPermanent;
import mage.game.*;
import mage.game.combat.CombatGroup;
import mage.game.draft.Draft;
import mage.game.events.GameEvent;
import mage.game.match.Match;
@ -761,19 +760,6 @@ public interface Player extends MageItem, Copyable<Player> {
void selectBlockers(Ability source, Game game, UUID defendingPlayerId);
UUID chooseAttackerOrder(List<Permanent> attacker, Game game);
/**
* Choose the order in which blockers get damage assigned to
*
* @param blockers list of blockers where to choose the next one from
* @param combatGroup the concerning combat group
* @param blockerOrder the already set order of blockers
* @param game
* @return blocker next to add to the blocker order
*/
UUID chooseBlockerOrder(List<Permanent> blockers, CombatGroup combatGroup, List<UUID> blockerOrder, Game game);
int getAmount(int min, int max, String message, Game game);
/**

View file

@ -18,10 +18,8 @@ import mage.constants.Outcome;
import mage.constants.RangeOfInfluence;
import mage.filter.FilterMana;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.draft.Draft;
import mage.game.match.Match;
import mage.game.permanent.Permanent;
import mage.game.tournament.Tournament;
import mage.target.Target;
import mage.target.TargetAmount;
@ -190,16 +188,6 @@ public class StubPlayer extends PlayerImpl {
}
@Override
public UUID chooseAttackerOrder(List<Permanent> attacker, Game game) {
return null;
}
@Override
public UUID chooseBlockerOrder(List<Permanent> blockers, CombatGroup combatGroup, List<UUID> blockerOrder, Game game) {
return null;
}
@Override
public int getAmount(int min, int max, String message, Game game) {
return 0;