修改英雄(合成、升级、获取)
This commit is contained in:
parent
472e75fa35
commit
6fc6162a56
@ -132,7 +132,7 @@ class Hero(object):
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['hero_id', 0, '英雄itemId']
|
||||
['!hero', [_common.Hero()], '英雄信息']
|
||||
]
|
||||
},
|
||||
|
||||
|
@ -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`)
|
||||
|
7
sql/gamedb2006_migrate_230628_01.sql
Normal file
7
sql/gamedb2006_migrate_230628_01.sql
Normal file
@ -0,0 +1,7 @@
|
||||
begin;
|
||||
|
||||
alter table t_hero add column `base_attr` mediumblob COMMENT '初始随机属性 (英雄重置时需要)';
|
||||
|
||||
insert into version (version) values(2023062801);
|
||||
|
||||
commit;
|
@ -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(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<count($rate)-1;$i++){
|
||||
if ($finalRate>=$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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user