/** * Push items into the clan bank. * @param SR_Clan $clan * @param string $itemname * @param int $amt * @param int $weight * @return boolean */ public static function push(SR_Clan $clan, $itemname, $amt, $weight) { $cid = $clan->getID(); if (false !== ($row = self::getByCIDINAME($cid, $itemname))) { if (false === $row->increase('sr4cb_iamt', $amt)) { return false; } } else { if (false === self::table(__CLASS__)->insertAssoc(array('sr4cb_cid' => $cid, 'sr4cb_iname' => $itemname, 'sr4cb_iamt' => $amt))) { return false; } } return $clan->increase('sr4cl_storage', $weight); }
private function onViewItems(SR_Clan $clan, SR_Player $player, $arg, $page) { $ipp = 10; $cid = $clan->getID(); $arg = GDO::escape($arg); $page = (int) $page; $table = GDO::table('SR_ClanBank'); $where = "sr4cb_cid={$cid} AND sr4cb_iname LIKE '%{$arg}%'"; $nItems = $table->countRows($where); if ($nItems === 0) { $player->msg('1007'); // $player->message('No match found.'); return true; } $nPages = GWF_PageMenu::getPagecount($ipp, $nItems); if ($page < 1 || $page > $nPages) { $player->msg('1009'); // $player->message('This page is empty.'); return false; } $from = GWF_PageMenu::getFrom($page, $ipp); if (false === ($result = $table->selectAll('sr4cb_iname, sr4cb_iamt', $where, 'sr4cb_iamt ASC, sr4cb_iname ASC', NULL, $ipp, $from, GDO::ARRAY_N))) { $player->message('DB ERROR 1.'); return false; } if (count($result) === 1) { return $this->onViewItem($clan, $player, $result[0][0], $result[0][1]); } $out = ''; $format = $player->lang('fmt_items'); foreach ($result as $row) { $from++; list($itemname, $amt) = $row; $damt = $amt === '1' ? '' : "({$amt})"; $out .= sprintf($format, $from, $itemname, $damt, $amt); // $out[] = sprintf('%d-%s%s', $from, $itemname, $amt); } $bot = Shadowrap::instance($player); return $bot->rply('5176', array($page, $nPages, substr($out, 2))); // return $bot->reply(sprintf('ClanBank page %d/%d: %s.', $page, $nPages, implode(', ', $out))); }
public static function onAddStorage(SR_Clan $clan, SR_Player $player) { $event = new self(array('sr4ch_id' => '0', 'sr4ch_cid' => $clan->getID(), 'sr4ch_time' => Shadowrun4::getTime(), 'sr4ch_pname' => $player->getName(), 'sr4ch_action' => self::ADD_STORAGE, 'sr4ch_iname' => NULL, 'sr4ch_amt' => $clan->getMaxStorage())); return self::insertAndSend($clan, $event); }