Search in sources :

Example 1 with LobbyPlayer

use of de.gg.game.network.LobbyPlayer in project ProjektGG by eskalon.

the class ServersideActionHandler method startNextRoundForEveryone.

private synchronized void startNextRoundForEveryone() {
    Log.info("Server", "Alle Spieler sind für die Runde bereit");
    for (LobbyPlayer player : server.getPlayers().values()) {
        player.setReady(false);
    }
    clientResultListeners.onAllPlayersReadied();
    session.startNextRound();
}
Also used : LobbyPlayer(de.gg.game.network.LobbyPlayer)

Example 2 with LobbyPlayer

use of de.gg.game.network.LobbyPlayer in project ProjektGG by eskalon.

the class GameSession method init.

/**
 * Sets the game up by initializing the world, the game entities and the
 * processing systems.
 * <p>
 * After the initialization the session can be updated via calling
 * {@link #update()}. To resume the game after a round ended
 * {@link #startNextRound()} has to get called.
 *
 * @param players
 *            A hashmap of all players in this session.
 * @param savedGame
 *            <i>Not</i> <code>null</code> if this is a loaded game state.
 */
public synchronized void init(HashMap<Short, LobbyPlayer> players, @Nullable SavedGame savedGame) {
    if (savedGame == null) {
        this.world = new World();
        this.world.generate(sessionSetup, players);
    } else {
        this.world = savedGame.world;
        this.currentRound = savedGame.currentRound;
        // Switch player IDs when loading game
        if (savedGame != null) {
            for (Entry<Short, LobbyPlayer> newE : players.entrySet()) {
                for (Entry<Short, String> oldE : savedGame.clientIdentifiers.entrySet()) {
                    if (newE.getValue().getHostname().equals(oldE.getValue())) {
                        // Change all mentions of the saved player id to the
                        // new one
                        // Use negative numbers so there are no collisions
                        Player p = world.getPlayers().remove(oldE.getKey());
                        world.getPlayers().put((short) -newE.getKey(), p);
                    }
                }
            }
            // Revert the IDs back to positive numbers
            for (short s : savedGame.world.getPlayers().keySet()) {
                Player p = world.getPlayers().remove(s);
                world.getPlayers().put((short) -s, p);
            }
        }
    // TODO in den Konstruktoren die Setups setzen
    // TODO in der Lobby das Setup disablen
    }
    // Add and initialize the smp system(s)
    this.roundEndSystem = new RoundEndSystem(localNetworkId);
    this.roundEndSystem.init(world);
    // Init the tick counter
    this.tickCounter = new TickCounter(new TickHandler() {

        @Override
        public void onTick() {
            fixedUpdate();
        }

        @Override
        public int getDeltaMultiplier() {
            return gameSpeed.getDeltaTimeMultiplied();
        }
    }, TICKS_PER_ROUND, TICK_DURATION, savedGame == null ? 0 : savedGame.lastProcessedTick);
    this.initialized = true;
}
Also used : TickCounter(de.gg.engine.misc.TickCounter) LobbyPlayer(de.gg.game.network.LobbyPlayer) Player(de.gg.game.model.entities.Player) World(de.gg.game.model.World) LobbyPlayer(de.gg.game.network.LobbyPlayer) RoundEndSystem(de.gg.game.systems.smp.RoundEndSystem) TickHandler(de.gg.engine.misc.TickCounter.TickHandler)

Example 3 with LobbyPlayer

use of de.gg.game.network.LobbyPlayer in project ProjektGG by eskalon.

the class AuthoritativeSession method init.

/**
 * {@inheritDoc}
 */
@Override
public void init(HashMap<Short, LobbyPlayer> players, @Nullable SavedGame savedGame) {
    for (LobbyPlayer player : players.values()) {
        player.setReady(false);
    }
    super.init(players, savedGame);
    // FIXME wenn man ein zweites mal ein spiel hostet, kann es passieren,
    // dass während dem obigen init() der GameLoadingScreen fertig wird.
    // Während dann die Modelle gesetzt werden, werden im init nochmals die
    // Buildings verändert. -> zusammenlegen
    // Setup the server processing systems
    ServerProcessingSystem<Character> s;
    s = new FirstCharacterEventWaveServerSystem(clientResultListeners);
    s.init(world, sessionSetup.getSeed());
    this.characterSystems.add(s);
    s = new NpcActionSystem(clientResultListeners);
    s.init(world, sessionSetup.getSeed());
    this.characterSystems.add(s);
    s = new NpcActionSystem2(clientResultListeners);
    s.init(world, sessionSetup.getSeed());
    this.characterSystems.add(s);
    ServerProcessingSystem<Player> s2;
    s2 = new FirstPlayerEventWaveServerSystem(clientResultListeners);
    s2.init(world, sessionSetup.getSeed());
    this.playerSystems.add(s2);
    s2 = new IllnessDamageSystem(clientResultListeners);
    s2.init(world, sessionSetup.getSeed());
    this.playerSystems.add(s2);
    // Load the systems states
    if (savedGame != null) {
        for (ProcessingSystem<Character> c : characterSystems) {
            ((ServerProcessingSystem<Character>) c).loadSavedState(savedGame.processingSystemStates.get(c.getClass().getSimpleName()));
        }
        for (ProcessingSystem<Player> p : playerSystems) {
            ((ServerProcessingSystem<Player>) p).loadSavedState(savedGame.processingSystemStates.get(p.getClass().getSimpleName()));
        }
    }
}
Also used : NpcActionSystem(de.gg.game.systems.server.NpcActionSystem) LobbyPlayer(de.gg.game.network.LobbyPlayer) Player(de.gg.game.model.entities.Player) Character(de.gg.game.model.entities.Character) NpcActionSystem2(de.gg.game.systems.server.NpcActionSystem2) FirstPlayerEventWaveServerSystem(de.gg.game.systems.server.FirstPlayerEventWaveServerSystem) ServerProcessingSystem(de.gg.game.systems.server.ServerProcessingSystem) LobbyPlayer(de.gg.game.network.LobbyPlayer) FirstCharacterEventWaveServerSystem(de.gg.game.systems.server.FirstCharacterEventWaveServerSystem) IllnessDamageSystem(de.gg.game.systems.server.IllnessDamageSystem)

Example 4 with LobbyPlayer

use of de.gg.game.network.LobbyPlayer in project ProjektGG by eskalon.

the class SlaveSession method init.

/**
 * {@inheritDoc}
 */
@Override
public void init(HashMap<Short, LobbyPlayer> players, @Nullable SavedGame savedGame) {
    super.init(players, savedGame);
    // Setup the client systems
    ProcessingSystem<Player> s;
    s = new FirstEventWaveClientSystem(eventBus, localNetworkId);
    s.init(world, sessionSetup.getSeed());
    this.playerSystems.add(s);
}
Also used : LobbyPlayer(de.gg.game.network.LobbyPlayer) Player(de.gg.game.model.entities.Player) FirstEventWaveClientSystem(de.gg.game.systems.client.FirstEventWaveClientSystem)

Example 5 with LobbyPlayer

use of de.gg.game.network.LobbyPlayer in project ProjektGG by eskalon.

the class WorldGenerator method generatePlayers.

private void generatePlayers() {
    for (Entry<Short, LobbyPlayer> entry : players.entrySet()) {
        LobbyPlayer lp = entry.getValue();
        Profession profession = new Profession(ProfessionType.values()[lp.getProfessionTypeIndex()]);
        Character character = CharacterFactory.createPlayerCharacter(random, profession.getProfession(), setup.getDifficulty(), lp.isMale(), lp.getReligion(), lp.getName(), lp.getSurname());
        world.characters.put(world.characterIndex, character);
        // TODO 1. Skill-Werte aus LobbyPlayer hinzufügen (Reihenfolge:
        // agility, bargain, combat, crafting, rhetorical, stealth)
        // TODO 2. House-IDS setzen
        Player player = PlayerFactory.createPlayerCharacter(world.characterIndex, lp.getIcon(), profession, (short) 0, (short) 0, 1, 1, 1, 1, 1, 1);
        world.players.put(entry.getKey(), player);
        world.characterIndex++;
    }
}
Also used : Profession(de.gg.game.model.entities.Profession) LobbyPlayer(de.gg.game.network.LobbyPlayer) Player(de.gg.game.model.entities.Player) Character(de.gg.game.model.entities.Character) LobbyPlayer(de.gg.game.network.LobbyPlayer)

Aggregations

LobbyPlayer (de.gg.game.network.LobbyPlayer)5 Player (de.gg.game.model.entities.Player)4 Character (de.gg.game.model.entities.Character)2 TickCounter (de.gg.engine.misc.TickCounter)1 TickHandler (de.gg.engine.misc.TickCounter.TickHandler)1 World (de.gg.game.model.World)1 Profession (de.gg.game.model.entities.Profession)1 FirstEventWaveClientSystem (de.gg.game.systems.client.FirstEventWaveClientSystem)1 FirstCharacterEventWaveServerSystem (de.gg.game.systems.server.FirstCharacterEventWaveServerSystem)1 FirstPlayerEventWaveServerSystem (de.gg.game.systems.server.FirstPlayerEventWaveServerSystem)1 IllnessDamageSystem (de.gg.game.systems.server.IllnessDamageSystem)1 NpcActionSystem (de.gg.game.systems.server.NpcActionSystem)1 NpcActionSystem2 (de.gg.game.systems.server.NpcActionSystem2)1 ServerProcessingSystem (de.gg.game.systems.server.ServerProcessingSystem)1 RoundEndSystem (de.gg.game.systems.smp.RoundEndSystem)1