game2005api/webapp/controller/GunController.class.php
2021-11-29 17:05:33 +08:00

95 lines
2.8 KiB
PHP

<?php
require_once('mt/GunTalentGrow.php');
require_once('mt/GunTalent.php');
require_once('models/GunSkin.php');
require_once('models/GunTalent.php');
require_once('models/User.php');
use phpcommon\SqlHelper;
use models\GunSkin;
use models\GunTalent;
use models\User;
class GunController extends BaseAuthedController {
public function skinList()
{
$skinList = array();
SqlHelper::ormSelect(
$this->_getSelfMysql(),
't_gun_skin',
array(
'account_id' => $this->_getAccountId()
),
function ($row) use(&$skinList) {
array_push($skinList, GunSkin::toDto($row));
}
);
$this->_rspData(array(
'skin_list' => $skinList
));
}
public function talentList()
{
$talentList = array();
SqlHelper::ormSelect(
$this->_getSelfMysql(),
't_gun_talent',
array(
'account_id' => $this->_getAccountId()
),
function ($row) use(&$talentList) {
array_push($talentList, GunTalent::toDto($row));
}
);
$this->_rspData(array(
'talent_list' => $talentList
));
}
public function upgradeTalentLv()
{
$typeId = getReqVal('type_id', 0);
$talentId = getReqVal('talent_id', 0);
$talentMeta = mt\GunTalent::get($typeId);
if (!$talentMeta) {
$this->_rspErr(1, 'type_id参数错误');
return;
}
if (!mt\GunTalent::isValidTalent($talentMeta, $talentId)) {
$this->_rspErr(1, 'talent_id参数错误');
return;
}
$talentDb = GunTalent::find($typeId, $talentId);
$currLv = isset($talentDb) ? $talentDb['talent_lv'] : 0;
$growMeta = mt\GunTalentGrow::getByIdLv($talentId, $currLv + 1);
if (!$growMeta) {
$this->_rspErr(2, '已满级');
return;
}
$ormUserInfo = $this->_getOrmUserInfo();
if ($ormUserInfo['level'] < $growMeta['need_user_level']) {
$this->_rspErr(3, '用户等级未到达');
return;
}
$costList = mt\GunTalentGrow::getCostList($growMeta);
$lackItem = array();
if (!$this->_hasEnoughItems($costList, $lackItem)) {
$this->_rspErr(3, '缺少材料');
return;
}
$this->_decItems($costList);
GunTalent::upgradeLv($typeId, $talentId, $currLv + 1);
$this->_rspData(array(
'property_chg' => array(
'user_info' => User::info($this->_getOrmUserInfo())
)
));
}
}