game2006api/webapp/controller/HeroController.class.php
2022-11-09 17:32:44 +08:00

908 lines
34 KiB
PHP

<?php
require_once('mt/Shop.php');
require_once('mt/Hero.php');
require_once('mt/Item.php');
require_once('mt/HeroLevel.php');
require_once('mt/HeroLevelAttr.php');
require_once('mt/HeroQuality.php');
require_once('mt/AttrHelper.php');
require_once('mt/Parameter.php');
require_once('mt/SkillCommon.php');
require_once('mt/Skill.php');
require_once('models/Hero.php');
require_once('models/Bag.php');
require_once('models/HeroSkin.php');
require_once('models/Chip.php');
require_once('models/NftUpReceive.php');
require_once('services/AwardService.php');
require_once('services/PropertyChgService.php');
require_once('services/RankActivityService.php');
require_once('services/LogService.php');
use phpcommon\SqlHelper;
use models\Hero;
use models\Bag;
use models\HeroSkin;
use models\Chip;
use models\NftUpReceive;
use services\LogService;
class HeroController extends BaseAuthedController {
public function heroList()
{
$heroList = array();
Hero::getHeroList(function ($row) use(&$heroList) {
array_push($heroList, Hero::toDto($row));
});
$this->_rspData(array(
'hero_list' => $heroList
));
}
public function heroDetails()
{
$unique_id = trim(getReqVal('unique_id', 0));
if ( ! $unique_id) {
$this->_rspErr(1, 'Please enter instructions');
return;
}
$heroDb = Hero::find($unique_id);
if (! $heroDb){
$this->_rspErr(1, "You don't have the hero yet");
return;
}
$hero = Hero::toDto($heroDb);
$this->_rspData(array(
'data' => $hero
));
}
public function upgradeSkillCommon(){
$heroUniId = getReqVal('hero_uniid', 0);
$skillIndex = getReqVal('skill_index', 0);
$heroDb = Hero::find($heroUniId);
if (!$heroDb) {
$this->_rspErr(1, "You don't have the hero yet");
return;
}
$item = explode('|',$heroDb['skill_common']);
$skill_common = \mt\SkillCommon::get($item[$skillIndex]);
if (!$skill_common){
$this->_rspErr(1, "You don't have the skill yet");
return;
}
$next_skill_common = \mt\SkillCommon::get($skill_common['nextlv_skill']);
if (! $next_skill_common){
$this->_rspErr(1, "It's already the highest level");
return;
}
if($heroDb['quality'] < $next_skill_common['skill_limit_star']){
$this->_rspErr(1, "Hero level is not enough");
return;
}
if($heroDb['skill_points'] < $next_skill_common['skill_point_cost']){
$this->_rspErr(1, "Not enough hero skill points");
return;
}
$item[$skillIndex] = $skill_common['nextlv_skill'];
$where = [
'skill_common'=>implode('|',$item),
'skill_points'=>$heroDb['skill_points']-$next_skill_common['skill_point_cost'],
'modifytime' => $this->_getNowTime()
];
Hero::update($heroUniId, $where);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'propery_chg' => $propertyChgService->toDto(),
));
}
public function upgradeSkill()
{
$heroUniId = getReqVal('hero_uniid', 0);
$skillUniId = getReqVal('skill_uniid', 0);
$skillIdx = getReqVal('skill_idx', 0);
$heroDb = Hero::find($heroUniId);
if (!$heroDb) {
$this->_rspErr(1, "You don't have the hero yet");
return;
}
if (!in_array($skillIdx, array(0, 1))) {
$this->_rspErr(1, 'skill_idx must be 0-1');
return;
}
$skill = \mt\Skill::get($skillUniId);
if (!$skill){
$this->_rspErr(1, "You don't have the skill yet");
return;
}
$next_skill = \mt\Skill::get($skill['nextlv_skill']);
if (!$next_skill){
$this->_rspErr(1, "It's already the highest level");
return;
}
if($heroDb['quality'] < $next_skill['skill_limit_star']){
$this->_rspErr(1, "Hero level is not enough");
return;
}
if(! $heroDb['skill_points'] || $heroDb['skill_points'] < $next_skill['skill_point']){
$this->_rspErr(1, "Not enough hero skill points");
return;
}
Hero::upgradeSkill($heroUniId,$skillIdx);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'propery_chg' => $propertyChgService->toDto(),
));
}
public function skinList()
{
$skinList = array();
SqlHelper::ormSelect(
$this->_getSelfMysql(),
't_hero_skin',
array(
'account_id' => $this->_getAccountId()
),
function ($row) use(&$skinList) {
array_push($skinList, HeroSkin::toDto($row));
}
);
$this->_rspData(array(
'skin_list' => $skinList
));
}
public function takeonSkin()
{
$heroUniId = getReqVal('hero_uniid', 0);
$skinId = getReqVal('skin_id', 0);
$heroDb = Hero::find($heroUniId);
$heroSkinDb = HeroSkin::find($skinId);
if (!$heroDb) {
$this->_rspErr(1, "You don't have the hero yet");
return;
}
if (!$heroSkinDb) {
$this->_rspErr(2, "You don't have the skin yet");
return;
}
Hero::takeonSkin($heroUniId, $skinId);
$this->_rspOk();
}
public function getUpgradeLevelList()
{
$infos = array();
for ($i = 0; $i < kMaxHeroUpLevelNum; ++$i) {
$heroUniId = $this->_getV(TN_HERO_LEVEL_UP, $i);
$info = null;
if ($heroUniId) {
$heroDb = Hero::find($heroUniId);
if ($heroDb) {
$heroDto = Hero::toDto($heroDb);
$info = array(
'info' => $heroDto,
'countdown' => $heroDto['unlock_lefttime']
);
}
}
array_push($infos, $info);
}
$this->_rspData(array(
'infos' => $infos
));
}
public function getUpgradeQualityList()
{
// $infos = array();
// for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) {
// $heroUniId = $this->_getV(TN_HERO_QUALITY_UP, $i);
// $info = null;
// if ($heroUniId) {
// $heroDb = Hero::find($heroUniId);
// if ($heroDb) {
// $heroDto = Hero::toDto($heroDb);
// $info = array(
// 'info' => $heroDto,
// 'countdown' => $heroDto['unlock_lefttime']
// );
// }
// }
// array_push($infos, $info);
// }
// $this->_rspData(array(
// 'infos' => $infos
// ));
$list = NftUpReceive::all(myself()->_getAccountId(),1);
$infos = array();
foreach ($list as $value){
if ($this->_getNowTime() - $value['createtime'] < 24*3600 && !$value['from_data']){
$hero = Hero::findByTokenId2($value['token_id1']);
$costHero = Hero::findByTokenId2($value['token_id2']);
$heroDto = null;
$costHeroDto = null;
if ($hero && $costHero){
$heroDto = Hero::toDto($hero);
$costHeroDto = Hero::toDto($costHero);
}
$info = array(
'trans_id'=>$value['trans_id'],
'state'=>$value['state'],
'heroInfo'=>$heroDto,
'costHeroInfo'=>$costHeroDto,
);
array_push($infos,$info);
}
}
$this->_rspData(array(
'infos' => $infos
));
}
public function receive()
{
$type = getReqVal('type', 0);
$heroUniId = getReqVal('hero_uniid', 0);
$heroDb = Hero::find($heroUniId);
if (!$heroDb) {
$this->_rspErr(1, 'hero does not exist1');
return;
}
$heroDto = Hero::toDto($heroDb);
if ($heroDto['unlock_lefttime'] > 0) {
$this->_rspErr(1, 'Countdown is not over');
return;
}
$oldHero = $heroDto;
$newHero = $heroDto;
switch ($type) {
case 1:
{
$idx = 0;
$found = false;
for ($i = 0; $i < kMaxHeroUpLevelNum; ++$i) {
$upHeroUniId = $this->_getV(TN_HERO_LEVEL_UP, $i);
if ($upHeroUniId == $heroUniId) {
$idx = $i;
$found = true;
break;
}
}
if (!$found) {
$this->_rspErr(1, 'hero does not exist2');
return;
}
$this->_setV(TN_HERO_LEVEL_UP, $idx, 0);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$propertyChgService->addBagChg();
$propertyChgService->addUserChg();
$nextLevelMeta = null;
$nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1);
if ($nextLevelMeta) {
$attrs = mt\HeroLevelAttr::addRandAttrNew($heroDb,1);
$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);
}
$newHeroDb = Hero::find($heroUniId);
$newHero = Hero::toDto($newHeroDb);
$rankActivityService = new services\RankActivityService();
$rankActivityService->heroUpgradeLevel($heroDb['hero_lv'] + 1);
}
{
//埋点
$event = [
'name' => LogService::HERO_LEVEL_UP,
];
$oldHero['level'] = $oldHero['hero_lv'];
$oldHero['item_id'] = $oldHero['hero_id'];
$newHero['level'] = $newHero['hero_lv'];
$newHero['item_id'] = $newHero['hero_id'];
LogService::LevelUpOrQualityUp($event,$oldHero,$newHero);
}
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'old_hero' => $oldHero,
'new_hero' => $newHero,
));
}
break;
case 2:
{
$this->_rspOk();return;
$idx = 0;
$found = false;
for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) {
$upHeroUniId = $this->_getV(TN_HERO_QUALITY_UP, $i);
if ($upHeroUniId == $heroUniId) {
$idx = $i;
$found = true;
break;
}
}
if (!$found) {
$this->_rspErr(1, 'hero does not exist');
return;
}
$costHeroUniId = $this->_getV(TN_HERO_QUALITY_UP, (int)$idx + 1000);
$this->_setV(TN_HERO_QUALITY_UP, $idx, 0);
$this->_setV(TN_HERO_QUALITY_UP, (int)$idx + 1000, 0);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$propertyChgService->addBagChg();
$propertyChgService->addUserChg();
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
if ($nextQualityMeta) {
$costHeroDb = Hero::find($costHeroUniId);
if ($costHeroDb['token_id']){
// SqlHelper::update(
// myself()->_getMarketMysql(),
// 't_nft',
// ['token_id'=>$costHeroDb['token_id']],
// ['deleted'=>1]
// );
}else{
Hero::update($costHeroUniId,
array(
'account_id' => myself()->_getAccountId() . '!!!',
)
);
}
Hero::update($costHeroUniId,
array(
'lock_type' => 0,
'unlock_time' => 0,
)
);
{
//埋点
$event = [
'name' => LogService::HERO_QUALITY_UP_MATERIAL,
];
$params = array(
array(
'unique_id'=>$costHeroDb['idx'],
'token_id'=>$costHeroDb['token_id'],
)
);
LogService::ConsumableMaterial($event,$params);
}
$rnd = rand(1, 100);
$probability = \services\FormulaService::Hero_Advanced_Probability($heroDb['quality'] + 1)*100;
if ($rnd > $probability) {
Hero::update($heroUniId,
array(
'advanced_count' => $heroDb['advanced_count'] + 1,
'lock_type' => 0,
'unlock_time' => 0,
)
);
$oldHero['advanced_count'] += 1;
$newHero['advanced_count'] += 1;
{
//埋点
$event = [
'name' => LogService::HERO_QUALITY_UP,
];
$oldHero['level'] = $oldHero['hero_lv'];
$oldHero['item_id'] = $oldHero['hero_id'];
$newHero['level'] = $newHero['hero_lv'];
$newHero['item_id'] = $newHero['hero_id'];
LogService::LevelUpOrQualityUp($event,$oldHero,$newHero);
}
$this->_rspRawData(array(
'errcode' => 0,
'errmsg' => '',
'state' => 0,
'old_hero' => $oldHero,
'new_hero' => $newHero,
//'errmsg' => 'advance failed',
'property_chg' => $propertyChgService->toDto(),
));
return;
}
$heroLucky = \services\FormulaService::Hero_Advanced_Lucky_Value($heroDb['quality']);
$nextHeroLucky = \services\FormulaService::Hero_Advanced_Lucky_Value($heroDb['quality'] + 1);
$heroTili = \services\FormulaService::Hero_NFT_Maximum_Physical_Strength($heroDb['quality'],$heroLucky);
$nextHeroTili = \services\FormulaService::Hero_NFT_Maximum_Physical_Strength($heroDb['quality'] + 1,$nextHeroLucky);
Hero::update($heroUniId,
array(
'hero_tili' => $heroDb['hero_tili']+($nextHeroTili-$heroTili),
'skill_points' => $heroDb['skill_points'] + $nextQualityMeta['skill_point'],
'quality' => $heroDb['quality'] + 1,
'advanced_count' => $heroDb['advanced_count'] + 1,
'lock_type' => 0,
'unlock_time' => 0,
'labour' => 0,
)
);
if ($heroDb['quality'] + 1 > myself()->_getV(TN_HERO_MAX_QUALITY, 0)) {
myself()->_setV(TN_HERO_MAX_QUALITY, 0, $heroDb['quality'] + 1);
}
$newHeroDb = Hero::find($heroUniId);
$newHero = Hero::toDto($newHeroDb);
error_log(json_encode(array(
'costHeroUniId' => $costHeroUniId,
'heroUniId' => $heroUniId
)));
$rankActivityService = new services\RankActivityService();
$rankActivityService->heroUpgradeQuality($heroDb['quality'] + 1);
}
if (!$nextQualityMeta) {
$this->_rspErr(1, 'quality is full');
return;
}
{
//埋点
$event = [
'name' => LogService::HERO_QUALITY_UP,
];
$oldHero['level'] = $oldHero['hero_lv'];
$oldHero['item_id'] = $oldHero['hero_id'];
$newHero['level'] = $newHero['hero_lv'];
$newHero['item_id'] = $newHero['hero_id'];
LogService::LevelUpOrQualityUp($event,$oldHero,$newHero);
}
$this->_rspData(array(
'state' => 1,
'property_chg' => $propertyChgService->toDto(),
'old_hero' => $oldHero,
'new_hero' => $newHero,
));
}
break;
default:
{
$this->_rspErr(1, 'type parameter error');
return;
}
break;
}
}
public function upgradeLevel()
{
$heroUniId = getReqVal('hero_uniid', 0);
$slotId = getReqVal('slot_id', 0);
$heroDb = Hero::find($heroUniId);
if (!in_array($slotId, array(0, kMaxHeroUpLevelNum - 1))) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
{
$srcHeroDb = Hero::find($this->_getV(TN_HERO_LEVEL_UP, $slotId));
if ($srcHeroDb) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
}
if (!$heroDb) {
$this->_rspErr(1, 'hero does not exist');
return;
}
if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
}
$heroMeta = mt\Hero::get($heroDb['hero_id']);
if (!$heroMeta) {
$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;
}
if ($heroDb['hero_lv'] + 1 == 15 && !$heroDb['token_id']){
$this->_rspErr(1, "Free heroes cannot continue to level up");
return;
}
$is_cec = false;
if ($heroDb['hero_lv']+1 <15){
$costItems = array(
array(
'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)
)
);
$is_cec = true;
}
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$heroDto = Hero::toDto($heroDb);
{
//埋点
$eventCEG = [
'name' => LogService::HERO_LEVEL_UP_CONSUME,
'val' => \services\FormulaService::Hero_Upgrade_CEG_Expend($heroDb['hero_lv']+1)
];
$heroDto['level'] = $heroDto['hero_lv'];
$heroDto['item_id'] = $heroDto['hero_id'];
LogService::consumeCEG($eventCEG,$heroDto,$heroDto);
}
if ($is_cec){
{
//埋点
$eventCEC = [
'name' => LogService::HERO_LEVEL_UP_CONSUME,
'val' => \services\FormulaService::Hero_Upgrade_CEC_Expend($heroDb['hero_lv']+1)
];
$heroDto['level'] = $heroDto['hero_lv'];
$heroDto['item_id'] = $heroDto['hero_id'];
LogService::consumeCEC($eventCEC,$heroDto,$heroDto);
}
}
$this->_decItems($costItems);
{
Hero::update(
$heroUniId,
array(
'lock_type' => Hero::LEVEL_LOCK
)
);
}
$this->_setV(TN_HERO_LEVEL_UP, (int)$slotId, (int)$heroDb['idx']);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$propertyChgService->addBagChg();
$propertyChgService->addUserChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
));
}
public function upgradeLevelPreview(){
$heroUniId = getReqVal('hero_uniid', 0);
$heroDb = Hero::find($heroUniId);
if (!$heroDb) {
$this->_rspErr(1, 'hero does not exist');
return;
}
$heroMeta = mt\Hero::get($heroDb['hero_id']);
if (!$heroMeta) {
$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;
}
$newHeroDb = $heroDb;
$newHeroDb['hero_lv'] += 1;
$attrs = mt\HeroLevelAttr::addRandAttrNew($heroDb,0);
$newHeroDb['rand_attr'] = json_encode($attrs);
$cost['CEG'] = \services\FormulaService::Hero_Upgrade_CEG_Expend($newHeroDb['hero_lv']);
$cost['CEC'] = \services\FormulaService::Hero_Upgrade_CEC_Expend($newHeroDb['hero_lv']);
$heroDto = Hero::toDto($heroDb);
$newHeroDto = Hero::toDto($newHeroDb);
$this->_rspData(array(
'old_hero' => $heroDto,
'new_hero' => $newHeroDto,
'cost' => $cost
));
}
public function upgradeQualityOld()
{
$costHeroUniId = getReqVal('cost_hero_uniid', 0);
$heroUniId = getReqVal('hero_uniid', 0);
$slotId = getReqVal('slot_id', 0);
$heroDb = Hero::find($heroUniId);
if (!in_array($slotId, array(0, kMaxHeroUpQualityNum - 1))) {
$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');
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;
}
if ($costHeroDb['lock_type']) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
}
{
$srcHeroDb = Hero::find($this->_getV(TN_HERO_QUALITY_UP, $slotId));
if ($srcHeroDb) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
}
{
$idx = 0;
$found = false;
for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) {
$upHeroUniId = $this->_getV(TN_HERO_QUALITY_UP, $i);
if ($upHeroUniId == $heroUniId) {
$idx = $i;
$found = true;
break;
}
}
if ($found) {
$this->_rspErr(1, 'hero already upgrading');
return;
}
}
if (!$heroDb) {
$this->_rspErr(1, 'hero does not exist');
return;
}
if ($heroDb['advanced_count'] >= mt\Parameter::getVal('advence_limit', 0)) {
$this->_rspErr(1, 'hero does not exist');
return;
}
if ($heroDb['state'] != Hero::GETED_STATE) {
$this->_rspErr(3, 'Trial hero cannot operate');
return;
}
if ($heroDb['lock_type']) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
}
if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
}
$heroMeta = mt\Hero::get($heroDb['hero_id']);
if (!$heroMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
if (!$nextQualityMeta) {
$this->_rspErr(5, "It's already the highest quality");
return;
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => \services\FormulaService::Hero_Advanced_CEG_Expend($heroDb['quality']+1)
),
array(
'item_id' => V_ITEM_DIAMOND,
'item_num' => \services\FormulaService::Hero_Advanced_CEC_Expend($heroDb['quality']+1)
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$this->_decItems($costItems);
Hero::update($heroUniId,
array(
'lock_type' => Hero::QUALITY_LOCK,
'unlock_time' => $this->_getNowTime() + $nextQualityMeta['time'],
)
);
Hero::update($costHeroUniId,
array(
'lock_type' => Hero::COST_LOCK,
'unlock_time' => $this->_getNowTime() + $nextQualityMeta['time'],
)
);
$this->_setV(TN_HERO_QUALITY_UP, (int)$slotId, (int)$heroDb['idx']);
$this->_setV(TN_HERO_QUALITY_UP, (int)$slotId + 1000, (int)$costHeroDb['idx']);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$propertyChgService->addBagChg();
$propertyChgService->addUserChg();
$heroDto = Hero::toDto($heroDb);
{
//埋点
$eventCEG = [
'name' => LogService::HERO_QUALITY_UP_CONSUME,
'val' => \services\FormulaService::Hero_Advanced_CEG_Expend($heroDb['quality']+1)
];
$heroDto['level'] = $heroDto['hero_lv'];
$heroDto['item_id'] = $heroDto['hero_id'];
LogService::consumeCEG($eventCEG,$heroDto,$heroDto);
}
{
//埋点
$eventCEC = [
'name' => LogService::HERO_QUALITY_UP_CONSUME,
'val' => \services\FormulaService::Hero_Advanced_CEC_Expend($heroDb['quality']+1)
];
$heroDto['level'] = $heroDto['hero_lv'];
$heroDto['item_id'] = $heroDto['hero_id'];
LogService::consumeCEC($eventCEC,$heroDto,$heroDto);
}
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
));
}
public function upgradeQualityPreview()
{
$heroUniId = getReqVal('hero_uniid', 0);
$costHeroUniId = getReqVal('cost_hero_uniid', 0);
$heroDb = Hero::find($heroUniId);
$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;
}
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
if (!$nextQualityMeta) {
$this->_rspErr(5, "It's already the highest level1");
return;
}
$newHeroDb = $heroDb;
$newHeroDb['quality'] += 1;
$cost['CEG'] = \services\FormulaService::Hero_Advanced_CEG_Expend($newHeroDb['quality']);
$cost['CEC'] = \services\FormulaService::Hero_Advanced_CEC_Expend($newHeroDb['quality']);
$cost['success_rate'] = \services\FormulaService::Hero_Advanced_Probability($newHeroDb['quality']);
$heroDto = Hero::toDto($heroDb);
$newHeroDto = Hero::toDto($newHeroDb);
$this->_rspData(array(
'old_hero' => $heroDto,
'new_hero' => $newHeroDto,
'cost' => $cost
));
}
public function upgradeQuality(){
$tokenId1 = getReqVal('token_id1', '');
$tokenId2 = getReqVal('token_id2', '');
$transId = getReqVal('trans_id', '');
if (!$tokenId1 || !$tokenId2 || !$transId){
$this->_rspErr(1, ' error param');
return;
}
if (NftUpReceive::find(myself()->_getAccountId(),$transId)){
$this->_rspErr(1, ' error param trans_id ');
return;
}
Hero::updateByTokenId($tokenId1,
array(
'lock_type' => Hero::QUALITY_LOCK,
'unlock_time' => $this->_getNowTime() + 3600 * 24,
)
);
Hero::updateByTokenId($tokenId2,
array(
'lock_type' => Hero::COST_LOCK,
'unlock_time' => $this->_getNowTime() + 3600 * 24,
)
);
NftUpReceive::add(
myself()->_getAccountId(),
array(
'account_id' => myself()->_getAccountId(),
'trans_id' => $transId,
'token_id1' => $tokenId1,
'token_id2' => $tokenId2,
'state' => 0,
'token_type' => 1,
'from_data' => 0,
'createtime' => $this->_getNowTime(),
'modifytime' => $this->_getNowTime()
)
);
myself()->_rspOk();
}
public function receiveUpgradeQuality(){
$transId = getReqVal('trans_id', '');
$tokenId = getReqVal('token_id', '');
if (!$tokenId || !$transId){
$this->_rspErr(1, ' error param');
return;
}
Hero::updateByTokenId($tokenId,
array(
'lock_type' => Hero::NO_LOCK,
'unlock_time' => 0,
)
);
NftUpReceive::setAccountIdNull(myself()->_getAccountId(),$transId);
myself()->_rspOk();
}
}