Some more rework for prevention effects.

This commit is contained in:
LevelX2 2014-04-25 11:30:54 +02:00
parent b930c5aae7
commit 300081d302
14 changed files with 64 additions and 190 deletions

View file

@ -84,10 +84,7 @@ class PatronOfTheKitsuneTriggeredAbility extends TriggeredAbilityImpl<PatronOfTh
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) {
return true;
}
return false;
return event.getType().equals(GameEvent.EventType.ATTACKER_DECLARED);
}
@Override

View file

@ -92,34 +92,11 @@ class PrahvSpiresOfOrderPreventionEffect extends PreventionEffectImpl<PrahvSpire
return new PrahvSpiresOfOrderPreventionEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public void init(Ability source, Game game) {
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (event.getSourceId().equals(target.getFirstTarget())) {
preventDamage(event, source, target.getFirstTarget(), game);
return true;
}
return false;
}
private void preventDamage(GameEvent event, Ability source, UUID target, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getId(), source.getControllerId(), damage));
}
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event instanceof DamageEvent && super.applies(event, source, game)) {

View file

@ -32,6 +32,7 @@ import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.delayed.PactDelayedTriggeredAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.PreventionEffectData;
import mage.abilities.effects.PreventionEffectImpl;
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
import mage.cards.CardImpl;
@ -97,20 +98,11 @@ class InterventionPactPreventDamageEffect extends PreventionEffectImpl<Intervent
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int prevented = event.getAmount();
event.setAmount(0);
this.used = true;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), prevented));
if (prevented > 0) {
Player player = game .getPlayer(source.getControllerId());
if(player != null){
player.gainLife(prevented, game);
}
PreventionEffectData preventEffectData = preventDamageAction(event, source, game);
if (preventEffectData.getPreventedDamage() > 0) {
Player player = game .getPlayer(source.getControllerId());
if(player != null){
player.gainLife(preventEffectData.getPreventedDamage(), game);
}
}
return false;

View file

@ -88,23 +88,6 @@ class ArmoredTransportPreventCombatDamageSourceEffect extends PreventionEffectIm
return new ArmoredTransportPreventCombatDamageSourceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage));
return true;
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {

View file

@ -100,7 +100,7 @@ class DamageCantBePreventedEffect extends ReplacementEffectImpl<DamageCantBePrev
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.PREVENT_DAMAGE) {
if (event.getType().equals(GameEvent.EventType.PREVENT_DAMAGE)) {
return true;
}
return false;

View file

@ -130,17 +130,20 @@ class GhostCouncilOfOrzhovaRemovingEffect extends OneShotEffect<GhostCouncilOfOr
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (permanent.moveToExile(source.getSourceId(), " Ghost Council of Orzhova Exile", source.getId(), game)) {
//create delayed triggered ability
AtEndOfTurnDelayedTriggeredAbility delayedAbility = new AtEndOfTurnDelayedTriggeredAbility(
new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD));
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
game.addDelayedTriggeredAbility(delayedAbility);
return true;
}
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
if (controller.moveCardToExileWithInfo(permanent, source.getSourceId(), permanent.getName(), source.getSourceId(), game, Zone.BATTLEFIELD)) {
//create delayed triggered ability
AtEndOfTurnDelayedTriggeredAbility delayedAbility = new AtEndOfTurnDelayedTriggeredAbility(
new ReturnFromExileEffect(source.getSourceId(), Zone.BATTLEFIELD));
delayedAbility.setSourceId(source.getSourceId());
delayedAbility.setControllerId(source.getControllerId());
game.addDelayedTriggeredAbility(delayedAbility);
return true;
}
}
}
return false;
}

View file

@ -47,8 +47,6 @@ import mage.target.TargetSource;
* @author Plopman
*/
public class CircleOfProtectionBlack extends CardImpl<CircleOfProtectionBlack> {
public CircleOfProtectionBlack(UUID ownerId) {
super(ownerId, 236, "Circle of Protection: Black", Rarity.COMMON, new CardType[]{CardType.ENCHANTMENT}, "{1}{W}");
@ -73,10 +71,12 @@ public class CircleOfProtectionBlack extends CardImpl<CircleOfProtectionBlack> {
class CircleOfProtectionBlackEffect extends PreventionEffectImpl<CircleOfProtectionBlackEffect> {
private static final FilterObject filter = new FilterObject("black source");
static{
filter.add(new ColorPredicate(ObjectColor.BLACK));
}
private TargetSource target;
private final TargetSource target;
public CircleOfProtectionBlackEffect() {
super(Duration.EndOfTurn);
@ -95,11 +95,6 @@ class CircleOfProtectionBlackEffect extends PreventionEffectImpl<CircleOfProtect
return new CircleOfProtectionBlackEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public void init(Ability source, Game game) {
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
@ -107,23 +102,11 @@ class CircleOfProtectionBlackEffect extends PreventionEffectImpl<CircleOfProtect
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) {
preventDamage(event, source, target.getFirstTarget(), game);
return true;
}
preventDamageAction(event, source, game);
this.used = true;
return false;
}
private void preventDamage(GameEvent event, Ability source, UUID target, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
this.used = true;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage));
}
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!this.used && super.applies(event, source, game)) {

View file

@ -74,7 +74,7 @@ class CircleOfProtectionBlueEffect extends PreventionEffectImpl<CircleOfProtecti
static{
filter.add(new ColorPredicate(ObjectColor.BLUE));
}
private TargetSource target;
private final TargetSource target;
public CircleOfProtectionBlueEffect() {
super(Duration.EndOfTurn);
@ -93,11 +93,6 @@ class CircleOfProtectionBlueEffect extends PreventionEffectImpl<CircleOfProtecti
return new CircleOfProtectionBlueEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public void init(Ability source, Game game) {
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
@ -105,23 +100,11 @@ class CircleOfProtectionBlueEffect extends PreventionEffectImpl<CircleOfProtecti
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) {
preventDamage(event, source, target.getFirstTarget(), game);
return true;
}
preventDamageAction(event, source, game);
this.used = true;
return false;
}
private void preventDamage(GameEvent event, Ability source, UUID target, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
this.used = true;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage));
}
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!this.used && super.applies(event, source, game)) {

View file

@ -75,7 +75,7 @@ class CircleOfProtectionGreenEffect extends PreventionEffectImpl<CircleOfProtect
static{
filter.add(new ColorPredicate(ObjectColor.GREEN));
}
private TargetSource target;
private final TargetSource target;
public CircleOfProtectionGreenEffect() {
super(Duration.EndOfTurn);
@ -94,11 +94,6 @@ class CircleOfProtectionGreenEffect extends PreventionEffectImpl<CircleOfProtect
return new CircleOfProtectionGreenEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public void init(Ability source, Game game) {
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
@ -106,23 +101,11 @@ class CircleOfProtectionGreenEffect extends PreventionEffectImpl<CircleOfProtect
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) {
preventDamage(event, source, target.getFirstTarget(), game);
return true;
}
preventDamageAction(event, source, game);
this.used = true;
return false;
}
private void preventDamage(GameEvent event, Ability source, UUID target, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
this.used = true;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage));
}
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!this.used && super.applies(event, source, game)) {

View file

@ -72,10 +72,12 @@ public class CircleOfProtectionRed extends CardImpl<CircleOfProtectionRed> {
class CircleOfProtectionRedEffect extends PreventionEffectImpl<CircleOfProtectionRedEffect> {
private static final FilterObject filter = new FilterObject("red source");
static{
filter.add(new ColorPredicate(ObjectColor.RED));
}
private TargetSource target;
}
private final TargetSource target;
public CircleOfProtectionRedEffect() {
super(Duration.EndOfTurn);
@ -94,11 +96,6 @@ class CircleOfProtectionRedEffect extends PreventionEffectImpl<CircleOfProtectio
return new CircleOfProtectionRedEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public void init(Ability source, Game game) {
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
@ -106,23 +103,11 @@ class CircleOfProtectionRedEffect extends PreventionEffectImpl<CircleOfProtectio
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) {
preventDamage(event, source, target.getFirstTarget(), game);
return true;
}
preventDamageAction(event, source, game);
this.used = true;
return false;
}
private void preventDamage(GameEvent event, Ability source, UUID target, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
this.used = true;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage));
}
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!this.used && super.applies(event, source, game)) {

View file

@ -75,7 +75,7 @@ class CircleOfProtectionWhiteEffect extends PreventionEffectImpl<CircleOfProtect
static{
filter.add(new ColorPredicate(ObjectColor.WHITE));
}
private TargetSource target;
private final TargetSource target;
public CircleOfProtectionWhiteEffect() {
super(Duration.EndOfTurn);
@ -94,11 +94,6 @@ class CircleOfProtectionWhiteEffect extends PreventionEffectImpl<CircleOfProtect
return new CircleOfProtectionWhiteEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public void init(Ability source, Game game) {
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), game);
@ -106,23 +101,11 @@ class CircleOfProtectionWhiteEffect extends PreventionEffectImpl<CircleOfProtect
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) {
preventDamage(event, source, target.getFirstTarget(), game);
return true;
}
preventDamageAction(event, source, game);
this.used = true;
return false;
}
private void preventDamage(GameEvent event, Ability source, UUID target, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getSourceId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
this.used = true;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getSourceId(), source.getControllerId(), damage));
}
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!this.used && super.applies(event, source, game)) {
@ -133,4 +116,4 @@ class CircleOfProtectionWhiteEffect extends PreventionEffectImpl<CircleOfProtect
return false;
}
}
}

View file

@ -84,7 +84,7 @@ public class GhostlyPossession extends CardImpl<GhostlyPossession> {
class GhostlyPossessionEffect extends PreventionEffectImpl<GhostlyPossessionEffect> {
public GhostlyPossessionEffect() {
super(Duration.WhileOnBattlefield);
super(Duration.WhileOnBattlefield, Integer.MAX_VALUE, true);
staticText = "Prevent all combat damage that would be dealt to and dealt by enchanted creature";
}
@ -102,17 +102,6 @@ class GhostlyPossessionEffect extends PreventionEffectImpl<GhostlyPossessionEffe
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), event.getAmount(), false);
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, source.getFirstTarget(), source.getId(), source.getControllerId(), damage));
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game) && event instanceof DamageEvent) {

View file

@ -88,8 +88,24 @@ public class ReturnFromExileEffect extends OneShotEffect<ReturnFromExileEffect>
exile = exile.copy();
for (UUID cardId: exile) {
Card card = game.getCard(cardId);
card.moveToZone(zone, source.getSourceId(), game, tapped);
game.informPlayers(new StringBuilder(controller.getName()).append(" moves ").append(card.getName()).append(" to ").append(zone.toString()).toString());
switch (zone) {
case BATTLEFIELD:
controller.putOntoBattlefieldWithInfo(card, game, Zone.EXILED, source.getSourceId(), tapped);
break;
case HAND:
controller.moveCardToHandWithInfo(card, source.getSourceId(), game, Zone.EXILED);
break;
case GRAVEYARD:
controller.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, Zone.EXILED);
break;
case LIBRARY:
controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.EXILED, true);
break;
default:
card.moveToZone(zone, source.getSourceId(), game, tapped);
game.informPlayers(new StringBuilder(controller.getName()).append(" moves ").append(card.getName()).append(" to ").append(zone.toString()).toString());
}
}
game.getExile().getExileZone(exileId).clear();
return true;

View file

@ -120,7 +120,7 @@ public abstract class SplitCard<T extends SplitCard<T>> extends CardImpl<T> {
@Override
public List<String> getRules() {
List<String> rules = new ArrayList<String>();
List<String> rules = new ArrayList<>();
// rules.addAll(leftHalfCard.getRules());
// rules.addAll(rightHalfCard.getRules());
if (getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) {
@ -149,7 +149,7 @@ public abstract class SplitCard<T extends SplitCard<T>> extends CardImpl<T> {
@Override
public List<Watcher> getWatchers() {
List<Watcher> allWatchers = new ArrayList<Watcher>();
List<Watcher> allWatchers = new ArrayList<>();
allWatchers.addAll(super.getWatchers());
allWatchers.addAll(leftHalfCard.getWatchers());
allWatchers.addAll(rightHalfCard.getWatchers());