make batchs for milling cards (per player, all)

Rework and test the couple of existing cards triggering on mill.
This commit is contained in:
Susucre 2024-05-01 20:55:50 +02:00
parent 4edb9ce270
commit 7c3bbed8f3
17 changed files with 452 additions and 107 deletions

View file

@ -17,6 +17,7 @@ public abstract class BatchEvent<T extends GameEvent> extends GameEvent {
private final Set<T> events = new HashSet<>();
private final boolean singleTargetId;
private final boolean singleSourceId;
private final boolean singlePlayerId;
/**
* @param eventType specific type of event
@ -25,9 +26,25 @@ 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), null, null);
this(eventType, singleTargetId, singleSourceId, false, firstEvent);
}
/**
* @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 singlePlayerId if true, all included events must have same player id
* @param firstEvent added to initialize the batch (batch is never empty)
*/
protected BatchEvent(EventType eventType, boolean singleTargetId, boolean singleSourceId, boolean singlePlayerId, T firstEvent) {
super(eventType,
(singleTargetId ? firstEvent.getTargetId() : null),
null,
(singlePlayerId ? firstEvent.getPlayerId() : null)
);
this.singleTargetId = singleTargetId;
this.singleSourceId = singleSourceId;
this.singlePlayerId = singlePlayerId;
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");
@ -42,6 +59,7 @@ public abstract class BatchEvent<T extends GameEvent> extends GameEvent {
super(eventType, null, null, null);
this.singleTargetId = false;
this.singleSourceId = false;
this.singlePlayerId = false;
}
public void addEvent(T event) {
@ -104,8 +122,10 @@ public abstract class BatchEvent<T extends GameEvent> extends GameEvent {
}
@Override // events can store a diff value, so search it from events list instead
@Deprecated // no use case currently supported
public UUID getPlayerId() {
if (singlePlayerId) {
return super.getPlayerId();
}
throw new IllegalStateException("Wrong code usage. Must search value from a getEvents list");
}