[ZNR] Implemented party mechanic (#7036)

* added incomplete party count implementation

* updated party count implementation

* added party count test

* fixed tests, updated test framework

* added an additional test

* fixed some errors in party count computation, should be good now

* fixed a small error with test generation

* fixed an NPE issue
This commit is contained in:
Evan Kranzler 2020-09-03 19:22:05 -04:00 committed by GitHub
commit cc0bb84dad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 245 additions and 3 deletions

View file

@ -0,0 +1,127 @@
package org.mage.test.cards.dynamicvalue;
import mage.constants.CardType;
import mage.constants.PhaseStep;
import mage.constants.SubType;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* @author TheElk801
*/
public class PartyCountTest extends CardTestPlayerBase {
private static final String shpd = "Shepherd of Heroes";
private static final String skrmshr = "Aven Skirmisher";
private static final String dncstr = "Dromoka Dunecaster";
private static final String ddgr = "Goldmeadow Dodger";
@Test
public void testSingleMember() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
addCard(Zone.HAND, playerA, shpd);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, shpd);
setStopAt(1, PhaseStep.END_TURN);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
assertLife(playerA, 22);
}
@Test
public void testTwoMembers() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 6);
addCard(Zone.HAND, playerA, skrmshr);
addCard(Zone.HAND, playerA, shpd);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, skrmshr);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, shpd);
setStopAt(1, PhaseStep.END_TURN);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
assertLife(playerA, 24);
}
@Test
public void testTwoMembers2() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 7);
addCard(Zone.HAND, playerA, skrmshr, 2);
addCard(Zone.HAND, playerA, shpd);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, skrmshr);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, skrmshr);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, shpd);
setStopAt(1, PhaseStep.END_TURN);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
assertLife(playerA, 24);
}
@Test
public void testThreeMembers() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 7);
addCard(Zone.HAND, playerA, skrmshr);
addCard(Zone.HAND, playerA, dncstr);
addCard(Zone.HAND, playerA, shpd);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, skrmshr);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, dncstr);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, shpd);
setStopAt(1, PhaseStep.END_TURN);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
assertLife(playerA, 26);
}
private void makeCreature(String name, SubType... subTypes) {
addCustomCardWithAbility(name, playerA, null, null, CardType.CREATURE, "{1}", Zone.BATTLEFIELD, subTypes);
}
@Test
public void testOddCombos() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
addCard(Zone.HAND, playerA, shpd);
makeCreature("crtA", SubType.ROGUE, SubType.WIZARD, SubType.WARRIOR);
makeCreature("crtB", SubType.ROGUE, SubType.CLERIC);
makeCreature("crtC", SubType.CLERIC, SubType.WIZARD);
makeCreature("crtD", SubType.WARRIOR, SubType.WIZARD);
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, shpd);
setStopAt(1, PhaseStep.END_TURN);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
assertLife(playerA, 28);
}
@Test
public void testChangelings() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 5);
addCard(Zone.BATTLEFIELD, playerA, "Impostor of the Sixth Pride", 4);
addCard(Zone.HAND, playerA, shpd);
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, shpd);
setStopAt(1, PhaseStep.END_TURN);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
assertLife(playerA, 28);
}
}

View file

@ -1,5 +1,6 @@
package org.mage.test.serverside.base;
import mage.MageInt;
import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl;
import mage.abilities.Ability;
@ -381,8 +382,15 @@ public abstract class MageTestPlayerBase {
protected void addCustomCardWithAbility(String customName, TestPlayer controllerPlayer, Ability ability, SpellAbility spellAbility,
CardType cardType, String spellCost, Zone putAtZone) {
addCustomCardWithAbility(customName, controllerPlayer, ability, spellAbility, cardType, spellCost, putAtZone, null);
}
protected void addCustomCardWithAbility(String customName, TestPlayer controllerPlayer, Ability ability, SpellAbility spellAbility,
CardType cardType, String spellCost, Zone putAtZone, SubType... additionalSubTypes) {
CustomTestCard.clearCustomAbilities(customName);
CustomTestCard.addCustomAbility(customName, spellAbility, ability);
CustomTestCard.clearAdditionalSubtypes(customName);
CustomTestCard.addAdditionalSubtypes(customName, additionalSubTypes);
CardSetInfo testSet = new CardSetInfo(customName, "custom", "123", Rarity.COMMON);
PermanentCard card = new PermanentCard(new CustomTestCard(controllerPlayer.getId(), testSet, cardType, spellCost), controllerPlayer.getId(), currentGame);
@ -414,6 +422,7 @@ class CustomTestCard extends CardImpl {
static private final Map<String, Abilities<Ability>> abilitiesList = new HashMap<>(); // card name -> abilities
static private final Map<String, SpellAbility> spellAbilitiesList = new HashMap<>(); // card name -> spell ability
static private final Map<String, Set<SubType>> subTypesList = new HashMap<>(); // card name -> additional subtypes
static void addCustomAbility(String cardName, SpellAbility spellAbility, Ability ability) {
if (!abilitiesList.containsKey(cardName)) {
@ -430,6 +439,16 @@ class CustomTestCard extends CardImpl {
spellAbilitiesList.remove(cardName);
}
static void addAdditionalSubtypes(String cardName, SubType... subtypes) {
if(subtypes!=null) {
subTypesList.computeIfAbsent(cardName, s -> new HashSet<>()).addAll(Arrays.asList(subtypes.clone()));
}
}
static void clearAdditionalSubtypes(String cardName) {
subTypesList.remove(cardName);
}
CustomTestCard(UUID ownerId, CardSetInfo setInfo, CardType cardType, String spellCost) {
super(ownerId, setInfo, new CardType[]{cardType}, spellCost);
@ -443,6 +462,17 @@ class CustomTestCard extends CardImpl {
this.addAbility(ability.copy());
}
}
Set<SubType> subTypeSet = subTypesList.get(setInfo.getName());
if (subTypeSet != null) {
for (SubType subType : subTypeSet) {
this.subtype.add(subType);
}
}
if (cardType == CardType.CREATURE) {
this.power = new MageInt(1);
this.toughness = new MageInt(1);
}
}
private CustomTestCard(final CustomTestCard card) {