mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Cost.chooseXValue moved to member of CostPart
This commit is contained in:
@@ -43,27 +43,6 @@ public class ThreadUtil {
|
||||
getGameThreadPool().execute(toRun);
|
||||
}
|
||||
|
||||
public static void invokeInGameThreadAndWait(final Runnable toRun) {
|
||||
if (isGameThread()) {
|
||||
toRun.run(); //just run in the current thread
|
||||
return;
|
||||
}
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
getGameThreadPool().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
toRun.run();
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
try {
|
||||
latch.await();
|
||||
}
|
||||
catch (final InterruptedException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void delay(int milliseconds, Runnable inputUpdater) {
|
||||
getScheduledPool().schedule(inputUpdater, milliseconds, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import forge.card.mana.ManaCostParser;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CounterType;
|
||||
import forge.game.mana.ManaCostBeingPaid;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
@@ -719,17 +718,5 @@ public class Cost {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static int chooseXValue(final Card card, final SpellAbility sa, final int maxValue) {
|
||||
/*final String chosen = sa.getSVar("ChosenX");
|
||||
if (chosen.length() > 0) {
|
||||
return AbilityFactory.calculateAmount(card, "ChosenX", null);
|
||||
}*/
|
||||
|
||||
int chosenX = sa.getActivatingPlayer().getController().chooseNumber(sa, card.toString() + " - Choose a Value for X", 0, maxValue);
|
||||
sa.setSVar("ChosenX", Integer.toString(chosenX));
|
||||
card.setSVar("ChosenX", Integer.toString(chosenX));
|
||||
return chosenX;
|
||||
}
|
||||
|
||||
public static final Cost Zero = new Cost(0);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class CostDamage extends CostPart {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, life);
|
||||
c = chooseXValue(source, ability, life);
|
||||
}
|
||||
else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
|
||||
@@ -188,7 +188,7 @@ public class CostDiscard extends CostPartWithList {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, handList.size());
|
||||
c = chooseXValue(source, ability, handList.size());
|
||||
}
|
||||
else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
@@ -239,7 +239,7 @@ public class CostDiscard extends CostPartWithList {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, handList.size());
|
||||
c = chooseXValue(source, ability, handList.size());
|
||||
}
|
||||
else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
|
||||
@@ -257,7 +257,7 @@ public class CostExile extends CostPartWithList {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, list.size());
|
||||
c = chooseXValue(source, ability, list.size());
|
||||
}
|
||||
else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
|
||||
@@ -75,7 +75,7 @@ public class CostFlipCoin extends CostPartWithList {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, this.getList().size());
|
||||
c = chooseXValue(source, ability, this.getList().size());
|
||||
} else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class CostGainLife extends CostPart {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, life);
|
||||
c = chooseXValue(source, ability, life);
|
||||
} else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class CostMill extends CostPartWithList {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, this.getList().size());
|
||||
c = chooseXValue(source, ability, this.getList().size());
|
||||
} else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
@@ -220,4 +220,16 @@ public abstract class CostPart {
|
||||
public void setAmount(final String amountIn) {
|
||||
this.amount = amountIn;
|
||||
}
|
||||
|
||||
protected int chooseXValue(final Card card, final SpellAbility sa, final int maxValue) {
|
||||
/*final String chosen = sa.getSVar("ChosenX");
|
||||
if (chosen.length() > 0) {
|
||||
return AbilityFactory.calculateAmount(card, "ChosenX", null);
|
||||
}*/
|
||||
|
||||
int chosenX = sa.getActivatingPlayer().getController().chooseNumber(sa, card.toString() + " - Choose a Value for X", 0, maxValue);
|
||||
sa.setSVar("ChosenX", Integer.toString(chosenX));
|
||||
card.setSVar("ChosenX", Integer.toString(chosenX));
|
||||
return chosenX;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class CostPayLife extends CostPart {
|
||||
limit = AbilityUtils.calculateAmount(source, sVar.split("LimitMax.")[1], ability);
|
||||
}
|
||||
int maxLifePayment = limit < life ? limit : life;
|
||||
c = Cost.chooseXValue(source, ability, maxLifePayment);
|
||||
c = chooseXValue(source, ability, maxLifePayment);
|
||||
} else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ public class CostPutCardToLib extends CostPartWithList {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, this.getList().size());
|
||||
c = chooseXValue(source, ability, this.getList().size());
|
||||
} else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class CostRemoveCounter extends CostPartWithList {
|
||||
if (amount.equals("All"))
|
||||
cntRemoved = maxCounters;
|
||||
else if ( c == null && "XChoice".equals(sVarAmount)) {
|
||||
cntRemoved = Cost.chooseXValue(source, ability, maxCounters);
|
||||
cntRemoved = chooseXValue(source, ability, maxCounters);
|
||||
}
|
||||
|
||||
if (maxCounters < cntRemoved)
|
||||
|
||||
@@ -128,7 +128,7 @@ public class CostReturn extends CostPartWithList {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, list.size());
|
||||
c = chooseXValue(source, ability, list.size());
|
||||
} else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ public class CostReveal extends CostPartWithList {
|
||||
if (num == null) {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
if (sVar.equals("XChoice")) {
|
||||
num = Cost.chooseXValue(source, ability, handList.size());
|
||||
num = chooseXValue(source, ability, handList.size());
|
||||
} else {
|
||||
num = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ public class CostSacrifice extends CostPartWithList {
|
||||
if (c == null) {
|
||||
// Generalize this
|
||||
if (ability.getSVar(amount).equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, list.size());
|
||||
c = chooseXValue(source, ability, list.size());
|
||||
} else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ public class CostTapType extends CostPartWithList {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, typeList.size());
|
||||
c = chooseXValue(source, ability, typeList.size());
|
||||
} else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public class CostUntapType extends CostPartWithList {
|
||||
final String sVar = ability.getSVar(amount);
|
||||
// Generalize this
|
||||
if (sVar.equals("XChoice")) {
|
||||
c = Cost.chooseXValue(source, ability, typeList.size());
|
||||
c = chooseXValue(source, ability, typeList.size());
|
||||
} else {
|
||||
c = AbilityUtils.calculateAmount(source, amount, ability);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user