- Improved handling of script execution in GameState to support subabilities and KW Awaken (other keywords with mana cost might need similar treatment later).

This commit is contained in:
Agetian
2017-08-21 04:50:49 +00:00
parent 1aa8475295
commit 13376d0ced

View File

@@ -652,15 +652,38 @@ public abstract class GameState {
System.err.println("ERROR: Unable to find SA with index " + numSA + " on card " + c + " to execute!"); System.err.println("ERROR: Unable to find SA with index " + numSA + " on card " + c + " to execute!");
} }
} else { } else {
if (!c.hasSVar(sPtr)) { // Special handling for keyworded abilities
System.err.println("ERROR: Unable to find SVar " + sPtr + " on card " + c + " + to execute!"); if (sPtr.startsWith("KW#")) {
return; String kwName = sPtr.substring(3);
} FCollectionView<SpellAbility> saList = c.getSpellAbilities();
String svarValue = c.getSVar(sPtr); if (kwName.equals("Awaken")) {
sa = AbilityFactory.getAbility(svarValue, c); for (SpellAbility ab : saList) {
if (sa == null) { if (ab.getDescription().startsWith("Awaken")) {
System.err.println("ERROR: Unable to generate ability for SVar " + svarValue); ab.setActivatingPlayer(c.getController());
ab.getSubAbility().setActivatingPlayer(c.getController());
sa = ab;
// target for Awaken is set in its first subability
handleScriptedTargetingForSA(game, sa.getSubAbility(), tgtID);
}
}
if (sa == null) {
System.err.println("ERROR: Could not locate keyworded ability Awaken in card " + c + " to execute!");
return;
}
}
} else {
// SVar-based script execution
if (!c.hasSVar(sPtr)) {
System.err.println("ERROR: Unable to find SVar " + sPtr + " on card " + c + " + to execute!");
return;
}
String svarValue = c.getSVar(sPtr);
sa = AbilityFactory.getAbility(svarValue, c);
if (sa == null) {
System.err.println("ERROR: Unable to generate ability for SVar " + svarValue);
}
} }
} }
@@ -668,6 +691,13 @@ public abstract class GameState {
handleScriptedTargetingForSA(game, sa, tgtID); handleScriptedTargetingForSA(game, sa, tgtID);
sa.resolve(); sa.resolve();
// resolve subabilities
SpellAbility subSa = sa.getSubAbility();
while (subSa != null) {
subSa.resolve();
subSa = subSa.getSubAbility();
}
} }
private void handlePrecastSpells(final Game game) { private void handlePrecastSpells(final Game game) {