game2006api/webapp/controller/GunController.class.php
2023-02-15 16:17:19 +08:00

881 lines
32 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/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\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 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);
$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()
{
$gunUniId = getReqVal('gun_uniid', 0);
$slotId = getReqVal('slot_id', 0);
$gunDb = Gun::find($gunUniId);
if (!in_array($slotId, array(0, kMaxHeroUpLevelNum - 1))) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
{
$srcGunDb = Gun::find($this->_getV(TN_GUN_LEVEL_UP, $slotId));
if ($srcGunDb) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
}
if (!$gunDb) {
$this->_rspErr(1, 'The gun does not exist');
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;
}
$nextLevelMeta = mt\GunLevel::getByLevel($gunDb['gun_lv'] +1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
}
if ($gunDb['gun_lv'] + 1 == 15 && !$gunDb['token_id']){
$this->_rspErr(1, "Free guns cannot continue to level up");
return;
}
$is_cec = false;
if ($gunDb['gun_lv']+1 <15){
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => \services\FormulaService::Weapon_Upgrade_CEG_Expend($gunDb['gun_lv']+1)
)
);
}else{
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => \services\FormulaService::Weapon_Upgrade_CEG_Expend($gunDb['gun_lv']+1)
),
array(
'item_id' => V_ITEM_DIAMOND,
'item_num' => \services\FormulaService::Weapon_Upgrade_CEC_Expend($gunDb['gun_lv']+1)
)
);
$is_cec = true;
}
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$gunDto = Gun::toDto($gunDb);
{
//埋点
$eventCEG = [
'name' => LogService::GUN_LEVEL_UP_CONSUME,
'val' => \services\FormulaService::Weapon_Upgrade_CEG_Expend($gunDb['gun_lv']+1)
];
$gunDto['level'] = $gunDto['gun_lv'];
$gunDto['item_id'] = $gunDto['gun_id'];
LogService::consumeCEG($eventCEG,$gunDto,$gunDto);
}
if ($is_cec){
{
//埋点
$eventCEC = [
'name' => LogService::GUN_LEVEL_UP_CONSUME,
'val' => \services\FormulaService::Weapon_Upgrade_CEC_Expend($gunDb['gun_lv']+1)
];
$gunDto['level'] = $gunDto['gun_lv'];
$gunDto['item_id'] = $gunDto['gun_id'];
LogService::consumeCEC($eventCEC,$gunDto,$gunDto);
}
}
$this->_decItems($costItems);
Gun::update($gunUniId,
array(
'lock_type' => Gun::LEVEL_LOCK,
)
);
$this->_setV(TN_GUN_LEVEL_UP, (int)$slotId, (int)$gunDb['idx']);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addGunChg();
$propertyChgService->addBagChg();
$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::getByLevel($gunDb['gun_lv'] +1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
}
$newGunDb = $gunDb;
$newGunDb['gun_lv'] += 1;
$attrs = mt\GunLevel::addRandAttrNew($gunDb,0);
$newGunDb['rand_attr'] = json_encode($attrs);
$cost['CEG'] = \services\FormulaService::Weapon_Upgrade_CEG_Expend( $newGunDb['gun_lv']);
$cost['CEC'] = \services\FormulaService::Weapon_Upgrade_CEC_Expend( $newGunDb['gun_lv']);
$gunDto = Gun::toDto($gunDb);
$newGunDto = Gun::toDto($newGunDb);
$this->_rspData(array(
'old_gun' => $gunDto,
'new_gun' => $newGunDto,
'cost' => $cost
));
}
public function upgradeQualityOld()
{
$costGunUniId = getReqVal('cost_gun_uniid', 0);
$gunUniId = getReqVal('gun_uniid', 0);
$slotId = getReqVal('slot_id', 0);
$gunDb = Gun::find($gunUniId);
if (!in_array($slotId, array(0, kMaxHeroUpQualityNum - 1))) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
if (!$gunDb['token_id']){
$this->_rspErr(100, 'Free heroes cannot quality up');
return;
}
$costGunDb = Gun::find($costGunUniId);
if (!$costGunDb) {
$this->_rspErr(1, 'cost hero parameter error');
return;
}
if ($gunDb['gun_id'] != $costGunDb['gun_id']){
$this->_rspErr(100, 'You need the same kind of hero');
return;
}
if ($costGunDb['quality']>1){
$this->_rspErr(100, 'Material gun quality too high');
return;
}
if ($costGunDb['lock_type']) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
}
{
$srcGunDb = Gun::find($this->_getV(TN_GUN_QUALITY_UP, $slotId));
if ($srcGunDb) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
}
{
$idx = 0;
$found = false;
for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) {
$upGunUniId = $this->_getV(TN_GUN_QUALITY_UP, $i);
if ($upGunUniId == $gunUniId) {
$idx = $i;
$found = true;
break;
}
}
if ($found) {
$this->_rspErr(1, 'gun already upgrading');
return;
}
}
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['lock_type']) {
$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;
}
$nextQualityMeta = mt\GunQuality::getByQuality($gunDb['quality'] + 1);
if (!$nextQualityMeta) {
$this->_rspErr(5, "It's already the highest level1");
return;
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => \services\FormulaService::Weapon_Advanced_CEG_Expend($gunDb['quality']+1)
),
array(
'item_id' => V_ITEM_DIAMOND,
'item_num' => \services\FormulaService::Weapon_Advanced_CEC_Expend($gunDb['quality']+1)
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$this->_decItems($costItems);
Gun::update($gunUniId,
array(
'lock_type' => Gun::QUALITY_LOCK,
'unlock_time' => $this->_getNowTime() + 20,
)
);
Gun::update($costGunUniId,
array(
'lock_type' => Gun::COST_LOCK,
'unlock_time' => $this->_getNowTime() + 20,
)
);
$this->_setV(TN_GUN_QUALITY_UP, (int)$slotId, (int)$gunDb['idx']);
$this->_setV(TN_GUN_QUALITY_UP, (int)$slotId + 1000, (int)$costGunDb['idx']);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addGunChg();
$propertyChgService->addUserChg();
$gunDto = Gun::toDto($gunDb);
{
//埋点
$eventCEG = [
'name' => LogService::GUN_QUALITY_UP_CONSUME,
'val' => \services\FormulaService::Weapon_Advanced_CEG_Expend($gunDb['quality']+1)
];
$gunDto['level'] = $gunDto['gun_lv'];
$gunDto['item_id'] = $gunDto['gun_id'];
LogService::consumeCEG($eventCEG,$gunDto,$gunDto);
}
{
//埋点
$eventCEC = [
'name' => LogService::GUN_QUALITY_UP_CONSUME,
'val' => \services\FormulaService::Weapon_Advanced_CEC_Expend($gunDb['quality']+1)
];
$gunDto['level'] = $gunDto['gun_lv'];
$gunDto['item_id'] = $gunDto['gun_id'];
LogService::consumeCEC($eventCEC,$gunDto,$gunDto);
}
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
));
}
public function upgradeQualityPreview()
{
$costGunUniId = getReqVal('cost_gun_uniid', 0);
$gunUniId = getReqVal('gun_uniid', 0);
$gunDb = Gun::find($gunUniId);
$costGunDb = Gun::findEx($costGunUniId);
if (!$gunDb || !$costGunDb) {
$this->_rspErr(100, 'server internal error');
return;
}
if (!$gunDb['token_id']){
$this->_rspErr(100, 'Free gun cannot quality up');
return;
}
if ($gunDb['gun_id'] != $costGunDb['gun_id']){
$this->_rspErr(100, 'You need the same kind of hero');
return;
}
if ($costGunDb['quality']>1){
$this->_rspErr(100, 'Material gun quality too high');
return;
}
$itemMeta = mt\Item::get($gunDb['gun_id']);
if (!$itemMeta) {
$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;
}
$newGunDb = $gunDb;
$newGunDb['quality'] += 1;
$cost['CEG'] = \services\FormulaService::Weapon_Advanced_CEG_Expend($newGunDb['quality']);
$cost['CEC'] = \services\FormulaService::Weapon_Advanced_CEC_Expend($newGunDb['quality']);
$cost['success_rate'] = \services\FormulaService::Weapon_Advanced_Probability($newGunDb['quality']);
$gunDto = Gun::toDto($gunDb);
$newGunDto = Gun::toDto($newGunDb);
$this->_rspData(array(
'old_gun' => $gunDto,
'new_gun' => $newGunDto,
'cost' => $cost
));
}
public function upgradeQuality(){
$tokenId1 = getReqVal('token_id1', '');
$tokenId2 = getReqVal('token_id2', '');
$transId = getReqVal('trans_id', '');
if (!$tokenId1 || !$tokenId2 || !$transId){
$this->_rspErr(1, ' error param');
return;
}
if (NftUpReceive::find(myself()->_getAccountId(),$transId)){
$this->_rspErr(1, ' error param trans_id ');
return;
}
Gun::updateByTokenId($tokenId1,
array(
'lock_type' => Gun::QUALITY_LOCK,
'unlock_time' => $this->_getNowTime() + 20,
)
);
Gun::updateByTokenId($tokenId2,
array(
'lock_type' => Gun::COST_LOCK,
'unlock_time' => $this->_getNowTime() + 20,
)
);
NftUpReceive::add(
myself()->_getAccountId(),
array(
'account_id' => myself()->_getAccountId(),
'trans_id' => $transId,
'token_id1' => $tokenId1,
'token_id2' => $tokenId2,
'state' => 0,
'token_type' => 2,
'from_data' => 0,
'createtime' => $this->_getNowTime(),
'modifytime' => $this->_getNowTime()
)
);
myself()->_rspOk();
}
public function receive(){
$type = getReqVal('type', 0);
$gunUniId = getReqVal('gun_uniid', 0);
$gunDb = Gun::find($gunUniId);
if (!$gunDb) {
$this->_rspErr(1, 'gun does not exist1');
return;
}
$gunDto = Gun::toDto($gunDb);
if ($gunDto['unlock_lefttime'] > 0) {
$this->_rspErr(1, 'Countdown is not over');
return;
}
$oldGun = $gunDto;
$newGun = $gunDto;
switch ($type) {
case 1:
{
$idx = 0;
$found = false;
for ($i = 0; $i < kMaxHeroUpLevelNum; ++$i) {
$upHeroUniId = $this->_getV(TN_GUN_LEVEL_UP, $i);
if ($upHeroUniId == $gunUniId) {
$idx = $i;
$found = true;
break;
}
}
if (!$found) {
$this->_rspErr(1, 'gun does not exist2');
return;
}
$this->_setV(TN_GUN_LEVEL_UP, $idx, 0);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addGunChg();
$propertyChgService->addUserChg();
$nextLevelMeta = mt\GunLevel::getByLevel($gunDb['gun_lv'] + 1);
if ($nextLevelMeta) {
$attrs = mt\GunLevel::addRandAttrNew($gunDb,1);
$where = array(
'gun_lv' => $gunDb['gun_lv'] + 1,
'rand_attr' => json_encode($attrs),
'lock_type' => 0,
'unlock_time' => 0,
);
Gun::update($gunUniId,$where);
if ($gunDb['gun_lv'] + 1 > myself()->_getV(TN_GUN_MAX_LEVEL, 0)) {
myself()->_setV(TN_GUN_MAX_LEVEL, 0, $gunDb['gun_lv'] + 1);
}
$newGunDb = Gun::find($gunUniId);
$newGun = Gun::toDto($newGunDb);
}
{
//埋点
$event = [
'name' => LogService::GUN_LEVEL_UP,
];
$oldGun['level'] = $oldGun['gun_lv'];
$oldGun['item_id'] = $oldGun['gun_id'];
$newGun['level'] = $newGun['gun_lv'];
$newGun['item_id'] = $newGun['gun_id'];
LogService::LevelUpOrQualityUp($event,$oldGun,$newGun);
}
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'old_gun' => $oldGun,
'new_gun' => $newGun,
));
}
break;
case 2:
{
$this->_rspOk();return;
$idx = 0;
$found = false;
for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) {
$upGunUniId = $this->_getV(TN_GUN_QUALITY_UP, $i);
if ($upGunUniId == $gunUniId) {
$idx = $i;
$found = true;
break;
}
}
if (!$found) {
$this->_rspErr(1, 'gun does not exist');
return;
}
$costGunUniId = $this->_getV(TN_GUN_QUALITY_UP, (int)$idx + 1000);
$this->_setV(TN_GUN_QUALITY_UP, $idx, 0);
$this->_setV(TN_GUN_QUALITY_UP, (int)$idx + 1000, 0);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addGunChg();
$propertyChgService->addUserChg();
$nextQualityMeta = mt\GunQuality::getByQuality($gunDb['quality'] + 1);
if ($nextQualityMeta) {
$costGunDb = Gun::find($costGunUniId);
if ($costGunDb['token_id']){
// SqlHelper::update(
// myself()->_getMarketMysql(),
// 't_nft',
// ['token_id'=>$costGunDb['token_id']],
// ['deleted'=>1]
// );
}else{
Gun::update($costGunUniId,
array(
'account_id' => myself()->_getAccountId() . '!!!',
'lock_type' => 0,
'unlock_time' => 0,
)
);
}
Gun::update($costGunUniId,
array(
'lock_type' => 0,
'unlock_time' => 0,
)
);
{
//埋点
$event = [
'name' => LogService::GUN_QUALITY_UP_MATERIAL,
];
$params = array(
array(
'unique_id'=>$costGunDb['idx'],
'token_id'=>$costGunDb['token_id'],
)
);
LogService::ConsumableMaterial($event,$params);
}
$rnd = rand(1, 100);
$probability = \services\FormulaService::Weapon_Advanced_Probability($gunDb['quality'] + 1)*100;
if ($rnd > $probability) {
Gun::update($gunUniId,
array(
'lock_type' => 0,
'unlock_time' => 0,
)
);
$this->_rspRawData(array(
'errcode' => 0,
'errmsg' => '',
'state' => 0,
'old_gun' => $oldGun,
'new_gun' => $newGun,
//'errmsg' => 'advance failed',
'property_chg' => $propertyChgService->toDto(),
));
return;
}
$gunLucky = \services\FormulaService::Weapon_Advanced_Lucky_Value($gunDb['quality']);
$nextGunLucky = \services\FormulaService::Weapon_Advanced_Lucky_Value($gunDb['quality'] + 1);
$durability = \services\FormulaService::Weapon_NFT_Maximum_Durability($gunDb['quality'],$gunLucky);
$nextDurability = \services\FormulaService::Weapon_NFT_Maximum_Durability($gunDb['quality'] + 1,$nextGunLucky);
Gun::update($gunUniId,
array(
'durability' => $gunDb['durability']+($nextDurability-$durability),
'quality' => $gunDb['quality'] + 1,
'lock_type' => 0,
'unlock_time' => 0,
'labour' => 0,
)
);
if ($gunDb['quality'] + 1 > myself()->_getV(TN_GUN_MAX_QUALITY, 0)) {
myself()->_setV(TN_GUN_MAX_QUALITY, 0, $gunDb['quality'] + 1);
}
$newGunDb = Gun::find($gunUniId);
$newGun = Gun::toDto($newGunDb);
error_log(json_encode(array(
'costGunUniId' => $costGunUniId,
'gunUniId' => $gunUniId
)));
$rankActivityService = new services\RankActivityService();
$rankActivityService->heroUpgradeQuality($gunDb['quality'] + 1);
}
if (!$nextQualityMeta) {
$this->_rspErr(1, 'quality is full');
return;
}
{
//埋点
$event = [
'name' => LogService::GUN_QUALITY_UP,
];
$oldGun['level'] = $oldGun['gun_lv'];
$oldGun['item_id'] = $oldGun['gun_id'];
$newGun['level'] = $newGun['gun_lv'];
$newGun['item_id'] = $newGun['gun_id'];
LogService::LevelUpOrQualityUp($event,$oldGun,$newGun);
}
$this->_rspData(array(
'state' => 1,
'property_chg' => $propertyChgService->toDto(),
'old_gun' => $oldGun,
'new_gun' => $newGun,
));
}
break;
default:
{
$this->_rspErr(1, 'type parameter error');
return;
}
break;
}
}
public function receiveUpgradeQuality(){
$transId = getReqVal('trans_id', '');
$tokenId = getReqVal('token_id', '');
if (!$tokenId || !$transId){
$this->_rspErr(1, ' error param');
return;
}
$tranDb= Transaction::find($transId);
if (!$tranDb){
myself()->_rspErr(1, 'param error');
return;
}
Gun::updateByTokenId($tokenId,
array(
'lock_type' => Gun::NO_LOCK,
'unlock_time' => 0,
)
);
$newGunDb = Gun::findByTokenId2($tokenId);
if (! $tranDb['result']){
$newGun = Gun::toDto($newGunDb);
$oldGun = $newGun;
}else{
$newGun = Gun::toDto($newGunDb);
$newGunDb['quality'] -= 1;
$oldGun = Gun::toDto($newGunDb);
}
NftUpReceive::setAccountIdNull(myself()->_getAccountId(),$transId);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addGunChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'new_gun' =>$newGun,
'old_gun'=>$oldGun,
'result'=>$tranDb['result']
));
}
public function getUpgradeQualityList(){
$list = NftUpReceive::all(myself()->_getAccountId(),2);
$infos = array();
foreach ($list as $value){
if ($this->_getNowTime() - $value['createtime'] < 24*3600 && !$value['from_data'] || $value['from_data'] ){
$gun = Gun::findByTokenId2($value['token_id1']);
$costGun = Gun::findByTokenId2($value['token_id2']);
$gunDto = null;
$costGunDto = null;
if ($gun && $costGun){
$gunDto = Gun::toDto($gun);
$costGunDto = Gun::toDto($costGun);
}
$tranDb= Transaction::find($value['trans_id']);
if (!$tranDb){
myself()->_rspErr(1, 'ERROR param '. $value['trans_id']);
continue;
}
$info = array(
'trans_id'=>$value['trans_id'],
'state'=>$value['state'],
'gunInfo'=>$gunDto,
'costGunInfo'=>$costGunDto,
'result'=>$tranDb['result']
);
array_push($infos,$info);
}
}
$this->_rspData(array(
'infos' => $infos
));
}
public function getLastQualityInfo(){
$tokenId = getReqVal('token_id', '');
if (!$tokenId){
$this->_rspErr(1, ' error param');
return;
}
$gunDb = Gun::findByTokenId2($tokenId);
if(!$gunDb || $gunDb['quality']<2){
$this->_rspErr(1, ' error param');
return;
}
$oldGunDb = $gunDb;
$oldGunDb['quality'] -= 1;
$this->_rspData(array(
'new_gun' =>Gun::toDto($gunDb),
'old_gun'=>Gun::toDto($oldGunDb)
));
}
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 ($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::getByLevel($gunDb['gun_lv'] +1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
}
//升级所需消耗
// $costItems = array();
// $lackItem = null;
// if (!$this->_hasEnoughItems($costItems, $lackItem)) {
// $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
// return;
// }
// $this->_decItems($costItems);
$attrs = mt\GunLevel::addRandAttrNew($gunDb,1);
Gun::update($gunUniId,
array(
'gun_lv' => $gunDb['gun_lv'] + 1,
'rand_attr' => json_encode($attrs),
));
Gun::update($costGunUniId,
array(
'account_id' => myself()->_getAccountId() . '!!!',
)
);
$newGun = Gun::toDto(Gun::find($gunUniId));
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addGunChg();
$propertyChgService->addUserChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'old_gun' => $oldGun,
'new_gun' => $newGun,
));
}
}