mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
Test framework: fixed support of chooseAbilityForCast for commanders, added destroy target custom effect (#7593);
This commit is contained in:
parent
a377999f57
commit
650acf9e1e
4 changed files with 30 additions and 3 deletions
|
@ -2040,7 +2040,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
return null;
|
||||
}
|
||||
|
||||
MageObject object = game.getObject(card.getId());
|
||||
MageObject object = game.getObject(card.getId()); // must be object to find real abilities (example: commander)
|
||||
if (object != null) {
|
||||
String message = "Choose ability to cast" + (nonMana ? " for FREE" : "") + "<br>" + object.getLogName();
|
||||
LinkedHashMap<UUID, ActivatedAbility> useableAbilities = getSpellAbilities(playerId, object, game.getState().getZone(object.getId()), game);
|
||||
|
@ -2065,6 +2065,8 @@ public class HumanPlayer extends PlayerImpl {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// default ability (example: on disconnect or cancel)
|
||||
return card.getSpellAbility();
|
||||
}
|
||||
|
||||
|
|
|
@ -4146,7 +4146,8 @@ public class TestPlayer implements Player {
|
|||
public SpellAbility chooseAbilityForCast(Card card, Game game, boolean noMana) {
|
||||
assertAliasSupportInChoices(false);
|
||||
|
||||
Map<UUID, ActivatedAbility> useable = PlayerImpl.getSpellAbilities(this.getId(), card, game.getState().getZone(card.getId()), game);
|
||||
MageObject object = game.getObject(card.getId()); // must be object to find real abilities (example: commander)
|
||||
Map<UUID, ActivatedAbility> useable = PlayerImpl.getSpellAbilities(this.getId(), object, game.getState().getZone(object.getId()), game);
|
||||
String allInfo = useable.values().stream().map(Object::toString).collect(Collectors.joining("\n"));
|
||||
if (useable.size() == 1) {
|
||||
return (SpellAbility) useable.values().iterator().next();
|
||||
|
|
|
@ -10,6 +10,7 @@ import mage.abilities.common.SimpleStaticAbility;
|
|||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.DamageTargetEffect;
|
||||
import mage.abilities.effects.common.DestroyTargetEffect;
|
||||
import mage.abilities.effects.common.cost.SpellsCostIncreasingAllEffect;
|
||||
import mage.abilities.effects.common.cost.SpellsCostReductionAllEffect;
|
||||
import mage.cards.Card;
|
||||
|
@ -32,6 +33,7 @@ import mage.server.util.ConfigWrapper;
|
|||
import mage.server.util.PluginClassLoader;
|
||||
import mage.server.util.config.GamePlugin;
|
||||
import mage.server.util.config.Plugin;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.common.TargetAnyTarget;
|
||||
import mage.util.CardUtil;
|
||||
import mage.util.Copier;
|
||||
|
@ -467,6 +469,21 @@ public abstract class MageTestPlayerBase {
|
|||
ability
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add target destroy ability that can be called by text "target destroy"
|
||||
*
|
||||
* @param controller
|
||||
*/
|
||||
protected void addCustomEffect_DestroyTarget(TestPlayer controller) {
|
||||
Ability ability = new SimpleActivatedAbility(new DestroyTargetEffect().setText("target destroy"), new ManaCostsImpl(""));
|
||||
ability.addTarget(new TargetPermanent());
|
||||
addCustomCardWithAbility(
|
||||
"target destroy for " + controller.getName(),
|
||||
controller,
|
||||
ability
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// custom card with global abilities list to init (can contains abilities per card name)
|
||||
|
|
|
@ -1521,7 +1521,14 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
public static LinkedHashMap<UUID, ActivatedAbility> getSpellAbilities(UUID playerId, MageObject object, Zone zone, Game game) {
|
||||
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>();
|
||||
for (Ability ability : object.getAbilities()) {
|
||||
Abilities<Ability> allAbilities;
|
||||
if (object instanceof Card) {
|
||||
allAbilities = ((Card) object).getAbilities(game);
|
||||
} else {
|
||||
allAbilities = object.getAbilities();
|
||||
}
|
||||
|
||||
for (Ability ability : allAbilities) {
|
||||
if (ability instanceof SpellAbility) {
|
||||
switch (((SpellAbility) ability).getSpellAbilityType()) {
|
||||
case BASE_ALTERNATE:
|
||||
|
|
Loading…
Reference in a new issue