Search in sources :

Example 1 with Creature

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

the class CombatScreen method setAmbushingMonsters.

public void setAmbushingMonsters(BaseScreen returnScreen, int x, int y, TextureAtlas a1) {
    CreatureType ct = Ultima4.creatures.getRandomAmbushing();
    fillCreatureTable(ct);
    MapLayer mLayer = tmap.getLayers().get("Monster Positions");
    Iterator<MapObject> iter = mLayer.getObjects().iterator();
    while (iter.hasNext()) {
        MapObject obj = iter.next();
        int index = (Integer) obj.getProperties().get("index");
        int startX = (Integer) obj.getProperties().get("startX");
        int startY = (Integer) obj.getProperties().get("startY");
        if (crSlots[index] == null) {
            continue;
        }
        Creature c = creatureSet.getInstance(crSlots[index], a1);
        c.currentX = startX;
        c.currentY = startY;
        c.currentPos = getMapPixelCoords(startX, startY);
        combatMap.addCreature(c);
    }
    // for the chest when returning after combat
    returnScreen.currentEncounter = creatureSet.getInstance(ct, a1);
    returnScreen.currentEncounter.currentX = x;
    returnScreen.currentEncounter.currentY = y;
    returnScreen.currentEncounter.currentPos = returnScreen.getMapPixelCoords(x, y);
}
Also used : Creature(objects.Creature) MapLayer(com.badlogic.gdx.maps.MapLayer) MapObject(com.badlogic.gdx.maps.MapObject)

Example 2 with Creature

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

the class CombatScreen method preMove.

private boolean preMove(Creature active, Direction dir) {
    int x = active.currentX;
    int y = active.currentY;
    AttackVector next = null;
    if (dir == Direction.NORTH) {
        next = new AttackVector(x, y - 1);
    }
    if (dir == Direction.SOUTH) {
        next = new AttackVector(x, y + 1);
    }
    if (dir == Direction.EAST) {
        next = new AttackVector(x + 1, y);
    }
    if (dir == Direction.WEST) {
        next = new AttackVector(x - 1, y);
    }
    if (next.x > combatMap.getWidth() - 1 || next.x < 0 || next.y > combatMap.getHeight() - 1 || next.y < 0) {
        if (combatMap.getType() == MapType.dungeon && !party.isOKtoExitDirection(dir)) {
            log("Cannot exit in that direction!");
            Sounds.play(Sound.BLOCKED);
            return false;
        } else {
            PartyMember ap = party.getActivePartyMember();
            ap.fled = true;
            ap.combatMapExitDirection = dir;
            Sounds.play(Sound.FLEE);
            if (party.getAbleCombatPlayers() == 0) {
                end();
                return false;
            } else {
                int ni = party.getNextActiveIndex();
                Creature nextActivePlayer = party.getMember(ni).combatCr;
                cursor.setPos(nextActivePlayer.currentPos);
            }
        }
    } else {
        int mask = combatMap.getValidMovesMask(context, x, y);
        if (!Direction.isDirInMask(dir, mask)) {
            Sounds.play(Sound.BLOCKED);
            return false;
        }
    }
    return true;
}
Also used : Creature(objects.Creature) PartyMember(objects.Party.PartyMember)

Example 3 with Creature

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

the class CombatScreen method keyUp.

@Override
public boolean keyUp(int keycode) {
    PartyMember ap = party.getActivePartyMember();
    Creature active = ap.combatCr;
    try {
        if (keycode == Keys.SPACE || ap.isDisabled()) {
            log("Pass");
        } else if (keycode == Keys.UP) {
            if (preMove(active, Direction.NORTH)) {
                active.currentY--;
                active.currentPos = getMapPixelCoords(active.currentX, active.currentY);
                checkTileAffects(ap, active.currentX, active.currentY);
            }
        } else if (keycode == Keys.DOWN) {
            if (preMove(active, Direction.SOUTH)) {
                active.currentY++;
                active.currentPos = getMapPixelCoords(active.currentX, active.currentY);
                checkTileAffects(ap, active.currentX, active.currentY);
            }
        } else if (keycode == Keys.RIGHT) {
            if (preMove(active, Direction.EAST)) {
                active.currentX++;
                active.currentPos = getMapPixelCoords(active.currentX, active.currentY);
                checkTileAffects(ap, active.currentX, active.currentY);
            }
        } else if (keycode == Keys.LEFT) {
            if (preMove(active, Direction.WEST)) {
                active.currentX--;
                active.currentPos = getMapPixelCoords(active.currentX, active.currentY);
                checkTileAffects(ap, active.currentX, active.currentY);
            }
        } else if (keycode == Keys.A) {
            log("Attack: ");
            Gdx.input.setInputProcessor(sip);
            sip.setinitialKeyCode(keycode, combatMap, active.currentX, active.currentY);
            return false;
        } else if (keycode == Keys.C) {
            log("Cast Spell (A-Z): ");
            Gdx.input.setInputProcessor(new SpellInputProcessor(this, context, stage, active.currentX, active.currentY, ap));
            return false;
        } else if (keycode == Keys.U) {
            Tile tile = combatMap.getTile(active.currentX, active.currentY);
            if (// altar
            tile.getIndex() == 74 || (party.getSaveGame().items & Item.RAGE_GOD.getLoc()) > 0 || (party.getSaveGame().items & Item.MASK_MINAX.getLoc()) > 0) {
                // altar or rage of god
                log("Use which item: ");
                log("");
                Gdx.input.setInputProcessor(sip);
                sip.setinitialKeyCode(keycode, combatMap, active.currentX, active.currentY);
                return false;
            } else {
                log("Nothing to use!");
            }
        } else if (keycode == Keys.R) {
            Gdx.input.setInputProcessor(new ReadyWearInputAdapter(ap, true));
            return false;
        } else if (keycode == Keys.W) {
            Gdx.input.setInputProcessor(new ReadyWearInputAdapter(ap, false));
            return false;
        } else if (keycode == Keys.G) {
            getChest(party.getActivePlayer(), active.currentX, active.currentY);
            return false;
        } else if (keycode == Keys.Z) {
            showZstats = showZstats + 1;
            if (showZstats >= STATS_PLAYER1 && showZstats <= STATS_PLAYER8) {
                if (showZstats > party.getMembers().size()) {
                    showZstats = STATS_WEAPONS;
                }
            }
            if (showZstats > STATS_SPELLS) {
                showZstats = STATS_NONE;
            }
            return false;
        }
        finishPlayerTurn();
    } catch (PartyDeathException e) {
        this.returnScreen.partyDeath();
    }
    return false;
}
Also used : Creature(objects.Creature) PartyMember(objects.Party.PartyMember) Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) PartyDeathException(util.PartyDeathException)

Example 4 with Creature

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

the class CombatScreen method finishPlayerTurn.

public void finishPlayerTurn() {
    // remove dead creatures
    Iterator<Creature> iter = combatMap.getCreatures().iterator();
    while (iter.hasNext()) {
        Creature c = iter.next();
        if (c.getDamageStatus() == CreatureStatus.DEAD) {
            iter.remove();
        }
    }
    boolean roundIsDone = party.isRoundDone() || combatMap.getCreatures().isEmpty();
    PartyMember next = party.getAndSetNextActivePlayer();
    if (next != null) {
        cursor.setVisible(true);
        Creature nextActivePlayer = next.combatCr;
        cursor.setPos(nextActivePlayer.currentPos);
    } else {
        cursor.setVisible(false);
    }
    if (roundIsDone) {
        finishTurn(0, 0);
    }
}
Also used : Creature(objects.Creature) PartyMember(objects.Party.PartyMember)

Example 5 with Creature

use of objects.Creature 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)

Aggregations

Creature (objects.Creature)32 Tile (objects.Tile)12 Drawable (objects.Drawable)8 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)6 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)6 Vector3 (com.badlogic.gdx.math.Vector3)6 SequenceAction (com.badlogic.gdx.scenes.scene2d.actions.SequenceAction)6 Actor (com.badlogic.gdx.scenes.scene2d.Actor)5 PartyMember (objects.Party.PartyMember)5 PartyDeathException (util.PartyDeathException)5 MapLayer (com.badlogic.gdx.maps.MapLayer)3 DungeonTileModelInstance (util.DungeonTileModelInstance)3 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)2 Texture (com.badlogic.gdx.graphics.Texture)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 MapObject (com.badlogic.gdx.maps.MapObject)2 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)2 Portal (objects.Portal)2 AssetManager (com.badlogic.gdx.assets.AssetManager)1 FileHandle (com.badlogic.gdx.files.FileHandle)1