Improved commander support for mdf/split/adventure cards (additional fixes for ac98a3a31a)

This commit is contained in:
Oleg Agafonov 2021-02-06 17:07:10 +04:00
parent 9416c6140a
commit 9b8df48183
12 changed files with 148 additions and 60 deletions

View file

@ -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 {

View file

@ -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)) {