287 lines
9.0 KiB
PHP
287 lines
9.0 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');
|
|
|
|
require_once('services/PropertyChgService.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()
|
|
{
|
|
$talentId = getReqVal('talent_id', 0);
|
|
|
|
$talentDb = GunTalent::find($talentId);
|
|
$currLv = isset($talentDb) ? $talentDb['talent_lv'] : 1;
|
|
$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($talentId, $currLv + 1);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addUserChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto()
|
|
));
|
|
}
|
|
|
|
public function gunList()
|
|
{
|
|
$gunList = array();
|
|
SqlHelper::ormSelect(
|
|
$this->_getSelfMysql(),
|
|
't_gun',
|
|
array(
|
|
'account_id' => $this->_getAccountId()
|
|
),
|
|
function ($row) use(&$gunList) {
|
|
array_push($gunList, Gun::toDto($row));
|
|
}
|
|
);
|
|
$this->_rspData(array(
|
|
'gun_list' => $gunList
|
|
));
|
|
}
|
|
|
|
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;
|
|
}
|
|
$currLevelMeta = mt\HeroLevel::getByQualityLevel($heroDb['quality'], $heroDb['hero_lv']);
|
|
if (!$currLevelMeta) {
|
|
$this->_rspErr(100, '服务器内部错误');
|
|
return;
|
|
}
|
|
$nextLevelMeta = mt\HeroLevel::getByQualityLevel($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;
|
|
}
|
|
$attrs = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
|
|
$ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $attrs);
|
|
if (!$ret) {
|
|
$this->_rspErr(2, '服务器内部错误');
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
Hero::update($heroUniId,
|
|
array(
|
|
'hero_lv' => $heroDb['hero_lv'] + 1,
|
|
'rand_attr' => json_encode($attrs)
|
|
)
|
|
);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addGunChg();
|
|
$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, '英雄不存在');
|
|
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;
|
|
}
|
|
$currQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']);
|
|
if (!$currQualityMeta) {
|
|
$this->_rspErr(100, '服务器内部错误');
|
|
return;
|
|
}
|
|
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
|
|
if (!$nextQualityMeta) {
|
|
$this->_rspErr(5, '已满级1');
|
|
return;
|
|
}
|
|
$nextLevelMeta = mt\HeroLevel::getByQualityLevel($heroDb['quality'] + 1, $heroDb['hero_lv']);
|
|
if (!$nextLevelMeta) {
|
|
$this->_rspErr(5, '已满级2');
|
|
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, '支付方式不支持');
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$attrs = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
|
|
{
|
|
$obtainAttrs = mt\HeroQuality::getRandAttr($nextQualityMeta);
|
|
mt\AttrHelper::mergeAttr($attrs, $obtainAttrs);
|
|
}
|
|
{
|
|
$ret = mt\HeroLevel::addRandAttr($nextLevelMeta, $attrs);
|
|
if (!$ret) {
|
|
$this->_rspErr(2, '服务器内部错误');
|
|
return;
|
|
}
|
|
}
|
|
$this->_decItems($costItems);
|
|
Hero::update($heroUniId,
|
|
array(
|
|
'hero_lv' => $heroDb['hero_lv'],
|
|
'quality' => $heroDb['quality'] + 1,
|
|
'rand_attr' => json_encode($attrs)
|
|
)
|
|
);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addGunChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
}
|