mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Optimize static effect checks even more based on profiling.
This commit is contained in:
@@ -56,12 +56,17 @@ import java.util.Map;
|
|||||||
public final class GameActionUtil {
|
public final class GameActionUtil {
|
||||||
// Cache these instead of generating them on the fly, to avoid excessive allocations every time
|
// Cache these instead of generating them on the fly, to avoid excessive allocations every time
|
||||||
// static abilities are checked.
|
// static abilities are checked.
|
||||||
private static final String[] BASIC_LAND_ABILITIES = new String[MagicColor.WUBRG.length];
|
@SuppressWarnings("unchecked")
|
||||||
|
private static final Map<String, String>[] BASIC_LAND_ABILITIES_PARAMS = new Map[MagicColor.WUBRG.length];
|
||||||
|
private static final AbilityRecordType[] BASIC_LAND_ABILITIES_TYPES = new AbilityRecordType[MagicColor.WUBRG.length];
|
||||||
static {
|
static {
|
||||||
for (int i = 0; i < MagicColor.WUBRG.length; i++ ) {
|
for (int i = 0; i < MagicColor.WUBRG.length; i++ ) {
|
||||||
String color = MagicColor.toShortString(MagicColor.WUBRG[i]);
|
String color = MagicColor.toShortString(MagicColor.WUBRG[i]);
|
||||||
BASIC_LAND_ABILITIES[i] = "AB$ Mana | Cost$ T | Produced$ " + color +
|
String abString = "AB$ Mana | Cost$ T | Produced$ " + color +
|
||||||
" | SpellDescription$ Add {" + color + "} to your mana pool.";
|
" | SpellDescription$ Add {" + color + "} to your mana pool.";
|
||||||
|
Map<String, String> mapParams = AbilityFactory.getMapParams(abString);
|
||||||
|
BASIC_LAND_ABILITIES_PARAMS[i] = mapParams;
|
||||||
|
BASIC_LAND_ABILITIES_TYPES[i] = AbilityRecordType.getRecordType(mapParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,10 +144,11 @@ public final class GameActionUtil {
|
|||||||
// add all appropriate mana abilities based on current types
|
// add all appropriate mana abilities based on current types
|
||||||
for (int i = 0; i < MagicColor.WUBRG.length; i++ ) {
|
for (int i = 0; i < MagicColor.WUBRG.length; i++ ) {
|
||||||
String landType = MagicColor.Constant.BASIC_LANDS.get(i);
|
String landType = MagicColor.Constant.BASIC_LANDS.get(i);
|
||||||
String abString = BASIC_LAND_ABILITIES[i];
|
Map<String, String> mapParams = BASIC_LAND_ABILITIES_PARAMS[i];
|
||||||
|
AbilityRecordType type = BASIC_LAND_ABILITIES_TYPES[i];
|
||||||
for (final Card land : lands) {
|
for (final Card land : lands) {
|
||||||
if (land.getType().hasSubtype(landType)) {
|
if (land.getType().hasSubtype(landType)) {
|
||||||
final SpellAbility sa = AbilityFactory.getAbility(abString, land);
|
final SpellAbility sa = AbilityFactory.getAbility(mapParams, type, land);
|
||||||
sa.setBasicLandAbility(true);
|
sa.setBasicLandAbility(true);
|
||||||
land.getCurrentState().addManaAbility(sa);
|
land.getCurrentState().addManaAbility(sa);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,16 +99,20 @@ public final class AbilityFactory {
|
|||||||
catch (RuntimeException ex) {
|
catch (RuntimeException ex) {
|
||||||
throw new RuntimeException(hostCard.getName() + ": " + ex.getMessage());
|
throw new RuntimeException(hostCard.getName() + ": " + ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse universal parameters
|
// parse universal parameters
|
||||||
AbilityRecordType type = AbilityRecordType.getRecordType(mapParams);
|
AbilityRecordType type = AbilityRecordType.getRecordType(mapParams);
|
||||||
if (null == type) {
|
if (null == type) {
|
||||||
String source = hostCard.getName().isEmpty() ? abString : hostCard.getName();
|
String source = hostCard.getName().isEmpty() ? abString : hostCard.getName();
|
||||||
throw new RuntimeException("AbilityFactory : getAbility -- no API in " + source);
|
throw new RuntimeException("AbilityFactory : getAbility -- no API in " + source);
|
||||||
}
|
}
|
||||||
|
return getAbility(mapParams, type, hostCard);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final SpellAbility getAbility(final Map<String, String> mapParams, AbilityRecordType type, final Card hostCard) {
|
||||||
return getAbility(type, type.getApiTypeOf(mapParams), mapParams, parseAbilityCost(hostCard, mapParams, type), hostCard);
|
return getAbility(type, type.getApiTypeOf(mapParams), mapParams, parseAbilityCost(hostCard, mapParams, type), hostCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Cost parseAbilityCost(final Card hostCard, Map<String, String> mapParams, AbilityRecordType type) {
|
public static Cost parseAbilityCost(final Card hostCard, Map<String, String> mapParams, AbilityRecordType type) {
|
||||||
Cost abCost = null;
|
Cost abCost = null;
|
||||||
if (type != AbilityRecordType.SubAbility) {
|
if (type != AbilityRecordType.SubAbility) {
|
||||||
|
|||||||
Reference in New Issue
Block a user