mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Merge pull request #295 from tool4ever/scriptparser
Small improvement to CardScriptParser
This commit is contained in:
@@ -596,7 +596,7 @@ public class PumpAi extends PumpAiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} // pumpTgtAI()
|
}
|
||||||
|
|
||||||
private boolean pumpMandatoryTarget(final Player ai, final SpellAbility sa) {
|
private boolean pumpMandatoryTarget(final Player ai, final SpellAbility sa) {
|
||||||
final Game game = ai.getGame();
|
final Game game = ai.getGame();
|
||||||
@@ -657,7 +657,7 @@ public class PumpAi extends PumpAiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} // pumpMandatoryTarget()
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
@@ -706,7 +706,7 @@ public class PumpAi extends PumpAiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} // pumpTriggerAI
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
|
||||||
@@ -778,7 +778,7 @@ public class PumpAi extends PumpAiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} // pumpDrawbackAI()
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
} // getPumpCreatures()
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -519,7 +519,7 @@ public abstract class PumpAiBase extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
} // getCurseCreatures()
|
}
|
||||||
|
|
||||||
protected boolean containsNonCombatKeyword(final List<String> keywords) {
|
protected boolean containsNonCombatKeyword(final List<String> keywords) {
|
||||||
for (final String keyword : keywords) {
|
for (final String keyword : keywords) {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ import io.sentry.Sentry;
|
|||||||
*/
|
*/
|
||||||
public final class AbilityFactory {
|
public final class AbilityFactory {
|
||||||
|
|
||||||
static final List<String> additionalAbilityKeys = Lists.newArrayList(
|
public static final List<String> additionalAbilityKeys = Lists.newArrayList(
|
||||||
"WinSubAbility", "OtherwiseSubAbility", // Clash
|
"WinSubAbility", "OtherwiseSubAbility", // Clash
|
||||||
"BidSubAbility", // BidLifeEffect
|
"BidSubAbility", // BidLifeEffect
|
||||||
"ChooseNumberSubAbility", "Lowest", "Highest", "NotLowest", // ChooseNumber
|
"ChooseNumberSubAbility", "Lowest", "Highest", "NotLowest", // ChooseNumber
|
||||||
@@ -80,7 +80,7 @@ public final class AbilityFactory {
|
|||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpellAbility buildSpellAbility(ApiType api, Card hostCard, Cost abCost, TargetRestrictions abTgt, Map<String, String> mapParams ) {
|
public SpellAbility buildSpellAbility(ApiType api, Card hostCard, Cost abCost, TargetRestrictions abTgt, Map<String, String> mapParams) {
|
||||||
switch(this) {
|
switch(this) {
|
||||||
case Ability: return new AbilityApiBased(api, hostCard, abCost, abTgt, mapParams);
|
case Ability: return new AbilityApiBased(api, hostCard, abCost, abTgt, mapParams);
|
||||||
case Spell: return new SpellApiBased(api, hostCard, abCost, abTgt, mapParams);
|
case Spell: return new SpellApiBased(api, hostCard, abCost, abTgt, mapParams);
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import com.google.common.collect.Maps;
|
|||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import forge.card.CardType;
|
import forge.card.CardType;
|
||||||
|
import forge.game.ability.AbilityFactory;
|
||||||
|
import forge.game.ability.AbilityFactory.AbilityRecordType;
|
||||||
import forge.game.ability.ApiType;
|
import forge.game.ability.ApiType;
|
||||||
import forge.game.replacement.ReplacementType;
|
import forge.game.replacement.ReplacementType;
|
||||||
import forge.game.trigger.TriggerType;
|
import forge.game.trigger.TriggerType;
|
||||||
@@ -74,6 +76,7 @@ public final class CardScriptParser {
|
|||||||
bad = true;
|
bad = true;
|
||||||
}
|
}
|
||||||
} else if (trimLine.startsWith("A:")) {
|
} else if (trimLine.startsWith("A:")) {
|
||||||
|
// TODO check if it's non-permanent, then Cost$ isn't mandatory
|
||||||
result.putAll(getActivatedAbilityErrors(trimLine.substring("A:".length()), index + "A:".length()));
|
result.putAll(getActivatedAbilityErrors(trimLine.substring("A:".length()), index + "A:".length()));
|
||||||
} else if (trimLine.startsWith("R:")) {
|
} else if (trimLine.startsWith("R:")) {
|
||||||
result.putAll(getReplacementErrors(trimLine.substring("R:".length()), index + "R:".length()));
|
result.putAll(getReplacementErrors(trimLine.substring("R:".length()), index + "R:".length()));
|
||||||
@@ -221,7 +224,7 @@ public final class CardScriptParser {
|
|||||||
if (trimValue.isEmpty()) {
|
if (trimValue.isEmpty()) {
|
||||||
isBadValue = true;
|
isBadValue = true;
|
||||||
}
|
}
|
||||||
} else if (trimKey.equals("SubAbility")) {
|
} else if (trimKey.equals("SubAbility") || AbilityFactory.additionalAbilityKeys.contains(trimKey)) {
|
||||||
if (sVars.contains(trimValue)) {
|
if (sVars.contains(trimValue)) {
|
||||||
sVarAbilities.add(trimValue);
|
sVarAbilities.add(trimValue);
|
||||||
} else {
|
} else {
|
||||||
@@ -315,7 +318,10 @@ public final class CardScriptParser {
|
|||||||
|
|
||||||
private static boolean isAbilityApiDeclarerLegal(final String declarer) {
|
private static boolean isAbilityApiDeclarerLegal(final String declarer) {
|
||||||
final String tDeclarer = declarer.trim();
|
final String tDeclarer = declarer.trim();
|
||||||
return tDeclarer.equals("AB") || tDeclarer.equals("DB") || tDeclarer.equals("SP");
|
for (AbilityRecordType type : AbilityRecordType.values()) {
|
||||||
|
if (type.getPrefix().equals(tDeclarer)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
private static boolean isAbilityApiLegal(final String api) {
|
private static boolean isAbilityApiLegal(final String api) {
|
||||||
try {
|
try {
|
||||||
@@ -506,7 +512,10 @@ public final class CardScriptParser {
|
|||||||
"RememberMap", "wasCastFrom", "wasNotCastFrom", "set",
|
"RememberMap", "wasCastFrom", "wasNotCastFrom", "set",
|
||||||
"inZone", "HasSVar");
|
"inZone", "HasSVar");
|
||||||
|
|
||||||
private static boolean isValidExclusive(final String valid) {
|
private static boolean isValidExclusive(String valid) {
|
||||||
|
if (valid.charAt(0) == '!') {
|
||||||
|
valid = valid.substring(1);
|
||||||
|
}
|
||||||
if (VALID_EXCLUSIVE.contains(valid)) {
|
if (VALID_EXCLUSIVE.contains(valid)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user