forked from External/mage
revert the GameEvent::setSourceId removal
xenodron mentionned that one of the use of setSourceId is to more easily find the Event that use non-standard sourceId. So reverting the change made in a previous commit. It was a non-functional change meant to ease new BatchEvent sharing sourceId, but I'll use setSourceId instead there.
This commit is contained in:
parent
00556c4cf6
commit
95adcf0e9a
26 changed files with 88 additions and 63 deletions
|
|
@ -10,7 +10,9 @@ import java.util.UUID;
|
|||
*/
|
||||
public class AttachEvent extends GameEvent {
|
||||
|
||||
// TODO: investigate why source is provided but not used at all?
|
||||
public AttachEvent(UUID targetPermanentId, Permanent attachment, Ability source) {
|
||||
super(GameEvent.EventType.ATTACH, targetPermanentId, attachment.getId(), attachment.getControllerId());
|
||||
super(GameEvent.EventType.ATTACH, targetPermanentId, null, attachment.getControllerId());
|
||||
this.setSourceId(attachment.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public class AttachedEvent extends GameEvent {
|
|||
|
||||
// TODO: investigate why source is provided but not used at all?
|
||||
public AttachedEvent(UUID targetPermanentId, Permanent attachment, Ability source) {
|
||||
super(GameEvent.EventType.ATTACHED, targetPermanentId, attachment.getId(), attachment.getControllerId());
|
||||
super(GameEvent.EventType.ATTACHED, targetPermanentId, null, attachment.getControllerId());
|
||||
this.setSourceId(attachment.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
|||
public class AttackerDeclaredEvent extends GameEvent {
|
||||
|
||||
public AttackerDeclaredEvent(UUID targetId, UUID attackerId, UUID attackerControllerId) {
|
||||
super(GameEvent.EventType.ATTACKER_DECLARED, targetId, attackerId, attackerControllerId);
|
||||
super(GameEvent.EventType.ATTACKER_DECLARED, targetId, null, attackerControllerId);
|
||||
this.setSourceId(attackerId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,10 @@ public abstract class BatchEvent<T extends GameEvent> extends GameEvent {
|
|||
* @param firstEvent added to initialize the batch (batch is never empty)
|
||||
*/
|
||||
protected BatchEvent(EventType eventType, boolean singleTargetId, boolean singleSourceId, T firstEvent) {
|
||||
super(eventType, (singleTargetId ? firstEvent.getTargetId() : null), (singleSourceId ? firstEvent.getSourceId() : null), null);
|
||||
super(eventType, (singleTargetId ? firstEvent.getTargetId() : null), null, null);
|
||||
this.singleTargetId = singleTargetId;
|
||||
this.singleSourceId = singleSourceId;
|
||||
this.setSourceId(singleSourceId ? firstEvent.getSourceId() : null);
|
||||
if (firstEvent instanceof BatchEvent) { // sanity check, if you need it then think twice and research carefully
|
||||
throw new UnsupportedOperationException("Wrong code usage: nesting batch events not supported");
|
||||
}
|
||||
|
|
@ -38,7 +39,7 @@ public abstract class BatchEvent<T extends GameEvent> extends GameEvent {
|
|||
* For alternate event structure logic used by ZoneChangeBatchEvent, list of events starts empty.
|
||||
*/
|
||||
protected BatchEvent(EventType eventType) {
|
||||
super(eventType, null, (UUID) null, null);
|
||||
super(eventType, null, null, null);
|
||||
this.singleTargetId = false;
|
||||
this.singleSourceId = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
|||
public class BlockerDeclaredEvent extends GameEvent {
|
||||
|
||||
public BlockerDeclaredEvent(UUID attackerId, UUID blockerId, UUID blockerControllerId) {
|
||||
super(GameEvent.EventType.BLOCKER_DECLARED, attackerId, blockerId, blockerControllerId);
|
||||
super(GameEvent.EventType.BLOCKER_DECLARED, attackerId, null, blockerControllerId);
|
||||
this.setSourceId(blockerId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@ public class CoinFlippedEvent extends GameEvent {
|
|||
private final int flipCount; // Number of flips that lead to this event. see [[Krark's Thumb]]
|
||||
|
||||
CoinFlippedEvent(UUID playerId, UUID sourceId, int flipCount, boolean result, boolean chosen, boolean winnable) {
|
||||
super(GameEvent.EventType.COIN_FLIPPED, playerId, sourceId, playerId);
|
||||
super(GameEvent.EventType.COIN_FLIPPED, playerId, null, playerId);
|
||||
this.result = result;
|
||||
this.chosen = chosen;
|
||||
this.winnable = winnable;
|
||||
this.flipCount = flipCount;
|
||||
this.setSourceId(sourceId);
|
||||
}
|
||||
|
||||
public boolean getResult() {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import java.util.UUID;
|
|||
public class CopiedStackObjectEvent extends GameEvent {
|
||||
|
||||
public CopiedStackObjectEvent(MageObject target, MageObject newCopy, UUID newControllerId) {
|
||||
super(GameEvent.EventType.COPIED_STACKOBJECT, newCopy.getId(), target.getId(), newControllerId);
|
||||
super(GameEvent.EventType.COPIED_STACKOBJECT, newCopy.getId(), null, newControllerId);
|
||||
this.setSourceId(target.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,9 @@ public abstract class DamageEvent extends GameEvent {
|
|||
private boolean asThoughWither = false;
|
||||
|
||||
public DamageEvent(EventType type, UUID targetId, UUID damageSourceId, UUID targetControllerId, int amount, boolean preventable, boolean combat) {
|
||||
super(type, targetId, damageSourceId, targetControllerId, amount, preventable);
|
||||
super(type, targetId, null, targetControllerId, amount, preventable);
|
||||
this.combat = combat;
|
||||
this.setSourceId(damageSourceId);
|
||||
}
|
||||
|
||||
public boolean isCombatDamage() {
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ public abstract class DamagedEvent extends GameEvent {
|
|||
protected int excess;
|
||||
|
||||
public DamagedEvent(EventType type, UUID targetId, UUID attackerId, UUID playerId, int amount, boolean combat) {
|
||||
super(type, targetId, attackerId, playerId, amount, false);
|
||||
super(type, targetId, null, playerId, amount, false);
|
||||
this.combat = combat;
|
||||
this.excess = 0;
|
||||
this.setSourceId(attackerId);
|
||||
}
|
||||
|
||||
public boolean isCombatDamage() {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
|||
public class DeclareAttackerEvent extends GameEvent {
|
||||
|
||||
public DeclareAttackerEvent(UUID targetId, UUID attackerId, UUID attackerControllerId) {
|
||||
super(GameEvent.EventType.DECLARE_ATTACKER, targetId, attackerId, attackerControllerId);
|
||||
super(GameEvent.EventType.DECLARE_ATTACKER, targetId, null, attackerControllerId);
|
||||
this.setSourceId(attackerId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.util.UUID;
|
|||
public class DeclareBlockerEvent extends GameEvent {
|
||||
|
||||
public DeclareBlockerEvent(UUID attackerId, UUID blockerId, UUID blockerControllerId) {
|
||||
super(GameEvent.EventType.DECLARE_BLOCKER, attackerId, blockerId, blockerControllerId);
|
||||
super(GameEvent.EventType.DECLARE_BLOCKER, attackerId, null, blockerControllerId);
|
||||
this.setSourceId(blockerId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ import java.util.UUID;
|
|||
public class DrawCardEvent extends GameEvent {
|
||||
|
||||
public DrawCardEvent(UUID playerId, Ability source, GameEvent originalDrawEvent) {
|
||||
super(GameEvent.EventType.DRAW_CARD, playerId,
|
||||
// source of draw events must be kept between replacements, example: UnpredictableCycloneTest
|
||||
originalDrawEvent == null
|
||||
? source == null ? null : source.getSourceId()
|
||||
: originalDrawEvent.getSourceId(),
|
||||
playerId, 0, false);
|
||||
super(GameEvent.EventType.DRAW_CARD, playerId, null, playerId, 0, false);
|
||||
|
||||
// source of draw events must be kept between replacements, example: UnpredictableCycloneTest
|
||||
this.setSourceId(originalDrawEvent == null
|
||||
? source == null ? null : source.getSourceId()
|
||||
: originalDrawEvent.getSourceId());
|
||||
|
||||
// source of draw events must be kept between replacements, example: UnpredictableCycloneTest
|
||||
if (originalDrawEvent != null) {
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ import java.util.UUID;
|
|||
public class DrawCardsEvent extends GameEvent {
|
||||
|
||||
public DrawCardsEvent(UUID playerId, Ability source, GameEvent originalDrawEvent, int amount) {
|
||||
super(GameEvent.EventType.DRAW_CARDS, playerId,
|
||||
// source of draw events must be kept between replacements, example: UnpredictableCycloneTest
|
||||
originalDrawEvent == null
|
||||
? source == null ? null : source.getSourceId()
|
||||
: originalDrawEvent.getSourceId(),
|
||||
playerId, amount, false);
|
||||
super(GameEvent.EventType.DRAW_CARDS, playerId, null, playerId, amount, false);
|
||||
|
||||
// source of draw events must be kept between replacements, example: UnpredictableCycloneTest
|
||||
this.setSourceId(originalDrawEvent == null
|
||||
? source == null ? null : source.getSourceId()
|
||||
: originalDrawEvent.getSourceId());
|
||||
|
||||
// source of draw events must be kept between replacements, example: UnpredictableCycloneTest
|
||||
if (originalDrawEvent != null) {
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ import java.util.UUID;
|
|||
public class DrewCardEvent extends GameEvent {
|
||||
|
||||
public DrewCardEvent(UUID cardId, UUID playerId, Ability source, GameEvent originalDrawEvent) {
|
||||
super(EventType.DREW_CARD, cardId,
|
||||
// source of draw events must be kept between replacements, example: UnpredictableCycloneTest
|
||||
originalDrawEvent == null
|
||||
? source == null ? null : source.getSourceId()
|
||||
: originalDrawEvent.getSourceId(),
|
||||
playerId, 0, false);
|
||||
super(EventType.DREW_CARD, cardId, null, playerId, 0, false);
|
||||
|
||||
// source of draw events must be kept between replacements, example: UnpredictableCycloneTest
|
||||
this.setSourceId(originalDrawEvent == null
|
||||
? source == null ? null : source.getSourceId()
|
||||
: originalDrawEvent.getSourceId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public class EnchantPlayerEvent extends GameEvent {
|
|||
|
||||
// TODO: investigate why source is provided but not used at all?
|
||||
public EnchantPlayerEvent(UUID targetId, Permanent attachment, Ability source) {
|
||||
super(GameEvent.EventType.ENCHANT_PLAYER, targetId, attachment.getId(), attachment.getControllerId());
|
||||
super(GameEvent.EventType.ENCHANT_PLAYER, targetId, null, attachment.getControllerId());
|
||||
this.setSourceId(attachment.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public class EnchantedPlayerEvent extends GameEvent {
|
|||
|
||||
// TODO: investigate why source is provided but not used at all?
|
||||
public EnchantedPlayerEvent(UUID targetId, Permanent attachment, Ability source) {
|
||||
super(GameEvent.EventType.ENCHANTED_PLAYER, targetId, attachment.getId(), attachment.getControllerId());
|
||||
super(GameEvent.EventType.ENCHANTED_PLAYER, targetId, null, attachment.getControllerId());
|
||||
this.setSourceId(attachment.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -641,31 +641,23 @@ public class GameEvent implements Serializable {
|
|||
}
|
||||
|
||||
public GameEvent(EventType type, UUID targetId, Ability source, UUID playerId) {
|
||||
this(type, null, targetId, source == null ? null : source.getSourceId(), playerId, 0, false);
|
||||
}
|
||||
|
||||
protected GameEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId) {
|
||||
this(type, null, targetId, sourceId, playerId, 0, false);
|
||||
this(type, null, targetId, source, playerId, 0, false);
|
||||
}
|
||||
|
||||
public GameEvent(EventType type, UUID targetId, Ability source, UUID playerId, ApprovingObject approvingObject) {
|
||||
this(type, null, targetId, source == null ? null : source.getSourceId(), playerId, 0, false, approvingObject);
|
||||
this(type, null, targetId, source, playerId, 0, false, approvingObject);
|
||||
}
|
||||
|
||||
public GameEvent(EventType type, UUID targetId, Ability source, UUID playerId, int amount, boolean flag) {
|
||||
this(type, null, targetId, source == null ? null : source.getSourceId(), playerId, amount, flag);
|
||||
}
|
||||
|
||||
public GameEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag) {
|
||||
this(type, null, targetId, sourceId, playerId, amount, flag);
|
||||
this(type, null, targetId, source, playerId, amount, flag);
|
||||
}
|
||||
|
||||
public GameEvent(UUID customEventType, UUID targetId, Ability source, UUID playerId) {
|
||||
this(EventType.CUSTOM_EVENT, customEventType, targetId, source == null ? null : source.getSourceId(), playerId, 0, false);
|
||||
this(EventType.CUSTOM_EVENT, customEventType, targetId, source, playerId, 0, false);
|
||||
}
|
||||
|
||||
public GameEvent(UUID customEventType, UUID targetId, Ability source, UUID playerId, int amount, boolean flag) {
|
||||
this(EventType.CUSTOM_EVENT, customEventType, targetId, source == null ? null : source.getSourceId(), playerId, amount, flag);
|
||||
this(EventType.CUSTOM_EVENT, customEventType, targetId, source, playerId, amount, flag);
|
||||
}
|
||||
|
||||
public static GameEvent getEvent(EventType type, UUID targetId, Ability source, UUID playerId, int amount) {
|
||||
|
|
@ -682,7 +674,7 @@ public class GameEvent implements Serializable {
|
|||
|
||||
@Deprecated // usage must be replaced by getEvent with source ability
|
||||
public static GameEvent getEvent(EventType type, UUID targetId, UUID playerId) {
|
||||
return new GameEvent(type, targetId, (UUID) null, playerId);
|
||||
return new GameEvent(type, targetId, null, playerId);
|
||||
}
|
||||
|
||||
public static GameEvent getEvent(EventType type, UUID targetId, Ability source, UUID playerId, String data, int amount) {
|
||||
|
|
@ -700,21 +692,18 @@ public class GameEvent implements Serializable {
|
|||
return new GameEvent(customEventType, targetId, source, playerId);
|
||||
}
|
||||
|
||||
private GameEvent(EventType type, UUID customEventType,
|
||||
UUID targetId, UUID sourceId, UUID playerId,
|
||||
int amount, boolean flag
|
||||
) {
|
||||
this(type, customEventType, targetId, sourceId, playerId, amount, flag, null);
|
||||
private GameEvent(EventType type, UUID customEventType, UUID targetId, Ability source, UUID playerId, int amount, boolean flag) {
|
||||
this(type, customEventType, targetId, source, playerId, amount, flag, null);
|
||||
}
|
||||
|
||||
private GameEvent(EventType type, UUID customEventType,
|
||||
UUID targetId, UUID sourceId, UUID playerId,
|
||||
UUID targetId, Ability source, UUID playerId,
|
||||
int amount, boolean flag, ApprovingObject approvingObject
|
||||
) {
|
||||
this.type = type;
|
||||
this.customEventType = customEventType;
|
||||
this.targetId = targetId;
|
||||
this.sourceId = sourceId;
|
||||
this.sourceId = source == null ? null : source.getSourceId(); // We only keep the sourceId from the whole source.
|
||||
this.amount = amount;
|
||||
this.playerId = playerId;
|
||||
this.flag = flag;
|
||||
|
|
@ -863,6 +852,18 @@ public class GameEvent implements Serializable {
|
|||
return identifier.equals(approvingObject.getApprovingAbility().getIdentifier());
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom sourceId setup for some events (use it in constructor).
|
||||
* TODO: replace all custom sourceId to normal event classes
|
||||
* for now, having the setter helps find all that do not provide an Ability source,
|
||||
* so keeping it is worthwhile until a thoughtfull cleanup.
|
||||
*
|
||||
* @param sourceId
|
||||
*/
|
||||
protected void setSourceId(UUID sourceId) {
|
||||
this.sourceId = sourceId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.type.toString();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import java.util.UUID;
|
|||
public class MadnessCardExiledEvent extends GameEvent {
|
||||
|
||||
public MadnessCardExiledEvent(UUID cardId, Ability source, UUID controllerId) {
|
||||
super(GameEvent.EventType.MADNESS_CARD_EXILED, cardId, source.getOriginalId(), controllerId);
|
||||
super(GameEvent.EventType.MADNESS_CARD_EXILED, cardId, null, controllerId);
|
||||
setSourceId(source.getOriginalId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,12 @@ public class ManaPaidEvent extends GameEvent {
|
|||
private final ManaType manaType;
|
||||
|
||||
public ManaPaidEvent(Ability abilityToPay, UUID manaSourceId, boolean manaFlag, UUID manaOriginalId, MageObject sourceObject, ManaType manaType) {
|
||||
super(GameEvent.EventType.MANA_PAID, abilityToPay.getId(), manaSourceId, abilityToPay.getControllerId(), 0, manaFlag);
|
||||
super(GameEvent.EventType.MANA_PAID, abilityToPay.getId(), null, abilityToPay.getControllerId(), 0, manaFlag);
|
||||
this.setData(manaOriginalId.toString());
|
||||
this.sourcePaidId = abilityToPay.getSourceId();
|
||||
this.sourceObject = sourceObject;
|
||||
this.manaType = manaType;
|
||||
this.setSourceId(manaSourceId);
|
||||
}
|
||||
|
||||
public UUID getSourcePaidId() {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import java.util.UUID;
|
|||
public class PhaseChangedEvent extends GameEvent {
|
||||
|
||||
public PhaseChangedEvent(UUID playerId, TurnMod extraTurnMode) {
|
||||
super(GameEvent.EventType.PHASE_CHANGED, playerId, extraTurnMode == null ? null : extraTurnMode.getId(), playerId);
|
||||
super(GameEvent.EventType.PHASE_CHANGED, playerId, null, playerId);
|
||||
this.setSourceId(extraTurnMode == null ? null : extraTurnMode.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ public class PreventDamageEvent extends GameEvent {
|
|||
|
||||
// TODO: investigate why source is provided but not used?
|
||||
public PreventDamageEvent(UUID targetId, UUID attackerId, Ability source, UUID playerId, int damageToPrevent, boolean isCombatDamage) {
|
||||
super(GameEvent.EventType.PREVENT_DAMAGE, targetId, attackerId, playerId, damageToPrevent, isCombatDamage);
|
||||
super(GameEvent.EventType.PREVENT_DAMAGE, targetId, null, playerId, damageToPrevent, isCombatDamage);
|
||||
this.setSourceId(attackerId);
|
||||
}
|
||||
|
||||
public boolean isCombatDamage() {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import java.util.UUID;
|
|||
public class PreventedDamageEvent extends GameEvent {
|
||||
|
||||
public PreventedDamageEvent(UUID targetId, UUID attackerId, Ability source, UUID playerId, int preventedDamage) {
|
||||
super(GameEvent.EventType.PREVENTED_DAMAGE, targetId, attackerId, playerId, preventedDamage, false);
|
||||
super(GameEvent.EventType.PREVENTED_DAMAGE, targetId, null, playerId, preventedDamage, false);
|
||||
this.setSourceId(attackerId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ public class StayAttachedEvent extends GameEvent {
|
|||
|
||||
// TODO: investigate why source is not used as source for the event?
|
||||
public StayAttachedEvent(UUID targetId, UUID attachmentId, Ability source) {
|
||||
super(GameEvent.EventType.STAY_ATTACHED, targetId, attachmentId, null);
|
||||
super(GameEvent.EventType.STAY_ATTACHED, targetId, null, null);
|
||||
this.setSourceId(attachmentId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@ public class TargetEvent extends GameEvent {
|
|||
* @param sourceControllerId can be different from real controller (example: ability instructs another player to targeting)
|
||||
*/
|
||||
public TargetEvent(Card target, UUID sourceId, UUID sourceControllerId) {
|
||||
super(GameEvent.EventType.TARGET, target.getId(), sourceId, sourceControllerId);
|
||||
super(GameEvent.EventType.TARGET, target.getId(), null, sourceControllerId);
|
||||
this.setSourceId(sourceId);
|
||||
}
|
||||
|
||||
public TargetEvent(Player target, UUID sourceId, UUID sourceControllerId) {
|
||||
super(GameEvent.EventType.TARGET, target.getId(), sourceId, sourceControllerId);
|
||||
super(GameEvent.EventType.TARGET, target.getId(), null, sourceControllerId);
|
||||
this.setSourceId(sourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public class UnattachEvent extends GameEvent {
|
|||
|
||||
// TODO: investigate why source is not used as source for the event?
|
||||
public UnattachEvent(UUID targetId, UUID attachmentId, Permanent attachment, Ability source) {
|
||||
super(GameEvent.EventType.UNATTACH, targetId, attachmentId, attachment == null ? null : attachment.getControllerId());
|
||||
super(GameEvent.EventType.UNATTACH, targetId, null, attachment == null ? null : attachment.getControllerId());
|
||||
this.setSourceId(attachmentId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public class UnattachedEvent extends GameEvent {
|
|||
|
||||
// TODO: investigate why source is provided but not used at all?
|
||||
public UnattachedEvent(UUID targetId, UUID attachmentId, Permanent attachment, Ability source) {
|
||||
super(GameEvent.EventType.UNATTACHED, targetId, attachmentId, attachment == null ? null : attachment.getControllerId());
|
||||
super(GameEvent.EventType.UNATTACHED, targetId, null, attachment == null ? null : attachment.getControllerId());
|
||||
this.setSourceId(attachmentId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue