From 1d350552367ba9f20053a7917cb5301873b4fbe8 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 24 Dec 2021 14:05:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BD=BF=E7=94=A8=E7=A4=BC?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webapp/controller/BagController.class.php | 64 +++++++++++++++++------ webapp/mt/Item.php | 16 ++++++ 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/webapp/controller/BagController.class.php b/webapp/controller/BagController.class.php index 8f40e7f2..b25def3c 100644 --- a/webapp/controller/BagController.class.php +++ b/webapp/controller/BagController.class.php @@ -2,6 +2,7 @@ require_once('mt/Parameter.php'); require_once('mt/Item.php'); +require_once('mt/Drop.php'); require_once('models/Bag.php'); @@ -54,22 +55,24 @@ class BagController extends BaseAuthedController { $this->_rspErr(2, '配置表错误'); return; } - if ($itemMeta['type'] != mt\Item::FUNC_TYPE) { - $this->_rspErr(3, '该道具为不可使用道具'); - return; - } - switch ($itemMeta['sub_type']) { - case mt\Item::FUNC_RENAME_CARD_SUBTYPE: - { - $this->renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3); - } - break; - default: - { + if ($itemMeta['type'] == mt\Item::FUNC_TYPE) { + switch ($itemMeta['sub_type']) { + case mt\Item::FUNC_RENAME_CARD_SUBTYPE: + { + $this->renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3); + } + break; + default: + { + $this->_rspErr(4, '该道具功能暂未实现'); + return; + } + break; + } + } else if ($itemMeta['type'] == mt\Item::GIFT_PACKAGE_TYPE) { + $this->openGiftPackage($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3); + } else { $this->_rspErr(4, '该道具功能暂未实现'); - return; - } - break; } } @@ -174,4 +177,35 @@ class BagController extends BaseAuthedController { )); } + private function openGiftPackage($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3) + { + $dropMeta = mt\Drop::get($itemMeta['drop']); + if (!$dropMeta) { + $this->_rspErr(1, '配置表错误'); + return; + } + $costItems = mt\Item::getUseCostItems($itemMeta); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); + return; + } + $this->_decItems($costItems); + $this->_decItems(array( + array( + 'item_id' => $itemMeta['id'], + 'item_num' => 1 + ) + )); + $this->_scatterDrop('gift_package:' . $itemMeta['id'], + $dropMeta, + $this->awardService, + $this->propertyChgService); + $this->propertyChgService->addBagChg(); + $this->_rspData(array( + 'award' => $this->awardService->toDto(), + 'property_chg' => $this->propertyChgService->toDto(), + )); + } + } diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index 7204883b..a0ad5ecf 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -169,6 +169,22 @@ class Item { return $costItems; } + public static function getUseCostItems($itemMeta) + { + $costItems = array(); + $tmpStrs1 = splitStr1($itemMeta['use_cost']); + foreach ($tmpStrs1 as $tmpStr1) { + $tmpStrs2 = splitStr2($tmpStr1); + if (count($tmpStrs2) >= 2) { + array_push($costItems, array( + 'item_id' => $tmpStrs2[0], + 'item_num' => $tmpStrs2[1] + )); + } + } + return $costItems; + } + public static function isBagItem($type, $subType) { return in_array($type, array(