mirror of
https://github.com/magefree/mage.git
synced 2026-01-10 04:42:07 -08:00
[WOC] Implement Alela, Cunning Conqueror (#10870)
Add new batch event `DAMAGED_PLAYER_BATCH_ONE_PLAYER`
This commit is contained in:
parent
73dffb8de9
commit
e39e5ee1b0
6 changed files with 305 additions and 9 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package mage.game;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import mage.MageObject;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.*;
|
||||
|
|
@ -44,8 +45,6 @@ import java.util.*;
|
|||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* <p>
|
||||
|
|
@ -817,21 +816,56 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
}
|
||||
|
||||
public void addSimultaneousDamage(DamagedEvent damagedEvent, Game game) {
|
||||
// combine damages per type (player or permanent)
|
||||
boolean flag = false;
|
||||
// This method does look for Batch Event in simultaneousEvents to batch
|
||||
// damagedEvent with. For each kind of batch, either there is a batch
|
||||
// of the proper class fitting the damagedEvent, or there is not.
|
||||
//
|
||||
// If there is not one of the batched event (i.e. if the respective flag is
|
||||
// at false after the loop), then a batched event is created for future
|
||||
// events to be batched with.
|
||||
|
||||
// All damage from any source to anything
|
||||
// the batch is of class DamagedBatchEvent
|
||||
boolean flagBatchAll = false;
|
||||
|
||||
// All damage from any source to a specific player (damagedEvent.getPlayerId())
|
||||
// the batch is of class DamagedPlayerBatchOnePlayerEvent
|
||||
boolean flagBatchForPlayer = false;
|
||||
|
||||
for (GameEvent event : simultaneousEvents) {
|
||||
|
||||
if ((event instanceof DamagedBatchEvent)
|
||||
&& ((DamagedBatchEvent) event).getDamageClazz().isInstance(damagedEvent)) {
|
||||
// old batch
|
||||
|
||||
// existing batch for damage of that damage class.
|
||||
((DamagedBatchEvent) event).addEvent(damagedEvent);
|
||||
flag = true;
|
||||
break;
|
||||
flagBatchAll = true;
|
||||
}
|
||||
|
||||
if (event instanceof DamagedPlayerBatchOnePlayerEvent) {
|
||||
DamagedPlayerBatchOnePlayerEvent eventForPlayer = (DamagedPlayerBatchOnePlayerEvent) event;
|
||||
if (eventForPlayer.getDamageClazz().isInstance(damagedEvent)
|
||||
&& event.getPlayerId().equals(damagedEvent.getPlayerId())) {
|
||||
|
||||
// existing batch for damage of that damage class to the same player
|
||||
eventForPlayer.addEvent(damagedEvent);
|
||||
flagBatchForPlayer = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!flag) {
|
||||
// new batch
|
||||
|
||||
if (!flagBatchAll) {
|
||||
// new batch for any kind of damage, creating a fresh one with damagedEvent inside.
|
||||
addSimultaneousEvent(DamagedBatchEvent.makeEvent(damagedEvent), game);
|
||||
}
|
||||
if (!flagBatchForPlayer && damagedEvent.getPlayerId() != null) {
|
||||
// new batch for damage from any source to the specific damaged player,
|
||||
// creating a fresh one with damagedEvent inside.
|
||||
DamagedBatchEvent event = new DamagedPlayerBatchOnePlayerEvent(damagedEvent.getPlayerId());
|
||||
event.addEvent(damagedEvent);
|
||||
addSimultaneousEvent(event, game);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleEvent(GameEvent event, Game game) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
package mage.game.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Susucr
|
||||
*/
|
||||
public class DamagedPlayerBatchOnePlayerEvent extends DamagedBatchEvent {
|
||||
|
||||
public DamagedPlayerBatchOnePlayerEvent(UUID playerId) {
|
||||
super(EventType.DAMAGED_PLAYER_BATCH_ONE_PLAYER, DamagedPlayerEvent.class);
|
||||
this.setPlayerId(playerId);
|
||||
}
|
||||
}
|
||||
|
|
@ -123,6 +123,11 @@ public class GameEvent implements Serializable {
|
|||
*/
|
||||
DAMAGED_PLAYER_BATCH,
|
||||
|
||||
/* DAMAGED_PLAYER_BATCH_ONE_PLAYER
|
||||
combines all player damaged events for a single player in one single event
|
||||
*/
|
||||
DAMAGED_PLAYER_BATCH_ONE_PLAYER,
|
||||
|
||||
/* DAMAGE_CAUSES_LIFE_LOSS,
|
||||
targetId the id of the damaged player
|
||||
sourceId sourceId of the ability which caused the damage, can be null for default events like combat
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue