Merge pull request #80 from magefree/master

merge
This commit is contained in:
theelk801 2017-09-23 17:30:43 -04:00 committed by GitHub
commit dafd75e1ab
50 changed files with 1118 additions and 505 deletions

View file

@ -40,6 +40,7 @@ import mage.abilities.effects.Effects;
import mage.constants.AbilityType;
import mage.constants.AbilityWord;
import mage.constants.EffectType;
import mage.constants.TargetAdjustment;
import mage.constants.Zone;
import mage.game.Controllable;
import mage.game.Game;
@ -539,4 +540,8 @@ public interface Ability extends Controllable, Serializable {
void setCanFizzle(boolean canFizzle);
boolean canFizzle();
void setTargetAdjustment(TargetAdjustment targetAdjustment);
TargetAdjustment getTargetAdjustment();
}

View file

@ -99,6 +99,7 @@ public abstract class AbilityImpl implements Ability {
protected List<Watcher> watchers = null;
protected List<Ability> subAbilities = null;
protected boolean canFizzle = true;
protected TargetAdjustment targetAdjustment = TargetAdjustment.NONE;
public AbilityImpl(AbilityType abilityType, Zone zone) {
this.id = UUID.randomUUID();
@ -147,6 +148,7 @@ public abstract class AbilityImpl implements Ability {
this.sourceObject = ability.sourceObject;
this.sourceObjectZoneChangeCounter = ability.sourceObjectZoneChangeCounter;
this.canFizzle = ability.canFizzle;
this.targetAdjustment = ability.targetAdjustment;
}
@Override
@ -1233,4 +1235,13 @@ public abstract class AbilityImpl implements Ability {
this.canFizzle = canFizzle;
}
@Override
public void setTargetAdjustment(TargetAdjustment targetAdjustment) {
this.targetAdjustment = targetAdjustment;
}
@Override
public TargetAdjustment getTargetAdjustment() {
return targetAdjustment;
}
}

View file

@ -71,6 +71,6 @@ public class ConditionalActivatedAbility extends ActivatedAbilityImpl {
if (ruleText != null && !ruleText.isEmpty()) {
return ruleText;
}
return super.getRule() + " Activate this ability only " + condition.toString();
return super.getRule() + " Activate this ability only " + condition.toString() + ".";
}
}

View file

@ -37,17 +37,32 @@ import mage.MageObjectImpl;
import mage.Mana;
import mage.ObjectColor;
import mage.abilities.*;
import mage.abilities.effects.common.NameACardEffect;
import mage.abilities.mana.ActivatedManaAbilityImpl;
import mage.cards.repository.PluginClassloaderRegistery;
import mage.constants.*;
import mage.counters.Counter;
import mage.counters.CounterType;
import mage.counters.Counters;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.FilterSpell;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.ColorPredicate;
import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.filter.predicate.mageobject.PowerPredicate;
import mage.game.*;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.target.TargetCard;
import mage.target.TargetPermanent;
import mage.target.TargetSpell;
import mage.target.common.TargetCardInOpponentsGraveyard;
import mage.target.common.TargetCreaturePermanent;
import mage.util.GameLog;
import mage.util.SubTypeList;
import mage.watchers.Watcher;
@ -317,6 +332,94 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
return spellAbility;
}
// @Override
// public void adjustCosts(Ability ability, Game game) {
// }
@Override
public void adjustTargets(Ability ability, Game game) {
int xValue;
TargetPermanent oldTargetPermanent;
FilterPermanent permanentFilter;
int minTargets;
int maxTargets;
switch (ability.getTargetAdjustment()) {
case NONE:
break;
case X_CMC_EQUAL_PERM:
xValue = ability.getManaCostsToPay().getX();
oldTargetPermanent = (TargetPermanent) ability.getTargets().get(0);
minTargets = oldTargetPermanent.getMinNumberOfTargets();
maxTargets = oldTargetPermanent.getMaxNumberOfTargets();
permanentFilter = oldTargetPermanent.getFilter().copy();
permanentFilter.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue));
ability.getTargets().clear();
ability.getTargets().add(new TargetPermanent(minTargets, maxTargets, permanentFilter, false));
break;
case X_TARGETS:
xValue = ability.getManaCostsToPay().getX();
permanentFilter = ((TargetPermanent) ability.getTargets().get(0)).getFilter();
ability.getTargets().clear();
ability.addTarget(new TargetPermanent(xValue, permanentFilter));
break;
case X_POWER_LEQ:// Minamo Sightbender only
xValue = ability.getManaCostsToPay().getX();
oldTargetPermanent = (TargetPermanent) ability.getTargets().get(0);
minTargets = oldTargetPermanent.getMinNumberOfTargets();
maxTargets = oldTargetPermanent.getMaxNumberOfTargets();
permanentFilter = oldTargetPermanent.getFilter().copy();
permanentFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, xValue + 1));
ability.getTargets().clear();
ability.getTargets().add(new TargetPermanent(minTargets, maxTargets, permanentFilter, false));
break;
case VERSE_COUNTER_TARGETS:
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(ability.getSourceId());
if (sourcePermanent != null) {
xValue = sourcePermanent.getCounters(game).getCount(CounterType.VERSE);
permanentFilter = ((TargetPermanent) ability.getTargets().get(0)).getFilter();
ability.getTargets().clear();
ability.addTarget(new TargetPermanent(0, xValue, permanentFilter, false));
}
break;
case X_CMC_EQUAL_GY_CARD: //Geth, Lord of the Vault only
xValue = ability.getManaCostsToPay().getX();
TargetCard oldTarget = (TargetCard) ability.getTargets().get(0);
FilterCard filterCard = oldTarget.getFilter().copy();
filterCard.add(new ConvertedManaCostPredicate(ComparisonType.EQUAL_TO, xValue));
ability.getTargets().clear();
ability.getTargets().add(new TargetCardInOpponentsGraveyard(filterCard));
break;
case CHOSEN_NAME: //Declaration of Naught only
ability.getTargets().clear();
FilterSpell filterSpell = new FilterSpell("spell with the chosen name");
filterSpell.add(new NamePredicate((String) game.getState().getValue(ability.getSourceId().toString() + NameACardEffect.INFO_KEY)));
TargetSpell target = new TargetSpell(1, filterSpell);
ability.addTarget(target);
break;
case CHOSEN_COLOR: //Pentarch Paladin only
ObjectColor chosenColor = (ObjectColor) game.getState().getValue(ability.getSourceId() + "_color");
ability.getTargets().clear();
FilterPermanent filter = new FilterPermanent("permanent of the chosen color.");
if (chosenColor != null) {
filter.add(new ColorPredicate(chosenColor));
} else {
filter.add(new ConvertedManaCostPredicate(ComparisonType.FEWER_THAN, -5));// Pretty sure this is always false
}
oldTargetPermanent = new TargetPermanent(filter);
ability.addTarget(oldTargetPermanent);
break;
case TREASURE_COUNTER_POWER: //Legacy's Allure only
sourcePermanent = game.getPermanentOrLKIBattlefield(ability.getSourceId());
if (sourcePermanent != null) {
xValue = sourcePermanent.getCounters(game).getCount(CounterType.TREASURE);
FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creature with power less than or equal to the number of treasure counters on {this}");
filter2.add(new PowerPredicate(ComparisonType.FEWER_THAN, xValue + 1));
ability.getTargets().clear();
ability.getTargets().add(new TargetCreaturePermanent(filter2));
}
break;
}
}
@Override
public void setOwnerId(UUID ownerId) {
this.ownerId = ownerId;

View file

@ -0,0 +1,16 @@
package mage.constants;
/**
*
* @author TheElk801
*/
public enum TargetAdjustment {
NONE,
X_TARGETS,
X_CMC_EQUAL_PERM,
X_CMC_EQUAL_GY_CARD,
X_POWER_LEQ, CHOSEN_NAME,
CHOSEN_COLOR,
VERSE_COUNTER_TARGETS,
TREASURE_COUNTER_POWER
}

View file

@ -122,6 +122,7 @@ public enum CounterType {
TIME("time"),
TOWER("tower"),
TRAP("trap"),
TREASURE("treasure"),
UNITY("unity"),
VELOCITY("velocity"),
VERSE("verse"),

View file

@ -0,0 +1,50 @@
/*
* 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.filter.predicate.permanent;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author North
*/
public class DefendingPlayerControlsPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>> {
@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return input.getObject().getControllerId().equals(game.getCombat().getDefenderId(input.getSourceId()));
}
@Override
public String toString() {
return "Another";
}
}

View file

@ -0,0 +1,50 @@
/*
* 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.filter.predicate.permanent;
import mage.cards.Card;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
/**
*
* @author North
*/
public class DefendingPlayerOwnsCardPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Card>> {
@Override
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
return input.getObject().getOwnerId().equals(game.getCombat().getDefenderId(input.getSourceId()));
}
@Override
public String toString() {
return "Another";
}
}

View file

@ -74,6 +74,7 @@ public class StackAbility extends StackObjImpl implements Ability {
private UUID controllerId;
private String name;
private String expansionSetCode;
private TargetAdjustment targetAdjustment = TargetAdjustment.NONE;
public StackAbility(Ability ability, UUID controllerId) {
this.ability = ability;
@ -86,6 +87,7 @@ public class StackAbility extends StackObjImpl implements Ability {
this.controllerId = stackAbility.controllerId;
this.name = stackAbility.name;
this.expansionSetCode = stackAbility.expansionSetCode;
this.targetAdjustment = stackAbility.targetAdjustment;
}
@Override
@ -537,7 +539,7 @@ public class StackAbility extends StackObjImpl implements Ability {
@Override
public int getSourceObjectZoneChangeCounter() {
throw new UnsupportedOperationException("Not supported.");
return ability.getSourceObjectZoneChangeCounter();
}
@Override
@ -612,4 +614,13 @@ public class StackAbility extends StackObjImpl implements Ability {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setTargetAdjustment(TargetAdjustment targetAdjustment) {
this.targetAdjustment = targetAdjustment;
}
@Override
public TargetAdjustment getTargetAdjustment() {
return targetAdjustment;
}
}

View file

@ -53,8 +53,7 @@ public interface Target extends Serializable {
boolean isNotTarget();
/**
* controls if it will be checked, if the target can be targeted from
* source
* controls if it will be checked, if the target can be targeted from source
*
* @param notTarget true = do not check for protection, false = check for
* protection
@ -113,6 +112,8 @@ public interface Target extends Serializable {
int getNumberOfTargets();
int getMinNumberOfTargets();
int getMaxNumberOfTargets();
void setMinNumberOfTargets(int minNumberofTargets);
@ -157,8 +158,8 @@ public interface Target extends Serializable {
void setTargetTag(int tag);
Target getOriginalTarget();
// used for cards like Spellskite
void setTargetAmount(UUID targetId, int amount, Game game);
}

View file

@ -105,6 +105,11 @@ public abstract class TargetImpl implements Target {
return this.minNumberOfTargets;
}
@Override
public int getMinNumberOfTargets() {
return this.minNumberOfTargets;
}
@Override
public int getMaxNumberOfTargets() {
return this.maxNumberOfTargets;