propertyChgService = new services\PropertyChgService(); $this->awardService = new services\AwardService(); } public function itemList() { $itemList = Bag::all(); $itemDtoList = array(); foreach ($itemList as $item) { array_push($itemDtoList, Bag::toDto($item)); } $this->_rspData(array( 'item_list' => $itemDtoList, )); } public function useItem() { $itemId = getReqVal('item_id', 0); $itemNum = getReqVal('item_num', 0); $param1 = getReqVal('param1', ''); $param2 = getReqVal('param2', ''); $param3 = getReqVal('param3', ''); if ($itemNum < 0) { $this->_rspErr(1, 'item_num must be greater than 0'); return; } $itemDb = Bag::find($itemId); if (!isset($itemDb) || $itemDb['item_num'] <= 0) { $this->_rspErr(1, 'Not enough item'); return; } $itemMeta = mt\Item::get($itemId); if (!$itemMeta) { $this->_rspErr(2, 'config error'); return; } 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; case mt\Item::DRUG_TILI_SUBTYPE: { $this->useTiliDrug($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3); } break; case mt\Item::DRUG_DURABILITY_SUBTYPE: { $this->useDurabilityDrug($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3); } break; default: { $this->_rspErr(4, 'The prop function has not been realized yet'); return; } break; } } else if ($itemMeta['type'] == mt\Item::GIFT_PACKAGE_TYPE) { $this->openGiftPackage($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3); } else if ($itemMeta['type'] == mt\Item::FRAGMENT_BOX_TYPE) { $this->openFragmentBox($itemDb, $itemMeta, $itemNum); } else { $this->_rspErr(4, 'The prop function has not been realized yet'); } } public function rename() { $itemDto = Bag::findByType(mt\Item::FUNC_TYPE, mt\Item::FUNC_RENAME_CARD_SUBTYPE); $userInfo = $this->_getOrmUserInfo(); if ($userInfo['rename_count'] == 0){ $errCode = 0; $errMsg = ''; $this->internalRename(getReqVal('name', ''), getReqVal('name_sign', ''), $errCode, $errMsg); if ($errCode) { $this->_rspErr($errCode, $errMsg); return; } }else{ if (!$itemDto || $itemDto['item_num'] < 0) { if (mt\Parameter::getVal('rename_diamond_cost', 0) <= 0) { $this->_rspErr(1, 'config error'); return; } if ($userInfo['diamond'] < mt\Parameter::getVal('rename_diamond_cost', 0)) { $this->_rspErr(1, 'Not enough item'); return; } } $errCode = 0; $errMsg = ''; $this->internalRename(getReqVal('name', ''), getReqVal('name_sign', ''), $errCode, $errMsg); if ($errCode) { $this->_rspErr($errCode, $errMsg); return; } if (!$itemDto || $itemDto['item_num'] <= 0) { $this->_decItems(array( array( 'item_id' => V_ITEM_DIAMOND, 'item_num' => mt\Parameter::getVal('rename_diamond_cost', 0) ) )); { //埋点 $event = [ 'name' => LogService::USER_RENAME, 'val' => mt\Parameter::getVal('rename_diamond_cost', 0) ]; LogService::consumeDiamond($event); } $this->propertyChgService->addUserChg(); } else { $this->_decItems(array( array( 'item_id' => $itemDto['item_id'], 'item_num' => 1 ) )); $this->propertyChgService->addBagChg(); } } $this->propertyChgService->addUserChg(); $this->_rspData(array( 'property_chg' => $this->propertyChgService->toDto(), )); } private function renameCard($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3) { $errCode = 0; $errMsg = ''; $this->internalRename($param1, $param2, $errCode, $errMsg); if ($errCode) { $this->_rspErr($errCode, $errMsg); return; } $this->_decItems(array( array( 'item_id' => $itemMeta['id'], 'item_num' => 1 ) )); $this->propertyChgService->addUserChg(); $this->propertyChgService->addBagChg(); $this->_rspData(array( 'property_chg' => $this->propertyChgService->toDto(), )); } private function internalRename($name, $nameSign, &$errCode, &$errMsg) { $errCode = 0; $errMsg = ''; if (mb_strlen($name) < 3) { $errCode = 5; $errMsg = 'Parameter error name length must not be less than 3'; return; } if (mb_strlen($name, 'utf8') > 12) { $errCode = 5; $errMsg = 'Parameter error name length must not be greater than 12'; return; } /*if(!preg_match("/^[a-z\d]*$/i",$name)) { $errCode = 5; $errMsg = 'Excuse me , the name you entered is in the wrong format.'; return; }*/ $nameService = new services\NameService(); if (!$nameService->verifyNameSign($name, $nameSign)){ $errCode = 5; $errMsg = 'Parameter name error, signature verification failed'; return; } if ($nameService->nameUsed($name)){ $errCode = 5; $errMsg = 'This name has been taken'; return; } $ret = $nameService->useName($name); if (!$ret) { $errCode = 10; $errMsg = 'server internal error'; return; } $this->_updateUserInfo(array( 'name' => $name, 'rename_count' => function () { return 'rename_count + 1'; } )); } private function openGiftPackage($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3) { $dropMeta = mt\Drop::get($itemMeta['drop']); if (!$dropMeta) { $this->_rspErr(1, 'config error'); return; } $costItems = mt\Item::getUseCostItems($itemMeta); error_log(json_encode($costItems)); $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(), )); } public function buyItem() { $itemId = getReqVal('item_id', 0); $itemMeta = mt\Item::get($itemId); if (!$itemMeta) { $this->_rspErr(1, "item_id error"); return; } if (!( $itemMeta['type'] == mt\Item::FUNC_TYPE && $itemMeta['sub_type'] == mt\Item::FUNC_RENAME_CARD_SUBTYPE)) { $this->_rspErr(1, "only supported rename card"); return; } $costItems= array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => $itemMeta['gold'] ) ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $items = array( array( 'item_id' => $itemId, 'item_num' => 1 ) ); $this->_decItems($costItems); $this->_addItems($items, $this->awardService, $this->propertyChgService); $this->propertyChgService->addUserChg(); $this->propertyChgService->addBagChg(); $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $this->propertyChgService->toDto(), )); } private function useTiliDrug($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3) { $errCode = 0; $errMsg = ''; $heroUniId = $param1; $heroDb = Hero::find($heroUniId); if (!$heroDb) { $this->_rspErr(1, "You don't have the hero yet"); return; } Hero::addTili($heroUniId, $itemMeta['param1']); Bag::decItemByUnIid($heroUniId, $itemNum); $this->propertyChgService->addBagChg(); $this->propertyChgService->addHeroChg(); $this->_rspData(array( 'property_chg' => $this->propertyChgService->toDto(), )); } private function useDurabilityDrug($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3) { $errCode = 0; $errMsg = ''; $targetUniId = $param1; $gunDb = Gun::findByUniId($targetUniId); if (!$gunDb) { $this->_rspErr(1, "You don't have the equip yet"); return; } Gun::addDurability($gunDb['gun_uniid'], $itemMeta['param1']); Bag::decItemByUnIid($itemDb['item_uniid'], $itemNum); $this->propertyChgService->addBagChg(); $this->propertyChgService->addGunChg(); $this->_rspData(array( 'property_chg' => $this->propertyChgService->toDto(), )); } private function openFragmentBox($itemDb, $itemMeta, $itemNum){ $this->_rspOk(); // if ($itemDb['item_num']<$itemNum){ // $this->_rspErr(1, "The shard chest is insufficient"); // return; // } // for ($i=1;$i<=$itemNum;$i++){ // if (! Nft::addNftByFragmentBox($itemMeta,$i)){ // $this->_rspErr(1, "server internal error"); // return; // } // Bag::decItemByUnIid($itemDb['item_uniid'], 1); // } // $this->propertyChgService->addBagChg(); // $this->_rspData(array( // 'property_chg' => $this->propertyChgService->toDto(), // )); } }