Ejemplo n.º 1
0
 public function startTrade($buyer, $seller, $shop)
 {
     if (!MPMU::access($buyer, "goldstd.shopkeep.shop")) {
         return;
     }
     if ($this->getState("trade-inv", $buyer, null) !== null) {
         echo "Already trading\n";
         //##DEBUG
         return;
     }
     echo __METHOD__ . "," . __LINE__ . "\n";
     //##DEBUG
     $l = $seller->getLevel();
     $tile = null;
     for ($i = -2; $i <= 0 && $tile == null; $i--) {
         $pos = $seller->add(0, $i, 0);
         $tile = $l->getTile($pos);
         if ($tile instanceof Chest) {
             break;
         } else {
             $tile = null;
         }
     }
     if ($tile == null) {
         $this->owner->getLogger()->error(mc::_("Error trading with NPC at %1%,%2%,%3% (%4%)", $seller->floorX(), $seller->floorY(), $seller->floorZ(), $seller->getLevel()->getName()));
         $buyer->sendMessage(mc::_("Sorry, nothing happens..."));
         return;
     }
     $inv = ["player" => [], "chest" => null];
     $inv["money"] = $this->owner->getMoney($buyer);
     var_dump($inv["money"]);
     //##DEBUG
     $inv["shop"] = $shop;
     foreach ($buyer->getInventory()->getContents() as $slot => &$item) {
         $inv["player"][$slot] = implode(":", [$item->getId(), $item->getDamage(), $item->getCount()]);
     }
     $inv["chest"] = new TraderInventory($tile, $buyer);
     $contents = [];
     foreach ($this->keepers[$shop]["items"] as $idmeta => $it) {
         $item = clone $it[0];
         $item->setCount(1);
         $contents[] = $item;
     }
     $inv["chest"]->setContents($contents);
     $this->setState("trade-inv", $buyer, $inv);
     $buyer->getInventory()->clearAll();
     $buyer->addWindow($inv["chest"]);
     echo __METHOD__ . "," . __LINE__ . "\n";
     //##DEBUG
 }
Ejemplo n.º 2
0
 private function validateSign($pl, $sign)
 {
     if (!MPMU::access($pl, "goldstd.signs.place")) {
         return false;
     }
     $sn = $this->texts[$sign[0]];
     if (!MPMU::access($pl, "goldstd.signs.place." . $sn)) {
         return false;
     }
     switch ($sn) {
         case "shop":
             $item = $this->parseItemLine($sign[1]);
             if ($item === null) {
                 $pl->sendMessage(mc::_("Invalid item line"));
                 return false;
             }
             $price = $this->parsePriceLine($sign[2]);
             if ($price === null) {
                 $pl->sendMessage(mc::_("Invalid price line"));
                 return false;
             }
             break;
         case "effects":
             $effect = $this->parseEffectLine($sign[1]);
             if ($effect === null) {
                 $pl->sendMessage(mc::_("Invalid effects line"));
                 return false;
             }
             $price = $this->parsePriceLine($sign[2]);
             if ($price === null) {
                 $pl->sendMessage(mc::_("Invalid price line"));
                 return false;
             }
             break;
         case "trade":
             $ret = true;
             foreach ([1, 2] as $i) {
                 $item = $this->parseItemLine($sign[$i]);
                 if ($item === null) {
                     $pl->sendMessage(mc::_("Invalid item%1% line", $i));
                     $ret = false;
                 }
             }
             return $ret;
         case "casino":
             list($odds, $payout) = $this->parseCasinoLine($sign[1]);
             if ($odds === null) {
                 $pl->sendMessage(mc::_("Invalid odds line"));
                 return false;
             }
             $price = $this->parsePriceLine($sign[2]);
             if ($price === null) {
                 $pl->sendMessage(mc::_("Invalid price line"));
                 return false;
             }
             break;
         case "command":
             $cmd = $this->parseCmdLine($sign[1]);
             if ($cmd === null) {
                 $pl->sendMessage(mc::_("Invalid command line"));
                 return false;
             }
             $price = $this->parsePriceLine($sign[2]);
             if ($price === null) {
                 $pl->sendMessage(mc::_("Invalid price line"));
                 return false;
             }
             break;
     }
     return true;
 }
Ejemplo n.º 3
0
 public function startTrade($buyer, $seller, $shop)
 {
     if (!MPMU::access($buyer, "goldstd.shopkeep.shop")) {
         return;
     }
     $this->cart->start($buyer, $this->keepers[$shop]["items"]);
 }