Ejemplo n.º 1
0
 protected function onRun(Session $ses, array $args)
 {
     if (!isset($args[0])) {
         return TextFormat::RED . "Usage: " . $this->getUsage();
     }
     if ($ses->getTeam() instanceof Team) {
         return TextFormat::RED . "You are alerady in a team!";
     }
     $name = array_shift($args);
     if (preg_match('#^[A-Za-z][A-Za-z0-9_\\-]{2,62}$#', $name) === 0) {
         $red = TextFormat::RED;
         $yellow = TextFormat::YELLOW;
         $aqua = TextFormat::AQUA;
         return $red . "A team name must{$yellow} start with an alphabet{$red}, must{$yellow} only contain{$aqua} alphabets{$red},{$aqua} numerals{$red},{$aqua} underscore{$red} and{$aqua} hyphens{$red}, must be{$yellow} at least 3 characters{$red} long and{$yellow} at most 63 characters{$red} long.";
     }
     if ($this->main->getTeamManager()->getTeamByExactName($name) instanceof Team) {
         return TextFormat::RED . "A team with this name already exists!";
     }
     $team = new Team($this->main, $this->main->getMySQLi()->nextTID(), $name, Settings::team_maxCapacity($ses->getRank()), false, [$ses->getUID() => Team::RANK_LEADER]);
     $ses->getMysqlSession()->data["tid"] = $team->tid;
     $ses->getMysqlSession()->data["teamrank"] = Team::RANK_LEADER;
     $ses->getMysqlSession()->data["teamjointime"] = time();
     $this->main->getTeamManager()->addTeam($team);
     $ses->getPlayer()->kick(TextFormat::YELLOW . "You have been kicked from the server in order to apply your changes about creating a team.", false);
     return null;
 }
Ejemplo n.º 2
0
 public function onSlap(Session $session)
 {
     $data = $this->game->getPlayerData($session);
     if ($data === null) {
         return;
     }
     if ($this->column === Settings::KIT_ARROWS and $data->getBowLevel() === 0) {
         $session->tell("You don't have a bow. Why are you buying arrows? Upgrade your bows first.");
         return;
     }
     $kit = $data->getEditingKit();
     $curLevel = $kit->{$this->column};
     if ($curLevel === $this->max) {
         $session->tell("You already have the maximum level of {$this->column}!");
         return;
     }
     $buy = $data->isGoingToBuy;
     $oldInfo = Settings::kitpvp_getKitUpgradeInfo($this->column, $curLevel);
     $newInfo = Settings::kitpvp_getKitUpgradeInfo($this->column, $curLevel + 1);
     if (!is_array($buy) or $buy["column"] !== $this->column or microtime(true) - $buy["timestamp"] > 5) {
         $price = $newInfo->getPrice();
         $balance = $session->getCoins();
         if ($balance < $price) {
             $session->tell("You need at least %g more coins to buy this kit!", $price - $balance);
             $data->isGoingToBuy = null;
             return;
         }
         if ($newInfo->sendCantPurchaseMessage($session)) {
             $data->isGoingToBuy = null;
             return;
         }
         $data->isGoingToBuy = ["column" => $this->column, "timestamp" => microtime(true)];
         $session->tell("Upgrade {$this->column} to level %d (%g coins required)", $curLevel + 1, $newInfo->getPrice());
         $oldName = $oldInfo->itemsToString();
         $session->tell("You will be equipped with %s%s after you purchase this upgrade.", $newInfo->itemsToString(), $oldName === false ? "" : " instead of {$oldName}");
         $session->tell("Click me again within 5 seconds to purchase this upgrade.");
     } else {
         $data->isGoingToBuy = null;
         if ($newInfo->sendCantPurchaseMessage($session)) {
             return;
         }
         $price = $newInfo->getPrice();
         $balance = $session->getCoins();
         if ($balance < $price) {
             $session->tell("You need %g more coins to buy this kit!", $price - $balance);
             return;
         }
         $session->setCoins($balance - $price);
         $kit->{$this->column} = $curLevel + 1;
         $kit->updated = true;
         $models = $this->game->getModels();
         if (isset($models[$kit->kitid])) {
             $model = $models[$kit->kitid];
             $model->despawnFrom($session->getPlayer());
             $model->spawnTo($session->getPlayer());
         }
         $session->tell("Your {$this->column} has been upgraded to level %d!", $curLevel + 1);
         $session->tell("Rejoin KitPvP or suicide to activate the kit change!");
     }
 }
Ejemplo n.º 3
0
 public function onLoadChunk(ChunkLoadEvent $event)
 {
     if ($event->getLevel()->getName() !== "world_pvp") {
         return;
     }
     $chunk = $event->getChunk();
     $hash = Level::chunkHash($chunk->getX(), $chunk->getZ());
     if (isset($this->modelLocs[$hash])) {
         foreach ($this->modelLocs[$hash] as $id => $loc) {
             $model = new PvpKitModel($this->game, $id, $loc);
             $model->spawnToAll();
             $this->models[$id] = $model;
         }
     }
     if (isset($this->shopLocs[$hash])) {
         foreach ($this->shopLocs[$hash] as $col => $loc) {
             $shop = new PvpUpgradeDummyShop($this->game, $loc, $col);
             $shop->spawnToAll();
             $this->shops[$col] = $shop;
         }
     }
     if ($hash === $this->bowHash) {
         $this->bow = new PvpBowHolder(Settings::kitpvp_getBowLocation($this->game->getMain()->getServer()), $this->game);
     }
 }
Ejemplo n.º 4
0
 protected function run(Session $ses, array $args)
 {
     if (!$ses->switchSession(Session::SESSION_GAME_HUB)) {
         return TextFormat::RED . "Failed to quit - you are not in a game, or your game refused to let you go.";
     }
     $ses->teleport(Settings::loginSpawn($this->getPlugin()->getServer()));
     return TextFormat::GREEN . "You are now at hub.";
 }
Ejemplo n.º 5
0
 protected function run(Session $ses, array $args)
 {
     if (!$ses->canActivateGrindCoins($secs)) {
         return TextFormat::RED . "You need to wait for at least " . MUtils::time_secsToString($secs) . " to activate coins grinding again.";
     }
     if (!$ses->wannaGrind) {
         $ses->wannaGrind = true;
         $ses->tell(TextFormat::AQUA . "After enabling coins grinding, coins you received will be multiplied by %s times. This doesn't apply to spending coins.", TextFormat::LIGHT_PURPLE . Settings::coinsFactor($ses, true) . TextFormat::AQUA);
         $ses->tell(TextFormat::AQUA . "It will last for %s each time, and you can't enable it again %s after activation.", TextFormat::LIGHT_PURPLE . MUtils::time_secsToString(Settings::getGrindDuration($ses)) . TextFormat::AQUA, TextFormat::LIGHT_PURPLE . MUtils::time_secsToString(Settings::getGrindActivationWaiting($ses)) . TextFormat::AQUA);
         return TextFormat::AQUA . "Run /grindcoin again to confirm enabling coins grinding.";
     }
     $ses->wannaGrind = false;
     $ses->getMysqlSession()->data["lastgrind"] = time();
     return TextFormat::GREEN . "You have activated coins grinding. You will receive an extra of " . TextFormat::LIGHT_PURPLE . (Settings::coinsFactor($ses) * 100 - 100) . "%" . TextFormat::GREEN . " coins for those you earn in the following " . TextFormat::LIGHT_PURPLE . MUtils::time_secsToString(Settings::getGrindDuration($ses)) . TextFormat::GREEN . ".";
 }
Ejemplo n.º 6
0
 public function onSlap(Session $session)
 {
     $data = $this->game->getPlayerData($session);
     $oldLevel = $data->getBowLevel();
     $newLevel = $oldLevel + 1;
     list($upgradePrice, $name, $description, $damage, $fireTicks, $knockback, $minImportance) = Settings::kitpvp_getBowInfo($newLevel);
     $rank = $session->getRank();
     if (($rank & Settings::RANK_SECTOR_IMPORTANCE) < $minImportance) {
         $session->tell("Upgrade your account to get more advanced bows!");
         return;
     }
     if ($upgradePrice === PHP_INT_MAX) {
         $session->tell("More bow upgrades coming soon!");
         return;
     }
     if ($data->isGoingToBuy === null or $data->isGoingToBuy["column"] !== "bow" or $data->isGoingToBuy["timestamp"] + 5 < microtime(true)) {
         $session->tell("Upgrade your bow to \"%s\".", $name);
         $session->tell($description);
         $session->tell("%s deals %f hearts of damage to victims.", $name, $damage / 2);
         if ($fireTicks > 0) {
             $session->tell("It also sets them on fire for %f seconds", $fireTicks / 20);
         }
         if ($knockback > 0) {
             $session->tell("An extra knockback of {$knockback}%% will also be casted.");
         }
         $session->tell("This upgrade costs you %g coins.", $upgradePrice);
         if ($upgradePrice > $session->getCoins()) {
             $session->tell("You need at least %g more coins to upgrade your bow!", $upgradePrice - $session->getCoins());
         } else {
             $session->tell("Click me within 5 seconds to confirm the purchase.");
             $data->isGoingToBuy = ["column" => "bow", "timestamp" => microtime(true)];
         }
     } else {
         $data->isGoingToBuy = null;
         if ($upgradePrice > $session->getCoins()) {
             $session->tell("You need at least %d more coins to upgrade your bow!", $upgradePrice - $session->getCoins());
             return;
         }
         $session->setCoins($coins = $session->getCoins() - $upgradePrice);
         $data->setBowLevel($newLevel);
         MUtils::word_addSingularArticle($name);
         $session->tell("Your bow is now {$name}! You have %d coins left.", $coins);
         $session->tell("Triple-click a model to toggle sword or bow.");
     }
 }
Ejemplo n.º 7
0
 public function __construct(LegionPE $main)
 {
     parent::__construct($main);
     $this->main = $main;
     $main->getServer()->getScheduler()->scheduleDelayedRepeatingTask($this, 2400, 2400);
     $this->sql = new \SQLite3(":memory:");
     $this->sql->exec("CREATE TABLE teams (id INTEGER PRIMARY KEY, name TEXT COLLATE NOCASE, open INTEGER)");
     $this->main->getMySQLi()->query("UPDATE teams SET has_founder=0 WHERE isnull((SELECT uid FROM players WHERE tid=teams.tid AND teamrank=%d))", MysqlConnection::RAW, Team::RANK_LEADER);
     $this->main->getMySQLi()->query("UPDATE players SET tid=-1,teamrank=0 WHERE(SELECT has_founder FROM teams WHERE tid=players.tid)=0", MysqlConnection::RAW);
     $this->main->getMySQLi()->query("DELETE FROM teams WHERE(SELECT COUNT(*)FROM players WHERE players.tid=teams.tid)=0", MysqlConnection::RAW);
     foreach ($this->main->getMySQLi()->query("SELECT *,(SELECT rank FROM players WHERE tid=teams.tid AND teamrank=4 LIMIT 1)AS leaderrank FROM teams", MysqlConnection::ALL) as $row) {
         $tid = (int) $row["tid"];
         $members = [];
         foreach ($this->main->getMySQLi()->query("SELECT uid,teamrank FROM players WHERE tid={$tid}", MysqlConnection::ALL) as $member) {
             $members[(int) $member["uid"]] = (int) $member["teamrank"];
         }
         $this->teams[$tid] = new Team($main, $tid, $row["name"], Settings::team_maxCapacity($row["leaderrank"]), (bool) (int) $row["open"], $members, isset($row["invited"]) ? $row["invited"] : "", isset($row["requires"]) ? $row["requires"] : "", isset($row["rules"]) ? $row["rules"] : "");
         $op = $this->sql->prepare("INSERT INTO teams (id, name, open)VALUES(:id, :name, :open)");
         $op->bindValue(":id", $tid);
         $op->bindValue(":name", $row["name"]);
         $op->bindValue(":open", $row["open"]);
         $op->execute();
     }
 }
Ejemplo n.º 8
0
 private function giveTools(PlayerInventory $inv, $rank)
 {
     $inv->getHolder()->setHealth(20);
     $inv->remove(Item::get(Item::SNOWBALL));
     $inv->addItem(...$this->config->playerItems);
     // TODO support shops
     $inv->addItem(new Snowball(0, Settings::easter_getSnowballCount($rank)));
 }
Ejemplo n.º 9
0
 public function canActivateGrindCoins(&$leftTime = 0)
 {
     $expiry = $this->mysqlSession->data["lastgrind"] + Settings::getGrindActivationWaiting($this);
     $leftTime = $expiry - time();
     return $leftTime <= 0;
 }
Ejemplo n.º 10
0
 protected function onSlap(Session $session)
 {
     if ($session->inSession($this->game)) {
         $data = $this->game->getPlayerData($session);
         $curEditing = $data->getEditingKitId();
         if ($curEditing !== $this->kid) {
             // choose to edit this
             $kit = $data->getKitById($this->kid);
             if ($kit === null) {
                 // create new kit
                 if (count($data->getKits()) >= Settings::kitpvp_maxKits($session)) {
                     // cannot create new kit: full
                     $session->tell("You cannot use more kits! Upgrade your account to have more kits!");
                     return;
                 }
                 // create new kit
                 $kit = PvpKit::getDefault($session->getUID(), $this->kid);
                 $data->addKit($this->kid, $kit);
             }
             /** @var PvpKitModel[] $others */
             $others = $this->game->getModels();
             if (isset($others[$curEditing])) {
                 $otherModel = $others[$curEditing];
                 $otherModel->unfireTo($session->getPlayer());
             }
             $this->fireTo($session->getPlayer());
             $data->setEditingKitId($this->kid);
             $session->tell("You are now editing \"{$kit->name}\".");
             if ($data->getKitIdInUse() !== $this->kid) {
                 $session->tell("Click me again to apply \"{$kit->name}\".");
             } else {
                 $session->tell("Click me again to swap between bow/sword kit");
             }
         } else {
             // make this the using kit
             if ($data->getKitIdInUse() === $this->kid) {
                 if ($data->getBowLevel() === 0) {
                     $session->tell("After you bought a bow, triple-click me to enable/disable it.");
                     $session->tell("But right now you haven't yet!");
                     return;
                 }
                 $data->setIsUsingBowKit($bool = !$data->isUsingBowKit());
                 $session->tell("Your %s kit has been changed into a %s kit!", $bool ? "sword" : "bow", $bool ? "bow" : "sword");
                 return;
             }
             $kit = $data->getKitById($this->kid);
             if ($kit->kitid !== $this->kid) {
                 throw new \UnexpectedValueException("Unexpected {$kit->kitid} !== {$this->kid} at " . __FILE__ . "#" . __LINE__);
                 // crash.
             }
             $this->setNameTagTo($session->getPlayer(), self::IN_USE_TAG . $this->getNameTag());
             $oldInUseId = $data->getKitIdInUse();
             $data->setKitIdInUse($this->kid);
             $others = $this->game->getModels();
             if (isset($others[$oldInUseId])) {
                 $otherModel = $others[$oldInUseId];
                 $otherModel->setNameTagTo($session->getPlayer(), substr($otherModel->getNameTag(), strlen(self::IN_USE_TAG)));
             }
             $session->tell("You are now using kit \"{$kit->name}\". Rejoin this game or suicide using /kill to activate.");
             $data->getKitInUse()->equip($session->getPlayer()->getInventory(), $data, true);
         }
     } else {
         $this->getMain()->getLogger()->warning("{$this} was spawned to an invalid entity!");
         $this->despawnFrom($session->getPlayer());
     }
 }
Ejemplo n.º 11
0
 public function havingMaxKits()
 {
     return count($this->kits) >= Settings::kitpvp_maxKits($this->session->getRank());
 }
Ejemplo n.º 12
0
 public function onRespawn(PlayerRespawnEvent $event, Session $session)
 {
     $event->setRespawnPosition(Settings::parkour_checkpoint_startPos($this->data[$session->getUID()]->getProgress(), $session->getMain()->getServer()));
 }
Ejemplo n.º 13
0
 public function setSpawnOnPlayer(Player $player)
 {
     $player->setSpawn(Settings::loginSpawn($this->getServer()));
 }
Ejemplo n.º 14
0
 public function equip(PlayerInventory $inv, PvpSessionData $data, $send = true)
 {
     $inv->clearAll();
     $messages = [];
     $info = Settings::kitpvp_getKitUpgradeInfo("helmet", $this->helmet);
     $inv->setHelmet($info->getItem());
     $messages[] = $info->itemsToString();
     $info = Settings::kitpvp_getKitUpgradeInfo("chestplate", $this->chestplate);
     $inv->setChestplate($info->getItem());
     $messages[] = $info->itemsToString();
     $info = Settings::kitpvp_getKitUpgradeInfo("leggings", $this->leggings);
     $inv->setLeggings($info->getItem());
     $messages[] = $info->itemsToString();
     $info = Settings::kitpvp_getKitUpgradeInfo("boots", $this->boots);
     $inv->setBoots($info->getItem());
     $messages[] = $info->itemsToString();
     $inv->sendArmorContents($inv->getViewers());
     if ($data->isUsingBowKit()) {
         $weapon = $data->getBowLevel() > 0 ? new Bow() : Item::get(Item::AIR);
         $messages[] = "a bow";
     } else {
         $info = Settings::kitpvp_getKitUpgradeInfo("weapon", $this->weapon);
         $weapon = $info->getItem();
         $messages[] = $info->itemsToString();
     }
     $info = Settings::kitpvp_getKitUpgradeInfo("food", $this->food);
     $food = $info->getItem();
     $messages[] = $info->itemsToString();
     $info = Settings::kitpvp_getKitUpgradeInfo("arrows", $this->arrows);
     $arrows = $info->getItem();
     $messages[] = $info->itemsToString();
     /** @var \pocketmine\item\Item[] $items */
     $items = [];
     if ($weapon->getId() !== Item::AIR) {
         $items[] = $weapon;
     }
     if ($food->getId() !== 0) {
         $items[] = $food;
     }
     if ($arrows->getId() !== 0) {
         $items[] = $arrows;
     }
     $inv->addItem(...$items);
     $cnt = Settings::easter_getSnowballCount($data->getSession());
     if ($cnt > 0) {
         $inv->addItem(new Snowball(0, $cnt));
     }
     if ($data->getKills() <= 500) {
         $inv->addItem(new Snowball(0, 8));
     }
     if ($send) {
         $inv->sendHeldItem($inv->getViewers());
         $inv->sendArmorContents($inv->getViewers());
     }
 }
Ejemplo n.º 15
0
 /**
  * @param BlockBreakEvent $event
  * @priority HIGH
  */
 public function onBlockBreak(BlockBreakEvent $event)
 {
     $player = $event->getPlayer();
     $session = $this->getMain()->getSessions()->getSession($player);
     if (!$session->inSession($this)) {
         return;
     }
     $data = $this->getPlayerData($session);
     if ($data->isPlaying() and $data->getArena()->isPlaying() and Settings::spleef_isArenaFloor($event->getBlock())) {
         $event->setCancelled(false);
     }
 }
Ejemplo n.º 16
0
 private function onFriendInboxCommand(Session $session)
 {
     $uid = $session->getUID();
     $fromSmall = self::TYPE_FROM_SMALL;
     $fromLarge = self::TYPE_FROM_LARGE;
     $friend = self::TYPE_FRIEND;
     $result = $this->main->getMySQLi()->query("SELECT(SELECT primaryname FROM players WHERE uid=sel.uid)AS name,theirFriends AS theirFriendsCnt,(SELECT rank FROM players WHERE uid=sel.uid)AS rank FROM(SELECT uid,(SELECT COUNT(*) FROM kitpvp_friends WHERE type={$friend} AND(smalluid=uid OR largeuid=uid))AS theirFriends FROM(SELECT IF(smalluid={$uid},largeuid,smalluid)AS uid FROM kitpvp_friends WHERE(smalluid={$uid} AND type={$fromLarge})OR(largeuid={$uid} AND type={$fromSmall}))AS friends)AS sel", MysqlConnection::ALL);
     $names = [];
     foreach ($result as &$row) {
         $row["theirFriendsCnt"] = (int) $row["theirFriendsCnt"];
         $name = $row["name"];
         if ($row["theirFriendsCnt"] >= Settings::kitpvp_maxFriends((int) $row["rank"])) {
             $name = TextFormat::RED . "{$name} (full)" . TextFormat::WHITE;
         }
         $names[] = $name;
     }
     return sprintf("You have %d received friend request(s) from:\n%s.", count($names), count($names) > 0 ? implode(", ", $names) : "---");
 }