mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
- Convert DamageDone|OnlyOnce to the new trigger DamageDoneOnce. Remove code for DamageDone|OnlyOnce (no longer needed).
This commit is contained in:
@@ -6,12 +6,12 @@
|
||||
* 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/>.
|
||||
*/
|
||||
@@ -23,13 +23,11 @@ import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.util.Expressions;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Trigger_DamageDone class.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@@ -39,7 +37,7 @@ public class TriggerDamageDone extends Trigger {
|
||||
* <p>
|
||||
* Constructor for Trigger_DamageDone.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param params
|
||||
* a {@link java.util.HashMap} object.
|
||||
* @param host
|
||||
@@ -57,63 +55,16 @@ public class TriggerDamageDone extends Trigger {
|
||||
final Card src = (Card) runParams2.get("DamageSource");
|
||||
final Object tgt = runParams2.get("DamageTarget");
|
||||
|
||||
// DamageDone with OnlyOnce$ True is interested in counting the damage only once, e.g. for all creatures in
|
||||
// combat.
|
||||
if (runParams2.containsKey("CombatDamageOnce")) {
|
||||
if (!this.mapParams.containsKey("OnlyOnce")) {
|
||||
// We're not interested in additional OnlyOnce triggers, only in standard DamageDone
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (this.mapParams.containsKey("OnlyOnce")) {
|
||||
// This currently only works for combat damage. Feel free to improve.
|
||||
if (runParams2.containsKey("IsCombatDamage") && ((Boolean) runParams2.get("IsCombatDamage")) && !runParams2.containsKey("CombatDamageOnce")) {
|
||||
return false;
|
||||
}
|
||||
// Ensure that the trigger doesn't run twice if we're only interested from damage from a ValidSource or to
|
||||
// a ValidTarget but not both (since otherwise the trigger will fire twice: once when testing the trigger
|
||||
// from source to target(s), and once when testing it from source(s) to target
|
||||
if (!(this.mapParams.containsKey("ValidSource") && this.mapParams.containsKey("ValidTarget"))) {
|
||||
if (this.mapParams.containsKey("ValidSource") && src == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.mapParams.containsKey("ValidTarget") && tgt == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mapParams.containsKey("ValidSource")) {
|
||||
if (src != null) {
|
||||
if (!src.isValid(this.mapParams.get("ValidSource").split(","), this.getHostCard().getController(),
|
||||
this.getHostCard(), null)) {
|
||||
return false;
|
||||
}
|
||||
} else if (runParams2.containsKey("DamageSources")) { // OnlyOnce$ True
|
||||
boolean hasValidSrc = false;
|
||||
for (Card srcs : (Set<Card>)runParams2.get("DamageSources")) {
|
||||
if (srcs.isValid(this.mapParams.get("ValidSource").split(","), this.getHostCard().getController(),
|
||||
this.getHostCard(), null)) {
|
||||
hasValidSrc = true;
|
||||
}
|
||||
}
|
||||
if (!hasValidSrc) { return false; }
|
||||
if (!src.isValid(this.mapParams.get("ValidSource").split(","), this.getHostCard().getController(),
|
||||
this.getHostCard(), null)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.mapParams.containsKey("ValidTarget")) {
|
||||
if (tgt != null) {
|
||||
if (!matchesValid(tgt, this.mapParams.get("ValidTarget").split(","), this.getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
} else if (runParams2.containsKey("DamageTargets")) { // OnlyOnce$ True
|
||||
boolean hasValidTgt = false;
|
||||
for (Object tgts : (Set<Card>)runParams2.get("DamageTargets")) {
|
||||
if (matchesValid(tgt, this.mapParams.get("ValidTarget").split(","), this.getHostCard())) {
|
||||
hasValidTgt = true;
|
||||
}
|
||||
}
|
||||
if (!hasValidTgt) { return false; }
|
||||
if (!matchesValid(tgt, this.mapParams.get("ValidTarget").split(","), this.getHostCard())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,12 +118,8 @@ public class TriggerDamageDone extends Trigger {
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void setTriggeringObjects(final SpellAbility sa) {
|
||||
if (this.getRunParams().containsKey("DamageSource")) {
|
||||
sa.setTriggeringObject("Source", CardUtil.getLKICopy((Card) this.getRunParams().get("DamageSource")));
|
||||
}
|
||||
if (this.getRunParams().containsKey("DamageTarget")) {
|
||||
sa.setTriggeringObject("Target", this.getRunParams().get("DamageTarget"));
|
||||
}
|
||||
sa.setTriggeringObject("Source", CardUtil.getLKICopy((Card)this.getRunParams().get("DamageSource")));
|
||||
sa.setTriggeringObject("Target", this.getRunParams().get("DamageTarget"));
|
||||
sa.setTriggeringObject("DamageAmount", this.getRunParams().get("DamageAmount"));
|
||||
// This parameter is here because LKI information related to combat doesn't work properly
|
||||
sa.setTriggeringObject("DefendingPlayer", this.getRunParams().get("DefendingPlayer"));
|
||||
@@ -181,13 +128,10 @@ public class TriggerDamageDone extends Trigger {
|
||||
@Override
|
||||
public String getImportantStackObjects(SpellAbility sa) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (sa.getTriggeringObject("Source") != null) {
|
||||
sb.append("Damage Source: ").append(sa.getTriggeringObject("Source")).append(", ");
|
||||
}
|
||||
if (sa.getTriggeringObject("Target") != null) {
|
||||
sb.append("Damaged: ").append(sa.getTriggeringObject("Target")).append(", ");
|
||||
}
|
||||
sb.append("Damage Source: ").append(sa.getTriggeringObject("Source")).append(", ");
|
||||
sb.append("Damaged: ").append(sa.getTriggeringObject("Target")).append(", ");
|
||||
sb.append("Amount: ").append(sa.getTriggeringObject("DamageAmount"));
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user