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!"); } }
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()); } }