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!"); } }
/** * @param Player $player * @param PvpSessionData|null $data */ public function spawnTo(Player $player, $data = null) { if ($data === null) { $data = $this->game->getPlayerData($player, true); // most likely newly joined if (!$data instanceof PvpSessionData) { return; // don't spawn to players who aren't programmatically in KitPvP } } $kit = $data->getKitById($this->kid, true, $isNew); $this->getInventory()->sendContents($player); $this->setNameTag($kit->name === "" ? "Kit {$this->kid}" : $kit->name); if ($data->getKitIdInUse() === $this->kid) { $this->nameTag = self::IN_USE_TAG . $this->nameTag; } parent::spawnTo($player); $kit->equip($this->getInventory(), $data, false); // TODO hardcode $this->getInventory()->sendArmorContents([$player]); $this->getInventory()->sendHeldItem($player); if ($data->getEditingKitId() === $this->kid) { $this->fireTo($player); } }