refactor: remove unused custom event type code (#12729)

* also make ApprovingObject Serializable
This commit is contained in:
xenohedron 2024-08-24 20:39:36 -04:00 committed by GitHub
parent 4259b7fa39
commit 85d612d10f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 47 deletions

View file

@ -3,11 +3,13 @@ package mage;
import mage.abilities.Ability;
import mage.game.Game;
import java.io.Serializable;
/**
*
* @author LevelX2
*/
public class ApprovingObject {
public class ApprovingObject implements Serializable {
private final Ability approvingAbility;
private final MageObjectReference approvingMageObjectReference;

View file

@ -32,7 +32,6 @@ public class GameEvent implements Serializable {
protected Zone zone;
protected List<UUID> appliedEffects = new ArrayList<>();
protected ApprovingObject approvingObject; // e.g. the approving object for casting a spell from non hand zone
protected UUID customEventType = null;
public enum EventType {
@ -668,28 +667,20 @@ public class GameEvent implements Serializable {
playerId player who gave the gift
*/
GAVE_GIFT,
//custom events
// custom events - must store some unique data to track
CUSTOM_EVENT
}
public GameEvent(EventType type, UUID targetId, Ability source, UUID playerId) {
this(type, null, targetId, source, playerId, 0, false);
this(type, targetId, source, playerId, 0, false, null);
}
public GameEvent(EventType type, UUID targetId, Ability source, UUID playerId, ApprovingObject approvingObject) {
this(type, null, targetId, source, playerId, 0, false, approvingObject);
this(type, 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, playerId, amount, flag);
}
public GameEvent(UUID customEventType, UUID targetId, Ability source, UUID playerId) {
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, playerId, amount, flag);
this(type, targetId, source, playerId, amount, flag, null);
}
public static GameEvent getEvent(EventType type, UUID targetId, Ability source, UUID playerId, int amount) {
@ -716,24 +707,10 @@ public class GameEvent implements Serializable {
return event;
}
public static GameEvent getEvent(UUID customEventType, UUID targetId, Ability source, UUID playerId, int amount) {
return new GameEvent(customEventType, targetId, source, playerId, amount, false);
}
public static GameEvent getEvent(UUID customEventType, UUID targetId, Ability source, UUID playerId) {
return new GameEvent(customEventType, targetId, source, playerId);
}
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, Ability source, UUID playerId,
private GameEvent(EventType type, UUID targetId, Ability source, UUID playerId,
int amount, boolean flag, ApprovingObject approvingObject
) {
this.type = type;
this.customEventType = customEventType;
this.targetId = targetId;
this.sourceId = source == null ? null : source.getSourceId(); // We only keep the sourceId from the whole source.
this.amount = amount;
@ -747,18 +724,12 @@ public class GameEvent implements Serializable {
return type;
}
public UUID getCustomEventType() {
return customEventType;
}
public UUID getId() {
return id;
}
/**
* Some batch events can contain multiple events list, see BatchGameEvent for usage
*
* @return
*/
public UUID getTargetId() {
return targetId;
@ -825,8 +796,6 @@ public class GameEvent implements Serializable {
/**
* Returns possibly approving object that allowed the creation of the event.
*
* @return
*/
public ApprovingObject getAdditionalReference() {
return approvingObject;
@ -847,17 +816,11 @@ public class GameEvent implements Serializable {
* creature or player, it deals double that damage to that creature or
* player instead." A creature that normally deals 2 damage will deal 8
* damage--not just 4, and not an infinite amount.
*
* @return
*/
public List<UUID> getAppliedEffects() {
return appliedEffects;
}
public boolean isCustomEvent(UUID customEventType) {
return type == EventType.CUSTOM_EVENT && this.customEventType.equals(customEventType);
}
public void addAppliedEffects(List<UUID> appliedEffects) {
if (appliedEffects != null) {
this.appliedEffects.addAll(appliedEffects);
@ -867,7 +830,7 @@ public class GameEvent implements Serializable {
public void setAppliedEffects(List<UUID> appliedEffects) {
if (appliedEffects != null) {
if (this.appliedEffects.isEmpty()) {
this.appliedEffects = appliedEffects; // Use object refecence to handle that an replacement effect can only be once applied to an event
this.appliedEffects = appliedEffects; // Use object reference to handle that an replacement effect can only be once applied to an event
} else {
this.appliedEffects.addAll(appliedEffects);
}
@ -888,9 +851,7 @@ public class GameEvent implements Serializable {
* 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
* so keeping it is worthwhile until a thoughtful cleanup.
*/
protected void setSourceId(UUID sourceId) {
this.sourceId = sourceId;