364 lines
12 KiB
PHP
364 lines
12 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('models/Chip.php');
|
|
|
|
require_once('services/PropertyChgService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\GunSkin;
|
|
use models\GunTalent;
|
|
use models\User;
|
|
use models\Gun;
|
|
use models\Bag;
|
|
use models\Chip;
|
|
|
|
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 gunDetails(){
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
if ( ! $unique_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$gunDb = Gun::find($unique_id);
|
|
if (! $gunDb){
|
|
$this->_rspErr(1, "You don't have the gun yet");
|
|
return;
|
|
}
|
|
$gun = Gun::toDto($gunDb);
|
|
$chipAttr = [];
|
|
$chipIdsArr = explode('|',$gun['chip_ids']);
|
|
foreach ($chipIdsArr as $val){
|
|
$chip = Chip::toDto(Chip::getChipByIdx($val));
|
|
foreach ($chip['rand_attr'] as $v){
|
|
array_push($chipAttr,$v);
|
|
}
|
|
}
|
|
$item = [];
|
|
foreach ($chipAttr as $k=>$v){
|
|
if (!isset($item[$v['attr_id']])){
|
|
$item[$v['attr_id']] = $v;
|
|
}else{
|
|
$item[$v['attr_id']]['val']+= $v['val'];
|
|
}
|
|
}
|
|
|
|
$gun['rand_attr'] = $item;//芯片属性
|
|
\mt\AttrHelper::mergeAttr($gun['attr'],$chipAttr);
|
|
$chipCore = [];
|
|
if (count($chipIdsArr) == 4){
|
|
$min = 15;
|
|
foreach ($chipIdsArr as $val){
|
|
$chip = Chip::getChipByIdx($val);
|
|
if ($chip['chip_grade']<$min){
|
|
$min = $chip['chip_grade'];
|
|
}
|
|
}
|
|
$chipCoreList = getMetaTable('chipCore@chipCore.php');
|
|
foreach ($chipCoreList as $val){
|
|
if ($val['chip_core_type']==2 && $val['chip_core_lv']<=$min){
|
|
array_push($chipCore,$val);
|
|
}
|
|
}
|
|
$gun['chip_core'] = $chipCore;
|
|
}else{
|
|
$gun['chip_core'] = [];
|
|
}
|
|
|
|
$this->_rspData(array(
|
|
'data' => $gun
|
|
));
|
|
}
|
|
|
|
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, "It's already the highest level");
|
|
return;
|
|
}
|
|
$ormUserInfo = $this->_getOrmUserInfo();
|
|
if ($ormUserInfo['level'] < $growMeta['need_user_level']) {
|
|
$this->_rspErr(3, 'User level not reached');
|
|
return;
|
|
}
|
|
$costList = mt\GunTalentGrow::getCostList($growMeta);
|
|
$lackItem = array();
|
|
if (!$this->_hasEnoughItems($costList, $lackItem)) {
|
|
$this->_rspErr(3, 'Lack of materials');
|
|
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();
|
|
Gun::getGunList(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, 'The gun does not exist');
|
|
return;
|
|
}
|
|
if ($gunDb['state'] != Gun::GETED_STATE) {
|
|
$this->_rspErr(3, 'The trial gun cannot be operated');
|
|
return;
|
|
}
|
|
if ($gunDb['unlock_time'] > $this->_getNowTime()) {
|
|
$this->_rspErr(2, 'Cannot operate during locking');
|
|
return;
|
|
}
|
|
if ($gunDb['unlock_trade_time'] > $this->_getNowTime()) {
|
|
$this->_rspErr(2, 'Cannot operate during locking');
|
|
return;
|
|
}
|
|
$itemMeta = mt\Item::get($gunDb['gun_id']);
|
|
if (!$itemMeta) {
|
|
$this->_rspErr(100, 'server internal error');
|
|
return;
|
|
}
|
|
$currLevelMeta = mt\GunLevel::getByQualityLevel($gunDb['quality'], $gunDb['gun_lv']);
|
|
if (!$currLevelMeta) {
|
|
$this->_rspErr(100, 'server internal error');
|
|
return;
|
|
}
|
|
$nextLevelMeta = mt\GunLevel::getByQualityLevel($gunDb['quality'], $gunDb['gun_lv'] + 1);
|
|
if (!$nextLevelMeta) {
|
|
$this->_rspErr(5, "It's already the highest level");
|
|
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, 'Payment method not supported');
|
|
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, 'server internal error');
|
|
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, 'The gun does not exist');
|
|
return;
|
|
}
|
|
if ($gunDb['state'] != Gun::GETED_STATE) {
|
|
$this->_rspErr(3, 'The trial gun cannot be operated');
|
|
return;
|
|
}
|
|
if ($gunDb['unlock_time'] > $this->_getNowTime()) {
|
|
$this->_rspErr(2, 'Cannot operate during locking');
|
|
return;
|
|
}
|
|
if ($gunDb['unlock_trade_time'] > $this->_getNowTime()) {
|
|
$this->_rspErr(2, 'Cannot operate during locking');
|
|
return;
|
|
}
|
|
$itemMeta = mt\Item::get($gunDb['gun_id']);
|
|
if (!$itemMeta) {
|
|
$this->_rspErr(100, 'server internal error');
|
|
return;
|
|
}
|
|
$currQualityMeta = mt\GunQuality::getByQuality($gunDb['quality']);
|
|
if (!$currQualityMeta) {
|
|
$this->_rspErr(100, 'server internal error');
|
|
return;
|
|
}
|
|
$nextQualityMeta = mt\GunQuality::getByQuality($gunDb['quality'] + 1);
|
|
if (!$nextQualityMeta) {
|
|
$this->_rspErr(5, "It's already the highest level1");
|
|
return;
|
|
}
|
|
$nextLevelMeta = mt\GunLevel::getByQualityLevel($gunDb['quality'] + 1, $gunDb['gun_lv']);
|
|
if (!$nextLevelMeta) {
|
|
$this->_rspErr(5, "It's already the highest level2");
|
|
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, 'Payment method not supported');
|
|
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());
|
|
{
|
|
$obtainAttrs = mt\GunQuality::getRandAttr($nextQualityMeta);
|
|
mt\AttrHelper::mergeAttr($attrs, $obtainAttrs);
|
|
}
|
|
{
|
|
$ret = mt\GunLevel::addRandAttr($nextLevelMeta, $baseAttrs, $attrs);
|
|
if (!$ret) {
|
|
$this->_rspErr(2, 'server internal error');
|
|
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(),
|
|
));
|
|
}
|
|
|
|
}
|