refactor: deduplicate combat damage steps (#11566)

This commit is contained in:
xenohedron 2023-12-21 22:44:01 -05:00 committed by GitHub
parent 0862461d6b
commit eec5c5b2e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 95 deletions

View file

@ -1,4 +1,3 @@
package mage.game.turn;
import java.util.UUID;
@ -14,15 +13,22 @@ import mage.game.events.GameEvent.EventType;
*/
public class CombatDamageStep extends Step {
public CombatDamageStep() {
super(PhaseStep.COMBAT_DAMAGE, true);
private final boolean first;
/**
* @param first if true, then it is the FirstCombatDamageStep
*/
public CombatDamageStep(boolean first) {
super(first ? PhaseStep.FIRST_COMBAT_DAMAGE : PhaseStep.COMBAT_DAMAGE, true);
this.stepEvent = EventType.COMBAT_DAMAGE_STEP;
this.preStepEvent = EventType.COMBAT_DAMAGE_STEP_PRE;
this.postStepEvent = EventType.COMBAT_DAMAGE_STEP_POST;
this.first = first;
}
protected CombatDamageStep(final CombatDamageStep step) {
super(step);
this.first = step.first;
}
@Override
@ -33,9 +39,14 @@ public class CombatDamageStep extends Step {
@Override
public boolean skipStep(Game game, UUID activePlayerId) {
// 508.8
if (game.getCombat().noAttackers()) {
return true;
}
// 510.4
if (first && !game.getCombat().hasFirstOrDoubleStrike(game)) {
return true;
}
return super.skipStep(game, activePlayerId);
}
@ -43,16 +54,14 @@ public class CombatDamageStep extends Step {
public void beginStep(Game game, UUID activePlayerId) {
super.beginStep(game, activePlayerId);
for (CombatGroup group : game.getCombat().getGroups()) {
group.assignDamageToBlockers(false, game);
group.assignDamageToBlockers(first, game);
}
for (CombatGroup group : game.getCombat().getBlockingGroups()) {
group.assignDamageToAttackers(false, game);
group.assignDamageToAttackers(first, game);
}
for (CombatGroup group : game.getCombat().getGroups()) {
group.applyDamage(game);
}
for (CombatGroup group : game.getCombat().getBlockingGroups()) {
group.applyDamage(game);
}
@ -60,10 +69,6 @@ public class CombatDamageStep extends Step {
game.getState().handleSimultaneousEvent(game);
}
public boolean getFirst() {
return false;
}
@Override
public CombatDamageStep copy() {
return new CombatDamageStep(this);