Fixed Warstorm Surge

This commit is contained in:
North 2011-08-18 22:45:05 +03:00
parent 13d6f9df3f
commit 053e4bbe8f

View file

@ -31,16 +31,18 @@ import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Outcome;
import mage.Constants.Rarity;
import mage.MageInt;
import mage.Constants.Zone;
import mage.abilities.Ability;
import mage.abilities.common.CreatureEntersBattlefieldTriggeredAbility;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCreatureOrPlayer;
import mage.target.common.TargetCreaturePermanent;
/**
*
@ -54,9 +56,7 @@ public class WarstormSurge extends CardImpl<WarstormSurge> {
this.color.setRed(true);
// Whenever a creature enters the battlefield under your control, it deals damage equal to its power to target creature or player.
Ability ability = new CreatureEntersBattlefieldTriggeredAbility(new WarstormSurgeEffect());
ability.addTarget(new TargetCreaturePermanent());
Ability ability = new WarstormSurgeTriggeredAbility();
ability.addTarget(new TargetCreatureOrPlayer());
this.addAbility(ability);
}
@ -71,6 +71,41 @@ public class WarstormSurge extends CardImpl<WarstormSurge> {
}
}
class WarstormSurgeTriggeredAbility extends TriggeredAbilityImpl<WarstormSurgeTriggeredAbility> {
public WarstormSurgeTriggeredAbility() {
super(Zone.BATTLEFIELD, new WarstormSurgeEffect(), false);
}
public WarstormSurgeTriggeredAbility(WarstormSurgeTriggeredAbility ability) {
super(ability);
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.ZONE_CHANGE) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (((ZoneChangeEvent) event).getToZone() == Zone.BATTLEFIELD
&& permanent.getCardType().contains(CardType.CREATURE)
&& permanent.getControllerId().equals(this.controllerId)) {
game.getState().setValue(sourceId.toString(), event.getTargetId());
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever a creature enters the battlefield under your control, it deals damage equal to its power to target creature or player.";
}
@Override
public WarstormSurgeTriggeredAbility copy() {
return new WarstormSurgeTriggeredAbility(this);
}
}
class WarstormSurgeEffect extends OneShotEffect<WarstormSurgeEffect> {
public WarstormSurgeEffect() {
@ -89,18 +124,22 @@ class WarstormSurgeEffect extends OneShotEffect<WarstormSurgeEffect> {
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(source.getFirstTarget());
UUID creatureId = (UUID) game.getState().getValue(source.getSourceId().toString());
Permanent creature = game.getPermanent(creatureId);
if (creature == null) {
creature = (Permanent) game.getLastKnownInformation(creatureId, Zone.BATTLEFIELD);
}
if (creature != null) {
int amount = creature.getPower().getValue();
UUID target = source.getTargets().get(1).getFirstTarget();
Permanent permanent = game.getPermanent(target);
if (permanent != null) {
permanent.damage(amount, source.getSourceId(), game, true, false);
UUID target = source.getTargets().getFirstTarget();
Permanent targetCreature = game.getPermanent(target);
if (targetCreature != null) {
targetCreature.damage(amount, creature.getId(), game, true, false);
return true;
}
Player player = game.getPlayer(target);
if (player != null) {
player.damage(amount, source.getSourceId(), game, false, true);
player.damage(amount, creature.getId(), game, false, true);
return true;
}
}