Skip to content

Commit 0a15a03

Browse files
tool4evertool4EvErtool4EvEr
authored
Fix battles attacking/blocking (#7075)
* Add battle SBA --------- Co-authored-by: tool4EvEr <tool4EvEr@192.168.0.59> Co-authored-by: tool4EvEr <tool4EvEr@192.168.0.60>
1 parent 0e46d43 commit 0a15a03

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

forge-game/src/main/java/forge/game/GameAction.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,11 +1659,23 @@ private boolean stateBasedAction_Saga(Card c, CardCollection sacrificeList) {
16591659

16601660
private boolean stateBasedAction_Battle(Card c, CardCollection removeList) {
16611661
boolean checkAgain = false;
1662-
if (!c.getType().isBattle()) {
1663-
return false;
1662+
if (!c.isBattle()) {
1663+
return checkAgain;
1664+
}
1665+
if (((c.getProtectingPlayer() == null || !c.getProtectingPlayer().isInGame()) &&
1666+
(game.getCombat() == null || game.getCombat().getAttackersOf(c).isEmpty())) ||
1667+
(c.getType().hasStringType("Siege") && c.getController().equals(c.getProtectingPlayer()))) {
1668+
Player newProtector = c.getController().getController().chooseSingleEntityForEffect(c.getController().getOpponents(), null, "Choose an opponent to protect this battle", null);
1669+
// seems unlikely unless range of influence gets implemented
1670+
if (newProtector == null) {
1671+
removeList.add(c);
1672+
} else {
1673+
c.setProtectingPlayer(newProtector);
1674+
}
1675+
checkAgain = true;
16641676
}
16651677
if (c.getCounters(CounterEnumType.DEFENSE) > 0) {
1666-
return false;
1678+
return checkAgain;
16671679
}
16681680
// 704.5v If a battle has defense 0 and it isn't the source of an ability that has triggered but not yet left the stack,
16691681
// it’s put into its owner’s graveyard.

forge-game/src/main/java/forge/game/card/CardFactoryUtil.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,14 +519,6 @@ public static List<String> getSharedKeywords(final Iterable<String> kw, final Ca
519519
return filteredkw;
520520
}
521521

522-
public static int getCardTypesFromList(final CardCollectionView list) {
523-
EnumSet<CardType.CoreType> types = EnumSet.noneOf(CardType.CoreType.class);
524-
for (Card c1 : list) {
525-
c1.getType().getCoreTypes().forEach(types::add);
526-
}
527-
return types.size();
528-
}
529-
530522
/**
531523
* Adds the ability factory abilities.
532524
*

forge-game/src/main/java/forge/game/combat/CombatUtil.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ public static boolean canAttackNextTurn(final Card attacker, final GameEntity de
201201
private static boolean canAttack(final Card attacker, final GameEntity defender, final boolean forNextTurn) {
202202
final Game game = attacker.getGame();
203203

204+
if (attacker.isBattle()) {
205+
return false;
206+
}
207+
204208
// Basic checks (unless is for next turn)
205209
if (!forNextTurn && (
206210
!attacker.isCreature()
@@ -480,6 +484,10 @@ public static boolean canBlock(final Card blocker, final boolean nextTurn) {
480484
return false;
481485
}
482486

487+
if (blocker.isBattle()) {
488+
return false;
489+
}
490+
483491
if (!nextTurn && blocker.isTapped() && !blocker.hasKeyword("CARDNAME can block as though it were untapped.")) {
484492
return false;
485493
}

forge-game/src/main/java/forge/game/cost/CostExile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ else if (type.contains("FromTopGrave")) {
222222
int amount = this.getAbilityAmount(ability);
223223

224224
if (nTypes > -1) {
225-
if (CardFactoryUtil.getCardTypesFromList(list) < nTypes) return false;
225+
if (AbilityUtils.countCardTypesFromList(list, false) < nTypes) return false;
226226
}
227227

228228
if (sharedType) { // will need more logic if cost ever wants more than 2 that share a type

forge-game/src/main/java/forge/game/player/Player.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import forge.game.*;
2727
import forge.game.ability.AbilityFactory;
2828
import forge.game.ability.AbilityKey;
29+
import forge.game.ability.AbilityUtils;
2930
import forge.game.ability.ApiType;
3031
import forge.game.ability.effects.DetachedCardEffect;
3132
import forge.game.ability.effects.RollDiceEffect;
@@ -2176,7 +2177,7 @@ public final void setDescended(final int n) {
21762177
}
21772178

21782179
public final boolean hasDelirium() {
2179-
return CardFactoryUtil.getCardTypesFromList(getCardsIn(ZoneType.Graveyard)) >= 4;
2180+
return AbilityUtils.countCardTypesFromList(getCardsIn(ZoneType.Graveyard), false) >= 4;
21802181
}
21812182

21822183
public final boolean hasLandfall() {

forge-gui/src/main/java/forge/player/HumanCostDecision.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public PaymentDecision visit(final CostExile cost) {
303303
inp.setCancelAllowed(true);
304304
inp.showAndWait();
305305
if (inp.hasCancelled() ||
306-
!Expressions.compare(CardFactoryUtil.getCardTypesFromList(list), "GE", nTypes)) {
306+
!Expressions.compare(AbilityUtils.countCardTypesFromList(list, false), "GE", nTypes)) {
307307
return null;
308308
}
309309
return PaymentDecision.card(inp.getSelected());

0 commit comments

Comments
 (0)