添加使用礼包

This commit is contained in:
aozhiwei 2021-12-24 14:05:37 +08:00
parent b4eda8b18b
commit 1d35055236
2 changed files with 65 additions and 15 deletions

View File

@ -2,6 +2,7 @@
require_once('mt/Parameter.php'); require_once('mt/Parameter.php');
require_once('mt/Item.php'); require_once('mt/Item.php');
require_once('mt/Drop.php');
require_once('models/Bag.php'); require_once('models/Bag.php');
@ -54,22 +55,24 @@ class BagController extends BaseAuthedController {
$this->_rspErr(2, '配置表错误'); $this->_rspErr(2, '配置表错误');
return; return;
} }
if ($itemMeta['type'] != mt\Item::FUNC_TYPE) { if ($itemMeta['type'] == mt\Item::FUNC_TYPE) {
$this->_rspErr(3, '该道具为不可使用道具'); switch ($itemMeta['sub_type']) {
return; case mt\Item::FUNC_RENAME_CARD_SUBTYPE:
} {
switch ($itemMeta['sub_type']) { $this->renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3);
case mt\Item::FUNC_RENAME_CARD_SUBTYPE: }
{ break;
$this->renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3); default:
} {
break; $this->_rspErr(4, '该道具功能暂未实现');
default: return;
{ }
break;
}
} else if ($itemMeta['type'] == mt\Item::GIFT_PACKAGE_TYPE) {
$this->openGiftPackage($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3);
} else {
$this->_rspErr(4, '该道具功能暂未实现'); $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(),
));
}
} }

View File

@ -169,6 +169,22 @@ class Item {
return $costItems; 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) public static function isBagItem($type, $subType)
{ {
return in_array($type, array( return in_array($type, array(