mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 04:22:01 -08:00
* Serpentine Spike - Fixed that the three targets had not to be different.
This commit is contained in:
parent
75162fc7ce
commit
f72ec06ecd
8 changed files with 195 additions and 129 deletions
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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.mageobject;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.filter.predicate.ObjectSourcePlayer;
|
||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.target.Target;
|
||||
|
||||
/**
|
||||
* All targets that are already selected in other target definitions of the
|
||||
* source are omitted To use this predicate you have to set the targetTag of all
|
||||
* targets involved in the card constructor to a unique value (e.g. using 1,2,3
|
||||
* for three targets)
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class AnotherTargetPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<MageObject>> {
|
||||
|
||||
private final int targetTag;
|
||||
|
||||
public AnotherTargetPredicate(int targetTag) {
|
||||
this.targetTag = targetTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ObjectSourcePlayer<MageObject> input, Game game) {
|
||||
StackObject source = game.getStack().getStackObject(input.getSourceId());
|
||||
if (source != null) {
|
||||
for (Target target : source.getStackAbility().getTargets()) {
|
||||
if (target.getTargetTag() > 0 // target is included in the target group to check
|
||||
&& target.getTargetTag() != targetTag // it's not the target of this predicate
|
||||
&& target.getTargets().contains(input.getObject().getId())) { // if the uuid already is used for another target in the group it's no allowed here
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Another target";
|
||||
}
|
||||
}
|
||||
|
|
@ -151,4 +151,8 @@ public interface Target extends Serializable {
|
|||
UUID getAbilityController();
|
||||
|
||||
Player getTargetController(Game game, UUID playerId);
|
||||
|
||||
int getTargetTag();
|
||||
|
||||
void setTargetTag(int tag);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ public abstract class TargetImpl implements Target {
|
|||
protected UUID targetController = null; // if null the ability controller is the targetController
|
||||
protected UUID abilityController = null; // only used if target controller != ability controller
|
||||
|
||||
protected int targetTag; // can be set if other target check is needed (AnotherTargetPredicate)
|
||||
|
||||
@Override
|
||||
public abstract TargetImpl copy();
|
||||
|
||||
|
|
@ -95,6 +97,7 @@ public abstract class TargetImpl implements Target {
|
|||
this.notTarget = target.notTarget;
|
||||
this.targetController = target.targetController;
|
||||
this.abilityController = target.abilityController;
|
||||
this.targetTag = target.targetTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -545,4 +548,20 @@ public abstract class TargetImpl implements Target {
|
|||
return requiredExplicitlySet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTargetTag() {
|
||||
return targetTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is used to be able to check, that another target is slected within the
|
||||
* group of targets of the ability with a target tag > 0.
|
||||
*
|
||||
* @param targetTag
|
||||
*/
|
||||
@Override
|
||||
public void setTargetTag(int targetTag) {
|
||||
this.targetTag = targetTag;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,44 +1,42 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
* 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.target;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.constants.Zone;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -50,7 +48,7 @@ public class TargetPermanent extends TargetObject {
|
|||
public TargetPermanent() {
|
||||
this(1, 1, new FilterPermanent(), false);
|
||||
}
|
||||
|
||||
|
||||
public TargetPermanent(FilterPermanent filter) {
|
||||
this(1, 1, filter, false);
|
||||
}
|
||||
|
|
@ -88,8 +86,8 @@ public class TargetPermanent extends TargetObject {
|
|||
// first for protection from spells or abilities (e.g. protection from colored spells, r1753)
|
||||
// second for protection from sources (e.g. protection from artifacts + equip ability)
|
||||
if (!isNotTarget()) {
|
||||
if (!permanent.canBeTargetedBy(game.getObject(source.getId()), controllerId, game) ||
|
||||
!permanent.canBeTargetedBy(game.getObject(source.getSourceId()), controllerId, game)) {
|
||||
if (!permanent.canBeTargetedBy(game.getObject(source.getId()), controllerId, game)
|
||||
|| !permanent.canBeTargetedBy(game.getObject(source.getSourceId()), controllerId, game)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -117,7 +115,8 @@ public class TargetPermanent extends TargetObject {
|
|||
/**
|
||||
* Checks if there are enough {@link Permanent} that can be chosen.
|
||||
*
|
||||
* Takes into account notTarget parameter, in case it's true doesn't check for protection, shroud etc.
|
||||
* Takes into account notTarget parameter, in case it's true doesn't check
|
||||
* for protection, shroud etc.
|
||||
*
|
||||
* @param sourceId the target event source
|
||||
* @param sourceControllerId controller of the target event source
|
||||
|
|
@ -132,7 +131,7 @@ public class TargetPermanent extends TargetObject {
|
|||
}
|
||||
int count = 0;
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
|
||||
if (!targets.containsKey(permanent.getId())) {
|
||||
if (notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
|
||||
count++;
|
||||
|
|
@ -146,9 +145,10 @@ public class TargetPermanent extends TargetObject {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks if there are enough {@link Permanent} that can be selected. Should not be used
|
||||
* for Ability targets since this does not check for protection, shroud etc.
|
||||
*
|
||||
* Checks if there are enough {@link Permanent} that can be selected. Should
|
||||
* not be used for Ability targets since this does not check for protection,
|
||||
* shroud etc.
|
||||
*
|
||||
* @param sourceControllerId - controller of the select event
|
||||
* @param game
|
||||
* @return - true if enough valid {@link Permanent} exist
|
||||
|
|
@ -162,7 +162,7 @@ public class TargetPermanent extends TargetObject {
|
|||
return true;
|
||||
}
|
||||
int count = 0;
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, game)) {
|
||||
if (!targets.containsKey(permanent.getId())) {
|
||||
count++;
|
||||
if (count >= remainingTargets) {
|
||||
|
|
@ -177,7 +177,7 @@ public class TargetPermanent extends TargetObject {
|
|||
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<>();
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
|
||||
if (!targets.containsKey(permanent.getId())) {
|
||||
if (notTarget || permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
|
|
@ -190,7 +190,7 @@ public class TargetPermanent extends TargetObject {
|
|||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<>();
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, game)) {
|
||||
if (!targets.containsKey(permanent.getId())) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue