Merge pull request #2736 from shootbot/master

Fixed Asylum Visitor and Spined Sliver bugs
This commit is contained in:
LevelX2 2017-01-02 17:30:07 +01:00 committed by GitHub
commit f777668a4d
2 changed files with 86 additions and 23 deletions

View file

@ -29,12 +29,15 @@ package mage.cards.a;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.MadnessAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -72,12 +75,12 @@ public class AsylumVisitor extends CardImpl {
}
class AsylumVisitorTriggeredAbility extends TriggeredAbilityImpl {
public AsylumVisitorTriggeredAbility() {
super(Zone.BATTLEFIELD, null);
super(Zone.BATTLEFIELD, new AsylumVisitorEffect());
}
public AsylumVisitorTriggeredAbility(final AsylumVisitorTriggeredAbility ability) {
public AsylumVisitorTriggeredAbility(final AsylumVisitorTriggeredAbility ability) {
super(ability);
}
@ -93,16 +96,10 @@ class AsylumVisitorTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Player you = game.getPlayer(this.getControllerId());
Player upkeepPlayer = game.getPlayer(event.getPlayerId());
if (you != null && upkeepPlayer != null && upkeepPlayer.getHand().isEmpty()) {
you.drawCards(1, game);
you.loseLife(1, game, false);
if (upkeepPlayer != null && upkeepPlayer.getHand().isEmpty()) {
return true;
}
return false;
}
@ -110,4 +107,33 @@ class AsylumVisitorTriggeredAbility extends TriggeredAbilityImpl {
public String getRule() {
return "At the beginning of each player's upkeep, if that player has no cards in hand, you draw a card and you lose 1 life.";
}
}
class AsylumVisitorEffect extends OneShotEffect {
public AsylumVisitorEffect() {
super(Outcome.DrawCard);
this.staticText = "you draw a card and you lose 1 life";
}
public AsylumVisitorEffect(final AsylumVisitorEffect effect) {
super(effect);
}
@Override
public AsylumVisitorEffect copy() {
return new AsylumVisitorEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
Player upkeepPlayer = game.getPlayer(game.getActivePlayerId());
if (you != null && upkeepPlayer != null && upkeepPlayer.getHand().isEmpty()) {
you.drawCards(1, game);
you.loseLife(1, game, false);
return true;
}
return false;
}
}

View file

@ -30,19 +30,19 @@ package mage.cards.s;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BecomesBlockedByCreatureTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.common.BlockedCreatureCount;
import mage.abilities.common.BecomesBlockedAllTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
import mage.abilities.effects.common.continuous.BoostTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.target.targetpointer.TargetPointer;
/**
*
@ -64,14 +64,10 @@ public class SpinedSliver extends CardImpl {
this.toughness = new MageInt(2);
// Whenever a Sliver becomes blocked, that Sliver gets +1/+1 until end of turn for each creature blocking it.
BlockedCreatureCount value = new BlockedCreatureCount();
Effect effect = new BoostSourceEffect(value, value, Duration.EndOfTurn, true);
BlockersCount value = new BlockersCount();
Effect effect = new BoostTargetEffect(value, value, Duration.EndOfTurn, true);
effect.setText("it gets +1/+1 until end of turn for each creature blocking it");
Ability ability = new BecomesBlockedByCreatureTriggeredAbility(effect, false);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD,
new GainAbilityAllEffect(ability,
Duration.WhileOnBattlefield, filter,
"Whenever a Sliver becomes blocked, that Sliver gets +1/+1 until end of turn for each creature blocking it.")));
this.addAbility(new BecomesBlockedAllTriggeredAbility(effect, false, filter, true));
}
public SpinedSliver(final SpinedSliver card) {
@ -83,3 +79,44 @@ public class SpinedSliver extends CardImpl {
return new SpinedSliver(this);
}
}
class BlockersCount implements DynamicValue {
private String message;
public BlockersCount() {
this.message = "each creature blocking it";
}
public BlockersCount(final BlockersCount blockersCount) {
super();
this.message = blockersCount.message;
}
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
TargetPointer attacker = effect.getTargetPointer();
UUID attackerId = attacker.getFirst(game, sourceAbility);
for (CombatGroup combatGroup : game.getCombat().getGroups()) {
if (combatGroup.getAttackers().contains(attackerId)) {
return combatGroup.getBlockers().size();
}
}
return 0;
}
@Override
public BlockersCount copy() {
return new BlockersCount(this);
}
@Override
public String getMessage() {
return message;
}
@Override
public String toString() {
return "X";
}
}