mirror of
https://github.com/correl/mage.git
synced 2024-12-27 03:00:13 +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, () -> {
|
execute("removeTable", sessionId, () -> {
|
||||||
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
SessionManager.instance.getSession(sessionId).ifPresent(session -> {
|
||||||
UUID userId = session.getUserId();
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
} else if ("plane".equalsIgnoreCase(command.zone)) {
|
} else if ("plane".equalsIgnoreCase(command.zone)) {
|
||||||
// eg: plane:Human:BantPlane:1
|
if (putPlaneToGame(game, player, command.cardName)) {
|
||||||
// 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());
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if ("loyalty".equalsIgnoreCase(command.zone)) {
|
} 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());
|
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.
|
* Find player by name.
|
||||||
*
|
*
|
||||||
|
|
|
@ -27,6 +27,7 @@ import mage.player.ai.ComputerPlayer7;
|
||||||
import mage.player.ai.ComputerPlayerMCTS;
|
import mage.player.ai.ComputerPlayerMCTS;
|
||||||
import mage.players.ManaPool;
|
import mage.players.ManaPool;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
import mage.server.util.SystemUtil;
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
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.
|
* Returns card list container for specified game zone and player.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue