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()); } }
public function getKitById($kid, $nonNull = false, &$shouldNull = false) { $shouldNull = false; if (isset($this->kits[$kid])) { return $this->kits[$kid]; } $shouldNull = true; return $nonNull ? PvpKit::getDefault($this->uid, $kid) : null; }