279 lines
8.6 KiB
PHP
279 lines
8.6 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('models/Nft.php');
|
|
require_once('models/NftUpReceive.php');
|
|
require_once('models/Transaction.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/RankActivityService.php');
|
|
require_once('services/LogService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\GunSkin;
|
|
use models\GunTalent;
|
|
use models\User;
|
|
use models\Gun;
|
|
use models\Bag;
|
|
use models\Chip;
|
|
use models\Nft;
|
|
use models\NftUpReceive;
|
|
use models\Transaction;
|
|
use services\LogService;
|
|
|
|
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 gunList()
|
|
{
|
|
$gunList = array();
|
|
Gun::getGunList(function ($row) use(&$gunList) {
|
|
array_push($gunList, Gun::toDto($row));
|
|
});
|
|
|
|
$this->_rspData(array(
|
|
'gun_list' => $gunList
|
|
));
|
|
}
|
|
|
|
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;
|
|
}
|
|
$gunDb['tags'] = '';
|
|
if ($gunDb['token_id']){
|
|
$nftDb = Nft::getNft($gunDb['token_id']);
|
|
$gunDb['tags'] = $nftDb['tags'];
|
|
}
|
|
|
|
$gun = Gun::toDto($gunDb);
|
|
$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 upgradeLevelPreview(){
|
|
$gunUniId = getReqVal('gun_uniid', 0);
|
|
$gunDb = Gun::find($gunUniId);
|
|
if (!$gunDb) {
|
|
$this->_rspErr(1, 'The gun does not exist');
|
|
return;
|
|
}
|
|
$itemMeta = mt\Item::get($gunDb['gun_id']);
|
|
if (!$itemMeta) {
|
|
$this->_rspErr(100, 'server internal error');
|
|
return;
|
|
}
|
|
$nextLevelMeta = \mt\GunLevel::find($gunDb['gun_id'],$gunDb['gun_lv']+1);
|
|
if (!$nextLevelMeta) {
|
|
$this->_rspErr(5, "It's already the highest level");
|
|
return;
|
|
}
|
|
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $nextLevelMeta['gold']
|
|
),
|
|
array(
|
|
'item_id' => V_ITEM_GUN_META,
|
|
'item_num' => $nextLevelMeta['stone']
|
|
)
|
|
);
|
|
$metaList = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE);
|
|
foreach ($metaList as $meta){
|
|
if ($meta['relationship'] == $gunDb['gun_id']) {
|
|
array_push($costItems,array(
|
|
'item_id' => $meta['id'],
|
|
'item_num' => $nextLevelMeta['piece'],
|
|
));
|
|
}
|
|
}
|
|
|
|
$newGunDb = $gunDb;
|
|
$newGunDb['gun_lv'] += 1;
|
|
$attrs = Gun::LvUpAddAttr($gunDb,0);
|
|
$newGunDb['rand_attr'] = json_encode($attrs);
|
|
|
|
|
|
$gunDto = Gun::toDto($gunDb);
|
|
$newGunDto = Gun::toDto($newGunDb);
|
|
$this->_rspData(array(
|
|
'old_gun' => $gunDto,
|
|
'new_gun' => $newGunDto,
|
|
'cost' => $costItems
|
|
));
|
|
}
|
|
|
|
public function upgradeLv(){
|
|
$gunUniId = getReqVal('gun_uniid', 0);
|
|
// $costGunUniId = getReqVal('cost_gun_uniid', 0);
|
|
$gunDb = Gun::find($gunUniId);
|
|
$oldGun = Gun::toDto($gunDb);
|
|
// $costGunDb = Gun::findEx($costGunUniId);
|
|
if (!$gunDb ) {
|
|
$this->_rspErr(100, 'param error or null');
|
|
return;
|
|
}
|
|
|
|
$itemMeta = mt\Item::get($gunDb['gun_id']);
|
|
if (!$itemMeta) {
|
|
$this->_rspErr(100, 'server internal error');
|
|
return;
|
|
}
|
|
|
|
$nextLevelMeta = \mt\GunLevel::find($gunDb['gun_id'],$gunDb['gun_lv']+1);
|
|
if (!$nextLevelMeta) {
|
|
$this->_rspErr(5, "It's already the highest level");
|
|
return;
|
|
}
|
|
//校验枪械碎片数量
|
|
$piece_item_id = 0;
|
|
$metaList = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE);
|
|
foreach ($metaList as $meta){
|
|
if ($meta['relationship'] == $gunDb['gun_id']) {
|
|
$piece_item_id = $meta['id'];
|
|
break;
|
|
}
|
|
}
|
|
$piece_num = Bag::getItemCount($piece_item_id);
|
|
if ($piece_num < $nextLevelMeta['piece']){
|
|
$this->_rspErr(3, "Lack of gun piece");
|
|
return;
|
|
}
|
|
//校验枪械水晶数量
|
|
$num = Bag::getItemCount(V_ITEM_GUN_META);
|
|
if ($num < $nextLevelMeta['stone']){
|
|
$this->_rspErr(3, "Lack of gun crystal");
|
|
return;
|
|
}
|
|
|
|
|
|
//校验用户gold数量
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $nextLevelMeta['gold']
|
|
),
|
|
// array(
|
|
// 'item_id' => V_ITEM_DIAMOND,
|
|
// 'item_num' => $nextLevelMeta['diamond']
|
|
// ),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$this->_decItems($costItems);
|
|
Bag::decItem($piece_item_id,$nextLevelMeta['piece']);
|
|
Bag::decItem(V_ITEM_GUN_META,$nextLevelMeta['stone']);
|
|
|
|
$attrs = Gun::LvUpAddAttr($gunDb,1);
|
|
Gun::update($gunUniId,
|
|
array(
|
|
'gun_lv' => $gunDb['gun_lv'] + 1,
|
|
'state' => Gun::GETED_STATE,
|
|
'rand_attr' => json_encode($attrs),
|
|
));
|
|
|
|
$newGun = Gun::toDto(Gun::find($gunUniId));
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addGunChg();
|
|
$propertyChgService->addUserChg();
|
|
$propertyChgService->addBagChg();
|
|
$this->_rspData(array(
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
'old_gun' => $oldGun,
|
|
'new_gun' => $newGun,
|
|
));
|
|
}
|
|
|
|
|
|
|
|
}
|