npcs no longer chat about hearing noise, ghost players hear ghost noise too, removed random ghost noise pitch even though it was super cool, because of stupid aliasing artefacts :(

This commit is contained in:
Jonas 2022-05-16 22:06:55 +02:00
parent 2d6e15a39f
commit 7761a74d2b
8 changed files with 30 additions and 19 deletions

View File

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

View File

@ -24,11 +24,11 @@ public class NoiseHandler {
public int[] noiseNotifier(Passenger predator, Passenger victim, int[] noiseAmount) {
if (predator.getPosition() - victim.getPosition()
> 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]++;
}
} 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]++;
}
}

View File

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

View File

@ -172,7 +172,7 @@ public class VoteHandler {
ClientGameInfoHandler.humansVotedFor + voteIndex + ClientGameInfoHandler.isAHuman, game);
}
}
Timer.humanAfterVoteTimer();
if (passengers[voteIndex].getIsGhost()) { // if player is a ghost
if (passengers[voteIndex].getIsOG()) { // if ghost is OG --> end game, humans win
System.out.println(ClientGameInfoHandler.gameOverHumansWin);
@ -200,6 +200,8 @@ public class VoteHandler {
}
}
}
Timer.humanAfterVoteTimer();
LOGGER.info(game.getGameState().toString());
// set hasVoted to false for all passengers for future voting
for (Passenger passenger : passengers) {

View File

@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger;
public class GhostNPC extends Ghost {
public static final Logger LOGGER = LogManager.getLogger(GhostNPC.class);
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.

View File

@ -1,6 +1,7 @@
package ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur;
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.Game;
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 BudaLogConfig l = new BudaLogConfig(LOGGER);
/**
* Creates a new GhostPlayer. Should be used at game start or if a HumanPlayer is turned into a
* ghost.
@ -48,6 +50,8 @@ public class GhostPlayer extends Ghost {
String formattedMsg;
if (msg.equals(GuiParameters.updateGameState)) {
formattedMsg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toGhostString();
} else if (msg.equals(ClientGameInfoHandler.noiseNotification)) {
formattedMsg = Protocol.noiseNotificationProtocol;
} else {
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 BudaLogConfig l = new BudaLogConfig(LOGGER);
public static final double probabilityToRingAlarmIfHeardNoise = 0.9;
/**
* Creates a new HumanNPC.

View File

@ -95,7 +95,9 @@ public class Sound {
nightnoises.stop();
}
public static void gameoverghosts() { gameoverghosts.play(defaultvolume); }
public static void gameoverghosts() {
stopmusicday();
gameoverghosts.play(defaultvolume); }
public static void gameoverhumans() {
stopmusicday();
@ -116,7 +118,8 @@ public class Sound {
}
public static void ghost() {
double playbackspeed = (Math.random() / 5.0) + 0.9;
//double playbackspeed = (Math.random() / 5.0) + 0.9; causes aliasing artefacts :/
double playbackspeed = 1;
int ghostsoundnr = random.nextInt(4) + 1;
System.out.println(ghostsoundnr);
AudioClip ghost;
@ -134,7 +137,7 @@ public class Sound {
ghost = ghost04;
break;
}
ghost.play(0.1, 0.0, playbackspeed, 0.0, 5);
ghost.play(0.06, 0.0, playbackspeed, 0.0, 5);
}
}