diff --git a/src/Game/Command/WeatherCommand.php b/src/Game/Command/WeatherCommand.php index e1452f2..0470c18 100644 --- a/src/Game/Command/WeatherCommand.php +++ b/src/Game/Command/WeatherCommand.php @@ -1,11 +1,11 @@ client; @@ -26,8 +26,26 @@ public function fire() }); return; } + if ($weather != null){ + + if($weather == 1){ + $this->gameManager->sendMessageToChannel($this->game, ":rain_cloud: It is raining. It is a cold rain, and the freezing drops chill you to the bone." ); + } - $this->gameManager->sendMessageToChannel($this->game, ":rain_cloud: It is raining. It is a cold rain, and the freezing drops chill you to the bone." ); + // Cloudy + else if($weather == 2){ + $this->gameManager->sendMessageToChannel($this->game, ":cloud: The cloud embrace the sky and cover the sun letting only a few glimmer of light"); + } + // Sunny + else{ + $this->gameManager->sendMessageToChannel($this->game, ":sunny: The warm sun is shining. Its brightness almost blinds you. You take a moment to appreciate its embrace."); + } + + } + + else{ + $this->gameManager->sendMessageToChannel($this->game,"No Game Running"); + } } } diff --git a/src/Game/Data/day_weather.txt b/src/Game/Data/day_weather.txt new file mode 100755 index 0000000..b21d39f --- /dev/null +++ b/src/Game/Data/day_weather.txt @@ -0,0 +1,3 @@ +:sunrise: The sun rises and the villagers awake. It is still raining, but it slows somewhat, allowing momentary respite from the cold, wet hell that we all live in. +:cloud: There is no sky today, only a thick layer of cloud blocking the sky. The air was cooler, announcing rain in the day to come. +:sunny: The morning came and the sun, high in the sky, gave hope that one day this madness will end. \ No newline at end of file diff --git a/src/Game/Data/first_weather.txt b/src/Game/Data/first_weather.txt new file mode 100755 index 0000000..7593bcd --- /dev/null +++ b/src/Game/Data/first_weather.txt @@ -0,0 +1,3 @@ +:moon: :rain_cloud: The rain comes down in torrents as the village sleeps, unaware of the horror that lurks outside in the wet. It is the middle +:moon: :cloud: The cloud covered the sky blocking even the few glimmering light. +:moon: The village sleeps, unaware of the horror that lurks outside in the dark. It is the middle of the night. diff --git a/src/Game/Data/night_weather.txt b/src/Game/Data/night_weather.txt new file mode 100755 index 0000000..80271dc --- /dev/null +++ b/src/Game/Data/night_weather.txt @@ -0,0 +1,3 @@ +:moon: :zzz: The sun sets, and the hard rain makes it difficult to hear anything outside. Villagers bar their doors, take long pulls of :beer:, and try not to think of what might lurk beyond the feeble candlelight. +:moon: :fog: A thick fog covered the village blocking all of the light. The Villagers bar their door waiting without rest until sunrise. +:full_moon: The sun set, and the moon lights up the sky giving a glimmer of hope. The Villagers bar their doors waiting in fear until sunrise. diff --git a/src/Game/Formatter/WeatherFormatter.php b/src/Game/Formatter/WeatherFormatter.php new file mode 100644 index 0000000..d2b2a83 --- /dev/null +++ b/src/Game/Formatter/WeatherFormatter.php @@ -0,0 +1,122 @@ +5, 'B'=>45, 'C'=>50) + * An array like this means that "A" has a 5% chance of being selected, "B" 45%, and "C" 50%. + */ + + public static function getWeather(array $weightedValues) { + + $rand = mt_rand(1, (int) array_sum($weightedValues)); + + foreach ($weightedValues as $key => $value) { + + $rand -= $value; + if ($rand <= 0) { + + return $key; + + } + } + } + + /** + * @param $game + * + * @return string + */ + + public static function format(Game $game) + { + // Send message according to GameState and weather + $state = $game->state; + /** + * Create an associate array with the value as weight. + * To modify the weight, just change the value with the integer. + * Raining = 25%, cloudy = 50%, sunny= 25% + */ + $weight = array( + "rainy" => 25, + "cloudy" => 50, + "sunny" => 25, + ); + + $Weather = WeatherFormatter::getWeather($weight); + $messages = array(":rain_cloud:",":cloud:",":sunny:"); + + if ($state == GameState::FIRST_NIGHT){ + + if (file_exists("src/Game/Data/first_weather.txt")){ + $messages = file("src/Game/Data/first_weather.txt"); + } + + if ($Weather == "rainy"){ + $msg = $messages[0]; + } + + else if ($Weather == "cloudy"){ + $msg = $messages[1]; + } + + else{ + $msg = $messages[2]; + } + + } + + if ($state == GameState::DAY){ + if (file_exists("src/Game/Data/day_weather.txt")){ + $messages = file("src/Game/Data/day_weather.txt"); + } + + if ($Weather == "rainy"){ + $msg = $messages[0]; + } + + else if ($Weather == "cloudy"){ + $msg = $messages[1]; + } + + else{ + $msg = $messages[2]; + } + + } + + if ($state == GameState::NIGHT){ + if (file_exists("src/Game/Data/night_weather.txt")){ + $messages = file("src/Game/Data/night_weather.txt"); + } + + if ($Weather == "rainy"){ + $msg = $messages[0]; + } + + else if ($Weather == "cloudy"){ + $msg = $messages[1]; + } + + else{ + $msg = $messages[2]; + } + + } + + return $msg; + } +} \ No newline at end of file diff --git a/src/Game/Formatter/test.txt b/src/Game/Formatter/test.txt new file mode 100644 index 0000000..7593bcd --- /dev/null +++ b/src/Game/Formatter/test.txt @@ -0,0 +1,3 @@ +:moon: :rain_cloud: The rain comes down in torrents as the village sleeps, unaware of the horror that lurks outside in the wet. It is the middle +:moon: :cloud: The cloud covered the sky blocking even the few glimmering light. +:moon: The village sleeps, unaware of the horror that lurks outside in the dark. It is the middle of the night. diff --git a/src/Game/Game.php b/src/Game/Game.php index bf90b3f..6a4330d 100755 --- a/src/Game/Game.php +++ b/src/Game/Game.php @@ -35,6 +35,7 @@ class Game public $wolvesVoted; public $witchHealed; public $witchPoisoned; + /** * @param $id @@ -605,5 +606,4 @@ public function getWitchPoisonedUserId() { public function setWitchPoisonedUserId($id) { $this->witchPoisonedUserId = $id; } - } \ No newline at end of file diff --git a/src/Game/GameManager.php b/src/Game/GameManager.php index 6053988..86d6c9c 100644 --- a/src/Game/GameManager.php +++ b/src/Game/GameManager.php @@ -10,6 +10,7 @@ use Slackwolf\Game\Formatter\RoleListFormatter; use Slackwolf\Game\Formatter\RoleSummaryFormatter; use Slackwolf\Game\Formatter\VoteSummaryFormatter; +use Slackwolf\Game\Formatter\WeatherFormatter; use Slackwolf\Message\Message; use Slackwolf\Game\OptionsManager; use Slackwolf\Game\OptionName; @@ -467,16 +468,16 @@ private function onFirstNight(Game $game) } }); } - + ; $playerList = PlayerListFormatter::format($game->getLivingPlayers()); $roleList = RoleListFormatter::format($game->getLivingPlayers()); - $msg = ":wolf: It is raining, and a new game of Werewolf is starting! For a tutorial, type !help.\r\n\r\n"; + $msg = ":wolf: A new game of Werewolf is starting! For a tutorial, type !help.\r\n\r\n"; $msg .= "Players: {$playerList}\r\n"; $msg .= "Possible Roles: {$game->getRoleStrategy()->getRoleListMsg()}\r\n\r\n"; - + $msg .= WeatherFormatter::format($game)."\r\n"; if ($this->optionsManager->getOptionValue(OptionName::role_seer)) { - $msg .= ":moon: :rain_cloud: The rain comes down in torrents as the village sleeps, unaware of the horror the lurks outside in the wet. It is the middle of the night."; + $msg .= " The game will begin when the Seer chooses someone."; } $this->sendMessageToChannel($game, $msg); @@ -492,8 +493,7 @@ private function onFirstNight(Game $game) private function onDay(Game $game) { $remainingPlayers = PlayerListFormatter::format($game->getLivingPlayers()); - - $dayBreakMsg = ":sunrise: The sun rises and the villagers awake. It is still raining, but it slows somewhat, allowing momentary respite from the cold, wet hell that we all live in.\r\n"; + $dayBreakMsg = WeatherFormatter::format($game)."\r\n"; $dayBreakMsg .= "Remaining Players: {$remainingPlayers}\r\n\r\n"; $dayBreakMsg .= "Villagers, find the Werewolves! Type !vote @username to vote to lynch a player."; if ($this->optionsManager->getOptionValue(OptionName::changevote)) @@ -514,7 +514,7 @@ private function onDay(Game $game) private function onNight(Game $game) { $client = $this->client; - $nightMsg = ":moon: :zzz: The sun sets, and the hard rain makes it difficult to hear anything outside. Villagers bar their doors, take long pulls of :beer:, and try not to think of what might lurk beyond the feeble candlelight. "; + $nightMsg = WeatherFormatter::format($game); $this->sendMessageToChannel($game, $nightMsg); $wolves = $game->getWerewolves(); diff --git a/src/Slackwolf.php b/src/Slackwolf.php index bb502a0..5dc6857 100644 --- a/src/Slackwolf.php +++ b/src/Slackwolf.php @@ -79,7 +79,7 @@ public function run() 'alive' => AliveCommand::class, 'dead' => DeadCommand::class, 'status' => StatusCommand::class, - 'weather' => WeatherCommand::class, + // 'weather' => WeatherCommand::class, ]; /*