From 6fc6162a5672ca21e9f7641c3c4c14e7712e267a Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Wed, 28 Jun 2023 20:01:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8B=B1=E9=9B=84(=E5=90=88?= =?UTF-8?q?=E6=88=90=E3=80=81=E5=8D=87=E7=BA=A7=E3=80=81=E8=8E=B7=E5=8F=96?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Hero.py | 2 +- sql/gamedb.sql | 1 + sql/gamedb2006_migrate_230628_01.sql | 7 ++ webapp/controller/HeroController.class.php | 47 +++++++-- webapp/models/Hero.php | 114 +++++++++++++-------- 5 files changed, 120 insertions(+), 51 deletions(-) create mode 100644 sql/gamedb2006_migrate_230628_01.sql diff --git a/doc/Hero.py b/doc/Hero.py index 0b4b0d4b..1cd28893 100644 --- a/doc/Hero.py +++ b/doc/Hero.py @@ -132,7 +132,7 @@ class Hero(object): ], 'response': [ _common.RspHead(), - ['hero_id', 0, '英雄itemId'] + ['!hero', [_common.Hero()], '英雄信息'] ] }, diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 8bb96a70..c1818529 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -170,6 +170,7 @@ CREATE TABLE `t_hero` ( `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:已初始激活', + `base_attr` mediumblob COMMENT '初始随机属性(英雄重置时需要)', PRIMARY KEY (`idx`), UNIQUE KEY `token_id` (`token_id`), KEY `account_id` (`account_id`) diff --git a/sql/gamedb2006_migrate_230628_01.sql b/sql/gamedb2006_migrate_230628_01.sql new file mode 100644 index 00000000..4f6dcff5 --- /dev/null +++ b/sql/gamedb2006_migrate_230628_01.sql @@ -0,0 +1,7 @@ +begin; + +alter table t_hero add column `base_attr` mediumblob COMMENT '初始随机属性 (英雄重置时需要)'; + +insert into version (version) values(2023062801); + +commit; diff --git a/webapp/controller/HeroController.class.php b/webapp/controller/HeroController.class.php index 229601a6..b0ba8dca 100644 --- a/webapp/controller/HeroController.class.php +++ b/webapp/controller/HeroController.class.php @@ -110,6 +110,9 @@ class HeroController extends BaseAuthedController { $this->_rspOk(); } + /* + 升级预览 + */ public function upgradeLevelPreview(){ $heroUniId = getReqVal('hero_uniid', 0); $heroDb = Hero::find($heroUniId); @@ -150,10 +153,8 @@ class HeroController extends BaseAuthedController { $heroDto = Hero::toDto($heroDb); $newHeroDto = $heroDto; $newHeroDto['hero_lv'] += 1; - $attrs_min = Hero::LvUpAddAttr($heroDb,\mt\HeroLevelAttr::MIN_RAND_ATTR); - $attrs_max = Hero::LvUpAddAttr($heroDb,\mt\HeroLevelAttr::MAX_RAND_ATTR); - $newHeroDto['rand_attr_min'] = $attrs_min; - $newHeroDto['rand_attr_max'] = $attrs_max; + $attrs_new = Hero::LvUpAddAttr($heroDb); + $newHeroDto['rand_attr'] = $attrs_new; $this->_rspData(array( 'old_hero' => $heroDto, @@ -162,6 +163,9 @@ class HeroController extends BaseAuthedController { )); } + /* + 英雄升级 + */ public function upgradeLv() { $heroUniId = getReqVal('hero_uniid', 0); @@ -225,7 +229,7 @@ class HeroController extends BaseAuthedController { Bag::decItem($piece_item_id,$nextLevelMeta['piece']); Bag::decItem(V_ITEM_HERO_META,$nextLevelMeta['serum']); - $attrs = Hero::LvUpAddAttr($heroDb,\mt\HeroLevelAttr::FINAL_RAND_ATTR); + $attrs = Hero::LvUpAddAttr($heroDb); Hero::update($heroUniId, array( 'hero_lv' => $heroDb['hero_lv'] + 1, 'rand_attr' => json_encode($attrs), @@ -247,6 +251,9 @@ class HeroController extends BaseAuthedController { )); } + /* + 英雄预设 + */ public function presetHero(){ $heroUid = getReqVal('hero_uid',0); $heroDb = Hero::find($heroUid); @@ -260,6 +267,9 @@ class HeroController extends BaseAuthedController { )); } + /* + 应用预设 + */ public function applyHero(){ $heroId = getReqVal('hero_uid',0); $chipPageId = getReqVal('chip_page',0); @@ -303,6 +313,9 @@ class HeroController extends BaseAuthedController { )); } + /* + 英雄碎片合成 + */ public function heroPieceSys(){ $itemId = getReqVal('item_id',0); $pieceNum = \mt\Parameter::getVal('hero_piece_synthesis_num',0); @@ -320,14 +333,36 @@ class HeroController extends BaseAuthedController { $heroMeta = \mt\Item::get($itemMeta['relationship']); Bag::decItem($itemId,$pieceNum); Hero::addHero($heroMeta); + $heroIdx = SqlHelper::getLastInsertId($this->_getSelfMysql()); + $heroInfo = Hero::toDto(Hero::find($heroIdx)); $propertyChgService = new services\PropertyChgService(); $propertyChgService->addHeroChg(); $propertyChgService->addBagChg(); $this->_rspData(array( - 'hero_id' => $heroMeta['id'], + 'hero' => $heroInfo, 'property_chg' => $propertyChgService->toDto(), )); } + /* + 英雄重置 + */ + public function heroResetLevel(){ + + } + + /* + 英雄分解 + */ + public function heroSalvage(){ + + } + + /* + 英雄融合 + */ + public function heroMerge(){ + + } } diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index 5146b4af..a71fcd51 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -221,10 +221,10 @@ class Hero extends BaseModel { public static function toDto($row) { $attr = emptyReplace(json_decode($row['rand_attr'], true), array()); - if (!$attr){ - $heroMeta = mt\Hero::get($row['hero_id']); - $attr = mt\Hero::getHeroAttr($heroMeta); - } +// if (!$attr){ +// $heroMeta = mt\Hero::get($row['hero_id']); +// $attr = mt\Hero::getHeroAttr($heroMeta); +// } // $lockType = 0; // $unlockTime = 0; @@ -332,7 +332,7 @@ class Hero extends BaseModel { } } $realHeroMeta = mt\Hero::get($heroMeta['id']); - $randAttr = array(); + $randAttr = self::getRandAttr($heroMeta['id']) ; $fieldsKv = array( 'hero_id' => $heroMeta['id'], 'hero_lv' => 1, @@ -346,6 +346,7 @@ class Hero extends BaseModel { 'unlock_time' => 0, 'unlock_trade_time' => 0, 'activate' => 1, + 'base_attr' => json_encode($randAttr), 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ); @@ -363,6 +364,54 @@ class Hero extends BaseModel { ); } + private static function getRandAttr($heroId){ + $heroMeta = mt\Hero::get($heroId); + $baseAttr = mt\Hero::getHeroAttr($heroMeta); + $paramMeta = mt\Parameter::getVal('quality',0); + $attr = array(); + if ($paramMeta){ + $rate = explode('|',$paramMeta); + $minRate = $rate[0]*100; + $maxRate = $rate[count($rate)-1]*100; + foreach ($baseAttr as $value){ + if (in_array($value['attr_id'],array(kHAT_Hp,kHAT_Atk,kHAT_Def))){ + $finalRate = rand($minRate,$maxRate) / 100; + $quality = 0; + for ($i=0;$i=$rate[$i] && $finalRate<$rate[$i+1]){ + $quality = $i+1; + } + if ($finalRate == $rate[count($rate)-1]){ + $quality = count($rate)-1; + } + } + if ( $value['attr_id'] == kHAT_Hp){ + $attr_val = round($value['val'] * $finalRate,0); + }else{ + $attr_val = round($value['val'] * $finalRate,2); + } + + array_push($attr,array( + 'attr_id' => $value['attr_id'], + 'val' => $attr_val, + 'quality' => $quality, +// 'rate' => $finalRate, + ) + ); + } else { + array_push($attr,array( + 'attr_id' => $value['attr_id'], + 'val' => $value['val'] , + 'quality' => 0, + ) + ); + } + } + + } + return $attr; + } + public static function update($heroUniId, $fieldsKv) { @@ -584,49 +633,26 @@ class Hero extends BaseModel { return $hero; } - public static function LvUpAddAttr($heroDb,$type){ - if ($heroDb['hero_lv'] == 1){ - $heroMeta = mt\Hero::get($heroDb['hero_id']); - $baseAttr = mt\Hero::getHeroAttr($heroMeta); - }else{ - $baseAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array()); - } + public static function LvUpAddAttr($heroDb){ + $randAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array()); $heroLevelMeta = \mt\HeroLevel::getByLevel($heroDb['hero_lv']+1); $levelAttrMeta= \mt\HeroLevelAttr::find($heroDb['hero_id']); - $attr= \mt\HeroLevelAttr::addRandAttr($levelAttrMeta,$type); - $randAttr = array(); - foreach ($baseAttr as $val){ - foreach ($attr as $v){ - if ($val['attr_id'] == $v['attr_id'] && $val['attr_id'] == kHAT_Def){ - //随机权重值*((防御力基础值+200)*pow((提升幅度+1),防御力系数)-200)+(1-随机权重值)*防御力基础值 - $temp = $v['val']*(($val['val']+200)*pow(($heroLevelMeta['promote']+1),$levelAttrMeta['def_rate'])-200)+(1-$v['val'])*$val['val']; - array_push($randAttr,array( - 'attr_id' => $v['attr_id'], - 'val' => sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1)), -// 'val' => $temp, +// $attr= \mt\HeroLevelAttr::addRandAttr($levelAttrMeta,$type); + foreach ($randAttr as &$val){ + if ($val['attr_id'] == kHAT_Def){ + //升级后防御力:上一级防御力*((提升幅度+1)^防御力系数) + $temp = $val['val'] * (pow(($heroLevelMeta['promote']+1),$levelAttrMeta['def_rate'])); + $val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1)); - )); - }else if($val['attr_id'] == $v['attr_id'] && $val['attr_id'] == kHAT_Hp){ - //生命基础值 * ((pow((提升幅度+1),生命值系数)-1)*随机权重值+1) - $temp = $val['val'] * ((pow(($heroLevelMeta['promote']+1),$levelAttrMeta['hp_rate'])-1)*$v['val']+1); - array_push($randAttr,array( - 'attr_id' => $v['attr_id'], - 'val' => sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1)), -// 'val' => $temp, - )); - }else if($val['attr_id'] == $v['attr_id'] && $val['attr_id'] == kHAT_Atk){ - //攻击力基础值 * ((pow((提升幅度+1),攻击力系数)-1)*随机权重值+1) - $temp = $val['val'] * ((pow(($heroLevelMeta['promote']+1),$levelAttrMeta['atk_rate'])-1)*$v['val']+1); - array_push($randAttr,array( - 'attr_id' => $v['attr_id'], - 'val' => sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1)), -// 'val' => $temp, - )); + }else if( $val['attr_id'] == kHAT_Hp){ + //升级后生命值:上一级生命值*((提升幅度+1)^生命值系数) + $temp = $val['val'] * (pow(($heroLevelMeta['promote']+1),$levelAttrMeta['hp_rate'])); + $val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1)); + }else if( $val['attr_id'] == kHAT_Atk){ + //升级后攻击力:上一级攻击力*((提升幅度+1)^攻击力系数) + $temp = $val['val'] * (pow(($heroLevelMeta['promote']+1),$levelAttrMeta['atk_rate'])); + $val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1)); } - } - if (!in_array($val['attr_id'],array(kHAT_Hp,kHAT_Atk,kHAT_Def))){ - array_push($randAttr,$val); - } } return $randAttr; }