mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
Manually added changes from halljared for group move events (fixes #1728).
This commit is contained in:
parent
5686f6b34f
commit
1dfa801d1f
3 changed files with 99 additions and 31 deletions
|
|
@ -32,8 +32,12 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Abilities;
|
||||
|
|
@ -59,6 +63,8 @@ import mage.game.combat.CombatGroup;
|
|||
import mage.game.command.Command;
|
||||
import mage.game.command.CommandObject;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.game.events.ZoneChangeGroupEvent;
|
||||
import mage.game.permanent.Battlefield;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.SpellStack;
|
||||
|
|
@ -655,7 +661,9 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
if (!simultaneousEvents.isEmpty() && !getTurn().isEndTurnRequested()) {
|
||||
// it can happen, that the events add new simultaneous events, so copy the list before
|
||||
List<GameEvent> eventsToHandle = new ArrayList<>();
|
||||
List<GameEvent> eventGroups = createEventGroups(simultaneousEvents, game);
|
||||
eventsToHandle.addAll(simultaneousEvents);
|
||||
eventsToHandle.addAll(eventGroups);
|
||||
simultaneousEvents.clear();
|
||||
for (GameEvent event : eventsToHandle) {
|
||||
this.handleEvent(event, game);
|
||||
|
|
@ -684,6 +692,76 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
return effects.replaceEvent(event, game);
|
||||
}
|
||||
|
||||
public List<GameEvent> createEventGroups(List<GameEvent> events, Game game) {
|
||||
|
||||
class ZoneChangeData {
|
||||
|
||||
private final Zone fromZone;
|
||||
private final Zone toZone;
|
||||
private final UUID sourceId;
|
||||
private final UUID playerId;
|
||||
|
||||
public ZoneChangeData(UUID sourceId, UUID playerId, Zone fromZone, Zone toZone) {
|
||||
this.sourceId = sourceId;
|
||||
this.playerId = playerId;
|
||||
this.fromZone = fromZone;
|
||||
this.toZone = toZone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (this.fromZone.ordinal() + 1) * 1
|
||||
+ (this.toZone.ordinal() + 1) * 10
|
||||
+ (this.sourceId != null ? this.sourceId.hashCode() : 0)
|
||||
+ (this.playerId != null ? this.playerId.hashCode() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ZoneChangeData) {
|
||||
ZoneChangeData data = (ZoneChangeData) obj;
|
||||
return this.fromZone == data.fromZone
|
||||
&& this.toZone == data.toZone
|
||||
&& this.sourceId == data.sourceId
|
||||
&& this.playerId == data.playerId;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Map<ZoneChangeData, List<GameEvent>> eventsByKey = new HashMap<>();
|
||||
List<GameEvent> groupEvents = new LinkedList<>();
|
||||
for (GameEvent event : events) {
|
||||
if (event instanceof ZoneChangeEvent) {
|
||||
ZoneChangeEvent castEvent = (ZoneChangeEvent) event;
|
||||
ZoneChangeData key = new ZoneChangeData(castEvent.getSourceId(), castEvent.getPlayerId(), castEvent.getFromZone(), castEvent.getToZone());
|
||||
if (eventsByKey.containsKey(key)) {
|
||||
eventsByKey.get(key).add(event);
|
||||
} else {
|
||||
List<GameEvent> list = new LinkedList<>();
|
||||
list.add(event);
|
||||
eventsByKey.put(key, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<ZoneChangeData, List<GameEvent>> entry : eventsByKey.entrySet()) {
|
||||
Set<Card> movedCards = new LinkedHashSet<>();
|
||||
for (Iterator<GameEvent> it = entry.getValue().iterator(); it.hasNext();) {
|
||||
GameEvent event = it.next();
|
||||
ZoneChangeEvent castEvent = (ZoneChangeEvent) event;
|
||||
UUID targetId = castEvent.getTargetId();
|
||||
Card card = game.getCard(targetId);
|
||||
movedCards.add(card);
|
||||
}
|
||||
ZoneChangeData eventData = entry.getKey();
|
||||
if (!movedCards.isEmpty()) {
|
||||
ZoneChangeGroupEvent event = new ZoneChangeGroupEvent(movedCards, eventData.sourceId, eventData.playerId, eventData.fromZone, eventData.toZone);
|
||||
groupEvents.add(event);
|
||||
}
|
||||
}
|
||||
return groupEvents;
|
||||
}
|
||||
|
||||
public void addCard(Card card) {
|
||||
setZone(card.getId(), Zone.OUTSIDE);
|
||||
for (Ability ability : card.getAbilities()) {
|
||||
|
|
|
|||
|
|
@ -123,7 +123,6 @@ import mage.game.events.DamagedPlayerEvent;
|
|||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.game.events.ZoneChangeGroupEvent;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
|
|
@ -3249,9 +3248,6 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
default:
|
||||
throw new UnsupportedOperationException("to Zone" + toZone.toString() + " not supported yet");
|
||||
}
|
||||
if (!successfulMovedCards.isEmpty()) {
|
||||
game.fireEvent(new ZoneChangeGroupEvent(successfulMovedCards, source == null ? null : source.getSourceId(), this.getId(), fromZone, toZone));
|
||||
}
|
||||
return successfulMovedCards.size() > 0;
|
||||
}
|
||||
|
||||
|
|
@ -3267,7 +3263,6 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
if (cards.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
game.fireEvent(new ZoneChangeGroupEvent(cards, source == null ? null : source.getSourceId(), this.getId(), null, Zone.EXILED));
|
||||
boolean result = false;
|
||||
for (Card card : cards) {
|
||||
Zone fromZone = game.getState().getZone(card.getId());
|
||||
|
|
@ -3368,7 +3363,6 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
}
|
||||
}
|
||||
}
|
||||
game.fireEvent(new ZoneChangeGroupEvent(movedCards, source == null ? null : source.getSourceId(), this.getId(), fromZone, Zone.GRAVEYARD));
|
||||
return movedCards;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue