consolidate batch event constructor (related to 7c3bbed8)

This commit is contained in:
xenohedron 2024-05-02 01:28:06 -04:00
parent f482eef06a
commit 30d498b80f
9 changed files with 13 additions and 19 deletions

View file

@ -19,16 +19,6 @@ public abstract class BatchEvent<T extends GameEvent> extends GameEvent {
private final boolean singleSourceId;
private final boolean singlePlayerId;
/**
* @param eventType specific type of event
* @param singleSourceId if true, all included events must have same source id
* @param singleTargetId if true, all included events must have same target id
* @param firstEvent added to initialize the batch (batch is never empty)
*/
protected BatchEvent(EventType eventType, boolean singleTargetId, boolean singleSourceId, T firstEvent) {
this(eventType, singleTargetId, singleSourceId, false, firstEvent);
}
/**
* @param eventType specific type of event
* @param singleSourceId if true, all included events must have same source id
@ -67,7 +57,10 @@ public abstract class BatchEvent<T extends GameEvent> extends GameEvent {
throw new IllegalStateException("Wrong code usage. Batch event initiated with single target id, but trying to add event with different target id");
}
if (singleSourceId && !getSourceId().equals(event.getSourceId())) {
throw new IllegalStateException("Wrong code usage. Batch event initiated with single source id, but trying to add event with different target id");
throw new IllegalStateException("Wrong code usage. Batch event initiated with single source id, but trying to add event with different source id");
}
if (singlePlayerId && !getPlayerId().equals(event.getPlayerId())) {
throw new IllegalStateException("Wrong code usage. Batch event initiated with single player id, but trying to add event with different player id");
}
this.events.add(event);
}

View file

@ -6,6 +6,6 @@ package mage.game.events;
public class DamagedBatchAllEvent extends BatchEvent<DamagedEvent> {
public DamagedBatchAllEvent(DamagedEvent firstEvent) {
super(EventType.DAMAGED_BATCH_FOR_ALL, false, false, firstEvent);
super(EventType.DAMAGED_BATCH_FOR_ALL, false, false, false, firstEvent);
}
}

View file

@ -3,7 +3,7 @@ package mage.game.events;
public class DamagedBatchForOnePermanentEvent extends BatchEvent<DamagedPermanentEvent> {
public DamagedBatchForOnePermanentEvent(DamagedPermanentEvent firstEvent) {
super(GameEvent.EventType.DAMAGED_BATCH_FOR_ONE_PERMANENT, true, false, firstEvent);
super(GameEvent.EventType.DAMAGED_BATCH_FOR_ONE_PERMANENT, true, false, false, firstEvent);
}
public boolean isCombatDamage() {

View file

@ -6,7 +6,8 @@ package mage.game.events;
public class DamagedBatchForOnePlayerEvent extends BatchEvent<DamagedPlayerEvent> {
public DamagedBatchForOnePlayerEvent(DamagedPlayerEvent firstEvent) {
super(EventType.DAMAGED_BATCH_FOR_ONE_PLAYER, true, false, firstEvent);
super(EventType.DAMAGED_BATCH_FOR_ONE_PLAYER, true, false, false, firstEvent);
// TODO: rework to support singlePlayerId = true
}
public boolean isCombatDamage() {

View file

@ -6,6 +6,6 @@ package mage.game.events;
public class DamagedBatchForPermanentsEvent extends BatchEvent<DamagedPermanentEvent> {
public DamagedBatchForPermanentsEvent(DamagedPermanentEvent firstEvent) {
super(EventType.DAMAGED_BATCH_FOR_PERMANENTS, false, false, firstEvent);
super(EventType.DAMAGED_BATCH_FOR_PERMANENTS, false, false, false, firstEvent);
}
}

View file

@ -6,6 +6,6 @@ package mage.game.events;
public class DamagedBatchForPlayersEvent extends BatchEvent<DamagedPlayerEvent> {
public DamagedBatchForPlayersEvent(DamagedPlayerEvent firstEvent) {
super(GameEvent.EventType.DAMAGED_BATCH_FOR_PLAYERS, false, false, firstEvent);
super(GameEvent.EventType.DAMAGED_BATCH_FOR_PLAYERS, false, false, false, firstEvent);
}
}

View file

@ -8,7 +8,7 @@ import java.util.UUID;
public class LifeLostBatchEvent extends BatchEvent<LifeLostEvent> {
public LifeLostBatchEvent(LifeLostEvent firstEvent) {
super(EventType.LOST_LIFE_BATCH, false, false, firstEvent);
super(EventType.LOST_LIFE_BATCH, false, false, false, firstEvent);
}
public int getLifeLostByPlayer(UUID playerID) {

View file

@ -6,7 +6,7 @@ package mage.game.events;
public class TappedBatchEvent extends BatchEvent<TappedEvent> {
public TappedBatchEvent(TappedEvent firstEvent) {
super(EventType.TAPPED_BATCH, false, false, firstEvent);
super(EventType.TAPPED_BATCH, false, false, false, firstEvent);
}
}

View file

@ -6,7 +6,7 @@ package mage.game.events;
public class UntappedBatchEvent extends BatchEvent<UntappedEvent> {
public UntappedBatchEvent(UntappedEvent firstEvent) {
super(EventType.UNTAPPED_BATCH, false, false, firstEvent);
super(EventType.UNTAPPED_BATCH, false, false, false, firstEvent);
}
}