mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Test framework: added planes support in tests (command: addPlane)
This commit is contained in:
parent
d9344093dd
commit
30fe344e23
3 changed files with 37 additions and 24 deletions
|
@ -1102,7 +1102,7 @@ public class MageServerImpl implements MageServer {
|
|||
execute("removeTable", sessionId, () -> {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||
UUID userId = session.getUserId();
|
||||
TableManager.instance.removeTable(userId, tableId); // delete account
|
||||
TableManager.instance.removeTable(userId, tableId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -522,29 +522,7 @@ public final class SystemUtil {
|
|||
continue;
|
||||
}
|
||||
} else if ("plane".equalsIgnoreCase(command.zone)) {
|
||||
// eg: plane:Human:BantPlane:1
|
||||
// Steps: 1) Remove the last plane and set its effects to discarded
|
||||
for (CommandObject cobject : game.getState().getCommand()) {
|
||||
if (cobject instanceof Plane) {
|
||||
if (cobject.getAbilities() != null) {
|
||||
for (Ability ability : cobject.getAbilities()) {
|
||||
for (Effect effect : ability.getEffects()) {
|
||||
if (effect instanceof ContinuousEffect) {
|
||||
((ContinuousEffect) effect).discard();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
game.getState().removeTriggersOfSourceId(cobject.getId());
|
||||
game.getState().getCommand().remove(cobject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Planes planeType = Planes.fromClassName(command.cardName);
|
||||
Plane plane = Plane.createPlane(planeType);
|
||||
if (plane != null) {
|
||||
plane.setControllerId(player.getId());
|
||||
game.addPlane(plane, null, player.getId());
|
||||
if (putPlaneToGame(game, player, command.cardName)) {
|
||||
continue;
|
||||
}
|
||||
} else if ("loyalty".equalsIgnoreCase(command.zone)) {
|
||||
|
@ -688,6 +666,36 @@ public final class SystemUtil {
|
|||
logger.info("Added card to player's " + zone.toString() + ": " + card.getName() + ", player = " + player.getName());
|
||||
}
|
||||
|
||||
public static boolean putPlaneToGame(Game game, Player player, String planeClassName) {
|
||||
// remove the last plane and set its effects to discarded
|
||||
for (CommandObject comObject : game.getState().getCommand()) {
|
||||
if (comObject instanceof Plane) {
|
||||
if (comObject.getAbilities() != null) {
|
||||
for (Ability ability : comObject.getAbilities()) {
|
||||
for (Effect effect : ability.getEffects()) {
|
||||
if (effect instanceof ContinuousEffect) {
|
||||
((ContinuousEffect) effect).discard();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
game.getState().removeTriggersOfSourceId(comObject.getId());
|
||||
game.getState().getCommand().remove(comObject);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// put new plane to game
|
||||
Planes planeType = Planes.fromClassName(planeClassName);
|
||||
Plane plane = Plane.createPlane(planeType);
|
||||
if (plane != null) {
|
||||
plane.setControllerId(player.getId());
|
||||
game.addPlane(plane, null, player.getId());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find player by name.
|
||||
*
|
||||
|
|
|
@ -27,6 +27,7 @@ import mage.player.ai.ComputerPlayer7;
|
|||
import mage.player.ai.ComputerPlayerMCTS;
|
||||
import mage.players.ManaPool;
|
||||
import mage.players.Player;
|
||||
import mage.server.util.SystemUtil;
|
||||
import mage.util.CardUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
@ -657,6 +658,10 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
|||
}
|
||||
}
|
||||
|
||||
public void addPlane(Player player, Planes plane) {
|
||||
Assert.assertTrue("Can't put plane to game: " + plane.getClassName(), SystemUtil.putPlaneToGame(currentGame, player, plane.getClassName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns card list container for specified game zone and player.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue