Moo
Signed-off-by: Aaron Brock <TheMineBench@gmail.com>
This commit is contained in:
parent
bcc7e1fb65
commit
af8d1bdc83
@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 10:32 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\spawn;
|
||||
|
||||
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
|
||||
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent;
|
||||
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
|
||||
use mineplex\plugin\util\UtilArray;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
|
||||
class SimpleSpawnComponent implements SpawnComponent, Listener {
|
||||
|
||||
private $arena;
|
||||
private $worldComponent;
|
||||
private $gameMode;
|
||||
|
||||
/** @var Position[] */
|
||||
private $spawns = [];
|
||||
|
||||
function __construct(Arena $arena, WorldComponent $worldComponent, $gameMode = Player::SURVIVAL)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
$this->worldComponent = $worldComponent;
|
||||
$this->gameMode = $gameMode;
|
||||
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
|
||||
}
|
||||
|
||||
public function onWorld(WorldLoadSuccessEvent $event)
|
||||
{
|
||||
print "WorldLoadSuccessEvent!";
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
$this->spawns = UtilArray::getValuesRecursively($this->worldComponent->getTeams());
|
||||
|
||||
foreach ($this->spawns as $key => $value)
|
||||
{
|
||||
if (!($value instanceof Position))
|
||||
unset($this->spawns[$key]);
|
||||
$this->spawns[$key] = new Position($value->getX(), $value->getY(), $value->getZ(), $event->getLevel());
|
||||
}
|
||||
|
||||
print (count($this->spawns) . " spawns Loaded");
|
||||
|
||||
$pos = $this->spawns[array_rand($this->spawns)];
|
||||
|
||||
print "\nX: " . $pos->getX();
|
||||
print "\nY: " . $pos->getY();
|
||||
print "\nZ: " . $pos->getZ();
|
||||
print "\nLevel: " . $pos->getLevel()->getName();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
* @return Position
|
||||
*/
|
||||
function respawn(Player $player)
|
||||
{
|
||||
if (count($this->spawns) < 1)
|
||||
{
|
||||
print "no spawns!";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$player->getInventory()->clearAll();
|
||||
$player->removeAllEffects();
|
||||
$player->resetFallDistance();
|
||||
$player->setGamemode($this->gameMode);
|
||||
$player->setHealth($player->getMaxHealth());
|
||||
|
||||
$pos = $this->spawns[array_rand($this->spawns)];
|
||||
|
||||
print "\nX: " . $pos->getX();
|
||||
print "\nY: " . $pos->getY();
|
||||
print "\nZ: " . $pos->getZ();
|
||||
print "\nLevel: " . $pos->getLevel()->getName();
|
||||
|
||||
$player->teleport($pos);
|
||||
return $pos;
|
||||
}
|
||||
|
||||
function respawnAll() {
|
||||
foreach ($this->arena->getPlayers() as $player)
|
||||
{
|
||||
$this->respawn($player);
|
||||
}
|
||||
}
|
||||
|
||||
function onEnd(ArenaEndEvent $event)
|
||||
{
|
||||
if ($event->getArena() !== $this->arena)
|
||||
return;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Exerosis
|
||||
* Date: 7/6/2015
|
||||
* Time: 10:47 PM
|
||||
*/
|
||||
|
||||
namespace mineplex\plugin\gameengine\game\components\spawn;
|
||||
|
||||
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
|
||||
use mineplex\plugin\gameengine\game\components\gamestate\events\GameStateChangeEvent;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\Server;
|
||||
|
||||
class SpawnAt implements Listener {
|
||||
|
||||
private $spawnComponent;
|
||||
private $arena;
|
||||
|
||||
private $gameStates;
|
||||
|
||||
function __construct(Arena $arena, SpawnComponent $spawnComponent, array $gameStates)
|
||||
{
|
||||
$this->arena = $arena;
|
||||
$this->spawnComponent = $spawnComponent;
|
||||
$this->gameStates = $gameStates;
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
|
||||
}
|
||||
|
||||
public function onStateChange(GameStateChangeEvent $event)
|
||||
{
|
||||
if ($this->arena !== $event->getArena())
|
||||
return;
|
||||
if (in_array($event->getToGameState(), $this->gameStates)) {
|
||||
$this->spawnComponent->respawnAll();
|
||||
print "called! \n";
|
||||
}
|
||||
}
|
||||
|
||||
public function onEnd(ArenaEndEvent $event)
|
||||
{
|
||||
if ($this->arena !== $event->getArena())
|
||||
return;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
}
|
@ -19,4 +19,6 @@ interface SpawnComponent {
|
||||
*/
|
||||
function respawn(Player $player);
|
||||
|
||||
function respawnAll();
|
||||
|
||||
}
|
@ -9,11 +9,14 @@
|
||||
namespace mineplex\plugin\gameengine\game\components\world;
|
||||
|
||||
use mineplex\plugin\gameengine\arenas\Arena;
|
||||
use mineplex\plugin\gameengine\arenas\events\ArenaEndEvent;
|
||||
use mineplex\plugin\gameengine\arenas\events\ArenaStartEvent;
|
||||
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadFailEvent;
|
||||
use mineplex\plugin\gameengine\game\components\world\event\WorldLoadSuccessEvent;
|
||||
use mineplex\plugin\util\UtilArray;
|
||||
use mineplex\plugin\util\UtilString;
|
||||
use mineplex\plugin\util\UtilFile;
|
||||
use pocketmine\event\HandlerList;
|
||||
use pocketmine\event\Listener;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -48,30 +51,14 @@ class WorldComponent implements Listener
|
||||
$this->gameId = $this->getNewGameId();
|
||||
|
||||
Server::getInstance()->getPluginManager()->registerEvents($this, $arena->getPlugin());
|
||||
|
||||
$this->loadWorld("Super Smash Mobs");
|
||||
}
|
||||
|
||||
// This is just some wierd testiong. Ignore it :P
|
||||
// public function onJoin(PlayerJoinEvent $event)
|
||||
// {
|
||||
// $this->player = $event->getPlayer();
|
||||
// }
|
||||
//
|
||||
// public function onEvent(UpdateEvent $event)
|
||||
// {
|
||||
// if (is_null($this->player))
|
||||
// return;
|
||||
//
|
||||
// if ($event->isTiming(UpdateType::S8))
|
||||
// {
|
||||
// $this->player->teleport($this->posTest);
|
||||
//
|
||||
// print("Teleporting " . $this->player->getName() . " to...\n");
|
||||
//
|
||||
// $this->player = null;
|
||||
// }
|
||||
// }
|
||||
public function onStart(ArenaStartEvent $event)
|
||||
{
|
||||
if ($this->arena !== $event->getArena())
|
||||
return;
|
||||
$this->loadWorld("Super Smash Mobs");
|
||||
}
|
||||
|
||||
private function unloadWorld()
|
||||
{
|
||||
@ -309,5 +296,12 @@ class WorldComponent implements Listener
|
||||
{
|
||||
return $this->ready;
|
||||
}
|
||||
|
||||
public function onEnd(ArenaEndEvent $event)
|
||||
{
|
||||
if ($this->arena !== $event->getArena())
|
||||
return;
|
||||
HandlerList::unregisterAll($this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@ use mineplex\plugin\gameengine\game\components\feature\managers\GameStateFeature
|
||||
use mineplex\plugin\gameengine\game\components\gamestate\GameState;
|
||||
use mineplex\plugin\gameengine\game\components\gamestate\GameStateComponent;
|
||||
use mineplex\plugin\gameengine\game\components\lobby\LobbyComponent;
|
||||
use mineplex\plugin\gameengine\game\components\spawn\SimpleSpawnComponent;
|
||||
use mineplex\plugin\gameengine\game\components\spawn\SpawnAt;
|
||||
use mineplex\plugin\gameengine\game\components\spectate\GameModeSpectateComponent;
|
||||
use mineplex\plugin\gameengine\game\components\world\WorldComponent;
|
||||
use mineplex\plugin\gameengine\game\Game;
|
||||
@ -35,7 +37,6 @@ class SurvivalGames implements Game {
|
||||
$spectateComponent = new GameModeSpectateComponent($arena);
|
||||
|
||||
//Init features
|
||||
|
||||
$noPickUpItem = new NoPickUpItem($arena, [Item::GRASS], true);
|
||||
|
||||
$pack = array(new NoBlockBreak($arena, [Item::GRASS]), new NoBlockPlace($arena, [Item::WOOD], true),new NoDropItem($arena, [Item::APPLE], true));
|
||||
@ -45,21 +46,23 @@ class SurvivalGames implements Game {
|
||||
GameState::LOBBY => array($noPickUpItem, $pack)
|
||||
);
|
||||
|
||||
|
||||
new GameStateFeatureManager($arena, $features);
|
||||
|
||||
//new LobbyComponent($arena);
|
||||
new LobbyComponent($arena);
|
||||
|
||||
/*
|
||||
$worldComponent = new WorldComponent($arena);
|
||||
|
||||
new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 50, 1);
|
||||
$spawnComponent = new SimpleSpawnComponent($arena, $worldComponent);
|
||||
|
||||
new SpawnAt($arena, $spawnComponent, [GameState::PRE_GAME]);
|
||||
|
||||
new LobbyCountdown($arena, $gameStateComponent, $worldComponent, GameState::LOBBY, GameState::PRE_GAME, 10, 1);
|
||||
|
||||
new GameStateCountdown($arena, $gameStateComponent, 10, GameState::PRE_GAME, GameState::GAME);
|
||||
|
||||
new GameStateCountdown($arena, $gameStateComponent, 60, GameState::GAME, GameState::POST_GAME);
|
||||
new GameStateCountdown($arena, $gameStateComponent, 20, GameState::GAME, GameState::POST_GAME);
|
||||
|
||||
new GameStateCountdown($arena, $gameStateComponent, 10, GameState::POST_GAME, GameState::RESTARTING);
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user