Skip to content

Commit

Permalink
"this combat" bug (#4547)
Browse files Browse the repository at this point in the history
* fixed bug in cards using 'this combat'

* handle tracking when creature removed from combat early
  • Loading branch information
hungriestPigeon authored Jan 19, 2024
1 parent cf2c2cc commit 9cbecf2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,8 @@ public void newTurn() {

public void endCombat() {
damagedThisCombat.clear();
setCreatureAttackedThisCombat(null, -1);
setCreatureBlockedThisCombat(false);
setCreatureGotBlockedThisCombat(false);
}
}
10 changes: 8 additions & 2 deletions forge-game/src/main/java/forge/game/combat/Combat.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import forge.game.spellability.SpellAbilityStackInstance;
import forge.game.staticability.StaticAbilityAssignCombatDamageAsUnblocked;
import forge.game.trigger.TriggerType;
import forge.game.zone.ZoneType;
import forge.util.CardTranslation;
import forge.util.Localizer;
import forge.util.collect.FCollection;
Expand Down Expand Up @@ -154,13 +155,18 @@ public void endCombat() {
lkiCache.clear();
combatantsThatDealtFirstStrikeDamage.clear();

//clear tracking for cards that care about "this combat"
Game game = playerWhoAttacks.getGame();
for (Card c : game.getCardsIncludePhasingIn(ZoneType.Battlefield)) {
c.getDamageHistory().endCombat();
}
playerWhoAttacks.clearAttackedPlayersMyCombat();

//update view for all attackers and blockers
for (Card c : attackers) {
c.getDamageHistory().endCombat();
c.updateAttackingForView();
}
for (Card c : blockers) {
c.getDamageHistory().endCombat();
c.updateBlockingForView();
}
}
Expand Down
4 changes: 0 additions & 4 deletions forge-game/src/main/java/forge/game/phase/PhaseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ private void declareAttackersTurnBasedAction() {
game.getTriggerHandler().runTrigger(TriggerType.AttackersDeclared, runParams, false);
}

playerTurn.clearAttackedPlayersMyCombat();
for (final Card c : combat.getAttackers()) {
CombatUtil.checkDeclaredAttacker(game, c, combat, true);
}
Expand Down Expand Up @@ -1275,9 +1274,6 @@ public final void setPlayerDeclaresBlockers(Player player) {
}

public void endCombat() {
for (Player player : game.getPlayers()) {
player.resetCombatantsThisCombat();
}
game.getEndOfCombat().executeUntil();
game.getEndOfCombat().executeUntilEndOfPhase(playerTurn);
if (inCombat()) {
Expand Down
17 changes: 0 additions & 17 deletions forge-game/src/main/java/forge/game/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -2741,23 +2741,6 @@ public void initPlane() {
view.updateCurrentPlaneName(currentPlanes.toString().replaceAll(" \\(.*","").replace("[",""));
}

public final void resetCombatantsThisCombat() {
// resets the status of attacked/blocked this phase
CardCollectionView list = getCardsIn(ZoneType.Battlefield, false);

for (Card c : list) {
if (c.getDamageHistory().getCreatureAttackedThisCombat() > 0) {
c.getDamageHistory().setCreatureAttackedThisCombat(null, -1);
}
if (c.getDamageHistory().getCreatureBlockedThisCombat()) {
c.getDamageHistory().setCreatureBlockedThisCombat(false);
}
if (c.getDamageHistory().getCreatureGotBlockedThisCombat()) {
c.getDamageHistory().setCreatureGotBlockedThisCombat(false);
}
}
}

public CardCollectionView getInboundTokens() {
return inboundTokens;
}
Expand Down

0 comments on commit 9cbecf2

Please sign in to comment.