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