diff --git a/doc/Chip.py b/doc/Chip.py index 01c6e3af..73582c88 100644 --- a/doc/Chip.py +++ b/doc/Chip.py @@ -44,19 +44,6 @@ class Chip(object): _common.RspHead(), ['!data', [_common.ChipPro()], '芯片信息'] ] - },{ - 'name': 'selectChip', - 'desc': '选择合成材料', - 'group': 'Chip', - 'url': 'webapp/index.php?c=Chip&a=selectChip', - 'params': [ - _common.ReqHead(), - ['unique_id', '', '芯片unique_id参数 例:参数1源芯片 参数2材料芯片'], - ], - 'response': [ - _common.RspHead(), - ['cost', '', '材料芯片的累计价值'] - ] },{ 'name': 'upgradeLevel', 'desc': '芯片升级', @@ -70,7 +57,6 @@ class Chip(object): 'response': [ _common.RspHead(), ['!data', [_common.Chip()], '芯片信息'], - ['state', 0, '1 成功,0 失败'], ['property_chg', _common.PropertyChg(), '属性变更'], ] }, diff --git a/doc/HeroSkill.py b/doc/HeroSkill.py new file mode 100644 index 00000000..9112e61c --- /dev/null +++ b/doc/HeroSkill.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import _common + +class HeroSkill(object): + + def __init__(self): + self.apis = [ + { + 'name': 'getSkillList', + 'desc': '技能列表', + 'group': 'HeroSkill', + 'url': 'webapp/index.php?c=HeroSkill&a=getSkillList', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['data', [], '技能itemId'] + ] + },{ + 'name': 'presetHero', + 'desc': '技能预设', + 'group': 'HeroSkill', + 'url': 'webapp/index.php?c=HeroSkill&a=presetHero', + 'params': [ + _common.ReqHead(), + ['skill_id', '0', '技能id'], + ], + 'response': [ + _common.RspHead(), + ['!data', [['item_id',0,'英雄itemId'],['state',0,'1:设置 0:未设置']], '技能itemId'] + ] + },{ + 'name': 'applyHero', + 'desc': '技能应用', + 'group': 'HeroSkill', + 'url': 'webapp/index.php?c=HeroSkill&a=applyHero', + 'params': [ + _common.ReqHead(), + ['skill_id', '0', '技能itemId'], + ['hero_ids', '0', '英雄itemId'], + ], + 'response': [ + _common.RspHead(), + ] + }, + ] diff --git a/doc/_common.py b/doc/_common.py index fc7d9fe5..14d97927 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -823,7 +823,7 @@ class ChipPro(object): ['inlay_state', 0, '镶嵌状态:0 未镶嵌;1 镶嵌了 ---弃用字段'], ['!rand_attr', [ChipAttr()], '属性'], ['!rand_attr_after', [ChipAttr()], '芯片升级后的属性'], - ['upgrade_cost', '', '芯片升级所需价值'], + ['cost',[],'升级所需gold消耗'] ] class BattleMember(object): diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 54fd1c3e..b6df5415 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -976,4 +976,23 @@ CREATE TABLE `t_chip_page` ( PRIMARY KEY (`idx`), UNIQUE KEY `account_page_id` (`account_id`, `page_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `t_hero_skill` +-- + +DROP TABLE IF EXISTS `t_hero_skill`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_hero_skill` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `hero_uid` int(11) NOT NULL DEFAULT '0' COMMENT 'hero uniid', + `skill_id` int(11) NOT NULL DEFAULT '0' COMMENT '技能 item_id', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `account_hero_skill` (`account_id`, `hero_uid`, `skill_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; \ No newline at end of file diff --git a/webapp/controller/ChipController.class.php b/webapp/controller/ChipController.class.php index a54768c5..d1440c68 100644 --- a/webapp/controller/ChipController.class.php +++ b/webapp/controller/ChipController.class.php @@ -29,9 +29,9 @@ class ChipController extends BaseAuthedController { $chipList = array(); Chip::getChipList(function ($row) use(&$chipList){ - if ($row['inlay_state'] != 1){ +// if ($row['inlay_state'] != 1){ array_push($chipList, Chip::toDto($row)); - } +// } }); $this->_rspData(array( 'data' => $chipList, @@ -80,8 +80,26 @@ class ChipController extends BaseAuthedController )); } $chip['rand_attr_after'] = $rand_attr; - $chip['upgrade_cost']=\services\FormulaService::getChipUpgradeCost($chip['chip_grade']+1); - $this->_rspData(['data'=>$chip]); + $paramMeta = mt\Parameter::getByName('chip_upgrade_cost'); + $gold = 0; + if ($paramMeta){ + $paramValue = explode('|',$paramMeta['param_value']); + switch ($chipDb['chip_grade']){ + case 1: { + $gold = $paramValue[0]; + };break; + case 2: { + $gold = $paramValue[1]; + };break; + } + } + $chip['cost'] = array( + 'item_id' => V_ITEM_GOLD, + 'item_num' => $gold + ); + $this->_rspData(array( + 'data' => $chip + )); } public function selectChip(){ @@ -115,8 +133,8 @@ class ChipController extends BaseAuthedController public function upgradeLevel(){ $idxMain = trim(getReqVal('unique_id_main', 0)); - $idxParam = array_filter(explode(' ',getReqVal('unique_id_param', 0))); - if (! $idxMain || count($idxParam)<=0 ) { + $idxParam = trim(getReqVal('unique_id_param', 0)); + if (!$idxMain || !$idxParam) { $this->_rspErr(1, 'Please enter parameter'); return; } @@ -129,52 +147,56 @@ class ChipController extends BaseAuthedController $this->_rspErr(1,' Level upper limit'); return; } - $upgrade_cost = \services\FormulaService::getChipUpgradeCost($chipDbMain['chip_grade']+1); - if ( $upgrade_cost == 0 ){ - $this->_rspErr(1, 'Error in calculation formula'); + $chipDbParam = Chip::find($idxParam); + if (!$chipDbParam){ + $this->_rspErr(1,"unique_id_param parameter error"); + return; + } + if ($chipDbParam['token_id']) { + $this->_rspErr(1, "Unable to use nft chip"); + return; + } + if ($chipDbParam['state'] == Chip::FREE_STATE) { + $this->_rspErr(1, "Unable to use free chip"); + return; + } + if ($chipDbParam['chip_grade'] != $chipDbMain['chip_grade']){ + $this->_rspErr(1, "Material chip grade does not meet"); + return; + } + $paramMeta = mt\Parameter::getByName('chip_upgrade_cost'); + $gold = 0; + if ($paramMeta){ + $paramValue = explode('|',$paramMeta['param_value']); + switch ($chipDbMain['chip_grade']){ + case 1: { + $gold = $paramValue[0]; + };break; + case 2: { + $gold = $paramValue[1]; + };break; + } + } + $costItems = array( + array( + 'item_id' => V_ITEM_GOLD, + 'item_num' => $gold + ), + ); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); return; } - $cumulative_cost = 0; - foreach ($idxParam as $val){ - $chipDbParam = Chip::find($val); - if (!$chipDbParam){ - $this->_rspErr(1,"unique_id_param:{$val} parameter error"); - return; - } - if ($chipDbParam['token_id']) { - $this->_rspErr(1, "Unable to use nft chip"); - return; - } - if ($chipDbParam['state'] == Chip::FREE_STATE) { - $this->_rspErr(1, "Unable to use free chip"); - return; - } - if ($chipDbParam['chip_grade']>$chipDbMain['chip_grade']){ - $this->_rspErr(1, "The selected material is too high grade"); - return; - } - $cumulative_cost += \services\FormulaService::getChipCumulativeCost($chipDbParam['chip_grade']); - } - //清除材料芯片 - foreach ($idxParam as $idx){ - Chip::update2($idx, - array( - 'account_id' => myself()->_getAccountId() . '!!!', - ) - ); - } + $this->_decItems($costItems); + Chip::update2($idxParam, + array( + 'account_id' => myself()->_getAccountId() . '!!!', + ) + ); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addChip(); - if (round(1,100) > ($cumulative_cost/$upgrade_cost)*100){ - //合成失败 - $this->_rspData([ - 'state' => 0, - 'property_chg' => $propertyChgService->toDto(), - ]); - return ; - } - $rand_attr = emptyReplace(json_decode($chipDbMain['rand_attr'], true), array()); $attrProMeta = \mt\ChipAttr::getAttrPool($chipDbMain); array_push($rand_attr,array( @@ -191,7 +213,6 @@ class ChipController extends BaseAuthedController $chipDbNew = Chip::toDto(Chip::find($idxMain)); $this->_rspData([ 'data'=>$chipDbNew, - 'state' => 1, 'property_chg' => $propertyChgService->toDto(), ]); } diff --git a/webapp/controller/HeroSkillController.class.php b/webapp/controller/HeroSkillController.class.php new file mode 100644 index 00000000..fb70e076 --- /dev/null +++ b/webapp/controller/HeroSkillController.class.php @@ -0,0 +1,111 @@ +_rspData(array( + 'data' => $list, + )); + } + + public function presetHero(){ + $skillId = getReqVal('skill_id',0); + $skillMeta = \mt\Skill::get($skillId); + if (! $skillMeta){ + $this->_rspErr(1,'skill_id parameter error'); + return ; + } + $heroList = array(); + Hero::getHeroList(function ($row) use(&$heroList) { + array_push($heroList, $row); + }); + $list = array_unique(array_column($heroList,'hero_id')); + $data = array(); + if (count($list) > 0){ + foreach ($list as $value){ + $data[$value] = array( + 'item_id' => $value, + 'state' => 0 + ); + } + } + + $rows = SqlHelper::ormSelect( + $this->_getSelfMysql(), + 't_hero_skill', + array( + 'account_id' => $this->_getAccountId(), + 'skill_id' => $skillId, + ) + ); + if ($rows){ + foreach ($rows as $row){ + $heroDb = Hero::find($row['hero_uid']); + $data[$heroDb['hero_id']]['state'] = 1; + } + } + $this->_rspData(array( + 'data' => $data, + )); + } + + public function applyHero(){ + $skillId = getReqVal('skill_id',0); + $heroIds = getReqVal('hero_ids',''); + $heroIdArr = explode('|',$heroIds); + if (!$skillId || count($heroIdArr)<0){ + $this->_rspErr(1,' parameter error'); + return ; + } + $skillMeta = \mt\Skill::get($skillId); + if (! $skillMeta){ + $this->_rspErr(1,'skill_id parameter error'); + return ; + } + foreach ($heroIdArr as $heroId){ + $heroMeta = \mt\Hero::get($heroId); + if (! $heroMeta){ + $this->_rspErr(1,'hero_id parameter error'); + return ; + } + } + foreach ($heroIdArr as $heroId){ + $heroList = Hero::getHeroByItemId($heroId); + if ($heroList){ + foreach ($heroList as $hero){ + SqlHelper::upsert + ($this->_getSelfMysql(), + 't_hero_skill', + array( + 'account_id' => $this->_getAccountId(), + 'hero_uid' => $hero['idx'], + ), + array( + 'skill_id' => $skillId, + 'modifytime' => $this->_getNowTime(), + ), + array( + 'account_id' => $this->_getAccountId(), + 'hero_uid' => $hero['idx'], + 'skill_id' => $skillId, + 'createtime' => $this->_getNowTime(), + 'modifytime' => $this->_getNowTime(), + + ) + ); + } + } + } + $this->_rspOk(); + } +} \ No newline at end of file diff --git a/webapp/models/ChipPage.php b/webapp/models/ChipPage.php index 401bb5d5..731e72d3 100644 --- a/webapp/models/ChipPage.php +++ b/webapp/models/ChipPage.php @@ -65,9 +65,11 @@ class ChipPage extends BaseModel $newRow = self::find($row['page_id']); $newData = emptyReplace(json_decode($newRow['data'], true), array()); $attrs = array(); - foreach ($newData as $value){ + foreach ($newData as $key=>$value){ + $newData[$key]['item_id'] = 0; if ($value['chip_id']){ $chipDb = Chip::find($value['chip_id']); + $newData[$key]['item_id'] = $chipDb['item_id']; $chipAttrMeta = ChipAttr::getAttrByItemId($chipDb['item_id']); $rand_attr = emptyReplace(json_decode($chipDb['rand_attr'], true), array()); array_push($attrs,array( diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index fce7fd33..1fac48ca 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -812,4 +812,14 @@ class Hero extends BaseModel { } } + public static function getHeroByItemId($itemId){ + $hero = array(); + self::getHeroList(function ($row) use (&$hero,$itemId) { + if ($row['hero_id'] == $itemId) { + array_push($hero,$row); + } + }); + return $hero; + } + } diff --git a/webapp/mt/Skill.php b/webapp/mt/Skill.php index 30fe2a37..3a77df1f 100644 --- a/webapp/mt/Skill.php +++ b/webapp/mt/Skill.php @@ -11,6 +11,17 @@ class Skill { return getXVal(self::getMetaList(), $id); } + public static function getPresetSkill() + { + $list = array(); + foreach (self::getMetaList() as $value){ + if ($value['skill_id'] < 20000){ + array_push($list,$value); + } + } + return $list; + } + protected static function getMetaList() { if (!self::$metaList) {