Skip to content

Commit

Permalink
refactor WhileKeyword
Browse files Browse the repository at this point in the history
  • Loading branch information
Northmoc committed Nov 22, 2023
1 parent 83e9766 commit 20bcd8f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
7 changes: 7 additions & 0 deletions forge-game/src/main/java/forge/game/trigger/Trigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -623,4 +623,11 @@ public void setOverridingAbility(SpellAbility overridingAbility0) {
super.setOverridingAbility(overridingAbility0);
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);
}
}
14 changes: 3 additions & 11 deletions forge-game/src/main/java/forge/game/trigger/TriggerExiled.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ public final boolean performTest(final Map<AbilityKey, Object> runParams) {
if (currentPayment != null) {
sa = currentPayment.getPayment().getAbility();

if (sa != null && sa.getHostCard() != null) {
if ((sa.isSpell() || sa.isAbility()) && sa.getHostCard().hasStartOfUnHiddenKeyword(keyword)) {
withKeyword = true;
}
}
if (whileKeywordCheck(keyword, sa)) withKeyword = true;
}

if (!withKeyword) {
Expand All @@ -102,18 +98,14 @@ public final boolean performTest(final Map<AbilityKey, Object> runParams) {
for (IndividualCostPaymentInstance individual : stack) {
sa = individual.getPayment().getAbility();

if (sa == null || sa.getHostCard() == null)
continue;

if ((sa.isSpell() || sa.isAbility()) && sa.getHostCard().hasStartOfUnHiddenKeyword(keyword)) {
if (whileKeywordCheck(keyword, sa)) {
withKeyword = true;
break;
}
}
}

if (!withKeyword)
return false;
if (!withKeyword) return false;
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ public final boolean performTest(final Map<AbilityKey, Object> runParams) {
if (currentPayment != null) {
sa = currentPayment.getPayment().getAbility();

if (sa != null && sa.getHostCard() != null) {
if (sa.isSpell() && sa.getHostCard().hasStartOfUnHiddenKeyword(keyword)) {
withKeyword = true;
}
}
if (whileKeywordCheck(keyword, sa)) withKeyword = true;
}

if (!withKeyword) {
Expand All @@ -91,10 +87,7 @@ public final boolean performTest(final Map<AbilityKey, Object> runParams) {
for (IndividualCostPaymentInstance individual : stack) {
sa = individual.getPayment().getAbility();

if (sa == null || sa.getHostCard() == null)
continue;

if (sa.isSpell() && sa.getHostCard().hasStartOfUnHiddenKeyword(keyword)) {
if (whileKeywordCheck(keyword, sa)) {
withKeyword = true;
break;
}
Expand Down

0 comments on commit 20bcd8f

Please sign in to comment.