game2006api/webapp/controller/GunController.class.php
2023-04-13 15:34:12 +08:00

276 lines
8.5 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_DIAMOND,
// 'item_num' => $nextLevelMeta['diamond']
// ),
);
$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 || !$costGunDb) {
$this->_rspErr(100, 'param error or null');
return;
}
if ($costGunDb['token_id']){
$this->_rspErr(100, 'NFT cannot be a material');
return;
}
// if ($costGunDb['state'] == Gun::FREE_STATE){
// $this->_rspErr(100, 'Unable to use free gun');
// return;
// }
if ($gunDb['gun_lv'] != $costGunDb['gun_lv']){
$this->_rspErr(100, 'You need the same level to do it');
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_DIAMOND,
// 'item_num' => $nextLevelMeta['diamond']
// ),
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$this->_decItems($costItems);
$attrs = Gun::LvUpAddAttr($gunDb,1);
Gun::update($gunUniId,
array(
'gun_lv' => $gunDb['gun_lv'] + 1,
'state' => Gun::GETED_STATE,
'rand_attr' => json_encode($attrs),
));
Gun::update($costGunUniId,
array(
'account_id' => myself()->_getAccountId() . '!!!',
)
);
$newGun = Gun::toDto(Gun::find($gunUniId));
$this->_addLog('upgrade','gun_level',array(
'param1' => 'tokenId:'.$gunDb['token_id'],
'param2' => 'uniid:'.$gunDb['idx'],
'param3' => 'itemId:'.$gunDb['gun_id'],
'param4' => 'oldLv:'.$gunDb['gun_lv'],
'param5' => 'newLv:'.$newGun['gun_lv'],
'param6' => json_encode($newGun),
));
$this->_addLog('consume','gun',array(
'param1' => 'uniid:'. $costGunDb['idx'],
'param2' => 'itemId:'.$costGunDb['gun_id'],
));
$this->_addLog('consume','cost',array(
'param1' => json_encode($costItems),
));
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addGunChg();
$propertyChgService->addUserChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'old_gun' => $oldGun,
'new_gun' => $newGun,
));
}
}