From 1f7311fefbd2f8d10e28c05d67c4e62adf0b5e7d Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Thu, 11 Jan 2024 15:42:45 +0800 Subject: [PATCH] 1 --- doc/Chip.py | 139 ++++---- doc/Hero.py | 37 +-- sql/gamedb.sql | 1 + sql/gamedb2006_migrate_231228_01.sql | 2 + webapp/controller/ChipController.class.php | 49 +++ webapp/controller/HeroController.class.php | 348 +++++---------------- webapp/models/Chip.php | 1 + webapp/mt/HeroQuality.php | 128 ++------ 8 files changed, 252 insertions(+), 453 deletions(-) diff --git a/doc/Chip.py b/doc/Chip.py index 73582c88..16101b73 100644 --- a/doc/Chip.py +++ b/doc/Chip.py @@ -1,63 +1,76 @@ -# -*- coding: utf-8 -*- - -import _common - -class Chip(object): - - def __init__(self): - self.apis = [ - { - 'name': 'chipList', - 'desc': '获取芯片列表', - 'group': 'Chip', - 'url': 'webapp/index.php?c=Chip&a=chipList', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ['!data', [_common.Chip()], '芯片列表'] - ] - },{ - 'name': 'chipDetails', - 'desc': '芯片详情', - 'group': 'Chip', - 'url': 'webapp/index.php?c=Chip&a=chipDetails', - 'params': [ - _common.ReqHead(), - ['unique_id', '', 'unique_id'], - ], - 'response': [ - _common.RspHead(), - ['!data', [_common.Chip()], '芯片信息'] - ] - },{ - 'name': 'upgradeLevelPreview', - 'desc': '芯片升级前置操作', - 'group': 'Chip', - 'url': 'webapp/index.php?c=Chip&a=upgradeLevelPreview', - 'params': [ - _common.ReqHead(), - ['unique_id', '', 'unique_id'], - ], - 'response': [ - _common.RspHead(), - ['!data', [_common.ChipPro()], '芯片信息'] - ] - },{ - 'name': 'upgradeLevel', - 'desc': '芯片升级', - 'group': 'Chip', - 'url': 'webapp/index.php?c=Chip&a=upgradeLevel', - 'params': [ - _common.ReqHead(), - ['unique_id_main', '', '源芯片token id'], - ['unique_id_param', '', '材料芯片token id 例:参数1 参数2 参数3'], - ], - 'response': [ - _common.RspHead(), - ['!data', [_common.Chip()], '芯片信息'], - ['property_chg', _common.PropertyChg(), '属性变更'], - ] - }, - ] +# -*- coding: utf-8 -*- + +import _common + +class Chip(object): + + def __init__(self): + self.apis = [ + { + 'name': 'chipList', + 'desc': '获取芯片列表', + 'group': 'Chip', + 'url': 'webapp/index.php?c=Chip&a=chipList', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['!data', [_common.Chip()], '芯片列表'] + ] + },{ + 'name': 'chipDetails', + 'desc': '芯片详情', + 'group': 'Chip', + 'url': 'webapp/index.php?c=Chip&a=chipDetails', + 'params': [ + _common.ReqHead(), + ['unique_id', '', 'unique_id'], + ], + 'response': [ + _common.RspHead(), + ['!data', [_common.Chip()], '芯片信息'] + ] + },{ + 'name': 'upgradeLevelPreview', + 'desc': '芯片升级前置操作', + 'group': 'Chip', + 'url': 'webapp/index.php?c=Chip&a=upgradeLevelPreview', + 'params': [ + _common.ReqHead(), + ['unique_id', '', 'unique_id'], + ], + 'response': [ + _common.RspHead(), + ['!data', [_common.ChipPro()], '芯片信息'] + ] + },{ + 'name': 'upgradeLevel', + 'desc': '芯片升级', + 'group': 'Chip', + 'url': 'webapp/index.php?c=Chip&a=upgradeLevel', + 'params': [ + _common.ReqHead(), + ['unique_id_main', '', '源芯片token id'], + ['unique_id_param', '', '材料芯片token id 例:参数1 参数2 参数3'], + ], + 'response': [ + _common.RspHead(), + ['!data', [_common.Chip()], '芯片信息'], + ['property_chg', _common.PropertyChg(), '属性变更'], + ] + },{ + 'name': 'upgradeQuality', + 'desc': '芯片升阶', + 'group': 'Chip', + 'url': 'webapp/index.php?c=Chip&a=upgradeQuality', + 'params': [ + _common.ReqHead(), + ['chip_uniid', '', '芯片唯一id'], + ], + 'response': [ + _common.RspHead(), + ['property_chg', _common.PropertyChg(), '属性变更'], + ] + }, + ] diff --git a/doc/Hero.py b/doc/Hero.py index 04de3c56..f5385cad 100644 --- a/doc/Hero.py +++ b/doc/Hero.py @@ -134,46 +134,31 @@ class Hero(object): _common.RspHead(), ] },{ - 'name': 'heroPieceSys', - 'desc': '英雄碎片合成', + 'name': 'upgradeQualityPreview', + 'desc': '升阶预览', 'group': 'Hero', - 'url': 'webapp/index.php?c=Hero&a=heroPieceSys', + 'url': 'webapp/index.php?c=Hero&a=upgradeQualityPreview', 'params': [ _common.ReqHead(), - ['item_id', 0, '碎片itemID'], + ['itemId', 0, 'itemId'], + ['quality', 0, '品阶'], ], 'response': [ _common.RspHead(), - ['!hero', [_common.Hero()], '英雄信息'] + [['cost', [], '所需道具'], ] },{ - 'name': 'beforeHeroReset', - 'desc': '英雄重置前', + 'name': 'upgradeQuality', + 'desc': '英雄升阶', 'group': 'Hero', - 'url': 'webapp/index.php?c=Hero&a=beforeHeroReset', + 'url': 'webapp/index.php?c=Hero&a=upgradeQuality', 'params': [ _common.ReqHead(), - ['hero_unnid', 0, '英雄唯一id'], + ['hero_uniid', 0, '英雄唯一id'], ], 'response': [ _common.RspHead(), - ['ceg', 0, 'ceg'], - ['!cost', [_common.AwardItem()], '返还资源'] - ] - },{ - 'name': 'heroResetLevel', - 'desc': '英雄重置', - 'group': 'Hero', - 'url': 'webapp/index.php?c=Hero&a=heroResetLevel', - 'params': [ - _common.ReqHead(), - ['hero_unnid', 0, '英雄唯一id'], - ['price', 0, 'ceg数量'], - ], - 'response': [ - _common.RspHead(), - ['trans_id', 0, '订单号'], - ['params', 0, 'params'], + [['property_chg', _common.PropertyChg(), '属性变更'], ] }, diff --git a/sql/gamedb.sql b/sql/gamedb.sql index e6a87ae2..36e77978 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -250,6 +250,7 @@ CREATE TABLE `t_chip` ( `active_token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'active_token_id', `active_count` int(11) NOT NULL DEFAULT '0' COMMENT 'active_count', `activate` int(11) NOT NULL DEFAULT '0' COMMENT '是否激活 1:已初始激活', + `quality` int(11) 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/sql/gamedb2006_migrate_231228_01.sql b/sql/gamedb2006_migrate_231228_01.sql index a6d6027e..a76e3fa3 100644 --- a/sql/gamedb2006_migrate_231228_01.sql +++ b/sql/gamedb2006_migrate_231228_01.sql @@ -21,6 +21,8 @@ CREATE TABLE `t_hash_rate_battle_data` ( PRIMARY KEY (`idx`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +alter table t_chip add column `quality` int(11) NOT NULL DEFAULT '0' COMMENT '品阶'; + insert into version (version) values(2023122801); commit; diff --git a/webapp/controller/ChipController.class.php b/webapp/controller/ChipController.class.php index 130e20b5..2f6a704c 100644 --- a/webapp/controller/ChipController.class.php +++ b/webapp/controller/ChipController.class.php @@ -7,6 +7,7 @@ require_once('models/User.php'); require_once('models/Bag.php'); require_once('mt/ChipAttr.php'); +require_once('mt/HeroQuality.php'); require_once('services/FormulaService.php'); require_once('services/PropertyChgService.php'); @@ -236,4 +237,52 @@ class ChipController extends BaseAuthedController ]); } + public function upgradeQuality(){ + $chipUniId = trim(getReqVal('chip_uniid', 0)); + if (!$chipUniId) { + $this->_rspErr(1, 'Please enter parameter'); + return; + } + $chipDb = Chip::find($chipUniId); + if (!$chipDb){ + $this->_rspErr(1,'unique_id_main parameter error'); + return; + } + if ($chipDb['quality'] == \mt\HeroQuality::MAX_QUALITY){ + $this->_rspErr(5, "It's already the highest level"); + return; + } + $heroQualityMeta = \mt\HeroQuality::getByQuality($chipDb['item_id'],$chipDb['quality']+1); + if (!$heroQualityMeta){ + $this->_rspErr(100, 'server internal error'); + return; + } + $costItems = array( + array( + 'item_id' => V_ITEM_GOLD, + 'item_num' => $heroQualityMeta['gold'] + ), + array( + 'item_id' => $heroQualityMeta['item'], + 'item_num' => $heroQualityMeta['item_num'] + ), + ); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); + return; + } + $this->_decItems($costItems); + Chip::update2($chipUniId, array( + 'quality' => $chipDb['quality'] + 1, + )); + $propertyChgService = new services\PropertyChgService(); + $propertyChgService->addChip(); + $propertyChgService->addUserChg(); + $propertyChgService->addBagChg(); + $this->_rspData(array( + 'property_chg' => $propertyChgService->toDto(), + )); + } + } diff --git a/webapp/controller/HeroController.class.php b/webapp/controller/HeroController.class.php index 6cd71415..9c5944c1 100644 --- a/webapp/controller/HeroController.class.php +++ b/webapp/controller/HeroController.class.php @@ -4,6 +4,7 @@ require_once('mt/Hero.php'); require_once('mt/Item.php'); require_once('mt/HeroLevel.php'); require_once('mt/Skill.php'); +require_once('mt/HeroQuality.php'); require_once('models/Hero.php'); require_once('models/HeroSkin.php'); @@ -36,24 +37,6 @@ use services\LogService; class HeroController extends BaseAuthedController { -// public function test(){ -// $heroUniId = getReqVal('hero_uniid', 0); -// $heroDb = Hero::find($heroUniId); -// if (!$heroDb) { -// $this->_rspErr(100, 'param error or null'); -// return; -// } -// if ($heroDb['hero_lv'] == 15){ -// $this->_rspErr(100, 'param error or null'); -// return; -// } -// $attrs = Hero::LvUpAddAttr($heroDb); -// Hero::update($heroUniId, array( -// 'hero_lv' => $heroDb['hero_lv'] + 1, -// 'rand_attr' => json_encode($attrs['rand_attr']), -// 'base_attr' => json_encode($attrs['base_attr']), -// )); -// } public function heroList() { @@ -140,6 +123,84 @@ class HeroController extends BaseAuthedController { $this->_rspOk(); } + /* + 升阶预览 + */ + public function upgradeQualityPreview(){ + $itemId = getReqVal('itemId', 0); + $quality = getReqVal('quality', 0); + + if ($quality == \mt\HeroQuality::MAX_QUALITY){ + $this->_rspErr(5, "It's already the highest quality"); + return; + } + $heroQualityMeta = \mt\HeroQuality::getByQuality($itemId,$quality+1); + if (!$heroQualityMeta){ + $this->_rspErr(100, 'server internal error'); + return; + } + $costItems = array( + array( + 'item_id' => V_ITEM_GOLD, + 'item_num' => $heroQualityMeta['gold'] + ), + array( + 'item_id' => $heroQualityMeta['item'], + 'item_num' => $heroQualityMeta['item_num'] + ), + ); + $this->_rspData(array( + 'cost' => $costItems + )); + } + + /* + 英雄升阶 + */ + public function upgradeQuality(){ + $heroUniId = getReqVal('hero_uniid', 0); + $heroDb = Hero::find($heroUniId); + if (!$heroDb) { + $this->_rspErr(100, 'param error or null'); + return; + } + if ($heroDb['quality'] == \mt\HeroQuality::MAX_QUALITY){ + $this->_rspErr(5, "It's already the highest level"); + return; + } + $heroQualityMeta = \mt\HeroQuality::getByQuality($heroDb['hero_id'],$heroDb['quality']+1); + if (!$heroQualityMeta){ + $this->_rspErr(100, 'server internal error'); + return; + } + $costItems = array( + array( + 'item_id' => V_ITEM_GOLD, + 'item_num' => $heroQualityMeta['gold'] + ), + array( + 'item_id' => $heroQualityMeta['item'], + 'item_num' => $heroQualityMeta['item_num'] + ), + ); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); + return; + } + $this->_decItems($costItems); + Hero::update($heroUniId, array( + 'quality' => $heroDb['quality'] + 1, + )); + $propertyChgService = new services\PropertyChgService(); + $propertyChgService->addHeroChg(); + $propertyChgService->addUserChg(); + $propertyChgService->addBagChg(); + $this->_rspData(array( + 'property_chg' => $propertyChgService->toDto(), + )); + } + /* 升级预览 */ @@ -193,110 +254,13 @@ class HeroController extends BaseAuthedController { )); } - /* - 英雄升级 - */ - public function upgradeLv() - { - return; - $heroUniId = getReqVal('hero_uniid', 0); - $heroDb = Hero::find($heroUniId); - $oldHero = Hero::toDto($heroDb); - if (!$heroDb) { - $this->_rspErr(100, 'param error or null'); - return; - } - - $heroMeta = mt\Hero::get($heroDb['hero_id']); - if (!$heroMeta) { - $this->_rspErr(100, 'server internal error'); - return; - } - $nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv'] + 1); - if (!$nextLevelMeta) { - $this->_rspErr(5, "It's already the highest level"); - return; - } - - //校验英雄碎片数量 - $piece_item_id = 0; - $metaList = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE); - foreach ($metaList as $meta){ - if ($meta['relationship'] == $heroDb['hero_id']) { - $piece_item_id = $meta['id']; - break; - } - } - $piece_num = Bag::getItemCount($piece_item_id); - if ($piece_num < $nextLevelMeta['piece']){ - $this->_rspErr(3, "Lack of hero piece"); - return; - } - - //校验英雄水晶数量 - $num = Bag::getItemCount(V_ITEM_HERO_META); - if ($num < $nextLevelMeta['serum']){ - $this->_rspErr(3, "Lack of hero crystal"); - return; - } - - //校验用户gold数量 - $costItems = array( - array( - 'item_id' => V_ITEM_GOLD, - 'item_num' => $nextLevelMeta['gold'] - ), -// array( -// 'item_id' => V_ITEM_DIAMOND, -// 'item_num' => $nextLevelMeta['diamond'] -// ) - ); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); - return; - } - $this->_decItems($costItems); - Bag::decItem($piece_item_id,$nextLevelMeta['piece']); - Bag::decItem(V_ITEM_HERO_META,$nextLevelMeta['serum']); - { - //埋点 - $event = [ - 'name' => LogService::HERO_LEVEL_UP, - 'val' => $nextLevelMeta['gold'] - ]; - LogService::consumeGold($event); - } - - $attrs = Hero::LvUpAddAttr($heroDb); - Hero::update($heroUniId, array( - 'hero_lv' => $heroDb['hero_lv'] + 1, - 'rand_attr' => json_encode($attrs['rand_attr']), - 'base_attr' => json_encode($attrs['base_attr']), -// 'state' => Hero::GETED_STATE, - )); - - if ($heroDb['hero_lv'] + 1 > myself()->_getV(TN_HERO_MAX_LEVEL, 0)) { - myself()->_setV(TN_HERO_MAX_LEVEL, 0, $heroDb['hero_lv'] + 1); - } - $newHero = Hero::toDto(Hero::find($heroUniId)); - $propertyChgService = new services\PropertyChgService(); - $propertyChgService->addHeroChg(); - $propertyChgService->addUserChg(); - $propertyChgService->addBagChg(); - $this->_rspData(array( - 'property_chg' => $propertyChgService->toDto(), - 'old_hero' => $oldHero, - 'new_hero' => $newHero, - )); - } - /* 英雄升级 */ public function upgradeLvNew() { + return $heroUniId = getReqVal('hero_uniid', 0); $heroDb = Hero::find($heroUniId); $oldHero = Hero::toDto($heroDb); @@ -444,158 +408,6 @@ class HeroController extends BaseAuthedController { $this->_rspOk(); } - /* - 英雄碎片合成 - */ - public function heroPieceSys(){ - return - error_log("HERO PRICE : " . json_encode($_REQUEST)); - $itemId = getReqVal('item_id',0); - $pieceNum = \mt\Parameter::getVal('hero_piece_synthesis_num',0); - $itemMeta = \mt\Item::get($itemId); - if (!$itemMeta || $itemMeta['type'] != \mt\Item::FRAGMENT_TYPE){ - $this->_rspErr(1, "param item_id error"); - return; - } - $bagDb = Bag::find($itemId); - if (!$bagDb || $bagDb['item_num'] < $pieceNum){ - $this->_rspErr(1, "Insufficient material"); - return; - } - $heroMeta = \mt\Item::get($itemMeta['relationship']); - Bag::decItem($itemId,$pieceNum); - Hero::addFreeHero($heroMeta); - $heroIdx = SqlHelper::getLastInsertId($this->_getSelfMysql()); - $heroInfo = Hero::toDto(Hero::find($heroIdx)); - $propertyChgService = new services\PropertyChgService(); - $propertyChgService->addHeroChg(); - $propertyChgService->addBagChg(); - $this->_rspData(array( - 'hero' => $heroInfo, - 'property_chg' => $propertyChgService->toDto(), - )); - } - - public function beforeHeroReset(){ - return; - $hero_unnid = getReqVal('hero_unnid',0); - $heroDb = Hero::find($hero_unnid); - if (!$heroDb){ - $this->_rspErr(1, "param hero_unnid error"); - return; - } - if ($heroDb['hero_lv'] == 1){ - $this->_rspErr(1, "Level 1 hero cannot operate"); - return; - } - $paramMeta = \mt\Parameter::getListValue('hero_reset_cost'); - if (!$paramMeta){ - $this->_rspErr(1, "parameter hero_reset_cost is null "); - return; - } - $actual_price = 0; - foreach ($paramMeta as $value){ - $temp = explode(":",$value); - if ($heroDb['hero_lv'] == $temp[0]){ - $actual_price = $temp[1]; - } - } - $piece = 0; - $serum = 0; - $gold = 0; - for ($i=1;$i<=$heroDb['hero_lv'];$i++){ - $heroLevelMeta = mt\HeroLevel::getByLevel($i); - $piece += $heroLevelMeta['piece']; - $serum += $heroLevelMeta['serum']; - $gold += $heroLevelMeta['gold']; - } - $costItems = array( - array( - 'item_id' => V_ITEM_GOLD, - 'item_num' => $gold, - ), - array( - 'item_id' => V_ITEM_HERO_META, - 'item_num' => $serum, - ), - - ); - $metaList = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE); - foreach ($metaList as $meta){ - if ($meta['relationship'] == $heroDb['hero_id']) { - array_push($costItems,array( - 'item_id' => $meta['id'], - 'item_num' => $piece, - )); - } - } - $this->_rspData(array( - 'ceg' => $actual_price, - "cost" => $costItems - )); - } - /* - 英雄重置 2:5|3:10|4:15|5:20|6:25|7:30|8:35|9:40|10:45|11:50|12:55|13:60|14:65|15:70 - */ - public function heroResetLevel(){ - return; - error_log("heroResetLevel : " . json_encode($_REQUEST)); - if (!$this->_isValidAddress()) { - $this->_rspErr(1, 'address is empty'); - return; - } - $hero_unnid = getReqVal('hero_unnid',0); - $price = getReqVal('price', 0); - $heroDb = Hero::find($hero_unnid); - if (!$heroDb){ - $this->_rspErr(1, "param hero_unnid error"); - return; - } - if ($heroDb['hero_lv'] <= 1){ - $this->_rspErr(1, "This is the lowest level of hero"); - return; - } - $paramMeta = \mt\Parameter::getListValue('hero_reset_cost'); - if (!$paramMeta){ - $this->_rspErr(1, "parameter hero_reset_cost is null "); - return; - } - $actual_price = 0; - foreach ($paramMeta as $value){ - $temp = explode(":",$value); - if ($heroDb['hero_lv'] == $temp[0]){ - $actual_price = $temp[1]; - } - } - if($price != $actual_price){ - $this->_rspErr(1, "The number of CEGs is incorrect "); - return; - } - $response = services\BlockChainService::gameItemMallBuy( - Transaction::RESET_HERO_LEVEL_TYPE, services\BlockChainService::CURRENCY_CEG, services\BlockChainService::formatCurrency($price), V_ITEM_RESET_CARD, 1); - $this->_setV(TN_DAILY_RESET_HERO_LEVEL_STATE, intval($hero_unnid), 1); - BcOrder::upsert($response['trans_id'], array( - 'item_id' => V_ITEM_RESET_CARD, - 'item_num' => 1, - 'price' => $price, - 'ext_data' => json_encode($hero_unnid), - )); - $this->_rspData($response); - } - - /* - 英雄分解 - */ - public function heroSalvage(){ - - } - - /* - 英雄融合 - */ - public function heroMerge(){ - - } } diff --git a/webapp/models/Chip.php b/webapp/models/Chip.php index 2903adc6..315f30d0 100644 --- a/webapp/models/Chip.php +++ b/webapp/models/Chip.php @@ -241,6 +241,7 @@ class Chip extends BaseModel 'chip_grade' => 1, 'chip_type' => $itemMeta['sub_type'], 'activate' => 1, + 'quality' => 1, 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); diff --git a/webapp/mt/HeroQuality.php b/webapp/mt/HeroQuality.php index 0e33aaba..a212344f 100644 --- a/webapp/mt/HeroQuality.php +++ b/webapp/mt/HeroQuality.php @@ -1,96 +1,32 @@ - $item[0], - 'type' => $item[1], - 'val' => rand($item[2], $item[3]) - )); - } - ++$i; - } - return $result; - } - - - protected static function getMetaList() - { - if (!self::$metaList) { - self::$metaList = getMetaTable('heroQuality@heroQuality.php'); - foreach (self::$metaList as $key=>$value){ - if ($value['id'] == 1){ - self::$metaList[$key]['promote_val'] = (1+$value['promote']/100); - }else{ - self::$metaList[$key]['promote_val'] = (1+$value['promote']/100)*self::$metaList[$key-1]['promote_val']; - } - - } - } - return self::$metaList; - } - - protected static function mustBeQualityHash() - { - if (!self::$qualityHash) { - self::$qualityHash = array(); - foreach (self::getMetaList() as $meta) { - self::$qualityHash[$meta['quality']] = $meta; - } - } - } - - protected static function mustBeCoefficientHash($list) - { - if (!self::$coefficientHash) { - self::$coefficientHash = array(); - foreach ($list as $val) { - self::$coefficientHash[$val['attr_id']] = $val; - } - } - } - - protected static $metaList; - protected static $qualityHash; - protected static $coefficientHash; - -} +