diff --git a/doc/Chip.py b/doc/Chip.py index da22277a..6ec5af66 100644 --- a/doc/Chip.py +++ b/doc/Chip.py @@ -31,6 +31,19 @@ class Chip(object): _common.RspHead(), ['!data', [_common.Chip()], '芯片信息'] ] + },{ + 'name': 'upgradeAttrChange', + 'desc': '芯片升级属性变化', + 'group': 'Chip', + 'url': 'webapp/index.php?c=Chip&a=upgradeAttrChange', + 'params': [ + _common.ReqHead(), + ['chip_uniid', '', '芯片唯一id'], + ], + 'response': [ + _common.RspHead(), + ['!data', [AttrChange()], '属性变化信息'] + ] },{ 'name': 'upgradeQuality', 'desc': '芯片升阶', @@ -79,3 +92,12 @@ class Chip(object): ] }, ] + +class AttrChange(object): + + def __init__(self): + self.fields = [ + ['attr_id', 0, '属性id'], + ['min_val', 0, '最小属性值'], + ['max_val', 0, '最大属性值'], + ] \ No newline at end of file diff --git a/doc/ChipPage.py b/doc/ChipPage.py index c260db47..7f9efba9 100644 --- a/doc/ChipPage.py +++ b/doc/ChipPage.py @@ -19,6 +19,20 @@ class ChipPage(object): _common.RspHead(), ['!data', [_common.ChipPage()], '页信息'] ] + },{ + 'name': 'unlockSlot', + 'desc': '解锁卡槽', + 'group': 'ChipPage', + 'url': 'webapp/index.php?c=ChipPage&a=unlockSlot', + 'params': [ + _common.ReqHead(), + ['hero_unnid', '', '英雄唯一id'], + ['slot_id', '', '卡槽id'], + ], + 'response': [ + _common.RspHead(), + ['property_chg', [_common.PropertyChg()], '信息变更'] + ] },{ 'name': 'useChip', 'desc': '使用芯片(镶嵌)', @@ -35,10 +49,10 @@ class ChipPage(object): ['!data', [_common.ChipPage()], '页信息'] ] },{ - 'name': 'removeChipOne', + 'name': 'removeChip', 'desc': '芯片移除', 'group': 'ChipPage', - 'url': 'webapp/index.php?c=ChipPage&a=removeChipOne', + 'url': 'webapp/index.php?c=ChipPage&a=removeChip', 'params': [ _common.ReqHead(), ['hero_unnid', '', '英雄唯一id'], @@ -46,20 +60,8 @@ class ChipPage(object): ], 'response': [ _common.RspHead(), - ['!data', [_common.ChipPage()], '页信息'] - ] - },{ - 'name': 'removeChipAll', - 'desc': '芯片移除(一键移除)', - 'group': 'ChipPage', - 'url': 'webapp/index.php?c=ChipPage&a=removeChipAll', - 'params': [ - _common.ReqHead(), - ['hero_unnid', '', '英雄唯一id'], - ], - 'response': [ - _common.RspHead(), - ['!data', [_common.ChipPage()], '页信息'] + ['!data', [_common.ChipPage()], '页信息'], + ['property_chg', [_common.PropertyChg()], '信息变更'] ] }, ] diff --git a/doc/_common.py b/doc/_common.py index da0dac52..dfcdcee8 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -1110,6 +1110,7 @@ class ChipPageSlot(object): def __init__(self): self.fields = [ ['slot_id', 0, '卡槽id'], + ['slot_type', 0, '卡槽类型(和芯片类型对应)1 攻击;2 防御;3 辅助'], ['state', 0, '0:未解锁 1:已解锁'], ['chip_id', '', '芯片唯一id'], ['item_id', '', '芯片itemId'], diff --git a/webapp/controller/ChipController.class.php b/webapp/controller/ChipController.class.php index 20099cb1..9eac5645 100644 --- a/webapp/controller/ChipController.class.php +++ b/webapp/controller/ChipController.class.php @@ -67,6 +67,53 @@ class ChipController extends BaseAuthedController )); } + public function upgradeAttrChange(){ + $chipUniId = getReqVal('chip_uniid', 0); + $chipDb = Chip::find($chipUniId); + if (!$chipDb) { + $this->_rspErr(100, 'param chip_uniid error '); + return; + } + if ($chipDb['quality'] == Chip::CHIP_QUALITY_MAX){ + $this->_rspErr(5, "It's already the highest level"); + return; + } + $chipAttrMeta = \mt\ChipAttribute::get($chipDb['item_id']); + if (!$chipAttrMeta){ + $this->_rspErr(100, 'mt error '); + return; + } + $randMetas = mt\BattleRandAttribute::getByInvoke($chipAttrMeta['battleAttribute'],$chipDb['quality'] + 1); + $attrList = array(); + foreach ($randMetas as $meta){ + $strs = explode('|', $meta['attributeRange']); + foreach ($strs as $str) { + $attrStr = explode(':', $str); + if (isset($attrList[$attrStr[0]])){ + if ( $attrList[$attrStr[0]][0] > $attrStr[1]){ + $attrList[$attrStr[0]][0] = $attrStr[1]; + } + if ($attrList[$attrStr[0]][1] < $attrStr[2]){ + $attrList[$attrStr[0]][1] = $attrStr[2]; + } + }else{ + $attrList[$attrStr[0]] = array($attrStr[1],$attrStr[2]); + } + } + } + $data = array(); + foreach ($attrList as $key => $value){ + array_push($data,array( + 'attr_id' => $key, + 'min_val' => $value[0], + 'max_val' => $value[1], + )); + } + $this->_rspData(array( + 'data' => $data, + )); + } + public function upgradeQuality(){ $chipUniId = getReqVal('chip_uniid', 0); $consumeUniIds = getReqVal('consume_uniids',0); diff --git a/webapp/controller/ChipPageController.class.php b/webapp/controller/ChipPageController.class.php index d314f274..6eaf9f6d 100644 --- a/webapp/controller/ChipPageController.class.php +++ b/webapp/controller/ChipPageController.class.php @@ -3,11 +3,14 @@ require_once('models/Chip.php'); require_once('models/ChipPage.php'); require_once('models/Hero.php'); +require_once('mt/EconomyAttribute.php'); require_once('services/ChipPageService.php'); +require_once('services/PropertyChgService.php'); use models\Chip; use models\ChipPage; use models\Hero; +use mt\EconomyAttribute; use services\ChipPageService; use phpcommon\SqlHelper; @@ -26,15 +29,69 @@ class ChipPageController extends BaseAuthedController ChipPage::addChipPage($heroUid); $chipPageDb = ChipPage::find($heroUid); } - $chipPageService = new services\ChipPageService(); - $chipPageService->refreshSlotState($chipPageDb,$heroDb); - $chipPageDb = ChipPage::find($heroUid); $chipPageDto = ChipPage::toDtoInfo($chipPageDb); $this->_rspData(array( 'data' => $chipPageDto, )); } + public function unlockSlot(){ + $heroUid = getReqVal('hero_unnid',0); + $slotId = getReqVal('slot_id',0); + if ($slotId < 1 || $slotId > ChipPage::MAX_CHIP_SLOT_NUM){ + $this->_rspErr(1,'param slot_id error'); + return ; + } + $heroDb = Hero::find($heroUid); + if (!$heroDb){ + $this->_rspErr(1,'param error'); + return ; + } + $heroMeta = \mt\Hero::get($heroDb['hero_id']); + $economyAttrMeta = EconomyAttribute::findByGrade($heroMeta['economyAttribute'],$heroDb['quality']); + if (!$economyAttrMeta){ + $this->_rspErr(1,'mt error'); + return ; + } + $chipSlot = explode("|",$economyAttrMeta['chipSlot']); + $chipPageDb = ChipPage::find($heroUid); + $pageHashData = ChipPage::dataToHash($chipPageDb); + $slotInfo = $pageHashData[$slotId]; + if ($slotInfo['state'] == 1){ + $this->_rspErr(1,'The slot has been unlocked'); + return ; + } + $unlockCount = ChipPage::getUnlockCount($chipPageDb,$slotInfo['slot_type']); + if ($chipSlot[$slotInfo['slot_type']-1] <= $unlockCount){ + $this->_rspErr(1,'The unlock condition was not met'); + return ; + } + $totalUnlockCount = ChipPage::getUnlockCount($chipPageDb); + $priceArr = explode('|',\mt\Parameter::getVal('hero_solt_unlock_price',0)); + if (! isset($priceArr[$totalUnlockCount])){ + $this->_rspErr(1,'mt No price found'); + return ; + } + $costItems = array( + array( + 'item_id' => V_ITEM_GOLD, + 'item_num' => $priceArr[$totalUnlockCount] + ) + ); + $propertyChgService = new services\PropertyChgService(); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); + return; + } + $this->_decItems($costItems); + $propertyChgService->addUserChg(); + ChipPage::unlockSlot($chipPageDb,$slotId); + $this->_rspData(array( + 'property_chg' => $propertyChgService->toDto(), + )); + } + public function useChip(){ $hero_unnid = getReqVal('hero_unnid',0); $slotId = getReqVal('slot_id',0); @@ -53,12 +110,14 @@ class ChipPageController extends BaseAuthedController $this->_rspErr(1,'page parameter error'); return ; } - if ($slotId > ChipPageService::MAX_CHIP_SLOT_NUM || $slotId < 0 ){ + if ($slotId > ChipPage::MAX_CHIP_SLOT_NUM || $slotId < 0 ){ $this->_rspErr(1,'No card slot exists'); return ; } $data = emptyReplace(json_decode($chipPageDb['data'], true), array()); - if ( $data[$slotId-1]['state'] != 1){ + $pageHashData = ChipPage::dataToHash($chipPageDb); + $slotInfo = $pageHashData[$slotId]; + if ( $slotInfo['state'] != 1){ $this->_rspErr(1,'Unlocked state'); return ; } @@ -72,23 +131,14 @@ class ChipPageController extends BaseAuthedController $this->_rspErr(1, "The used chip"); return; } - switch ($slotId%3){ - case 1 : $type = 1;break; - case 2 : $type = 2;break; - case 0 : $type = 3;break; - default:$type = 0; - } - - if ($chipDb['chip_type'] != $type){ + if ($chipDb['chip_type'] != $slotInfo['slot_type']){ $this->_rspErr(1, "Type mismatch"); return; } - if ( $data[$slotId-1]['chip_id'] ){ - - Chip::updateInlayState($data[$slotId-1]['chip_id'],0); + if ( $slotInfo['chip_id'] ){ + Chip::updateInlayState($slotInfo['chip_id'],0); } $data[$slotId-1]['chip_id'] = $chip_unnid; - Chip::updateInlayState($chip_unnid,1); ChipPage::update($hero_unnid,array( 'data' => json_encode($data) @@ -100,7 +150,7 @@ class ChipPageController extends BaseAuthedController )); } - public function removeChipOne(){ + public function removeChip(){ $hero_unnid = getReqVal('hero_unnid',0); $slotId = getReqVal('slot_id',0); if (!$hero_unnid || !$slotId){ @@ -117,6 +167,25 @@ class ChipPageController extends BaseAuthedController $this->_rspErr(1,'page parameter error'); return ; } + $price = \mt\Parameter::getVal('hero_chip_remove_price',0); + if ($price == 0){ + $this->_rspErr(1,'mt price error'); + return ; + } + $costItems = array( + array( + 'item_id' => V_ITEM_GOLD, + 'item_num' => $price + ) + ); + $propertyChgService = new services\PropertyChgService(); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); + return; + } + $this->_decItems($costItems); + $propertyChgService->addUserChg(); $data = emptyReplace(json_decode($chipPageDb['data'], true), array()); foreach ($data as &$value){ if ($value['slot_id'] == $slotId){ @@ -131,10 +200,12 @@ class ChipPageController extends BaseAuthedController $chipPageDto = ChipPage::toDtoInfo($newChipPageDb); $this->_rspData(array( 'data' => $chipPageDto, + 'property_chg' => $propertyChgService->toDto(), )); } public function removeChipAll(){ + return $hero_unnid = getReqVal('hero_unnid',0); $heroDb = Hero::find($hero_unnid); if (!$heroDb){ diff --git a/webapp/models/ChipPage.php b/webapp/models/ChipPage.php index 9786e749..fff563f2 100644 --- a/webapp/models/ChipPage.php +++ b/webapp/models/ChipPage.php @@ -10,6 +10,7 @@ use services\ChipPageService; class ChipPage extends BaseModel { + const MAX_CHIP_SLOT_NUM = 9; public static function find($hero_unnid){ $row = SqlHelper::ormSelectOne( @@ -22,6 +23,47 @@ class ChipPage extends BaseModel return $row; } + public static function dataToHash($row){ + $dataHash = array(); + $data = emptyReplace(json_decode($row['data'], true), array()); + array_walk($data, function ($row) use(&$dataHash) { + $dataHash[$row['slot_id']] = $row; + }); + return $dataHash; + } + + public static function getUnlockCount($row , $slotType = 0){ + $data = emptyReplace(json_decode($row['data'], true), array()); + $count = 0; + if ($slotType == 0){ + foreach ($data as $value){ + if($value['state'] == 1){ + $count += 1; + } + } + }else{ + foreach ($data as $value){ + if($slotType == $value['slot_type'] && $value['state'] == 1){ + $count += 1; + } + } + } + + return $count; + } + + public static function unlockSlot($row,$slot){ + $data = emptyReplace(json_decode($row['data'], true), array()); + foreach ($data as $key=>$value){ + if ($value['slot_id'] == $slot){ + $data[$key]['state'] = 1; + } + } + self::update($row['hero_uniid'],array( + 'data' => json_encode($data) + )); + } + public static function toDtoInfo($row){ $data = emptyReplace(json_decode($row['data'], true), array()); @@ -119,11 +161,19 @@ class ChipPage extends BaseModel public static function addChipPage($hero_uniid){ $data = array(); - for ($i=1;$i <= ChipPageService::MAX_CHIP_SLOT_NUM;$i++){ + for ($i=1;$i <= self::MAX_CHIP_SLOT_NUM;$i++){ + if ( $i<=3 ){ + $slotType = 1; + }elseif($i>3 && $i <= 6){ + $slotType = 2; + }else{ + $slotType = 3; + } array_push( $data, array( 'slot_id'=>$i, + 'slot_type'=>$slotType, 'state'=>0, 'chip_id'=>0, ) diff --git a/webapp/mt/BattleRandAttribute.php b/webapp/mt/BattleRandAttribute.php index 1d6e3bb7..d8d79ae7 100644 --- a/webapp/mt/BattleRandAttribute.php +++ b/webapp/mt/BattleRandAttribute.php @@ -62,7 +62,7 @@ class BattleRandAttribute { return array_values($newAttr); } - protected static function getByInvoke($invoke,$quality){ + public static function getByInvoke($invoke,$quality){ $metaList = array(); foreach (self::getMetaList() as $meta){ $rateNeed = explode('|', $meta['rareNeed']); diff --git a/webapp/services/ChipPageService.php b/webapp/services/ChipPageService.php index 7e8ff6cf..88e90b9c 100644 --- a/webapp/services/ChipPageService.php +++ b/webapp/services/ChipPageService.php @@ -13,10 +13,10 @@ use mt\Item; use phpcommon\SqlHelper; class ChipPageService extends BaseService { - const MAX_CHIP_SLOT_NUM = 30; + const MAX_CHIP_SLOT_NUM = 9; const INIT_CHIP_PAGE_NUM = 3; - public function refreshSlotState($row,$heroDb){ + public function refreshSlotState($chipPageDb,$heroDb){ $itemMeta = Item::get($heroDb['hero_id']); if (!$itemMeta){ @@ -43,7 +43,7 @@ class ChipPageService extends BaseService array_push($slotArr,$i*3 +3 ); } } - $data = emptyReplace(json_decode($row['data'], true), array()); + $data = emptyReplace(json_decode($chipPageDb['data'], true), array()); foreach ($data as &$val){ if ( in_array($val['slot_id'],$slotArr) ){ @@ -52,7 +52,7 @@ class ChipPageService extends BaseService $val['state'] = 0; } } - ChipPage::update($row['hero_uniid'],array( + ChipPage::update($chipPageDb['hero_uniid'],array( 'data' => json_encode($data), )); }