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 createGuildConsume() { $consume = explode("|",mt\Parameter::getVal('create_club_cost', '')); $costItems = array( array( 'item_id' => $consume[0], 'item_num' => $consume[1] ), ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); $this->_rspOk(); } // 兑换水晶 public function exchangeCrystal() { // step1. consume items // step2. send rewards $this->_rspOk(); } public function useItemS() { $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 || $itemDb['item_num']< $itemNum) { $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::FUNC_GUILD_CARD_SUBTYPE: { $this->_decItems(array( array( 'item_id' => $itemMeta['id'], 'item_num' => 1 ) )); $this->_rspOk(); return; } break; case mt\Item::RECOVER_DRUG_SUBTYPE: { $this->useRecoverDrug($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3); } break; case mt\Item::PACKAGING_SUBTYPE: { $this->useSealDrug($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::TREASURE_BOX) { $this->openTreasureBox($itemDb, $itemMeta, $itemNum); } else if ($itemMeta['type'] == mt\Item::BATTLE_REWARD_BOX) { $this->openBattleBox($itemDb, $itemMeta, $itemNum); } else { $this->_rspErr(4, 'The prop function has not been realized yet'); } } public function rename() { $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; } myself()->_rspOk(); return; } $itemDto = Bag::findByType(mt\Item::FUNC_TYPE, mt\Item::FUNC_RENAME_CARD_SUBTYPE); error_log(json_encode($itemDto)); if (!$itemDto || $itemDto['item_num'] < 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; } $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 oldRename() { $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) ) )); myself()->_incV(TN_TOTAL_DIAMOND_CONSUME, 0, mt\Parameter::getVal('rename_diamond_cost', 0)); $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(), )); } private function openTreasureBox($itemDb,$itemMeta,$itemNum){ $dropMeta = mt\Drop::get($itemMeta['drop']); if (!$dropMeta) { $this->_rspErr(1, 'config error'); return; } $costItems = mt\Item::getUseCostItems($itemMeta); foreach ($costItems as &$costItem){ $costItem['item_num'] *= $itemNum; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } if ($itemDb['item_num'] < $itemNum){ $this->_rspErr(3, "item inadequate in number"); return; } $this->_decItems($costItems); $this->_decItems(array( array( 'item_id' => $itemMeta['id'], 'item_num' => $itemNum ) )); for ($i=1;$i<=$itemNum;$i++){ $this->_scatterDrop('serverBox:' . $itemMeta['id'], $dropMeta, $this->awardService, $this->propertyChgService); } $this->propertyChgService->addBagChg(); $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $this->propertyChgService->toDto(), )); } private function openBattleBox($itemDb,$itemMeta,$itemNum){ $costItems = mt\Item::getUseCostItems($itemMeta); if (count($costItems) > 0){ foreach ($costItems as &$costItem){ $costItem['item_num'] *= $itemNum; } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } } if ($itemMeta['quality'] > 3){ $maxCec = \mt\Parameter::getVal('CEC_ServerDailyLootMax_Special',1500); $nameIndex = RealtimeData::CEC_NAME_INDEX2; }else{ $maxCec = \mt\Parameter::getVal('CEC_ServerDailyLootMax_Normal',500); $nameIndex = RealtimeData::CEC_NAME_INDEX1; } $items = array(); for ($i=0;$i<$itemNum;$i++){ $itemsTemp = \services\LootService::dropOutItem($itemMeta['loot']); foreach ($itemsTemp as $itemTemp){ if ($itemTemp['item_id'] == V_ITEM_BCEG){ $currentOutPutCec = RealtimeData::getDailyCec($nameIndex); if ($currentOutPutCec + $itemTemp['item_num'] <= $maxCec){ RealtimeData::incDailyCec($nameIndex,$itemTemp['item_num']); array_push($items,$itemTemp); } }else{ array_push($items,$itemTemp); } } } $hashItems = array(); foreach ($items as $item){ $awardItemMeta = \mt\Item::get($item['item_id']); $this->sendNotice($awardItemMeta , $item['item_num']); if (isset($hashItems[$item['item_id']])){ $hashItems[$item['item_id']]['item_num'] += $item['item_num']; }else{ $hashItems[$item['item_id']] = $item; } } if (count($costItems) > 0){ $this->_decItems($costItems); } $this->_decItems(array( array( 'item_id' => $itemMeta['id'], 'item_num' => $itemNum ) )); $this->_addItems($hashItems,$this->awardService,$this->propertyChgService); $this->propertyChgService->addBagChg(); $event = array( 'ID' => 'Box', 'SUB_ID' => 'open', 'SUB_KEY' => 'open_box', 'cost_info' => array( 'item_id' => $itemMeta['id'], 'item_num' => $itemNum, 'cost_gold' => $costItems ), 'result' => $hashItems, ); LogService::burialPointEvent($event); $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $this->propertyChgService->toDto(), )); } private function sendNotice($itemMeta,$awardNum){ $elements = array(); array_push($elements, array( 'ele_type' => 2, 'color' => '#ffffff', 'lang_key' => 'Marquee_rewards_get_1', 'lang_params' => array(), )); array_push($elements, array( 'ele_type' => 1, //'color' => '#', 'text' => myself()->_getUserInfo(array('name'))['name'], )); array_push($elements, array( 'ele_type' => 2, 'color' => '#ffffff', 'lang_key' => 'Marquee_rewards_get_2', 'lang_params' => array(), )); array_push($elements, array( 'ele_type' => 2, 'color' => '#ff3f3f', 'lang_key' => $itemMeta['name'], 'lang_params' => array(), )); array_push($elements, array( 'ele_type' => 2, 'color' => '#ffffff', 'lang_key' => 'Marquee_rewards_get_3', 'lang_params' => array(), )); if ($itemMeta['id'] == V_ITEM_BCEG){ array_push($elements, array( 'ele_type' => 1, 'color' => '#ff3f3f', 'text' => $awardNum, )); $this->_send($elements); }elseif($itemMeta['id'] == 901004){ $this->_send($elements); }elseif($itemMeta['type'] == \mt\Item::APPOINT_PROP_TYPE && $itemMeta['sub_type'] == \mt\Item::APPOINT_HERO_SUBTYPE){ $this->_send($elements); }elseif($itemMeta['type'] == \mt\Item::APPOINT_PROP_TYPE && $itemMeta['sub_type'] == \mt\Item::APPOINT_CHIP_SUBTYPE && $itemMeta['quality'] > 3){ $this->_send($elements); } } private function _send($elements){ $content = myself()->_callServiceStatic('NoticeService', 'buildCustom', $elements); $loop = 1; $interval = 1; myself()->_callServiceStatic('NoticeService', 'send', $content, $loop, $interval); } public function buyItemS() { $itemId = getReqVal('item_id', 0); $itemNum = getReqVal('item_num', 1); $itemMeta = mt\Item::get($itemId); if (!$itemMeta) { $this->_rspErr(1, "item_id error"); return; } if ($itemNum < 1){ $this->_rspErr(1, "item_num error"); return; } if ($itemMeta['type'] != mt\Item::FUNC_TYPE) { $this->_rspErr(1, "only supported property"); return; } $costItems= array(); if ($itemMeta['gold'] > 0){ array_push($costItems,array( 'item_id' => V_ITEM_GOLD, 'item_num' => $itemMeta['gold'] * $itemNum )); } if ($itemMeta['diamond'] > 0){ array_push($costItems,array( 'item_id' => V_ITEM_DIAMOND, 'item_num' => $itemMeta['diamond'] * $itemNum )); } $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); $items = array( array( 'item_id' => $itemId, 'item_num' => $itemNum ) ); $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 useRecoverDrug($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; } // if (!$heroDb['token_id']){ // $this->_rspErr(1, "this hero is not NFT"); // return; // } $this->_decItems(array( array( 'item_id' => $itemMeta['id'], 'item_num' => 1 ) )); Hero::recoverUsedTime($heroUniId); $this->propertyChgService->addBagChg(); $this->propertyChgService->addHeroChg(); $event = array( 'ID' => 'hero', 'SUB_ID' => 'restore', 'SUB_KEY' => 'hero_restore', 'before' => $heroDb, 'result' => 1, 'after' => Hero::find($heroUniId), ); LogService::burialPointEvent($event); $this->_rspData(array( 'property_chg' => $this->propertyChgService->toDto(), )); } private function useSealDrug($itemDb, $itemMeta, $itemNum, $param1, $param2, $param3) { $userInfo = $this->_getOrmUserInfo(); $errCode = 0; $errMsg = ''; $heroUniId = $param1; $heroDb = Hero::find($heroUniId); if (!$heroDb) { $this->_rspErr(1, "You don't have the hero yet"); return; } // if (!$heroDb['token_id']){ // $this->_rspErr(1, "this hero is not NFT"); // return; // } $this->_decItems(array( array( 'item_id' => $itemMeta['id'], 'item_num' => 1 ) )); Hero::update($heroUniId,array( 'seal_type' => Hero::SEAL_STATE )); if ($userInfo['hero_id'] == $heroUniId){ $heroUniIdNew = 0; $heroId = 0; Hero::randHero($heroUniIdNew,$heroId); User::Update(array( 'hero_id' => $heroUniIdNew )); $this->propertyChgService->addUserChg(); } $this->propertyChgService->addBagChg(); $this->propertyChgService->addHeroChg(); $event = array( 'ID' => 'hero', 'SUB_ID' => 'lock', 'SUB_KEY' => 'hero_lock', 'before' => $heroDb, 'result' => 1, 'after' => Hero::find($heroUniId), ); LogService::burialPointEvent($event); $this->_rspData(array( 'property_chg' => $this->propertyChgService->toDto(), )); } public function syntheticGold(){ return $itemId = getReqVal('item_id', 0); $paramMeta = mt\Parameter::getVal('gold_synthesis_rank',0); if (!$paramMeta){ $this->_rspErr(1,"config error"); return ; } $consume = explode("|",$paramMeta); switch ($itemId){ case V_ITEM_GOLDS :{ $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => $consume[0] ) ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); Bag::addItem(V_ITEM_GOLDS,1); $this->awardService->addItem(V_ITEM_GOLDS, 1); $outcome = array( 'item_id' => V_ITEM_GOLDS, 'item_num' => 1, ); } break; case V_ITEM_GOLDBRICK :{ $costItems = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => $consume[1] ) ); $lackItem = null; if (!$this->_hasEnoughItems($costItems, $lackItem)) { $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } $this->_decItems($costItems); Bag::addItem(V_ITEM_GOLDBRICK,1); $this->awardService->addItem(V_ITEM_GOLDBRICK, 1); $outcome = array( 'item_id' => V_ITEM_GOLDBRICK, 'item_num' => 1, ); } break; default:{ $outcome = array(); $this->_rspErr(1,"param error"); return ; } } $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg(); $propertyChgService->addBagChg(); $event = array( 'ID' => 'gold', 'SUB_ID' => 'synthesis', 'SUB_KEY' => 'gold_synthesis', 'cost_gold' => $costItems, 'outcome' => $outcome, ); LogService::burialPointEvent($event); $this->_rspData(array( 'award' => $this->awardService->toDto(), 'property_chg' => $propertyChgService->toDto(), )); } public function resolveGolds(){ return $item_uniid= getReqVal('item_uniid', 0); $itemDb = Bag::findByUniId($item_uniid); if (!$itemDb || $itemDb['item_num'] <= 0) { $this->_rspErr(1, 'Not enough item'); return; } $itemMeta = mt\Item::get($itemDb['item_id']); if (!$itemMeta || $itemMeta['type'] != \mt\Item::GOLD_SYN) { $this->_rspErr(2, 'config error'); return; } $paramMeta = mt\Parameter::getVal('gold_synthesis_rank',0); if (!$paramMeta){ $this->_rspErr(1,"config error"); return ; } $consume = explode("|",$paramMeta); switch ($itemMeta['id']){ case V_ITEM_GOLDS :{ $items = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => $consume[0] ) ); } break; case V_ITEM_GOLDBRICK :{ $items = array( array( 'item_id' => V_ITEM_GOLD, 'item_num' => $consume[1] ) ); } break; default:{ $this->_rspErr(1,"param error"); return ; } } Bag::decItemByUnIid($item_uniid,1); $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(), )); } }