Created
June 13, 2017 15:39
-
-
Save tomocrafter/d2b39f8a2f68d1a79116c8059cb450c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace HungerGames\MiniGame; | |
use pocketmine\Server; | |
use pocketmine\Player; | |
use pocketmine\network\protocol\LevelEventPacket; | |
use pocketmine\math\Vector3; | |
//use HungerGames\HungerGames; | |
class Parkour{ | |
public $Parkour = []; | |
private $time_start = []; | |
private $time_end = []; | |
public function __construct(/*HungerGames */$hunger){ | |
$this->hunger = $hunger; | |
$this->server = $hunger->server; | |
$this->database = $hunger->database; | |
} | |
public function start(PLayer $p){ | |
$user = $p->getName(); | |
if(!isset($this->Parkour["Nomal"][$user])){ | |
$p->sendMessage("§cタイムアタックを開始しました。\nゴール地点の感圧板までダッシュだ!!"); | |
$this->time_start[$user] = time(); | |
$this->Parkour["Nomal"][$user] = "true"; | |
} | |
} | |
public function end(Player $p){ | |
$user = $p->getName(); | |
if(isset($this->Parkour["Nomal"][$user])){ | |
$out = "§aParkourをクリアしました! Time: "; | |
$this->time_end[$user] = time(); | |
$time = $this->time_end[$user] - $this->time_start[$user]; | |
if($time >= 60){ | |
$minute = floor($time / 60); | |
$second = $time - $minute * 60; | |
if($minute >= 60){ | |
$hour = floor($minute / 60); | |
$minute = $minute - $hour * 60; | |
$last_time = $hour . " : " . $minute . " ; " . $second;//一時間以上 | |
}else{ | |
$last_time = $minute . " ; " . $second;//59分以内 | |
} | |
}else{ | |
$last_time = "00 ; " . $time;//59秒以内 | |
} | |
echo "time: " . $time . "\n"; | |
echo "allowFlight: " . $p->getAllowFlight() . "\n"; | |
if($time <= 15 || $p->getAllowFlight()){//不正行為判定 | |
$p->close("", "不正行為は禁止です"); | |
unset($this->Parkour["Nomal"][$user]); | |
return; | |
} | |
$this->server->broadcastMessage("§a${user}さんが、{$last_time}でクリアしました!"); | |
unset($this->Parkour["Nomal"][$user]); | |
$p->sendMessage($out); | |
$p->sendPopup("§aお疲れ様です♪\n保存したdataは \"site.tomocraft.net/ServerInfo/player.php\"で確認できます。"); | |
$d = $this->database["spawn"]; | |
$p->teleport(new Vector3($d['x'], $d['y'], $d['z'])); | |
} | |
} | |
public function stopParkour(Player $p){ | |
$user = $p->getName(); | |
if(isset($this->Parkour["Nomal"][$user])){ | |
$d = $this->database["spawn"]; | |
unset($this->Parkour["Nomal"][$user]); | |
$p->sendMessage("Parkour (パルクール) を終了します。"); | |
$p->teleport(new Vector3($d['x'], $d['y'], $d['z'])); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment