From af4a6de809c3f24c17e38b6527e8ee6e6a061c4b Mon Sep 17 00:00:00 2001 From: tool4ever Date: Fri, 25 Jul 2025 07:02:57 +0200 Subject: [PATCH] Refactor Offering (#8199) --- .../src/main/java/forge/game/GameActionUtil.java | 4 ++-- forge-game/src/main/java/forge/game/card/Card.java | 8 ++++---- .../src/main/java/forge/game/card/CardUtil.java | 10 +--------- .../main/java/forge/game/cost/CostAdjustment.java | 2 +- .../src/main/java/forge/game/keyword/Keyword.java | 14 -------------- .../res/cardsfolder/b/blast_furnace_hellkite.txt | 2 +- forge-gui/res/cardsfolder/p/patron_of_the_akki.txt | 2 +- .../res/cardsfolder/p/patron_of_the_kitsune.txt | 2 +- forge-gui/res/cardsfolder/p/patron_of_the_moon.txt | 2 +- .../res/cardsfolder/p/patron_of_the_nezumi.txt | 2 +- .../res/cardsfolder/p/patron_of_the_orochi.txt | 2 +- 11 files changed, 14 insertions(+), 36 deletions(-) diff --git a/forge-game/src/main/java/forge/game/GameActionUtil.java b/forge-game/src/main/java/forge/game/GameActionUtil.java index 73b4651689c..01cb02ea4ce 100644 --- a/forge-game/src/main/java/forge/game/GameActionUtil.java +++ b/forge-game/src/main/java/forge/game/GameActionUtil.java @@ -495,8 +495,8 @@ public final class GameActionUtil { String[] k = keyword.split(":"); final Cost cost = new Cost(k[1], false); costs.add(new OptionalCostValue(OptionalCost.Flash, cost)); - } else if (keyword.endsWith(" offering")) { - final String type = keyword.split(" ")[0]; + } else if (keyword.startsWith("Offering")) { + final String type = keyword.split(":")[1]; final Cost cost = new Cost("Sac<1/" + type + ">", false); costs.add(new OptionalCostValue(OptionalCost.Offering, cost)); } diff --git a/forge-game/src/main/java/forge/game/card/Card.java b/forge-game/src/main/java/forge/game/card/Card.java index 9749305e646..73cb4c124c9 100644 --- a/forge-game/src/main/java/forge/game/card/Card.java +++ b/forge-game/src/main/java/forge/game/card/Card.java @@ -2726,13 +2726,13 @@ public class Card extends GameEntity implements Comparable, IHasSVars, ITr sbLong.append(onlyMana? "" : ".").append(extra); sbLong.append(!complex ? " (" + (inst.getReminderText()) + ")" : ""); sbLong.append("\r\n"); - } else if (keyword.endsWith(" offering")) { - String offeringType = keyword.split(" ")[0]; + } else if (keyword.startsWith("Offering")) { + String type = keyword.split(":")[1]; if (sb.length() != 0) { sb.append("\r\n"); } - sbLong.append(keyword); - sbLong.append(" (").append(Keyword.getInstance("Offering:" + offeringType).getReminderText()).append(")"); + sbLong.append(type).append(" offering"); + sbLong.append(" (").append(inst.getReminderText()).append(")"); } else if (keyword.startsWith("Equip") || keyword.startsWith("Fortify") || keyword.startsWith("Outlast") || keyword.startsWith("Unearth") || keyword.startsWith("Scavenge") || keyword.startsWith("Spectacle") || keyword.startsWith("Evoke") diff --git a/forge-game/src/main/java/forge/game/card/CardUtil.java b/forge-game/src/main/java/forge/game/card/CardUtil.java index 7a9566f1026..6b15b6df13b 100644 --- a/forge-game/src/main/java/forge/game/card/CardUtil.java +++ b/forge-game/src/main/java/forge/game/card/CardUtil.java @@ -59,11 +59,8 @@ public final class CardUtil { "Fortify", "Transfigure", "Champion", "Evoke", "Prowl", "Freerunning", "Reinforce", "Unearth", "Level up", "Miracle", "Overload", "Cleave", "Scavenge", "Encore", "Bestow", "Outlast", "Dash", "Surge", "Emerge", "Hexproof:", - "Bands with other", "Landwalk", + "Bands with other", "Landwalk", "Offering", "etbCounter", "Reflect", "Ward").build(); - /** List of keyword endings of keywords that could be modified by text changes. */ - public static final ImmutableList modifiableKeywordEndings = ImmutableList.builder().add( - "cycling", "offering").build(); public static boolean isKeywordModifiable(final String kw) { for (final String modKw : modifiableKeywords) { @@ -71,11 +68,6 @@ public final class CardUtil { return true; } } - for (final String end : modifiableKeywordEndings) { - if (kw.endsWith(end)) { - return true; - } - } return false; } diff --git a/forge-game/src/main/java/forge/game/cost/CostAdjustment.java b/forge-game/src/main/java/forge/game/cost/CostAdjustment.java index 2813dd4803c..ed0a6bda460 100644 --- a/forge-game/src/main/java/forge/game/cost/CostAdjustment.java +++ b/forge-game/src/main/java/forge/game/cost/CostAdjustment.java @@ -360,7 +360,7 @@ public class CostAdjustment { String offeringType = ""; for (KeywordInterface inst : sa.getHostCard().getKeywords(Keyword.OFFERING)) { final String kw = inst.getOriginal(); - offeringType = kw.split(" ")[0]; + offeringType = kw.split(":")[1]; break; } diff --git a/forge-game/src/main/java/forge/game/keyword/Keyword.java b/forge-game/src/main/java/forge/game/keyword/Keyword.java index d4fae8aae7c..9880c30b38b 100644 --- a/forge-game/src/main/java/forge/game/keyword/Keyword.java +++ b/forge-game/src/main/java/forge/game/keyword/Keyword.java @@ -253,20 +253,6 @@ public enum Keyword { details = ""; } - if (keyword == Keyword.UNDEFINED) { - //check for special keywords that have a prefix before the keyword enum name - int idx = k.indexOf(' '); - String enumName = k.replace(" ", "_").toUpperCase(Locale.ROOT); - String firstWord = idx == -1 ? enumName : enumName.substring(0, idx); - if (idx != -1) { - idx = k.indexOf(' ', idx + 1); - String secondWord = idx == -1 ? enumName.substring(firstWord.length() + 1) : enumName.substring(firstWord.length() + 1, idx); - if (secondWord.equalsIgnoreCase("OFFERING")) { - keyword = Keyword.OFFERING; - details = firstWord; - } - } - } KeywordInstance inst; try { inst = keyword.type.getConstructor().newInstance(); diff --git a/forge-gui/res/cardsfolder/b/blast_furnace_hellkite.txt b/forge-gui/res/cardsfolder/b/blast_furnace_hellkite.txt index 14acb981072..b4a1951e697 100644 --- a/forge-gui/res/cardsfolder/b/blast_furnace_hellkite.txt +++ b/forge-gui/res/cardsfolder/b/blast_furnace_hellkite.txt @@ -2,7 +2,7 @@ Name:Blast-Furnace Hellkite ManaCost:7 R R Types:Creature Dragon PT:5/5 -K:Artifact offering +K:Offering:Artifact K:Flying K:Double Strike S:Mode$ Continuous | Affected$ Creature.attacking Opponent | AddKeyword$ Double Strike | Description$ Creatures attacking your opponents have double strike. diff --git a/forge-gui/res/cardsfolder/p/patron_of_the_akki.txt b/forge-gui/res/cardsfolder/p/patron_of_the_akki.txt index 498fa26f045..7391d383e83 100644 --- a/forge-gui/res/cardsfolder/p/patron_of_the_akki.txt +++ b/forge-gui/res/cardsfolder/p/patron_of_the_akki.txt @@ -2,7 +2,7 @@ Name:Patron of the Akki ManaCost:4 R R Types:Legendary Creature Spirit PT:5/5 -K:Goblin offering +K:Offering:Goblin T:Mode$ Attacks | ValidCard$ Card.Self | TriggerZones$ Battlefield | Execute$ TrigPump | TriggerDescription$ Whenever CARDNAME attacks, creatures you control get +2/+0 until end of turn. SVar:TrigPump:DB$ PumpAll | ValidCards$ Creature.YouCtrl | NumAtt$ +2 AI:RemoveDeck:All diff --git a/forge-gui/res/cardsfolder/p/patron_of_the_kitsune.txt b/forge-gui/res/cardsfolder/p/patron_of_the_kitsune.txt index 908a5ba781e..bb976591943 100644 --- a/forge-gui/res/cardsfolder/p/patron_of_the_kitsune.txt +++ b/forge-gui/res/cardsfolder/p/patron_of_the_kitsune.txt @@ -2,7 +2,7 @@ Name:Patron of the Kitsune ManaCost:4 W W Types:Legendary Creature Spirit PT:5/6 -K:Fox offering +K:Offering:Fox T:Mode$ Attacks | ValidCard$ Creature | TriggerZones$ Battlefield | Execute$ PatronLife | OptionalDecider$ You | TriggerDescription$ Whenever a creature attacks, you gain 1 life. SVar:PatronLife:DB$ GainLife | LifeAmount$ 1 AI:RemoveDeck:All diff --git a/forge-gui/res/cardsfolder/p/patron_of_the_moon.txt b/forge-gui/res/cardsfolder/p/patron_of_the_moon.txt index 4125d1b57f1..4487555e47f 100644 --- a/forge-gui/res/cardsfolder/p/patron_of_the_moon.txt +++ b/forge-gui/res/cardsfolder/p/patron_of_the_moon.txt @@ -2,7 +2,7 @@ Name:Patron of the Moon ManaCost:5 U U Types:Legendary Creature Spirit PT:5/4 -K:Moonfolk offering +K:Offering:Moonfolk K:Flying A:AB$ ChangeZone | Cost$ 1 | ChangeNum$ 2 | Origin$ Hand | Destination$ Battlefield | Tapped$ True | ChangeType$ Land.YouCtrl | SpellDescription$ Put up to two land cards from your hand onto the battlefield tapped. AI:RemoveDeck:All diff --git a/forge-gui/res/cardsfolder/p/patron_of_the_nezumi.txt b/forge-gui/res/cardsfolder/p/patron_of_the_nezumi.txt index ac26af8c747..0e8a09d400d 100644 --- a/forge-gui/res/cardsfolder/p/patron_of_the_nezumi.txt +++ b/forge-gui/res/cardsfolder/p/patron_of_the_nezumi.txt @@ -2,7 +2,7 @@ Name:Patron of the Nezumi ManaCost:5 B B Types:Legendary Creature Spirit PT:6/6 -K:Rat offering +K:Offering:Rat T:Mode$ ChangesZone | Origin$ Battlefield | Destination$ Graveyard | TriggerZones$ Battlefield | ValidCard$ Card.OppOwn | Execute$ TrigLoseLife | TriggerDescription$ Whenever a permanent is put into an opponent's graveyard, that player loses 1 life. SVar:TrigLoseLife:DB$ LoseLife | Defined$ TriggeredCardOwner | LifeAmount$ 1 AI:RemoveDeck:All diff --git a/forge-gui/res/cardsfolder/p/patron_of_the_orochi.txt b/forge-gui/res/cardsfolder/p/patron_of_the_orochi.txt index d0f25207880..3ee142e83fb 100644 --- a/forge-gui/res/cardsfolder/p/patron_of_the_orochi.txt +++ b/forge-gui/res/cardsfolder/p/patron_of_the_orochi.txt @@ -2,7 +2,7 @@ Name:Patron of the Orochi ManaCost:6 G G Types:Legendary Creature Spirit PT:7/7 -K:Snake offering +K:Offering:Snake A:AB$ UntapAll | Cost$ T | ValidCards$ Forest,Creature.Green | ActivationLimit$ 1 | SpellDescription$ Untap all Forests and all green creatures. Activate only once each turn. AI:RemoveDeck:All Oracle:Snake offering (You may cast this card any time you could cast an instant by sacrificing a Snake and paying the difference in mana costs between this and the sacrificed Snake. Mana cost includes color.)\n{T}: Untap all Forests and all green creatures. Activate only once each turn.