Merge origin/master

This commit is contained in:
LevelX2 2016-08-11 17:41:57 +02:00
commit 318a0745f0
4 changed files with 232 additions and 7 deletions

View file

@ -0,0 +1,158 @@
/*
* 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.sets.arabiannights;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.InvertCondition;
import mage.abilities.condition.common.SourceTappedCondition;
import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
import mage.abilities.effects.Effect;
import mage.abilities.keyword.IndestructibleAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.common.FilterControlledArtifactPermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.abilities.effects.common.continuous.GainAbilityControlledEffect;
import mage.constants.Outcome;
import mage.filter.FilterObject;
import mage.filter.FilterStackObject;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.game.stack.StackObject;
/**
*
* @author spjspj
*/
public class GuardianBeast extends CardImpl {
private static final FilterObject filterAura = new FilterStackObject("auras");
private static final FilterControlledArtifactPermanent filter = new FilterControlledArtifactPermanent("Noncreature artifacts");
static {
filterAura.add(new CardTypePredicate(CardType.ENCHANTMENT));
filterAura.add(new SubtypePredicate("Aura"));
filter.add(Predicates.not(new CardTypePredicate(CardType.CREATURE)));
}
public GuardianBeast(UUID ownerId) {
super(ownerId, 5, "Guardian Beast", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{3}{B}");
this.expansionSetCode = "ARN";
this.subtype.add("Beast");
this.power = new MageInt(2);
this.toughness = new MageInt(4);
// As long as Guardian Beast is untapped, noncreature artifacts you control can't be enchanted, they're indestructible, and other players can't gain control of them. This effect doesn't remove Auras already attached to those artifacts.
Effect effect = new ConditionalContinuousEffect(new GainAbilityControlledEffect(IndestructibleAbility.getInstance(), Duration.WhileOnBattlefield, filter), new InvertCondition(new SourceTappedCondition()), "noncreature artifacts you control can't be enchanted, they're indestructible, and other players can't gain control of them");
GuardianBeastConditionalEffect effect2 = new GuardianBeastConditionalEffect(this.getId());
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect2));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect));
}
public GuardianBeast(final GuardianBeast card) {
super(card);
}
@Override
public GuardianBeast copy() {
return new GuardianBeast(this);
}
}
class GuardianBeastConditionalEffect extends ContinuousRuleModifyingEffectImpl {
private static final FilterControlledArtifactPermanent filter = new FilterControlledArtifactPermanent("Noncreature artifacts");
private UUID guardianBeastId;
static {
filter.add(Predicates.not(new CardTypePredicate(CardType.CREATURE)));
}
public GuardianBeastConditionalEffect(UUID guardianBeastId) {
super(Duration.WhileOnBattlefield, Outcome.Neutral);
staticText = "Noncreature artifacts you control have they can't be enchanted, they're indestructible, and other players can't gain control of them";
this.guardianBeastId = guardianBeastId;
}
public GuardianBeastConditionalEffect(final GuardianBeastConditionalEffect effect) {
super(effect);
this.guardianBeastId = effect.guardianBeastId;
}
@Override
public GuardianBeastConditionalEffect copy() {
return new GuardianBeastConditionalEffect(this);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return true;
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent sourceObject = game.getPermanent(source.getSourceId());
Permanent targetPermanent = game.getPermanent(event.getTargetId());
Permanent guardianBeast = game.getPermanent(guardianBeastId);
if (guardianBeast == null || guardianBeast.isTapped() || sourceObject == null || targetPermanent == null) {
return false;
}
if (targetPermanent.getControllerId() != guardianBeast.getControllerId()) {
return false;
}
StackObject spell = game.getStack().getStackObject(event.getSourceId());
if (event.getType() == EventType.LOSE_CONTROL || event.getType() == EventType.ATTACH || event.getType() == EventType.TARGET && spell != null && spell.getCardType().contains(CardType.ENCHANTMENT) && spell.getSubtype().contains("Aura")) {
for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
if (perm != null && perm.getId() == targetPermanent.getId() && !perm.getCardType().contains(CardType.CREATURE)) {
return true;
}
}
}
return false;
}
}

View file

@ -0,0 +1,52 @@
/*
* 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.sets.masterseditioniv;
import java.util.UUID;
/**
*
* @author spjspj
*/
public class GuardianBeast extends mage.sets.arabiannights.GuardianBeast {
public GuardianBeast(UUID ownerId) {
super(ownerId);
this.cardNumber = "85";
this.expansionSetCode = "ME4";
}
public GuardianBeast(final GuardianBeast card) {
super(card);
}
@Override
public GuardianBeast copy() {
return new GuardianBeast(this);
}
}

View file

@ -24,8 +24,7 @@
* 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.effects.common.continuous;
import java.util.UUID;
@ -37,6 +36,7 @@ import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
@ -73,6 +73,7 @@ public class GainControlTargetEffect extends ContinuousEffectImpl {
this(duration, true, controllingPlayerId);
}
public GainControlTargetEffect(Duration duration, boolean fixedControl, UUID controllingPlayerId) {
super(duration, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl);
this.controllingPlayerId = controllingPlayerId;
@ -100,13 +101,20 @@ public class GainControlTargetEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
boolean targetStillExists = false;
for (UUID permanentId: getTargetPointer().getTargets(game, source)) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
targetStillExists = true;
GameEvent loseControlEvent = GameEvent.getEvent(GameEvent.EventType.LOSE_CONTROL, permanentId, source.getId(), permanent.getControllerId());
if (game.replaceEvent(loseControlEvent)) {
return false;
}
if (controllingPlayerId != null) {
permanent.changeControllerId(controllingPlayerId, game);
permanent.getAbilities().setControllerId(controllingPlayerId);
@ -114,14 +122,14 @@ public class GainControlTargetEffect extends ContinuousEffectImpl {
permanent.changeControllerId(source.getControllerId(), game);
permanent.getAbilities().setControllerId(source.getControllerId());
}
}
}
}
if (!targetStillExists) {
// no valid target exists, effect can be discarded
discard();
}
return true;
}
}
return false;
}
@ -139,8 +147,8 @@ public class GainControlTargetEffect extends ContinuousEffectImpl {
sb.append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(" target ");
} else {
if (!target.getTargetName().startsWith("another")) {
sb.append("target ");
}
sb.append("target ");
}
}
sb.append(mode.getTargets().get(0).getTargetName());
if (!duration.toString().isEmpty()) {

View file

@ -625,6 +625,13 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public boolean changeControllerId(UUID controllerId, Game game) {
Player newController = game.getPlayer(controllerId);
GameEvent loseControlEvent = GameEvent.getEvent(GameEvent.EventType.LOSE_CONTROL, this.getId(), null, controllerId);
if (game.replaceEvent(loseControlEvent)) {
return false;
}
if (newController != null && (!newController.hasLeft() || !newController.hasLost())) {
this.controllerId = controllerId;
return true;