diff --git a/doc/Chip.py b/doc/Chip.py index aa97e9ca..672a96ee 100644 --- a/doc/Chip.py +++ b/doc/Chip.py @@ -53,12 +53,13 @@ class Chip(object): 'url': 'webapp/index.php?c=Chip&a=inlayChip', 'params': [ _common.ReqHead(), - ['hero_id', '', '英雄idx'], + ['type', '', '1 英雄;2 枪械'], + ['unique_id', '', '英雄或枪械的唯一id'], ['token_id', '', '芯片token id'], ], 'response': [ _common.RspHead(), - ['!data', [_common.Hero()], '英雄加成信息'] + ['!data', [_common.Hero()], '英雄或枪械加成信息,用英雄举例'] ] },{ 'name': 'demountChip', @@ -67,12 +68,13 @@ class Chip(object): 'url': 'webapp/index.php?c=Chip&a=demountChip', 'params': [ _common.ReqHead(), - ['hero_id', '', '英雄idx'], + ['type', '', '1 英雄;2 枪械'], + ['unique_id', '', '英雄或枪械的唯一id'], ['token_id', '', '芯片token id'], ], 'response': [ _common.RspHead(), - ['!data', [_common.Hero()], '英雄加成信息'] + ['!data', [_common.Hero()], '英雄或枪械加成信息,用英雄举例'] ] },{ 'name': 'replaceChip', @@ -81,13 +83,14 @@ class Chip(object): 'url': 'webapp/index.php?c=Chip&a=replaceChip', 'params': [ _common.ReqHead(), - ['hero_id', '', '英雄idx'], + ['type', '', '1 英雄;2 枪械'], + ['unique_id', '', '英雄或枪械的唯一id'], ['token_id_new', '', '新芯片token id'], ['token_id_old', '', '被替换的芯片token id'], ], 'response': [ _common.RspHead(), - ['!data', [_common.Hero()], '英雄加成信息'] + ['!data', [_common.Hero()], '英雄或枪械加成信息,用英雄举例'] ] },{ 'name': 'aKeyInlayChip', diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 44948963..727fc0c5 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -265,6 +265,7 @@ CREATE TABLE `t_gun` ( `last_pve_get_ceg_time` bigint NOT NULL DEFAULT '0' COMMENT '最后pve获取金币的时间', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + `chip_ids` varchar(100) NOT NULL DEFAULT '0' COMMENT '已镶嵌的芯片idx组', PRIMARY KEY (`idx`), UNIQUE KEY `token_id` (`token_id`), KEY `account_id` (`account_id`) diff --git a/webapp/controller/ChipController.class.php b/webapp/controller/ChipController.class.php index 89468983..3a5e1aec 100644 --- a/webapp/controller/ChipController.class.php +++ b/webapp/controller/ChipController.class.php @@ -2,12 +2,14 @@ require_once('models/Chip.php'); require_once('models/Hero.php'); +require_once('models/Gun.php'); require_once('mt/ChipAttr.php'); require_once('mt/AttrHelper.php'); require_once('services/FormulaService.php'); use models\Chip; use models\Hero; +use models\Gun; use services\NftService; use phpcommon\SqlHelper; @@ -23,7 +25,9 @@ class ChipController extends BaseAuthedController $chipList = Chip::all($type); $chipDtoList = array(); foreach ($chipList as $item) { - array_push($chipDtoList, Chip::toDto($item)); + if ($item['inlay_state'] == 0){ + array_push($chipDtoList, Chip::toDto($item)); + } } $this->_rspData(array( 'data' => $chipDtoList, @@ -40,7 +44,9 @@ class ChipController extends BaseAuthedController $chipList = Chip::all($type); $chipDtoList = array(); foreach ($chipList as $item) { - array_push($chipDtoList, Chip::toDto($item)); + if ($item['inlay_state'] == 0){ + array_push($chipDtoList, Chip::toDto($item)); + } } $data = $this->_orderByChip($chipDtoList,$order); $this->_rspData(array( @@ -57,7 +63,7 @@ class ChipController extends BaseAuthedController $chipList = Chip::all($type); $chipDtoList = array(); foreach ($chipList as $item) { - if ($item['supper_state']==0 && $item['inlay_state']==0 && $item['state']==0){ + if ($item['supper_state']==0 && $item['inlay_state']==0){ array_push($chipDtoList, Chip::toDto($item)); } } @@ -67,73 +73,110 @@ class ChipController extends BaseAuthedController } public function inlayChip(){ - $hero_id = trim(getReqVal('hero_id', 0)); + $type = trim(getReqVal('type', 0)); + $unique_id = trim(getReqVal('unique_id', 0)); $token_id = trim(getReqVal('token_id', 0)); - if (! $token_id || ! $hero_id) { + if (!$type || ! $token_id || ! $unique_id) { $this->_rspErr(1, 'Please enter instructions'); return; } - $this->_doInlay($hero_id,$token_id); - $hero = $this->_inLayNewAttr($hero_id); - $chip_core = $this->_chipCore($hero_id); - $hero['chip_core'] = $chip_core; - $this->_rspData(['data'=>$hero]); + if ($type == 1){ + $this->_doInlayHero($unique_id,$token_id); + $hero = $this->_inLayNewAttr($unique_id); + $chip_core = $this->_chipCore($unique_id,$type); + $hero['chip_core'] = $chip_core; + $this->_rspData(['data'=>$hero]); + }else{ + $this->_doInlayGun($unique_id,$token_id); + $gun = $this->_inLayNewAttrGun($unique_id); + $chip_core = $this->_chipCore($unique_id,$type); + $gun['chip_core'] = $chip_core; + $this->_rspData(['data'=>$gun]); + } + } public function demountChip(){ - $hero_id = trim(getReqVal('hero_id', 0)); + $type = trim(getReqVal('type', 0)); + $unique_id = trim(getReqVal('unique_id', 0)); $token_id = trim(getReqVal('token_id', 0)); - if (! $token_id || ! $hero_id) { + if (!$type || ! $token_id || ! $unique_id) { $this->_rspErr(1, 'Please enter instructions'); return; } - $this->_doDemount($hero_id,$token_id); - $hero = $this->_inLayNewAttr($hero_id); - $chip_core = $this->_chipCore($hero_id); - $hero['chip_core'] = $chip_core; - $this->_rspData(['data'=>$hero]); + if ($type == 1){ + $this->_doDemount($unique_id,$token_id); + $hero = $this->_inLayNewAttr($unique_id); + $chip_core = $this->_chipCore($unique_id,$type); + $hero['chip_core'] = $chip_core; + $this->_rspData(['data'=>$hero]); + }else{ + $this->_doDemountGun($unique_id,$token_id); + $gun = $this->_inLayNewAttrGun($unique_id); + $chip_core = $this->_chipCore($unique_id,$type); + $gun['chip_core'] = $chip_core; + $this->_rspData(['data'=>$gun]); + } + } public function replaceChip(){ - $hero_id = trim(getReqVal('hero_id', 0)); + $type = trim(getReqVal('type', 0)); + $unique_id = trim(getReqVal('unique_id', 0)); $token_id_new = trim(getReqVal('token_id_new', 0)); $token_id_old = trim(getReqVal('token_id_old', 0)); - if (! $token_id_new ||! $token_id_old || ! $hero_id) { + if (! $token_id_new ||! $token_id_old || ! $unique_id || !$type) { $this->_rspErr(1, 'Please enter instructions'); return; } - $this->_doDemount($hero_id,$token_id_old); - $this->_doInlay($hero_id,$token_id_new); - $hero = $this->_inLayNewAttr($hero_id); - $chip_core = $this->_chipCore($hero_id); - $hero['chip_core'] = $chip_core; - $this->_rspData(['data'=>$hero]); + if ($type == 1){ + $this->_doDemount($unique_id,$token_id_old); + $this->_doInlayHero($unique_id,$token_id_new); + $hero = $this->_inLayNewAttr($unique_id); + $chip_core = $this->_chipCore($unique_id,$type); + $hero['chip_core'] = $chip_core; + $this->_rspData(['data'=>$hero]); + }else{ + $this->_doDemountGun($unique_id,$token_id_old); + $this->_doInlayGun($unique_id,$token_id_new); + $gun = $this->_inLayNewAttrGun($unique_id); + $chip_core = $this->_chipCore($unique_id,$type); + $gun['chip_core'] = $chip_core; + $this->_rspData(['data'=>$gun]); + } + } public function aKeyInlayChip(){ - $hero_id = trim(getReqVal('hero_id', 0)); - if ( ! $hero_id) { + $type = trim(getReqVal('type', 0)); + $unique_id = trim(getReqVal('unique_id', 0)); + if ( ! $type || ! $unique_id) { $this->_rspErr(1, 'Please enter instructions'); return; } - $hero = Hero::find($hero_id); - if (! $hero){ - $this->_rspErr(1, 'Not enough hero'); + if ($type == 1){ + $hero_or_gun = Hero::find($unique_id); + }else{ + $hero_or_gun = Gun::find($unique_id); + } + + if (! $hero_or_gun){ + $this->_rspErr(1, 'Not enough hero or gun'); return; } $limit = 0; - if (! $hero['chip_ids'] ){ + if (! $hero_or_gun['chip_ids'] ){ $limit = 4; } - if ($hero['chip_ids'] && !strpos($hero['chip_ids'], '|')){ + if ($hero_or_gun['chip_ids'] && !strpos($hero_or_gun['chip_ids'], '|')){ $limit = 3; } - if ($hero['chip_ids'] && strpos($hero['chip_ids'], '|')){ - $chipIdsArr = explode('|',$hero['chip_ids']); + if ($hero_or_gun['chip_ids'] && strpos($hero_or_gun['chip_ids'], '|')){ + $chipIdsArr = explode('|',$hero_or_gun['chip_ids']); $limit = 4-count($chipIdsArr); } - $chipList = Chip::all(1); + $chipList = Chip::all($type); if (! $chipList){ $this->_rspErr(1, 'Not enough chip'); return; @@ -150,14 +193,23 @@ class ChipController extends BaseAuthedController $this->_rspErr(1, 'The chip slot is full'); return; } - foreach ($res as $val){ - $this->_doInlay($hero_id,$val['token_id']); + if ($type == 1){ + foreach ($res as $val){ + $this->_doInlayHero($unique_id,$val['token_id']); + } + $hero_new = $this->_inLayNewAttr($unique_id); + $chip_core = $this->_chipCore($unique_id,$type); + $hero_new['chip_core'] = $chip_core; + $this->_rspData(['data'=>$hero_new]); + }else{ + foreach ($res as $val){ + $this->_doInlayGun($unique_id,$val['token_id']); + } + $gun_new = $this->_inLayNewAttrGun($unique_id); + $chip_core = $this->_chipCore($unique_id,$type); + $gun_new['chip_core'] = $chip_core; + $this->_rspData(['data'=>$gun_new]); } - $hero_new = $this->_inLayNewAttr($hero_id); - $chip_core = $this->_chipCore($hero_id); - $hero_new['chip_core'] = $chip_core; - $this->_rspData(['data'=>$hero_new]); - } public function beforeSynthetic(){ @@ -172,7 +224,7 @@ class ChipController extends BaseAuthedController return; } if ($chip['chip_grade'] == 15){ - $this->_rspErr(1, "Chip level upper limit"); + $this->_rspErr(1, "Chip Lv upper limit"); return; } $chip = Chip::toDto($chip); @@ -246,7 +298,7 @@ class ChipController extends BaseAuthedController //合成成功 $this->_upgraded($chip_main); $chip_new = Chip::toDto(Chip::getChipByTokenId($token_id_main)); - $chip_new['strength_temporary'] = \services\FormulaService::getChipPhysicalStrengthValue($chip_new['chip_grade'],$chip_new['lucky_final']+$chip_new['lucky_temporary']); + $chip_new['strength_temporary'] = \services\FormulaService::getChipPhysicalStrengthValue($chip_new['chip_grade'],$chip_new['lucky_temporary']); $this->_rspData(['data'=>$chip_new]); } } @@ -259,9 +311,9 @@ class ChipController extends BaseAuthedController } $chip = Chip::getChipByTokenId($token_id); $fieldsKv = [ - 'lucky_final'=>$chip['lucky_final']+$chip['lucky_temporary'], + 'lucky_final'=>$chip['lucky_temporary'], 'lucky_temporary'=>0, - 'strength' => \services\FormulaService::getChipPhysicalStrengthValue($chip['chip_grade'],$chip['lucky_final']+$chip['lucky_temporary']) + 'strength' => \services\FormulaService::getChipPhysicalStrengthValue($chip['chip_grade'],$chip['lucky_temporary']) ]; Chip::update($chip['token_id'],$fieldsKv); $this->_rspOk(); @@ -304,7 +356,7 @@ class ChipController extends BaseAuthedController $chip = Chip::getChipByTokenId($token_id); $upgrade_cost =\services\FormulaService::getChipUpgradeCost($chip['chip_grade']+1); //芯片升星价值 - $chipList = Chip::all(1); + $chipList = Chip::all($chip['chip_type']); $chipDtoList = array(); foreach ($chipList as $item) { if ($item['supper_state']==0 && $item['inlay_state']==0 && $item['state']==0 && $item['token_id'] != $token_id && $item['chip_grade'] <= $chip['chip_grade']){ @@ -364,14 +416,7 @@ class ChipController extends BaseAuthedController } - - - public function test(){ - $chip = Chip::getChipByTokenId(1660629357); - print_r($chip); - } - - private function _doInlay($hero_id,$token_id){ + private function _doInlayHero($hero_id,$token_id){ $chip = Chip::getChipByTokenId($token_id); $hero = Hero::find($hero_id); if (! $chip || ! $hero){ @@ -395,9 +440,33 @@ class ChipController extends BaseAuthedController Chip::updateChipInlayState($token_id,1); } - private function _doDemount($hero_id,$token_id){ + private function _doInlayGun($gun_id,$token_id){ $chip = Chip::getChipByTokenId($token_id); - $hero = Hero::find($hero_id); + $gun = Gun::find($gun_id); + if (! $chip || ! $gun){ + $this->_rspErr(1, 'Not enough chip or gun'); + return; + } + if (! $gun['chip_ids']){ + $fieldsKv = ['chip_ids'=>$chip['idx']]; + } + if ($gun['chip_ids'] && !strpos($gun['chip_ids'], '|')){ + $chipIdsArr = [$gun['chip_ids']]; + array_push($chipIdsArr,$chip['idx']); + $fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)]; + } + if ($gun['chip_ids'] && strpos($gun['chip_ids'], '|')){ + $chipIdsArr = explode('|',$gun['chip_ids']); + array_push($chipIdsArr,$chip['idx']); + $fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)]; + } + Gun::update($gun_id,$fieldsKv); + Chip::updateChipInlayState($token_id,1); + } + + private function _doDemount($unique_id,$token_id){ + $chip = Chip::getChipByTokenId($token_id); + $hero = Hero::find($unique_id); if (! $chip || ! $hero){ $this->_rspErr(1, 'Not enough chip or hero'); return; @@ -406,9 +475,23 @@ class ChipController extends BaseAuthedController $k = array_search($chip['idx'],$chipIdsArr); unset($chipIdsArr[$k]); $fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)]; - Hero::update($hero_id,$fieldsKv); + Hero::update($unique_id,$fieldsKv); Chip::updateChipInlayState($token_id,0); + } + private function _doDemountGun($unique_id,$token_id){ + $chip = Chip::getChipByTokenId($token_id); + $gun = Gun::find($unique_id); + if (! $chip || ! $gun){ + $this->_rspErr(1, 'Not enough chip or gun'); + return; + } + $chipIdsArr = explode('|',$gun['chip_ids']); + $k = array_search($chip['idx'],$chipIdsArr); + unset($chipIdsArr[$k]); + $fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)]; + Gun::update($unique_id,$fieldsKv); + Chip::updateChipInlayState($token_id,0); } private function _inLayNewAttr($hero_id){ @@ -442,9 +525,45 @@ class ChipController extends BaseAuthedController return $hero; } - private function _chipCore($hero_id){ + private function _inLayNewAttrGun($gun_id){ + $gun = Gun::find($gun_id); + if (! $gun){ + $this->_rspErr(1, 'Not enough gun'); + return; + } + $chipAttr = []; + if (! $gun['chip_ids'] ){ + return $gun; + } + if ($gun['chip_ids'] && !strpos($gun['chip_ids'], '|')){ + $chip =Chip::toDto(Chip::getChipByIdx($gun['chip_ids'])); + foreach ($chip['rand_attr'] as $val){ + array_push($chipAttr,$val); + } + } + if ($gun['chip_ids'] && strpos($gun['chip_ids'], '|')){ + $chipIdsArr = explode('|',$gun['chip_ids']); + foreach ($chipIdsArr as $val){ + $chip = Chip::toDto(Chip::getChipByIdx($val)); + foreach ($chip['rand_attr'] as $v){ + array_push($chipAttr,$v); + } + } + } + $gun_attr = emptyReplace(json_decode($gun['rand_attr'], true), array()); + \mt\AttrHelper::mergeAttr($gun_attr,$chipAttr); + $gun['rand_attr'] = $gun_attr; + return $gun; + } + + private function _chipCore($unique_id,$type){ $chipCore = []; - $hero = Hero::find($hero_id); + if ($type==1){ + $hero = Hero::find($unique_id); + }else{ + $hero = Gun::find($unique_id); + } + if ($hero['chip_ids'] && strpos($hero['chip_ids'], '|')){ $chipIdsArr = explode('|',$hero['chip_ids']); if (count($chipIdsArr) == 4){ @@ -457,7 +576,7 @@ class ChipController extends BaseAuthedController } $chipCoreList = getMetaTable('chipCore@chipCore.php'); foreach ($chipCoreList as $val){ - if ($val['chip_core_type']==1 && $val['chip_core_lv']<=$min){ + if ($val['chip_core_type']==$type && $val['chip_core_lv']<=$min){ array_push($chipCore,$val); } } @@ -521,9 +640,8 @@ class ChipController extends BaseAuthedController if ($new_grade == 3 || $new_grade == 5){ Chip::updateRandAttr($chip); } - $lucky = \services\FormulaService::getChipLuckyValue($chip['chip_grade']); - $lucky_pro = \services\FormulaService::getChipLuckyValue($new_grade); - Chip::update($chip['token_id'],['lucky_temporary'=>$lucky_pro-$lucky, 'chip_grade'=>$new_grade]); + $lucky = ltrim(\services\FormulaService::getChipLuckyValue($new_grade),'-') ; + Chip::update($chip['token_id'],['lucky_temporary'=>$lucky, 'chip_grade'=>$new_grade]); } private function _bestFun($upgrade_cost,$chip_param,$chip_param_out){