forked from magefree/mage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor together experience counter DynamicValue
- Loading branch information
Showing
6 changed files
with
129 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
Mage.Tests/src/test/java/org/mage/test/cards/single/onc/OtharriSunsGloryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.mage.test.cards.single.onc; | ||
|
||
import mage.constants.PhaseStep; | ||
import mage.constants.Zone; | ||
import mage.counters.CounterType; | ||
import mage.players.Player; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mage.test.serverside.base.CardTestPlayerBase; | ||
|
||
/** | ||
* @author Susucr | ||
*/ | ||
public class OtharriSunsGloryTest extends CardTestPlayerBase { | ||
|
||
/** | ||
* {@link mage.cards.o.OtharriSunsGlory Otharri, Suns' Glory} {3}{R}{W} | ||
* Legendary Creature — Phoenix | ||
* Flying, lifelink, haste | ||
* Whenever Otharri, Suns’ Glory attacks, you get an experience counter. Then create a 2/2 red Rebel creature token that’s tapped and attacking for each experience counter you have. | ||
* {2}{R}{W}, Tap an untapped Rebel you control: Return Otharri from your graveyard to the battlefield tapped. | ||
* 3/3 | ||
*/ | ||
private static final String otharri = "Otharri, Suns' Glory"; | ||
|
||
private static void checkExperienceCounter(String message, Player player, int expected) { | ||
Assert.assertEquals(message, expected, player.getCounters().getCount(CounterType.EXPERIENCE)); | ||
} | ||
|
||
@Test | ||
public void test_Experience_Rebels() { | ||
setStrictChooseMode(true); | ||
|
||
addCard(Zone.BATTLEFIELD, playerA, otharri); | ||
|
||
attack(1, playerA, otharri, playerB); | ||
runCode("experience count playerA after first attack", 1, PhaseStep.POSTCOMBAT_MAIN, playerA, | ||
(info, player, game) -> checkExperienceCounter(info, player, 1)); | ||
|
||
attack(3, playerA, otharri, playerB); | ||
|
||
setStopAt(3, PhaseStep.END_TURN); | ||
execute(); | ||
|
||
assertLife(playerA, 20 + 3 * 2); | ||
assertLife(playerB, 20 - 3 * 2 - 2 * (1 + 2)); | ||
assertPermanentCount(playerA, "Rebel Token", 1 + 2); | ||
assertCounterCount(playerA, CounterType.EXPERIENCE, 2); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
Mage/src/main/java/mage/abilities/dynamicvalue/common/SourceControllerCountersCount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package mage.abilities.dynamicvalue.common; | ||
|
||
import mage.abilities.Ability; | ||
import mage.abilities.dynamicvalue.DynamicValue; | ||
import mage.abilities.effects.Effect; | ||
import mage.counters.CounterType; | ||
import mage.game.Game; | ||
import mage.players.Player; | ||
|
||
/** | ||
* @author Susucr | ||
*/ | ||
public enum SourceControllerCountersCount implements DynamicValue { | ||
EXPERIENCE(CounterType.EXPERIENCE), | ||
RAD(CounterType.RAD); | ||
|
||
private final CounterType counterType; | ||
|
||
|
||
SourceControllerCountersCount(CounterType counterType) { | ||
this.counterType = counterType; | ||
} | ||
|
||
@Override | ||
public SourceControllerCountersCount copy() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public int calculate(Game game, Ability sourceAbility, Effect effect) { | ||
int amount = 0; | ||
Player player = game.getPlayer(sourceAbility.getControllerId()); | ||
if (player != null) { | ||
amount = player.getCounters().getCount(counterType); | ||
} | ||
return amount; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "1"; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return counterType.getName() + " you have"; | ||
} | ||
} |