Skip to content

Commit 41d990b

Browse files
authored
Some cleanup (Card-Forge#9413)
1 parent 8f9399b commit 41d990b

File tree

72 files changed

+102
-109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+102
-109
lines changed

docs/Card-scripting-API/AbilityFactory.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Syntax definitions like the above will use different symbols to separate the var
1515
- curly brackets to denote the type of a parameter
1616

1717
>*NOTE:*
18-
> - these factories are refactored from time to time (often to adapt to new sets), so while some entries could be slightly outdated, the base information should still be correct
18+
> - these factories are refactored from time to time (often to adapt to new mechanics), so while some entries could be slightly outdated, the base information should still be correct
1919
> - when in doubt you can always cross-check with the [available APIs](https://github.com/Card-Forge/forge/tree/master/forge-game/src/main/java/forge/game/ability/effects) code
2020
> - a few factories also have _*All_ variants, these are slowly being phased out
2121
> - some parameters are only added for very exotic cards, these won't be included here to keep the focus on understanding the general concepts of scripting
@@ -27,7 +27,7 @@ Syntax definitions like the above will use different symbols to separate the var
2727
## Cost / UnlessCost
2828
`Cost$ {AbilityCost}` is the appropriate way to set the cost of the ability. Currently for spells, any additional costs including the original Mana cost need to appear in the Cost param in the AbilityFactory. For each card that uses it, the order in which the cost is paid will always be the same.
2929

30-
Secondary abilities such as the DB executed by triggers or replacements (usually) don't need costs. (This is one reason to use DB over AB in these cases.)
30+
Secondary abilities such as those executed by triggers or replacements (usually) don't need costs. (This is one reason to use DB over AB in these cases.)
3131

3232
Read more about it in [Costs](Costs.md)
3333

@@ -305,6 +305,8 @@ Parameters:
305305

306306
## Fight
307307

308+
## FlipACoin
309+
308310
## Fog
309311
This AF is based on the original *Fog* spell: "Prevent all combat damage that would be dealt this turn." While this could be done with an Effect, the specialized nature of the AI gives it its own AF.
310312

@@ -406,7 +408,7 @@ SVar:DBExchange:DB$ ExchangeControl | Defined$ ParentTarget | ValidTgts$ Land.Op
406408
```
407409

408410
## Regenerate
409-
Regenerate is for creating regeneration shields.
411+
Creating regeneration shields.
410412

411413
## Reveal
412414

@@ -468,7 +470,7 @@ The trigger-specific params are defined in [Triggers](Triggers.md).
468470

469471
### ImmediateTrigger
470472
Parameters:
471-
- `TriggerAmount$ {Integer}`
473+
- `TriggerAmount$ {Integer}` (Default: 1)
472474

473475
## Turn structure
474476

forge-ai/src/main/java/forge/ai/ComputerUtilCost.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static boolean checkRemoveCounterCost(final Cost cost, final Card source,
8989
// ignore Loyality abilities with Zero as Cost
9090
if (!type.is(CounterEnumType.LOYALTY)) {
9191
PaymentDecision pay = decision.visit(remCounter);
92-
if (pay == null || pay.c <= 0) {
92+
if (pay == null || pay.counterTable.totalValues() <= 0) {
9393
return false;
9494
}
9595
}

forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private static AiAbilityDecision hiddenOriginCanPlayAI(final Player ai, final Sp
321321
}
322322
}
323323

324-
Iterable<Player> pDefined = Lists.newArrayList(source.getController());
324+
Iterable<Player> pDefined;
325325
final TargetRestrictions tgt = sa.getTargetRestrictions();
326326
if (tgt != null && tgt.canTgtPlayer()) {
327327
sa.resetTargets();
@@ -335,12 +335,10 @@ private static AiAbilityDecision hiddenOriginCanPlayAI(final Player ai, final Sp
335335
return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
336336
}
337337
pDefined = sa.getTargets().getTargetPlayers();
338+
} else if (sa.hasParam("DefinedPlayer")) {
339+
pDefined = AbilityUtils.getDefinedPlayers(source, sa.getParam("DefinedPlayer"), sa);
338340
} else {
339-
if (sa.hasParam("DefinedPlayer")) {
340-
pDefined = AbilityUtils.getDefinedPlayers(source, sa.getParam("DefinedPlayer"), sa);
341-
} else {
342-
pDefined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
343-
}
341+
pDefined = AbilityUtils.getDefinedPlayers(source, sa.getParam("Defined"), sa);
344342
}
345343

346344
String type = sa.getParam("ChangeType");

forge-ai/src/main/java/forge/ai/ability/ChooseCardAi.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ public Card chooseSingleCard(final Player ai, final SpellAbility sa, Iterable<Ca
170170
ownChoices = CardLists.filter(options, CardPredicates.isControlledByAnyOf(ai.getAllies()));
171171
}
172172
choice = ComputerUtilCard.getBestAI(ownChoices);
173-
} else if (logic.equals("BestBlocker")) {
173+
} else if ("BestBlocker".equals(logic)) {
174174
if (IterableUtil.any(options, CardPredicates.UNTAPPED)) {
175175
options = CardLists.filter(options, CardPredicates.UNTAPPED);
176176
}
177177
choice = ComputerUtilCard.getBestCreatureAI(options);
178-
} else if (logic.equals("Clone")) {
178+
} else if ("Clone".equals(logic)) {
179179
final String filter = "Permanent.YouDontCtrl,Permanent.nonLegendary";
180180
CardCollection newOptions = CardLists.getValidCards(options, filter, ctrl, host, sa);
181181
if (!newOptions.isEmpty()) {
@@ -185,7 +185,7 @@ public Card chooseSingleCard(final Player ai, final SpellAbility sa, Iterable<Ca
185185
} else if ("RandomNonLand".equals(logic)) {
186186
options = CardLists.getValidCards(options, "Card.nonLand", host.getController(), host, sa);
187187
choice = Aggregates.random(options);
188-
} else if (logic.equals("NeedsPrevention")) {
188+
} else if ("NeedsPrevention".equals(logic)) {
189189
final Game game = ai.getGame();
190190
final Combat combat = game.getCombat();
191191
CardCollectionView better = CardLists.filter(options, c -> {
@@ -242,7 +242,7 @@ public Card chooseSingleCard(final Player ai, final SpellAbility sa, Iterable<Ca
242242
} else {
243243
choice = ComputerUtilCard.getWorstPermanentAI(options, false, false, false, false);
244244
}
245-
} else if (logic.equals("Duneblast")) {
245+
} else if ("Duneblast".equals(logic)) {
246246
CardCollectionView aiCreatures = ai.getCreaturesInPlay();
247247
aiCreatures = CardLists.getNotKeyword(aiCreatures, Keyword.INDESTRUCTIBLE);
248248

@@ -252,15 +252,15 @@ public Card chooseSingleCard(final Player ai, final SpellAbility sa, Iterable<Ca
252252

253253
Card chosen = ComputerUtilCard.getBestCreatureAI(aiCreatures);
254254
return chosen;
255-
} else if (logic.equals("OrzhovAdvokist")) {
255+
} else if ("OrzhovAdvokist".equals(logic)) {
256256
if (ai.equals(sa.getActivatingPlayer()) || // who cares if you can't attack yourself
257257
(ai.getOpponents().size() > 1 && // if there is another opponent good to attack, take the counters
258258
!AiAttackController.choosePreferredDefenderPlayer(ai).equals(sa.getActivatingPlayer()))) {
259259
choice = ComputerUtilCard.getBestAI(options);
260260
// TODO: would also be nice to take the counters if not in a good position to attack anyway
261261
// – might also be good to do a separate AI for Noble Heritage
262262
}
263-
} else if (logic.equals("Phylactery")) {
263+
} else if ("Phylactery".equals(logic)) {
264264
CardCollection aiArtifacts = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.ARTIFACTS);
265265
CardCollection indestructibles = CardLists.filter(aiArtifacts, CardPredicates.hasKeyword(Keyword.INDESTRUCTIBLE));
266266
CardCollection nonCreatures = CardLists.filter(aiArtifacts, CardPredicates.NON_CREATURES);
@@ -276,7 +276,7 @@ public Card chooseSingleCard(final Player ai, final SpellAbility sa, Iterable<Ca
276276
// Choose the best (hopefully the fattest, whatever) creature so that hopefully it won't die too easily
277277
choice = ComputerUtilCard.getBestAI(creatures);
278278
}
279-
} else if (logic.equals("NextTurnAttacker")) {
279+
} else if ("NextTurnAttacker".equals(logic)) {
280280
choice = ComputerUtilCard.getBestCreatureToAttackNextTurnAI(ai, options);
281281
} else {
282282
choice = ComputerUtilCard.getBestAI(options);

forge-core/src/main/java/forge/item/SealedProduct.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public String toString() {
101101

102102
protected List<PaperCard> generate() {
103103
return BoosterGenerator.getBoosterPack(contents);
104-
105104
}
106105

107106
protected PaperCard getRandomBasicLand(final String setCode) {

forge-game/src/main/java/forge/game/Game.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ public Game(Iterable<RegisteredPlayer> players0, GameRules rules0, Match match0,
372372

373373
sbaCheckedCommandList = new ArrayList<>();
374374

375-
// update players
376375
view.updatePlayers(this);
377376

378377
subscribeToEvents(gameLog.getEventVisitor());

forge-game/src/main/java/forge/game/ability/AbilityUtils.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ public static CardCollection getDefinedCards(final Card hostCard, final String d
7373
player = hostCard.getController();
7474
}
7575

76-
if (defined.contains("AndSelf")) {
77-
cards.add(hostCard);
78-
defined = defined.replace("AndSelf", "");
79-
}
80-
8176
if (defined.equals("Self")) {
8277
c = hostCard;
8378
} else if (defined.equals("CorrectedSelf")) {

forge-game/src/main/java/forge/game/cost/CostRemoveAnyCounter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ public boolean payAsDecided(Player ai, PaymentDecision decision, SpellAbility ab
129129
removed += v.getValue();
130130
e.getKey().subtractCounter(v.getKey(), v.getValue(), ai);
131131
}
132-
if (e.getKey() instanceof Card) {
133-
e.getKey().getGame().updateLastStateForCard((Card) e.getKey());
132+
if (e.getKey() instanceof Card c) {
133+
e.getKey().getGame().updateLastStateForCard(c);
134134
}
135135
}
136136

forge-game/src/main/java/forge/game/cost/CostRemoveCounter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ public boolean payAsDecided(Player ai, PaymentDecision decision, SpellAbility ab
187187
removed += v.getValue();
188188
e.getKey().subtractCounter(v.getKey(), v.getValue(), ai);
189189
}
190-
if (e.getKey() instanceof Card) {
191-
e.getKey().getGame().updateLastStateForCard((Card) e.getKey());
190+
if (e.getKey() instanceof Card c) {
191+
e.getKey().getGame().updateLastStateForCard(c);
192192
}
193193
}
194194

forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public static CardCollectionView applyContinuousAbility(final StaticAbility stAb
491491

492492
if (params.containsKey("IgnoreEffectCost")) {
493493
String cost = params.get("IgnoreEffectCost");
494-
buildIgnorEffectAbility(stAb, cost, affectedPlayers, affectedCards);
494+
buildIgnoreEffectAbility(stAb, cost, affectedPlayers, affectedCards);
495495
}
496496
}
497497

@@ -940,7 +940,7 @@ private static ColorSet getColorsFromParam(StaticAbility stAb, final String colo
940940
return addColors;
941941
}
942942

943-
private static void buildIgnorEffectAbility(final StaticAbility stAb, final String costString, final List<Player> players, final CardCollectionView cards) {
943+
private static void buildIgnoreEffectAbility(final StaticAbility stAb, final String costString, final List<Player> players, final CardCollectionView cards) {
944944
final List<Player> validActivator = new ArrayList<>(players);
945945
for (final Card c : cards) {
946946
validActivator.add(c.getController());

0 commit comments

Comments
 (0)