forked from External/mage
Improved commander support for mdf/split/adventure cards (additional fixes for ac98a3a31a)
This commit is contained in:
parent
9416c6140a
commit
9b8df48183
12 changed files with 148 additions and 60 deletions
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
package mage.game;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -8,11 +6,13 @@ import java.util.UUID;
|
|||
* @author magenoxx_at_gmail.com
|
||||
*/
|
||||
public interface Controllable {
|
||||
|
||||
UUID getControllerId();
|
||||
|
||||
UUID getId();
|
||||
|
||||
default boolean isControlledBy(UUID controllerID){
|
||||
if(getControllerId() == null){
|
||||
default boolean isControlledBy(UUID controllerID) {
|
||||
if (getControllerId() == null) {
|
||||
return false;
|
||||
}
|
||||
return getControllerId().equals(controllerID);
|
||||
|
|
|
|||
|
|
@ -244,6 +244,9 @@ public abstract class GameImpl implements Game, Serializable {
|
|||
card = ((PermanentCard) card).getCard();
|
||||
}
|
||||
|
||||
// init each card by parts... if you add new type here then getInitAbilities must be
|
||||
// implemented too (it allows to split abilities between card and parts)
|
||||
|
||||
// main card
|
||||
card.setOwnerId(ownerId);
|
||||
addCardToState(card);
|
||||
|
|
|
|||
|
|
@ -847,14 +847,8 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
public void addCard(Card card) {
|
||||
setZone(card.getId(), Zone.OUTSIDE);
|
||||
|
||||
// dirty hack to fix double triggers, see https://github.com/magefree/mage/issues/7187
|
||||
// main mdf card don't have attached abilities, only parts contains it
|
||||
if (card instanceof ModalDoubleFacesCard) {
|
||||
return;
|
||||
}
|
||||
|
||||
// add card's abilities to game
|
||||
for (Ability ability : card.getAbilities()) {
|
||||
// add card specific abilities to game
|
||||
for (Ability ability : card.getInitAbilities()) {
|
||||
addAbility(ability, null, card);
|
||||
}
|
||||
}
|
||||
|
|
@ -912,10 +906,10 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
* span
|
||||
*
|
||||
* @param ability
|
||||
* @param sourceId
|
||||
* @param sourceId - if source object can be moved between zones then you must set it here (each game cycle clear all source related triggers)
|
||||
* @param attachedTo
|
||||
*/
|
||||
public void addAbility(Ability ability, UUID sourceId, Card attachedTo) {
|
||||
public void addAbility(Ability ability, UUID sourceId, MageObject attachedTo) {
|
||||
if (ability instanceof StaticAbility) {
|
||||
for (UUID modeId : ability.getModes().getSelectedModes()) {
|
||||
Mode mode = ability.getModes().get(modeId);
|
||||
|
|
@ -932,7 +926,13 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
List<Watcher> watcherList = new ArrayList<>(ability.getWatchers()); // Workaround to prevent ConcurrentModificationException, not clear to me why this is happening now
|
||||
for (Watcher watcher : watcherList) {
|
||||
// TODO: Check that watcher for commanderAbility (where attachedTo = null) also work correctly
|
||||
watcher.setControllerId(attachedTo == null ? ability.getControllerId() : attachedTo.getOwnerId());
|
||||
UUID controllerId = ability.getControllerId();
|
||||
if (attachedTo instanceof Card) {
|
||||
controllerId = ((Card) attachedTo).getOwnerId();
|
||||
} else if (attachedTo instanceof Controllable) {
|
||||
controllerId = ((Controllable) attachedTo).getControllerId();
|
||||
}
|
||||
watcher.setControllerId(controllerId);
|
||||
watcher.setSourceId(attachedTo == null ? ability.getSourceId() : attachedTo.getId());
|
||||
watchers.add(watcher);
|
||||
}
|
||||
|
|
@ -944,7 +944,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
|
||||
public void addDesignation(Designation designation, Game game, UUID controllerId) {
|
||||
getDesignations().add(designation);
|
||||
for (Ability ability : designation.getAbilities()) {
|
||||
for (Ability ability : designation.getInitAbilities()) {
|
||||
ability.setControllerId(controllerId);
|
||||
addAbility(ability, designation.getId(), null);
|
||||
}
|
||||
|
|
@ -967,7 +967,9 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
public void addCommandObject(CommandObject commandObject) {
|
||||
getCommand().add(commandObject);
|
||||
setZone(commandObject.getId(), Zone.COMMAND);
|
||||
for (Ability ability : commandObject.getAbilities()) {
|
||||
|
||||
// must add only command object specific abilities, all other abilities adds from card parts (on loadCards)
|
||||
for (Ability ability : commandObject.getInitAbilities()) {
|
||||
addAbility(ability, commandObject);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
|
||||
package mage.game.command;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.game.Controllable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Viserion, nantuko
|
||||
*/
|
||||
public interface CommandObject extends MageObject, Controllable {
|
||||
|
|
|
|||
|
|
@ -19,10 +19,7 @@ import mage.game.events.ZoneChangeEvent;
|
|||
import mage.util.GameLog;
|
||||
import mage.util.SubTypes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class Commander implements CommandObject {
|
||||
|
||||
|
|
@ -34,6 +31,11 @@ public class Commander implements CommandObject {
|
|||
public Commander(Card card) {
|
||||
this.sourceObject = card;
|
||||
|
||||
// All abilities must be added to the game before usage. It adding by addCard and addCommandObject calls
|
||||
// Example: if commander from mdf card then
|
||||
// * commander object adds cast/play as commander abilities
|
||||
// * sourceObject adds normal cast/play abilities and all other things
|
||||
|
||||
// replace spell ability by commander cast spell (to cast from command zone)
|
||||
for (Ability ability : card.getAbilities()) {
|
||||
if (ability instanceof SpellAbility) {
|
||||
|
|
@ -78,14 +80,7 @@ public class Commander implements CommandObject {
|
|||
continue;
|
||||
}
|
||||
|
||||
// skip triggers
|
||||
// workaround to fix double triggers for commanders on battlefield (example: Esika, God of the Tree)
|
||||
// TODO: is commanders on command zone can have triggers (is there a card with triggered ability in all zones)?
|
||||
if (ability instanceof TriggeredAbility) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// OK, can add it (example: activated, static, alternative cost, etc)
|
||||
// all other abilities must be added to commander (example: triggers from command zone, alternative cost, etc)
|
||||
Ability newAbility = ability.copy();
|
||||
abilities.add(newAbility);
|
||||
}
|
||||
|
|
@ -186,6 +181,22 @@ public class Commander implements CommandObject {
|
|||
return abilities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Abilities<Ability> getInitAbilities() {
|
||||
// see commander contruction comments for more info
|
||||
|
||||
// collect ignore list
|
||||
Set<UUID> ignore = new HashSet<>();
|
||||
sourceObject.getAbilities().forEach(ability -> ignore.add(ability.getId()));
|
||||
|
||||
// return only object specific abilities
|
||||
Abilities<Ability> res = new AbilitiesImpl<>();
|
||||
this.getAbilities().stream()
|
||||
.filter(ability -> !ignore.contains(ability.getId()))
|
||||
.forEach(res::add);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAbility(Ability ability, Game game) {
|
||||
if (this.getAbilities().contains(ability)) {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,7 @@ import mage.MageInt;
|
|||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Abilities;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.*;
|
||||
import mage.abilities.costs.AlternativeSourceCosts;
|
||||
import mage.abilities.costs.mana.ActivationManaAbilityStep;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
|
|
@ -570,6 +567,11 @@ public class Spell extends StackObjImpl implements Card {
|
|||
return card.getAbilities();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Abilities<Ability> getInitAbilities() {
|
||||
return new AbilitiesImpl<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Abilities<Ability> getAbilities(Game game) {
|
||||
return card.getAbilities(game);
|
||||
|
|
|
|||
|
|
@ -44,12 +44,12 @@ import java.util.UUID;
|
|||
*/
|
||||
public class StackAbility extends StackObjImpl implements Ability {
|
||||
|
||||
private static ArrayList<CardType> emptyCardType = new ArrayList<>();
|
||||
private static List<String> emptyString = new ArrayList<>();
|
||||
private static ObjectColor emptyColor = new ObjectColor();
|
||||
private static ManaCosts<ManaCost> emptyCost = new ManaCostsImpl<>();
|
||||
private static Costs<Cost> emptyCosts = new CostsImpl<>();
|
||||
private static Abilities<Ability> emptyAbilites = new AbilitiesImpl<>();
|
||||
private static final ArrayList<CardType> emptyCardType = new ArrayList<>();
|
||||
private static final List<String> emptyString = new ArrayList<>();
|
||||
private static final ObjectColor emptyColor = new ObjectColor();
|
||||
private static final ManaCosts<ManaCost> emptyCost = new ManaCostsImpl<>();
|
||||
private static final Costs<Cost> emptyCosts = new CostsImpl<>();
|
||||
private static final Abilities<Ability> emptyAbilites = new AbilitiesImpl<>();
|
||||
|
||||
private final Ability ability;
|
||||
private UUID controllerId;
|
||||
|
|
@ -186,6 +186,11 @@ public class StackAbility extends StackObjImpl implements Ability {
|
|||
return new AbilitiesImpl<>(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Abilities<Ability> getInitAbilities() {
|
||||
return new AbilitiesImpl<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAbility(Ability ability, Game game) {
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue