Search in sources :

Example 1 with Drawable

use of objects.Drawable in project ultimate-java by pantinor.

the class Context method saveGame.

public void saveGame(float x, float y, float z, Direction orientation, Maps map) {
    if (map == Maps.WORLD) {
        party.getSaveGame().x = (int) x;
        party.getSaveGame().y = (int) y;
        party.getSaveGame().dngx = (int) x;
        party.getSaveGame().dngy = (int) y;
        party.getSaveGame().dnglevel = 0;
        party.getSaveGame().orientation = 0;
    } else {
        Portal p = Maps.WORLD.getMap().getPortal(map.getId());
        party.getSaveGame().x = (int) x;
        party.getSaveGame().y = (int) y;
        party.getSaveGame().dngx = (p == null ? (int) x : p.getX());
        party.getSaveGame().dngy = (p == null ? (int) y : p.getY());
        party.getSaveGame().dnglevel = (int) z;
        party.getSaveGame().orientation = orientation.getVal() - 1;
    }
    party.getSaveGame().location = map.getId();
    Stage surfaceStage = Maps.WORLD.getMap().getSurfaceMapStage();
    if (surfaceStage != null) {
        party.getSaveGame().resetMonsters();
        Drawable[] objects = new Drawable[24];
        int count = 0;
        for (Actor a : surfaceStage.getActors()) {
            if (a instanceof Drawable) {
                Drawable d = (Drawable) a;
                objects[count] = d;
                if (count > 23) {
                    break;
                }
                count++;
            }
        }
        for (int i = 0; i < 24; i++) {
            if (objects[i] != null) {
                party.getSaveGame().objects_save_tileids[i] = (byte) objects[i].getTile().getIndex();
                party.getSaveGame().objects_save_x[i] = (byte) objects[i].getCx();
                party.getSaveGame().objects_save_y[i] = (byte) objects[i].getCy();
            }
        }
        List<Creature> monsters = Maps.WORLD.getMap().getCreatures();
        for (int i = 0; i < 8 && monsters.size() > i; i++) {
            Tile tile = Ultima4.baseTileSet.getTileByName(monsters.get(i).getTile().toString());
            if (tile == null) {
                continue;
            }
            party.getSaveGame().monster_save_tileids[i] = (byte) tile.getIndex();
            party.getSaveGame().monster_save_x[i] = (byte) monsters.get(i).currentX;
            party.getSaveGame().monster_save_y[i] = (byte) monsters.get(i).currentY;
        }
    }
    try {
        party.getSaveGame().write(PARTY_SAV_BASE_FILENAME);
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        File file = new File("journal.save");
        JAXBContext jaxbContext = JAXBContext.newInstance(JournalEntries.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(this.journalEntries, file);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) Creature(objects.Creature) Drawable(objects.Drawable) Tile(objects.Tile) JAXBContext(javax.xml.bind.JAXBContext) PartyDeathException(util.PartyDeathException) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Portal(objects.Portal) Stage(com.badlogic.gdx.scenes.scene2d.Stage) File(java.io.File)

Example 2 with Drawable

use of objects.Drawable in project ultimate-java by pantinor.

the class GameScreen method preMove.

private boolean preMove(Vector3 currentTile, Direction dir) {
    int nx = (int) currentTile.x;
    int ny = (int) currentTile.y;
    if (context.getParty().getMember(0).getPlayer().status == StatusType.SLEEPING) {
        finishTurn(nx, ny);
        return false;
    }
    if (context.getTransportContext() == TransportContext.BALLOON) {
        log("Drift only!");
        return false;
    }
    if (dir == Direction.NORTH) {
        ny = (int) currentTile.y - 1;
    }
    if (dir == Direction.SOUTH) {
        ny = (int) currentTile.y + 1;
    }
    if (dir == Direction.WEST) {
        nx = (int) currentTile.x - 1;
    }
    if (dir == Direction.EAST) {
        nx = (int) currentTile.x + 1;
    }
    BaseMap bm = context.getCurrentMap();
    if (bm.getBorderbehavior() == MapBorderBehavior.exit) {
        if (nx > bm.getWidth() - 1 || nx < 0 || ny > bm.getHeight() - 1 || ny < 0) {
            // remove any city/town actors (chests) from the map we are leaving
            for (Actor a : mapObjectsStage.getActors()) {
                if (a instanceof Drawable) {
                    Drawable d = (Drawable) a;
                    if (d.getMapId() != Maps.WORLD.getId() && d.getMapId() == bm.getId()) {
                        d.remove();
                    }
                }
            }
            Portal p = Maps.WORLD.getMap().getPortal(bm.getId());
            loadNextMap(Maps.WORLD, p.getX(), p.getY());
            return false;
        }
    }
    int mask = bm.getValidMovesMask(context, (int) currentTile.x, (int) currentTile.y);
    if (!Direction.isDirInMask(dir, mask)) {
        Sounds.play(Sound.BLOCKED);
        finishTurn((int) currentTile.x, (int) currentTile.y);
        return false;
    }
    return true;
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) Drawable(objects.Drawable) Portal(objects.Portal) BaseMap(objects.BaseMap)

Example 3 with Drawable

use of objects.Drawable in project ultimate-java by pantinor.

the class GameScreen method keyUp.

@Override
public boolean keyUp(int keycode) {
    context.setLastCommandTime(System.currentTimeMillis());
    Vector3 v = getCurrentMapCoords();
    Tile ct = context.getCurrentMap().getTile(v);
    if (keycode == Keys.UP) {
        if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.NORTH.getVal()) {
            avatarDirection = Direction.NORTH.getVal() - 1;
            finishTurn((int) v.x, (int) v.y);
            return false;
        }
        if (!preMove(v, Direction.NORTH)) {
            return false;
        }
        if (newMapPixelCoords.y + tilePixelHeight >= context.getCurrentMap().getHeight() * tilePixelHeight) {
            newMapPixelCoords.y = 0;
            postMove(Direction.NORTH, (int) v.x, context.getCurrentMap().getHeight() - 1);
        } else {
            newMapPixelCoords.y = newMapPixelCoords.y + tilePixelHeight;
            postMove(Direction.NORTH, (int) v.x, (int) v.y - 1);
        }
        avatarDirection = Direction.NORTH.getVal() - 1;
    } else if (keycode == Keys.RIGHT) {
        if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.EAST.getVal()) {
            avatarDirection = Direction.EAST.getVal() - 1;
            finishTurn((int) v.x, (int) v.y);
            return false;
        }
        if (!preMove(v, Direction.EAST)) {
            return false;
        }
        if (newMapPixelCoords.x + tilePixelWidth >= context.getCurrentMap().getWidth() * tilePixelWidth) {
            newMapPixelCoords.x = 0;
            postMove(Direction.EAST, 0, (int) v.y);
        } else {
            newMapPixelCoords.x = newMapPixelCoords.x + tilePixelWidth;
            postMove(Direction.EAST, (int) v.x + 1, (int) v.y);
        }
        avatarDirection = Direction.EAST.getVal() - 1;
    } else if (keycode == Keys.LEFT) {
        if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.WEST.getVal()) {
            avatarDirection = Direction.WEST.getVal() - 1;
            finishTurn((int) v.x, (int) v.y);
            return false;
        }
        if (!preMove(v, Direction.WEST)) {
            return false;
        }
        if (newMapPixelCoords.x - tilePixelWidth < 0) {
            newMapPixelCoords.x = (context.getCurrentMap().getWidth() - 1) * tilePixelWidth;
            postMove(Direction.WEST, context.getCurrentMap().getWidth() - 1, (int) v.y);
        } else {
            newMapPixelCoords.x = newMapPixelCoords.x - tilePixelWidth;
            postMove(Direction.WEST, (int) v.x - 1, (int) v.y);
        }
        avatarDirection = Direction.WEST.getVal() - 1;
    } else if (keycode == Keys.DOWN) {
        if (context.getTransportContext() == TransportContext.SHIP && avatarDirection + 1 != Direction.SOUTH.getVal()) {
            avatarDirection = Direction.SOUTH.getVal() - 1;
            finishTurn((int) v.x, (int) v.y);
            return false;
        }
        if (!preMove(v, Direction.SOUTH)) {
            return false;
        }
        if (newMapPixelCoords.y - tilePixelHeight < 0) {
            newMapPixelCoords.y = (context.getCurrentMap().getHeight() - 1) * tilePixelHeight;
            postMove(Direction.SOUTH, (int) v.x, 0);
        } else {
            newMapPixelCoords.y = newMapPixelCoords.y - tilePixelHeight;
            postMove(Direction.SOUTH, (int) v.x, (int) v.y + 1);
        }
        avatarDirection = Direction.SOUTH.getVal() - 1;
    } else if (keycode == Keys.F && context.getTransportContext() == TransportContext.SHIP) {
        log("Fire Cannon > ");
        ShipInputAdapter sia = new ShipInputAdapter(v);
        Gdx.input.setInputProcessor(sia);
        return false;
    } else if (keycode == Keys.H) {
        CombatScreen.holeUp(Maps.WORLD, (int) v.x, (int) v.y, this, context, Ultima4.creatures, Ultima4.standardAtlas, false);
        return false;
    } else if (keycode == Keys.K || keycode == Keys.D) {
        if (context.getCurrentMap().getId() == Maps.WORLD.getId()) {
            if (keycode == Keys.K && context.getTransportContext() == TransportContext.BALLOON) {
                context.getParty().getSaveGame().balloonstate = 1;
                log("Klimb altitude");
            } else if (keycode == Keys.D && context.getTransportContext() == TransportContext.BALLOON) {
                if (ct.getRule().has(TileAttrib.canlandballoon)) {
                    context.getParty().getSaveGame().balloonstate = 0;
                    renderer.getFOV().calculateFOV(context.getCurrentMap().getShadownMap(), (int) v.x, (int) v.y, 17f);
                    log("Land balloon");
                } else {
                    log("Not here!");
                }
            }
        } else {
            Portal p = context.getCurrentMap().getPortal(v.x, v.y, 0);
            if (p != null) {
                loadNextMap(Maps.get(p.getDestmapid()), p.getStartx(), p.getStarty());
                log(p.getMessage());
                return false;
            }
        }
    } else if (keycode == Keys.E) {
        if (context.getTransportContext() == TransportContext.BALLOON) {
            log("Only on foot!");
            return false;
        }
        Portal p = context.getCurrentMap().getPortal(v.x, v.y, 0);
        if (p != null) {
            if (Maps.get(p.getDestmapid()).getMap().getType() == MapType.shrine) {
                Virtue virtue = Virtue.get(Maps.get(p.getDestmapid()).getId() - 25);
                if (context.getParty().canEnterShrine(virtue)) {
                    loadNextMap(Maps.get(p.getDestmapid()), p.getStartx(), p.getStarty());
                } else {
                    log("Thou dost not bear the rune of entry!");
                    log("A strange force keeps you out!");
                }
            } else {
                Maps dest = Maps.get(p.getDestmapid());
                if (dest == Maps.ABYSS) {
                    if ((context.getParty().getSaveGame().items & Item.CANDLE_USED.getLoc()) == 0 || (context.getParty().getSaveGame().items & Item.BELL_USED.getLoc()) == 0 || (context.getParty().getSaveGame().items & Item.BOOK_USED.getLoc()) == 0) {
                        log("A strange force keeps you out!");
                        return false;
                    }
                }
                if (p.getDestmapid() != context.getCurrentMap().getId()) {
                    loadNextMap(dest, p.getStartx(), p.getStarty());
                } else {
                    newMapPixelCoords = getMapPixelCoords(p.getStartx(), p.getStarty());
                    recalcFOV(context.getCurrentMap(), p.getStartx(), p.getStarty());
                }
                return false;
            }
        }
    } else if (keycode == Keys.Q) {
        if (context.getCurrentMap().getId() == Maps.WORLD.getId() && context.getParty().getSaveGame().balloonstate == 0) {
            context.saveGame(v.x, v.y, 0, null, Maps.WORLD);
            log("Saved Game.");
        } else {
            log("Cannot save here!");
        }
    } else if (keycode == Keys.L) {
        if (context.getCurrentMap().getId() == Maps.WORLD.getId()) {
            if (context.getParty().getSaveGame().sextants >= 1) {
                log("Locate position with sextant");
                log(String.format("Latitude:    %s' %s\"", (char) ((int) v.y / 16 + 'A'), (char) ((int) v.y % 16 + 'A')));
                log(String.format("Longitude: %s' %s\"", (char) ((int) v.x / 16 + 'A'), (char) ((int) v.x % 16 + 'A')));
            } else {
                log("Locate position with what?");
            }
        } else {
            log("Not here!");
        }
    } else if (keycode == Keys.N) {
        log("New Order:");
        log("exhange #:");
        NewOrderInputAdapter noia = new NewOrderInputAdapter(this);
        Gdx.input.setInputProcessor(noia);
        return false;
    } else if (keycode == Keys.S) {
        BaseMap bm = context.getCurrentMap();
        ItemMapLabels l = bm.searchLocation(this, context.getParty(), (int) v.x, (int) v.y, 0);
        if (l != null) {
            log("You found " + l.getDesc() + ".");
        } else {
            log("Nothing here!");
        }
    } else if (keycode == Keys.M) {
        mainGame.setScreen(new MixtureScreen(mainGame, this, Ultima4.skin, context.getParty()));
    } else if (keycode == Keys.B) {
        board((int) v.x, (int) v.y);
    } else if (keycode == Keys.X) {
        if (context.getTransportContext() == TransportContext.SHIP) {
            Tile st = Ultima4.baseTileSet.getTileByName("ship");
            Drawable ship = new Drawable(context.getCurrentMap(), (int) v.x, (int) v.y, st, Ultima4.standardAtlas);
            ship.setX(newMapPixelCoords.x);
            ship.setY(newMapPixelCoords.y);
            mapObjectsStage.addActor(ship);
        } else if (context.getTransportContext() == TransportContext.HORSE) {
            Creature cr = Ultima4.creatures.getInstance(CreatureType.horse, Ultima4.standardAtlas);
            cr.currentX = (int) v.x;
            cr.currentY = (int) v.y;
            context.getCurrentMap().addCreature(cr);
        } else if (context.getTransportContext() == TransportContext.BALLOON) {
            if (context.getParty().getSaveGame().balloonstate == 0) {
                addBalloonActor((int) v.x, (int) v.y);
                context.getParty().getSaveGame().balloonx = (int) v.x;
                context.getParty().getSaveGame().balloony = (int) v.y;
            } else {
                log("Thou must land first!");
                return false;
            }
        }
        context.getParty().setTransport(Ultima4.baseTileSet.getTileByIndex(0x1f));
        mainAvatar = avatarAnim;
    } else if (keycode == Keys.P) {
        peerGem();
    } else if (keycode == Keys.U) {
        log("Use Item:");
        log("");
        ItemInputAdapter iia = new ItemInputAdapter(this);
        Gdx.input.setInputProcessor(iia);
        return false;
    } else if (keycode == Keys.T || keycode == Keys.O || keycode == Keys.J || keycode == Keys.L || keycode == Keys.A || keycode == Keys.G || keycode == Keys.R || keycode == Keys.W) {
        Gdx.input.setInputProcessor(sip);
        sip.setinitialKeyCode(keycode, context.getCurrentMap(), (int) v.x, (int) v.y);
        return false;
    } else if (keycode == Keys.C) {
        log("Cast Spell: ");
        log("Who casts (1-8): ");
        Gdx.input.setInputProcessor(new SpellInputProcessor(this, context, stage, (int) v.x, (int) v.y, null));
        return false;
    } else if (keycode == Keys.Z) {
        showZstats = showZstats + 1;
        if (showZstats >= STATS_PLAYER1 && showZstats <= STATS_PLAYER8) {
            if (showZstats > context.getParty().getMembers().size()) {
                showZstats = STATS_WEAPONS;
            }
        }
        if (showZstats > STATS_SPELLS) {
            showZstats = STATS_NONE;
        }
    } else if (keycode == Keys.ESCAPE) {
        mainGame.setScreen(new BookScreen(mainGame, this, Ultima4.skin));
    } else if (keycode == Keys.SPACE) {
        log("Pass");
    }
    finishTurn((int) v.x, (int) v.y);
    return false;
}
Also used : Creature(objects.Creature) Drawable(objects.Drawable) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) Tile(objects.Tile) Vector3(com.badlogic.gdx.math.Vector3) BaseMap(objects.BaseMap) Portal(objects.Portal)

Example 4 with Drawable

use of objects.Drawable in project ultimate-java by pantinor.

the class GameScreen method getChest.

public void getChest(int index, int x, int y) {
    if (context.getParty().isFlying()) {
        log("Not in a ballon!");
        return;
    }
    boolean found = false;
    Drawable chest = null;
    Array<Actor> as = mapObjectsStage.getActors();
    for (Actor a : as) {
        if (a instanceof Drawable) {
            Drawable d = (Drawable) a;
            if (StringUtils.equals("chest", d.getTile().getName()) && d.getCx() == x && d.getCy() == y) {
                chest = (Drawable) a;
                found = true;
                chest.remove();
                break;
            }
        }
    }
    if (chest == null) {
        // check tile too, ie in cities
        Tile tile = context.getCurrentMap().getTile(x, y);
        if (tile.getRule() == TileRule.chest) {
            replaceTile("brick_floor", x, y);
            found = true;
        }
    }
    try {
        if (found) {
            PartyMember pm = context.getParty().getMember(index);
            if (pm == null) {
                System.err.println("member is null " + index);
            }
            if (pm.getPlayer() == null) {
                System.err.println("player is null " + index);
            }
            context.getChestTrapHandler(pm);
            log(String.format("The Chest Holds: %d Gold", context.getParty().getChestGold()));
            if (context.getCurrentMap().getType() == MapType.city) {
                context.getParty().adjustKarma(KarmaAction.STOLE_CHEST);
            }
        } else {
            log("Not Here!");
        }
    } catch (PartyDeathException e) {
        partyDeath();
    }
}
Also used : PartyMember(objects.Party.PartyMember) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Drawable(objects.Drawable) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) Tile(objects.Tile) PartyDeathException(util.PartyDeathException)

Example 5 with Drawable

use of objects.Drawable in project ultimate-java by pantinor.

the class SpellUtil method spellUndead.

public static void spellUndead(BaseScreen screen, PartyMember caster) {
    if (screen.scType == ScreenType.COMBAT) {
        SequenceAction seq = Actions.action(SequenceAction.class);
        final CombatScreen combatScreen = (CombatScreen) screen;
        int level = caster.getPlayer().getLevel();
        // from the AD&D dungeon masters guide page 75 :)
        boolean turn = Utils.rand.nextInt(100) >= 50;
        if (level > 1) {
            turn = Utils.rand.nextInt(100) >= 35;
        }
        if (level > 2) {
            turn = Utils.rand.nextInt(100) >= 20;
        }
        if (level > 3) {
            turn = true;
        }
        for (Creature cr : combatScreen.combatMap.getCreatures()) {
            if (cr.getUndead() && turn) {
                Tile tile = Ultima4.baseTileSet.getTileByName("hit_flash");
                Drawable d = new Drawable(combatScreen.combatMap, cr.currentX, cr.currentY, tile, Ultima4.standardAtlas);
                d.setX(cr.currentPos.x);
                d.setY(cr.currentPos.y);
                d.addAction(Actions.sequence(Actions.delay(.4f), Actions.fadeOut(.2f), Actions.removeActor()));
                seq.addAction(Actions.run(new AddActorAction(combatScreen.getStage(), d)));
                seq.addAction(Actions.run(new PlaySoundAction(Sound.NPC_STRUCK)));
                Utils.dealDamage(caster, cr, 23);
            } else {
                seq.addAction(Actions.run(new PlaySoundAction(Sound.EVADE)));
            }
            if (cr.getDamageStatus() == CreatureStatus.DEAD) {
                seq.addAction(Actions.run(combatScreen.new RemoveCreatureAction(cr)));
            }
        }
        seq.addAction(Actions.run(new Runnable() {

            @Override
            public void run() {
                combatScreen.finishPlayerTurn();
            }
        }));
        combatScreen.getStage().addAction(seq);
    }
}
Also used : Creature(objects.Creature) Drawable(objects.Drawable) Tile(objects.Tile) SequenceAction(com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)

Aggregations

Drawable (objects.Drawable)12 Tile (objects.Tile)10 Creature (objects.Creature)8 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)6 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)5 Vector3 (com.badlogic.gdx.math.Vector3)3 SequenceAction (com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)3 Portal (objects.Portal)3 PartyDeathException (util.PartyDeathException)3 BaseMap (objects.BaseMap)2 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Actions.removeActor (com.badlogic.gdx.scenes.scene2d.actions.Actions.removeActor)1 File (java.io.File)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 Party (objects.Party)1 PartyMember (objects.Party.PartyMember)1 ProjectileActor (objects.ProjectileActor)1