Skip to content

Commit

Permalink
Merge pull request #3794 from tool4ever/xcolor
Browse files Browse the repository at this point in the history
Improve cost reduction logic for X shards with color restriction
  • Loading branch information
kevlahnota authored Sep 20, 2023
2 parents ef56481 + f33bf79 commit da3168c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
6 changes: 3 additions & 3 deletions forge-ai/src/main/java/forge/ai/ComputerUtilMana.java
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ private static boolean canPayShardWithSpellAbility(ManaCostShard toPay, Player a
continue;
}

if (!sa.allowsPayingWithShard(m.getSourceCard(), ManaAtom.fromName(s))) {
if (!sa.allowsPayingWithShard(sourceCard, ManaAtom.fromName(s))) {
continue;
}

Expand All @@ -1008,7 +1008,7 @@ private static boolean canPayShardWithSpellAbility(ManaCostShard toPay, Player a
continue;
}

if (!sa.allowsPayingWithShard(m.getSourceCard(), c)) {
if (!sa.allowsPayingWithShard(sourceCard, c)) {
continue;
}

Expand All @@ -1020,7 +1020,7 @@ private static boolean canPayShardWithSpellAbility(ManaCostShard toPay, Player a
return false;
}

if (!sa.allowsPayingWithShard(m.getSourceCard(), MagicColor.fromName(m.getOrigProduced()))) {
if (!sa.allowsPayingWithShard(sourceCard, MagicColor.fromName(m.getOrigProduced()))) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ private static int applyReduceCostAbility(final StaticAbility staticAbility, fin
minMana = Integer.valueOf(staticAbility.getParam("MinMana"));
}

final int maxReduction = Math.max(0, manaCost.getConvertedManaCost() - minMana - sumReduced);
final int maxReduction = manaCost.getConvertedManaCost() - minMana - sumReduced;
if (maxReduction > 0) {
return Math.min(value, maxReduction);
}
Expand Down
22 changes: 18 additions & 4 deletions forge-game/src/main/java/forge/game/mana/ManaCostBeingPaid.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public final void decreaseShard(final ManaCostShard shard, final int manaToSubtr
for (Entry<ManaCostShard, ShardCount> e : unpaidShards.entrySet()) {
final ManaCostShard eShard = e.getKey();
sc = e.getValue();
if (eShard.isOfKind(shard.getShard()) && !eShard.isMonoColor()) {
if (eShard != ManaCostShard.COLORED_X && eShard.isOfKind(shard.getShard()) && !eShard.isMonoColor()) {
if (otherSubtract >= sc.totalCount) {
otherSubtract -= sc.totalCount;
sc.xCount = sc.totalCount = 0;
Expand Down Expand Up @@ -377,6 +377,20 @@ public final void decreaseShard(final ManaCostShard shard, final int manaToSubtr
// nothing more left in otherSubtract
return;
}
} else if (sc.xCount > 0) { // X part that can only be paid by specific color
if (otherSubtract >= sc.xCount) {
otherSubtract -= sc.xCount;
sc.totalCount -= sc.xCount;
sc.xCount = 0;
if (sc.totalCount == 0) {
toRemove.add(eShard);
}
} else {
sc.totalCount -= otherSubtract;
sc.xCount -= otherSubtract;
// nothing more left in otherSubtract
return;
}
}
}
}
Expand Down Expand Up @@ -717,10 +731,10 @@ public final byte getUnpaidColors() {
}
return result;
}

public boolean hasAnyKind(int kind) {
for (ManaCostShard s : unpaidShards.keySet()) {
if (s.isOfKind(kind)) {
for (Map.Entry<ManaCostShard, ShardCount> e : unpaidShards.entrySet()) {
if (e.getKey().isOfKind(kind) && e.getValue().totalCount > e.getValue().xCount) {
return true;
}
}
Expand Down
16 changes: 8 additions & 8 deletions forge-gui/res/cardsfolder/p/primitive_justice.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Name:Primitive Justice
ManaCost:1 R
Types:Sorcery
A:SP$ Destroy | Cost$ X 1 R | XColor$ RG | AnnounceTitle$ how many times to pay the additional cost | Announce$ AdditionalCostPayTimes | ValidTgts$ Artifact | TgtPrompt$ Select target artifact | TargetMin$ TargetNum | TargetMax$ TargetNum | SubAbility$ DBGainLife | SpellDescription$ Destroy target artifact. For each additional {1}{R} you paid, destroy another target artifact. For each additional {1}{G} you paid, destroy another target artifact, and you gain 1 life.
S:Mode$ RaiseCost | ValidCard$ Card.Self | Type$ Spell | Amount$ IncreaseCost | EffectZone$ All | Description$ As an additional cost to cast this spell, you may pay {1}{R} and/or {1}{G} any number of times.
SVar:DBGainLife:DB$ GainLife | Defined$ You | LifeAmount$ GManaPaid
SVar:AdditionalCostPayTimes:Number$0
SVar:TargetNum:SVar$AdditionalCostPayTimes/Plus.1
SVar:IncreaseCost:SVar$AdditionalCostPayTimes
SVar:X:SVar$AdditionalCostPayTimes
SVar:GManaPaid:Count$xColorPaid G
A:SP$ Destroy | Cost$ 1 R | AnnounceTitle$ how many times to pay the additional cost | Announce$ AdditionalCostPayTimesR,AdditionalCostPayTimesG | ValidTgts$ Artifact | TgtPrompt$ Select target artifact | TargetMin$ TargetNum | TargetMax$ TargetNum | SubAbility$ DBGainLife | SpellDescription$ Destroy target artifact. For each additional {1}{R} you paid, destroy another target artifact. For each additional {1}{G} you paid, destroy another target artifact, and you gain 1 life.
S:Mode$ RaiseCost | ValidCard$ Card.Self | Type$ Spell | Cost$ 1 R | Amount$ AdditionalCostPayTimesR | EffectZone$ All | Description$ As an additional cost to cast this spell, you may pay {1}{R} and/or {1}{G} any number of times.
S:Mode$ RaiseCost | ValidCard$ Card.Self | Type$ Spell | Cost$ 1 G | Amount$ AdditionalCostPayTimesG | EffectZone$ All
SVar:DBGainLife:DB$ GainLife | Defined$ You | LifeAmount$ AdditionalCostPayTimesG
SVar:AdditionalCostPayTimesR:Number$0
SVar:AdditionalCostPayTimesG:Number$0
SVar:TargetNum:SVar$AdditionalCostPayTimesR/Plus.TargetNum2
SVar:TargetNum2:SVar$AdditionalCostPayTimesG/Plus.1
Oracle:As an additional cost to cast this spell, you may pay {1}{R} and/or {1}{G} any number of times.\nDestroy target artifact. For each additional {1}{R} you paid, destroy another target artifact. For each additional {1}{G} you paid, destroy another target artifact, and you gain 1 life.

0 comments on commit da3168c

Please sign in to comment.