mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Trigger.whileKeywordCheck
This commit is contained in:
@@ -27,11 +27,13 @@ import forge.game.ability.ApiType;
|
||||
import forge.game.ability.effects.CharmEffect;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardState;
|
||||
import forge.game.cost.IndividualCostPaymentInstance;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.OptionalCost;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.CostPaymentStack;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.CardTranslation;
|
||||
import forge.util.Lang;
|
||||
@@ -624,10 +626,33 @@ public abstract class Trigger extends TriggerReplacementBase {
|
||||
overridingAbility0.setTrigger(this);
|
||||
}
|
||||
|
||||
boolean whileKeywordCheck(final String keyword, final SpellAbility sa) {
|
||||
if (sa == null || sa.getHostCard() == null) return false;
|
||||
if (keyword.equals("Craft")) {
|
||||
return sa.isAbility() && sa.isCraft();
|
||||
} else return sa.isSpell() && sa.getHostCard().hasStartOfUnHiddenKeyword(keyword);
|
||||
boolean whileKeywordCheck(final String keyword, final Map<AbilityKey, Object> runParams) {
|
||||
SpellAbility sa;
|
||||
|
||||
IndividualCostPaymentInstance currentPayment =
|
||||
(IndividualCostPaymentInstance) runParams.get(AbilityKey.IndividualCostPaymentInstance);
|
||||
if (currentPayment != null) {
|
||||
sa = currentPayment.getPayment().getAbility();
|
||||
if (sa != null) {
|
||||
if (whileKeywordSACheck(keyword, sa)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
CostPaymentStack stack = (CostPaymentStack) runParams.get(AbilityKey.CostStack);
|
||||
for (IndividualCostPaymentInstance individual : stack) {
|
||||
sa = individual.getPayment().getAbility();
|
||||
if (whileKeywordSACheck(keyword, sa)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean whileKeywordSACheck(final String keyword, final SpellAbility sa) {
|
||||
if (sa == null || sa.getHostCard() == null) return false;
|
||||
if (sa.isAbility()) {
|
||||
if (keyword.equals("Craft") && sa.isCraft()) return true;
|
||||
}
|
||||
return sa.isSpell() && sa.getHostCard().hasStartOfUnHiddenKeyword(keyword);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ package forge.game.trigger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import forge.game.cost.IndividualCostPaymentInstance;
|
||||
import forge.game.zone.CostPaymentStack;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import forge.game.ability.AbilityKey;
|
||||
@@ -79,33 +77,8 @@ public class TriggerExiled extends Trigger {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasParam("WhileKeyword")) {
|
||||
final String keyword = getParam("WhileKeyword");
|
||||
boolean withKeyword = false;
|
||||
|
||||
IndividualCostPaymentInstance currentPayment = (IndividualCostPaymentInstance) runParams.get(AbilityKey.IndividualCostPaymentInstance);
|
||||
|
||||
SpellAbility sa;
|
||||
if (currentPayment != null) {
|
||||
sa = currentPayment.getPayment().getAbility();
|
||||
|
||||
if (whileKeywordCheck(keyword, sa)) withKeyword = true;
|
||||
}
|
||||
|
||||
if (!withKeyword) {
|
||||
CostPaymentStack stack = (CostPaymentStack) runParams.get(AbilityKey.CostStack);
|
||||
|
||||
for (IndividualCostPaymentInstance individual : stack) {
|
||||
sa = individual.getPayment().getAbility();
|
||||
|
||||
if (whileKeywordCheck(keyword, sa)) {
|
||||
withKeyword = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!withKeyword) return false;
|
||||
if (hasParam("WhileKeyword") && !whileKeywordCheck(getParam("WhileKeyword"), runParams)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -119,9 +92,7 @@ public class TriggerExiled extends Trigger {
|
||||
|
||||
@Override
|
||||
public String getImportantStackObjects(SpellAbility sa) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(Localizer.getInstance().getMessage("lblExiled")).append(": ").append(sa.getTriggeringObject(AbilityKey.Card));
|
||||
return sb.toString();
|
||||
return Localizer.getInstance().getMessage("lblExiled") + ": " + sa.getTriggeringObject(AbilityKey.Card);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,15 +17,13 @@
|
||||
*/
|
||||
package forge.game.trigger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.cost.IndividualCostPaymentInstance;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.CostPaymentStack;
|
||||
import forge.util.Localizer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Trigger_Sacrificed class.
|
||||
@@ -65,37 +63,8 @@ public class TriggerSacrificed extends Trigger {
|
||||
if (!matchesValidParam("ValidCause", runParams.get(AbilityKey.Cause))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasParam("WhileKeyword")) {
|
||||
final String keyword = getParam("WhileKeyword");
|
||||
boolean withKeyword = false;
|
||||
|
||||
// When cast with Emerge, the cost instance is there
|
||||
IndividualCostPaymentInstance currentPayment = (IndividualCostPaymentInstance) runParams.get(AbilityKey.IndividualCostPaymentInstance);
|
||||
|
||||
SpellAbility sa;
|
||||
if (currentPayment != null) {
|
||||
sa = currentPayment.getPayment().getAbility();
|
||||
|
||||
if (whileKeywordCheck(keyword, sa)) withKeyword = true;
|
||||
}
|
||||
|
||||
if (!withKeyword) {
|
||||
// When done for another card to get the Mana, the Emerge card is there
|
||||
CostPaymentStack stack = (CostPaymentStack) runParams.get(AbilityKey.CostStack);
|
||||
|
||||
for (IndividualCostPaymentInstance individual : stack) {
|
||||
sa = individual.getPayment().getAbility();
|
||||
|
||||
if (whileKeywordCheck(keyword, sa)) {
|
||||
withKeyword = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!withKeyword)
|
||||
return false;
|
||||
if (hasParam("WhileKeyword") && !whileKeywordCheck(getParam("WhileKeyword"), runParams)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -109,9 +78,8 @@ public class TriggerSacrificed extends Trigger {
|
||||
|
||||
@Override
|
||||
public String getImportantStackObjects(SpellAbility sa) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(Localizer.getInstance().getMessage("lblSacrificed")).append(": ").append(sa.getTriggeringObject(AbilityKey.Card));
|
||||
return sb.toString();
|
||||
return Localizer.getInstance().getMessage("lblSacrificed") + ": " +
|
||||
sa.getTriggeringObject(AbilityKey.Card);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user