Molten hydra fix (calculateAmount had incorrect order of if-else and returned 0 for CostRemoveCounter too early)

This commit is contained in:
Maxmtg
2013-04-08 06:24:21 +00:00
parent 1b71f3a409
commit ba3d04010e
3 changed files with 23 additions and 18 deletions

View File

@@ -303,16 +303,6 @@ public class AbilityUtils {
// return result soon for plain numbers
if (StringUtils.isNumeric(amount)) { return Integer.parseInt(amount) * multiplier; }
// These are some special cases - who is implementing them?
if (amount.equals("ChosenX") || amount.equals("ChosenY")) {
// isn't made yet
return 0;
}
// cost hasn't been paid yet
if (amount.startsWith("Cost")) {
return 0;
}
// Try to fetch variable, try ability first, then card.
String svarval = null;
if (ability != null) {
@@ -324,6 +314,19 @@ public class AbilityUtils {
}
svarval = card.getSVar(amount);
}
if (StringUtils.isBlank(svarval)) {
// Some variables may be not chosen yet at this moment
// So return 0 and don't issue an error.
if (amount.equals("ChosenX") || amount.equals("ChosenY")) {
// isn't made yet
return 0;
}
// cost hasn't been paid yet
if (amount.startsWith("Cost")) {
return 0;
}
}
// Nothing to do here if value is missing or blank
if (StringUtils.isBlank(svarval)) {

View File

@@ -156,16 +156,18 @@ public class CostRemoveCounter extends CostPartWithList {
if(inp.hasCancelled())
return false;
source.setSVar("CostCountersRemoved", Integer.toString(inp.getSelected().size()));
// Have to hack here: remove all counters minus one, without firing any triggers,
// triggers will fire when last is removed by executePayment.
// They don't care how many were removed anyway
int sum = 0;
for(Card crd : inp.getSelected()) {
int cntRemoved = inp.getTimesSelected(crd);
if(cntRemoved < 2) continue;
int removed = inp.getTimesSelected(crd);
sum += removed;
if(removed < 2) continue;
int oldVal = crd.getCounters().get(getCounter()).intValue();
crd.getCounters().put(getCounter(), Integer.valueOf(oldVal - cntRemoved + 1));
crd.getCounters().put(getCounter(), Integer.valueOf(oldVal - removed + 1));
}
source.setSVar("CostCountersRemoved", Integer.toString(sum));
cntRemoved = 1;
return executePayment(ability, inp.getSelected());

View File

@@ -91,8 +91,8 @@ public class CostUtil {
choiceArray[i] = i;
}
final Integer chosenX = GuiChoose.one(card.toString() + " - Choose a Value for X", choiceArray);
sa.setSVar("ChosenX", "Number$" + Integer.toString(chosenX));
card.setSVar("ChosenX", "Number$" + Integer.toString(chosenX));
sa.setSVar("ChosenX", Integer.toString(chosenX));
card.setSVar("ChosenX", Integer.toString(chosenX));
return chosenX;
}
@@ -119,8 +119,8 @@ public class CostUtil {
choiceArray[i] = Integer.valueOf(i);
}
final Integer chosenY = GuiChoose.one(card.toString() + " - Choose a Value for Y", choiceArray);
sa.setSVar("ChosenY", "Number$" + Integer.toString(chosenY));
card.setSVar("ChosenY", "Number$" + Integer.toString(chosenY));
sa.setSVar("ChosenY", Integer.toString(chosenY));
card.setSVar("ChosenY", Integer.toString(chosenY));
return chosenY;
}