Search in sources :

Example 6 with Portal

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

the class DungeonScreen method endCombat.

@Override
public void endCombat(boolean isWon, BaseMap combatMap, boolean wounded) {
    mainGame.setScreen(this);
    if (isWon) {
        if (currentEncounter != null) {
            log("Victory!");
            context.getParty().adjustKarma(KarmaAction.KILLED_EVIL);
            int x = (Math.round(currentPos.x) - 1);
            int y = (Math.round(currentPos.z) - 1);
            /* add a chest, if the creature leaves one */
            if (!currentEncounter.getNochest() && dungeonTiles[currentLevel][x][y] == DungeonTile.NOTHING) {
                ModelInstance instance = new ModelInstance(chestModel, x + .5f, 0, y + .5f);
                instance.nodes.get(0).scale.set(.010f, .010f, .010f);
                instance.calculateTransforms();
                DungeonTileModelInstance in = new DungeonTileModelInstance(instance, DungeonTile.CHEST, currentLevel);
                in.x = x;
                in.y = y;
                modelInstances.add(in);
                dungeonTiles[currentLevel][x][y] = DungeonTile.CHEST;
            }
        }
    } else {
        if (combatMap.getType() == MapType.combat && context.getParty().didAnyoneFlee()) {
            log("Battle is lost!");
        // no flee penalty in dungeons
        } else if (!context.getParty().isAnyoneAlive()) {
            partyDeath();
        }
    }
    if (currentEncounter != null) {
        dngMap.getMap().removeCreature(currentEncounter);
        currentEncounter = null;
    }
    // if exiting dungeon rooms, move out of the room with orientation to next coordinate
    if (combatMap.getType() == MapType.dungeon) {
        Direction exitDirection = context.getParty().getActivePartyMember().combatMapExitDirection;
        if (exitDirection != null) {
            currentDir = exitDirection;
            int x = (Math.round(currentPos.x) - 1);
            int y = (Math.round(currentPos.z) - 1);
            // check for portal to another dungeon
            for (Portal p : combatMap.getPortals()) {
                if (p.getX() == x && p.getY() == y && p.getExitDirection() == exitDirection) {
                    Maps m = Maps.get(p.getDestmapid());
                    if (m == dngMap) {
                        break;
                    }
                    log("Entering " + m.getLabel() + "!");
                    DungeonScreen sc = new DungeonScreen(this.gameScreen, this.context, m);
                    sc.restoreSaveGameLocation(p.getStartx(), p.getStarty(), p.getStartlevel(), currentDir);
                    mainGame.setScreen(sc);
                    this.gameScreen.newMapPixelCoords = this.gameScreen.getMapPixelCoords(p.getRetroActiveDest().getX(), p.getRetroActiveDest().getY());
                    return;
                }
            }
            if (exitDirection == Direction.EAST) {
                x = x + 1;
                if (x > 7) {
                    x = 0;
                }
            } else if (exitDirection == Direction.WEST) {
                x = x - 1;
                if (x < 0) {
                    x = 7;
                }
            } else if (exitDirection == Direction.NORTH) {
                y = y - 1;
                if (y < 0) {
                    y = 7;
                }
            } else if (exitDirection == Direction.SOUTH) {
                y = y + 1;
                if (y > 7) {
                    y = 0;
                }
            }
            DungeonTile tile = dungeonTiles[currentLevel][x][y];
            try {
                if (tile != DungeonTile.WALL) {
                    currentPos = new Vector3(x + .5f, .5f, y + .5f);
                    camera.position.set(currentPos);
                    if (currentDir == Direction.EAST) {
                        camera.lookAt(currentPos.x + 1, currentPos.y, currentPos.z);
                    } else if (currentDir == Direction.WEST) {
                        camera.lookAt(currentPos.x - 1, currentPos.y, currentPos.z);
                    } else if (currentDir == Direction.NORTH) {
                        camera.lookAt(currentPos.x, currentPos.y, currentPos.z - 1);
                    } else if (currentDir == Direction.SOUTH) {
                        camera.lookAt(currentPos.x, currentPos.y, currentPos.z + 1);
                    }
                    checkTileAffects(tile, x, y);
                    moveMiniMapIcon();
                }
            } catch (PartyDeathException e) {
                partyDeath();
            }
            if (tile.getValue() >= 208 && tile.getValue() <= 223) {
                RoomLocater loc = null;
                for (RoomLocater r : locaters) {
                    if (r.z == currentLevel && r.x == x && r.y == y) {
                        loc = r;
                        break;
                    }
                }
                enterRoom(loc, Direction.reverse(currentDir));
            }
        }
    }
}
Also used : DungeonTileModelInstance(util.DungeonTileModelInstance) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) DungeonTileModelInstance(util.DungeonTileModelInstance) Portal(objects.Portal) Vector3(com.badlogic.gdx.math.Vector3) PartyDeathException(util.PartyDeathException)

Aggregations

Portal (objects.Portal)6 BaseMap (objects.BaseMap)3 Drawable (objects.Drawable)3 Tile (objects.Tile)3 Vector3 (com.badlogic.gdx.math.Vector3)2 Actor (com.badlogic.gdx.scenes.scene2d.Actor)2 File (java.io.File)2 JAXBContext (javax.xml.bind.JAXBContext)2 Creature (objects.Creature)2 PartyDeathException (util.PartyDeathException)2 FileHandle (com.badlogic.gdx.files.FileHandle)1 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)1 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)1 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)1 TiledMapTile (com.badlogic.gdx.maps.tiled.TiledMapTile)1 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 MapSet (objects.MapSet)1