Search in sources :

Example 36 with Tile

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

the class CombatScreen method moveCreature.

/**
 * Moves an object in combat according to its chosen combat action
 */
public boolean moveCreature(CombatAction action, Creature cr, int targetX, int targetY) {
    int nx = cr.currentX;
    int ny = cr.currentY;
    int mask = combatMap.getValidMovesMask(context, nx, ny, cr, -1, -1);
    Direction dir;
    if (action == CombatAction.FLEE) {
        dir = Utils.getPath(MapBorderBehavior.fixed, combatMap.getWidth(), combatMap.getHeight(), targetX, targetY, mask, false, nx, ny);
        if (dir == null && (nx == 0 || ny == 0)) {
            // force a map exit
            cr.currentX = -1;
            cr.currentY = -1;
            return true;
        }
    } else {
        dir = Utils.getPath(MapBorderBehavior.fixed, combatMap.getWidth(), combatMap.getHeight(), targetX, targetY, mask, true, nx, ny);
    }
    Vector3 pixelPos = null;
    if (dir == null) {
        return false;
    } else {
        if (dir == Direction.NORTH) {
            ny--;
        }
        if (dir == Direction.SOUTH) {
            ny++;
        }
        if (dir == Direction.EAST) {
            nx++;
        }
        if (dir == Direction.WEST) {
            nx--;
        }
    }
    boolean slowed = false;
    SlowedType slowedType = SlowedType.SLOWED_BY_TILE;
    if (cr.getSwims() || cr.getSails()) {
        slowedType = SlowedType.SLOWED_BY_WIND;
    } else if (cr.getFlies()) {
        slowedType = SlowedType.SLOWED_BY_NOTHING;
    }
    switch(slowedType) {
        case SLOWED_BY_TILE:
            Tile t = combatMap.getTile(nx, ny);
            if (t != null) {
                slowed = context.slowedByTile(t);
            }
            break;
        case SLOWED_BY_WIND:
            slowed = context.slowedByWind(dir);
            break;
        case SLOWED_BY_NOTHING:
        default:
            break;
    }
    if (!slowed) {
        pixelPos = getMapPixelCoords(nx, ny);
        cr.currentPos = pixelPos;
        cr.currentX = nx;
        cr.currentY = ny;
        return true;
    }
    return false;
}
Also used : Tile(objects.Tile) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) TiledMapTile(com.badlogic.gdx.maps.tiled.TiledMapTile) Vector3(com.badlogic.gdx.math.Vector3)

Example 37 with Tile

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

the class Context method getCombatMap.

public Maps getCombatMap(Creature c, BaseMap bm, int creatureX, int creatureY, int avatarX, int avatarY) {
    Tile ct = bm.getTile(creatureX, creatureY);
    Maps cm = ct.getCombatMap();
    TileRule ptr = bm.getTile(avatarX, avatarY).getRule();
    if (c.getSwims() && !ptr.has(TileAttrib.unwalkable)) {
        cm = Maps.SHORE_CON;
    } else if (c.getSails() && !ptr.has(TileAttrib.unwalkable)) {
        cm = Maps.SHORSHIP_CON;
    }
    if (transportContext == TransportContext.SHIP) {
        if (c.getSwims()) {
            cm = Maps.SHIPSEA_CON;
        } else if (c.getSails()) {
            cm = Maps.SHIPSHIP_CON;
        } else {
            cm = Maps.SHIPSHOR_CON;
        }
    }
    return cm;
}
Also used : Tile(objects.Tile)

Example 38 with Tile

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

the class SpellUtil method spellDispel.

public static void spellDispel(BaseScreen screen, Context context, PartyMember caster, Direction dir) {
    if (screen.scType == ScreenType.MAIN) {
        GameScreen gameScreen = (GameScreen) screen;
        Vector3 v = gameScreen.getCurrentMapCoords();
        int x = (int) v.x;
        int y = (int) v.y;
        if (dir == Direction.NORTH) {
            y--;
        }
        if (dir == Direction.SOUTH) {
            y++;
        }
        if (dir == Direction.EAST) {
            x++;
        }
        if (dir == Direction.WEST) {
            x--;
        }
        Tile dispellable = context.getCurrentMap().getTile(x, y);
        if (dispellable.getRule() == null || !dispellable.getRule().has(TileAttrib.dispelable)) {
            return;
        }
        gameScreen.replaceTile("grass", x, y);
    } else if (screen.scType == ScreenType.COMBAT) {
        CombatScreen combatScreen = (CombatScreen) screen;
        int x = caster.combatCr.currentX;
        int y = caster.combatCr.currentY;
        if (dir == Direction.NORTH) {
            y--;
        }
        if (dir == Direction.SOUTH) {
            y++;
        }
        if (dir == Direction.EAST) {
            x++;
        }
        if (dir == Direction.WEST) {
            x--;
        }
        Tile dispellable = combatScreen.combatMap.getTile(x, y);
        if (dispellable.getRule() == null || !dispellable.getRule().has(TileAttrib.dispelable)) {
            return;
        }
        combatScreen.replaceTile("dungeon_floor", x, y);
    } else if (screen.scType == ScreenType.DUNGEON) {
        DungeonScreen dngScreen = (DungeonScreen) screen;
        int x = (Math.round(dngScreen.currentPos.x) - 1);
        int y = (Math.round(dngScreen.currentPos.z) - 1);
        if (dngScreen.currentDir == Direction.NORTH) {
            y = y - 1 < 0 ? DungeonScreen.DUNGEON_MAP - 1 : y - 1;
        }
        if (dngScreen.currentDir == Direction.SOUTH) {
            y = y + 1 >= DungeonScreen.DUNGEON_MAP ? 0 : y + 1;
        }
        if (dngScreen.currentDir == Direction.EAST) {
            x = x + 1 >= DungeonScreen.DUNGEON_MAP ? 0 : x + 1;
        }
        if (dngScreen.currentDir == Direction.WEST) {
            x = x - 1 < 0 ? DungeonScreen.DUNGEON_MAP - 1 : x - 1;
        }
        DungeonTileModelInstance dispellable = null;
        for (DungeonTileModelInstance dmi : dngScreen.modelInstances) {
            if (dmi.getTile().getValue() >= DungeonTile.FIELD_POISON.getValue() && dmi.getTile().getValue() <= DungeonTile.FIELD_SLEEP.getValue()) {
                if (dmi.x == x && dmi.y == y && dmi.getLevel() == dngScreen.currentLevel) {
                    dispellable = dmi;
                    break;
                }
            }
        }
        if (dispellable != null) {
            dngScreen.modelInstances.remove(dispellable);
            dngScreen.dungeonTiles[dngScreen.currentLevel][x][y] = DungeonTile.NOTHING;
            dngScreen.createMiniMap();
        }
    }
}
Also used : DungeonTileModelInstance(util.DungeonTileModelInstance) Tile(objects.Tile) Vector3(com.badlogic.gdx.math.Vector3)

Example 39 with Tile

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

the class SpellUtil method spellTremor.

public static void spellTremor(BaseScreen screen, PartyMember caster) {
    if (screen.scType == ScreenType.COMBAT) {
        final CombatScreen combatScreen = (CombatScreen) screen;
        SequenceAction seq = Actions.action(SequenceAction.class);
        for (Creature cr : combatScreen.combatMap.getCreatures()) {
            /* creatures with over 192 hp are unaffected */
            if (cr.getHP() > 192) {
                seq.addAction(Actions.run(new PlaySoundAction(Sound.EVADE)));
                continue;
            } else {
                if (Utils.rand.nextInt(2) == 0) {
                    /* Deal maximum damage to creature */
                    Utils.dealDamage(caster, cr, 0xFF);
                    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)));
                } else if (Utils.rand.nextInt(2) == 0) {
                    /* Deal enough damage to creature to make it flee */
                    if (cr.getHP() > 23) {
                        Utils.dealDamage(caster, cr, cr.getHP() - 23);
                        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)));
                    }
                } 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

Tile (objects.Tile)39 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)22 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)16 Creature (objects.Creature)12 Drawable (objects.Drawable)10 File (java.io.File)8 JAXBContext (javax.xml.bind.JAXBContext)8 DungeonTile (ultima.Constants.DungeonTile)8 Unmarshaller (javax.xml.bind.Unmarshaller)7 BaseMap (objects.BaseMap)7 TileSet (objects.TileSet)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)6 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)5 TiledMap (com.badlogic.gdx.maps.tiled.TiledMap)5 Vector3 (com.badlogic.gdx.math.Vector3)5 FileInputStream (java.io.FileInputStream)5 ArrayList (java.util.ArrayList)5 MapSet (objects.MapSet)5 TiledMapTileLayer (com.badlogic.gdx.maps.tiled.TiledMapTileLayer)4