修改hero升级公式
This commit is contained in:
parent
cd89285e1e
commit
41117704f3
@ -451,7 +451,7 @@ class BaseAuthedController extends BaseController {
|
||||
switch ($itemMeta['type']) {
|
||||
case mt\Item::HERO_TYPE:
|
||||
{
|
||||
$res = Hero::addHero($itemMeta);
|
||||
$res = Hero::addFreeHero($itemMeta);
|
||||
if ($res){
|
||||
$lastIdx = SqlHelper::getLastInsertId( myself()->_getSelfMysql());
|
||||
$awardService->addHero($item['item_id'],$lastIdx);
|
||||
|
@ -162,7 +162,7 @@ class HeroController extends BaseAuthedController {
|
||||
$heroDto = Hero::toDto($heroDb);
|
||||
$newHeroDto = $heroDto;
|
||||
$newHeroDto['hero_lv'] += 1;
|
||||
$attrs_new = Hero::LvUpAddAttr($heroDb);
|
||||
$attrs_new = Hero::nextLvAttr($heroDb);
|
||||
$newHeroDto['rand_attr'] = $attrs_new;
|
||||
$this->_rspData(array(
|
||||
|
||||
@ -249,7 +249,8 @@ class HeroController extends BaseAuthedController {
|
||||
$attrs = Hero::LvUpAddAttr($heroDb);
|
||||
Hero::update($heroUniId, array(
|
||||
'hero_lv' => $heroDb['hero_lv'] + 1,
|
||||
'rand_attr' => json_encode($attrs),
|
||||
'rand_attr' => json_encode($attrs['rand_attr']),
|
||||
'base_attr' => json_encode($attrs['base_attr']),
|
||||
'state' => Hero::GETED_STATE,
|
||||
));
|
||||
|
||||
@ -327,7 +328,8 @@ class HeroController extends BaseAuthedController {
|
||||
$attrs = Hero::LvUpAddAttr($heroDb);
|
||||
Hero::update($heroUniId, array(
|
||||
'hero_lv' => $heroDb['hero_lv'] + 1,
|
||||
'rand_attr' => json_encode($attrs),
|
||||
'rand_attr' => json_encode($attrs['rand_attr']),
|
||||
'base_attr' => json_encode($attrs['base_attr']),
|
||||
'state' => Hero::GETED_STATE,
|
||||
));
|
||||
|
||||
@ -346,7 +348,6 @@ class HeroController extends BaseAuthedController {
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
英雄预设
|
||||
*/
|
||||
|
@ -36,10 +36,12 @@ class Hero extends BaseModel {
|
||||
const QUALITY_LOCK = 2;
|
||||
const SEND_LOCK = 3;
|
||||
const COST_LOCK = 4;
|
||||
//需要材料所需等级
|
||||
const LV_1 = 4;
|
||||
const LV_2 = 9;
|
||||
const LV_3 = 14;
|
||||
//添加英雄方式
|
||||
const TYPE_FREE = 0; //免费英雄(D)
|
||||
const TYPE_1 = 1; //收费英雄(D~B)
|
||||
const TYPE_2 = 2; //收费英雄(C~A)
|
||||
const TYPE_3 = 3; //收费英雄(B~S)
|
||||
const TYPE_4 = 4; //收费英雄(D~S)
|
||||
|
||||
public static function find($heroUniId)
|
||||
{
|
||||
@ -318,7 +320,37 @@ class Hero extends BaseModel {
|
||||
$heroMeta,
|
||||
myself()->_getAccountId(),
|
||||
null,
|
||||
self::FREE_STATE);
|
||||
self::TYPE_FREE);
|
||||
}
|
||||
|
||||
public static function addHero1($heroMeta)
|
||||
{
|
||||
return self::internalAddHero(
|
||||
myself()->_getSelfMysql(),
|
||||
$heroMeta,
|
||||
myself()->_getAccountId(),
|
||||
null,
|
||||
self::TYPE_1);
|
||||
}
|
||||
|
||||
public static function addHero2($heroMeta)
|
||||
{
|
||||
return self::internalAddHero(
|
||||
myself()->_getSelfMysql(),
|
||||
$heroMeta,
|
||||
myself()->_getAccountId(),
|
||||
null,
|
||||
self::TYPE_2);
|
||||
}
|
||||
|
||||
public static function addHero3($heroMeta)
|
||||
{
|
||||
return self::internalAddHero(
|
||||
myself()->_getSelfMysql(),
|
||||
$heroMeta,
|
||||
myself()->_getAccountId(),
|
||||
null,
|
||||
self::TYPE_3);
|
||||
}
|
||||
|
||||
public static function addHero($heroMeta)
|
||||
@ -328,7 +360,7 @@ class Hero extends BaseModel {
|
||||
$heroMeta,
|
||||
myself()->_getAccountId(),
|
||||
null,
|
||||
self::GETED_STATE);
|
||||
self::TYPE_4);
|
||||
}
|
||||
|
||||
public static function addNftHero($heroMeta, $tokenId)
|
||||
@ -341,7 +373,7 @@ class Hero extends BaseModel {
|
||||
self::GETED_STATE);
|
||||
}
|
||||
|
||||
public static function internalAddHero($conn, $heroMeta, $accountId, $tokenId,$state)
|
||||
public static function internalAddHero($conn, $heroMeta, $accountId, $tokenId,$type)
|
||||
{
|
||||
// $skinItemMeta = \mt\Item::getMetaListByType(\mt\Item::HERO_SKIN_TYPE);
|
||||
// if ($skinItemMeta){
|
||||
@ -351,8 +383,9 @@ class Hero extends BaseModel {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
$state = $type > 0 ? self::GETED_STATE : self::FREE_STATE;
|
||||
$realHeroMeta = mt\Hero::get($heroMeta['id']);
|
||||
$randAttr = self::getRandAttr($heroMeta['id']) ;
|
||||
$randAttr = self::getRandAttr($heroMeta['id'],$type) ;
|
||||
$fieldsKv = array(
|
||||
'hero_id' => $heroMeta['id'],
|
||||
'hero_lv' => 1,
|
||||
@ -385,27 +418,65 @@ class Hero extends BaseModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static function getRandAttr($heroId){
|
||||
private static function _getAttrQuality($type){
|
||||
$quality = 0;
|
||||
switch ($type){
|
||||
case self::TYPE_FREE :{
|
||||
$quality = 1;
|
||||
}break;
|
||||
case self::TYPE_1 :{
|
||||
$paramMeta = mt\Parameter::getVal('small_box_quality',0);
|
||||
}break;
|
||||
case self::TYPE_2 :{
|
||||
$paramMeta = mt\Parameter::getVal('big_box_quality',0);
|
||||
}break;
|
||||
case self::TYPE_3 :{
|
||||
$paramMeta = mt\Parameter::getVal('super_box_quality',0);
|
||||
}break;
|
||||
case self::TYPE_4 :{
|
||||
$paramMeta = mt\Parameter::getVal('buy_hero_quality',0);
|
||||
}break;
|
||||
default:{
|
||||
$quality = 1;
|
||||
}
|
||||
}
|
||||
if (isset($paramMeta)){
|
||||
$weightArr = explode("|",$paramMeta);
|
||||
$totalWeight = 0;
|
||||
foreach ($weightArr as $value){
|
||||
$weights = explode(":",$value);
|
||||
$totalWeight += $weights[1];
|
||||
}
|
||||
$currWeight = 0;
|
||||
$rnd = rand() % $totalWeight;
|
||||
foreach ($weightArr as $value){
|
||||
$weights = explode(":",$value);
|
||||
$currWeight += $weights[1];
|
||||
if ($currWeight > $rnd) {
|
||||
$quality = $weights[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $quality;
|
||||
}
|
||||
|
||||
private static function getRandAttr($heroId,$type){
|
||||
$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;
|
||||
}
|
||||
$quality = self::_getAttrQuality($type);
|
||||
$minRate = $rate[$quality-1] * 100;
|
||||
$maxRate = $rate[$quality] * 100 - 1;
|
||||
if ($quality == 5){
|
||||
$maxRate = $rate[$quality] * 100;
|
||||
}
|
||||
$finalRate = rand($minRate,$maxRate) / 100;
|
||||
if ( $value['attr_id'] == kHAT_Hp){
|
||||
$attr_val = round($value['val'] * $finalRate,0);
|
||||
}else{
|
||||
@ -428,7 +499,6 @@ class Hero extends BaseModel {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $attr;
|
||||
}
|
||||
@ -582,7 +652,6 @@ class Hero extends BaseModel {
|
||||
return $locking;
|
||||
}
|
||||
|
||||
|
||||
public static function getFreeHero(){
|
||||
$hero = array();
|
||||
Hero::getHeroList(function ($row) use (&$hero) {
|
||||
@ -642,8 +711,6 @@ class Hero extends BaseModel {
|
||||
return $info;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function getHeroByItemId($itemId){
|
||||
$hero = array();
|
||||
self::getHeroList(function ($row) use (&$hero,$itemId) {
|
||||
@ -654,28 +721,133 @@ class Hero extends BaseModel {
|
||||
return $hero;
|
||||
}
|
||||
|
||||
public static function LvUpAddAttr($heroDb){
|
||||
public static function nextLvAttr($heroDb){ // 165 249 327
|
||||
$randAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
|
||||
$heroLevelMeta = \mt\HeroLevel::getByLevel($heroDb['hero_lv']+1);
|
||||
$levelAttrMeta= \mt\HeroLevelAttr::find($heroDb['hero_id']);
|
||||
// $levelAttrMeta= \mt\HeroLevelAttr::find($heroDb['hero_id']);
|
||||
// $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'] == 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_Def,
|
||||
kHAT_Hp,
|
||||
kHAT_Atk
|
||||
))){
|
||||
$temp = $val['val'] * ($heroLevelMeta['promote']+1);
|
||||
$val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1));
|
||||
}
|
||||
// if ($val['attr_id'] == kHAT_Def){
|
||||
// //升级后防御力:上一级防御力*((提升幅度+1)^防御力系数)
|
||||
// $temp = $val['val'] * (pow(($heroLevelMeta['promote']+1),$levelAttrMeta['def_rate']));
|
||||
//// $temp = $val['val'] * ($heroLevelMeta['promote']+1);
|
||||
// $val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1));
|
||||
//
|
||||
// }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));
|
||||
// }
|
||||
}
|
||||
return $randAttr;
|
||||
}
|
||||
|
||||
public static function LvUpAddAttr($heroDb){
|
||||
$heroMeta = mt\Hero::get($heroDb['hero_id']);
|
||||
$baseAttr = mt\Hero::getHeroAttr($heroMeta);
|
||||
$attrLv1 = emptyReplace(json_decode($heroDb['base_attr'], true), array());
|
||||
$randAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
|
||||
$paramQualityMeta = mt\Parameter::getVal('quality',0);
|
||||
$heroLevelMeta = \mt\HeroLevel::getByLevel($heroDb['hero_lv']+1);
|
||||
foreach ($randAttr as &$val){
|
||||
if (in_array($val['attr_id'],array(
|
||||
kHAT_Def,
|
||||
kHAT_Hp,
|
||||
kHAT_Atk
|
||||
))){
|
||||
switch ($val['quality']){
|
||||
case 1 :{
|
||||
$paramMeta = mt\Parameter::getVal('d_probability',0);
|
||||
}break;
|
||||
case 2 :{
|
||||
$paramMeta = mt\Parameter::getVal('c_probability',0);
|
||||
}break;
|
||||
case 3 :{
|
||||
$paramMeta = mt\Parameter::getVal('b_probability',0);
|
||||
}break;
|
||||
case 4 :{
|
||||
$paramMeta = mt\Parameter::getVal('a_probability',0);
|
||||
}break;
|
||||
default:{
|
||||
$temp = $val['val'] * ($heroLevelMeta['promote']+1);
|
||||
$val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1));
|
||||
}
|
||||
}
|
||||
$quality = $val['quality'];
|
||||
if (isset($paramMeta)){
|
||||
$weightArr = explode("|",$paramMeta);
|
||||
$totalWeight = 0;
|
||||
foreach ($weightArr as $value){
|
||||
$weights = explode(":",$value);
|
||||
$totalWeight += $weights[1];
|
||||
}
|
||||
$currWeight = 0;
|
||||
$rnd = rand() % $totalWeight;
|
||||
foreach ($weightArr as $value){
|
||||
$weights = explode(":",$value);
|
||||
$currWeight += $weights[1];
|
||||
if ($currWeight > $rnd) {
|
||||
$quality = $weights[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($val['quality'] != $quality){
|
||||
$rate = explode('|',$paramQualityMeta);
|
||||
$minRate = $rate[$quality-1] * 100;
|
||||
$maxRate = $rate[$quality] * 100 - 1;
|
||||
if ($quality == 5){
|
||||
$maxRate = $rate[$quality] * 100;
|
||||
}
|
||||
$finalRate = rand($minRate,$maxRate) / 100;
|
||||
$tempVal = round(self::_getAttrVal($baseAttr,$val['attr_id']) * $finalRate,2);
|
||||
$val['quality'] = $quality;
|
||||
$v = ($tempVal / self::_getAttrVal($attrLv1,$val['attr_id'])) * $val['val'] * (1 + $heroLevelMeta['promote']);
|
||||
$val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $v), 0, -1));
|
||||
self::_setAttrVal($attrLv1,$val['attr_id'],array(
|
||||
'val'=>$tempVal,
|
||||
'quality'=>$quality,
|
||||
));
|
||||
}else{
|
||||
$temp = $val['val'] * ($heroLevelMeta['promote']+1);
|
||||
$val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'base_attr' => $attrLv1,
|
||||
'rand_attr' => $randAttr,
|
||||
);
|
||||
}
|
||||
|
||||
private static function _getAttrVal($baseAttr,$attrId){
|
||||
$hashAttr = array();
|
||||
foreach ($baseAttr as $value){
|
||||
$hashAttr[$value['attr_id']] =$value;
|
||||
}
|
||||
return $hashAttr[$attrId]['val'];
|
||||
}
|
||||
|
||||
private static function _setAttrVal(&$baseAttr,$attrId,$attrVal){
|
||||
foreach ($baseAttr as &$value){
|
||||
if ($value['attr_id'] == $attrId){
|
||||
$value['val'] = $attrVal['val'];
|
||||
$value['quality'] = $attrVal['quality'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class LogService extends BaseService
|
||||
|
||||
public static function consumeDiamond($event,$param = [])
|
||||
{
|
||||
$logInfo = self::goldRecord();
|
||||
$logInfo = self::diamondRecord(myself()->_getAccountId());
|
||||
$data = self::userInfo();
|
||||
$data['type'] = self::CONSUME_TYPE;
|
||||
$data['event_name'] = $event['name'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user