Merge remote-tracking branch 'origin/master'

# Conflicts:
#	OgGhostWinners.txt
This commit is contained in:
Seraina 2022-05-17 11:45:56 +02:00
commit 02012f316d
22 changed files with 150 additions and 29 deletions

View File

@ -6,4 +6,6 @@ serai
serai serai
serai serai
serai serai
serai Jonas
Jonas
Jonas

View File

@ -122,6 +122,10 @@ public class Game implements Runnable {
LOGGER.info(gameState.toGhostString()); LOGGER.info(gameState.toGhostString());
for (ClientHandler client : lobbyClients) {//begins filling the train with clients for (ClientHandler client : lobbyClients) {//begins filling the train with clients
//send train horn sound to client:
client.sendMsgToClient(Protocol.playSound + "$" + "TH");
int index = order[i]; int index = order[i];
if (passengerTrain[index].getIsGhost()) { //if there is a ghost if (passengerTrain[index].getIsGhost()) { //if there is a ghost
GhostPlayer ghostPlayer = new GhostPlayer(passengerTrain[index].getPosition(), GhostPlayer ghostPlayer = new GhostPlayer(passengerTrain[index].getPosition(),

View File

@ -24,11 +24,11 @@ public class NoiseHandler {
public int[] noiseNotifier(Passenger predator, Passenger victim, int[] noiseAmount) { public int[] noiseNotifier(Passenger predator, Passenger victim, int[] noiseAmount) {
if (predator.getPosition() - victim.getPosition() if (predator.getPosition() - victim.getPosition()
> 0) { // if predator is to the right of victim > 0) { // if predator is to the right of victim
for (int i = predator.getPosition() - 1; i > victim.getPosition(); i--) { for (int i = predator.getPosition() ; i > victim.getPosition(); i--) { //-1
noiseAmount[i]++; noiseAmount[i]++;
} }
} else { // if predator is to the left of victim } else { // if predator is to the left of victim
for (int i = predator.getPosition() + 1; i < victim.getPosition(); i++) { for (int i = predator.getPosition(); i < victim.getPosition(); i++) { //+1
noiseAmount[i]++; noiseAmount[i]++;
} }
} }

View File

@ -121,15 +121,14 @@ public class ServerGameInfoHandler {
case ClientGameInfoHandler.noiseNotification + 4 + " time(s)": case ClientGameInfoHandler.noiseNotification + 4 + " time(s)":
case ClientGameInfoHandler.noiseNotification + 5 + " time(s)": case ClientGameInfoHandler.noiseNotification + 5 + " time(s)":
case ClientGameInfoHandler.noiseNotification: case ClientGameInfoHandler.noiseNotification:
//todo: jonas: handle bell behaviour correctly.
String outMsg = npc.getName() + ": " + noiseRandomizer();
//TODO: add likelyhood
if(!npc.getKickedOff()) { if(!npc.getKickedOff()) {
game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg); if (Math.random() < GhostNPC.probabilityToRingAlarmIfHeardNoise) {
game.getLobby().getAdmin().sendMsgToClientsInLobby( game.getLobby().getAdmin().sendMsgToClientsInLobby(
Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition
+ "$" + npc.getPosition()); + "$" + npc.getPosition());
} }
}
break; break;
case ClientGameInfoHandler.ghostVoteRequest: case ClientGameInfoHandler.ghostVoteRequest:
npc.vote(game); npc.vote(game);
@ -151,14 +150,14 @@ public class ServerGameInfoHandler {
case ClientGameInfoHandler.noiseNotification + 4 + " time(s)": case ClientGameInfoHandler.noiseNotification + 4 + " time(s)":
case ClientGameInfoHandler.noiseNotification + 5 + " time(s)": case ClientGameInfoHandler.noiseNotification + 5 + " time(s)":
case ClientGameInfoHandler.noiseNotification: //new case where times are not noted. case ClientGameInfoHandler.noiseNotification: //new case where times are not noted.
//todo: jonas: handle bell behaviour correctly.
String outMsg = npc.getName() + ": " + noiseRandomizer();
if(!npc.getKickedOff()) { if(!npc.getKickedOff()) {
game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg); if (Math.random() < HumanNPC.probabilityToRingAlarmIfHeardNoise) {
game.getLobby().getAdmin().sendMsgToClientsInLobby( game.getLobby().getAdmin().sendMsgToClientsInLobby(
Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition
+ "$" + npc.getPosition()); + "$" + npc.getPosition());
} }
}
break; break;
case ClientGameInfoHandler.humanVoteRequest: case ClientGameInfoHandler.humanVoteRequest:
npc.vote(game); npc.vote(game);

View File

@ -26,7 +26,7 @@ public class Timer {
/** /**
* The maximum length of the human vote in the day, in seconds * The maximum length of the human vote in the day, in seconds
*/ */
public static final int humanVoteTime = 60; public static final int humanVoteTime = 63;
/** /**
* The length of time in seconds after the human vote, as the 'winner' of the vote is announced, * The length of time in seconds after the human vote, as the 'winner' of the vote is announced,

View File

@ -4,6 +4,7 @@ import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -171,8 +172,16 @@ public class VoteHandler {
passenger.send( passenger.send(
ClientGameInfoHandler.humansVotedFor + voteIndex + ClientGameInfoHandler.isAHuman, game); ClientGameInfoHandler.humansVotedFor + voteIndex + ClientGameInfoHandler.isAHuman, game);
} }
for (ClientHandler c: game.getLobby().getLobbyClients()) { //send human vote sound to clients
c.sendMsgToClient(Protocol.playSound + "$" + "HV");
} }
Timer.humanAfterVoteTimer(); } else if (!passengers[voteIndex].getIsOG()) {
for (ClientHandler c: game.getLobby().getLobbyClients()) { //send ghost vote sound to clients
c.sendMsgToClient(Protocol.playSound + "$" + "GV");
}
}
if (passengers[voteIndex].getIsGhost()) { // if player is a ghost if (passengers[voteIndex].getIsGhost()) { // if player is a ghost
if (passengers[voteIndex].getIsOG()) { // if ghost is OG --> end game, humans win if (passengers[voteIndex].getIsOG()) { // if ghost is OG --> end game, humans win
System.out.println(ClientGameInfoHandler.gameOverHumansWin); System.out.println(ClientGameInfoHandler.gameOverHumansWin);
@ -200,6 +209,8 @@ public class VoteHandler {
} }
} }
} }
Timer.humanAfterVoteTimer();
LOGGER.info(game.getGameState().toString()); LOGGER.info(game.getGameState().toString());
// set hasVoted to false for all passengers for future voting // set hasVoted to false for all passengers for future voting
for (Passenger passenger : passengers) { for (Passenger passenger : passengers) {

View File

@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger;
public class GhostNPC extends Ghost { public class GhostNPC extends Ghost {
public static final Logger LOGGER = LogManager.getLogger(GhostNPC.class); public static final Logger LOGGER = LogManager.getLogger(GhostNPC.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
public static final double probabilityToRingAlarmIfHeardNoise = 0.5;
/** /**
* Creates a new GhostNPC. Should be used at game start or if a HumanNPC is turned into a ghost. * Creates a new GhostNPC. Should be used at game start or if a HumanNPC is turned into a ghost.

View File

@ -1,6 +1,7 @@
package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur; package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler;
import ch.unibas.dmi.dbis.cs108.gamelogic.ClientVoteData; import ch.unibas.dmi.dbis.cs108.gamelogic.ClientVoteData;
import ch.unibas.dmi.dbis.cs108.gamelogic.Game; import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler; import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler;
@ -14,6 +15,7 @@ public class GhostPlayer extends Ghost {
public static final Logger LOGGER = LogManager.getLogger(GhostPlayer.class); public static final Logger LOGGER = LogManager.getLogger(GhostPlayer.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
/** /**
* Creates a new GhostPlayer. Should be used at game start or if a HumanPlayer is turned into a * Creates a new GhostPlayer. Should be used at game start or if a HumanPlayer is turned into a
* ghost. * ghost.
@ -48,6 +50,8 @@ public class GhostPlayer extends Ghost {
String formattedMsg; String formattedMsg;
if (msg.equals(GuiParameters.updateGameState)) { if (msg.equals(GuiParameters.updateGameState)) {
formattedMsg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toGhostString(); formattedMsg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toGhostString();
} else if (msg.equals(ClientGameInfoHandler.noiseNotification)) {
formattedMsg = Protocol.noiseNotificationProtocol;
} else { } else {
formattedMsg = ServerGameInfoHandler.format(msg, this, game); formattedMsg = ServerGameInfoHandler.format(msg, this, game);
} }

View File

@ -10,6 +10,7 @@ public class HumanNPC extends Human {
public static final Logger LOGGER = LogManager.getLogger(HumanNPC.class); public static final Logger LOGGER = LogManager.getLogger(HumanNPC.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
public static final double probabilityToRingAlarmIfHeardNoise = 0.9;
/** /**
* Creates a new HumanNPC. * Creates a new HumanNPC.

View File

@ -1,8 +1,10 @@
package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur; package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler;
import ch.unibas.dmi.dbis.cs108.gamelogic.Game; import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler; import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -29,6 +31,11 @@ public class Spectator extends Passenger{
*/ */
@Override @Override
public void send(String msg, Game game) { public void send(String msg, Game game) {
if (msg.equals(ClientGameInfoHandler.noiseNotification)) {
clientHandler.sendMsgToClient(Protocol.noiseNotificationProtocol);
} else {
clientHandler.sendMsgToClient(ServerGameInfoHandler.spectatorFormat(msg, game)); clientHandler.sendMsgToClient(ServerGameInfoHandler.spectatorFormat(msg, game));
} }
} }
}

View File

@ -105,9 +105,13 @@ public class JClientProtocolParser {
case "HV": case "HV":
Sound.voteforhuman(); Sound.voteforhuman();
break; break;
case "TH":
Sound.trainhorn();
break;
default: default:
LOGGER.warn("Invalid sound request"); LOGGER.warn("Invalid sound request");
} }
break;
default: default:
System.out.println("Received unknown command: " + msg); System.out.println("Received unknown command: " + msg);
} }

View File

@ -17,6 +17,9 @@ public class Sound {
static URL bellURL = Sound.class.getResource("sounds/bell.wav"); static URL bellURL = Sound.class.getResource("sounds/bell.wav");
static AudioClip bell = new AudioClip(bellURL.toString()); static AudioClip bell = new AudioClip(bellURL.toString());
static URL trainhornURL = Sound.class.getResource("sounds/trainhorn.wav");
static AudioClip trainhorn = new AudioClip(trainhornURL.toString());
static URL daynoisesURL = Sound.class.getResource("sounds/daynoises.wav"); static URL daynoisesURL = Sound.class.getResource("sounds/daynoises.wav");
static AudioClip daynoises = new AudioClip(daynoisesURL.toString()); static AudioClip daynoises = new AudioClip(daynoisesURL.toString());
@ -41,6 +44,32 @@ public class Sound {
static URL ghost04URL = Sound.class.getResource("sounds/ghost04.wav"); static URL ghost04URL = Sound.class.getResource("sounds/ghost04.wav");
static AudioClip ghost04 = new AudioClip(ghost04URL.toString()); static AudioClip ghost04 = new AudioClip(ghost04URL.toString());
static URL ghost05URL = Sound.class.getResource("sounds/ghost05.wav");
static AudioClip ghost05 = new AudioClip(ghost05URL.toString());
static URL ghost06URL = Sound.class.getResource("sounds/ghost06.wav");
static AudioClip ghost06 = new AudioClip(ghost06URL.toString());
static URL ghost07URL = Sound.class.getResource("sounds/ghost07.wav");
static AudioClip ghost07 = new AudioClip(ghost07URL.toString());
static URL ghost08URL = Sound.class.getResource("sounds/ghost08.wav");
static AudioClip ghost08 = new AudioClip(ghost08URL.toString());
static URL ghost09URL = Sound.class.getResource("sounds/ghost09.wav");
static AudioClip ghost09 = new AudioClip(ghost09URL.toString());
static URL ghost10URL = Sound.class.getResource("sounds/ghost10.wav");
static AudioClip ghost10 = new AudioClip(ghost10URL.toString());
static URL ghost11URL = Sound.class.getResource("sounds/ghost11.wav");
static AudioClip ghost11 = new AudioClip(ghost11URL.toString());
static URL ghost12URL = Sound.class.getResource("sounds/ghost12.wav");
static AudioClip ghost12 = new AudioClip(ghost12URL.toString());
static URL musicdayURL = Sound.class.getResource("sounds/music_day.wav"); static URL musicdayURL = Sound.class.getResource("sounds/music_day.wav");
static AudioClip musicday = new AudioClip(musicdayURL.toString()); static AudioClip musicday = new AudioClip(musicdayURL.toString());
@ -77,6 +106,8 @@ public class Sound {
bell.play(defaultvolume - 0.5); bell.play(defaultvolume - 0.5);
} }
public static void trainhorn() {trainhorn.play(defaultvolume); }
public static void startDaynoises() { public static void startDaynoises() {
daynoises.setCycleCount(AudioClip.INDEFINITE); daynoises.setCycleCount(AudioClip.INDEFINITE);
daynoises.play(defaultvolume - 0.5); daynoises.play(defaultvolume - 0.5);
@ -95,16 +126,28 @@ public class Sound {
nightnoises.stop(); nightnoises.stop();
} }
public static void gameoverghosts() { gameoverghosts.play(defaultvolume); } public static void gameoverghosts() {
waitForABitThenEndDayMusic();
voteforghost.stop();
voteforhuman.stop();
gameoverghosts.play(defaultvolume - 0.3); }
public static void gameoverhumans() { public static void gameoverhumans() {
stopmusicday(); waitForABitThenEndDayMusic();
gameoverhumans.play(defaultvolume); voteforghost.stop();
voteforhuman.stop();
gameoverhumans.play(defaultvolume - 0.1);
} }
public static void voteforghost() { voteforghost.play(defaultvolume); } public static void voteforghost() {
waitForABitThenEndDayMusic();
voteforghost.play(defaultvolume - 0.4);
}
public static void voteforhuman() { voteforhuman.play(defaultvolume); } public static void voteforhuman() {
waitForABitThenEndDayMusic();
voteforhuman.play(defaultvolume - 0.2);
}
public static void musicday() { public static void musicday() {
musicday.play(defaultvolume); musicday.play(defaultvolume);
@ -116,8 +159,9 @@ public class Sound {
} }
public static void ghost() { public static void ghost() {
double playbackspeed = (Math.random() / 5.0) + 0.9; //double playbackspeed = (Math.random() / 5.0) + 0.9; causes aliasing artefacts :/
int ghostsoundnr = random.nextInt(4) + 1; double playbackspeed = 1;
int ghostsoundnr = random.nextInt(12) + 1;
System.out.println(ghostsoundnr); System.out.println(ghostsoundnr);
AudioClip ghost; AudioClip ghost;
switch (ghostsoundnr) { switch (ghostsoundnr) {
@ -130,13 +174,57 @@ public class Sound {
case 3: case 3:
ghost = ghost03; ghost = ghost03;
break; break;
default: case 4:
ghost = ghost04; ghost = ghost04;
break; break;
case 5:
ghost = ghost05;
break;
case 6:
ghost = ghost06;
break;
case 7:
ghost = ghost07;
break;
case 8:
ghost = ghost08;
break;
case 9:
ghost = ghost09;
break;
case 10:
ghost = ghost10;
break;
case 11:
ghost = ghost11;
break;
case 12:
ghost = ghost12;
break;
default:
ghost = ghost01;
break;
} }
ghost.play(0.1, 0.0, playbackspeed, 0.0, 5); ghost.play(0.08, 0.0, playbackspeed, 0.0, 5);
} }
/**
* waits for a bit, then ends day music. :)
*/
public static void waitForABitThenEndDayMusic() {
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1820);
//the time it takes for the vote result sound to ramp up, so the music ends exactly on the "big reveal"
} catch (InterruptedException e) {
e.printStackTrace();
}
stopmusicday();
}
}).start();
}
} }

View File

@ -215,7 +215,7 @@ public class Protocol {
/** /**
* Used to tell the client to play a sound, namely the sounds for when humans have voted for a human (PLSND$HV), * Used to tell the client to play a sound, namely the sounds for when humans have voted for a human (PLSND$HV),
* when humans have voted for a ghost (PLSND$GV), when humans have won (i.e. have voted for the OG - PLSND$HW) * when humans have voted for a ghost (PLSND$GV), when humans have won (i.e. have voted for the OG - PLSND$HW)
* or when ghosts have won (PLSND$GW) * or when ghosts have won (PLSND$GW), or the train horn at the start of the game (PLSND$TH). Not used for ghost sounds.
*/ */
public static final String playSound = "PLSND"; public static final String playSound = "PLSND";