Skip to content

Commit 1bb1a3d

Browse files
authored
Affinity: extra class for the special cases (Card-Forge#10007)
* Affinity: extra class for the special cases * Update CardFactoryUtil.java Keyword String not used
1 parent a736364 commit 1bb1a3d

File tree

7 files changed

+53
-32
lines changed

7 files changed

+53
-32
lines changed

forge-game/src/main/java/forge/game/card/CardFactoryUtil.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,23 +3824,12 @@ public void resolve() {
38243824
public static void addStaticAbility(final KeywordInterface inst, final CardState state, final boolean intrinsic) {
38253825
String keyword = inst.getOriginal();
38263826

3827-
if (keyword.startsWith("Affinity")) {
3828-
final String[] k = keyword.split(":");
3829-
final String t = k[1];
3830-
3831-
String desc;
3832-
if (k.length > 2) {
3833-
String typeText = k[2];
3834-
if (typeText.contains(" with "))
3835-
desc = typeText.substring(typeText.indexOf(" with ") + 6);
3836-
else
3837-
desc = typeText + "s";
3838-
} else
3839-
desc = CardType.getPluralType(t);
3827+
if (inst instanceof Affinity affinity) {
3828+
final String t = affinity.getValidType();
38403829

38413830
StringBuilder sb = new StringBuilder();
38423831
sb.append("Mode$ ReduceCost | ValidCard$ Card.Self | Type$ Spell | Amount$ AffinityX | EffectZone$ All");
3843-
sb.append("| Description$ Affinity for ").append(desc);
3832+
sb.append("| Description$ ").append(affinity.getTitle());
38443833
sb.append(" (").append(inst.getReminderText()).append(")");
38453834
String effect = sb.toString();
38463835

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package forge.game.keyword;
2+
3+
import java.util.Arrays;
4+
5+
import forge.card.CardType;
6+
import forge.util.Lang;
7+
8+
public class Affinity extends KeywordWithType {
9+
10+
@Override
11+
public String getTitle() {
12+
StringBuilder sb = new StringBuilder();
13+
sb.append("Affinity for ").append(descType);
14+
return sb.toString();
15+
}
16+
17+
@Override
18+
protected void parse(String details) {
19+
if ("Affinity".equalsIgnoreCase(details)) {
20+
type = "Permanent.withAffinity";
21+
descType = "Affinity";
22+
reminderType = "permanent with affinity"; // technically the reminder says "permanent you control with affinity", but thats a TestCard
23+
} else if ("Outlaw".equalsIgnoreCase(details)) {
24+
type = "Permanent.Outlaw";
25+
descType = "outlaws";
26+
reminderType = Lang.getInstance().buildValidDesc(CardType.Constant.OUTLAW_TYPES, true);
27+
} else if ("Historic".equalsIgnoreCase(details)) {
28+
type = "Permanent.Historic";
29+
descType = "historic permanents";
30+
reminderType = "artifact, legendary, and/or Saga permanent";
31+
} else if (details.contains(":")) {
32+
String k[];
33+
k = details.split(":");
34+
type = k[0];
35+
descType = Lang.getPlural(k[1]);
36+
reminderType = k[1];
37+
} else {
38+
type = details;
39+
descType = CardType.getPluralType(type);
40+
reminderType = Lang.getInstance().buildValidDesc(Arrays.asList(type.split(",")), true);
41+
}
42+
}
43+
}

forge-game/src/main/java/forge/game/keyword/Keyword.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public enum Keyword {
1010
UNDEFINED("", SimpleKeyword.class, false, ""),
1111
ABSORB("Absorb", KeywordWithAmount.class, false, "If a source would deal damage to this creature, prevent %d of that damage."),
12-
AFFINITY("Affinity", KeywordWithType.class, false, "This spell costs {1} less to cast for each %s you control."),
12+
AFFINITY("Affinity", Affinity.class, false, "This spell costs {1} less to cast for each %s you control."),
1313
AFFLICT("Afflict", KeywordWithAmount.class, false, "Whenever this creature becomes blocked, defending player loses %d life."),
1414
AFTERLIFE("Afterlife", KeywordWithAmount.class, false, "When this creature dies, create {%1$d:1/1 white and black Spirit creature token} with flying."),
1515
AFTERMATH("Aftermath", SimpleKeyword.class, false, "Cast this spell only from your graveyard. Then exile it."),

forge-game/src/main/java/forge/game/keyword/KeywordWithType.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ protected void parse(String details) {
2929
String k[];
3030
if (details.contains(":")) {
3131
switch (getKeyword()) {
32-
case AFFINITY:
3332
case BANDSWITH:
3433
case ENCHANT:
3534
case HEXPROOF:
@@ -49,22 +48,12 @@ protected void parse(String details) {
4948
type = "Card." + StringUtils.capitalize(color.getName());
5049
descType = color.getName();
5150
} else {
52-
descType = type = details;
53-
boolean multiple = switch(getKeyword()) {
54-
case AFFINITY -> true;
55-
default -> false;
56-
};
57-
descType = Lang.getInstance().buildValidDesc(Arrays.asList(type.split(",")), multiple);
51+
type = details;
52+
descType = Lang.getInstance().buildValidDesc(Arrays.asList(type.split(",")), false);
5853
}
5954
}
6055

61-
if (descType.equalsIgnoreCase("Outlaw")) {
62-
reminderType = "Assassin, Mercenary, Pirate, Rogue, and/or Warlock";
63-
} else if (type.equalsIgnoreCase("historic permanent")) {
64-
reminderType = "artifact, legendary, and/or Saga permanent";
65-
} else {
66-
reminderType = descType;
67-
}
56+
reminderType = descType;
6857
}
6958

7059
@Override

forge-gui/res/cardsfolder/b/banish_to_another_universe.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Name:Banish to Another Universe
22
ManaCost:4 W
33
Types:Enchantment
4-
K:Affinity:Permanent.Historic:historic permanent
4+
K:Affinity:Historic
55
T:Mode$ ChangesZone | Origin$ Any | Destination$ Battlefield | ValidCard$ Card.Self | Execute$ TrigExile | TriggerDescription$ When CARDNAME enters, exile target nonland permanent an opponent controls until CARDNAME leaves the battlefield.
66
SVar:TrigExile:DB$ ChangeZone | Origin$ Battlefield | Destination$ Exile | ValidTgts$ Permanent.nonLand+OppCtrl | TgtPrompt$ Select target nonland permanent an opponent controls | Duration$ UntilHostLeavesPlay
77
SVar:PlayMain1:TRUE

forge-gui/res/cardsfolder/h/hellspur_brute.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Name:Hellspur Brute
22
ManaCost:4 R
33
Types:Creature Minotaur Mercenary
44
PT:5/4
5-
K:Affinity:Permanent.Outlaw:outlaw
5+
K:Affinity:Outlaw
66
K:Trample
77
DeckHints:Type$Assassin|Mercenary|Pirate|Rogue|Warlock
88
Oracle:Affinity for outlaws (This spell costs {1} less to cast for each Assassin, Mercenary, Pirate, Rogue, and/or Warlock you control.)\nTrample

forge-gui/res/cardsfolder/s/sojourners_enforcermite.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ Name:Sojourner's Enforcermite
22
ManaCost:6
33
Types:Artifact Creature Frog Myr Salamander
44
PT:6/6
5-
K:Affinity:Permanent.withAffinity:permanent with affinity
5+
K:Affinity:Affinity
66
K:TypeCycling:Affinity:2
77
Oracle:Affinity for Affinity (This card costs {1} less to cast for each permanent you control with affinity.)\nAffinitycycling {2} ({2}, Discard this card: Search your library for a card with affinity, reveal it, put it into your hand, then shuffle.)

0 commit comments

Comments
 (0)