forked from External/mage
Refactor batch events (#11995)
* create new abstract class for batch event framework * adjust CardUtil.getEventTargets to support new framework * update TappedBatchEvent to new framework * update UntappedBatchEvent to new framework * slight cleanup * update LifeLostBatchEvent to new framework * update ZoneChangeBatchEvent to new framework * complete refactor by moving damage events to new framework * remove old code no longer used * clean up some nonsense code in star wars card * fix watcher checking id before event type * fix wrong id usage * fix missed wrong id usage
This commit is contained in:
parent
8869d282b2
commit
cb28fb5a56
39 changed files with 308 additions and 635 deletions
|
|
@ -1,54 +1,8 @@
|
|||
package mage.game.events;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ZoneChangeBatchEvent extends GameEvent implements BatchGameEvent<ZoneChangeEvent> {
|
||||
|
||||
private final Set<ZoneChangeEvent> events = new HashSet<>();
|
||||
public class ZoneChangeBatchEvent extends BatchEvent<ZoneChangeEvent> {
|
||||
|
||||
public ZoneChangeBatchEvent() {
|
||||
super(EventType.ZONE_CHANGE_BATCH, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ZoneChangeEvent> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> getTargets() {
|
||||
return events
|
||||
.stream()
|
||||
.map(GameEvent::getTargetId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAmount() {
|
||||
return events
|
||||
.stream()
|
||||
.mapToInt(GameEvent::getAmount)
|
||||
.sum();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // events can store a diff value, so search it from events list instead
|
||||
public UUID getTargetId() {
|
||||
throw new IllegalStateException("Wrong code usage. Must search value from a getEvents list or use CardUtil.getEventTargets(event)");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // events can store a diff value, so search it from events list instead
|
||||
public UUID getSourceId() {
|
||||
throw new IllegalStateException("Wrong code usage. Must search value from a getEvents list.");
|
||||
}
|
||||
|
||||
public void addEvent(ZoneChangeEvent event) {
|
||||
this.events.add(event);
|
||||
super(EventType.ZONE_CHANGE_BATCH);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue