added apply and update methods to MagicGame and MagicPlayer
parent
096794537c
commit
94d9a2ce97
|
@ -67,6 +67,7 @@ public class MagicGame {
|
|||
private int startTurn;
|
||||
private int mainPhaseCount=100000000;
|
||||
private int landPlayed;
|
||||
private int maxLand;
|
||||
private int spellsPlayed;
|
||||
private boolean creatureDiedThisTurn;
|
||||
private boolean priorityPassed;
|
||||
|
@ -162,6 +163,7 @@ public class MagicGame {
|
|||
turn = game.turn;
|
||||
startTurn = game.startTurn;
|
||||
landPlayed = game.landPlayed;
|
||||
maxLand = game.maxLand;
|
||||
spellsPlayed = game.spellsPlayed;
|
||||
creatureDiedThisTurn = game.creatureDiedThisTurn;
|
||||
priorityPassed = game.priorityPassed;
|
||||
|
@ -246,6 +248,7 @@ public class MagicGame {
|
|||
step.hashCode(),
|
||||
turnPlayer.getIndex(),
|
||||
landPlayed,
|
||||
maxLand,
|
||||
priorityPassedCount,
|
||||
(priorityPassed ? 1L : -1L),
|
||||
(stateCheckRequired ? 1L : -1L),
|
||||
|
@ -497,8 +500,42 @@ public class MagicGame {
|
|||
public void update() {
|
||||
doDelayedActions();
|
||||
MagicPermanent.update(this);
|
||||
MagicPlayer.update(this);
|
||||
MagicGame.update(this);
|
||||
doDelayedActions();
|
||||
}
|
||||
|
||||
public void apply(final MagicLayer layer) {
|
||||
switch (layer) {
|
||||
case Game:
|
||||
maxLand = 1;
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("No case for " + layer + " in MagicGame.apply");
|
||||
}
|
||||
}
|
||||
|
||||
private void apply(final MagicPermanent source, final MagicStatic mstatic) {
|
||||
final MagicLayer layer = mstatic.getLayer();
|
||||
switch (layer) {
|
||||
case Game:
|
||||
mstatic.modGame(source, this);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("No case for " + layer + " in MagicGame.apply");
|
||||
}
|
||||
}
|
||||
|
||||
public static void update(final MagicGame game) {
|
||||
game.apply(MagicLayer.Game);
|
||||
for (final MagicPermanentStatic mpstatic : game.getStatics(MagicLayer.Game)) {
|
||||
final MagicStatic mstatic = mpstatic.getStatic();
|
||||
final MagicPermanent source = mpstatic.getPermanent();
|
||||
if (mstatic.accept(game, source, source)) {
|
||||
game.apply(source, mstatic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doDelayedActions() {
|
||||
while (!delayedActions.isEmpty()) {
|
||||
|
@ -729,7 +766,7 @@ public class MagicGame {
|
|||
}
|
||||
|
||||
public boolean canPlayLand(final MagicPlayer controller) {
|
||||
return landPlayed < 1 && canPlaySorcery(controller);
|
||||
return landPlayed < maxLand && canPlaySorcery(controller);
|
||||
}
|
||||
|
||||
public int getLandPlayed() {
|
||||
|
@ -743,11 +780,19 @@ public class MagicGame {
|
|||
public void decLandPlayed() {
|
||||
landPlayed--;
|
||||
}
|
||||
|
||||
public void incMaxLand() {
|
||||
maxLand++;
|
||||
}
|
||||
|
||||
public void resetLandPlayed() {
|
||||
landPlayed = 0;
|
||||
}
|
||||
|
||||
public void resetMaxLand() {
|
||||
maxLand = 1;
|
||||
}
|
||||
|
||||
public void setLandPlayed(final int lp) {
|
||||
landPlayed = lp;
|
||||
}
|
||||
|
|
|
@ -333,9 +333,8 @@ public class MagicPermanent implements MagicSource,MagicTarget,Comparable<MagicP
|
|||
}
|
||||
|
||||
public static void updateProperties(final MagicGame game) {
|
||||
for (final MagicLayer layer : MagicLayer.values()) {
|
||||
for (final MagicLayer layer : MagicLayer.PermanentLayers) {
|
||||
for (final MagicPlayer player : game.getPlayers()) {
|
||||
player.apply(layer);
|
||||
for (final MagicPermanent perm : player.getPermanents()) {
|
||||
perm.apply(layer);
|
||||
}
|
||||
|
@ -396,9 +395,6 @@ public class MagicPermanent implements MagicSource,MagicTarget,Comparable<MagicP
|
|||
case SwitchPT:
|
||||
mstatic.modPowerToughness(source, this, cachedPowerToughness);
|
||||
break;
|
||||
case Player:
|
||||
mstatic.modPlayer(source, this);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("No case for " + layer + " in MagicPermanent.apply");
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import magic.model.target.MagicTarget;
|
|||
import magic.model.target.MagicTargetFilter;
|
||||
import magic.model.action.MagicLoseGameAction;
|
||||
import magic.model.mstatic.MagicLayer;
|
||||
import magic.model.mstatic.MagicStatic;
|
||||
import magic.model.mstatic.MagicPermanentStatic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -572,7 +574,33 @@ public class MagicPlayer implements MagicTarget {
|
|||
cachedAbilityFlags = MagicAbility.noneOf();
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("No case for " + layer + " in MagicPlayer.apply");
|
||||
}
|
||||
}
|
||||
|
||||
private void apply(final MagicPermanent source, final MagicStatic mstatic) {
|
||||
final MagicLayer layer = mstatic.getLayer();
|
||||
switch (layer) {
|
||||
case Player:
|
||||
mstatic.modPlayer(source, this);
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("No case for " + layer + " in MagicPlayer.apply");
|
||||
}
|
||||
}
|
||||
|
||||
public static void update(final MagicGame game) {
|
||||
for (final MagicPlayer player : game.getPlayers()) {
|
||||
player.apply(MagicLayer.Player);
|
||||
}
|
||||
for (final MagicPermanentStatic mpstatic : game.getStatics(MagicLayer.Player)) {
|
||||
final MagicStatic mstatic = mpstatic.getStatic();
|
||||
final MagicPermanent source = mpstatic.getPermanent();
|
||||
for (final MagicPlayer player : game.getPlayers()) {
|
||||
if (mstatic.accept(game, source, source)) {
|
||||
player.apply(source, mstatic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package magic.model.action;
|
||||
|
||||
import magic.model.MagicGame;
|
||||
|
||||
public class MagicChangeLandPlayedAction extends MagicAction {
|
||||
|
||||
private final int change;
|
||||
|
||||
public MagicChangeLandPlayedAction(final int change) {
|
||||
this.change = change;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction(final MagicGame game) {
|
||||
for (int i = change; i < 0; i++) {
|
||||
game.decLandPlayed();
|
||||
}
|
||||
for (int i = change; i > 0; i--) {
|
||||
game.incLandPlayed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undoAction(final MagicGame game) {
|
||||
//undo done by MagicMarkerAction
|
||||
}
|
||||
}
|
|
@ -5,10 +5,11 @@ import magic.model.MagicPlayer;
|
|||
import magic.model.MagicPowerToughness;
|
||||
import magic.model.MagicSubType;
|
||||
import magic.model.MagicAbility;
|
||||
import magic.model.MagicGame;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class MagicDummyPermanentModifier implements MagicPermanentModifier {
|
||||
public class MagicDummyModifier implements MagicModifier {
|
||||
|
||||
@Override
|
||||
public MagicPlayer getController(final MagicPermanent source, final MagicPermanent permanent, final MagicPlayer controller) {
|
||||
|
@ -41,7 +42,12 @@ public class MagicDummyPermanentModifier implements MagicPermanentModifier {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void modPlayer(final MagicPermanent source, final MagicPermanent permanent) {
|
||||
public void modPlayer(final MagicPermanent source, final MagicPlayer player) {
|
||||
//leave player unchanged
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modGame(final MagicPermanent source, final MagicGame game) {
|
||||
//leave game unchanged
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package magic.model.mstatic;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
public enum MagicLayer {
|
||||
Card, //0. properties from the card, not formally defined in rules
|
||||
Copy, //1. copy
|
||||
|
@ -18,4 +20,6 @@ public enum MagicLayer {
|
|||
Player, //8. affect player, e.g. you have hexproof
|
||||
Game, //9. affect game rules, e.g. modify maximum hand size, creature is Indestructible
|
||||
;
|
||||
|
||||
public static final EnumSet<MagicLayer> PermanentLayers = EnumSet.range(Card, SwitchPT);
|
||||
}
|
||||
|
|
|
@ -5,11 +5,12 @@ import magic.model.MagicPlayer;
|
|||
import magic.model.MagicPowerToughness;
|
||||
import magic.model.MagicSubType;
|
||||
import magic.model.MagicAbility;
|
||||
import magic.model.MagicGame;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
// Determines variable power, toughness, abilities, sub types and colors for a single creature permanent.
|
||||
public interface MagicPermanentModifier {
|
||||
public interface MagicModifier {
|
||||
|
||||
MagicPlayer getController(final MagicPermanent source, final MagicPermanent permanent, final MagicPlayer controller);
|
||||
|
||||
|
@ -23,5 +24,7 @@ public interface MagicPermanentModifier {
|
|||
|
||||
int getColorFlags(final MagicPermanent permanent, final int flags);
|
||||
|
||||
void modPlayer(final MagicPermanent source, final MagicPermanent permanent);
|
||||
void modPlayer(final MagicPermanent source, final MagicPlayer player);
|
||||
|
||||
void modGame(final MagicPermanent source, final MagicGame game);
|
||||
}
|
|
@ -12,7 +12,7 @@ import magic.model.target.MagicTargetFilter;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class MagicStatic extends MagicDummyPermanentModifier implements MagicChangeCardDefinition {
|
||||
public abstract class MagicStatic extends MagicDummyModifier implements MagicChangeCardDefinition {
|
||||
|
||||
public static final boolean UntilEOT = true;
|
||||
public static final boolean Forever = !UntilEOT;
|
||||
|
|
|
@ -51,6 +51,7 @@ public class MagicCleanupPhase extends MagicPhase {
|
|||
}
|
||||
game.setTurn(game.getTurn()+1);
|
||||
game.resetLandPlayed();
|
||||
game.resetMaxLand();
|
||||
game.setCreatureDiedThisTurn(false);
|
||||
game.setSpellsPlayed(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue