mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Cost: make Cost better copyable
When adding CostParts, make CostAddMana join together
This commit is contained in:
@@ -134,6 +134,10 @@ public class Cost {
|
|||||||
return manapart == null ? ManaCost.ZERO : manapart.getManaToPay();
|
return manapart == null ? ManaCost.ZERO : manapart.getManaToPay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Cost() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private Cost(int genericMana) {
|
private Cost(int genericMana) {
|
||||||
costParts.add(new CostPartMana(ManaCost.get(genericMana), null));
|
costParts.add(new CostPartMana(ManaCost.get(genericMana), null));
|
||||||
}
|
}
|
||||||
@@ -447,12 +451,21 @@ public class Cost {
|
|||||||
return splitStr;
|
return splitStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final Cost copy() {
|
||||||
|
Cost toRet = new Cost();
|
||||||
|
toRet.isAbility = this.isAbility;
|
||||||
|
for (CostPart cp : this.costParts) {
|
||||||
|
toRet.costParts.add(cp.copy());
|
||||||
|
}
|
||||||
|
return toRet;
|
||||||
|
}
|
||||||
|
|
||||||
public final Cost copyWithNoMana() {
|
public final Cost copyWithNoMana() {
|
||||||
Cost toRet = new Cost(0);
|
Cost toRet = new Cost(0);
|
||||||
toRet.isAbility = this.isAbility;
|
toRet.isAbility = this.isAbility;
|
||||||
for (CostPart cp : this.costParts) {
|
for (CostPart cp : this.costParts) {
|
||||||
if (!(cp instanceof CostPartMana))
|
if (!(cp instanceof CostPartMana))
|
||||||
toRet.costParts.add(cp);
|
toRet.costParts.add(cp.copy());
|
||||||
}
|
}
|
||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
@@ -773,7 +786,8 @@ public class Cost {
|
|||||||
} else {
|
} else {
|
||||||
costParts.add(0, new CostPartMana(oldManaCost.toManaCost(), r));
|
costParts.add(0, new CostPartMana(oldManaCost.toManaCost(), r));
|
||||||
}
|
}
|
||||||
} else if (part instanceof CostDiscard || part instanceof CostTapType) {
|
} else if (part instanceof CostDiscard || part instanceof CostTapType ||
|
||||||
|
part instanceof CostAddMana) {
|
||||||
boolean alreadyAdded = false;
|
boolean alreadyAdded = false;
|
||||||
for (final CostPart other : costParts) {
|
for (final CostPart other : costParts) {
|
||||||
if (other.getClass().equals(part.getClass()) &&
|
if (other.getClass().equals(part.getClass()) &&
|
||||||
@@ -786,6 +800,8 @@ public class Cost {
|
|||||||
} else if (part instanceof CostTapType) {
|
} else if (part instanceof CostTapType) {
|
||||||
CostTapType tappart = (CostTapType)part;
|
CostTapType tappart = (CostTapType)part;
|
||||||
costParts.add(new CostTapType(amount, part.getType(), part.getTypeDescription(), !tappart.canTapSource));
|
costParts.add(new CostTapType(amount, part.getType(), part.getTypeDescription(), !tappart.canTapSource));
|
||||||
|
} else if (part instanceof CostAddMana) {
|
||||||
|
costParts.add(new CostAddMana(amount, part.getType(), part.getTypeDescription()));
|
||||||
}
|
}
|
||||||
toRemove.add(other);
|
toRemove.add(other);
|
||||||
alreadyAdded = true;
|
alreadyAdded = true;
|
||||||
|
|||||||
@@ -71,10 +71,6 @@ public class CostAddMana extends CostPart {
|
|||||||
public boolean payAsDecided(Player ai, PaymentDecision decision, SpellAbility sa) {
|
public boolean payAsDecided(Player ai, PaymentDecision decision, SpellAbility sa) {
|
||||||
Card source = sa.getHostCard();
|
Card source = sa.getHostCard();
|
||||||
|
|
||||||
/*ColorSet cid = null;
|
|
||||||
if (ai.getGame().getRules().hasCommander()) {
|
|
||||||
cid = ai.getCommander().getRules().getColorIdentity();
|
|
||||||
}*/
|
|
||||||
List<Mana> manaProduced = new ArrayList<Mana>();
|
List<Mana> manaProduced = new ArrayList<Mana>();
|
||||||
final String type = this.getType();
|
final String type = this.getType();
|
||||||
for (int n = 0; n < decision.c; n++) {
|
for (int n = 0; n < decision.c; n++) {
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package forge.game.cost;
|
package forge.game.cost;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import forge.card.CardStateName;
|
import forge.card.CardStateName;
|
||||||
@@ -44,8 +43,7 @@ public class CostAdjustment {
|
|||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: find better way to copy Cost object
|
Cost result = cost.copy();
|
||||||
Cost result = new Cost("0", sa.isAbility()).add(cost);
|
|
||||||
|
|
||||||
boolean isStateChangeToFaceDown = false;
|
boolean isStateChangeToFaceDown = false;
|
||||||
if (sa.isSpell() && ((Spell) sa).isCastFaceDown()) {
|
if (sa.isSpell() && ((Spell) sa).isCastFaceDown()) {
|
||||||
@@ -60,7 +58,7 @@ public class CostAdjustment {
|
|||||||
if (!cardsOnBattlefield.contains(host)) {
|
if (!cardsOnBattlefield.contains(host)) {
|
||||||
cardsOnBattlefield.add(host);
|
cardsOnBattlefield.add(host);
|
||||||
}
|
}
|
||||||
final List<StaticAbility> raiseAbilities = new ArrayList<StaticAbility>();
|
final List<StaticAbility> raiseAbilities = Lists.newArrayList();
|
||||||
|
|
||||||
// Sort abilities to apply them in proper order
|
// Sort abilities to apply them in proper order
|
||||||
for (Card c : cardsOnBattlefield) {
|
for (Card c : cardsOnBattlefield) {
|
||||||
@@ -166,8 +164,8 @@ public class CostAdjustment {
|
|||||||
if (!cardsOnBattlefield.contains(originalCard)) {
|
if (!cardsOnBattlefield.contains(originalCard)) {
|
||||||
cardsOnBattlefield.add(originalCard);
|
cardsOnBattlefield.add(originalCard);
|
||||||
}
|
}
|
||||||
final List<StaticAbility> reduceAbilities = new ArrayList<StaticAbility>();
|
final List<StaticAbility> reduceAbilities = Lists.newArrayList();
|
||||||
final List<StaticAbility> setAbilities = new ArrayList<StaticAbility>();
|
final List<StaticAbility> setAbilities = Lists.newArrayList();
|
||||||
|
|
||||||
// Sort abilities to apply them in proper order
|
// Sort abilities to apply them in proper order
|
||||||
for (Card c : cardsOnBattlefield) {
|
for (Card c : cardsOnBattlefield) {
|
||||||
@@ -216,7 +214,7 @@ public class CostAdjustment {
|
|||||||
if (!delved.isEmpty()) {
|
if (!delved.isEmpty()) {
|
||||||
final Map<ZoneType, CardCollection> triggerList = Maps.newEnumMap(ZoneType.class);
|
final Map<ZoneType, CardCollection> triggerList = Maps.newEnumMap(ZoneType.class);
|
||||||
triggerList.put(ZoneType.Graveyard, delved);
|
triggerList.put(ZoneType.Graveyard, delved);
|
||||||
final HashMap<String, Object> runParams = new HashMap<String, Object>();
|
final Map<String, Object> runParams = Maps.newHashMap();
|
||||||
runParams.put("Cards", triggerList);
|
runParams.put("Cards", triggerList);
|
||||||
runParams.put("Destination", ZoneType.Exile);
|
runParams.put("Destination", ZoneType.Exile);
|
||||||
game.getTriggerHandler().runTrigger(TriggerType.ChangesZoneAll, runParams, false);
|
game.getTriggerHandler().runTrigger(TriggerType.ChangesZoneAll, runParams, false);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package forge.game.cost;
|
package forge.game.cost;
|
||||||
|
|
||||||
|
|
||||||
import forge.game.CardTraitBase;
|
import forge.game.CardTraitBase;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
@@ -29,7 +28,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
/**
|
/**
|
||||||
* The Class CostPart.
|
* The Class CostPart.
|
||||||
*/
|
*/
|
||||||
public abstract class CostPart implements Comparable<CostPart> {
|
public abstract class CostPart implements Comparable<CostPart>, Cloneable {
|
||||||
private String originalAmount;
|
private String originalAmount;
|
||||||
private String amount;
|
private String amount;
|
||||||
private final String originalType, originalTypeDescription;
|
private final String originalType, originalTypeDescription;
|
||||||
@@ -186,6 +185,16 @@ public abstract class CostPart implements Comparable<CostPart> {
|
|||||||
|
|
||||||
public int paymentOrder() { return 5; }
|
public int paymentOrder() { return 5; }
|
||||||
|
|
||||||
|
public CostPart copy() {
|
||||||
|
CostPart clone = null;
|
||||||
|
try {
|
||||||
|
clone = (CostPart) clone();
|
||||||
|
} catch (final CloneNotSupportedException e) {
|
||||||
|
System.err.println(e);
|
||||||
|
}
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(CostPart o) {
|
public int compareTo(CostPart o) {
|
||||||
return this.paymentOrder() - o.paymentOrder();
|
return this.paymentOrder() - o.paymentOrder();
|
||||||
|
|||||||
Reference in New Issue
Block a user