forked from External/mage
if multiple permanents come to battlefield at the same time, they are aware now of each other. (e.g. useful for for Valakut, the Molten Pinnacle).
This commit is contained in:
parent
9a0c05f576
commit
ca831aee05
6 changed files with 39 additions and 6 deletions
|
|
@ -159,6 +159,8 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
|
|||
if (effect.applyEffectsAfter()) {
|
||||
game.applyEffects();
|
||||
}
|
||||
// effects like entersBattlefield have to trigger simultanously so objects see each other
|
||||
game.getState().handleSimultaneousEvent(game);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -118,11 +118,9 @@ public abstract class EffectImpl<T extends Effect<T>> implements Effect<T> {
|
|||
|
||||
@Override
|
||||
public void setValue(String key, Object value) {
|
||||
if (values == null) {
|
||||
synchronized (this) {
|
||||
if (values == null) {
|
||||
values = new HashMap<String, Object>();
|
||||
}
|
||||
synchronized (this) {
|
||||
if (values == null) {
|
||||
values = new HashMap<String, Object>();
|
||||
}
|
||||
}
|
||||
values.put(key, value);
|
||||
|
|
|
|||
|
|
@ -172,6 +172,12 @@ public interface Game extends MageItem, Serializable {
|
|||
|
||||
//game event methods
|
||||
void fireEvent(GameEvent event);
|
||||
/**
|
||||
* The events are stored until the resolution of the current effect ends
|
||||
* and fired then all together (e.g. X lands enter the battlefield from Scapeshift)
|
||||
* @param event
|
||||
*/
|
||||
void addSimultaneousEvent(GameEvent event);
|
||||
boolean replaceEvent(GameEvent event);
|
||||
|
||||
//game play methods
|
||||
|
|
|
|||
|
|
@ -1790,6 +1790,11 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
return state.getPriorityPlayerId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSimultaneousEvent(GameEvent event) {
|
||||
state.addSimultaneousEvent(event, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fireEvent(GameEvent event) {
|
||||
state.handleEvent(event, this);
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
private final Map<UUID, Abilities<ActivatedAbility>> otherAbilities = new HashMap<UUID, Abilities<ActivatedAbility>>();
|
||||
private final TurnMods turnMods;
|
||||
private final Watchers watchers;
|
||||
|
||||
|
||||
private UUID activePlayerId;
|
||||
private UUID priorityPlayerId;
|
||||
|
|
@ -114,6 +115,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
private Combat combat;
|
||||
private Map<String, Object> values = new HashMap<String, Object>();
|
||||
private Map<UUID, Zone> zones = new HashMap<UUID, Zone>();
|
||||
private List<GameEvent> simultaneousEvents = new ArrayList<GameEvent>();
|
||||
|
||||
public GameState() {
|
||||
players = new Players();
|
||||
|
|
@ -172,6 +174,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
otherAbilities.put(entry.getKey(), entry.getValue().copy());
|
||||
}
|
||||
this.paused = state.paused;
|
||||
this.simultaneousEvents.addAll(state.simultaneousEvents);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -482,6 +485,20 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
Player origPlayer = players.get(copyPlayer.getId());
|
||||
origPlayer.restore(copyPlayer);
|
||||
}
|
||||
this.simultaneousEvents = state.simultaneousEvents;
|
||||
}
|
||||
|
||||
public void addSimultaneousEvent(GameEvent event, Game game) {
|
||||
simultaneousEvents.add(event);
|
||||
}
|
||||
|
||||
public void handleSimultaneousEvent(Game game) {
|
||||
if (!simultaneousEvents.isEmpty()) {
|
||||
for (GameEvent event:simultaneousEvents) {
|
||||
this.handleEvent(event, game);
|
||||
}
|
||||
simultaneousEvents.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void handleEvent(GameEvent event, Game game) {
|
||||
|
|
@ -665,6 +682,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
watchers.clear();
|
||||
values.clear();
|
||||
zones.clear();
|
||||
simultaneousEvents.clear();
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
|
|
|
|||
|
|
@ -748,7 +748,11 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
EntersTheBattlefieldEvent event = new EntersTheBattlefieldEvent(this, sourceId, getControllerId(), fromZone);
|
||||
if (!game.replaceEvent(event)) {
|
||||
if (fireEvent) {
|
||||
game.fireEvent(event);
|
||||
if (sourceId == null) { // play lands
|
||||
game.fireEvent(event);
|
||||
} else { // from effects
|
||||
game.addSimultaneousEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue