Search in sources :

Example 6 with Player

use of de.gg.game.model.entities.Player 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 7 with Player

use of de.gg.game.model.entities.Player in project ProjektGG by eskalon.

the class FirstCharacterEventWaveServerSystem method process.

@Override
public void process(short id, Character c) {
    // DEATH
    if (c.getHp() <= 0) {
        // a) Player characters:
        Player p = world.getPlayerByCharacterId(id);
        if (p != null) {
        // TODO Charakter tauschen, Erbe, Illness-Reset, Family-Reset
        }
        // b) Player siblings:
        // TODO Erbe
        // c) Other characters:
        // TODO replace character by random new one
        // d) For everyone:
        // TODO Ämter resetten, Character aus Liste entfernen
        resultListener.onCharacterDeath(id);
        return;
    }
}
Also used : Player(de.gg.game.model.entities.Player)

Example 8 with Player

use of de.gg.game.model.entities.Player in project ProjektGG by eskalon.

the class AuthoritativeSession method onNewBallot.

@Override
protected void onNewBallot(@Nullable Ballot matterToVoteOn) {
    individualVotes.clear();
    if (matterToVoteOn != null) {
        // AI vote
        for (short charId : matterToVoteOn.getVoters()) {
            boolean isPlayer = false;
            for (Player p : world.getPlayers().values()) {
                if (p.getCurrentlyPlayedCharacterId() == charId) {
                    isPlayer = true;
                    break;
                }
            }
            if (!isPlayer) {
                individualVotes.put(charId, CharacterBehaviour.getVoteOption(charId, matterToVoteOn, this));
            }
        }
        // Check if all votes were made
        if (individualVotes.size() == matterToVoteOn.getVoters().size()) {
            BallotResults result = new BallotResults(BallotUtils.getBallotResult(matterToVoteOn, individualVotes, sessionSetup.getSeed()), individualVotes);
            finishCurrentVote(result);
            clientResultListeners.onVoteFinished(result);
        }
    }
}
Also used : LobbyPlayer(de.gg.game.network.LobbyPlayer) Player(de.gg.game.model.entities.Player) BallotResults(de.gg.game.model.votes.BallotResults)

Example 9 with Player

use of de.gg.game.model.entities.Player 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 10 with Player

use of de.gg.game.model.entities.Player 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)

Aggregations

Player (de.gg.game.model.entities.Player)11 LobbyPlayer (de.gg.game.network.LobbyPlayer)5 World (de.gg.game.model.World)4 Character (de.gg.game.model.entities.Character)3 ImageTextButton (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton)2 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)2 Subscribe (com.google.common.eventbus.Subscribe)2 ButtonClickListener (de.gg.game.input.ButtonClickListener)2 GameSession (de.gg.game.session.GameSession)2 Keys (com.badlogic.gdx.Input.Keys)1 Color (com.badlogic.gdx.graphics.Color)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 Button (com.badlogic.gdx.scenes.scene2d.ui.Button)1 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)1 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 ThreadHandler (de.damios.guacamole.concurrent.ThreadHandler)1 Log (de.damios.guacamole.gdx.Log)1 Text (de.damios.guacamole.gdx.assets.Text)1