Skip to content

Commit

Permalink
Adding sytem weather effect (chrisgillis#51)
Browse files Browse the repository at this point in the history
Signed-off-by: GrumpyMurloc <[email protected]>
  • Loading branch information
GrumpyMurloc committed Nov 6, 2016
1 parent ff40ed6 commit ff697ef
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 8 deletions.
19 changes: 17 additions & 2 deletions src/Game/Command/WeatherCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ public function fire()
return;
}

$this->gameManager->sendMessageToChannel($this->game, ":rain_cloud: It is raining. It is a cold rain, and the freezing drops chill you to the bone." );

$weather= $this->game->weather;
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 comment has been minimized.

Copy link
@chrisgillis

chrisgillis Nov 9, 2016

These integers for the state of the weather might be better as defined constants.
define('RAINING', 1); for example.

You can take this a step further by instead creating an enum.

abstract class Weather {
  const Rainy = 1;
  const Sunny = 2;
}

You can then access them like so: $weather == Weather::Rainy

}
// 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");
}

This comment has been minimized.

Copy link
@chrisgillis

chrisgillis Nov 9, 2016

Also, in general, I think the !weather command can be removed. Weather should simply be a function of the games messaging, not a callable command.

}
}
59 changes: 59 additions & 0 deletions src/Game/Formatter/WeatherFormatter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php namespace Slackwolf\Game\Formatter;

use Slackwolf\Game\Game;
use Slackwolf\Game\GameState;

/**
* Defines the WeatherFormatter class.
*/
class WeatherFormatter
{

/**
* @param $game
*
* @return string
*/
public static function format(Game $game)
{
// Send message according to GameState and weather
$state= $game->state;

if($state== GameState::FIRST_NIGHT){
if($game->weather==1){
$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.";
}
else if($game->weather==1){
$msg= ":moon: :cloud: The cloud covered the sky blocking even the few glimmering light pass. ";
}
else{
$msg= "The village sleeps, unaware of the horror the lurks outside in the dark. It is the middle of the night.";
}

}
if($state== GameState::DAY){
if($game->weather==1){
$msg= ":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.";
}
else if($game->weather==1){
$msg= ":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.";
}
else{
$msg= ":sunny: The morning came and the sun, high in the sky, gave hope that one day this madness will end.";
}
}
if($state== GameState::NIGHT){
if($game->weather==1){
$msg= ":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.";
}
else if($game->weather==1){
$msg= ":moon: :fog: A thick fog covered the village blocking all of the light. The Villagers bar their door waiting without rest until sunrise.";
}
else{
$msg= ":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.";
}
}

return $msg;

This comment has been minimized.

Copy link
@chrisgillis

chrisgillis Nov 9, 2016

This could be built more elegantly by including a /data directory in the project with a day_weather.txt and a night_weather.txt file containing the various messages. You can then load the text file as an array in your formatter class.

}
}
11 changes: 11 additions & 0 deletions src/Game/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Game
public $wolvesVoted;
public $witchHealed;
public $witchPoisoned;
public $weather;

/**
* @param $id
Expand Down Expand Up @@ -606,4 +607,14 @@ public function setWitchPoisonedUserId($id) {
$this->witchPoisonedUserId = $id;
}


public function setWeather(){
// Randomize the weather 1=rain, 2= cloudy, 3=sunny
// Might be better using string instead of int.
$this->weather= rand(1,3);

This comment has been minimized.

Copy link
@chrisgillis

chrisgillis Nov 9, 2016

You might consider adding a weight to the generation of the weather to trend towards cloudy most of the time, for example.


}
public function getWeather(){
return $this->weather;
}
}
13 changes: 7 additions & 6 deletions src/Game/GameManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -467,16 +468,16 @@ private function onFirstNight(Game $game)
}
});
}

$game->setweather();
$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";

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 .= WeatherFormatter::format($game);

This comment has been minimized.

Copy link
@chrisgillis

chrisgillis Nov 9, 2016

Why only send a weather message if the seer role is enabled?

$msg .= " The game will begin when the Seer chooses someone.";
}
$this->sendMessageToChannel($game, $msg);
Expand All @@ -492,8 +493,8 @@ 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";
$game->setweather();
$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))
Expand All @@ -514,7 +515,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();
Expand Down

0 comments on commit ff697ef

Please sign in to comment.