Beispiel #1
0
 public function onPlayerTrade(Player $giver, Player $taker)
 {
     $good = clone $giver->getInventory()->getItemInHand();
     $gift = clone $good;
     $gift->setCount(1);
     $taker->getInventory()->addItem($gift);
     $good->setCount($n = $good->getCount() - 1);
     $slot = $giver->getInventory()->getHeldItemSlot();
     if ($n <= 0) {
         $giver->getInventory()->clear($slot);
     } else {
         $giver->getInventory()->setItem($slot, $good);
     }
     $item = ItemName::str($good);
     if (MPMU::apiVersion("1.12.0")) {
         $giver->sendTip(mc::_("Gave one %1%", $item));
         $taker->sendTip(mc::_("Received %1%", $item));
     } else {
         $giver->sendMessage(mc::_("Gave one %1%", $item));
         $taker->sendMessage(mc::_("Received %1%", $item));
     }
 }
Beispiel #2
0
 private function activateSign($pl, $tile)
 {
     $sign = $tile->getText();
     if (!MPMU::access($pl, "goldstd.signs.use")) {
         return;
     }
     $sn = $this->texts[$sign[0]];
     if (!MPMU::access($pl, "goldstd.signs.use." . $sn)) {
         return;
     }
     switch ($sn) {
         case "shop":
             $item = $this->parseItemLine($sign[1]);
             if ($item === null) {
                 $pl->sendMessage(mc::_("Invalid item line"));
                 return;
             }
             $price = $this->parsePriceLine($sign[2]);
             if ($price === null) {
                 $pl->sendMessage(mc::_("Invalid price line"));
                 return;
             }
             $money = $this->owner->getMoney($pl);
             if ($money < $price) {
                 $pl->sendMessage(mc::_("[GoldStd] You do not have enough money"));
             } else {
                 $this->owner->grantMoney($pl, -$price);
                 $pl->getInventory()->addItem(clone $item);
                 $pl->sendMessage(mc::_("[GoldStd] Item purchased"));
             }
             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;
             }
             $money = $this->owner->getMoney($pl);
             if ($money < $price) {
                 $pl->sendMessage(mc::_("[GoldStd] You do not have enough money"));
             } else {
                 $this->owner->grantMoney($pl, -$price);
                 $pl->addEffect($effect);
                 $pl->sendMessage(mc::_("[GoldStd] Potion %1% purchased", $effect->getName()));
             }
             break;
         case "trade":
             // This is what you get...
             $item1 = $this->parseItemLine($sign[1]);
             if ($item1 === null) {
                 $pl->sendMessage(mc::_("Invalid item1 line"));
                 return;
             }
             // This is what you pay...
             $item2 = $this->parseItemLine($sign[2]);
             if ($item2 === null) {
                 $pl->sendMessage(mc::_("Invalid item2 line"));
                 return;
             }
             /*** Check if the player has item2 in stock ***/
             $inv = $pl->getInventory();
             $cnt = 0;
             $slots = [];
             foreach ($pl->getInventory()->getContents() as $slot => &$item) {
                 if ($item2->getId() != $item->getId()) {
                     continue;
                 }
                 if ($item2->getDamage() && $item2->getDamage() != $item->getDamage()) {
                     continue;
                 }
                 // OK, he got it...
                 $cnt += $item->getCount();
                 $slots[] = [$slot, $item->getCount()];
             }
             if ($cnt == 0) {
                 $pl->sendMessage(mc::_("You do not have any %1%", ItemName::str($item2)));
                 return;
             }
             if ($cnt < $item2->getCount()) {
                 $pl->sendMessage(mc::_("You do not have enough %1%", ItemName::str($item2)));
                 $pl->sendMessage(mc::_("You have %1%, you need %2%", $cnt, $item2->getCount()));
                 return;
             }
             $cnt = $item2->getCount();
             // Take away stock...
             while ($cnt >= 0) {
                 list($slot, $qty) = array_pop($slots);
                 if ($qty > $cnt) {
                     // More than enough...
                     $newitem = clone $item2;
                     $newitem->setCount($qty - $cnt);
                     $cnt = 0;
                     $pl->getInventory()->setItem($slot, $newitem);
                     break;
                 }
                 if ($qty <= $cnt) {
                     // Not enough, consume that slot completely...
                     $cnt -= $qty;
                     $pl->getInventory()->clear($slot);
                 }
             }
             $pl->sendMessage(mc::n(mc::_("Gave away one %1%", ItemName::str($item2)), mc::_("Gave away %2% %1%s", ItemName::str($item2), $item2->getCount()), $item2->getCount()));
             // Give new stock...
             $pl->getInventory()->addItem(clone $item1);
             $pl->sendMessage(mc::n(mc::_("Got one %1%", ItemName::str($item1)), mc::_("Got %2% %1%s", ItemName::str($item1), $item1->getCount()), $item1->getCount()));
             break;
         case "casino":
             list($odds, $payout) = $this->parseCasinoLine($sign[1]);
             if ($odds === null) {
                 $pl->sendMessage(mc::_("Invalid odds line"));
                 return;
             }
             $price = $this->parsePriceLine($sign[2]);
             if ($price === null) {
                 $pl->sendMessage(mc::_("Invalid price line"));
                 return;
             }
             $money = $this->owner->getMoney($pl);
             if ($money < $price) {
                 $pl->sendMessage(mc::_("[GoldStd] You do not have enough moneys"));
             } else {
                 $pl->sendMessage(mc::_("[GoldStd] Betting %1%...", $price));
                 $this->owner->grantMoney($pl, -$price);
                 $rand = mt_rand(0, $odds);
                 if ($rand == 1) {
                     $pl->sendMessage(mc::_("[GoldStd] You WON!!! prize...%1%G", $payout));
                     $this->owner->grantMoney($pl, $payout);
                 } else {
                     $pl->sendMessage(mc::_("[GoldStd] BooooM!!! You lost"));
                 }
             }
             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;
             }
             $money = $this->owner->getMoney($pl);
             if ($money < $price) {
                 $pl->sendMessage(mc::_("[GoldStd] You do not have enough money"));
             } else {
                 $this->owner->grantMoney($pl, -$price);
                 $pl->sendMessage(mc::_("[GoldStd] Command %1% purchased", $sign[1]));
                 Cmd::opexec($pl, $cmd);
             }
             break;
     }
 }