game2005api/webapp/controller/GunController.class.php
2021-11-26 14:22:38 +08:00

293 lines
8.9 KiB
PHP

<?php
require_once('mt/NewShop.php');
require_once('mt/GunTalentLv.php');
require_once('mt/GunTalent.php');
class GunController extends BaseAuthedController {
public function getGunInfo()
{
$data = array();
phpcommon\SqlHelper::select
($this->_getSelfMysql(),
'gun_intensify',
array(
'gun_type_id',
'skill_id',
'skill_lv'
),
array(
'accountid' => $this->_getAccountId()
),
function ($row) use(&$data) {
array_push($data, array(
'gun_type_id' => $row['gun_type_id'],
'skill_id' => $row['skill_id'],
'skill_lv' => $row['skill_lv'],
));
}
);
$this->_rspDataOld($data);
}
public function skillLvUp()
{
$talentId = $_REQUEST['skill_id'];
$gunTypeId = $_REQUEST['skill_type_id'];
$talentLvMeta = mt\GunTalentLv::get($talentId);
if (!$talentLvMeta) {
$this->_rspErr(99, "技能不存在");
return;
}
$gunTalentMeta = mt\GunTalentLv::get($gunTypeId);
if (!$gunTalentMeta) {
$this->_rspErr(1, "参数错误");
return;
}
if (!mt\GunTalentLv::isValidTalent($gunTypeId, $talentId)) {
$this->_rspErr(1, "参数错误");
return;
}
$talentLv = $this->_getTalentLv($talentId, $gunTypeId);
if (mt\GunTalentLv::isFullLv($talentLvMeta, $talentLv)) {
$this->_rspErr(98, "已满级");
return;
}
$nextLvMeta = mt\GunTalentLv::getByLv($meta, $talentLv + 1);
if (!$nextLvMeta) {
$this->_rspErr(2, "配置表错误");
return;
}
$costList = mt\GunTalentLv::getCostList($nextLvMeta);
$lackItem = array();
if (!$this->_hasEnoughItemsEx($costItem, $lackItem)) {
switch ($lackItem['item_id']) {
case V_ITEM_GOLD:
{
$this->_rspErr(97, "金币不足");
}
break;
case V_ITEM_DIAMOND:
{
$this->_rspErr(96, "钻石不足");
}
break;
default:
{
$this->_rspErr(95, "道具不足");
}
break;
}
return;
}
++$talentLv;
phpcommon\SqlHelper::upsert
($this->_getSelfMysql(),
'gun_intensify',
array(
'accountid' => $this->_getAccountId(),
'gun_type_id' => $gunTypeId,
'skill_id' => $talentId
),
array(
'skill_lv' => $talentLv,
'modifytime' => $this->_getNowTime()
),
array(
'accountid' => $this->_getAccountId(),
'gun_type_id' => $gunTypeId,
'skill_id' => $talentId,
'skill_lv' => $talentLv,
'createtime' => $this->_getNowTime(),
'modifytime' => $this->_getNowTime()
)
);
$this->_rspRawData(array(
'errcode' => 100,
'errmsg' => '',
'data' => array(
'gun_type_id' => $gunTypeId,
'skill_id' => $talentId,
'skill_lv' => $talentLv,
)
));
}
public function getGunAndSkinInfo()
{
$data = array();
phpcommon\SqlHelper::select
($this->_getSelfMysql(),
'gun',
array(
'gun_id',
'skin_id'
),
array(
'accountid' => $this->_getAccountId()
),
function ($row) use(&$data) {
array_push($data, array(
'gun_id' => $row['gun_id'],
'skin_lv' => $row['skin_id'],
));
}
);
phpcommon\SqlHelper::select
($this->_getSelfMysql(),
'gun_skin',
array(
'gun_id',
'skin_id'
),
array(
'accountid' => $this->_getAccountId()
),
function ($row) use(&$data) {
array_push($data, array(
'gun_id' => $row['gun_id'],
'skin_lv' => $row['skin_id'],
));
}
);
$this->_rspRawData(array(
'errcode' => 100,
'errmsg' => '',
'data' => $data
));
}
public function equipGunSkin()
{
$gunId = $_REQUEST['gun_id'];
$skinId = $_REQUEST['skin_id'];
phpcommon\SqlHelper::upsert
($this->_getSelfMysql(),
'gun',
array(
'accountid' => $this->_getAccountId(),
'gun_id' => $gunId
),
array(
),
array(
'accountid' => $this->_getAccountId(),
'gun_id' => $gunId,
'skin_id' => $skinId,
'trytime' => 0,
'createtime' => $this->_getNowTime(),
'modifytime' => $this->_getNowTime()
)
);
$this->_rspRawData(array(
'errcode' => 100,
'errmsg' => '',
'data' => array(
'gun_id' => $gunId,
'skin_id' => $skinId
)
));
}
public function buyGunSkin()
{
$account_id = $_REQUEST['account_id'];
$gunId = $_REQUEST['gun_id'];
$skinId = $_REQUEST['skin_id'];
$goodsId = $_REQUEST['goodsID'];
$shopMeta = mt\NewShop::getShopItemById(3);
if (!$shopMeta) {
$this->_rspErr(1, "参数错误");
return;
}
$goodsInfo = mt\NewShop::getGoodsInfo($shopMeta, $goodsId);
if (!$goodsInfo) {
$this->_rspErr(1, "参数错误");
return;
}
$costList = array(
array(
'item_id' => $goodsInfo['costItemId'],
'item_num' => $goodsInfo['costItemNum'],
)
);
$lackItem = array();
if (!$this->_hasEnoughItemsEx($costItem, $lackItem)) {
switch ($lackItem['item_id']) {
case V_ITEM_GOLD:
{
$this->_rspErr(88, "金币不足");
}
break;
case V_ITEM_DIAMOND:
{
$this->_rspErr(87, "钻石不足");
}
break;
default:
{
$this->_rspErr(86, "道具不足");
}
break;
}
return;
}
{
phpcommon\SqlHelper::upsert
($this->_getSelfMysql(),
'gun_skin',
array(
'accountid' => $this->_getAccountId(),
'gun_id' => $gunId,
'skin_id' => $skinId
),
array(
'trytime' => 0,
'modifytime' => $this->_getNowTime()
),
array(
'accountid' => $this->_getAccountId(),
'gun_id' => $gunId,
'skin_id' => $skinId,
'trytime' => 0,
'createtime' => $this->_getNowTime(),
'modifytime' => $this->_getNowTime()
)
);
phpcommon\SqlHelper::upsert
($this->_getSelfMysql(),
'gun',
array(
'accountid' => $this->_getAccountId(),
'gun_id' => $gunId
),
array(
'skin_id' => $skinId,
'modifytime' => $this->_getNowTime()
),
array(
'accountid' => $this->_getAccountId(),
'gun_id' => $gunId,
'skin_id' => $skinId,
'trytime' => 0,
'createtime' => $this->_getNowTime(),
'modifytime' => $this->_getNowTime()
)
);
}
$this->_rspRawData(array(
'errcode' => 100,
'errmsg' => '',
'data' => array(
'gun_id' => $gunId,
'skin_id' => $skinid
)
));
}
}