Commit 7f4dc855 authored by Hans Mackowiak's avatar Hans Mackowiak

Merge branch '793-new-feature-paylife-trigger' into 'master'

New Feature: PayLife Trigger

Closes #793

See merge request !1265
parents 948c13dd 005fa3d7
......@@ -23,7 +23,7 @@ import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
/**
* The Class CostPayLife.
* The Class CostDamage.
*/
public class CostDamage extends CostPart {
......
......@@ -25,7 +25,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* The Class CostPayLife.
* The Class CostDraw.
*/
public class CostDraw extends CostPart {
/**
......
......@@ -57,17 +57,6 @@ public class CostPayLife extends CostPart {
return sb.toString();
}
/*
* (non-Javadoc)
*
* @see forge.card.cost.CostPart#refund(forge.Card)
*/
@Override
public final void refund(final Card source) {
// Really should be activating player
source.getController().payLife(this.paidAmount * -1, null);
}
/*
* (non-Javadoc)
*
......
......@@ -515,14 +515,15 @@ public class Player extends GameEntity implements Comparable<Player> {
return false;
}
if (lifePayment <= 0)
return true;
loseLife(lifePayment);
// rule 118.8
if (life >= lifePayment) {
return (loseLife(lifePayment) > 0);
}
return false;
// Run triggers
final Map<String, Object> runParams = Maps.newHashMap();
runParams.put("Player", this);
runParams.put("LifeAmount", lifePayment);
game.getTriggerHandler().runTrigger(TriggerType.PayLife, runParams, false);
return true;
}
public final boolean canPayEnergy(final int energyPayment) {
......
......@@ -20,13 +20,14 @@ package forge.game.trigger;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;
import java.util.Map;
/**
* <p>
* Trigger_LifeGained class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class TriggerLifeGained extends Trigger {
......@@ -36,32 +37,30 @@ public class TriggerLifeGained extends Trigger {
* </p>
*
* @param params
* a {@link java.util.HashMap} object.
* a {@link java.util.Map} object.
* @param host
* a {@link forge.game.card.Card} object.
* @param intrinsic
* the intrinsic
*/
public TriggerLifeGained(final java.util.Map<String, String> params, final Card host, final boolean intrinsic) {
public TriggerLifeGained(final Map<String, String> params, final Card host, final boolean intrinsic) {
super(params, host, intrinsic);
}
/** {@inheritDoc} */
@Override
public final boolean performTest(final java.util.Map<String, Object> runParams2) {
if (this.mapParams.containsKey("ValidPlayer")) {
if (!matchesValid(runParams2.get("Player"), this.mapParams.get("ValidPlayer").split(","),
this.getHostCard())) {
public final boolean performTest(final Map<String, Object> runParams2) {
if (hasParam("ValidPlayer")) {
if (!matchesValid(runParams2.get("Player"), getParam("ValidPlayer").split(","), getHostCard())) {
return false;
}
}
if (this.mapParams.containsKey("ValidSource")) {
if (!matchesValid(runParams2.get("Source"), this.mapParams.get("ValidSource").split(","),
this.getHostCard())) {
if (hasParam("ValidSource")) {
if (!matchesValid(runParams2.get("Source"), getParam("ValidSource").split(","), getHostCard())) {
return false;
}
}
if (this.mapParams.containsKey("Spell")) {
if (hasParam("Spell")) {
final SpellAbility spellAbility = (SpellAbility) runParams2.get("SourceSA");
if (spellAbility == null || !spellAbility.getRootAbility().isSpell()) {
return false;
......@@ -71,12 +70,11 @@ public class TriggerLifeGained extends Trigger {
return true;
}
/** {@inheritDoc} */
@Override
public final void setTriggeringObjects(final SpellAbility sa) {
sa.setTriggeringObject("LifeAmount", this.getRunParams().get("LifeAmount"));
sa.setTriggeringObject("Player", this.getRunParams().get("Player"));
sa.setTriggeringObject("LifeAmount", getRunParams().get("LifeAmount"));
sa.setTriggeringObject("Player", getRunParams().get("Player"));
}
@Override
......
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.game.trigger;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;
import java.util.Map;
/**
* <p>
* Trigger_LifeGained class.
* </p>
*
* @author Forge
*/
public class TriggerPayLife extends Trigger {
/**
* <p>
* Constructor for TriggerPayLife.
* </p>
*
* @param params
* a {@link java.util.Map} object.
* @param host
* a {@link forge.game.card.Card} object.
* @param intrinsic
* the intrinsic
*/
public TriggerPayLife(final Map<String, String> params, final Card host, final boolean intrinsic) {
super(params, host, intrinsic);
}
/** {@inheritDoc} */
@Override
public final boolean performTest(final Map<String, Object> runParams2) {
if (hasParam("ValidPlayer")) {
if (!matchesValid(runParams2.get("Player"), getParam("ValidPlayer").split(","), getHostCard())) {
return false;
}
}
return true;
}
/** {@inheritDoc} */
@Override
public final void setTriggeringObjects(final SpellAbility sa) {
sa.setTriggeringObject("LifeAmount", getRunParams().get("LifeAmount"));
sa.setTriggeringObject("Player", getRunParams().get("Player"));
}
@Override
public String getImportantStackObjects(SpellAbility sa) {
StringBuilder sb = new StringBuilder();
sb.append("Player: ").append(sa.getTriggeringObject("Player")).append(", ");
sb.append("paid Amount: ").append(sa.getTriggeringObject("LifeAmount"));
return sb.toString();
}
}
......@@ -64,6 +64,7 @@ public enum TriggerType {
NewGame(TriggerNewGame.class),
PayCumulativeUpkeep(TriggerPayCumulativeUpkeep.class),
PayEcho(TriggerPayEcho.class),
PayLife(TriggerPayLife.class),
Phase(TriggerPhase.class),
PhaseIn(TriggerPhaseIn.class),
PhaseOut(TriggerPhaseOut.class),
......
Name:Font of Agonies
ManaCost:B
Types:Enchantment
T:Mode$ PayLife | ValidPlayer$ You | TriggerZones$ Battlefield | Execute$ TrigPutCounter | TriggerDescription$ Whenever you pay life, put that many blood counters on CARDNAME.
SVar:TrigPutCounter:DB$ PutCounter | Defined$ Self | CounterType$ BLOOD | CounterNum$ X | References$ X
SVar:X:TriggerCount$LifeAmount
A:AB$ Destroy | Cost$ 1 B SubCounter<4/BLOOD> | ValidTgts$ Creature | TgtPrompt$ Select target creature | SpellDescription$ Destroy target creature.
Oracle:Whenever you pay life, put that many blood counters on Font of Agonies.\n{1}{B}, Remove four blood counters from Font of Agonies: Destroy target creature.
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment