use of mage.constants.PlanarDieRollResult in project mage by magefree.
the class RandomTest method test_GenerateRandomPlanarDicePng.
@Test
@Ignore
public void test_GenerateRandomPlanarDicePng() throws IOException {
String dest = "f:/test/xmage/";
// RandomUtil.setSeed(123);
Player player = new HumanPlayer("random", RangeOfInfluence.ALL, 1);
Game game = new TwoPlayerDuel(MultiplayerAttackOption.MULTIPLE, RangeOfInfluence.ALL, MulliganType.GAME_DEFAULT.getMulligan(0), 50);
int height = 512;
int weight = 512;
BufferedImage image = new BufferedImage(weight, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < weight; x++) {
for (int y = 0; y < height; y++) {
// roll planar dice
PlanarDieRollResult res = player.rollPlanarDie(Outcome.Neutral, null, game);
image.setRGB(x, y, new Color(res.equals(PlanarDieRollResult.CHAOS_ROLL) ? 255 : 0, res.equals(PlanarDieRollResult.PLANAR_ROLL) ? 255 : 0, res.equals(PlanarDieRollResult.BLANK_ROLL) ? 255 : 0).getRGB());
}
}
ImageIO.write(image, "png", new File(dest + "xmage_random_planar_dice.png"));
}
use of mage.constants.PlanarDieRollResult in project mage by magefree.
the class RollPlanarDieEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
PlanarDieRollResult planarRoll = controller.rollPlanarDie(outcome, source, game);
if (planarRoll == PlanarDieRollResult.CHAOS_ROLL && chaosEffects != null && chaosTargets != null) {
for (int i = 0; i < chaosTargets.size(); i++) {
Target target = chaosTargets.get(i);
if (target != null) {
target.clearChosen();
}
}
for (int i = 0; i < chaosEffects.size(); i++) {
Effect effect = chaosEffects.get(i);
Target target = null;
if (chaosTargets.size() > i) {
target = chaosTargets.get(i);
}
boolean done = false;
while (controller.canRespond() && effect != null && !done) {
if (target != null && !target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target, source, game);
source.addTarget(target);
}
if (target != null) {
effect.setTargetPointer(new FixedTarget(target.getFirstTarget()));
}
try {
effect.apply(game, source);
} catch (UnsupportedOperationException exception) {
}
if (effect instanceof ContinuousEffect) {
game.addEffect((ContinuousEffect) effect, source);
}
done = true;
}
}
} else if (planarRoll == PlanarDieRollResult.PLANAR_ROLL) {
// 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;
}
}
// 2) Choose a new random plane we haven't been to, or reset if we've been everywhere
List<String> planesVisited = game.getState().getSeenPlanes();
if (game.getState().getSeenPlanes() != null) {
if (planesVisited.size() == Planes.values().length) {
game.getState().resetSeenPlanes();
}
}
boolean foundNextPlane = false;
while (!foundNextPlane) {
Plane plane = Plane.createRandomPlane();
try {
if (plane != null && !planesVisited.contains(plane.getName())) {
foundNextPlane = true;
plane.setControllerId(controller.getId());
game.addPlane(plane, null, controller.getId());
}
} catch (Exception ex) {
}
}
}
return true;
}
return false;
}
Aggregations