forked from Ad5001/UHC
BUg fixes + How To Play + TimeBomb
This commit is contained in:
parent
6cd5bec03a
commit
899278162b
5 changed files with 138 additions and 14 deletions
58
resources/scenarios/TimeBomb.php
Normal file
58
resources/scenarios/TimeBomb.php
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Ad5001\UHC\scenario\Scenario;
|
||||||
|
use pocketmine\event\player\PlayerDeathEvent;
|
||||||
|
use pocketmine\block\Chest;
|
||||||
|
use pocketmine\block\Air;
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\utils\TextFormats as C;
|
||||||
|
|
||||||
|
class TimeBomb extends Scenario {
|
||||||
|
|
||||||
|
public function onDeath(PlayerDeathEvent $event) {
|
||||||
|
$v3 = new Vector3($event->getPlayer()->x $event->getPlayer()->y, $event->getPlayer()->z);
|
||||||
|
$v3n = new Vector3($event->getPlayer()->x $event->getPlayer()->y, $event->getPlayer()->z + 1);
|
||||||
|
$lvl = $event->getPlayer()->getLevel();
|
||||||
|
$lvl->setBlock($v3, new Chest());
|
||||||
|
$lvl->setBlock($v3n, new Chest());
|
||||||
|
$t = $level->getTile($v3);
|
||||||
|
$t->getInventory()->setContents($event->getPlayer()->getInventory()->getContents());
|
||||||
|
$event->getPlayer()->getInevntory()->clearAll();
|
||||||
|
$h = $this->getServer()->getScheduler()->scheduleRepeatingTask($t = new TimeBombExplodeChestTask($this, $v3, $lvl), 20);
|
||||||
|
$t->setHandler($h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TimeBombExplodeChestTask extends \pocketmine\scheduler\PluginTask {
|
||||||
|
|
||||||
|
public function __construct(TimeBomb $main, Vector3 $v3, \pocketmine\level\Level $lvl) {
|
||||||
|
parent::__construct($main->getMain());
|
||||||
|
$this->main = $main;
|
||||||
|
$this->v3 = $v3;
|
||||||
|
$this->seconds = 20;
|
||||||
|
$this->lvl = $lvl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function onRun($tick) {
|
||||||
|
switch($this->seconds) {
|
||||||
|
case 20:
|
||||||
|
$this->lvl->addParticle($this->part = new \pocketmine\level\particle\FloatingTextParticle($this->v3, C::GREEN . "before the explosion !", "20 seconds"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$this->part->setTitle(strval($this->seconds) . " seconds");
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
$ex = new Explosion(\pocketmine\level\Position::fromObject($this->v3, $this->lvl), 7);
|
||||||
|
$ex->explodeA();
|
||||||
|
$ex->explodeB();
|
||||||
|
$this->lvl->getTile($this->v3)->getInventory()->setContents([]);
|
||||||
|
$this->lvl->setBlock($this->v3, new Air());
|
||||||
|
$this->lvl->setBlock(new Vector3($this->v3->x, $this->v3->y, $this->v3->z + 1), new Air());
|
||||||
|
$this->part->setInvisible(true);
|
||||||
|
$this->main->getScheduler()->cancelTask($this->getTaskId());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,7 @@ use Ad5001\UHC\event\GameStartEvent;
|
||||||
use Ad5001\UHC\event\GameFinishEvent;
|
use Ad5001\UHC\event\GameFinishEvent;
|
||||||
|
|
||||||
class Main extends PluginBase implements Listener{
|
class Main extends PluginBase implements Listener{
|
||||||
const PREFIX = C::GOLD . "[" . C::DARK_RED . "UHC" . C::GOLD . "] ". C::RESET;
|
const PREFIX = C::GOLD . "[" . C::DARK_RED . "UHC" . C::GOLD . "] ". C::RESET . C::WHITE;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class Main extends PluginBase implements Listener{
|
||||||
$event->setCancelled();
|
$event->setCancelled();
|
||||||
}
|
}
|
||||||
} elseif($event->getTarget()->getName() === $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and !isset($this->quit[$event->getEntity()])) {
|
} elseif($event->getTarget()->getName() === $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and !isset($this->quit[$event->getEntity()])) {
|
||||||
$event->getPlayer()->setGamemode(3);
|
$event->getEntity()->setGamemode(3);
|
||||||
} elseif($event->getTarget()->getName() === $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and isset($this->quit[$event->getEntity()])) {
|
} elseif($event->getTarget()->getName() === $world->getName() and isset($this->UHCManager->getStartedUHCs()[$world->getName()]) and isset($this->quit[$event->getEntity()])) {
|
||||||
$quit = explode("/", $this->quit[$event->getEntity()]);
|
$quit = explode("/", $this->quit[$event->getEntity()]);
|
||||||
if($quit[3] === $world->getName()) {
|
if($quit[3] === $world->getName()) {
|
||||||
|
@ -121,6 +121,34 @@ switch($cmd->getName()){
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
case "howtoplay":
|
||||||
|
case "?":
|
||||||
|
case "help":
|
||||||
|
if(!isset($args[1])) {
|
||||||
|
$sender->sendMessage(self::PREFIX . "Welcome to UHC's help ! WHat do you want to know about UHC?\n" . self::PREFIX . "- The game (/uhc howtoplay game)\n" . self::PREFIX . "- The commands (/uhc howtoplay commands)\n" . self::PREFIX . "- The scenarios (/uhc howtoplay scenarios)\n");
|
||||||
|
} else {
|
||||||
|
switch(strtolower($args[1])) {
|
||||||
|
case "game":
|
||||||
|
$sender->sendMessage(self::PREFIX . "UHC (aka Ultra HardCord) is a new difficulty where it's hardcord but with no health regen exept for golden apples and potions and only 1 life. The most popular 'UHC' Game is a PvP (Player versus Player) game where you're in this mode and you need to kill other players.\n" . self::PREFIX . "What do you want to know next?\n" . self::PREFIX . "- The commands (/uhc howtoplay commands)\n" . self::PREFIX . "- The scenarios (/uhc howtoplay scenarios)\n");
|
||||||
|
break;
|
||||||
|
case "commands":
|
||||||
|
$sender->sendMessage(self::PREFIX . "This UHC Plugin have special commands. For players: /scenarios will give you the list of the current enabled scenarios. " . ($sender->isOp() ? "For OP: '/uhc start' start the uhc. '/uhc stop' finish it. '/scenarios add <scenario>' adds a scenario. '/scenario rm <scenario>' remove a scenario. '/scenarios list' gives you the list of installed scenarios.\n" : "\n") . self::PREFIX . "What do you want to know next?\n" . self::PREFIX . "- The game (/uhc howtoplay game)\n" . self::PREFIX . "- The scenarios (/uhc howtoplay scenarios)");
|
||||||
|
break;
|
||||||
|
case "scenarios":
|
||||||
|
$sender->sendMessage(self::PREFIX . "Scenarios are 'addons' to the UHC that modify some mechanics or some parts of the game. You can download them or create them yourself. Look at ccommands if you want to know how to add a scenario to a game and look at https://github.com/Ad5001/UHC/wiki/What-are-Scenarios%3F. If you want to know more about a scenario, use /uhc howtoplay <scenario name>.\n" . self::PREFIX . "What do you want to know next?\n" . self::PREFIX . "- The game (/uhc howtoplay game)\n" . self::PREFIX . "- The commands (/uhc howtoplay commands)\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if(in_array($this->UHCManager->getLevels()[$sender->getLevel()->getName()]->scenarioManager->getScenarios(), $args[0])) {
|
||||||
|
$sender->sendMessage(self::PREFIX . "Help for $args[0]. " . $args[0]::help);
|
||||||
|
} else {
|
||||||
|
$sender->sendMessage(self::PREFIX . "No help for $args[0]");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -182,6 +210,7 @@ switch($cmd->getName()){
|
||||||
$sender->sendMessage(self::PREFIX . "Current enabled scenarios : " . implode(", ", $scs));
|
$sender->sendMessage(self::PREFIX . "Current enabled scenarios : " . implode(", ", $scs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -37,6 +37,7 @@ class UHCGame implements Listener{
|
||||||
public function __construct(Plugin $plugin, UHCWorld $world) {
|
public function __construct(Plugin $plugin, UHCWorld $world) {
|
||||||
$this->m = $plugin;
|
$this->m = $plugin;
|
||||||
$this->world = $world;
|
$this->world = $world;
|
||||||
|
$world->getLevel()->setTime(0);
|
||||||
$plugin->getServer()->getPluginManager()->registerEvents($this, $plugin);
|
$plugin->getServer()->getPluginManager()->registerEvents($this, $plugin);
|
||||||
$this->players = $world->getLevel()->getPlayers();
|
$this->players = $world->getLevel()->getPlayers();
|
||||||
$event = new GameStartEvent($this, $world, $this->players);
|
$event = new GameStartEvent($this, $world, $this->players);
|
||||||
|
@ -48,6 +49,9 @@ class UHCGame implements Listener{
|
||||||
} else {
|
} else {
|
||||||
$radius = $world->radius;
|
$radius = $world->radius;
|
||||||
foreach($this->players as $player) {
|
foreach($this->players as $player) {
|
||||||
|
$player->getInventory()->clearAll();
|
||||||
|
$player->setGamemode(0);
|
||||||
|
for($e = 1; $e < 24; $e++) {$player->removeEffect($e);}
|
||||||
$x = rand($radius + $world->getLevel()->getSpawnLocation()->x, $world->getLevel()->getSpawnLocation()->x - $radius);
|
$x = rand($radius + $world->getLevel()->getSpawnLocation()->x, $world->getLevel()->getSpawnLocation()->x - $radius);
|
||||||
$z = rand($radius + $world->getLevel()->getSpawnLocation()->z, $world->getLevel()->getSpawnLocation()->z - $radius);
|
$z = rand($radius + $world->getLevel()->getSpawnLocation()->z, $world->getLevel()->getSpawnLocation()->z - $radius);
|
||||||
$pos = new Vector3($x, 128, $z);
|
$pos = new Vector3($x, 128, $z);
|
||||||
|
@ -79,8 +83,7 @@ class UHCGame implements Listener{
|
||||||
|
|
||||||
public function onRespawn(PlayerRespawnEvent $event) {
|
public function onRespawn(PlayerRespawnEvent $event) {
|
||||||
if(isset($this->respawn[$event->getPlayer()->getName()]) and !$this->cancelled) {
|
if(isset($this->respawn[$event->getPlayer()->getName()]) and !$this->cancelled) {
|
||||||
$player->teleport($this->world->getLevel());
|
$event->getPlayer()->setGamemode(3);
|
||||||
$player->setGamemode(3);
|
|
||||||
unset($this->respawn[$event->getPlayer()->getName()]);
|
unset($this->respawn[$event->getPlayer()->getName()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ use Ad5001\UHC\Main;
|
||||||
use Ad5001\UHC\scenario\ScenarioManager;
|
use Ad5001\UHC\scenario\ScenarioManager;
|
||||||
|
|
||||||
|
|
||||||
class UHCWorld {
|
class UHCWorld implements Listener {
|
||||||
public function __construct(Plugin $main, Level $level, int $maxplayers, int $radius) {
|
public function __construct(Plugin $main, Level $level, int $maxplayers, int $radius) {
|
||||||
$this->p = $main;
|
$this->p = $main;
|
||||||
$this->lvl = $level;
|
$this->lvl = $level;
|
||||||
|
@ -30,6 +30,7 @@ class UHCWorld {
|
||||||
$this->players = [];
|
$this->players = [];
|
||||||
$this->cfg = $main->getConfig();
|
$this->cfg = $main->getConfig();
|
||||||
$this->radius = $radius;
|
$this->radius = $radius;
|
||||||
|
$main->getServer()->getPluginManager()->registerEvents($this, $main);
|
||||||
$this->scenarioManager = new ScenarioManager($this->p, $this);
|
$this->scenarioManager = new ScenarioManager($this->p, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +45,31 @@ class UHCWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function onEntityDamage(\pocketmine\event\entity\EntityDamageEvent $event) {
|
||||||
|
if(!$this->isStarted()) {
|
||||||
|
$event->setCancelled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function onBlockBreak(\pocketmine\event\block\BlockBreakEvent $event) {
|
||||||
|
if(!$this->isStarted()) {
|
||||||
|
if(!$event->getPlayer()->isCreative()) {
|
||||||
|
$event->setCancelled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) {
|
||||||
|
if(!$this->isStarted()) {
|
||||||
|
if(!$event->getPlayer()->isCreative()) {
|
||||||
|
$event->setCancelled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getPlayers() {
|
public function getPlayers() {
|
||||||
return $this->players;
|
return $this->players;
|
||||||
}
|
}
|
||||||
|
@ -60,18 +86,21 @@ class UHCWorld {
|
||||||
|
|
||||||
|
|
||||||
public function setPlayers(array $players) {
|
public function setPlayers(array $players) {
|
||||||
foreach($players as $player) {
|
foreach($this->players as $key => $player) {
|
||||||
if(!in_array($player, $this->players)){
|
if(!in_array($player, $this->players)){
|
||||||
foreach($this->players as $pl) {
|
$player->sendMessage(Main::PREFIX . C::YELLOW . "You joined the game.");
|
||||||
$pl->sendMessage(Main::PREFIX . C::YELLOW . "{$player->getName()} left the game.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach($this->players as $player) {
|
|
||||||
if(!in_array($player, $players)){
|
|
||||||
foreach($this->players as $pl) {
|
foreach($this->players as $pl) {
|
||||||
$pl->sendMessage(Main::PREFIX . C::YELLOW . "{$player->getName()} joined the game.");
|
$pl->sendMessage(Main::PREFIX . C::YELLOW . "{$player->getName()} joined the game.");
|
||||||
$this->getLevel()->addParticle($part = new FloatingTextParticle(new Vector3($this->getLevel()->getSafeSpawn()->x, $this->getLevel()->getSafeSpawn()->y, $this->getLevel()->getSafeSpawn()->z), C::GREEN . "Welcome to the UHC game, {$player->getName()}!\n" . C::GREEN . "Need help? Use /uhc howtoplay.", C::YELLOW . "-=<UHC>=-"), [$pl]);
|
$this->getLevel()->addParticle($part = new FloatingTextParticle(new Vector3($this->getLevel()->getSafeSpawn()->x, $this->getLevel()->getSafeSpawn()->y, $this->getLevel()->getSafeSpawn()->z), C::GREEN . "Welcome to the UHC game, {$player->getName()}!\n" . C::GREEN . "Need help? Use /uhc howtoplay.", C::YELLOW . "-=<UHC>=-"), [$player]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($players as $player) {
|
||||||
|
if(!in_array($player, $players)){
|
||||||
|
$player->sendMessage(Main::PREFIX . C::YELLOW . "You left the game.");
|
||||||
|
foreach($this->players as $pl) {
|
||||||
|
$pl->sendMessage(Main::PREFIX . C::YELLOW . "{$player->getName()} left the game.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,6 +140,11 @@ abstract class Scenario implements ScenarioInt, Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function help() {
|
||||||
|
return "This scenario does not purpose help.";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getLogger() {
|
public function getLogger() {
|
||||||
return $this->getMain()->getLogger();
|
return $this->getMain()->getLogger();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue