diff --git a/doc/Chip.py b/doc/Chip.py new file mode 100644 index 00000000..898d63ea --- /dev/null +++ b/doc/Chip.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +import _common + +class Chip(object): + + def __init__(self): + self.apis = [ + { + 'name': 'chipList', + 'desc': '获取芯片列表', + 'group': 'Bag', + 'url': 'webapp/index.php?c=Chip&a=chipList', + 'params': [ + _common.ReqHead(), + ['type', '', '芯片类型:1 角色;2 枪械'], + ], + 'response': [ + _common.RspHead(), + ['!data', [_common.Chip()], '芯片列表'] + ] + }, + + ] diff --git a/doc/_common.py b/doc/_common.py index f021d3f2..f171aef0 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -625,3 +625,35 @@ class Phase3Box(object): self.fields = [ ['box_id', '', '箱子id'], ] + +class ChipAttr(object): + + def __init__(self): + self.fields = [ + ['attr_id', 0, '属性id'], + ['type', 0, '1: 绝对值 2:百分比'], + ['val', 0, '综合属性值'], + ['chip_type', 0, '1:角色芯片 2:枪械芯片'], + ['attr_num', 0, '成长属性值'], + ['attr_pool_num', 0, '固定属性值'], + ] + +class Chip(object): + + def __init__(self): + self.fields = [ + ['idx', 0, '主键id'], + ['token_id', '', 'token id'], + ['account_id', '', '账号id'], + ['item_id', 0, '道具id'], + ['item_num', 0, '道具数量'], + ['chip_grade', 0, '芯片等级'], + ['chip_type', 0, '芯片类型:1 角色;2 枪械'], + ['state', 0, '芯片添加状态:0 正常;1 选择;-1 锁定'], + ['supper_state', 0, '是否锁定:0 正常;1 锁住'], + ['inlay_state', 0, '镶嵌状态:0 未镶嵌;1 镶嵌了'], + ['!rand_attr', [ChipAttr()], '属性'], + ['lucky_temporary', '', '临时幸运值'], + ['lucky_final', '', '最终幸运值'], + ['strength', '', '体力值'], + ] \ No newline at end of file diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 4e0ed53f..44948963 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -150,6 +150,7 @@ CREATE TABLE `t_hero` ( `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`) @@ -225,6 +226,9 @@ CREATE TABLE `t_chip` ( `rand_attr` mediumblob COMMENT '随机属性', `today_get_gold` bigint NOT NULL DEFAULT '0' COMMENT '金币', `last_get_gold_time` int(11) NOT NULL DEFAULT '0' COMMENT '最后获取金币的时间', + `lucky_temporary` varchar(10) NOT NULL DEFAULT '0' COMMENT '临时幸运值', + `lucky_final` varchar(10) NOT NULL DEFAULT '0' COMMENT '最终幸运值', + `strength` varchar(10) NOT NULL DEFAULT '0' COMMENT '体力值', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), diff --git a/webapp/controller/ChipController.class.php b/webapp/controller/ChipController.class.php index 6796bf61..45ec0801 100644 --- a/webapp/controller/ChipController.class.php +++ b/webapp/controller/ChipController.class.php @@ -4,6 +4,7 @@ require_once('models/Chip.php'); require_once('models/Hero.php'); require_once('mt/ChipAttr.php'); require_once('mt/AttrHelper.php'); +require_once('services/FormulaService.php'); use models\Chip; use models\Hero; @@ -29,6 +30,24 @@ class ChipController extends BaseAuthedController )); } + public function chipOrder(){ + $type = getReqVal('type',''); + if (! $type){ + $this->_rspErr(1,'Please enter instructions'); + return ; + } + $order = getReqVal('order','asc'); + $chipList = Chip::all($type); + $chipDtoList = array(); + foreach ($chipList as $item) { + array_push($chipDtoList, Chip::toDto($item)); + } + $data = $this->_orderByChip($chipDtoList,$order); + $this->_rspData(array( + 'data' => $data, + )); + } + public function beforeInlay(){ $type = getReqVal('type',''); if (! $type){ @@ -126,7 +145,7 @@ class ChipController extends BaseAuthedController } } - $res = $this->_orderByChipDesc($usable,$limit); + $res = $this->_getHignGradeLimit($usable,$limit); if (! $res){ $this->_rspErr(1, 'The chip slot is full'); return; @@ -141,8 +160,136 @@ class ChipController extends BaseAuthedController } + public function beforeSynthetic(){ + $token_id = trim(getReqVal('token_id', 0)); + if (! $token_id) { + $this->_rspErr(1, 'Please enter instructions'); + return; + } + $chip = Chip::getChipByTokenId($token_id); + if ($chip['supper_state'] == 1 || $chip['inlay_state'] == 1 || $chip['state'] == -1){ + $this->_rspErr(1, "The chip can't synthetic"); + return; + } + if ($chip['chip_grade'] == 15){ + $this->_rspErr(1, "Chip level upper limit"); + return; + } + $chip = Chip::toDto($chip); + foreach ($chip['rand_attr'] as $k=>$val){ + $attr = \mt\ChipAttr::getAttrById($val['attr_id'],$val['chip_type']); + $chip['rand_attr_after'][$k] =[ + 'attr_id'=>$val['attr_id'], + 'type'=>$val['type'], + 'val'=>$attr['lv'.($chip['chip_grade']+1)]*$val['attr_pool_num'], + 'chip_type'=>$val['chip_type'] + ]; + } + $chip['upgrade_cost']=\services\FormulaService::getChipUpgradeCost($chip['chip_grade']+1); + $this->_rspData(['data'=>$chip]); + } + + public function selectChip(){ + $token_id = trim(getReqVal('token_id', 0)); + $token_ids = explode(' ',$token_id); + if (count($token_ids)<0){ + $this->_rspErr(1, 'Please enter instructions'); + return; + } + + + $chip_main = Chip::getChipByTokenId($token_ids[0]); + $chip_param = Chip::getChipByTokenId($token_ids[1]); + if ($chip_param['supper_state'] == 1 || $chip_param['inlay_state'] == 1 || $chip_param['state'] == -1){ + $this->_rspErr(1, "The chip can't select"); + return; + } + if ($chip_param['chip_grade']>$chip_main['chip_grade']){ + $this->_rspErr(1, "The selected material is too high grade"); + return; + } + if ($chip_param['state']){ + Chip::update($token_ids[1],['state'=>0]); + $cost = 0; + }else{ + Chip::update($token_ids[1],['state'=>1]); + $cost = \services\FormulaService::getChipCumulativeCost($chip_param['chip_grade']); + } + $this->_rspData(['data'=>$cost]); + } + + public function syntheticChip(){ + $token_id_main = trim(getReqVal('token_id_main', 0)); + $token_id_param = getReqVal('token_id_param', 0); + if (! $token_id_main || ! $token_id_param) { + $this->_rspErr(1, 'Please enter instructions'); + return; + } + $chip_main = Chip::getChipByTokenId($token_id_main); + $upgrade_cost = \services\FormulaService::getChipUpgradeCost($chip_main['chip_grade']+1); + if ($upgrade_cost==0){ + $this->_rspErr(1, 'Error in calculation formula'); + return; + } + $cumulative_cost = 0; + foreach ($token_id_param as $val){ + $chip_param = Chip::getChipByTokenId($val); + $cumulative_cost += \services\FormulaService::getChipCumulativeCost($chip_param['chip_grade']); + Chip::deleteChip(['token_id'=>$val]); + } + $num = round(round(($cumulative_cost/$upgrade_cost),5)*10000); + if ($num_rspErr(1, 'The chip Upgrade failed'); + return; + }else{ + //合成成功 + $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']); + $this->_rspData(['data'=>$chip_new]); + } + } + + public function isNeedLucky(){ + $token_id = trim(getReqVal('token_id', 0)); + if (! $token_id) { + $this->_rspErr(1, 'Please enter instructions'); + return; + } + $chip = Chip::getChipByTokenId($token_id); + $fieldsKv = [ + 'lucky_final'=>$chip['lucky_final']+$chip['lucky_temporary'], + 'lucky_temporary'=>0, + 'strength' => \services\FormulaService::getChipPhysicalStrengthValue($chip['chip_grade'],$chip['lucky_final']+$chip['lucky_temporary']) + ]; + Chip::update($chip['token_id'],$fieldsKv); + $this->_rspOk(); + } + + public function isNotNeedLucky(){ + $token_id = trim(getReqVal('token_id', 0)); + if (! $token_id) { + $this->_rspErr(1, 'Please enter instructions'); + return; + } + $chip = Chip::getChipByTokenId($token_id); + $fieldsKv = [ + 'lucky_temporary'=>0, + ]; + Chip::update($chip['token_id'],$fieldsKv); + $this->_rspOk(); + } + + public function aKeySynthetic(){ + + } + + + public function test(){ - + $chip = Chip::getChipByTokenId(1660629360); + print_r($chip); } private function _doInlay($hero_id,$token_id){ @@ -244,7 +391,7 @@ class ChipController extends BaseAuthedController } } - private function _orderByChipDesc($data,$limit){ + private function _getHignGradeLimit($data,$limit){ $len = count($data); if ($len<=1 || $len<=$limit){ return $data; @@ -259,7 +406,45 @@ class ChipController extends BaseAuthedController } } return array_slice($data,0,$limit); + } + private function _orderByChip($data,$order){ + $len = count($data); + if ($len<=1){ + return $data; + } + if ($order == 'desc'){ + for ($i = 0; $i < $len - 1; $i++) { + for ($j = $i + 1; $j < $len; $j++) { + if ($data[$i]['chip_grade'] < $data[$j]['chip_grade']) { + $tmp = $data[$i]; + $data[$i] = $data[$j]; + $data[$j] = $tmp; + } + } + } + }else{ + for ($i = 0; $i < $len - 1; $i++) { + for ($j = $i + 1; $j < $len; $j++) { + if ($data[$i]['chip_grade'] > $data[$j]['chip_grade']) { + $tmp = $data[$i]; + $data[$i] = $data[$j]; + $data[$j] = $tmp; + } + } + } + } + return $data; + } + + private function _upgraded($chip){ + $new_grade = $chip['chip_grade']+1; + 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]); } } \ No newline at end of file diff --git a/webapp/models/Chip.php b/webapp/models/Chip.php index c052eef6..d593da8e 100644 --- a/webapp/models/Chip.php +++ b/webapp/models/Chip.php @@ -31,7 +31,8 @@ class Chip extends BaseModel 't_nft', array( 'owner_address' => myself()->_getOpenId(), - 'token_type' =>3 + 'token_type' =>3, + 'deleted' => 0 ) ); foreach ($nft as $nftDb) { @@ -78,9 +79,9 @@ class Chip extends BaseModel 'type' => 2, 'val' => $attr['lv'.$row['chip_grade']]*$val['attr_pool_number'], // 'chip_name' => $attr['chip_name'], -// 'chip_type' => $attr['chip_type'], -// 'attr_num' => $attr['lv'.$row['chip_grade']], -// 'attr_pool_num' => $val['attr_pool_number'], + 'chip_type' => $attr['chip_type'], + 'attr_num' => $attr['lv'.$row['chip_grade']], + 'attr_pool_num' => $val['attr_pool_number'], ]; array_push($attrs,$newAttr); } @@ -166,6 +167,17 @@ class Chip extends BaseModel } + public static function update($token_id, $fieldsKv){ + SqlHelper::update + (myself()->_getSelfMysql(), + 't_chip', + array( + 'token_id' => $token_id, + ), + $fieldsKv + ); + } + public static function updateChipInlayState($token_id,$state){ return SqlHelper::update( myself()->_getSelfMysql(), @@ -186,4 +198,25 @@ class Chip extends BaseModel ) ); } + + public static function deleteChip($whereKv){ + SqlHelper::update( + myself()->_getMarketMysql(), + 't_nft', + $whereKv, + ['deleted'=>1] + ); + } + + public static function updateRandAttr($chip){ + $attr_pool = mt\ChipAttr::generateOneAttr($chip['chip_type']); + $rand_attr = emptyReplace(json_decode($chip['rand_attr'], true), array()); + array_push($rand_attr,$attr_pool); + $fieldsKv = [ + 'chip_grade'=>$chip['chip_grade']+1, + 'rand_attr'=>json_encode($rand_attr) + ]; + self::update($chip['token_id'],$fieldsKv); + } + } \ No newline at end of file diff --git a/webapp/mt/ChipAttr.php b/webapp/mt/ChipAttr.php index 259f5638..2397e90e 100644 --- a/webapp/mt/ChipAttr.php +++ b/webapp/mt/ChipAttr.php @@ -5,6 +5,7 @@ namespace mt; require_once('mt/AttrHelper.php'); require_once('mt/StrHelper.php'); +require_once('mt/Item.php'); use phpcommon; @@ -83,27 +84,26 @@ class ChipAttr { } } -// public static function getChipValue($grade){ -//// (self::_SIGN($grade,6,"<"))*(15*$grade*($grade-1)+10) -// -// } -// -// private static function _SIGN($grade,$n,$symbol){ -// if ($symbol == '>'){ -// if ($grade>$n){ -// return 1; -// }else{ -// return 0; -// } -// } -// if ($symbol == '<'){ -// if ($grade<$n){ -// return 1; -// }else{ -// return 0; -// } -// } -// } + public static function generateOneAttr($type){ +// $itemMeta = Item::get($item_id); +// return self::getAttrPool(self::getAttrByItemId($itemMeta['id'])); + +// $attr_pool = self::getAttrPool(self::getAttrByItemId($itemMeta['id'])); +// $attr = emptyReplace(json_decode($chip['rand_attr'], true), array()); +// array_push($attr,$attr_pool); +// return $attr; + if ($type == self::ROLE_CHIP_SUBTYPE){ + $chip = self::getNodeChip(); + $attr = $chip[ array_rand($chip)]; + return self::getAttrPool($attr); + } + if ($type == self::GUN_CHIP_SUBTYPE){ + $chip = self::getGunChip(); + $attr = $chip[ array_rand($chip)]; + return self::getAttrPool($attr); + } + return array(); + } private static function _randomNum($itemMeta,$chip_grade,$chipList){ $attr_pool = array(); diff --git a/webapp/mt/StrHelper.php b/webapp/mt/StrHelper.php index e837b1dd..be1702b5 100644 --- a/webapp/mt/StrHelper.php +++ b/webapp/mt/StrHelper.php @@ -15,7 +15,7 @@ class StrHelper { return $values; } - private function parse($data, $separators, $i, &$arr) { + private static function parse($data, $separators, $i, &$arr) { $strs = explode($separators[$i], $data); foreach ($strs as $str) { if ($i + 1 < count($separators)) { diff --git a/webapp/services/FormulaService.php b/webapp/services/FormulaService.php index 3646c2c9..3b2e7c62 100644 --- a/webapp/services/FormulaService.php +++ b/webapp/services/FormulaService.php @@ -271,4 +271,36 @@ class FormulaService extends BaseService { return 0; } + public static function getCegDiscountRate(){ + //CEG_Discount_Rate=ROUND(CEG_Dynamic_Index /( CEG_Dynamic_Price / CEG_Base_Price),3) + return 1; + } + + //芯片升星累计成本 + public static function getChipCumulativeCost($grade){ + //( SIGN(芯片星级<6)*(15*芯片星级*(芯片星级-1)+10)+SIGN(芯片星级>5)*SIGN(芯片星级<10)*(80*(芯片星级-4)*( 芯片星级-3)+50) +SIGN(芯片星级>9)*SIGN(芯片星级<14)*(370*(芯片星级-8)*( 芯片星级-7)*(2*芯片星级-15)/6+80*(芯片星级-8)+2100) +SIGN(芯片星级>13)*SIGN(芯片星级<16)*(600*(芯片星级-8)*(芯片星级-7)*(2*芯片星级-15)/6-14000)) *CEG_Discount_Rate + return (($grade<6?1:0)*(15*$grade*($grade-1)+10)+($grade>5?1:0)*($grade<10?1:0)*(80*($grade-4)*( $grade-3)+50) +($grade>9?1:0)*($grade<14?1:0)*(370*($grade-8)*( $grade-7)*(2*$grade-15)/6+80*($grade-8)+2100) +($grade>13?1:0)*($grade<16?1:0)*(600*($grade-8)*($grade-7)*(2*$grade-15)/6-14000)) *1; + + //( SIGN(芯片星级<6)*((15*芯片星级+10)*(芯片星级-1)+10)+SIGN(芯片星级>5)*SIGN(芯片星级<10)*(80*(芯片星级-4)*( 芯片星级-3)+90) +SIGN(芯片星级>9)*SIGN(芯片星级<14)*(370*(芯片星级-8)*( 芯片星级-7)*(2*芯片星级-15)/6+80*(芯片星级-8)+2140) +SIGN(芯片星级>13)*SIGN(芯片星级<16)*(600*(芯片星级-8)*(芯片星级-7)*(2*芯片星级-15)/6-13960)) *CEG_Discount_Rate + /* return (($grade<6?1:0)*((15*$grade+10)*($grade-1)+10)+($grade>5?1:0)*($grade<10?1:0)*(80*($grade-4)*($grade-3)+90)+($grade>9?1:0)*($grade<14?1:0)*(370*($grade-8)*($grade-7)*(2*$grade-15)/6+80*($grade-8)+2140)+($grade>13?1:0)*($grade<16?1:0)*(600*($grade-8)*($grade-7)*(2*$grade-15)/6-13960))*self::getCegDiscountRate();*/ + + } + + //芯片升星成本 + public static function getChipUpgradeCost($grade){ + //(SIGN(芯片星级=1)*10+SIGN(芯片星级<6)*SIGN(芯片星级>1)*(30*(芯片星级-1))+SIGN(芯片星级>5)*SIGN(芯片星级<10)*(160*(芯片星级-4))-SIGN(芯片星级=6)*100+SIGN(芯片星级>9)*SIGN(芯片星级<14)*(370*(芯片星级-8)^2+80)+SIGN(芯片星级=10)*100 +SIGN(芯片星级>13)*SIGN(芯片星级<16)*(600*(芯片星级-8)^2)-SIGN(芯片星级=14)*3850) *CEG_Discount_Rate + return (($grade==1?1:0)*10+($grade<6?1:0)*($grade>1?1:0)*(30*($grade-1))+($grade>5?1:0)*($grade<10?1:0)*(160*($grade-4))-($grade==6?1:0)*100+($grade>9?1:0)*($grade<14?1:0)*(370*($grade-8)*($grade-8)+80)+($grade==10?1:0)*100+($grade>13?1:0)*($grade<16?1:0)*(600*($grade-8)*($grade-8))-($grade==14?1:0)*3850)*self::getCegDiscountRate(); + + } + + public static function getChipLuckyValue($grade){ + //芯片幸运值=SIGN(芯片星数>4)*ROUND( 0.00419*芯片星数^5-0.0705*芯片星数^4 +0.24*芯片星数^3 +8.5*芯片星数^2-39.9*芯片星数+38,1) + return ($grade>4?1:0)*round(0.00419*pow($grade,5)-0.0705*pow($grade,4)+0.24*pow($grade,3)+8.5*pow($grade,2)-39.9*$grade+38,1); + } + + public static function getChipPhysicalStrengthValue($grade,$lucky){ + //芯片体力值(命名:Hero_Chip_NFT_Maximum_Physical_Strength) = SIGN(英雄芯片NFT星数>4)*( 英雄芯片NFT幸运值*ROUND(1+0.04*英雄芯片NFT星数,3)) + return ($grade>4?1:0)*($lucky*round(1+0.04*$grade,3)); + } + }