mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Refactor OpponentsLostLifeCount to enum
This commit is contained in:
parent
ccba9b2e5a
commit
283b101a08
6 changed files with 26 additions and 34 deletions
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.cards.c;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.EntersBattlefieldAbility;
|
||||
|
@ -11,14 +9,15 @@ import mage.abilities.keyword.TrampleAbility;
|
|||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class CryptbornHorror extends CardImpl {
|
||||
|
@ -26,7 +25,7 @@ public final class CryptbornHorror extends CardImpl {
|
|||
private static final String rule = "with X +1/+1 counters on it, where X is the total life lost by your opponents this turn";
|
||||
|
||||
public CryptbornHorror(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{B/R}{B/R}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{B/R}{B/R}");
|
||||
this.subtype.add(SubType.HORROR);
|
||||
this.color.setBlack(true);
|
||||
this.color.setRed(true);
|
||||
|
@ -64,7 +63,7 @@ class CryptbornHorrorEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanentEntering(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
int oll = new OpponentsLostLifeCount().calculate(game, source, this);
|
||||
int oll = OpponentsLostLifeCount.instance.calculate(game, source, this);
|
||||
if (oll > 0) {
|
||||
permanent.addCounters(CounterType.P1P1.createInstance(oll), source, game);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.cards.n;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
|
@ -18,8 +16,9 @@ import mage.constants.TargetController;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author spjspj
|
||||
*/
|
||||
public final class NehebTheEternal extends CardImpl {
|
||||
|
@ -74,7 +73,7 @@ class NehebTheEternalManaEffect extends ManaEffect {
|
|||
|
||||
@Override
|
||||
public Mana produceMana(boolean netMana, Game game, Ability source) {
|
||||
return Mana.RedMana(new OpponentsLostLifeCount().calculate(game, source, this));
|
||||
return Mana.RedMana(OpponentsLostLifeCount.instance.calculate(game, source, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.cards.r;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.SpellAbility;
|
||||
|
@ -20,8 +18,9 @@ import mage.game.events.GameEvent.EventType;
|
|||
import mage.game.stack.Spell;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class RakdosLordOfRiots extends CardImpl {
|
||||
|
@ -84,9 +83,7 @@ class RakdosLordOfRiotsCantCastEffect extends ContinuousRuleModifyingEffectImpl
|
|||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (event.getSourceId().equals(source.getSourceId())) {
|
||||
if (new OpponentsLostLifeCount().calculate(game, source, this) == 0) {
|
||||
return true;
|
||||
}
|
||||
return OpponentsLostLifeCount.instance.calculate(game, source, this) == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -107,8 +104,7 @@ class RakdosLordOfRiotsCostReductionEffect extends CostModificationEffectImpl {
|
|||
public boolean apply(Game game, Ability source, Ability abilityToModify) {
|
||||
Ability spellAbility = abilityToModify;
|
||||
if (spellAbility != null) {
|
||||
OpponentsLostLifeCount dynamicValue = new OpponentsLostLifeCount();
|
||||
int amount = dynamicValue.calculate(game, source, this);
|
||||
int amount = OpponentsLostLifeCount.instance.calculate(game, source, this);
|
||||
if (amount > 0) {
|
||||
CardUtil.reduceCost(spellAbility, amount);
|
||||
return true;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.cards.s;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.EntersBattlefieldAbility;
|
||||
|
@ -11,14 +9,15 @@ import mage.abilities.keyword.MenaceAbility;
|
|||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public final class SithLord extends CardImpl {
|
||||
|
@ -26,7 +25,7 @@ public final class SithLord extends CardImpl {
|
|||
private static final String rule = "with X +1/+1 counters on it, where X is the total life lost by your opponents this turn";
|
||||
|
||||
public SithLord(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{B}{B}");
|
||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}{B}");
|
||||
this.subtype.add(SubType.HUMAN);
|
||||
this.subtype.add(SubType.SITH);
|
||||
this.power = new MageInt(2);
|
||||
|
@ -62,7 +61,7 @@ public final class SithLord extends CardImpl {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanentEntering(source.getSourceId());
|
||||
if (permanent != null) {
|
||||
int oll = new OpponentsLostLifeCount().calculate(game, source, this);
|
||||
int oll = OpponentsLostLifeCount.instance.calculate(game, source, this);
|
||||
if (oll > 0) {
|
||||
permanent.addCounters(CounterType.P1P1.createInstance(oll), source, game);
|
||||
}
|
||||
|
@ -76,5 +75,5 @@ public final class SithLord extends CardImpl {
|
|||
return new SithLordEffect(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
|
||||
package mage.abilities.dynamicvalue.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.PlayerLostLifeWatcher;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class OpponentsLostLifeCount implements DynamicValue {
|
||||
public enum OpponentsLostLifeCount implements DynamicValue {
|
||||
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
|
@ -29,7 +30,7 @@ public class OpponentsLostLifeCount implements DynamicValue {
|
|||
|
||||
@Override
|
||||
public OpponentsLostLifeCount copy() {
|
||||
return new OpponentsLostLifeCount();
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
|
||||
package mage.abilities.keyword;
|
||||
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.dynamicvalue.common.OpponentsLostLifeCount;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.SpellAbilityType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.PlayerLostLifeWatcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
@ -40,8 +39,7 @@ public class SpectacleAbility extends SpellAbility {
|
|||
|
||||
@Override
|
||||
public ActivationStatus canActivate(UUID playerId, Game game) {
|
||||
PlayerLostLifeWatcher watcher = game.getState().getWatcher(PlayerLostLifeWatcher.class);
|
||||
if (watcher != null && watcher.getAllOppLifeLost(playerId, game) > 0) {
|
||||
if (OpponentsLostLifeCount.instance.calculate(game, playerId) > 0) {
|
||||
return super.canActivate(playerId, game);
|
||||
}
|
||||
return ActivationStatus.getFalse();
|
||||
|
|
Loading…
Reference in a new issue