示例#1
0
文件: give.php 项目: sinfocol/gwf3
 public static function giveItem(SR_Player $player, SR_Player $target, $id, $amt = 1)
 {
     if ($amt < 1) {
         $player->msg('1038');
         // 			$player->message('Please give a positive amount of items.');
         return false;
     }
     if (false === ($item = $player->getInvItem($id))) {
         $player->msg('1029');
         // 			$player->message('You don`t have that item.');
         return false;
     }
     // 		if (false === $item->isItemTradeable())
     // 		{
     // 			$player->message('You are not allowed to trade this item.');
     // 			return false;
     // 		}
     if ($item->isItemStackable()) {
         if ($amt > $item->getAmount()) {
             $player->msg('1040', array($item->getItemName()));
             // 				$player->message(sprintf('You only have %d %s.', $item->getAmount(), $item->getName()));
             return false;
         }
         $giveItem = SR_Item::createByName($item->getItemName(), $amt, true);
         $item->useAmount($player, $amt);
     } else {
         if ($amt !== 1) {
             $player->message('Currently you can only give one equipment at a time.');
             return false;
         }
         $player->removeFromInventory($item);
         $giveItem = $item;
     }
     $busymsg = $player->isFighting() ? Shadowfunc::displayBusy($player->busy(SR_Player::GIVE_TIME)) : '';
     self::rply($player, '5115', array($amt, $giveItem->displayFullName($player), $target->getName(), $busymsg));
     // 		$player->message(sprintf('You gave %d %s to %s.%s', $amt, $giveItem->getName(), $target->getName(), $busymsg));
     $target->giveItems(array($giveItem), $player->getName());
     // 		if ($target instanceof SR_TalkingNPC)
     // 		{
     // 			$target->onNPCGive($player, $items);
     // 		}
     return true;
 }
示例#2
0
 public function giveQuesties(SR_Player $player, $itemname, $have, $need)
 {
     $left = $need - $have;
     $give = 0;
     while ($left > 0) {
         if (false === ($item = $player->getInvItem($itemname))) {
             break;
         }
         $possible = Common::clamp($item->getAmount(), 0, $left);
         $item->useAmount($player, $possible);
         $give += $possible;
         $left -= $possible;
         $have += $possible;
     }
     if ($give > 0) {
         $player->msg('5239', array($give, $itemname, $this->getName()));
     }
     return $have;
 }