game2006api/webapp/controller/GunController.class.php
aozhiwei cb954f34a7 1
2022-01-13 16:40:27 +08:00

313 lines
10 KiB
PHP

<?php
require_once('mt/GunTalentGrow.php');
require_once('mt/GunTalent.php');
require_once('mt/Parameter.php');
require_once('mt/AttrHelper.php');
require_once('models/GunSkin.php');
require_once('models/GunTalent.php');
require_once('models/User.php');
require_once('models/Gun.php');
require_once('models/Bag.php');
require_once('services/PropertyChgService.php');
use phpcommon\SqlHelper;
use models\GunSkin;
use models\GunTalent;
use models\User;
use models\Gun;
use models\Bag;
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);
$gunUniId = getReqVal('gun_uniid', 0);
$gunDb = Gun::find($gunUniId);
if (!$gunDb) {
$this->_rspErr(1, '枪不存在');
return;
}
if ($gunDb['state'] != Gun::GETED_STATE) {
$this->_rspErr(3, '试用枪不能操作');
return;
}
if ($gunDb['unlock_time'] > $this->_getNowTime()) {
$this->_rspErr(2, '锁定期间不能操作');
return;
}
if ($gunDb['unlock_trade_time'] > $this->_getNowTime()) {
$this->_rspErr(2, '锁定期间不能操作');
return;
}
$itemMeta = mt\Item::get($gunDb['gun_id']);
if (!$itemMeta) {
$this->_rspErr(100, '服务器内部错误');
return;
}
$currLevelMeta = mt\GunLevel::getByQualityLevel($gunDb['quality'], $gunDb['gun_lv']);
if (!$currLevelMeta) {
$this->_rspErr(100, '服务器内部错误');
return;
}
$nextLevelMeta = mt\GunLevel::getByQualityLevel($gunDb['quality'], $gunDb['gun_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;
}
$baseAttrs = mt\Item::getBaseAttrs($itemMeta);
mt\AttrHelper::mergeAttr($baseAttrs, Bag::getAttrs());
$attrs = emptyReplace(json_decode($gunDb['rand_attr'], true), array());
$ret = mt\GunLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs);
if (!$ret) {
$this->_rspErr(2, '服务器内部错误');
return;
}
$this->_decItems($costItems);
Gun::update($gunUniId,
array(
'gun_lv' => $gunDb['gun_lv'] + 1,
'rand_attr' => json_encode($attrs),
'lock_type' => Gun::LEVEL_LOCK,
'unlock_time' => $this->_getNowTime() + $currLevelMeta['time'],
'unlock_trade_time' => $this->_getNowTime() + $currLevelMeta['time'] + mt\Parameter::getVal('gun_lock_transaction_time', 0)
)
);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addGunChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
));
}
public function upgradeQuality()
{
$costItemId = getReqVal('cost_item_id', 0);
$gunUniId = getReqVal('gun_uniid', 0);
$gunDb = Gun::find($gunUniId);
if (!$gunDb) {
$this->_rspErr(1, '枪不存在');
return;
}
if ($gunDb['state'] != Gun::GETED_STATE) {
$this->_rspErr(3, '试用枪不能操作');
return;
}
if ($gunDb['unlock_time'] > $this->_getNowTime()) {
$this->_rspErr(2, '锁定期间不能操作');
return;
}
if ($gunDb['unlock_trade_time'] > $this->_getNowTime()) {
$this->_rspErr(2, '锁定期间不能操作');
return;
}
$itemMeta = mt\Item::get($gunDb['gun_id']);
if (!$itemMeta) {
$this->_rspErr(100, '服务器内部错误');
return;
}
$currQualityMeta = mt\GunQuality::getByQuality($gunDb['quality']);
if (!$currQualityMeta) {
$this->_rspErr(100, '服务器内部错误');
return;
}
$nextQualityMeta = mt\GunQuality::getByQuality($gunDb['quality'] + 1);
if (!$nextQualityMeta) {
$this->_rspErr(5, '已满级1');
return;
}
$nextLevelMeta = mt\GunLevel::getByQualityLevel($gunDb['quality'] + 1, $gunDb['gun_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;
}
$baseAttrs = mt\Item::getBaseAttrs($itemMeta);
$baseAttrs = mt\AttrHelper::mergeAttr($baseAttrs, Bag::getAttrs());
$attrs = emptyReplace(json_decode($gunDb['rand_attr'], true), array());
{
$obtainAttrs = mt\GunQuality::getRandAttr($nextQualityMeta);
mt\AttrHelper::mergeAttr($attrs, $obtainAttrs);
}
{
$ret = mt\GunLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs);
if (!$ret) {
$this->_rspErr(2, '服务器内部错误');
return;
}
}
$this->_decItems($costItems);
Gun::update($gunUniId,
array(
'gun_lv' => $gunDb['gun_lv'],
'quality' => $gunDb['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('gun_lock_transaction_time', 0)
)
);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addGunChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
));
}
}