converted sunburstMap to byte (from strings and hashmaps)

This commit is contained in:
Maxmtg
2013-05-14 06:45:36 +00:00
parent 74340921ec
commit edf8422360
5 changed files with 24 additions and 53 deletions

View File

@@ -190,7 +190,7 @@ public class Card extends GameEntity implements Comparable<Card> {
private int replicateMagnitude = 0;
private int sunburstValue = 0;
private String colorsPaid = "";
private byte colorsPaid = 0;
private Player owner = null;
private Player controller = null;
@@ -876,7 +876,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
// TODO: Append colors instead of replacing
public final void setColorsPaid(final String s) {
public final void setColorsPaid(final byte s) {
this.colorsPaid = s;
}
@@ -887,7 +887,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*
* @return a String.
*/
public final String getColorsPaid() {
public final byte getColorsPaid() {
return this.colorsPaid;
}

View File

@@ -294,19 +294,21 @@ public abstract class TriggerReplacementBase {
}
if (params.containsKey("ManaSpent")) {
if (!this.getHostCard().getColorsPaid().contains(params.get("ManaSpent"))) {
byte spent = MagicColor.fromName(params.get("ManaSpent"));
if ( 0 == (this.getHostCard().getColorsPaid() & spent)) {
return false;
}
}
if (params.containsKey("ManaNotSpent")) {
if (this.getHostCard().getColorsPaid().contains(params.get("ManaNotSpent"))) {
byte spent = MagicColor.fromName(params.get("ManaSpent"));
if ( 0 != (this.getHostCard().getColorsPaid() & spent)) {
return false;
}
}
if (params.containsKey("WerewolfTransformCondition")) {
if (CardUtil.getLastTurnCast("Card", this.getHostCard()).size() > 0) {
if (!CardUtil.getLastTurnCast("Card", this.getHostCard()).isEmpty()) {
return false;
}
}

View File

@@ -102,7 +102,7 @@ public class ManaCostBeingPaid {
// holds Mana_Part objects
// ManaPartColor is stored before ManaPartColorless
private final HashMap<ManaCostShard, Integer> unpaidShards = new HashMap<ManaCostShard, Integer>();
private final HashMap<String, Integer> sunburstMap = new HashMap<String, Integer>();
private byte sunburstMap = 0;
private int cntX = 0;
private final String sourceRestriction;
@@ -146,9 +146,7 @@ public class ManaCostBeingPaid {
* @return a int.
*/
public final int getSunburst() {
final int ret = this.sunburstMap.size();
this.sunburstMap.clear();
return ret;
return ColorSet.fromMask(sunburstMap).countColors();
}
/**
@@ -158,26 +156,8 @@ public class ManaCostBeingPaid {
*
* @return a String.
*/
public final String getColorsPaid() {
String s = "";
for (final String key : this.sunburstMap.keySet()) {
if (key.equalsIgnoreCase("black") || key.equalsIgnoreCase("B")) {
s += "B";
}
if (key.equalsIgnoreCase("blue") || key.equalsIgnoreCase("U")) {
s += "U";
}
if (key.equalsIgnoreCase("green") || key.equalsIgnoreCase("G")) {
s += "G";
}
if (key.equalsIgnoreCase("red") || key.equalsIgnoreCase("R")) {
s += "R";
}
if (key.equalsIgnoreCase("white") || key.equalsIgnoreCase("W")) {
s += "W";
}
}
return s;
public final byte getColorsPaid() {
return sunburstMap;
}
/**
@@ -470,13 +450,7 @@ public class ManaCostBeingPaid {
this.increaseColorlessMana(1);
}
if (!mana.equals(Constant.Color.COLORLESS)) {
if (this.sunburstMap.containsKey(mana)) {
this.sunburstMap.put(mana, this.sunburstMap.get(mana) + 1);
} else {
this.sunburstMap.put(mana, 1);
}
}
this.sunburstMap |= colorMask;
return true;
}
@@ -550,20 +524,13 @@ public class ManaCostBeingPaid {
return false;
}
String manaColor = mana.getColor();
decreaseShard(choice, 1);
if (choice.isOr2Colorless() && choice.getColorMask() != mana.getColorCode() ) {
this.increaseColorlessMana(1);
}
if (!mana.isColor(Constant.Color.COLORLESS)) {
if (this.sunburstMap.containsKey(manaColor)) {
this.sunburstMap.put(manaColor, this.sunburstMap.get(manaColor) + 1);
} else {
this.sunburstMap.put(manaColor, 1);
}
}
this.sunburstMap |= mana.getColorCode();
return true;
}

View File

@@ -21,8 +21,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import forge.Card;
import forge.CardLists;
import forge.card.MagicColor;
import forge.card.ability.AbilityUtils;
import forge.card.cardfactory.CardFactoryUtil;
import forge.game.GameState;
@@ -315,11 +318,11 @@ public class SpellAbilityCondition extends SpellAbilityVariables {
}
}
if (null != this.getManaSpent()) {
if (!sa.getSourceCard().getColorsPaid().contains(this.getManaSpent())) {
if (StringUtils.isNotEmpty(this.getManaSpent())) {
byte manaSpent = MagicColor.fromName(getManaSpent()); // they always check for single color
if( 0 == (manaSpent & sa.getSourceCard().getColorsPaid())) // no match of colors
return false;
}
}
if (this.getsVarToCheck() != null) {
final int svarValue = AbilityUtils.calculateAmount(sa.getSourceCard(), this.getsVarToCheck(), sa);

View File

@@ -6,6 +6,7 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils;
import forge.Card;
import forge.card.ColorSet;
import forge.card.mana.ManaCostBeingPaid;
import forge.card.spellability.SpellAbility;
import forge.view.ButtonUtil;
@@ -13,7 +14,7 @@ import forge.view.ButtonUtil;
public class InputPayManaX extends InputPayManaBase {
private static final long serialVersionUID = -6900234444347364050L;
private int xPaid = 0;
private String colorsPaid;
private byte colorsPaid;
private final String manaCostStr;
private final boolean xCanBe0;
private boolean canceled = false;
@@ -85,9 +86,7 @@ public class InputPayManaX extends InputPayManaBase {
@Override
protected void onManaAbilityPaid() {
if (this.manaCost.isPaid()) {
if (!this.colorsPaid.contains(this.manaCost.getColorsPaid())) {
this.colorsPaid += this.manaCost.getColorsPaid();
}
this.colorsPaid |= manaCost.getColorsPaid();
this.manaCost = new ManaCostBeingPaid(manaCostStr);
this.xPaid++;
}
@@ -116,7 +115,7 @@ public class InputPayManaX extends InputPayManaBase {
final Card card = saPaidFor.getSourceCard();
card.setXManaCostPaid(this.xPaid);
card.setColorsPaid(this.colorsPaid);
card.setSunburstValue(this.colorsPaid.length());
card.setSunburstValue(ColorSet.fromMask(this.colorsPaid).countColors());
this.stop();
}
}