game2006api/webapp/controller/HeroController.class.php
aozhiwei ecf7065315 1
2022-06-13 11:37:00 +08:00

367 lines
12 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/HeroQuality.php');
require_once('mt/AttrHelper.php');
require_once('mt/Parameter.php');
require_once('models/Hero.php');
require_once('models/Bag.php');
require_once('models/HeroSkin.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;
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 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 upgradeSkill()
{
$heroUniId = getReqVal('hero_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;
}
Hero::upgradeSkill($heroUniId, $skillIdx);
$this->_rspOk();
}
public function getUpgradeLevelList()
{
$infos = array();
for ($i = 0; $i <= 1; ++$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' => 0
);
}
}
array_push($infos, $info);
}
$this->_rspData(array(
'infos' => $infos
));
}
public function getUpgradeQualityList()
{
$infos = array();
for ($i = 0; $i <= 1; ++$i) {
}
$this->_rspData(array(
'infos' => $infos
));
}
public function receive()
{
/*
$baseAttrs = mt\Hero::getHeroAttr($heroMeta);
mt\AttrHelper::mergeAttr($baseAttrs, Bag::getAttrs());
$attrs = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
$ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs);
if (!$ret) {
$this->_rspErr(2, 'server internal error');
return;
}
Hero::update($heroUniId,
array(
'hero_lv' => $heroDb['hero_lv'] + 1,
'rand_attr' => json_encode($attrs),
'lock_type' => Hero::LEVEL_LOCK,
'unlock_time' => $this->_getNowTime() + $currLevelMeta['time'],
'unlock_trade_time' => $this->_getNowTime() + $currLevelMeta['time'] + mt\Parameter::getVal('hero_lock_transaction_time', 0)
)
);
$rankActivityService = new service\RankActivityService();
$rankActivityService->heroUpgradeLevel($heroDb['hero_lv'] + 1);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
));
*/
}
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, 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::getByQualityLevel($heroDb['quality'], $heroDb['hero_lv']);
if (!$currLevelMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$nextLevelMeta = mt\HeroLevel::getByQualityLevel($heroDb['quality'], $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' => $currLevelMeta['gold']
)
);
}
break;
case V_ITEM_DIAMOND:
{
$costItems = array(
array(
'item_id' => $costItemId,
'item_num' => $currLevelMeta['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);
$this->_setV(TN_HERO_LEVEL_UP, (int)$slotId, (int)$heroDb['idx']);
{
Hero::update(
$heroUniId,
array(
'hero_lv' => $heroDb['hero_lv'] + 1,
'lock_type' => Hero::LEVEL_LOCK,
'unlock_time' => $this->_getNowTime() + $currLevelMeta['time'],
)
);
}
$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);
$heroUniId = getReqVal('hero_uniid', 0);
$heroDb = Hero::find($heroUniId);
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;
}
$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::getByQualityLevel($heroDb['quality'] + 1, $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' => $currQualityMeta['gold']
)
);
}
break;
case V_ITEM_DIAMOND:
{
$costItems = array(
array(
'item_id' => $costItemId,
'item_num' => $currQualityMeta['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;
}
$baseAttrs = mt\Hero::getHeroAttr($heroMeta);
mt\AttrHelper::mergeAttr($baseAttrs, Bag::getAttrs());
$attrs = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
{
$obtainAttrs = mt\HeroQuality::getRandAttr($nextQualityMeta);
mt\AttrHelper::mergeAttr($attrs, $obtainAttrs);
}
{
$ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs);
if (!$ret) {
$this->_rspErr(2, 'server internal error');
return;
}
}
$this->_decItems($costItems);
Hero::update($heroUniId,
array(
'hero_lv' => $heroDb['hero_lv'],
'quality' => $heroDb['quality'] + 1,
'rand_attr' => json_encode($attrs),
'lock_type' => Gun::QUALITY_LOCK,
'unlock_time' => $this->_getNowTime() + $currQualityMeta['time'],
'unlock_trade_time' => $this->_getNowTime() + $currQualityMeta['time'] + mt\Parameter::getVal('hero_lock_transaction_time', 0)
)
);
$rankActivityService = new services\RankActivityService();
$rankActivityService->heroUpgradeQuality($heroDb['quality'] + 1);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
));
}
}