2014-08-05 11:43:05 -07:00
|
|
|
package magic.model.action;
|
|
|
|
|
2020-01-15 12:02:42 -08:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
2014-08-05 11:43:05 -07:00
|
|
|
import magic.model.MagicGame;
|
|
|
|
import magic.model.MagicPermanent;
|
|
|
|
import magic.model.MagicPermanentState;
|
2014-08-05 20:39:34 -07:00
|
|
|
import magic.model.mstatic.MagicStatic;
|
|
|
|
|
2015-04-14 03:51:51 -07:00
|
|
|
public class FlipAction extends MagicAction {
|
2014-08-05 11:43:05 -07:00
|
|
|
|
|
|
|
public final MagicPermanent permanent;
|
2014-08-05 20:39:34 -07:00
|
|
|
private Collection<MagicStatic> oldStatics = Collections.emptyList();
|
|
|
|
private Collection<MagicStatic> newStatics = Collections.emptyList();
|
2014-08-05 11:43:05 -07:00
|
|
|
|
2015-04-14 03:51:51 -07:00
|
|
|
public FlipAction(final MagicPermanent aPermanent) {
|
2014-08-05 11:43:05 -07:00
|
|
|
permanent = aPermanent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void doAction(final MagicGame game) {
|
2018-04-07 17:59:14 -07:00
|
|
|
if (permanent.isFlipCard() && !permanent.isFlipped()) {
|
2014-08-05 20:39:34 -07:00
|
|
|
oldStatics = permanent.getStatics();
|
2015-12-31 02:54:52 -08:00
|
|
|
|
2015-04-13 02:22:38 -07:00
|
|
|
game.doAction(ChangeStateAction.Set(permanent, MagicPermanentState.Flipped));
|
2014-08-05 20:39:34 -07:00
|
|
|
|
|
|
|
newStatics = permanent.getStatics();
|
|
|
|
game.removeStatics(permanent, oldStatics);
|
|
|
|
game.addStatics(permanent, newStatics);
|
2014-08-05 11:43:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void undoAction(final MagicGame game) {
|
2014-08-31 05:34:20 -07:00
|
|
|
game.removeStatics(permanent, newStatics);
|
|
|
|
game.addStatics(permanent, oldStatics);
|
2014-08-05 11:43:05 -07:00
|
|
|
}
|
|
|
|
}
|