720 lines
25 KiB
PHP
720 lines
25 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('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/RankActivityService.php');
|
|
|
|
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Hero;
|
|
use models\Bag;
|
|
use models\HeroSkin;
|
|
use models\Chip;
|
|
|
|
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;
|
|
}
|
|
$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'] = [];
|
|
}
|
|
|
|
$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
|
|
));
|
|
}
|
|
|
|
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();
|
|
$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);
|
|
if ($nextLevelMeta) {
|
|
Hero::update($heroUniId,
|
|
array(
|
|
'hero_lv' => $heroDb['hero_lv'] + 1,
|
|
'rand_attr' => json_encode($attrs),
|
|
'lock_type' => 0,
|
|
'unlock_time' => 0,
|
|
)
|
|
);
|
|
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);
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
'old_hero' => $oldHero,
|
|
'new_hero' => $newHero,
|
|
));
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
$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();
|
|
$currQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']);
|
|
$nextQualityMeta = null;
|
|
if ($currQualityMeta) {
|
|
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
|
|
if ($nextQualityMeta) {
|
|
$rnd = rand(1, 100);
|
|
//$rnd = 1000;
|
|
if ($rnd > $nextQualityMeta['success_rate']) {
|
|
Hero::update($costHeroUniId,
|
|
array(
|
|
'lock_type' => 0,
|
|
'unlock_time' => 0,
|
|
)
|
|
);
|
|
Hero::update($heroUniId,
|
|
array(
|
|
'advanced_count' => $heroDb['advanced_count'] + 1,
|
|
'lock_type' => 0,
|
|
'unlock_time' => 0,
|
|
)
|
|
);
|
|
$oldHero['advanced_count'] += 1;
|
|
$newHero['advanced_count'] += 1;
|
|
$this->_rspRawData(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'state' => 0,
|
|
'old_hero' => $oldHero,
|
|
'new_hero' => $newHero,
|
|
//'errmsg' => 'advance failed',
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
return;
|
|
}
|
|
Hero::update($heroUniId,
|
|
array(
|
|
'quality' => $heroDb['quality'] + 1,
|
|
'advanced_count' => $heroDb['advanced_count'] + 1,
|
|
'lock_type' => 0,
|
|
'unlock_time' => 0,
|
|
)
|
|
);
|
|
if ($heroDb['quality'] + 1 > myself()->_getV(TN_HERO_MAX_QUALITY, 0)) {
|
|
myself()->_setV(TN_HERO_MAX_QUALITY, 0, $heroDb['quality'] + 1);
|
|
}
|
|
Hero::update($costHeroUniId,
|
|
array(
|
|
'account_id' => myself()->_getAccountId() . '!!!',
|
|
'lock_type' => 0,
|
|
'unlock_time' => 0,
|
|
)
|
|
);
|
|
$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;
|
|
}
|
|
$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()
|
|
{
|
|
$costItemId = getReqVal('cost_item_id', 0);
|
|
$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['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;
|
|
}
|
|
$heroMeta = mt\Hero::get($heroDb['hero_id']);
|
|
if (!$heroMeta) {
|
|
$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);
|
|
if (!$nextLevelMeta) {
|
|
$this->_rspErr(5, "It's already the highest level");
|
|
return;
|
|
}
|
|
$costItems = array();
|
|
switch ($costItemId) {
|
|
case V_ITEM_GOLD:
|
|
{
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => $costItemId,
|
|
'item_num' => $nextLevelMeta['gold']
|
|
)
|
|
);
|
|
}
|
|
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'],
|
|
)
|
|
);
|
|
}
|
|
$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 upgradeQuality()
|
|
{
|
|
$costItemId = getReqVal('cost_item_id', 0);
|
|
$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;
|
|
}
|
|
$costHeroDb = Hero::find($costHeroUniId);
|
|
if (!$costHeroDb) {
|
|
$this->_rspErr(1, 'cost hero parameter error');
|
|
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;
|
|
}
|
|
$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;
|
|
}
|
|
$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;
|
|
}
|
|
$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();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function upgradeQualityPreview()
|
|
{
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
$heroDb = Hero::find($heroUniId);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(100, 'server internal error');
|
|
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);
|
|
$newHeroDto = Hero::toDto($newHeroDb);
|
|
$this->_rspData(array(
|
|
|
|
'old_hero' => $heroDto,
|
|
'new_hero' => $newHeroDto
|
|
));
|
|
}
|
|
|
|
}
|