mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
color conversion routine for mana implemented
This commit is contained in:
@@ -85,6 +85,14 @@ public class MagicColor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getIndexOfFirstColor(byte color){
|
||||||
|
for(int i = 0; i < NUMBER_OR_COLORS; i++) {
|
||||||
|
if ((color & WUBRG[i]) != 0)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1; // colorless
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Interface Color.
|
* The Interface Color.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public class ManaPool {
|
|||||||
*/
|
*/
|
||||||
public ManaPool(final Player player) {
|
public ManaPool(final Player player) {
|
||||||
owner = player;
|
owner = player;
|
||||||
|
restoreColorReplacements();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getAmountOfColor(final byte color) {
|
public final int getAmountOfColor(final byte color) {
|
||||||
@@ -416,8 +417,25 @@ public class ManaPool {
|
|||||||
p.getGame().fireEvent(new GameEventZone(ZoneType.Battlefield, p, EventValueChangeType.ComplexUpdate, null));
|
p.getGame().fireEvent(new GameEventZone(ZoneType.Battlefield, p, EventValueChangeType.ComplexUpdate, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private byte[] colorConversionMatrix = new byte[6];
|
||||||
|
|
||||||
|
private static final byte[] identityMatrix = { MagicColor.WHITE, MagicColor.BLUE, MagicColor.BLACK, MagicColor.RED, MagicColor.GREEN, 0 };
|
||||||
|
|
||||||
|
public void restoreColorReplacements() {
|
||||||
|
for(int i = 0; i < colorConversionMatrix.length; i++)
|
||||||
|
colorConversionMatrix[i] = identityMatrix[i];
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canPayForShardWithColor(ManaCostShard shard, byte color) {
|
public boolean canPayForShardWithColor(ManaCostShard shard, byte color) {
|
||||||
// add color changing manipulations here
|
int rowIdx = MagicColor.getIndexOfFirstColor(color);
|
||||||
return shard.canBePaidWithManaOfColor(color);
|
byte line = colorConversionMatrix[rowIdx < 0 ? identityMatrix.length - 1 : rowIdx];
|
||||||
|
for(int i = 0; i < MagicColor.NUMBER_OR_COLORS; i++)
|
||||||
|
{
|
||||||
|
byte outColor = MagicColor.WUBRG[i];
|
||||||
|
if (( line & outColor) != 0 && shard.canBePaidWithManaOfColor(outColor))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return shard.canBePaidWithManaOfColor((byte)0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,11 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
|||||||
if (manaCost.isAnyPartPayableWith(color, player.getManaPool())) { colorCanUse |= color; }
|
if (manaCost.isAnyPartPayableWith(color, player.getManaPool())) { colorCanUse |= color; }
|
||||||
if (manaCost.needsColor(color, player.getManaPool())) { colorNeeded |= color; }
|
if (manaCost.needsColor(color, player.getManaPool())) { colorNeeded |= color; }
|
||||||
}
|
}
|
||||||
boolean canUseColorless = manaCost.isAnyPartPayableWith((byte)0, player.getManaPool());
|
if (manaCost.isAnyPartPayableWith(MagicColor.COLORLESS, player.getManaPool()))
|
||||||
|
colorCanUse |= MagicColor.COLORLESS;
|
||||||
|
|
||||||
|
if ( 0 == colorCanUse ) // no mana cost or something
|
||||||
|
return;
|
||||||
|
|
||||||
List<SpellAbility> abilities = new ArrayList<SpellAbility>();
|
List<SpellAbility> abilities = new ArrayList<SpellAbility>();
|
||||||
// you can't remove unneeded abilities inside a for (am:abilities) loop :(
|
// you can't remove unneeded abilities inside a for (am:abilities) loop :(
|
||||||
@@ -125,10 +129,10 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
|||||||
ma.setActivatingPlayer(player);
|
ma.setActivatingPlayer(player);
|
||||||
|
|
||||||
AbilityManaPart m = ma.getManaPartRecursive();
|
AbilityManaPart m = ma.getManaPartRecursive();
|
||||||
if (m == null || !ma.canPlay()) { continue; }
|
if (m == null || !ma.canPlay()) { continue; }
|
||||||
if (!canUseColorless && !abilityProducesManaColor(ma, m, colorCanUse)) { continue; }
|
if (!abilityProducesManaColor(ma, m, colorCanUse)) { continue; }
|
||||||
if (ma.isAbility() && ma.getRestrictions().isInstantSpeed()) { continue; }
|
if (ma.isAbility() && ma.getRestrictions().isInstantSpeed()) { continue; }
|
||||||
if (!m.meetsManaRestrictions(saPaidFor)) { continue; }
|
if (!m.meetsManaRestrictions(saPaidFor)) { continue; }
|
||||||
|
|
||||||
abilities.add(ma);
|
abilities.add(ma);
|
||||||
|
|
||||||
@@ -216,7 +220,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
|||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
private static boolean abilityProducesManaColor(final SpellAbility am, AbilityManaPart m, final byte neededColor) {
|
private static boolean abilityProducesManaColor(final SpellAbility am, AbilityManaPart m, final byte neededColor) {
|
||||||
if (neededColor == 0) {
|
if (0 != (neededColor & MagicColor.COLORLESS)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user