修改英雄升级升阶功能

This commit is contained in:
hujiabin 2022-09-07 11:43:04 +08:00
parent a396cbdbab
commit 9c6af771c2
13 changed files with 582 additions and 216 deletions

View File

@ -72,9 +72,9 @@ class Battle(object):
]
},
{
'desc': '获取战斗数据(客户端不用处理)getBattleData',
'desc': '获取战斗数据(客户端不用处理)getBattleDataNew',
'group': 'Battle',
'url': 'webapp/index.php?c=Battle&a=getBattleData',
'url': 'webapp/index.php?c=Battle&a=getBattleDataNew',
'params': [
_common.ReqHead(),

View File

@ -71,7 +71,6 @@ class Hero(object):
_common.ReqHead(),
['hero_uniid', 0, '英雄唯一id'],
['slot_id', 0, '槽id(0-1)'],
['cost_item_id', 0, '支付方式'],
],
'response': [
_common.RspHead(),

View File

@ -2,11 +2,13 @@
require_once('models/Hero.php');
require_once('models/Gun.php');
require_once('models/Chip.php');
require_once('services/BattleDataService.php');
use phpcommon\SqlHelper;
use models\Hero;
use models\Gun;
use models\Chip;
class BattleController extends BaseAuthedController {
@ -97,4 +99,59 @@ class BattleController extends BaseAuthedController {
myself()->_rspData($data);
}
public function getBattleDataNew()
{
$members = json_decode(getReqVal('members', ''), true);
$data = array(
'members' => array()
);
foreach ($members as $member) {
$info = array(
'account_id' => $member['account_id'],
'session_id' => $member['session_id'],
'hero_uniid' => $member['hero_uniid'],
'weapon_uniid1' => $member['weapon_uniid1'],
'weapon_uniid2' => $member['weapon_uniid2'],
'battle_uuid' => $member['battle_uuid'],
'hero_dto' => '',
'weapon_dto1' => '',
'weapon_dto2' => '',
'is_valid_battle' => 0,
'payload' => json_encode($member['cmjoin']),
'errcode' => 0,
'errmsg' => '',
);
if (!phpcommon\isValidSessionId($member['account_id'], $member['session_id'])) {
$info['errcode'] = 50;
$info['errmsg'] = 'invalid session_id';
}else{
{
$heroDb = Hero::findByAccountId($member['account_id'],
$member['hero_uniid']);
if ($heroDb) {
$info['is_valid_battle'] = 1;
$info['hero_dto'] = Hero::toDto($heroDb);
} else {
$info['errcode'] = 51;
$info['errmsg'] = 'paramater error';
}
}
{
for ($i = 1; $i <= 2; ++$i) {
$gunDb = Gun::findByAccountId($member['account_id'],
$member['weapon_uniid' . $i]);
if ($gunDb) {
$info['weapon_dto' . $i] = Gun::toDto($gunDb);
}
}
}
}
array_push($data['members'], $info);
}
// $attr = Hero::getChipAttr($info['hero_dto']['chip_ids']);
myself()->_rspData($data);
}
}

View File

@ -6,6 +6,7 @@ require_once('models/Gun.php');
require_once('models/User.php');
require_once('mt/ChipAttr.php');
require_once('services/FormulaService.php');
require_once('phpcommon/tglog.php');
use models\Chip;
@ -14,6 +15,7 @@ use models\Gun;
use models\User;
use services\NftService;
use phpcommon\SqlHelper;
use phpcommon\TGLog;
class ChipController extends BaseAuthedController
{
@ -103,17 +105,13 @@ class ChipController extends BaseAuthedController
if (! $this->_doInlayHero($unique_id,$token_id)){
return;
}
$hero = $this->_inLayNewAttr($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$hero['chip_core'] = $chip_core;
$hero = Hero::toDto(Hero::find($unique_id));
$this->_rspData(['data'=>$hero]);
}else{
if (! $this->_doInlayGun($unique_id,$token_id)){
return;
}
$gun = $this->_inLayNewAttrGun($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$gun['chip_core'] = $chip_core;
$gun = Gun::toDto(Gun::find($unique_id));
$this->_rspData(['data'=>$gun]);
}
@ -131,17 +129,13 @@ class ChipController extends BaseAuthedController
if (!$this->_doDemount($unique_id,$token_id)){
return;
}
$hero = $this->_inLayNewAttr($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$hero['chip_core'] = $chip_core;
$hero = Hero::toDto(Hero::find($unique_id));
$this->_rspData(['data'=>$hero]);
}else{
if (! $this->_doDemountGun($unique_id,$token_id)){
return;
}
$gun = $this->_inLayNewAttrGun($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$gun['chip_core'] = $chip_core;
$gun = Gun::toDto(Gun::find($unique_id));
$this->_rspData(['data'=>$gun]);
}
@ -163,9 +157,7 @@ class ChipController extends BaseAuthedController
if (! $this->_doInlayHero($unique_id,$token_id_new)){
return;
}
$hero = $this->_inLayNewAttr($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$hero['chip_core'] = $chip_core;
$hero = Hero::toDto(Hero::find($unique_id));
$this->_rspData(['data'=>$hero]);
}else{
if (! $this->_doDemountGun($unique_id,$token_id_old)){
@ -174,9 +166,7 @@ class ChipController extends BaseAuthedController
if (! $this->_doInlayGun($unique_id,$token_id_new)){
return;
}
$gun = $this->_inLayNewAttrGun($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$gun['chip_core'] = $chip_core;
$gun = Gun::toDto(Gun::find($unique_id));
$this->_rspData(['data'=>$gun]);
}
@ -232,17 +222,13 @@ class ChipController extends BaseAuthedController
foreach ($res as $val){
$this->_doInlayHero($unique_id,$val['token_id']);
}
$hero_new = $this->_inLayNewAttr($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$hero_new['chip_core'] = $chip_core;
$hero_new = Hero::toDto(Hero::find($unique_id));
$this->_rspData(['data'=>$hero_new]);
}else{
foreach ($res as $val){
$this->_doInlayGun($unique_id,$val['token_id']);
}
$gun_new = $this->_inLayNewAttrGun($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$gun_new['chip_core'] = $chip_core;
$gun_new = Gun::toDto(Gun::find($unique_id));
$this->_rspData(['data'=>$gun_new]);
}
}
@ -479,6 +465,7 @@ class ChipController extends BaseAuthedController
// 'token_type' =>3,
// )
// );
// print_r($nft_active);die;
// foreach ($nft_active as $item){
// $chip = Chip::getChipByTokenId($item['token_id']);
// if ($chip['chip_type'] == 1){
@ -490,6 +477,8 @@ class ChipController extends BaseAuthedController
// Chip::update($chip['token_id'],['strength'=>$tili]);
// }
// $this->_rspOk();
}

View File

@ -54,44 +54,6 @@ class GunController extends BaseAuthedController {
return;
}
$gun = Gun::toDto($gunDb);
$chipAttr = [];
$chipIdsArr = explode('|',$gun['chip_ids']);
foreach ($chipIdsArr as $val){
$chip = Chip::toDto(Chip::getChipByIdx($val));
foreach ($chip['rand_attr'] as $v){
array_push($chipAttr,$v);
}
}
$item = [];
foreach ($chipAttr as $k=>$v){
if (!isset($item[$v['attr_id']])){
$item[$v['attr_id']] = $v;
}else{
$item[$v['attr_id']]['val']+= $v['val'];
}
}
$gun['attr_chip'] = $item;//芯片属性
$chipCore = [];
if (count($chipIdsArr) == 4){
$min = 15;
foreach ($chipIdsArr as $val){
$chip = Chip::getChipByIdx($val);
if ($chip['chip_grade']<$min){
$min = $chip['chip_grade'];
}
}
$chipCoreList = getMetaTable('chipCore@chipCore.php');
foreach ($chipCoreList as $val){
if ($val['chip_core_type']==2 && $val['chip_core_lv']<=$min){
array_push($chipCore,$val);
}
}
$gun['chip_core'] = $chipCore;
}else{
$gun['chip_core'] = [];
}
$this->_rspData(array(
'data' => $gun
));

View File

@ -53,44 +53,8 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(1, "You don't have the hero yet");
return;
}
$chipAttr = [];
$hero = Hero::toDto($heroDb);
$chipIdsArr = explode('|',$hero['chip_ids']);
foreach ($chipIdsArr as $val){
$chip = Chip::toDto(Chip::getChipByIdx($val));
foreach ($chip['rand_attr'] as $v){
array_push($chipAttr,$v);
}
}
$item = [];
foreach ($chipAttr as $k=>$v){
if (!isset($item[$v['attr_id']])){
$item[$v['attr_id']] = $v;
}else{
$item[$v['attr_id']]['val']+= $v['val'];
}
}
$hero['attr_chip'] = $item;//芯片属性
$chipCore = [];
if (count($chipIdsArr) == 4){
$min = 15;
foreach ($chipIdsArr as $val){
$chip = Chip::getChipByIdx($val);
if ($chip['chip_grade']<$min){
$min = $chip['chip_grade'];
}
}
$chipCoreList = getMetaTable('chipCore@chipCore.php');
foreach ($chipCoreList as $val){
if ($val['chip_core_type']==1 && $val['chip_core_lv']<=$min){
array_push($chipCore,$val);
}
}
$hero['chip_core'] = $chipCore;
}else{
$hero['chip_core'] = [];
}
$hero = Hero::toDto($heroDb);
$this->_rspData(array(
'data' => $hero
));
@ -274,6 +238,7 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(1, 'Countdown is not over');
return;
}
$oldHero = $heroDto;
$newHero = $heroDto;
switch ($type) {
@ -289,6 +254,7 @@ class HeroController extends BaseAuthedController {
break;
}
}
if (!$found) {
$this->_rspErr(1, 'hero does not exist2');
return;
@ -298,20 +264,36 @@ class HeroController extends BaseAuthedController {
$propertyChgService->addHeroChg();
$propertyChgService->addBagChg();
$propertyChgService->addUserChg();
$currLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv']);
if ($currLevelMeta) {
$nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv'] + 1);
$attrs = $heroDto['attr'];
mt\HeroLevelAttr::addRandAttr($heroDb['hero_lv'] + 1, $attrs);
// $currLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv']);
// if ($currLevelMeta) {
$nextLevelMeta = null;
$nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1);
$attrs = mt\HeroLevelAttr::addRandAttrNew($heroDb);
if ($nextLevelMeta) {
Hero::update($heroUniId,
array(
'hero_lv' => $heroDb['hero_lv'] + 1,
'rand_attr' => json_encode($attrs),
'lock_type' => 0,
'unlock_time' => 0,
)
$where = array(
'hero_lv' => $heroDb['hero_lv'] + 1,
'rand_attr' => json_encode($attrs),
'lock_type' => 0,
'unlock_time' => 0,
'skill_points' => $heroDb['skill_points']+$nextLevelMeta['skill_point']
);
//免费英雄到底15级后生成NFT
// if ($heroDb['hero_lv'] + 1 == 15 && !$heroDb['token_id']){
// $token_id = myself()->_getNowTime();
// if(!\services\NftService::addNft($heroDb['hero_id'],$token_id)){
// return ;
// }
// $where = array(
// 'hero_lv' => $heroDb['hero_lv'] + 1,
// 'token_id'=> $token_id,
// 'rand_attr' => json_encode($attrs),
// 'lock_type' => 0,
// 'unlock_time' => 0,
// 'skill_points' => $heroDb['skill_points']+$nextLevelMeta['skill_point']
// );
// }
Hero::update($heroUniId, $where);
if ($heroDb['hero_lv'] + 1 > myself()->_getV(TN_HERO_MAX_LEVEL, 0)) {
myself()->_setV(TN_HERO_MAX_LEVEL, 0, $heroDb['hero_lv'] + 1);
}
@ -320,7 +302,7 @@ class HeroController extends BaseAuthedController {
$rankActivityService = new services\RankActivityService();
$rankActivityService->heroUpgradeLevel($heroDb['hero_lv'] + 1);
}
}
// }
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'old_hero' => $oldHero,
@ -351,14 +333,14 @@ class HeroController extends BaseAuthedController {
$propertyChgService->addHeroChg();
$propertyChgService->addBagChg();
$propertyChgService->addUserChg();
$currQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']);
// $currQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']);
$nextQualityMeta = null;
if ($currQualityMeta) {
// if ($currQualityMeta) {
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
if ($nextQualityMeta) {
$rnd = rand(1, 100);
//$rnd = 1000;
if ($rnd > $nextQualityMeta['success_rate']) {
$probability = \services\FormulaService::Hero_Advanced_Probability($heroDb['quality'] + 1)*100;
if ($rnd > $probability) {
Hero::update($costHeroUniId,
array(
'lock_type' => 0,
@ -385,8 +367,12 @@ class HeroController extends BaseAuthedController {
));
return;
}
$heroLucky = \services\FormulaService::Hero_Advanced_Lucky_Value($heroDb['quality'] + 1);
$heroTili = \services\FormulaService::Hero_NFT_Maximum_Physical_Strength($heroDb['quality'] + 1,$heroLucky);
Hero::update($heroUniId,
array(
'hero_tili' => $heroTili,
'skill_points' => $heroDb['skill_points'] + $nextQualityMeta['skill_point'],
'quality' => $heroDb['quality'] + 1,
'advanced_count' => $heroDb['advanced_count'] + 1,
'lock_type' => 0,
@ -412,7 +398,7 @@ class HeroController extends BaseAuthedController {
$rankActivityService = new services\RankActivityService();
$rankActivityService->heroUpgradeQuality($heroDb['quality'] + 1);
}
}
// }
if (!$nextQualityMeta) {
$this->_rspErr(1, 'quality is full');
return;
@ -436,7 +422,6 @@ class HeroController extends BaseAuthedController {
public function upgradeLevel()
{
$costItemId = getReqVal('cost_item_id', 0);
$heroUniId = getReqVal('hero_uniid', 0);
$slotId = getReqVal('slot_id', 0);
$heroDb = Hero::find($heroUniId);
@ -455,14 +440,7 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(1, 'hero does not exist');
return;
}
if ($heroDb['state'] != Hero::GETED_STATE) {
$this->_rspErr(3, 'Trial hero cannot operate');
return;
}
if ($heroDb['unlock_time'] > $this->_getNowTime()) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
}
if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
@ -472,57 +450,48 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(100, 'server internal error');
return;
}
$currLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv']);
if (!$currLevelMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv'] + 1);
// $currLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv']);
// if (!$currLevelMeta) {
// $this->_rspErr(100, 'server internal error');
// return;
// }
$nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
}
$costItems = array();
switch ($costItemId) {
case V_ITEM_GOLD:
{
if ($heroDb['hero_lv']+1 <15){
$costItems = array(
array(
'item_id' => $costItemId,
'item_num' => $nextLevelMeta['gold']
'item_id' => V_ITEM_GOLD,
'item_num' => \services\FormulaService::Hero_Upgrade_CEG_Expend($heroDb['hero_lv']+1)
)
);
}else{
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => \services\FormulaService::Hero_Upgrade_CEG_Expend($heroDb['hero_lv']+1)
),
array(
'item_id' => V_ITEM_DIAMOND,
'item_num' => \services\FormulaService::Hero_Upgrade_CEC_Expend($heroDb['hero_lv']+1)
)
);
}
break;
case V_ITEM_DIAMOND:
{
$costItems = array(
array(
'item_id' => $costItemId,
'item_num' => $nextLevelMeta['diamond']
)
);
}
break;
default:
{
$this->_rspErr(2, 'Payment method not supported');
return;
}
break;
}
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$this->_decItems($costItems);
{
Hero::update(
$heroUniId,
array(
'lock_type' => Hero::LEVEL_LOCK,
'unlock_time' => $this->_getNowTime() + $nextLevelMeta['time'],
'lock_type' => Hero::LEVEL_LOCK
)
);
}
@ -538,7 +507,6 @@ class HeroController extends BaseAuthedController {
public function upgradeQuality()
{
$costItemId = getReqVal('cost_item_id', 0);
$costHeroUniId = getReqVal('cost_hero_uniid', 0);
$heroUniId = getReqVal('hero_uniid', 0);
$slotId = getReqVal('slot_id', 0);
@ -547,6 +515,11 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
if (!$heroDb['token_id']){
$this->_rspErr(100, 'Free heroes cannot quality up');
return;
}
$costHeroDb = Hero::find($costHeroUniId);
if (!$costHeroDb) {
$this->_rspErr(1, 'cost hero parameter error');
@ -604,50 +577,32 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(100, 'server internal error');
return;
}
$currQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']);
if (!$currQualityMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
// $currQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']);
// if (!$currQualityMeta) {
// $this->_rspErr(100, 'server internal error');
// return;
// }
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
if (!$nextQualityMeta) {
$this->_rspErr(5, "It's already the highest level1");
$this->_rspErr(5, "It's already the highest quality");
return;
}
$nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv']);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level2");
return;
}
$costItems = array();
switch ($costItemId) {
case V_ITEM_GOLD:
{
$costItems = array(
array(
'item_id' => $costItemId,
'item_num' => $nextQualityMeta['gold']
)
);
}
break;
case V_ITEM_DIAMOND:
{
$costItems = array(
array(
'item_id' => $costItemId,
'item_num' => $nextQualityMeta['diamond']
)
);
}
break;
default:
{
$this->_rspErr(2, 'Payment method not supported');
return;
}
break;
}
// $nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv']);
// if (!$nextLevelMeta) {
// $this->_rspErr(5, "It's already the highest level2");
// return;
// }
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => \services\FormulaService::Hero_Advanced_CEG_Expend($heroDb['hero_lv']+1)
),
array(
'item_id' => V_ITEM_DIAMOND,
'item_num' => \services\FormulaService::Hero_Advanced_CEC_Expend($heroDb['hero_lv']+1)
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
@ -680,31 +635,37 @@ class HeroController extends BaseAuthedController {
public function upgradeQualityPreview()
{
$heroUniId = getReqVal('hero_uniid', 0);
$costHeroUniId = getReqVal('cost_hero_uniid', 0);
$heroDb = Hero::find($heroUniId);
if (!$heroDb) {
$costHeroDb = Hero::find($costHeroUniId);
if (!$heroDb || !$costHeroDb) {
$this->_rspErr(100, 'server internal error');
return;
}
if (!$heroDb['token_id']){
$this->_rspErr(100, 'Free heroes cannot quality up');
return;
}
if ($heroDb['hero_id'] != $costHeroDb['hero_id']){
$this->_rspErr(100, 'You need the same kind of hero');
return;
}
if ($costHeroDb['quality']>1){
$this->_rspErr(100, 'Material hero quality too high');
return;
}
$heroMeta = mt\Hero::get($heroDb['hero_id']);
if (!$heroMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$currQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']);
if (!$currQualityMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
if (!$nextQualityMeta) {
$this->_rspErr(5, "It's already the highest level1");
return;
}
$nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv']);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level2");
return;
}
$newHeroDb = $heroDb;
$newHeroDb['quality'] += 1;
$heroDto = Hero::toDto($heroDb);
@ -716,4 +677,5 @@ class HeroController extends BaseAuthedController {
));
}
}

View File

@ -220,4 +220,49 @@ class Chip extends BaseModel
self::update($chip['token_id'],$fieldsKv);
}
public static function getChipAttr($chip_ids){
$data = ['attr_chip'=>[],'chip_core'=>[]];
if (! $chip_ids) {
return $data;
}
$chipAttr = [];
$chipIdsArr = explode('|',$chip_ids);
foreach ($chipIdsArr as $val){
$chip = self::toDto(self::getChipByIdx($val));
foreach ($chip['rand_attr'] as $v){
array_push($chipAttr,$v);
}
}
$item = [];
foreach ($chipAttr as $k=>$v){
if (!isset($item[$v['attr_id']])){
$item[$v['attr_id']] = $v;
}else{
$item[$v['attr_id']]['val']+= $v['val'];
}
}
$data['attr_chip'] = $item;
$chipCore = [];
if (count($chipIdsArr) == 4){
$min = 15;
foreach ($chipIdsArr as $val){
$chip = self::getChipByIdx($val);
if ($chip['chip_grade']<$min){
$min = $chip['chip_grade'];
}
}
$chipCoreList = getMetaTable('chipCore@chipCore.php');
foreach ($chipCoreList as $val){
if ($val['chip_core_type']==1 && $val['chip_core_lv']<=$min){
array_push($chipCore,$val);
}
}
$data['chip_core'] = $chipCore;
}else{
$data['chip_core'] = [];
}
return $data;
}
}

View File

@ -168,6 +168,8 @@ class Gun extends BaseModel {
'raw_pve_ceg_uplimit' => 0,
'attr_base' => $baseAttr,
'attr_pro' => $attr,
'attr_chip' => Chip::getChipAttr($row['chip_ids'])['attr_chip'],
'chip_core' => Chip::getChipAttr($row['chip_ids'])['chip_core'],
'try_count' => $row['try_count'],
'today_get_gold' => $todayGetGold,
'last_get_gold_time' => $lastGetGoldTime,

View File

@ -3,7 +3,7 @@
namespace models;
require_once('mt/Hero.php');
require_once('mt/HeroLevel.php');
require_once('mt/HeroLevelAttr.php');
require_once('mt/HeroQuality.php');
require_once('mt/AttrHelper.php');
require_once('mt/Item.php');
@ -12,12 +12,14 @@ require_once('models/HeroSkin.php');
require_once('services/NftService.php');
require_once('services/FormulaService.php');
use mt;
use phpcommon;
use phpcommon\SqlHelper;
use services\NftService;
use services\FormulaService;
class Hero extends BaseModel {
const GETED_STATE = 0;
@ -123,6 +125,7 @@ class Hero extends BaseModel {
public static function toDto($row)
{
$attr = emptyReplace(json_decode($row['rand_attr'], true), array());
$lockType = 0;
$unlockTime = 0;
/*if ($row['lock_type'] != 0 && $row['unlock_time'] - myself()->_getNowTime() > 0) {
@ -146,10 +149,21 @@ class Hero extends BaseModel {
$todayPveGetCeg = 0;
}
$baseAttr=[];
$attrPro=[];
$heroMeta = mt\Hero::get($row['hero_id']);
if ($heroMeta) {
$baseAttr = mt\Hero::getHeroAttr($heroMeta);
$attrPro1=[];
if ($row['hero_lv']>1){
$attrPro1 = self::getAttrProByLevel($row,$baseAttr,$attr);
}
$attrPro2=[];
if ($row['quality']>1){
$attrPro2 = self::getAttrProByQuality($row,$baseAttr);
}
$attrPro = self::mergeAttrPro($baseAttr,$attrPro1,$attrPro2);
}
$skill_common = explode("|",$row['skill_common']);
$attr_skill = [];
foreach ($skill_common as $val){
@ -158,7 +172,7 @@ class Hero extends BaseModel {
array_push($attr_skill,$item);
}
}
$heroLucky = $qualityMeta ? $qualityMeta['lucky'] : 0;
$heroLucky = \services\FormulaService::Hero_Advanced_Lucky_Value($row['quality']);
$dto = array(
'token_id' => $row['token_id'],
'hero_uniid' => $row['idx'],
@ -174,8 +188,10 @@ class Hero extends BaseModel {
'pve_ceg_uplimit' => 0,
'raw_pve_ceg_uplimit' => 0,
'attr_base' => $baseAttr,
'attr_pro' => $attr,
'attr_pro' => $attrPro,
'attr_skill' => $attr_skill,
'attr_chip' => Chip::getChipAttr($row['chip_ids'])['attr_chip'],
'chip_core' => Chip::getChipAttr($row['chip_ids'])['chip_core'],
'try_count' => $row['try_count'],
'lock_type' => $lockType,
'unlock_time' => $unlockTime,
@ -430,4 +446,78 @@ class Hero extends BaseModel {
return $locking;
}
private static function mergeAttrPro($baseAttr,$attrPro1,$attrPro2){
$newAttr = [];
$newAttrPro = [];
if ($attrPro1 && !$attrPro2){
$newAttrPro = $attrPro1;
}
if (!$attrPro1 && $attrPro2){
$newAttrPro = $attrPro2;
}
if ($attrPro1 && $attrPro2){
foreach ($attrPro1 as $value){
foreach ($attrPro2 as $val){
if ($value['attr_id'] == $val['attr_id']){
array_push($newAttr,
[
'attr_id' => $value['attr_id'],
'type' => $value['type'],
'val' => $value['val']+$val['val'],
]);
}
}
}
if ($newAttr){
foreach ($baseAttr as $value){
foreach ($newAttr as $val){
if ($value['attr_id'] == $val['attr_id']){
array_push($newAttrPro,
[
'attr_id' => $value['attr_id'],
'type' => $value['type'],
'val' => $val['val']-$value['val'],
]);
}
}
}
}
}
return $newAttrPro;
}
private static function getAttrProByLevel($row,$baseAttr,$attr){
$attrPro1 = [];
$coefficient_level = mt\HeroLevelAttr::getCoefficientByLevel($row['hero_lv'],$row['hero_id']);
foreach ($baseAttr as $val){
$coef_level = mt\HeroLevelAttr::getByCoefficient($coefficient_level,$val['attr_id']);
foreach ($attr as $v){
if ($val['attr_id'] == $v['attr_id']){
array_push($attrPro1,[
'attr_id' => $val['attr_id'],
'type'=> $val['type'],
'val' => $val['val']*pow($v['val'],$coef_level['val']),
]);
}
}
}
return $attrPro1;
}
private static function getAttrProByQuality($row,$baseAttr){
$attrPro2 = [];
$qualityMeta = mt\HeroQuality::getByQuality($row['quality']);
$coefficient_quality = mt\HeroQuality::getCoefficientByQuality($row['quality'],$row['hero_id']);
foreach ($baseAttr as $val){
$coef_quality = mt\HeroQuality::getByCoefficient($coefficient_quality,$val['attr_id']);
array_push($attrPro2,[
'attr_id' => $val['attr_id'],
'type'=> $val['type'],
'val' => $val['val']*pow(1+$qualityMeta['promote']/100,$coef_quality['val']),
]);
}
return $attrPro2;
}
}

View File

@ -4,16 +4,109 @@ namespace mt;
require_once('mt/StrHelper.php');
require_once('mt/AttrHelper.php');
require_once('mt/Hero.php');
use phpcommon;
class HeroLevelAttr {
private static $BASE_ATTR = [kHAT_Hp,kHAT_Atk,kHAT_Def,kHAT_Critical,kHAT_CriDamage,kHAT_Dodge,kHAT_Ruduce];
public static function get($id)
{
return getXVal(self::getMetaList(), $id);
}
public static function getByLevel($level)
{
self::mustBeLevelHash();
return getXVal(self::$levelHash, $level, null);
}
public static function getByCoefficient($data,$index)
{
self::mustBeCoefficientHash($data);
return getXVal(self::$coefficientHash, $index, null);
}
public static function getCoefficientByLevel($level,$hero_id){
$meta = self::getByLevel($level);
return [
[
'attr_id'=>kHAT_Hp,
'val' => self::_getCoefficient($meta,$hero_id,'hp_rate')
], [
'attr_id'=>kHAT_Atk,
'val' => self::_getCoefficient($meta,$hero_id,'atk_rate')
], [
'attr_id'=>kHAT_Def,
'val' => self::_getCoefficient($meta,$hero_id,'def_rate')
], [
'attr_id'=>kHAT_Critical,
'val' => self::_getCoefficient($meta,$hero_id,'crit_atk_rate')
], [
'attr_id'=>kHAT_CriDamage,
'val' => self::_getCoefficient($meta,$hero_id,'damage_rate')
], [
'attr_id'=>kHAT_Dodge,
'val' => self::_getCoefficient($meta,$hero_id,'miss_rate')
], [
'attr_id'=>kHAT_Ruduce,
'val' => self::_getCoefficient($meta,$hero_id,'ruduce_rate')
],
];
}
private static function _getCoefficient($meta,$hero_id,$title){
if ($meta[$title.'2']){
$item = explode('|',$meta[$title.'2']);
foreach ($item as $val){
$item_1 = explode(':',$val);
if ($item_1[0] == $hero_id){
return $item_1[1];
}
}
return $meta[$title];
}
return $meta[$title];
}
public static function addRandAttrNew($heroDb){
$heroMeta = Hero::get($heroDb['hero_id']);
$newAttrs = array();
if ($heroMeta) {
$meta = self::getByLevel($heroDb['hero_lv']+1);
foreach (self::$BASE_ATTR as $item){
$val = self::getAttrValue($meta);
array_push(
$newAttrs,
[
'attr_id' => $item,
'val' => $val,
]);
}
}
$rand_attr = $attr = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
if (!$rand_attr){
foreach ($newAttrs as $item){
array_push(
$rand_attr,
[
'attr_id' => $item['attr_id'],
'val' => 1+$item['val'],
]);
}
}else{
foreach ($rand_attr as &$item){
foreach ($newAttrs as $v){
if ($item['attr_id'] == $v['attr_id']){
$item['val'] = $item['val']*(1+$v['val']);
}
}
}
}
return $rand_attr;
}
public static function addRandAttr($level, &$dbAttrs)
{
$newAttrs = array();
@ -39,6 +132,7 @@ class HeroLevelAttr {
}
}
}
AttrHelper::mergeAttr($dbAttrs, $newAttrs);
return true;
}
@ -80,6 +174,29 @@ class HeroLevelAttr {
return self::$metaList;
}
protected static function mustBeLevelHash()
{
if (!self::$levelHash) {
self::$levelHash = array();
foreach (self::getMetaList() as $meta) {
self::$levelHash[$meta['level']] = $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 $levelHash;
protected static $coefficientHash;
}

View File

@ -17,6 +17,40 @@ class HeroQuality {
return getXVal(self::$qualityHash, $quality, null);
}
public static function getByCoefficient($data,$index)
{
self::mustBeCoefficientHash($data);
return getXVal(self::$coefficientHash, $index, null);
}
public static function getCoefficientByQuality($quality,$hero_id){
$meta = self::getByQuality($quality);
return [
[
'attr_id'=>kHAT_Hp,
'val' => self::_getCoefficient($meta,$hero_id,'hp_rate')
], [
'attr_id'=>kHAT_Atk,
'val' => self::_getCoefficient($meta,$hero_id,'atk_rate')
], [
'attr_id'=>kHAT_Def,
'val' => self::_getCoefficient($meta,$hero_id,'def_rate')
], [
'attr_id'=>kHAT_Critical,
'val' => self::_getCoefficient($meta,$hero_id,'crit_atk_rate')
], [
'attr_id'=>kHAT_CriDamage,
'val' => self::_getCoefficient($meta,$hero_id,'damage_rate')
], [
'attr_id'=>kHAT_Dodge,
'val' => self::_getCoefficient($meta,$hero_id,'miss_rate')
], [
'attr_id'=>kHAT_Ruduce,
'val' => self::_getCoefficient($meta,$hero_id,'ruduce_rate')
],
];
}
public static function getRandAttr($qualityMeta)
{
$nums = explode(':', $qualityMeta['rand_attrs_num']);
@ -38,6 +72,19 @@ class HeroQuality {
}
return $result;
}
private static function _getCoefficient($meta,$hero_id,$title){
if ($meta[$title.'2']){
$item = explode('|',$meta[$title.'2']);
foreach ($item as $val){
$item_1 = explode(':',$val);
if ($item_1[0] == $hero_id){
return $item_1[1];
}
}
return $meta[$title];
}
return $meta[$title];
}
protected static function getMetaList()
{
@ -57,7 +104,18 @@ class HeroQuality {
}
}
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;
}

View File

@ -277,6 +277,12 @@ class FormulaService extends BaseService {
return 1;
}
//CEC折扣比率
public static function CEC_Discount_Rate(){
//CEC_Discount_Rate=ROUND(CEC_Dynamic_Index /( CEC_Dynamic_Price / CEC_Base_Price),3)
return 1;
}
//英雄芯片劳力值
public static function Hero_Chip_Labor_Value(){
return 1;
@ -353,5 +359,52 @@ class FormulaService extends BaseService {
return round($tili*10*self::CEG_Discount_Rate());
}
//英雄NFT每次升级的CEG消耗公式
public static function Hero_Upgrade_CEG_Expend($grand){
//ROUND(43*ROUND(0.08*当前英雄等级^2+0.08*当前英雄等级+1,0)*CEG_Discount_Rate,0
return round(43*round(0.08*pow($grand,2)+0.08*$grand+1,0)*self::CEG_Discount_Rate(),0);
}
//英雄NFT每次升级的CEC消耗公式
public static function Hero_Upgrade_CEC_Expend($grand){
//ROUND (ROUND(0.09*单次CEG消耗,0)*SIGN(当前英雄等级>14)*CEC_Discount_Rate,2)
// return round(round(0.09*self::Hero_Upgrade_CEG_Expend($grand),0)*($grand>14?1:0)*self::CEC_Discount_Rate(),2);
//ROUND(ROUND(0.036*43*ROUND(0.08*当前英雄等级^2+0.08*当前英雄等级+1,0),0)*SIGN(player等级>14)*CEC_Discount_Rate,2)
return round(round(0.036*43*round(0.08*pow($grand,2)+0.08*$grand+1,0),0)*($grand>14?1:0)*self::CEC_Discount_Rate(),2);
}
//英雄NFT每次进阶的CEG消耗公式
public static function Hero_Advanced_CEG_Expend($quality){
//ROUND((ROUND(0.08*当前英雄阶数^2+0.08*当前英雄阶数+1,0)*10+100)*CEG_Discount_Rate,0)
return round((round(0.08*pow($quality,2)+0.08*$quality+1,0)*10+100)*self::CEG_Discount_Rate(),0);
}
//英雄NFT每次进阶的CEC消耗公式
public static function Hero_Advanced_CEC_Expend($quality){
//ROUND((ROUND(0.08*当前英雄阶数^2+0.08*当前英雄阶数+1,0)*1.5+10)*CEC_Discount_Rate,2)
// return round((round(0.08*pow($quality,2)+0.08*$quality+1,0)*1.5+10)*self::CEC_Discount_Rate(),2);
//ROUND((ROUND(0.08*player阶数^2+0.08*player阶数+1,0)*0.6+4)*CEC_Discount_Rate,2)
return round((round(0.08*pow($quality,2)+0.08*$quality+1,0)*0.6+4)*self::CEC_Discount_Rate(),2);
}
//英雄NFT每次进阶成功的概率公式
public static function Hero_Advanced_Probability($quality){
//SIGN(当前英雄阶数>9.5)*ROUND(0.0043*当前英雄阶数^2-0.144*当前英雄阶数+1.2629,2)+SIGN(当前英雄阶数<9.5)*ROUND(1.2-0.1*当前英雄阶数,2)
return ($quality>9.5?1:0)*round(0.0043*pow($quality,2)-0.144*$quality+1.2629,2)+($quality<9.5?1:0)*round(1.2-0.1*$quality,2);
}
//英雄NFT幸运值
public static function Hero_Advanced_Lucky_Value($quality){
//ROUND((0.0354*英雄NFT阶数^5-0.8464*英雄NFT阶数^4+10.907*英雄NFT阶数^3 -48.868*英雄NFT阶数^2+312.18*英雄NFT阶数-80)/10,1)*10
return round((0.0354*pow($quality,5)-0.8464*pow($quality,4)+10.907*pow($quality,3)-48.868*pow($quality,2)+312.18*$quality-80)/10,1)*10;
}
//英雄NFT最大体力值
public static function Hero_NFT_Maximum_Physical_Strength($quality,$lucky){
//英雄NFT幸运值*ROUND(1.1714+0.0286*当前英雄NFT阶数,3)
return $lucky*round(1.1714+0.0286*$quality,3);
}
}

View File

@ -3,8 +3,11 @@
namespace services;
require_once('models/Nft.php');
require_once('mt/Item.php');
use phpcommon\SqlHelper;
use models\Nft;
use mt\Item;
class NftService extends BaseService {
@ -76,4 +79,33 @@ class NftService extends BaseService {
}
}
public static function addNft($itemId,$token_id){
$itemMeta = Item::get($itemId);
if ($itemMeta) {
$tokenType = Nft::getTokenType($itemMeta);
if ($tokenType == Nft::NONE_TYPE) {
myself()->_rspErr(1, 'param item_id error');
return false;
} else {
SqlHelper::insert(
myself()->_getMarketMysql(),
't_nft',
array(
'token_id' => $token_id,
'token_type' => $tokenType,
'game_id' => 2006,
'item_id' => $itemId,
'owner_address' => myself()->_getOpenId(),
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
return true;
}
} else {
myself()->_rspErr(1, 'param item_id error');
return false;
}
}
}