mirror of
https://github.com/correl/mage.git
synced 2024-12-29 19:15:06 +00:00
* UI: choose spell to cast dialog - added card name for spell abilities (split, adventure, additional spell, etc, see #6549);
This commit is contained in:
parent
dcd6cf34f3
commit
0c2e08f54e
2 changed files with 106 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
package mage.view;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.SpellAbility;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedHashMap;
|
||||
|
@ -28,15 +29,30 @@ public class AbilityPickerView implements Serializable {
|
|||
if (objectName == null) {
|
||||
rule = ability.getRule(true);
|
||||
} else {
|
||||
rule = ability.getRule(objectName);
|
||||
if (rule.isEmpty()) {
|
||||
rule = ability.toString();
|
||||
// spell abilities must start with "Cast name" (split cards have different names for each spell part)
|
||||
if (ability instanceof SpellAbility) {
|
||||
SpellAbility spell = (SpellAbility) ability;
|
||||
rule = getAbilityRules(spell, spell.getCardName());
|
||||
if (!rule.startsWith("Cast ")) {
|
||||
rule = spell.toString() + ": " + rule; // spell.toString() must return this.name (example: Cast Armed)
|
||||
}
|
||||
} else {
|
||||
rule = getAbilityRules(ability, objectName);
|
||||
}
|
||||
}
|
||||
choices.put(ability.getId(), num + ". " + rule);
|
||||
}
|
||||
}
|
||||
|
||||
private String getAbilityRules(Ability ability, String objectName) {
|
||||
String rule = ability.getRule(objectName);
|
||||
if (rule.isEmpty()) {
|
||||
rule = ability.toString();
|
||||
}
|
||||
rule = Character.toUpperCase(rule.charAt(0)) + rule.substring(1);
|
||||
return rule;
|
||||
}
|
||||
|
||||
public AbilityPickerView(Map<UUID, String> modes, String message) {
|
||||
this.choices = modes;
|
||||
this.message = message;
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
package org.mage.test.serverside;
|
||||
|
||||
import mage.abilities.Abilities;
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import mage.game.permanent.PermanentImpl;
|
||||
import mage.view.AbilityPickerView;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public class AbilityPickerTest extends CardTestPlayerBase {
|
||||
|
||||
@Test
|
||||
public void test_PickerChoices_FusedSpells() {
|
||||
// must be 3 spells for choices
|
||||
Abilities<Ability> abilities = getAbilitiesFromCard("Armed // Dangerous");
|
||||
Assert.assertEquals(3, abilities.size());
|
||||
|
||||
AbilityPickerView view = new AbilityPickerView("test name", abilities, "test message");
|
||||
Assert.assertEquals(3, view.getChoices().size());
|
||||
view.getChoices().values().forEach(c -> {
|
||||
Assert.assertTrue("Must start with Cast text, but found: " + c, c.contains("Cast "));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_PickerChoices_AdventureSpells() {
|
||||
// must be 2 spells for choices and 1 static ability
|
||||
Abilities<Ability> abilities = getAbilitiesFromCard("Foulmire Knight");
|
||||
Assert.assertEquals(3, abilities.size());
|
||||
|
||||
AbilityPickerView view = new AbilityPickerView("test name", abilities, "test message");
|
||||
Assert.assertEquals(3, view.getChoices().size());
|
||||
view.getChoices().values().forEach(c -> {
|
||||
if (c.contains("Deathtouch")) {
|
||||
return;
|
||||
}
|
||||
Assert.assertTrue("Must start with Cast text, but found: " + c, c.contains("Cast "));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_PickerChoices_ActivatedAbilities() {
|
||||
// must be 1 cast + 3 abilities
|
||||
Abilities<Ability> abilities = getAbilitiesFromCard("Dimir Cluestone");
|
||||
Assert.assertEquals(4, abilities.size());
|
||||
|
||||
AbilityPickerView view = new AbilityPickerView("test name", abilities, "test message");
|
||||
Assert.assertEquals(4, view.getChoices().size());
|
||||
int castCount = 0;
|
||||
int abilsCount = 0;
|
||||
for (String c : view.getChoices().values()) {
|
||||
if (c.contains("Cast ")) {
|
||||
castCount++;
|
||||
} else {
|
||||
abilsCount++;
|
||||
}
|
||||
}
|
||||
Assert.assertEquals(1, castCount);
|
||||
Assert.assertEquals(3, abilsCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_PickerChoices_AdditionalSpells() {
|
||||
// must be 2 cast
|
||||
Abilities<Ability> abilities = getAbilitiesFromCard("Cling to Dust");
|
||||
Assert.assertEquals(2, abilities.size());
|
||||
|
||||
AbilityPickerView view = new AbilityPickerView("test name", abilities, "test message");
|
||||
Assert.assertEquals(2, view.getChoices().size());
|
||||
view.getChoices().values().forEach(c -> {
|
||||
Assert.assertTrue("Must start with Cast text, but found: " + c, c.contains("Cast "));
|
||||
});
|
||||
}
|
||||
|
||||
private Abilities<Ability> getAbilitiesFromCard(String cardName) {
|
||||
CardInfo info = CardRepository.instance.findCard(cardName);
|
||||
PermanentImpl permanent = new PermanentCard(info.getCard(), playerA.getId(), currentGame);
|
||||
return permanent.getAbilities(currentGame);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue