mirror of
https://github.com/Relintai/mtg-forge-ios.git
synced 2025-01-08 15:39:35 +01:00
add more Damage Once Triggers
git-svn-id: http://svn.slightlymagic.net/forge/trunk@35706 269b9781-a132-4a9b-9d4e-f004f1b56b58
This commit is contained in:
parent
1645528ea1
commit
9b1dfe5caa
@ -50,6 +50,24 @@ public class CardDamageMap extends ForwardingTable<Card, GameEntity, Integer> {
|
||||
}
|
||||
|
||||
public void triggerDamageDoneOnce(boolean isCombat) {
|
||||
// Source -> Targets
|
||||
for (Map.Entry<Card, Map<GameEntity, Integer>> e : this.rowMap().entrySet()) {
|
||||
int sum = 0;
|
||||
for (final Integer i : e.getValue().values()) {
|
||||
sum += i;
|
||||
}
|
||||
if (sum > 0) {
|
||||
final GameEntity ge = e.getKey();
|
||||
final Map<String, Object> runParams = Maps.newHashMap();
|
||||
runParams.put("DamageSource", ge);
|
||||
runParams.put("DamageTargets", Sets.newHashSet(e.getValue().keySet()));
|
||||
runParams.put("DamageAmount", sum);
|
||||
runParams.put("IsCombatDamage", isCombat);
|
||||
|
||||
ge.getGame().getTriggerHandler().runTrigger(TriggerType.DamageDealtOnce, runParams, false);
|
||||
}
|
||||
}
|
||||
// Targets -> Source
|
||||
for (Map.Entry<GameEntity, Map<Card, Integer>> e : this.columnMap().entrySet()) {
|
||||
int sum = 0;
|
||||
for (final int i : e.getValue().values()) {
|
||||
|
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.GameEntity;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.util.Expressions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Trigger_DamageDone class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: TriggerDamageDone.java 21390 2013-05-08 07:44:50Z Max mtg $
|
||||
*/
|
||||
public class TriggerDamageDealtOnce extends Trigger {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for TriggerDamageDealtOnce.
|
||||
* </p>
|
||||
*
|
||||
* @param params
|
||||
* a {@link java.util.HashMap} object.
|
||||
* @param host
|
||||
* a {@link forge.game.card.Card} object.
|
||||
* @param intrinsic
|
||||
* the intrinsic
|
||||
*/
|
||||
public TriggerDamageDealtOnce(final java.util.Map<String, String> params, final Card host, final boolean intrinsic) {
|
||||
super(params, host, intrinsic);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public final boolean performTest(final java.util.Map<String, Object> runParams2) {
|
||||
final Card srcs = (Card) runParams2.get("DamageSource");
|
||||
final Set<GameEntity> tgt = (Set<GameEntity>) runParams2.get("DamageTargets");
|
||||
|
||||
if (this.mapParams.containsKey("CombatDamage")) {
|
||||
if (this.mapParams.get("CombatDamage").equals("True")) {
|
||||
if (!((Boolean) runParams2.get("IsCombatDamage"))) {
|
||||
return false;
|
||||
}
|
||||
} else if (this.mapParams.get("CombatDamage").equals("False")) {
|
||||
if (((Boolean) runParams2.get("IsCombatDamage"))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mapParams.containsKey("ValidTarget")) {
|
||||
boolean valid = false;
|
||||
for (GameEntity c : tgt) {
|
||||
if (c.isValid(this.mapParams.get("ValidTarget").split(","), this.getHostCard().getController(),this.getHostCard(), null)) {
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mapParams.containsKey("ValidSource")) {
|
||||
if (!matchesValid(srcs, this.mapParams.get("ValidSource").split(","), this.getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mapParams.containsKey("DamageAmount")) {
|
||||
final String fullParam = this.mapParams.get("DamageAmount");
|
||||
|
||||
final String operator = fullParam.substring(0, 2);
|
||||
final int operand = Integer.parseInt(fullParam.substring(2));
|
||||
final int actualAmount = (Integer) runParams2.get("DamageAmount");
|
||||
|
||||
if (!Expressions.compare(actualAmount, operator, operand)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void setTriggeringObjects(final SpellAbility sa) {
|
||||
sa.setTriggeringObject("Source", this.getRunParams().get("DamageSource"));
|
||||
sa.setTriggeringObject("Targets", this.getRunParams().get("DamageTargets"));
|
||||
sa.setTriggeringObject("DamageAmount", this.getRunParams().get("DamageAmount"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImportantStackObjects(SpellAbility sa) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Damage Source: ").append(sa.getTriggeringObject("Source")).append(", ");
|
||||
sb.append("Damaged: ").append(sa.getTriggeringObject("Targets")).append(", ");
|
||||
sb.append("Amount: ").append(sa.getTriggeringObject("DamageAmount"));
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
package forge.game.trigger;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
|
||||
@ -12,15 +14,11 @@ public class TriggerDamageDoneOnce extends Trigger {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean performTest(Map<String, Object> runParams2) {
|
||||
final Object tgt = runParams2.get("DamageTarget");
|
||||
if (this.mapParams.containsKey("ValidTarget")) {
|
||||
if (!matchesValid(tgt, this.mapParams.get("ValidTarget").split(","), this.getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
final Set<Card> srcs = (Set<Card>) runParams2.get("DamageSources");
|
||||
final GameEntity tgt = (GameEntity) runParams2.get("DamageTarget");
|
||||
|
||||
if (this.mapParams.containsKey("CombatDamage")) {
|
||||
if (this.mapParams.get("CombatDamage").equals("True")) {
|
||||
@ -34,15 +32,37 @@ public class TriggerDamageDoneOnce extends Trigger {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mapParams.containsKey("ValidSource")) {
|
||||
boolean valid = false;
|
||||
for (Card c : srcs) {
|
||||
if (c.isValid(this.mapParams.get("ValidSource").split(","), this.getHostCard().getController(),this.getHostCard(), null)) {
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mapParams.containsKey("ValidTarget")) {
|
||||
if (!matchesValid(tgt, this.mapParams.get("ValidTarget").split(","), this.getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTriggeringObjects(SpellAbility sa) {
|
||||
|
||||
if (this.getRunParams().containsKey("DamageTarget")) {
|
||||
sa.setTriggeringObject("Target", this.getRunParams().get("DamageTarget"));
|
||||
}
|
||||
if (this.getRunParams().containsKey("DamageSources")) {
|
||||
sa.setTriggeringObject("Sources", this.getRunParams().get("DamageSources"));
|
||||
}
|
||||
sa.setTriggeringObject("DamageAmount", this.getRunParams().get("DamageAmount"));
|
||||
|
||||
|
||||
|
@ -39,6 +39,7 @@ public enum TriggerType {
|
||||
CounterRemoved(TriggerCounterRemoved.class),
|
||||
Crewed(TriggerCrewed.class),
|
||||
Cycled(TriggerCycled.class),
|
||||
DamageDealtOnce(TriggerDamageDealtOnce.class),
|
||||
DamageDone(TriggerDamageDone.class),
|
||||
DamageDoneOnce(TriggerDamageDoneOnce.class),
|
||||
DamagePrevented(TriggerDamagePrevented.class),
|
||||
|
Loading…
Reference in New Issue
Block a user