mirror of
https://github.com/correl/mage.git
synced 2025-01-13 11:01:58 +00:00
Added CompoundCondition, AttachedToTappedCondition and EquipmentAttachedCondition.
This commit is contained in:
parent
176c2a76b4
commit
b7c45a7090
9 changed files with 202 additions and 12 deletions
71
Mage/src/mage/abilities/condition/CompoundCondition.java
Normal file
71
Mage/src/mage/abilities/condition/CompoundCondition.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.abilities.condition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* Combines conditions to one compound conditon, all single conditons
|
||||
* must be true to return true for the compound condtion.
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class CompoundCondition implements Condition {
|
||||
|
||||
private final ArrayList<Condition> conditions = new ArrayList();
|
||||
private final String text;
|
||||
|
||||
public CompoundCondition(Condition... conditions) {
|
||||
this("", conditions);
|
||||
}
|
||||
|
||||
public CompoundCondition(String text, Condition... conditions) {
|
||||
this.conditions.addAll(Arrays.asList(conditions));
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (Condition condition: conditions) {
|
||||
if (!condition.apply(game, source)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
|
@ -39,7 +39,7 @@ import mage.game.permanent.Permanent;
|
|||
*/
|
||||
public class AttachedToCounterCondition implements Condition {
|
||||
|
||||
private CounterType counterType;
|
||||
private final CounterType counterType;
|
||||
private int amount = 1;
|
||||
private int from = -1;
|
||||
private int to;
|
||||
|
@ -61,11 +61,11 @@ public class AttachedToCounterCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
if (permanent == null || permanent.getAttachedTo() == null) {
|
||||
Permanent attachment = game.getPermanent(source.getSourceId());
|
||||
if (attachment == null || attachment.getAttachedTo() == null) {
|
||||
return false;
|
||||
}
|
||||
Permanent attachedTo = game.getPermanent(permanent.getAttachedTo());
|
||||
Permanent attachedTo = game.getPermanent(attachment.getAttachedTo());
|
||||
if (attachedTo == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class AttachedToTappedCondition implements Condition {
|
||||
|
||||
private static final AttachedToTappedCondition fInstance = new AttachedToTappedCondition();
|
||||
|
||||
public static AttachedToTappedCondition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent attachment = game.getPermanent(source.getSourceId());
|
||||
if (attachment == null || attachment.getAttachedTo() == null) {
|
||||
return false;
|
||||
}
|
||||
Permanent attachedTo = game.getPermanent(attachment.getAttachedTo());
|
||||
if (attachedTo == null) {
|
||||
return false;
|
||||
}
|
||||
return attachedTo.isTapped();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
* Describes condition when Equipment is attached to an object
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class EquipmentAttachedCondition implements Condition {
|
||||
|
||||
private static final EquipmentAttachedCondition fInstance = new EquipmentAttachedCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent attachment = game.getPermanent(source.getSourceId());
|
||||
return attachment == null || attachment.getAttachedTo() == null;
|
||||
}
|
||||
|
||||
}
|
|
@ -27,13 +27,12 @@
|
|||
*/
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Describes condition when creature is equipped.
|
||||
*
|
||||
|
@ -41,7 +40,7 @@ import java.util.UUID;
|
|||
*/
|
||||
public class EquippedCondition implements Condition {
|
||||
|
||||
private static EquippedCondition fInstance = new EquippedCondition();
|
||||
private static final EquippedCondition fInstance = new EquippedCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
return fInstance;
|
||||
|
@ -53,7 +52,7 @@ public class EquippedCondition implements Condition {
|
|||
if (permanent != null) {
|
||||
for (UUID uuid : permanent.getAttachments()) {
|
||||
Permanent attached = game.getBattlefield().getPermanent(uuid);
|
||||
if (attached.getSubtype().contains("Equipment")) {
|
||||
if (attached != null && attached.getSubtype().contains("Equipment")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ import mage.game.permanent.Permanent;
|
|||
|
||||
public class SourceTappedCondition implements Condition {
|
||||
|
||||
private static SourceTappedCondition fInstance = new SourceTappedCondition();
|
||||
private static final SourceTappedCondition fInstance = new SourceTappedCondition();
|
||||
|
||||
public static Condition getInstance() {
|
||||
public static SourceTappedCondition getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public class BecomesBasicLandTargetEffect extends ContinuousEffectImpl<BecomesBa
|
|||
|
||||
public BecomesBasicLandTargetEffect(Duration duration, boolean chooseLandType, String... landNames) {
|
||||
super(duration, Outcome.Detriment);
|
||||
landTypes.addAll(Arrays.asList(landNames));
|
||||
this.landTypes.addAll(Arrays.asList(landNames));
|
||||
this.chooseLandType = chooseLandType;
|
||||
this.staticText = setText();
|
||||
|
||||
|
|
|
@ -77,7 +77,12 @@ public class BoostControlledEffect extends ContinuousEffectImpl<BoostControlledE
|
|||
}
|
||||
|
||||
/**
|
||||
* @param power
|
||||
* @param toughness
|
||||
* @param duration
|
||||
* @param filter
|
||||
* @param lockedIn if true, power and toughness will be calculated only once, when the ability resolves
|
||||
* @param excludeSource
|
||||
*/
|
||||
public BoostControlledEffect(DynamicValue power, DynamicValue toughness, Duration duration, FilterCreaturePermanent filter, boolean excludeSource, boolean lockedIn) {
|
||||
super(duration, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature);
|
||||
|
|
|
@ -436,7 +436,7 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
public Permanent getPermanent(UUID permanentId) {
|
||||
if (permanentId != null && battlefield.containsPermanent(permanentId)) {
|
||||
Permanent permanent = battlefield.getPermanent(permanentId);
|
||||
setZone(permanent.getId(), Zone.BATTLEFIELD);
|
||||
setZone(permanent.getId(), Zone.BATTLEFIELD); // shouldn't this be set anyway? (LevelX2)
|
||||
return permanent;
|
||||
}
|
||||
return null;
|
||||
|
|
Loading…
Reference in a new issue