Adding force start & force stop games

This commit is contained in:
Ad5001 2017-03-05 21:56:04 +01:00
parent 66013363d5
commit dffd800ac8
No known key found for this signature in database
GPG Key ID: F05C5A0D59BC40DD
3 changed files with 34 additions and 10 deletions

View File

@ -17,4 +17,6 @@ Sub Commands:
- setseektime <minutes to seek>(or sst): Sets the time seekers have to find all hiders before hiders wins - setseektime <minutes to seek>(or sst): Sets the time seekers have to find all hiders before hiders wins
- setspawn(or ss): Sets the spawn of the place players will wait, hide, and seek - setspawn(or ss): Sets the spawn of the place players will wait, hide, and seek
- setseekersspawn(or sss): Sets the place where players will be tped to while hiders are hiding - setseekersspawn(or sss): Sets the place where players will be tped to while hiders are hiding
- start: Force start the game
- stop: Force stop the game
Please note that all those subcommands are relative to the world where you execute the command in. Please note that all those subcommands are relative to the world where you execute the command in.

View File

@ -48,7 +48,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener
// Game based informations // Game based informations
protected $step = self::STEP_WAIT; protected $step = self::STEP_WAIT;
protected $win = self::NO_WIN; protected $win = self::NO_WIN;
protected $stepTick; public $stepTick;
protected $hidersLeft; protected $hidersLeft;
protected $seekersCount; protected $seekersCount;
@ -96,7 +96,6 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener
} }
} }
if($this->getWaitTime() - ($tickWaited / 20) <= 0) { if($this->getWaitTime() - ($tickWaited / 20) <= 0) {
$this->stepTick = $tick;
$this->start(); $this->start();
foreach(array_merge($this->getPlayers(), $this->getSpectators()) as $p) { foreach(array_merge($this->getPlayers(), $this->getSpectators()) as $p) {
$p->sendMessage(Main::PREFIX . "§aGame started ! There is $this->seekersCount seekers and $this->hidersLeft hiders."); $p->sendMessage(Main::PREFIX . "§aGame started ! There is $this->seekersCount seekers and $this->hidersLeft hiders.");
@ -189,6 +188,7 @@ class Game extends PluginTask /* Allows easy game running */ implements Listener
Starts the game Starts the game
*/ */
public function start() { public function start() {
$this->stepTick = $this->getMain()->getServer()->getTick();
$count = count($this->players); $count = count($this->players);
$this->seekersCount = round($count * ($this->getSeekersPercentage() / 100), 0, PHP_ROUND_HALF_UP); // Minimum $this->getSeekersPercentage() percents of the players (inimum because if there are less than $this->getSeekersPercentage(), then there could be no seeker) $this->seekersCount = round($count * ($this->getSeekersPercentage() / 100), 0, PHP_ROUND_HALF_UP); // Minimum $this->getSeekersPercentage() percents of the players (inimum because if there are less than $this->getSeekersPercentage(), then there could be no seeker)
$this->hidersLeft = count($this->players) - $this->seekersCount; $this->hidersLeft = count($this->players) - $this->seekersCount;

View File

@ -67,6 +67,7 @@ A
switch($cmd->getName()) { switch($cmd->getName()) {
case "hideandseek": case "hideandseek":
if(isset($args[0])) { if(isset($args[0])) {
$game = $this->getGameManager()->getGameByLevel($sender->getLevel());
switch(strtolower($args[0])) { switch(strtolower($args[0])) {
case "creategame": case "creategame":
case "addgame": case "addgame":
@ -84,7 +85,6 @@ A
break; break;
case "deletegame": case "deletegame":
case "delgame": case "delgame":
$game = $this->getGameManager()->getGameByLevel($sender->getLevel());
if(!is_null($game)) { if(!is_null($game)) {
unset($this->getGameManager()->{$sender->getLevel()->getName()}); unset($this->getGameManager()->{$sender->getLevel()->getName()});
$sender->sendMessage(self::PREFIX . "§cSuccefully deleted hide and seek game in level {$sender->getLevel()->getName()}."); $sender->sendMessage(self::PREFIX . "§cSuccefully deleted hide and seek game in level {$sender->getLevel()->getName()}.");
@ -95,7 +95,6 @@ A
break; break;
case "setmaxplayers": case "setmaxplayers":
case "smp": case "smp":
$game = $this->getGameManager()->getGameByLevel($sender->getLevel());
if(!is_null($game)) { if(!is_null($game)) {
if(isset($args[1]) && is_int($args[1]) && $args[1] > 1) { if(isset($args[1]) && is_int($args[1]) && $args[1] > 1) {
$game->setMaxPlayers($args[1]); $game->setMaxPlayers($args[1]);
@ -110,7 +109,6 @@ A
break; break;
case "setseekerspercentage": case "setseekerspercentage":
case "ssp": case "ssp":
$game = $this->getGameManager()->getGameByLevel($sender->getLevel());
if(!is_null($game)) { if(!is_null($game)) {
if(isset($args[1]) && is_int($args[1]) && $args[1] > 0 && $args[1] < 100) { if(isset($args[1]) && is_int($args[1]) && $args[1] > 0 && $args[1] < 100) {
$game->setSeekersPercentage($args[1]); $game->setSeekersPercentage($args[1]);
@ -126,7 +124,6 @@ A
case "setwaitingtime": case "setwaitingtime":
case "setwaittime": case "setwaittime":
case "swt": case "swt":
$game = $this->getGameManager()->getGameByLevel($sender->getLevel());
if(!is_null($game)) { if(!is_null($game)) {
if(isset($args[1]) && is_int($args[1]) && $args[1] > 0) { if(isset($args[1]) && is_int($args[1]) && $args[1] > 0) {
$game->setWaitTime($args[1]); $game->setWaitTime($args[1]);
@ -141,7 +138,6 @@ A
break; break;
case "setseektime": case "setseektime":
case "sst": case "sst":
$game = $this->getGameManager()->getGameByLevel($sender->getLevel());
if(!is_null($game)) { if(!is_null($game)) {
if(isset($args[1]) && is_int($args[1]) && $args[1] > 0) { if(isset($args[1]) && is_int($args[1]) && $args[1] > 0) {
$game->setSeekTime($args[1]); $game->setSeekTime($args[1]);
@ -157,7 +153,6 @@ A
case "setspawn": case "setspawn":
case "ss": case "ss":
$pos = new \pocketmine\math\Vector3($sender->x, $sender->y, $sender->z); $pos = new \pocketmine\math\Vector3($sender->x, $sender->y, $sender->z);
$game = $this->getGameManager()->getGameByLevel($sender->getLevel());
if(!is_null($game)) { if(!is_null($game)) {
$game->setSpawn($pos); $game->setSpawn($pos);
$sender->sendMessage(self::PREFIX . "§cSuccefully set spawn of hide and seek game in level {$sender->getLevel()->getName()} to x: $pos->x, y: $pos->y, z: $pos->z."); $sender->sendMessage(self::PREFIX . "§cSuccefully set spawn of hide and seek game in level {$sender->getLevel()->getName()} to x: $pos->x, y: $pos->y, z: $pos->z.");
@ -169,7 +164,6 @@ A
case "setseekersspawn": case "setseekersspawn":
case "sss": case "sss":
$pos = new \pocketmine\math\Vector3($sender->x, $sender->y, $sender->z); $pos = new \pocketmine\math\Vector3($sender->x, $sender->y, $sender->z);
$game = $this->getGameManager()->getGameByLevel($sender->getLevel());
if(!is_null($game)) { if(!is_null($game)) {
$game->setSeekersSpawn($pos); $game->setSeekersSpawn($pos);
$sender->sendMessage(self::PREFIX . "§cSuccefully set seekers spawn of hide and seek game in level {$sender->getLevel()->getName()} to x: $pos->x, y: $pos->y, z: $pos->z."); $sender->sendMessage(self::PREFIX . "§cSuccefully set seekers spawn of hide and seek game in level {$sender->getLevel()->getName()} to x: $pos->x, y: $pos->y, z: $pos->z.");
@ -178,8 +172,34 @@ A
$sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world."); $sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world.");
} }
break; break;
case "editmode": case "editmode": //TODO: Mode to edit the map (doesn't let players joining exept if they have a permission & enables block placing and breaking)
break; break;
case "start":
if(!is_null($game)) {
if(count($game->getPlayers()) > 1) {
$game->start();
foreach(array_merge($game->getPlayers(), $game->getSpectators()) as $p) {
$p->sendMessage(Main::PREFIX . "§aGame started ! There is $this->seekersCount seekers and $this->hidersLeft hiders.");
if($p->HideAndSeekRole == self::ROLE_SEEK) {
$p->teleport($game->getSeekerSpawn());
} elseif($p->HideAndSeekRole == self::ROLE_HIDE) {
$p->teleport($game->getSpawn());
$p->sendPopup("§lHider: You have 1 minute to hide yourself so seekers won't find you ! Don't get caught for " . $this->getSeekTime() . " minutes to win !");
}
}
}
return true;
} else {
$sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world.");
}
break;
case "stop":
if(!is_null($game)) {
$sender->sendMessage(self::PREFIX . "§aStoping game....");
return true;
} else {
$sender->sendMessage(self::PREFIX . "§cYou're not in an hide and seek game world.");
}
default: default:
$sender->sendMessage(str_ireplace(PHP_EOL, PHP_EOL . self::PREFIX,self::PREFIX. "§cSub-command {$args[0]} not found ! $sender->sendMessage(str_ireplace(PHP_EOL, PHP_EOL . self::PREFIX,self::PREFIX. "§cSub-command {$args[0]} not found !
Possible subcommands: Possible subcommands:
@ -191,6 +211,8 @@ Possible subcommands:
- setseektime <minutes to seek>(or sst): Sets the time seekers have to find all hiders before hiders wins - setseektime <minutes to seek>(or sst): Sets the time seekers have to find all hiders before hiders wins
- setspawn(or ss): Sets the spawn of the place players will wait, hide, and seek - setspawn(or ss): Sets the spawn of the place players will wait, hide, and seek
- setseekersspawn(or sss): Sets the place where players will be tped to while hiders are hiding - setseekersspawn(or sss): Sets the place where players will be tped to while hiders are hiding
- start: Force start the game
- stop: Force stop the game
Please note that all those subcommands are relative to the world where you execute the command in.")); Please note that all those subcommands are relative to the world where you execute the command in."));
break; break;
} }