Search in sources :

Example 1 with PlanarDieRollResult

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"));
}
Also used : Player(mage.players.Player) HumanPlayer(mage.player.human.HumanPlayer) Game(mage.game.Game) PlanarDieRollResult(mage.constants.PlanarDieRollResult) HumanPlayer(mage.player.human.HumanPlayer) TwoPlayerDuel(mage.game.TwoPlayerDuel) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with PlanarDieRollResult

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;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Ability(mage.abilities.Ability) Player(mage.players.Player) PlanarDieRollResult(mage.constants.PlanarDieRollResult) Plane(mage.game.command.Plane) MageObject(mage.MageObject) CommandObject(mage.game.command.CommandObject) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) OneShotEffect(mage.abilities.effects.OneShotEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Effect(mage.abilities.effects.Effect) List(java.util.List) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Aggregations

PlanarDieRollResult (mage.constants.PlanarDieRollResult)2 Player (mage.players.Player)2 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 List (java.util.List)1 MageObject (mage.MageObject)1 Ability (mage.abilities.Ability)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 Game (mage.game.Game)1 TwoPlayerDuel (mage.game.TwoPlayerDuel)1 CommandObject (mage.game.command.CommandObject)1 Plane (mage.game.command.Plane)1 HumanPlayer (mage.player.human.HumanPlayer)1 Target (mage.target.Target)1 FixedTarget (mage.target.targetpointer.FixedTarget)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1