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();
}
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;
}
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()));
}
}
}
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);
}
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++;
}
}
Aggregations