mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Merge pull request #2930 from ingmargoudt/master
put comparing logic in counttype, remove all switches
This commit is contained in:
commit
26fc9161d4
8 changed files with 66 additions and 145 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,4 +5,18 @@ package mage.abilities;
|
|||
*/
|
||||
public enum CountType {
|
||||
MORE_THAN, FEWER_THAN, EQUAL_TO;
|
||||
|
||||
|
||||
public static boolean compare(int source, CountType comparison, int target){
|
||||
switch (comparison){
|
||||
case MORE_THAN:
|
||||
return source > target;
|
||||
case FEWER_THAN:
|
||||
return source < target;
|
||||
case EQUAL_TO:
|
||||
return source == target;
|
||||
default:
|
||||
throw new IllegalArgumentException("comparison rules for "+comparison + " missing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import mage.game.Game;
|
|||
@FunctionalInterface
|
||||
public interface Condition extends Serializable {
|
||||
|
||||
public enum ComparisonType {
|
||||
enum ComparisonType {
|
||||
|
||||
GreaterThan(">"),
|
||||
Equal("=="),
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.CountType;
|
||||
import mage.abilities.condition.Condition;
|
||||
|
@ -40,7 +41,6 @@ import mage.util.CardUtil;
|
|||
* Cards in controller hand condition. This condition can decorate other
|
||||
* conditions as well as be used standalone.
|
||||
*
|
||||
*
|
||||
* @author LevelX
|
||||
*/
|
||||
public class CardsInHandCondition implements Condition {
|
||||
|
@ -77,70 +77,24 @@ public class CardsInHandCondition implements Condition {
|
|||
if (controller != null) {
|
||||
switch (targetController) {
|
||||
case YOU:
|
||||
switch (this.type) {
|
||||
case FEWER_THAN:
|
||||
conditionApplies = game.getPlayer(source.getControllerId()).getHand().size() < this.count;
|
||||
break;
|
||||
case MORE_THAN:
|
||||
conditionApplies = game.getPlayer(source.getControllerId()).getHand().size() > this.count;
|
||||
break;
|
||||
case EQUAL_TO:
|
||||
conditionApplies = game.getPlayer(source.getControllerId()).getHand().size() == this.count;
|
||||
break;
|
||||
}
|
||||
conditionApplies = CountType.compare(game.getPlayer(source.getControllerId()).getHand().size(), type, count);
|
||||
break;
|
||||
case ACTIVE:
|
||||
Player player = game.getPlayer(game.getActivePlayerId());
|
||||
if (player != null) {
|
||||
switch (this.type) {
|
||||
case FEWER_THAN:
|
||||
conditionApplies = player.getHand().size() < this.count;
|
||||
break;
|
||||
case MORE_THAN:
|
||||
conditionApplies = player.getHand().size() > this.count;
|
||||
break;
|
||||
case EQUAL_TO:
|
||||
conditionApplies = player.getHand().size() == this.count;
|
||||
break;
|
||||
}
|
||||
conditionApplies = CountType.compare(player.getHand().size(), type, count);
|
||||
}
|
||||
break;
|
||||
case ANY:
|
||||
boolean conflict = false;
|
||||
switch (this.type) {
|
||||
case FEWER_THAN:
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
if (player.getHand().size() >= this.count) {
|
||||
conflict = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
if (!CountType.compare(player.getHand().size(), type, this.count)) {
|
||||
conflict = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case MORE_THAN:
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
if (player.getHand().size() <= this.count) {
|
||||
conflict = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EQUAL_TO:
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
if (player.getHand().size() != this.count) {
|
||||
conflict = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
conditionApplies = !conflict;
|
||||
break;
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.CountType;
|
||||
import mage.abilities.condition.Condition;
|
||||
|
@ -39,7 +40,7 @@ import mage.game.Game;
|
|||
/**
|
||||
* Checks if one opponent (each opponent is checked on its own) fulfills
|
||||
* the defined condition of controlling the defined number of permanents.
|
||||
*
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
|
@ -66,7 +67,7 @@ public class OpponentControlsPermanentCondition implements Condition {
|
|||
* @param type
|
||||
* @param count
|
||||
*/
|
||||
public OpponentControlsPermanentCondition ( FilterPermanent filter, CountType type, int count ) {
|
||||
public OpponentControlsPermanentCondition(FilterPermanent filter, CountType type, int count) {
|
||||
this.filter = filter;
|
||||
this.type = type;
|
||||
this.count = count;
|
||||
|
@ -74,30 +75,16 @@ public class OpponentControlsPermanentCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
boolean conditionApplies = false;
|
||||
for(UUID opponentId :game.getOpponents(source.getControllerId())) {
|
||||
boolean conditionApplies = false;
|
||||
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
|
||||
FilterPermanent localFilter = filter.copy();
|
||||
localFilter.add(new ControllerIdPredicate(opponentId));
|
||||
switch ( this.type ) {
|
||||
case FEWER_THAN:
|
||||
if (game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) < this.count) {
|
||||
conditionApplies = true;
|
||||
break;
|
||||
}
|
||||
case MORE_THAN:
|
||||
if (game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) > this.count) {
|
||||
conditionApplies = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case EQUAL_TO:
|
||||
if (game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) == this.count) {
|
||||
conditionApplies = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
if (CountType.compare(game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game), type, this.count)) {
|
||||
conditionApplies = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
return conditionApplies;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public class PermanentHasCounterCondition implements Condition {
|
|||
private CounterType counterType;
|
||||
private int amount;
|
||||
private FilterPermanent filter;
|
||||
private CountType type;
|
||||
private CountType counttype;
|
||||
private boolean anyPlayer;
|
||||
|
||||
public PermanentHasCounterCondition(CounterType counterType, int amount, FilterPermanent filter) {
|
||||
|
@ -59,7 +59,7 @@ public class PermanentHasCounterCondition implements Condition {
|
|||
this.counterType = counterType;
|
||||
this.amount = amount;
|
||||
this.filter = filter;
|
||||
this.type = type;
|
||||
this.counttype = type;
|
||||
this.anyPlayer = false;
|
||||
}
|
||||
|
||||
|
@ -67,32 +67,19 @@ public class PermanentHasCounterCondition implements Condition {
|
|||
this.counterType = counterType;
|
||||
this.amount = amount;
|
||||
this.filter = filter;
|
||||
this.type = type;
|
||||
this.counttype = type;
|
||||
this.anyPlayer = any;
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
List<Permanent> permanents = game.getBattlefield().getActivePermanents(this.filter, source.getControllerId(), game);
|
||||
if(this.anyPlayer == true) {
|
||||
if(this.anyPlayer) {
|
||||
permanents = game.getBattlefield().getAllActivePermanents(this.filter, game);
|
||||
}
|
||||
for (Permanent permanent : permanents) {
|
||||
switch (this.type) {
|
||||
case FEWER_THAN:
|
||||
if (permanent.getCounters(game).getCount(this.counterType) < this.amount) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case MORE_THAN:
|
||||
if (permanent.getCounters(game).getCount(this.counterType) > this.amount) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case EQUAL_TO:
|
||||
if (permanent.getCounters(game).getCount(this.counterType) == this.amount) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
if(CountType.compare(permanent.getCounters(game).getCount(this.counterType), counttype, this.amount))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -38,11 +38,10 @@ import mage.game.Game;
|
|||
* Battlefield checking condition. This condition can decorate other conditions
|
||||
* as well as be used standalone.
|
||||
*
|
||||
* @see #Controls(mage.filter.Filter)
|
||||
* @see #Controls(mage.filter.Filter, mage.abilities.condition.Condition)
|
||||
*
|
||||
* @author nantuko
|
||||
* @author maurer.it_at_gmail.com
|
||||
* @see #Controls(mage.filter.Filter)
|
||||
* @see #Controls(mage.filter.Filter, mage.abilities.condition.Condition)
|
||||
*/
|
||||
public class PermanentsOnTheBattlefieldCondition implements Condition {
|
||||
|
||||
|
@ -56,7 +55,7 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
|
|||
* Applies a filter and delegates creation to
|
||||
* {@link #ControlsPermanent(mage.filter.FilterPermanent, mage.abilities.condition.common.ControlsPermanent.CountType, int)}
|
||||
* with {@link CountType#MORE_THAN}, and 0.
|
||||
*
|
||||
*
|
||||
* @param filter
|
||||
*/
|
||||
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter) {
|
||||
|
@ -72,14 +71,14 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
|
|||
* @param type
|
||||
* @param count
|
||||
*/
|
||||
public PermanentsOnTheBattlefieldCondition ( FilterPermanent filter, CountType type, int count ) {
|
||||
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter, CountType type, int count) {
|
||||
this(filter, type, count, true);
|
||||
}
|
||||
|
||||
public PermanentsOnTheBattlefieldCondition ( FilterPermanent filter, CountType type, int count, boolean onlyControlled ) {
|
||||
|
||||
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter, CountType type, int count, boolean onlyControlled) {
|
||||
this.filter = filter;
|
||||
this.type = type;
|
||||
this.count = count;
|
||||
this.count = count;
|
||||
this.onlyControlled = onlyControlled;
|
||||
}
|
||||
|
||||
|
@ -94,7 +93,7 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
|
|||
* @param count
|
||||
* @param conditionToDecorate
|
||||
*/
|
||||
public PermanentsOnTheBattlefieldCondition ( FilterPermanent filter, CountType type, int count, Condition conditionToDecorate ) {
|
||||
public PermanentsOnTheBattlefieldCondition(FilterPermanent filter, CountType type, int count, Condition conditionToDecorate) {
|
||||
this(filter, type, count);
|
||||
this.condition = conditionToDecorate;
|
||||
}
|
||||
|
@ -108,20 +107,11 @@ public class PermanentsOnTheBattlefieldCondition implements Condition {
|
|||
localFilter.add(new ControllerIdPredicate(source.getControllerId()));
|
||||
}
|
||||
|
||||
switch ( this.type ) {
|
||||
case FEWER_THAN:
|
||||
conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) < this.count;
|
||||
break;
|
||||
case MORE_THAN:
|
||||
conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) > this.count;
|
||||
break;
|
||||
case EQUAL_TO:
|
||||
conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) == this.count;
|
||||
break;
|
||||
}
|
||||
int permanentsOnBattlefield = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game);
|
||||
conditionApplies = CountType.compare(permanentsOnBattlefield, 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ import mage.players.PlayerList;
|
|||
*/
|
||||
public class TenOrLessLifeCondition implements Condition {
|
||||
|
||||
public static enum CheckType { AN_OPPONENT, CONTROLLER, TARGET_OPPONENT, EACH_PLAYER }
|
||||
public enum CheckType { AN_OPPONENT, CONTROLLER, TARGET_OPPONENT, EACH_PLAYER }
|
||||
|
||||
private final CheckType type;
|
||||
|
||||
|
|
Loading…
Reference in a new issue