176 lines
5.0 KiB
PHP
176 lines
5.0 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('models/Hero.php');
|
|
require_once('models/HeroSkin.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Hero;
|
|
use models\HeroSkin;
|
|
|
|
class HeroController extends BaseAuthedController {
|
|
|
|
public function heroList()
|
|
{
|
|
$heroList = array();
|
|
SqlHelper::ormSelect(
|
|
$this->_getSelfMysql(),
|
|
't_hero',
|
|
array(
|
|
'account_id' => $this->_getAccountId()
|
|
),
|
|
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, '你还没这个英雄');
|
|
return;
|
|
}
|
|
if (!$heroSkinDb) {
|
|
$this->_rspErr(2, '你还没这个皮肤');
|
|
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, '你还没这个英雄');
|
|
return;
|
|
}
|
|
if (!in_array($skillIdx, array(0, 1))) {
|
|
$this->_rspErr(1, 'skill_idx参数必须为0-1');
|
|
return;
|
|
}
|
|
Hero::upgradeSkill($heroUniId, $skillIdx);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function upgradeLevel()
|
|
{
|
|
$costItemId = getReqVal('cost_item_id', 0);
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
$heroDb = Hero::find($heroUniId);
|
|
if (!$heroDb) {
|
|
$this->_rspErr(1, '英雄不存在');
|
|
return;
|
|
}
|
|
if ($heroDb['state'] == Hero::GETED_STATE) {
|
|
$this->_rspErr(3, '试用英雄不能操作');
|
|
return;
|
|
}
|
|
if ($heroDb['unlock_time'] > $this->_getNowTime()) {
|
|
$this->_rspErr(2, '锁定期间不能操作');
|
|
return;
|
|
}
|
|
if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) {
|
|
$this->_rspErr(2, '锁定期间不能操作');
|
|
return;
|
|
}
|
|
$initLevelMeta = mt\HeroLevel::get(1, 1);
|
|
if (!$initLevelMeta) {
|
|
$this->_rspErr(100, '服务器内部错误');
|
|
return;
|
|
}
|
|
$currLevelMeta = mt\HeroLevel::get($heroDb['quality'], $heroDb['hero_lv']);
|
|
if (!$currLevelMeta) {
|
|
$this->_rspErr(100, '服务器内部错误');
|
|
return;
|
|
}
|
|
$nextLevelMeta = mt\HeroLevel::get($heroDb['quality'], $heroDb['hero_lv'] + 1);
|
|
if (!$nextLevelMeta) {
|
|
$this->_rspErr(5, '已满级');
|
|
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, '支付方式不支持');
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$randAttr = array();
|
|
$this->_decItems($costItems);
|
|
Hero::update($heroUniId,
|
|
array(
|
|
'level' => $heroDb['level'] + 1,
|
|
'rand_attr' => json_encode($randAttr)
|
|
)
|
|
);
|
|
|
|
}
|
|
|
|
public function upgradeQuality()
|
|
{
|
|
$heroUniId = getReqVal('hero_uniid', 0);
|
|
}
|
|
|
|
}
|