Merge remote-tracking branch 'upstream/master' into patch-carddb-performance

This commit is contained in:
leriomaggio
2021-08-26 03:03:25 +01:00
26 changed files with 46 additions and 82 deletions

View File

@@ -2704,7 +2704,6 @@ public class ComputerUtil {
for (Trigger trigger : theTriggers) {
final Card source = trigger.getHostCard();
if (!trigger.zonesCheck(game.getZoneOf(source))) {
continue;
}

View File

@@ -89,7 +89,7 @@ public class ComputerUtilCombat {
return ComputerUtilCombat.canAttackNextTurn(attacker, input);
}
});
} // canAttackNextTurn(Card)
}
/**
* <p>
@@ -176,7 +176,6 @@ public class ComputerUtilCombat {
return n;
}
// Returns the damage an unblocked attacker would deal
/**
* <p>
@@ -494,7 +493,6 @@ public class ComputerUtilCombat {
final List<Card> attackers = combat.getAttackersOf(ai);
for (final Card attacker : attackers) {
final List<Card> blockers = combat.getBlockers(attacker);
if (blockers.isEmpty()) {
@@ -696,7 +694,6 @@ public class ComputerUtilCombat {
* @return a boolean.
*/
public static boolean combatantWouldBeDestroyed(Player ai, final Card combatant, Combat combat) {
if (combat.isAttacking(combatant)) {
return ComputerUtilCombat.attackerWouldBeDestroyed(ai, combatant, combat);
}
@@ -2221,7 +2218,6 @@ public class ComputerUtilCombat {
return killDamage;
}
/**
* <p>
* predictDamage.

View File

@@ -1505,7 +1505,7 @@ public class ComputerUtilMana {
}
if (manaToAdd < 1 && !payCosts.getCostMana().canXbe0()) {
// AI cannot really handle X costs properly but this keeps AI form violating rules
// AI cannot really handle X costs properly but this keeps AI from violating rules
manaToAdd = 1;
}

View File

@@ -60,7 +60,6 @@ public class CopySpellAbilityAi extends SpellAbilityAi {
final TargetRestrictions tgt = sa.getTargetRestrictions();
if (tgt != null) {
// Filter AI-specific targets if provided
if ("OnlyOwned".equals(sa.getParam("AITgts"))) {
if (!top.getActivatingPlayer().equals(aiPlayer)) {
@@ -148,4 +147,3 @@ public class CopySpellAbilityAi extends SpellAbilityAi {
}
}

View File

@@ -219,7 +219,6 @@ public class DestroyAi extends SpellAbilityAi {
return false;
}
// target loop
// TODO use can add more Targets
while (sa.getTargets().size() < maxTargets) {
@@ -411,7 +410,6 @@ public class DestroyAi extends SpellAbilityAi {
} else {
return mandatory;
}
}
public boolean doLandForLandRemovalLogic(SpellAbility sa, Player ai, Card tgtLand, String logic) {

View File

@@ -17,7 +17,6 @@ import forge.game.spellability.SpellAbility;
public class TapAi extends TapAiBase {
@Override
protected boolean canPlayAI(Player ai, SpellAbility sa) {
final PhaseHandler phase = ai.getGame().getPhaseHandler();
final Player turn = phase.getPlayerTurn();
@@ -71,7 +70,6 @@ public class TapAi extends TapAiBase {
sa.resetTargets();
return tapPrefTargeting(ai, source, sa, false);
}
}
}

View File

@@ -506,7 +506,6 @@ public class BoosterGenerator {
@SuppressWarnings("unchecked")
public static PrintSheet makeSheet(String sheetKey, Iterable<PaperCard> src) {
PrintSheet ps = new PrintSheet(sheetKey);
String[] sKey = TextUtil.splitWithParenthesis(sheetKey, ' ', 2);
Predicate<PaperCard> setPred = (Predicate<PaperCard>) (sKey.length > 1 ? IPaperCard.Predicates.printedInSets(sKey[1].split(" ")) : Predicates.alwaysTrue());
@@ -517,7 +516,6 @@ public class BoosterGenerator {
// source replacement operators - if one is applied setPredicate will be ignored
Iterator<String> itMod = operators.iterator();
while (itMod.hasNext()) {
String mainCode = itMod.next();
if (mainCode.regionMatches(true, 0, "fromSheet", 0, 9) ||
@@ -529,7 +527,6 @@ public class BoosterGenerator {
setPred = Predicates.alwaysTrue();
} else if (mainCode.startsWith("promo") || mainCode.startsWith("name")) { // get exactly the named cards, that's a tiny inlined print sheet
String list = StringUtils.strip(mainCode.substring(5), "() ");
String[] cardNames = TextUtil.splitWithParenthesis(list, ',', '"', '"');
List<PaperCard> srcList = new ArrayList<>();
@@ -540,25 +537,21 @@ public class BoosterGenerator {
src = srcList;
setPred = Predicates.alwaysTrue();
} else {
continue;
}
itMod.remove();
}
// only special operators should remain by now - the ones that could not be turned into one predicate
String mainCode = operators.isEmpty() ? null : operators.get(0).trim();
if (null == mainCode || mainCode.equalsIgnoreCase(BoosterSlots.ANY)) { // no restriction on rarity
Predicate<PaperCard> predicate = Predicates.and(setPred, extraPred);
ps.addAll(Iterables.filter(src, predicate));
} else if (mainCode.equalsIgnoreCase(BoosterSlots.UNCOMMON_RARE)) { // for sets like ARN, where U1 cards are considered rare and U3 are uncommon
Predicate<PaperCard> predicateRares = Predicates.and(setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred);
ps.addAll(Iterables.filter(src, predicateRares));
@@ -574,25 +567,21 @@ public class BoosterGenerator {
Predicate<PaperCard> predicateRare = Predicates.and( setPred, IPaperCard.Predicates.Presets.IS_RARE, extraPred);
ps.addAll(Iterables.filter(src, predicateRare), 2);
} else {
throw new IllegalArgumentException("Booster generator: operator could not be parsed - " + mainCode);
}
return ps;
}
/**
* This method also modifies passed parameter
*/
private static Predicate<PaperCard> buildExtraPredicate(List<String> operators) {
List<Predicate<PaperCard>> conditions = new ArrayList<>();
Iterator<String> itOp = operators.iterator();
while (itOp.hasNext()) {
String operator = itOp.next();
if (StringUtils.isEmpty(operator)) {
itOp.remove();
@@ -669,7 +658,6 @@ public class BoosterGenerator {
toAdd = Predicates.not(toAdd);
}
conditions.add(toAdd);
}
if (conditions.isEmpty()) {

View File

@@ -273,7 +273,7 @@ public class GameAction {
copied.setState(CardStateName.Original, false);
copied.setBackSide(false);
// reset timestamp in changezone effects so they have same timestamp if ETB simutaneously
// reset timestamp in changezone effects so they have same timestamp if ETB simultaneously
copied.setTimestamp(game.getNextTimestamp());
}
@@ -376,7 +376,7 @@ public class GameAction {
}
cards.set(cards.indexOf(copied), c);
if (zoneTo.is(ZoneType.Library)) {
java.util.Collections.reverse(cards);
Collections.reverse(cards);
}
mergedCards = cards;
if (cause != null) {
@@ -805,6 +805,12 @@ public class GameAction {
Card result = moveTo(game.getStackZone(), c, cause, params);
if (cause != null && cause.isSpell() && result.equals(cause.getHostCard())) {
result.setSplitStateToPlayAbility(cause);
// CR 112.2 A spells controller is, by default, the player who put it on the stack.
result.setController(cause.getActivatingPlayer(), 0);
// for triggers like from Wild-Magic Sorcerer
game.getAction().checkStaticAbilities(false);
game.getTriggerHandler().resetActiveTriggers();
}
return result;
}

View File

@@ -218,8 +218,7 @@ public class AbilityUtils {
if (o instanceof SpellAbility) {
c = ((SpellAbility) o).getHostCard();
}
}
else {
} else {
AbilityKey type = AbilityKey.fromString(defined.substring(9));
final Object crd = root.getTriggeringObject(type);
if (crd instanceof Card) {

View File

@@ -42,7 +42,6 @@ public class CopyPermanentEffect extends TokenEffectBase {
}
final StringBuilder sb = new StringBuilder();
final List<Card> tgtCards = getTargetCards(sa);
sb.append("Copy ");

View File

@@ -120,7 +120,7 @@ public class PlayEffect extends SpellAbilityEffect {
}
if (sa.hasParam("RandomCopied")) {
final CardCollection choice = new CardCollection();
final String num = sa.hasParam("RandomNum") ? sa.getParam("RandomNum") : "1";
final String num = sa.getParamOrDefault("RandomNum", "1");
int ncopied = AbilityUtils.calculateAmount(source, num, sa);
for (PaperCard cp : Aggregates.random(cards, ncopied)) {
final Card possibleCard = Card.fromPaperCard(cp, sa.getActivatingPlayer());
@@ -138,13 +138,11 @@ public class PlayEffect extends SpellAbilityEffect {
source + " - " + Localizer.getInstance().getMessage("lblChooseUpTo") + " " + Lang.nounWithNumeral(choicenum, "card"), 0, choicenum, true, null
)
);
}
else {
} else {
tgtCards = choice;
}
System.err.println("Copying random spell(s): " + tgtCards.toString());
}
else {
} else {
return;
}
} else if (sa.hasParam("CopyFromChosenName")) {

View File

@@ -64,7 +64,7 @@ public class SetStateEffect extends SpellAbilityEffect {
}
// Cards which are not on the battlefield should not be able to transform.
// TurnFace should be allowed in other zones like Exil too
// TurnFace should be allowed in other zones like Exile too
if (!"TurnFace".equals(mode) && !gameCard.isInZone(ZoneType.Battlefield)) {
continue;
}

View File

@@ -4116,7 +4116,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
// of lists. Optimizes common operations such as hasKeyword().
public final void visitKeywords(CardState state, Visitor<KeywordInterface> visitor) {
visitUnhiddenKeywords(state, visitor);
visitHiddenExtreinsicKeywords(visitor);
visitHiddenExtrinsicKeywords(visitor);
}
@Override
@@ -4417,10 +4417,10 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
// Hidden Keywords will be returned without the indicator HIDDEN
public final List<KeywordInterface> getHiddenExtrinsicKeywords() {
ListKeywordVisitor visitor = new ListKeywordVisitor();
visitHiddenExtreinsicKeywords(visitor);
visitHiddenExtrinsicKeywords(visitor);
return visitor.getKeywords();
}
private void visitHiddenExtreinsicKeywords(Visitor<KeywordInterface> visitor) {
private void visitHiddenExtrinsicKeywords(Visitor<KeywordInterface> visitor) {
for (KeywordInterface inst : hiddenExtrinsicKeyword.getValues()) {
if (!visitor.visit(inst)) {
return;
@@ -5492,7 +5492,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
public final void animateBestow() {
animateBestow(true);
}
public final void animateBestow(final boolean updateView) {
if (isBestowed()) {
return;
@@ -5509,7 +5508,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
public final void unanimateBestow() {
unanimateBestow(true);
}
public final void unanimateBestow(final boolean updateView) {
if (!isBestowed()) {
return;
@@ -5602,7 +5600,6 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
public boolean hasProtectionFrom(final Card source, final boolean checkSBA) {
return hasProtectionFrom(source, checkSBA, false);
}
public boolean hasProtectionFrom(final Card source, final boolean checkSBA, final boolean damageSource) {
if (source == null) {
return false;
@@ -5805,6 +5802,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
Collections.sort(ability);
return StringUtils.join(ability.toArray(), ","); //fix nosuchmethod on some android devices...
}
public Zone getZone() {
return currentZone;
}

View File

@@ -1615,7 +1615,6 @@ public class CardFactoryUtil {
replicateTrigger.setOverridingAbility(replicateAbility);
replicateTrigger.setSVar("ReplicateAmount", "0");
inst.addTrigger(replicateTrigger);
} else if (keyword.startsWith("Ripple")) {
final String[] k = keyword.split(":");
final String num = k[1];

View File

@@ -147,8 +147,7 @@ public class SpellAbilityStackInstance implements IIdentifiable, IHasCardView {
//store zones to open and players to open them for at the time the SpellAbility first goes on the stack based on the selected targets
if (tc == null) {
playersWithValidTargets = null;
}
else {
} else {
playersWithValidTargets = Maps.newHashMap();
for (Card card : tc.getTargetCards()) {
ZoneType zoneType = card.getZone() != null ? card.getZone().getZoneType() : null;

View File

@@ -698,7 +698,6 @@ public class StaticAbility extends CardTraitBase implements IIdentifiable, Clone
return layers;
}
public int getMayPlayTurn() {
return mayPlayTurn;
}

View File

@@ -7,7 +7,6 @@ import forge.game.player.Player;
public class StaticAbilityCantPutCounter {
public static boolean applyCantPutCounter(final StaticAbility stAb, final Card card, final CounterType type) {
if (stAb.hasParam("CounterType")) {
CounterType t = CounterType.getType(stAb.getParam("CounterType"));
if (t != null && !type.equals(t)) {
@@ -26,7 +25,6 @@ public class StaticAbilityCantPutCounter {
}
public static boolean applyCantPutCounter(final StaticAbility stAb, final Player player, final CounterType type) {
if (stAb.hasParam("CounterType")) {
CounterType t = CounterType.getType(stAb.getParam("CounterType"));
if (t != null && !type.equals(t)) {

View File

@@ -135,8 +135,7 @@ public abstract class Trigger extends TriggerReplacementBase {
String currentName;
if (this.isIntrinsic() && cardState != null && cardState.getCard() == getHostCard()) {
currentName = cardState.getName();
}
else {
} else {
currentName = getHostCard().getName();
}
String desc = getParam("TriggerDescription");
@@ -169,7 +168,6 @@ public abstract class Trigger extends TriggerReplacementBase {
SpellAbility sa = ensureAbility();
return replaceAbilityText(desc, sa);
}
public final String replaceAbilityText(final String desc, SpellAbility sa) {
@@ -355,7 +353,6 @@ public abstract class Trigger extends TriggerReplacementBase {
return true;
}
public boolean meetsRequirementsOnTriggeredObjects(Game game, final Map<AbilityKey, Object> runParams) {
if ("True".equals(getParam("EvolveCondition"))) {
final Card moved = (Card) runParams.get(AbilityKey.Card);

View File

@@ -455,10 +455,6 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
game.getPhaseHandler().setPriority(sp.getActivatingPlayer());
}
//FIXME: additional check cmc, etc..
game.getTriggerHandler().resetActiveTriggers();
game.getAction().checkStaticAbilities();
if (sp.isSpell() && !sp.isCopied()) {
thisTurnCast.add(CardUtil.getLKICopy(sp.getHostCard()));
sp.getActivatingPlayer().addSpellCastThisTurn();

View File

@@ -312,7 +312,6 @@ public class ImageCache {
if (1 == bestFitScale) {
result = original;
} else {
int destWidth = (int)(original.getWidth() * bestFitScale);
int destHeight = (int)(original.getHeight() * bestFitScale);

View File

@@ -4,7 +4,7 @@ Types:Creature Tiefling Rogue
PT:3/2
T:Mode$ DamageDoneOnce | CombatDamage$ True | ValidSource$ Creature.YouCtrl | TriggerZones$ Battlefield | ValidTarget$ Player | Execute$ DBToken | TriggerDescription$ Whenever one or more creatures you control deal combat damage to a player, create two Treasure tokens.
SVar:DBToken:DB$ Token | TokenAmount$ 2 | TokenScript$ c_a_treasure_sac | TokenOwner$ You
A:AB$ Pump | Cost$ 4 B Sac<X/Treasure> | SorcerySpeed$ True | ValidTgts$ Creature | TgtPrompt$ Select target creature | IsCurse$ True | NumAtt$ -X | NumDef$ -X | SpellDescription$ Target creature gets -X/-X until end of turn. Activate only as a sorcery.
A:AB$ Pump | Cost$ B Sac<X/Treasure> | SorcerySpeed$ True | ValidTgts$ Creature | TgtPrompt$ Select target creature | IsCurse$ True | NumAtt$ -X | NumDef$ -X | SpellDescription$ Target creature gets -X/-X until end of turn. Activate only as a sorcery.
SVar:X:Count$xPaid
DeckHas:Ability$Token & Ability$Sacrifice
Oracle:Whenever one or more creatures you control deal combat damage to a player, create two Treasure tokens.\n{B}, Sacrifice X Treasures: Target creature gets -X/-X until end of turn. Activate only as a sorcery.