Skip to content

Commit

Permalink
refactor together experience counter DynamicValue
Browse files Browse the repository at this point in the history
  • Loading branch information
Susucre committed May 1, 2024
1 parent 8843bd3 commit 74adbf2
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 145 deletions.
45 changes: 9 additions & 36 deletions Mage.Sets/src/mage/cards/k/KalemneDiscipleOfIroas.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package mage.cards.k;

import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.common.SpellCastControllerTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.dynamicvalue.common.SourceControllerCountersCount;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.abilities.effects.common.counter.AddCountersPlayersEffect;
import mage.abilities.keyword.DoubleStrikeAbility;
Expand All @@ -16,8 +14,6 @@
import mage.counters.CounterType;
import mage.filter.FilterSpell;
import mage.filter.predicate.mageobject.ManaValuePredicate;
import mage.game.Game;
import mage.players.Player;

import java.util.UUID;

Expand Down Expand Up @@ -53,8 +49,13 @@ public KalemneDiscipleOfIroas(UUID ownerId, CardSetInfo setInfo) {
), filterSpell, false));

// Kalemne, Disciple of Iroas gets +1/+1 for each experience counter you have.
DynamicValue value = new SourceControllerExperienceCountersCount();
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostSourceEffect(value, value, Duration.WhileOnBattlefield)));
this.addAbility(new SimpleStaticAbility(
new BoostSourceEffect(
SourceControllerCountersCount.EXPERIENCE,
SourceControllerCountersCount.EXPERIENCE,
Duration.WhileOnBattlefield
)
));
}

private KalemneDiscipleOfIroas(final KalemneDiscipleOfIroas card) {
Expand All @@ -65,32 +66,4 @@ private KalemneDiscipleOfIroas(final KalemneDiscipleOfIroas card) {
public KalemneDiscipleOfIroas copy() {
return new KalemneDiscipleOfIroas(this);
}
}

class SourceControllerExperienceCountersCount implements DynamicValue {

@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.EXPERIENCE);
}
return amount;
}

@Override
public SourceControllerExperienceCountersCount copy() {
return new SourceControllerExperienceCountersCount();
}

@Override
public String toString() {
return "1";
}

@Override
public String getMessage() {
return "experience counter you have";
}
}
}
39 changes: 4 additions & 35 deletions Mage.Sets/src/mage/cards/k/KelsienThePlague.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.common.delayed.WhenTargetDiesDelayedTriggeredAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.dynamicvalue.common.SourceControllerCountersCount;
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
Expand All @@ -19,8 +18,6 @@
import mage.constants.*;
import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player;
import mage.target.TargetPermanent;

import java.util.UUID;
Expand All @@ -46,7 +43,8 @@ public KelsienThePlague(UUID ownerId, CardSetInfo setInfo) {

// Kelsien, the Plague gets +1/+1 for each experience counter you have.
this.addAbility(new SimpleStaticAbility(new BoostSourceEffect(
KelsienThePlagueCount.instance, KelsienThePlagueCount.instance,
SourceControllerCountersCount.EXPERIENCE,
SourceControllerCountersCount.EXPERIENCE,
Duration.WhileOnBattlefield
)));

Expand All @@ -67,33 +65,4 @@ private KelsienThePlague(final KelsienThePlague card) {
public KelsienThePlague copy() {
return new KelsienThePlague(this);
}
}

enum KelsienThePlagueCount implements DynamicValue {
instance;

@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.EXPERIENCE);
}
return amount;
}

@Override
public KelsienThePlagueCount copy() {
return instance;
}

@Override
public String toString() {
return "1";
}

@Override
public String getMessage() {
return "experience counter you have";
}
}
}
47 changes: 10 additions & 37 deletions Mage.Sets/src/mage/cards/m/MintharaMercilessSoul.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import mage.abilities.common.BeginningOfEndStepTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.RevoltCondition;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.SourceControllerCountersCount;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostAllEffect;
import mage.abilities.effects.common.counter.AddCountersPlayersEffect;
import mage.abilities.keyword.WardAbility;
Expand All @@ -16,8 +15,6 @@
import mage.constants.*;
import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player;
import mage.watchers.common.RevoltWatcher;

import java.util.UUID;
Expand All @@ -37,8 +34,7 @@ public MintharaMercilessSoul(UUID ownerId, CardSetInfo setInfo) {
this.toughness = new MageInt(2);

// Ward {X}, where X is the number of experience counters you have.
DynamicValue value = new MintharaMercilessSoulCount();
Ability ability = new WardAbility(value, "the number of experience counters you have");
Ability ability = new WardAbility(SourceControllerCountersCount.EXPERIENCE, "the number of experience counters you have");
this.addAbility(ability);

// At the beginning of your end step, if a permanent you controlled left the battlefield this turn, you get an experience counter.
Expand All @@ -48,8 +44,13 @@ public MintharaMercilessSoul(UUID ownerId, CardSetInfo setInfo) {
), new RevoltWatcher());

// Creatures you control get +1/+0 for each experience counter you have.
this.addAbility(new SimpleStaticAbility(new BoostAllEffect(value, StaticValue.get(0),
Duration.WhileOnBattlefield, StaticFilters.FILTER_CONTROLLED_CREATURES, false)));
this.addAbility(new SimpleStaticAbility(new BoostAllEffect(
SourceControllerCountersCount.EXPERIENCE,
StaticValue.get(0),
Duration.WhileOnBattlefield,
StaticFilters.FILTER_CONTROLLED_CREATURES,
false
)));
}

private MintharaMercilessSoul(final MintharaMercilessSoul card) {
Expand All @@ -60,32 +61,4 @@ private MintharaMercilessSoul(final MintharaMercilessSoul card) {
public MintharaMercilessSoul copy() {
return new MintharaMercilessSoul(this);
}
}

class MintharaMercilessSoulCount implements DynamicValue {

@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.EXPERIENCE);
}
return amount;
}

@Override
public MintharaMercilessSoulCount copy() {
return new MintharaMercilessSoulCount();
}

@Override
public String toString() {
return "1";
}

@Override
public String getMessage() {
return "experience counter you have";
}
}
}
45 changes: 8 additions & 37 deletions Mage.Sets/src/mage/cards/o/OtharriSunsGlory.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapTargetCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.dynamicvalue.common.SourceControllerCountersCount;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlSourceEffect;
import mage.abilities.effects.common.counter.AddCountersPlayersEffect;
Expand All @@ -20,9 +19,7 @@
import mage.counters.CounterType;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.permanent.TappedPredicate;
import mage.game.Game;
import mage.game.permanent.token.RebelRedToken;
import mage.players.Player;
import mage.target.common.TargetControlledPermanent;

import java.util.UUID;
Expand Down Expand Up @@ -56,11 +53,13 @@ public OtharriSunsGlory(UUID ownerId, CardSetInfo setInfo) {
// Haste
this.addAbility(HasteAbility.getInstance());

// 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.
// 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.
Ability ability = new AttacksTriggeredAbility(new AddCountersPlayersEffect(CounterType.EXPERIENCE.createInstance(), TargetController.YOU));
DynamicValue value = new OtharriSunsGloryCount();
ability.addEffect(new CreateTokenEffect(new RebelRedToken(), value, true, true).concatBy("Then"));
ability.addEffect(new CreateTokenEffect(
new RebelRedToken(),
SourceControllerCountersCount.EXPERIENCE,
true, true
).concatBy("Then"));
this.addAbility(ability);

// {2}{R}{W}, Tap an untapped Rebel you control: Return Otharri from your graveyard to the battlefield tapped.
Expand All @@ -81,32 +80,4 @@ private OtharriSunsGlory(final OtharriSunsGlory card) {
public OtharriSunsGlory copy() {
return new OtharriSunsGlory(this);
}
}

class OtharriSunsGloryCount implements DynamicValue {

@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.EXPERIENCE);
}
return amount;
}

@Override
public OtharriSunsGloryCount copy() {
return new OtharriSunsGloryCount();
}

@Override
public String toString() {
return "1";
}

@Override
public String getMessage() {
return "experience counter you have";
}
}
}
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);
}
}
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";
}
}

0 comments on commit 74adbf2

Please sign in to comment.