put comparing logic in counttype, remove all switches

This commit is contained in:
ingmargoudt 2017-03-06 11:46:22 +01:00
parent 0adc715499
commit 3d029d6ad5
8 changed files with 66 additions and 145 deletions

View file

@ -53,13 +53,12 @@ import mage.players.Player;
import mage.target.common.TargetOpponent;
/**
*
* @author LevelX2
*/
public class NezumiShortfang extends CardImpl {
public NezumiShortfang(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{B}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{B}");
this.subtype.add("Rat");
this.subtype.add("Rogue");
@ -73,9 +72,9 @@ public class NezumiShortfang extends CardImpl {
ability.addCost(new TapSourceCost());
ability.addTarget(new TargetOpponent());
ability.addEffect(new ConditionalOneShotEffect(
new FlipSourceEffect(new StabwhiskerTheOdious()),
new CardsInTargetOpponentHandCondition(CountType.FEWER_THAN, 1),
"Then if that player has no cards in hand, flip {this}"));
new FlipSourceEffect(new StabwhiskerTheOdious()),
new CardsInTargetOpponentHandCondition(CountType.FEWER_THAN, 1),
"Then if that player has no cards in hand, flip {this}"));
this.addAbility(ability);
}
@ -128,7 +127,7 @@ class StabwhiskerLoseLifeEffect extends OneShotEffect {
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (opponent != null) {
int lifeLose = 3 - opponent.getHand().size();
if (lifeLose > 0 ) {
if (lifeLose > 0) {
opponent.loseLife(lifeLose, game, false);
}
return true;
@ -143,16 +142,16 @@ class CardsInTargetOpponentHandCondition implements Condition {
private CountType type;
private int count;
public CardsInTargetOpponentHandCondition() {
this(CountType.EQUAL_TO, 0);
}
public CardsInTargetOpponentHandCondition() {
this(CountType.EQUAL_TO, 0);
}
public CardsInTargetOpponentHandCondition (CountType type, int count ) {
public CardsInTargetOpponentHandCondition(CountType type, int count) {
this.type = type;
this.count = count;
}
public CardsInTargetOpponentHandCondition (CountType type, int count, Condition conditionToDecorate ) {
public CardsInTargetOpponentHandCondition(CountType type, int count, Condition conditionToDecorate) {
this(type, count);
this.condition = conditionToDecorate;
}
@ -164,20 +163,10 @@ class CardsInTargetOpponentHandCondition implements Condition {
if (opponent == null) {
return false;
}
switch ( this.type ) {
case FEWER_THAN:
conditionApplies = opponent.getHand().size() < this.count;
break;
case MORE_THAN:
conditionApplies = opponent.getHand().size() > this.count;
break;
case EQUAL_TO:
conditionApplies = opponent.getHand().size() == this.count;
break;
}
conditionApplies = CountType.compare(opponent.getHand().size(), type, count);
//If a decorated condition exists, check it as well and apply them together.
if ( this.condition != null ) {
if (this.condition != null) {
conditionApplies = conditionApplies && this.condition.apply(game, source);
}