英雄枪械升级属性更新

This commit is contained in:
hujiabin 2023-03-14 16:44:59 +08:00
parent a7c0282113
commit 35e2a6cfba
8 changed files with 304 additions and 2139 deletions

View File

@ -83,8 +83,7 @@ class Gun(object):
['quality', 0, '品阶'],
['durability', 0, '耐久'],
['ceg_uplimit', 0, 'ceg今天获取上限'],
['!attr_base', [Attr()], '枪械基础属性'],
['!attr_pro', [Attr()], '枪械升级升阶加成属性'],
['!rand_attr', [Attr()], '枪械属性'],
['try_count', 0, '剩余体验次数 当state=1时才有意义'],
['lock_type', 0, '0:无锁 1:升级 2:升阶 3:派遣中'],
['unlock_time', 0, '使用解锁utc时间(升级或者升阶触发),锁定期间不可战斗和做其他操作,配合lock_type使用'],
@ -239,8 +238,7 @@ class Hero(object):
['quality', 0, '品阶'],
['skill_lv1', 0, '主动技能等级'],
['skill_lv2', 0, '被动技能等级'],
['!attr_base', [Attr()], '英雄基础属性'],
['!attr_pro', [Attr()], '英雄升级升阶提升属性'],
['!rand_attr', [Attr()], '英雄属性'],
['try_count', 0, '剩余体验次数 当state=1时才有意义'],
['lock_type', 0, '0:无锁 1:升级 2:升阶 3:派遣中'],
['unlock_lefttime', 0, '解锁剩余时间(单位秒)'],

View File

@ -52,6 +52,18 @@ class GunController extends BaseAuthedController {
));
}
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) {
@ -124,126 +136,6 @@ class GunController extends BaseAuthedController {
));
}
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);
@ -256,7 +148,7 @@ class GunController extends BaseAuthedController {
$this->_rspErr(100, 'server internal error');
return;
}
$nextLevelMeta = mt\GunLevel::getByLevel($gunDb['gun_lv'] +1);
$nextLevelMeta = \mt\GunLevel::find($gunDb['gun_id'],$gunDb['gun_lv']+1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
@ -275,7 +167,7 @@ class GunController extends BaseAuthedController {
$newGunDb = $gunDb;
$newGunDb['gun_lv'] += 1;
$attrs = mt\GunLevel::addRandAttrNew($gunDb,0);
$attrs = Gun::LvUpAddAttr($gunDb,0);
$newGunDb['rand_attr'] = json_encode($attrs);
@ -288,551 +180,6 @@ class GunController extends BaseAuthedController {
));
}
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);
@ -861,7 +208,7 @@ class GunController extends BaseAuthedController {
return;
}
$nextLevelMeta = mt\GunLevel::getByLevel($gunDb['gun_lv'] +1);
$nextLevelMeta = \mt\GunLevel::find($gunDb['gun_id'],$gunDb['gun_lv']+1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
@ -885,7 +232,7 @@ class GunController extends BaseAuthedController {
}
$this->_decItems($costItems);
$attrs = mt\GunLevel::addRandAttrNew($gunDb,1);
$attrs = Gun::LvUpAddAttr($gunDb,1);
Gun::update($gunUniId,
array(
'gun_lv' => $gunDb['gun_lv'] + 1,
@ -908,4 +255,6 @@ class GunController extends BaseAuthedController {
));
}
}

View File

@ -131,27 +131,26 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(100, 'server internal error');
return;
}
$nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1);
$nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv'] + 1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
}
$meta = mt\HeroLevel::get($heroDb['hero_lv'] + 1);
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $meta['gold']
'item_num' => $nextLevelMeta['gold']
),
array(
'item_id' => V_ITEM_DIAMOND,
'item_num' => $meta['diamond']
'item_num' => $nextLevelMeta['diamond']
)
);
$newHeroDb = $heroDb;
$newHeroDb['hero_lv'] += 1;
$attrs = mt\HeroLevelAttr::addRandAttrNew($heroDb,0);
$attrs = Hero::LvUpAddAttr($heroDb,0);
$newHeroDb['rand_attr'] = json_encode($attrs);
$heroDto = Hero::toDto($heroDb);
@ -216,22 +215,21 @@ class HeroController extends BaseAuthedController {
$this->_rspErr(100, 'server internal error');
return;
}
$nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1);
$nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv'] + 1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
}
//升级所需消耗
$meta = mt\HeroLevel::get($heroDb['hero_lv'] + 1);
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $meta['gold']
'item_num' => $nextLevelMeta['gold']
),
array(
'item_id' => V_ITEM_DIAMOND,
'item_num' => $meta['diamond']
'item_num' => $nextLevelMeta['diamond']
)
);
$lackItem = null;
@ -241,7 +239,7 @@ class HeroController extends BaseAuthedController {
}
$this->_decItems($costItems);
$attrs = mt\HeroLevelAttr::addRandAttrNew($heroDb,1);
$attrs = Hero::LvUpAddAttr($heroDb,1);
Hero::update($heroUniId, array(
'hero_lv' => $heroDb['hero_lv'] + 1,
'rand_attr' => json_encode($attrs),
@ -379,823 +377,4 @@ class HeroController extends BaseAuthedController {
}
public function upgradeSkillCommon(){
$heroUniId = getReqVal('hero_uniid', 0);
$skillIndex = getReqVal('skill_index', 0);
$heroDb = Hero::find($heroUniId);
if (!$heroDb) {
$this->_rspErr(1, "You don't have the hero yet");
return;
}
$item = explode('|',$heroDb['skill_common']);
$skill_common = \mt\SkillCommon::get($item[$skillIndex]);
if (!$skill_common){
$this->_rspErr(1, "You don't have the skill yet");
return;
}
$next_skill_common = \mt\SkillCommon::get($skill_common['nextlv_skill']);
if (! $next_skill_common){
$this->_rspErr(1, "It's already the highest level");
return;
}
if($heroDb['quality'] < $next_skill_common['skill_limit_star']){
$this->_rspErr(1, "Hero level is not enough");
return;
}
if($heroDb['skill_points'] < $next_skill_common['skill_point_cost']){
$this->_rspErr(1, "Not enough hero skill points");
return;
}
$item[$skillIndex] = $skill_common['nextlv_skill'];
$where = [
'skill_common'=>implode('|',$item),
'skill_points'=>$heroDb['skill_points']-$next_skill_common['skill_point_cost'],
'modifytime' => $this->_getNowTime()
];
Hero::update($heroUniId, $where);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'propery_chg' => $propertyChgService->toDto(),
));
}
public function upgradeSkill()
{
$heroUniId = getReqVal('hero_uniid', 0);
$skillUniId = getReqVal('skill_uniid', 0);
$skillIdx = getReqVal('skill_idx', 0);
$heroDb = Hero::find($heroUniId);
if (!$heroDb) {
$this->_rspErr(1, "You don't have the hero yet");
return;
}
if (!in_array($skillIdx, array(0, 1))) {
$this->_rspErr(1, 'skill_idx must be 0-1');
return;
}
$skill = \mt\Skill::get($skillUniId);
if (!$skill){
$this->_rspErr(1, "You don't have the skill yet");
return;
}
$next_skill = \mt\Skill::get($skill['nextlv_skill']);
if (!$next_skill){
$this->_rspErr(1, "It's already the highest level");
return;
}
if($heroDb['quality'] < $next_skill['skill_limit_star']){
$this->_rspErr(1, "Hero level is not enough");
return;
}
if(! $heroDb['skill_points'] || $heroDb['skill_points'] < $next_skill['skill_point']){
$this->_rspErr(1, "Not enough hero skill points");
return;
}
Hero::upgradeSkill($heroUniId,$skillIdx,$next_skill['skill_point']);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'propery_chg' => $propertyChgService->toDto(),
));
}
public function getUpgradeLevelList()
{
$infos = array();
for ($i = 0; $i < kMaxHeroUpLevelNum; ++$i) {
$heroUniId = $this->_getV(TN_HERO_LEVEL_UP, $i);
$info = null;
if ($heroUniId) {
$heroDb = Hero::find($heroUniId);
if ($heroDb) {
$heroDto = Hero::toDto($heroDb);
$info = array(
'info' => $heroDto,
'countdown' => $heroDto['unlock_lefttime']
);
}
}
array_push($infos, $info);
}
$this->_rspData(array(
'infos' => $infos
));
}
public function getUpgradeQualityList()
{
// $infos = array();
// for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) {
// $heroUniId = $this->_getV(TN_HERO_QUALITY_UP, $i);
// $info = null;
// if ($heroUniId) {
// $heroDb = Hero::find($heroUniId);
// if ($heroDb) {
// $heroDto = Hero::toDto($heroDb);
// $info = array(
// 'info' => $heroDto,
// 'countdown' => $heroDto['unlock_lefttime']
// );
// }
// }
// array_push($infos, $info);
// }
// $this->_rspData(array(
// 'infos' => $infos
// ));
$list = NftUpReceive::all(myself()->_getAccountId(),1);
$infos = array();
foreach ($list as $value){
if ($this->_getNowTime() - $value['createtime'] < 24*3600 && !$value['from_data'] || $value['from_data'] ){
$hero = Hero::findByTokenId2($value['token_id1']);
$costHero = Hero::findByTokenId2($value['token_id2']);
$heroDto = null;
$costHeroDto = null;
if ($hero && $costHero){
$heroDto = Hero::toDto($hero);
$costHeroDto = Hero::toDto($costHero);
}
$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'],
'heroInfo'=>$heroDto,
'costHeroInfo'=>$costHeroDto,
'result'=>$tranDb['result']
);
array_push($infos,$info);
}
}
$this->_rspData(array(
'infos' => $infos
));
}
public function receive()
{
$type = getReqVal('type', 0);
$heroUniId = getReqVal('hero_uniid', 0);
$heroDb = Hero::find($heroUniId);
if (!$heroDb) {
$this->_rspErr(1, 'hero does not exist1');
return;
}
$heroDto = Hero::toDto($heroDb);
if ($heroDto['unlock_lefttime'] > 0) {
$this->_rspErr(1, 'Countdown is not over');
return;
}
$oldHero = $heroDto;
$newHero = $heroDto;
switch ($type) {
case 1:
{
$idx = 0;
$found = false;
for ($i = 0; $i < kMaxHeroUpLevelNum; ++$i) {
$upHeroUniId = $this->_getV(TN_HERO_LEVEL_UP, $i);
if ($upHeroUniId == $heroUniId) {
$idx = $i;
$found = true;
break;
}
}
if (!$found) {
$this->_rspErr(1, 'hero does not exist2');
return;
}
$this->_setV(TN_HERO_LEVEL_UP, $idx, 0);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$propertyChgService->addBagChg();
$propertyChgService->addUserChg();
$nextLevelMeta = null;
$nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1);
if ($nextLevelMeta) {
$attrs = mt\HeroLevelAttr::addRandAttrNew($heroDb,1);
$where = array(
'hero_lv' => $heroDb['hero_lv'] + 1,
'rand_attr' => json_encode($attrs),
'lock_type' => 0,
'unlock_time' => 0,
'skill_points' => $heroDb['skill_points']+$nextLevelMeta['skill_point']
);
//免费英雄到底15级后生成NFT
// if ($heroDb['hero_lv'] + 1 == 15 && !$heroDb['token_id']){
// $token_id = myself()->_getNowTime();
// if(!\services\NftService::addNft($heroDb['hero_id'],$token_id)){
// return ;
// }
// $where = array(
// 'hero_lv' => $heroDb['hero_lv'] + 1,
// 'token_id'=> $token_id,
// 'rand_attr' => json_encode($attrs),
// 'lock_type' => 0,
// 'unlock_time' => 0,
// 'skill_points' => $heroDb['skill_points']+$nextLevelMeta['skill_point']
// );
// }
Hero::update($heroUniId, $where);
if ($heroDb['hero_lv'] + 1 > myself()->_getV(TN_HERO_MAX_LEVEL, 0)) {
myself()->_setV(TN_HERO_MAX_LEVEL, 0, $heroDb['hero_lv'] + 1);
}
$newHeroDb = Hero::find($heroUniId);
$newHero = Hero::toDto($newHeroDb);
}
{
//埋点
$event = [
'name' => LogService::HERO_LEVEL_UP,
];
$oldHero['level'] = $oldHero['hero_lv'];
$oldHero['item_id'] = $oldHero['hero_id'];
$newHero['level'] = $newHero['hero_lv'];
$newHero['item_id'] = $newHero['hero_id'];
LogService::LevelUpOrQualityUp($event,$oldHero,$newHero);
}
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'old_hero' => $oldHero,
'new_hero' => $newHero,
));
}
break;
case 2:
{
$this->_rspOk();return;
$idx = 0;
$found = false;
for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) {
$upHeroUniId = $this->_getV(TN_HERO_QUALITY_UP, $i);
if ($upHeroUniId == $heroUniId) {
$idx = $i;
$found = true;
break;
}
}
if (!$found) {
$this->_rspErr(1, 'hero does not exist');
return;
}
$costHeroUniId = $this->_getV(TN_HERO_QUALITY_UP, (int)$idx + 1000);
$this->_setV(TN_HERO_QUALITY_UP, $idx, 0);
$this->_setV(TN_HERO_QUALITY_UP, (int)$idx + 1000, 0);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$propertyChgService->addBagChg();
$propertyChgService->addUserChg();
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
if ($nextQualityMeta) {
$costHeroDb = Hero::find($costHeroUniId);
if ($costHeroDb['token_id']){
// SqlHelper::update(
// myself()->_getMarketMysql(),
// 't_nft',
// ['token_id'=>$costHeroDb['token_id']],
// ['deleted'=>1]
// );
}else{
Hero::update($costHeroUniId,
array(
'account_id' => myself()->_getAccountId() . '!!!',
)
);
}
Hero::update($costHeroUniId,
array(
'lock_type' => 0,
'unlock_time' => 0,
)
);
{
//埋点
$event = [
'name' => LogService::HERO_QUALITY_UP_MATERIAL,
];
$params = array(
array(
'unique_id'=>$costHeroDb['idx'],
'token_id'=>$costHeroDb['token_id'],
)
);
LogService::ConsumableMaterial($event,$params);
}
$rnd = rand(1, 100);
$probability = \services\FormulaService::Hero_Advanced_Probability($heroDb['quality'] + 1)*100;
if ($rnd > $probability) {
Hero::update($heroUniId,
array(
'advanced_count' => $heroDb['advanced_count'] + 1,
'lock_type' => 0,
'unlock_time' => 0,
)
);
$oldHero['advanced_count'] += 1;
$newHero['advanced_count'] += 1;
{
//埋点
$event = [
'name' => LogService::HERO_QUALITY_UP,
];
$oldHero['level'] = $oldHero['hero_lv'];
$oldHero['item_id'] = $oldHero['hero_id'];
$newHero['level'] = $newHero['hero_lv'];
$newHero['item_id'] = $newHero['hero_id'];
LogService::LevelUpOrQualityUp($event,$oldHero,$newHero);
}
$this->_rspRawData(array(
'errcode' => 0,
'errmsg' => '',
'state' => 0,
'old_hero' => $oldHero,
'new_hero' => $newHero,
//'errmsg' => 'advance failed',
'property_chg' => $propertyChgService->toDto(),
));
return;
}
$heroLucky = \services\FormulaService::Hero_Advanced_Lucky_Value($heroDb['quality']);
$nextHeroLucky = \services\FormulaService::Hero_Advanced_Lucky_Value($heroDb['quality'] + 1);
$heroTili = \services\FormulaService::Hero_NFT_Maximum_Physical_Strength($heroDb['quality'],$heroLucky);
$nextHeroTili = \services\FormulaService::Hero_NFT_Maximum_Physical_Strength($heroDb['quality'] + 1,$nextHeroLucky);
Hero::update($heroUniId,
array(
'hero_tili' => $heroDb['hero_tili']+($nextHeroTili-$heroTili),
'skill_points' => $heroDb['skill_points'] + $nextQualityMeta['skill_point'],
'quality' => $heroDb['quality'] + 1,
'advanced_count' => $heroDb['advanced_count'] + 1,
'lock_type' => 0,
'unlock_time' => 0,
'labour' => 0,
)
);
if ($heroDb['quality'] + 1 > myself()->_getV(TN_HERO_MAX_QUALITY, 0)) {
myself()->_setV(TN_HERO_MAX_QUALITY, 0, $heroDb['quality'] + 1);
}
$newHeroDb = Hero::find($heroUniId);
$newHero = Hero::toDto($newHeroDb);
error_log(json_encode(array(
'costHeroUniId' => $costHeroUniId,
'heroUniId' => $heroUniId
)));
$rankActivityService = new services\RankActivityService();
$rankActivityService->heroUpgradeQuality($heroDb['quality'] + 1);
}
if (!$nextQualityMeta) {
$this->_rspErr(1, 'quality is full');
return;
}
{
//埋点
$event = [
'name' => LogService::HERO_QUALITY_UP,
];
$oldHero['level'] = $oldHero['hero_lv'];
$oldHero['item_id'] = $oldHero['hero_id'];
$newHero['level'] = $newHero['hero_lv'];
$newHero['item_id'] = $newHero['hero_id'];
LogService::LevelUpOrQualityUp($event,$oldHero,$newHero);
}
$this->_rspData(array(
'state' => 1,
'property_chg' => $propertyChgService->toDto(),
'old_hero' => $oldHero,
'new_hero' => $newHero,
));
}
break;
default:
{
$this->_rspErr(1, 'type parameter error');
return;
}
break;
}
}
public function upgradeLevel()
{
$heroUniId = getReqVal('hero_uniid', 0);
$slotId = getReqVal('slot_id', 0);
$heroDb = Hero::find($heroUniId);
if (!in_array($slotId, array(0, kMaxHeroUpLevelNum - 1))) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
{
$srcHeroDb = Hero::find($this->_getV(TN_HERO_LEVEL_UP, $slotId));
if ($srcHeroDb) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
}
if (!$heroDb) {
$this->_rspErr(1, 'hero does not exist');
return;
}
if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
}
$heroMeta = mt\Hero::get($heroDb['hero_id']);
if (!$heroMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
}
if ($heroDb['hero_lv'] + 1 == 15 && !$heroDb['token_id']){
$this->_rspErr(1, "Free heroes cannot continue to level up");
return;
}
$is_cec = false;
if ($heroDb['hero_lv']+1 <15){
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => \services\FormulaService::Hero_Upgrade_CEG_Expend($heroDb['hero_lv']+1)
)
);
}else{
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => \services\FormulaService::Hero_Upgrade_CEG_Expend($heroDb['hero_lv']+1)
),
array(
'item_id' => V_ITEM_DIAMOND,
'item_num' => \services\FormulaService::Hero_Upgrade_CEC_Expend($heroDb['hero_lv']+1)
)
);
$is_cec = true;
}
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$heroDto = Hero::toDto($heroDb);
{
//埋点
$eventCEG = [
'name' => LogService::HERO_LEVEL_UP_CONSUME,
'val' => \services\FormulaService::Hero_Upgrade_CEG_Expend($heroDb['hero_lv']+1)
];
$heroDto['level'] = $heroDto['hero_lv'];
$heroDto['item_id'] = $heroDto['hero_id'];
LogService::consumeCEG($eventCEG,$heroDto,$heroDto);
}
if ($is_cec){
{
//埋点
$eventCEC = [
'name' => LogService::HERO_LEVEL_UP_CONSUME,
'val' => \services\FormulaService::Hero_Upgrade_CEC_Expend($heroDb['hero_lv']+1)
];
$heroDto['level'] = $heroDto['hero_lv'];
$heroDto['item_id'] = $heroDto['hero_id'];
LogService::consumeCEC($eventCEC,$heroDto,$heroDto);
}
}
$this->_decItems($costItems);
{
Hero::update(
$heroUniId,
array(
'lock_type' => Hero::LEVEL_LOCK
)
);
}
$this->_setV(TN_HERO_LEVEL_UP, (int)$slotId, (int)$heroDb['idx']);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$propertyChgService->addBagChg();
$propertyChgService->addUserChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
));
}
public function upgradeQualityOld()
{
$costHeroUniId = getReqVal('cost_hero_uniid', 0);
$heroUniId = getReqVal('hero_uniid', 0);
$slotId = getReqVal('slot_id', 0);
$heroDb = Hero::find($heroUniId);
if (!in_array($slotId, array(0, kMaxHeroUpQualityNum - 1))) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
if (!$heroDb['token_id']){
$this->_rspErr(100, 'Free heroes cannot quality up');
return;
}
$costHeroDb = Hero::find($costHeroUniId);
if (!$costHeroDb) {
$this->_rspErr(1, 'cost hero parameter error');
return;
}
if ($heroDb['hero_id'] != $costHeroDb['hero_id']){
$this->_rspErr(100, 'You need the same kind of hero');
return;
}
if ($costHeroDb['quality']>1){
$this->_rspErr(100, 'Material hero quality too high');
return;
}
if ($costHeroDb['lock_type']) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
}
{
$srcHeroDb = Hero::find($this->_getV(TN_HERO_QUALITY_UP, $slotId));
if ($srcHeroDb) {
$this->_rspErr(1, 'slot_id parameter error');
return;
}
}
{
$idx = 0;
$found = false;
for ($i = 0; $i < kMaxHeroUpQualityNum; ++$i) {
$upHeroUniId = $this->_getV(TN_HERO_QUALITY_UP, $i);
if ($upHeroUniId == $heroUniId) {
$idx = $i;
$found = true;
break;
}
}
if ($found) {
$this->_rspErr(1, 'hero already upgrading');
return;
}
}
if (!$heroDb) {
$this->_rspErr(1, 'hero does not exist');
return;
}
if ($heroDb['advanced_count'] >= mt\Parameter::getVal('advence_limit', 0)) {
$this->_rspErr(1, 'hero does not exist');
return;
}
if ($heroDb['state'] != Hero::GETED_STATE) {
$this->_rspErr(3, 'Trial hero cannot operate');
return;
}
if ($heroDb['lock_type']) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
}
if ($heroDb['unlock_trade_time'] > $this->_getNowTime()) {
$this->_rspErr(2, 'Cannot operate during locking');
return;
}
$heroMeta = mt\Hero::get($heroDb['hero_id']);
if (!$heroMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
if (!$nextQualityMeta) {
$this->_rspErr(5, "It's already the highest quality");
return;
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => \services\FormulaService::Hero_Advanced_CEG_Expend($heroDb['quality']+1)
),
array(
'item_id' => V_ITEM_DIAMOND,
'item_num' => \services\FormulaService::Hero_Advanced_CEC_Expend($heroDb['quality']+1)
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$this->_decItems($costItems);
Hero::update($heroUniId,
array(
'lock_type' => Hero::QUALITY_LOCK,
'unlock_time' => $this->_getNowTime() + $nextQualityMeta['time'],
)
);
Hero::update($costHeroUniId,
array(
'lock_type' => Hero::COST_LOCK,
'unlock_time' => $this->_getNowTime() + $nextQualityMeta['time'],
)
);
$this->_setV(TN_HERO_QUALITY_UP, (int)$slotId, (int)$heroDb['idx']);
$this->_setV(TN_HERO_QUALITY_UP, (int)$slotId + 1000, (int)$costHeroDb['idx']);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$propertyChgService->addBagChg();
$propertyChgService->addUserChg();
$heroDto = Hero::toDto($heroDb);
{
//埋点
$eventCEG = [
'name' => LogService::HERO_QUALITY_UP_CONSUME,
'val' => \services\FormulaService::Hero_Advanced_CEG_Expend($heroDb['quality']+1)
];
$heroDto['level'] = $heroDto['hero_lv'];
$heroDto['item_id'] = $heroDto['hero_id'];
LogService::consumeCEG($eventCEG,$heroDto,$heroDto);
}
{
//埋点
$eventCEC = [
'name' => LogService::HERO_QUALITY_UP_CONSUME,
'val' => \services\FormulaService::Hero_Advanced_CEC_Expend($heroDb['quality']+1)
];
$heroDto['level'] = $heroDto['hero_lv'];
$heroDto['item_id'] = $heroDto['hero_id'];
LogService::consumeCEC($eventCEC,$heroDto,$heroDto);
}
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
));
}
public function upgradeQualityPreview()
{
$heroUniId = getReqVal('hero_uniid', 0);
$costHeroUniId = getReqVal('cost_hero_uniid', 0);
$heroDb = Hero::find($heroUniId);
$costHeroDb = Hero::findEx($costHeroUniId);
if (!$heroDb) {
$this->_rspErr(100, 'server internal error');
return;
}
if (!$heroDb['token_id']){
$this->_rspErr(100, 'Free heroes cannot quality up');
return;
}
if ($heroDb['hero_id'] != $costHeroDb['hero_id']){
$this->_rspErr(100, 'You need the same kind of hero');
return;
}
if ($costHeroDb['quality']>1){
$this->_rspErr(100, 'Material hero quality too high');
return;
}
$heroMeta = mt\Hero::get($heroDb['hero_id']);
if (!$heroMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$nextQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality'] + 1);
if (!$nextQualityMeta) {
$this->_rspErr(5, "It's already the highest level1");
return;
}
$newHeroDb = $heroDb;
$newHeroDb['quality'] += 1;
$cost['CEG'] = \services\FormulaService::Hero_Advanced_CEG_Expend($newHeroDb['quality']);
$cost['CEC'] = \services\FormulaService::Hero_Advanced_CEC_Expend($newHeroDb['quality']);
$cost['success_rate'] = \services\FormulaService::Hero_Advanced_Probability($newHeroDb['quality']);
$heroDto = Hero::toDto($heroDb);
$newHeroDto = Hero::toDto($newHeroDb);
$this->_rspData(array(
'old_hero' => $heroDto,
'new_hero' => $newHeroDto,
'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;
}
Hero::updateByTokenId($tokenId1,
array(
'lock_type' => Hero::QUALITY_LOCK,
'unlock_time' => $this->_getNowTime() + 3600 * 24,
)
);
Hero::updateByTokenId($tokenId2,
array(
'lock_type' => Hero::COST_LOCK,
'unlock_time' => $this->_getNowTime() + 3600 * 24,
)
);
NftUpReceive::add(
myself()->_getAccountId(),
array(
'account_id' => myself()->_getAccountId(),
'trans_id' => $transId,
'token_id1' => $tokenId1,
'token_id2' => $tokenId2,
'state' => 0,
'token_type' => 1,
'from_data' => 0,
'createtime' => $this->_getNowTime(),
'modifytime' => $this->_getNowTime()
)
);
myself()->_rspOk();
}
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;
}
Hero::updateByTokenId($tokenId,
array(
'lock_type' => Hero::NO_LOCK,
'unlock_time' => 0,
)
);
$newHeroDb = Hero::findByTokenId2($tokenId);
if (! $tranDb['result']){
$newHero = Hero::toDto($newHeroDb);
$oldHero = $newHero;
}else{
$newHero = Hero::toDto($newHeroDb);
$newHeroDb['quality'] -= 1;
$oldHero = Hero::toDto($newHeroDb);
}
NftUpReceive::setAccountIdNull(myself()->_getAccountId(),$transId);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'new_hero' =>$newHero,
'old_hero'=>$oldHero,
'result'=>$tranDb['result']
));
}
public function getLastQualityInfo(){
$tokenId = getReqVal('token_id', '');
if (!$tokenId){
$this->_rspErr(1, ' error param');
return;
}
$heroDb = Hero::findByTokenId2($tokenId);
if(!$heroDb || $heroDb['quality']<2){
$this->_rspErr(1, ' error param');
return;
}
$oldHeroDb = $heroDb;
$oldHeroDb['quality'] -= 1;
$this->_rspData(array(
'new_hero' =>Hero::toDto($heroDb),
'old_hero'=>Hero::toDto($oldHeroDb)
));
}
}

View File

@ -546,6 +546,7 @@ class UserController extends BaseAuthedController {
}
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto()
));

View File

@ -49,6 +49,7 @@ class Gun extends BaseModel {
}
return $row;
}
public static function findEx($gunUniId){
$row = SqlHelper::ormSelectOne(
myself()->_getSelfMysql(),
@ -233,6 +234,10 @@ class Gun extends BaseModel {
public static function toDto($row)
{
$attr = emptyReplace(json_decode($row['rand_attr'], true), array());
if (!$attr){
$itemMeta = mt\Item::get($row['gun_id']);
$attr = mt\Equip::getGunBaseAttrs($itemMeta['relationship']);
}
// $lockType = 0;
// $unlockTime = 0;
// //if ($row['lock_type'] != 0 && $row['unlock_time'] - myself()->_getNowTime() > 0) {
@ -240,21 +245,7 @@ class Gun extends BaseModel {
$lockType = $row['lock_type'];
$unlockTime = $row['unlock_time'];
}
$itemMeta = mt\Item::get($row['gun_id']);
$baseAttr=[];
$attrPro=[];
if ($itemMeta) {
$baseAttr = mt\Equip::getGunBaseAttrs($itemMeta['relationship']);
$attrPro1=[];
if ($row['gun_lv']>1){
$attrPro1 = self::getAttrProByLevel($row,$baseAttr,$attr);
}
$attrPro2=[];
if ($row['quality']>1){
$attrPro2 = self::getAttrProByQuality($row,$baseAttr);
}
$attrPro = self::mergeAttrPro($baseAttr,$attrPro1,$attrPro2);
}
$todayGetGold = $row['today_get_gold'];
$lastGetGoldTime = $row['last_get_gold_time'];
if (myself()->_getDaySeconds($lastGetGoldTime) < myself()->_getNowDaySeconds()) {
@ -284,8 +275,7 @@ class Gun extends BaseModel {
'ceg_uplimit' => 0,
'pve_ceg_uplimit' => 0,
'raw_pve_ceg_uplimit' => 0,
'attr_base' => $baseAttr,
'attr_pro' => $attrPro,
'rand_attr' => $attr,
'try_count' => $row['try_count'],
'current_pvp_get_ceg' => $todayGetGold / 100,
'last_pvp_get_ceg_time' => $lastGetGoldTime,
@ -489,142 +479,6 @@ class Gun extends BaseModel {
return $finalyAddGold;
}
private static function getAttrProByLevel($row,$baseAttr,$attr){
$attrPro1 = [];
$itemMeta = mt\Item::get($row['gun_id']);
if ($itemMeta){
$coefficient_level = mt\GunLevel::getCoefficientByLevel($row['gun_lv'],$itemMeta['relationship']);
foreach ($baseAttr as $val){
$coef_level = mt\GunLevel::getByCoefficient($coefficient_level,$val['attr_id']);
foreach ($attr as $v){
//狙击抢和散弹枪不用提升弹夹数量
if ($val['attr_id'] == $v['attr_id'] && $val['attr_id'] == kHAT_Volume ){
if (in_array($itemMeta['id'],self::$limit_the_cartridge_gun)){
array_push($attrPro1,[
'attr_id' => $val['attr_id'],
'type'=> $val['type'],
'val' => strval(1)
]);
}else{
array_push($attrPro1,[
'attr_id' => $val['attr_id'],
'type'=> $val['type'],
'val' => strval($val['val']*pow($v['val'],$coef_level['val'])),
]);
}
}
//装弹时间升级提升公式
if ($val['attr_id'] == $v['attr_id'] && $val['attr_id'] == kHAT_ReloadTime){
array_push($attrPro1,[
'attr_id' => $val['attr_id'],
'type'=> $val['type'],
'val' => strval($val['val']/pow($v['val'],$coef_level['val']))
]);
}
if ($val['attr_id'] == $v['attr_id'] && $val['attr_id'] != kHAT_ReloadTime && $val['attr_id'] != kHAT_Volume &&
$val['attr_id'] != kHAT_FireRate && $val['attr_id'] != kHAT_BulletSpeed){
array_push($attrPro1,[
'attr_id' => $val['attr_id'],
'type'=> $val['type'],
'val' => strval($val['val']*pow($v['val'],$coef_level['val'])),
]);
}
}
}
}
return $attrPro1;
}
private static function getAttrProByQuality($row,$baseAttr){
$attrPro2 = [];
$itemMeta = mt\Item::get($row['gun_id']);
if ($itemMeta) {
$qualityMeta = mt\GunQuality::getByQuality($row['quality']);
$coefficient_quality = mt\GunQuality::getCoefficientByQuality($row['quality'], $itemMeta['relationship']);
foreach ($baseAttr as $val) {
$coef_quality = mt\HeroQuality::getByCoefficient($coefficient_quality, $val['attr_id']);
if ($coef_quality){
//射速升级提升公式
if ($val['attr_id'] == kHAT_ReloadTime){
array_push($attrPro2,[
'attr_id' => $val['attr_id'],
'type'=> $val['type'],
'val' => strval($val['val']/pow($qualityMeta['promote_val'] , $coef_quality['val']))
]);
}
if ($val['attr_id'] == kHAT_Volume){
if (in_array($itemMeta['id'],self::$limit_the_cartridge_gun)){
array_push($attrPro2,[
'attr_id' => $val['attr_id'],
'type'=> $val['type'],
'val' => strval(1)
]);
}else{
array_push($attrPro2, [
'attr_id' => $val['attr_id'],
'type' => $val['type'],
'val' => strval($val['val'] * pow($qualityMeta['promote_val'], $coef_quality['val'])),
]);
}
}
if($val['attr_id'] != kHAT_ReloadTime && $val['attr_id'] != kHAT_Volume &&
$val['attr_id'] != kHAT_FireRate && $val['attr_id'] != kHAT_BulletSpeed){
array_push($attrPro2, [
'attr_id' => $val['attr_id'],
'type' => $val['type'],
'val' => strval($val['val'] * pow($qualityMeta['promote_val'], $coef_quality['val'])),
]);
}
}
}
}
return $attrPro2;
}
private static function mergeAttrPro($baseAttr,$attrPro1,$attrPro2){
$newAttr = [];
$newAttrPro = [];
if ($attrPro1 && !$attrPro2){
$newAttrPro = $attrPro1;
}
if (!$attrPro1 && $attrPro2){
$newAttrPro = $attrPro2;
}
if ($attrPro1 && $attrPro2){
foreach ($attrPro1 as $value){
foreach ($attrPro2 as $val){
if ($value['attr_id'] == $val['attr_id']){
array_push($newAttr,
[
'attr_id' => $value['attr_id'],
'type' => $value['type'],
'val' => $value['val']+$val['val'],
]);
}
}
}
if ($newAttr){
foreach ($baseAttr as $value){
foreach ($newAttr as $val){
if ($value['attr_id'] == $val['attr_id']){
array_push($newAttrPro,
[
'attr_id' => $value['attr_id'],
'type' => $value['type'],
'val' => strval($val['val']-$value['val'])
]);
}
}
}
}
}
return $newAttrPro;
}
public static function calcMissionGainGold($gunDto, $count)
{
if ($count <= 0) {
@ -670,22 +524,10 @@ class Gun extends BaseModel {
public static function toDtoInfo($row){
$attr = emptyReplace(json_decode($row['rand_attr'], true), array());
$itemMeta = mt\Item::get($row['gun_id']);
$baseAttr=[];
$attrPro=[];
$gun_name = 'XXX';
if ($itemMeta) {
$gun_name = $itemMeta['name'];
$baseAttr = mt\Equip::getGunBaseAttrs($itemMeta['relationship']);
$attrPro1=[];
if ($row['gun_lv']>1){
$attrPro1 = self::getAttrProByLevel($row,$baseAttr,$attr);
}
$attrPro2=[];
if ($row['quality']>1){
$attrPro2 = self::getAttrProByQuality($row,$baseAttr);
}
$attrPro = self::mergeAttrPro($baseAttr,$attrPro1,$attrPro2);
if (!$attr){
$attr = mt\Equip::getGunBaseAttrs($itemMeta['relationship']);
}
$todayGetGold = $row['today_get_gold'];
$lastGetGoldTime = $row['last_get_gold_time'];
if (myself()->_getDaySeconds($lastGetGoldTime) < myself()->_getNowDaySeconds()) {
@ -699,30 +541,18 @@ class Gun extends BaseModel {
}
$gunLucky = \services\FormulaService::Weapon_Advanced_Lucky_Value($row['quality']);
$rand_attr = $baseAttr;
if ($attrPro){
foreach ($rand_attr as $k=>$value){
foreach ($attrPro as $val){
if ($val['attr_id'] == $value['attr_id']){
$rand_attr[$k]['val'] = $val['val'];
}
}
}
}
$info = array(
'idx' => $row['idx'],
'token_id' => $row['token_id'],
'gun_uniid' => $row['idx'],
'gun_name' => $gun_name,
'gun_name' => $itemMeta['name'],
'gun_id' => $row['gun_id'],
'gun_lv' => $row['gun_lv'],
'state' => $row['state'],
'quality' => $row['quality'],
'lucky' => strval($gunLucky),
'durability' => $row['durability'],
'rand_attr' => array_values($rand_attr),
'rand_attr' => $attr,
'current_pvp_get_ceg' => $todayGetGold / 100,
'current_pve_get_ceg' => $todayPveGetCeg / 100,
'chip_ids' => $row['chip_ids'],
@ -736,23 +566,55 @@ class Gun extends BaseModel {
return $info;
}
private static function _mergeArr($data){
if ($data){
$result = array();
foreach ($data as $value){
$key = $value['attr_id'];
if(!isset($result[$key])){
$result[$key] = array(
'attr_id'=>$value['attr_id'],
'type'=>$value['type'],
'val'=>$value['val'],
);
}else{
$result[$key]['val'] += $value['val'];
public static function LvUpAddAttr($gunDb,$type){
if ($gunDb['gun_lv'] == 1){
$itemMeta = mt\Item::get($gunDb['gun_id']);
$baseAttr = mt\Equip::getGunBaseAttrs($itemMeta['relationship']);
}else{
$baseAttr = emptyReplace(json_decode($gunDb['rand_attr'], true), array());
}
$gunLevelMeta = \mt\GunLevel::find($gunDb['gun_id'],$gunDb['gun_lv']+1);
$attr = \mt\GunLevel::addRandAttr($gunLevelMeta,$type);
$randAttr = array();
foreach ($baseAttr as $val){
foreach ($attr as $v){
if ($val['attr_id'] == $v['attr_id'] && $v['attr_id'] == kHAT_Atk) {
//攻击力:上一级攻击力 *1+提升幅度*随机数)
$temp = $val['val'] * (1 + $gunLevelMeta['promote'] * $v['val']);
array_push($randAttr, array(
'attr_id' => $v['attr_id'],
'val' => $temp,
));
}else if ($val['attr_id'] == $v['attr_id'] && in_array($v['attr_id'] ,array(kHAT_ReloadTime,kHAT_FireRate))) {
//射速 装弹时间
//上级数值-表格数据
$temp = $val['val'] - $v['val'];
array_push($randAttr, array(
'attr_id' => $v['attr_id'],
'val' => $temp,
));
}else if($val['attr_id'] == $v['attr_id'] && in_array($v['attr_id'] ,array(kHAT_Volume,kHAT_BulletSpeed,kHAT_ShotRange,kHAT_Critical,kHAT_CriDamage))){
//子弹数 子弹飞行速度 射程 暴击率 暴击增伤
//上级数值+表格数据
$temp = $val['val'] + $v['val'];
array_push($randAttr, array(
'attr_id' => $v['attr_id'],
'val' => $temp,
));
}
}
}
foreach ($baseAttr as &$val){
foreach ($randAttr as $v){
if ($val['attr_id'] == $v['attr_id']){
$val['val'] = $v['val'];
}
}
return $result;
}
return $baseAttr;
}
}

View File

@ -220,6 +220,10 @@ class Hero extends BaseModel {
public static function toDto($row)
{
$attr = emptyReplace(json_decode($row['rand_attr'], true), array());
if (!$attr){
$heroMeta = mt\Hero::get($row['hero_id']);
$attr = mt\Hero::getHeroAttr($heroMeta);
}
// $lockType = 0;
// $unlockTime = 0;
@ -255,22 +259,6 @@ class Hero extends BaseModel {
}
$baseAttr=[];
$attrPro=[];
$heroMeta = mt\Hero::get($row['hero_id']);
if ($heroMeta) {
$baseAttr = mt\Hero::getHeroAttr($heroMeta);
$attrPro1=[];
if ($row['hero_lv']>1){
$attrPro1 = self::getAttrProByLevel($row,$baseAttr,$attr);
}
$attrPro2=[];
if ($row['quality']>1){
$attrPro2 = self::getAttrProByQuality($row,$baseAttr);
}
$attrPro = self::mergeAttrPro($baseAttr,$attrPro1,$attrPro2);
}
$heroLucky = \services\FormulaService::Hero_Advanced_Lucky_Value($row['quality']);
$userDb = myself()->_getOrmUserInfo();
$isSelect = 0;
@ -289,8 +277,7 @@ class Hero extends BaseModel {
'quality' => $row['quality'],
'skill_lv1' => $row['skill_lv1'],
'skill_lv2' => $row['skill_lv2'],
'attr_base' => $baseAttr,
'attr_pro' => $attrPro,
'rand_attr' => $attr,
'try_count' => $row['try_count'],
'lock_type' => $lockType,
'unlock_time' => $unlockTime,
@ -549,82 +536,6 @@ class Hero extends BaseModel {
return $locking;
}
private static function mergeAttrPro($baseAttr,$attrPro1,$attrPro2){
$newAttr = [];
$newAttrPro = [];
if ($attrPro1 && !$attrPro2){
$newAttrPro = $attrPro1;
}
if (!$attrPro1 && $attrPro2){
$newAttrPro = $attrPro2;
}
if ($attrPro1 && $attrPro2){
foreach ($attrPro1 as $value){
foreach ($attrPro2 as $val){
if ($value['attr_id'] == $val['attr_id']){
array_push($newAttr,
[
'attr_id' => $value['attr_id'],
'type' => $value['type'],
'val' => $value['val']+$val['val'],
]);
}
}
}
if ($newAttr){
foreach ($baseAttr as $value){
foreach ($newAttr as $val){
if ($value['attr_id'] == $val['attr_id']){
array_push($newAttrPro,
[
'attr_id' => $value['attr_id'],
'type' => $value['type'],
'val' => strval($val['val']-$value['val']),
]);
}
}
}
}
}
return $newAttrPro;
}
private static function getAttrProByLevel($row,$baseAttr,$attr){
$attrPro1 = [];
$coefficient_level = mt\HeroLevelAttr::getCoefficientByLevel($row['hero_lv'],$row['hero_id']);
foreach ($baseAttr as $val){
foreach ($attr as $v){
$coef_level = mt\HeroLevelAttr::getByCoefficient($coefficient_level,$val['attr_id']);
//&& $val['attr_id'] != kHAT_Atk
if ( $val['attr_id'] == $v['attr_id'] ){
array_push($attrPro1,[
'attr_id' => $val['attr_id'],
'type'=> $val['type'],
'val' => strval($val['val']*pow($v['val'],$coef_level['val'])),
]);
}
}
}
return $attrPro1;
}
private static function getAttrProByQuality($row,$baseAttr){
$attrPro2 = [];
$qualityMeta = mt\HeroQuality::getByQuality($row['quality']);
$coefficient_quality = mt\HeroQuality::getCoefficientByQuality($row['quality'],$row['hero_id']);
foreach ($baseAttr as $val){
$coef_quality = mt\HeroQuality::getByCoefficient($coefficient_quality,$val['attr_id']);
if ($coef_quality){
array_push($attrPro2, [
'attr_id' => $val['attr_id'],
'type' => $val['type'],
'val' => strval($val['val'] * pow($qualityMeta['promote_val'], $coef_quality['val'])),
]);
}
}
return $attrPro2;
}
public static function getFreeHero(){
$hero = array();
@ -637,7 +548,15 @@ class Hero extends BaseModel {
}
public static function toDtoInfo($row){
$heroMeta = mt\Hero::get($row['hero_id']);
$attr = emptyReplace(json_decode($row['rand_attr'], true), array());
if ($attr){
foreach ($attr as &$value){
$value['val'] = floor($value['val']);
}
}else{
$attr = mt\Hero::getHeroAttr($heroMeta);
}
$todayGetGold = $row['today_get_gold'];
$lastGetGoldTime = $row['last_get_gold_time'];
if (myself()->_getDaySeconds($lastGetGoldTime) <
@ -650,60 +569,18 @@ class Hero extends BaseModel {
myself()->_getNowDaySeconds()) {
$todayPveGetCeg = 0;
}
$baseAttr=[];
$attrPro=[];
$hero_name = 'XXX';
$heroMeta = mt\Hero::get($row['hero_id']);
if ($heroMeta) {
$hero_name = $heroMeta['name'];
$baseAttr = mt\Hero::getHeroAttr($heroMeta);
$attrPro1=[];
if ($row['hero_lv']>1){
$attrPro1 = self::getAttrProByLevel($row,$baseAttr,$attr);
}
$attrPro2=[];
if ($row['quality']>1){
$attrPro2 = self::getAttrProByQuality($row,$baseAttr);
}
$attrPro = self::mergeAttrPro($baseAttr,$attrPro1,$attrPro2);
}
$skill_common = explode("|",$row['skill_common']);
$attr_skill = [];
foreach ($skill_common as $val){
$item = mt\SkillCommon::getAttrBySkillCommon($val);
if ($item){
array_push($attr_skill,$item);
}
}
$rand_attr = $baseAttr;
if ($attrPro){
foreach ($rand_attr as $k=>$value){
foreach ($attrPro as $val){
if ($val['attr_id'] == $value['attr_id']){
$rand_attr[$k]['val'] = $val['val'];
}
}
}
}
if ($attr_skill){
$rand_attr = self::_mergeArr(array_merge($rand_attr,$attr_skill));
}
$heroLucky = \services\FormulaService::Hero_Advanced_Lucky_Value($row['quality']);
$info = array(
'idx' => $row['idx'],
'token_id' => $row['token_id'],
'hero_uniid' => $row['idx'],
'hero_name' => $hero_name,
'hero_name' => $heroMeta['name'],
'hero_id' => $row['hero_id'],
'hero_lv' => $row['hero_lv'],
'hero_tili' => $row['hero_tili'],
'quality' => $row['quality'],
'rand_attr' => array_values($rand_attr),
// 'attr_base' => $baseAttr,
// 'attr_pro' => $attrPro,
// 'attr_skill' => $attr_skill,
'rand_attr' => $attr,
'current_pvp_get_ceg' => $todayGetGold / 100,
'current_pve_get_ceg' => $todayPveGetCeg / 100,
'advanced_count' => $row['advanced_count'],
@ -719,24 +596,7 @@ class Hero extends BaseModel {
return $info;
}
private static function _mergeArr($data){
if ($data){
$result = array();
foreach ($data as $value){
$key = $value['attr_id'];
if(!isset($result[$key])){
$result[$key] = array(
'attr_id'=>$value['attr_id'],
'type'=>$value['type'],
'val'=>$value['val'],
);
}else{
$result[$key]['val'] += $value['val'];
}
}
return $result;
}
}
public static function getHeroByItemId($itemId){
$hero = array();
@ -748,4 +608,51 @@ class Hero extends BaseModel {
return $hero;
}
public static function LvUpAddAttr($heroDb,$type){
if ($heroDb['hero_lv'] == 1){
$heroMeta = mt\Hero::get($heroDb['hero_id']);
$baseAttr = mt\Hero::getHeroAttr($heroMeta);
}else{
$baseAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
}
$heroLevelMeta = \mt\HeroLevel::getByLevel($heroDb['hero_lv']+1);
$levelAttrMeta= \mt\HeroLevelAttr::find($heroDb['hero_id']);
$attr= \mt\HeroLevelAttr::addRandAttr($levelAttrMeta,$type);
$randAttr = array();
foreach ($baseAttr as $val){
foreach ($attr as $v){
if ($val['attr_id'] == $v['attr_id'] && $val['attr_id'] == kHAT_Def){
//随机权重值*((防御力基础值+200)*pow((提升幅度+1),防御力系数)-200)+(1-随机权重值)*防御力基础值
$temp = $v['val']*(($val['val']+200)*pow(($heroLevelMeta['promote']+1),$levelAttrMeta['def_rate'])-200)+(1-$v['val'])*$val['val'];
array_push($randAttr,array(
'attr_id' => $v['attr_id'],
'val' => sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1)),
// 'val' => $temp,
));
}else if($val['attr_id'] == $v['attr_id'] && $val['attr_id'] == kHAT_Hp){
//生命基础值 * ((pow((提升幅度+1),生命值系数)-1)*随机权重值+1)
$temp = $val['val'] * ((pow(($heroLevelMeta['promote']+1),$levelAttrMeta['hp_rate'])-1)*$v['val']+1);
array_push($randAttr,array(
'attr_id' => $v['attr_id'],
'val' => sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1)),
// 'val' => $temp,
));
}else if($val['attr_id'] == $v['attr_id'] && $val['attr_id'] == kHAT_Atk){
//攻击力基础值 * ((pow((提升幅度+1),攻击力系数)-1)*随机权重值+1)
$temp = $val['val'] * ((pow(($heroLevelMeta['promote']+1),$levelAttrMeta['atk_rate'])-1)*$v['val']+1);
array_push($randAttr,array(
'attr_id' => $v['attr_id'],
'val' => sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1)),
// 'val' => $temp,
));
}
}
if (!in_array($val['attr_id'],array(kHAT_Hp,kHAT_Atk,kHAT_Def))){
array_push($randAttr,$val);
}
}
return $randAttr;
}
}

View File

@ -11,140 +11,124 @@ use mt;
class GunLevel {
private static $BASE_ATTR = [kHAT_Volume,kHAT_ReloadTime,kHAT_FireRate,kHAT_Atk,kHAT_BulletSpeed,kHAT_ShotRange,kHAT_Critical,kHAT_CriDamage];
public static function get($id)
public static function find($id,$level)
{
return getXVal(self::getMetaList(), $id);
$meta = array();
foreach (self::getMetaList() as $value){
if ($value['gun_id'] == $id && $value['level'] == $level){
$meta = $value;
}
}
return $meta;
}
public static function getByLevel( $level)
{
self::mustBeLevelHash();
return getXVal(self::$levelHash, $level, null);
}
public static function getByCoefficient($data,$index)
{
self::mustBeCoefficientHash($data);
return getXVal(self::$coefficientHash, $index, null);
}
public static function getCoefficientByLevel($level,$gun_id){
$meta = self::getByLevel($level);
return [
[
'attr_id'=>kHAT_Volume,
'val' => self::_getCoefficient($meta,$gun_id,'clip_volume_rate')
], [
'attr_id'=>kHAT_ReloadTime,
'val' => self::_getCoefficient($meta,$gun_id,'reload_time_rate')
], [
'attr_id'=>kHAT_FireRate,
'val' => self::_getCoefficient($meta,$gun_id,'fire_rate_rate')
], [
'attr_id'=>kHAT_Atk,
'val' => self::_getCoefficient($meta,$gun_id,'atk_rate')
], [
'attr_id'=>kHAT_BulletSpeed,
'val' => self::_getCoefficient($meta,$gun_id,'bullet_speed_rate')
], [
'attr_id'=>kHAT_ShotRange,
'val' => self::_getCoefficient($meta,$gun_id,'range')
], [
'attr_id'=>kHAT_Critical,
'val' => self::_getCoefficient($meta,$gun_id,'crit_atk_rate')
], [
'attr_id'=>kHAT_CriDamage,
'val' => self::_getCoefficient($meta,$gun_id,'damage_rate')
],
];
}
private static function _getCoefficient($meta,$gun_id,$title){
if ($meta[$title.'2']){
$item = explode('|',$meta[$title.'2']);
foreach ($item as $val){
$item_1 = explode(':',$val);
if ($item_1[0] == $gun_id){
return $item_1[1];
public static function addRandAttr($meta,$type){
$attr = array();
if ($meta){
if ($type == 1) {
array_push($attr,array(
'attr_id' => kHAT_Atk,
'val' => self::getRandValue($meta,'attr_weight')
));
if ($meta['clip_volume']){
array_push($attr,array(
'attr_id' => kHAT_Volume,
'val' => self::getRandValue($meta,'clip_volume')
));
}
if ($meta['reload_time']){
array_push($attr,array(
'attr_id' => kHAT_ReloadTime,
'val' => self::getRandValue($meta,'reload_time')
));
}
if ($meta['fire_rate']){
array_push($attr,array(
'attr_id' => kHAT_FireRate,
'val' => self::getRandValue($meta,'fire_rate')
));
}
if ($meta['bullet_speed']){
array_push($attr,array(
'attr_id' => kHAT_BulletSpeed,
'val' => self::getRandValue($meta,'bullet_speed')
));
}
if ($meta['range']){
array_push($attr,array(
'attr_id' => kHAT_ShotRange,
'val' => self::getRandValue($meta,'range')
));
}
if ($meta['crit_atk']){
array_push($attr,array(
'attr_id' => kHAT_Critical,
'val' => self::getRandValue($meta,'crit_atk')
));
}
if ($meta['damage']){
array_push($attr,array(
'attr_id' => kHAT_CriDamage,
'val' => self::getRandValue($meta,'damage')
));
}
}else{
array_push($attr,array(
'attr_id' => kHAT_Atk,
'val' => self::getRandValueMin($meta,'attr_weight')
));
if ($meta['clip_volume']){
array_push($attr,array(
'attr_id' => kHAT_Volume,
'val' => self::getRandValueMin($meta,'clip_volume')
));
}
if ($meta['reload_time']){
array_push($attr,array(
'attr_id' => kHAT_ReloadTime,
'val' => self::getRandValueMin($meta,'reload_time')
));
}
if ($meta['fire_rate']){
array_push($attr,array(
'attr_id' => kHAT_FireRate,
'val' => self::getRandValueMin($meta,'fire_rate')
));
}
if ($meta['bullet_speed']){
array_push($attr,array(
'attr_id' => kHAT_BulletSpeed,
'val' => self::getRandValueMin($meta,'bullet_speed')
));
}
if ($meta['range']){
array_push($attr,array(
'attr_id' => kHAT_ShotRange,
'val' => self::getRandValueMin($meta,'range')
));
}
if ($meta['crit_atk']){
array_push($attr,array(
'attr_id' => kHAT_Critical,
'val' => self::getRandValueMin($meta,'crit_atk')
));
}
if ($meta['damage']){
array_push($attr,array(
'attr_id' => kHAT_CriDamage,
'val' => self::getRandValueMin($meta,'damage')
));
}
}
return $meta[$title];
}
return $meta[$title];
return $attr;
}
public static function addRandAttrNew($gunDb,$type){
$itemMeta = Item::get($gunDb['gun_id']);
$gunMeta = Equip::get($itemMeta['relationship']);
$newAttrs = array();
if ($gunMeta) {
$meta = self::getByLevel($gunDb['gun_lv']+1);
foreach (self::$BASE_ATTR as $item){
if ($type == 1){
$val = self::getAttrValue($meta);
}else{
$val = self::getAttrValueMin($meta);
}
array_push(
$newAttrs,
[
'attr_id' => $item,
'val' => $val,
]);
}
}
$rand_attr = emptyReplace(json_decode($gunDb['rand_attr'], true), array());
if (!$rand_attr){
foreach ($newAttrs as $item){
array_push(
$rand_attr,
[
'attr_id' => $item['attr_id'],
'val' => 1+$item['val'],
]);
}
}else{
foreach ($rand_attr as &$item){
foreach ($newAttrs as $v){
if ($item['attr_id'] == $v['attr_id']){
$item['val'] = $item['val']*(1+$v['val']);
}
}
}
}
return $rand_attr;
}
public static function addRandAttr($levelMeta, $baseAttrs, &$dbAttrs)
protected static function getRandValue($meta,$key)
{
$nums = explode(':', $levelMeta['rand_attrs_num']);
$num = rand($nums[0], $nums[1]);
$cfgAttrs = StrHelper::parseList($levelMeta['rand_attrs'], array('|', ':'));
AttrHelper::addRandAttrs($cfgAttrs, $num, $baseAttrs, $dbAttrs);
return true;
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('gunLevel@gunLevel.php');
}
return self::$metaList;
}
protected static function mustBeLevelHash()
{
if (!self::$levelHash) {
self::$levelHash = array();
foreach (self::getMetaList() as $meta) {
self::$levelHash[$meta['level']] = $meta;
}
}
}
protected static function getAttrValue($meta)
{
$strs = explode('|', $meta['attr_weight']);
$strs = explode('|', $meta[$key]);
$totalSpace = 0;
foreach ($strs as $tmpStr) {
@ -171,27 +155,27 @@ class GunLevel {
return 0;
}
protected static function getAttrValueMin($meta)
protected static function getRandValueMin($meta,$key)
{
$strs = explode('|', $meta['attr_weight']);
$strs = explode('|', $meta[$key]);
foreach ($strs as $tmpStr) {
$strs2 = explode(':', $tmpStr);
return $strs2[0];
}
}
protected static function mustBeCoefficientHash($list)
public static function get($id)
{
if (!self::$coefficientHash) {
self::$coefficientHash = array();
foreach ($list as $val) {
self::$coefficientHash[$val['attr_id']] = $val;
}
return getXVal(self::getMetaList(), $id);
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('gunLevel@gunLevel.php');
}
return self::$metaList;
}
protected static $metaList;
protected static $levelHash;
protected static $coefficientHash;
}

View File

@ -9,141 +9,49 @@ require_once('mt/Hero.php');
use phpcommon;
class HeroLevelAttr {
private static $BASE_ATTR = [kHAT_Hp,kHAT_Atk,kHAT_Def,kHAT_Critical,kHAT_CriDamage,kHAT_Dodge,kHAT_Ruduce];
public static function get($id)
public static function find($id)
{
return getXVal(self::getMetaList(), $id);
}
public static function getByLevel($level)
{
self::mustBeLevelHash();
return getXVal(self::$levelHash, $level, null);
}
public static function getByCoefficient($data,$index)
{
foreach ($data as $val){
if ($val['attr_id'] == $index){
return $val;
}
}
}
public static function getCoefficientByLevel($level,$hero_id){
$meta = self::getByLevel($level);
return [
[
'attr_id'=>kHAT_Hp,
'val' => self::_getCoefficient($meta,$hero_id,'hp_rate')
], [
'attr_id'=>kHAT_Atk,
'val' => self::_getCoefficient($meta,$hero_id,'atk_rate')
], [
'attr_id'=>kHAT_Def,
'val' => self::_getCoefficient($meta,$hero_id,'def_rate')
], [
'attr_id'=>kHAT_Critical,
'val' => self::_getCoefficient($meta,$hero_id,'crit_atk_rate')
], [
'attr_id'=>kHAT_CriDamage,
'val' => self::_getCoefficient($meta,$hero_id,'damage_rate')
], [
'attr_id'=>kHAT_Dodge,
'val' => self::_getCoefficient($meta,$hero_id,'miss_rate')
], [
'attr_id'=>kHAT_Ruduce,
'val' => self::_getCoefficient($meta,$hero_id,'ruduce_rate')
],
];
}
private static function _getCoefficient($meta,$hero_id,$title){
if ($meta[$title.'2']){
$item = explode('|',$meta[$title.'2']);
foreach ($item as $val){
$item_1 = explode(':',$val);
if ($item_1[0] == $hero_id){
return $item_1[1];
}
}
return $meta[$title];
}
return $meta[$title];
}
public static function addRandAttrNew($heroDb,$type){
$heroMeta = Hero::get($heroDb['hero_id']);
$newAttrs = array();
if ($heroMeta) {
$meta = self::getByLevel($heroDb['hero_lv']+1);
foreach (self::$BASE_ATTR as $item){
if ($type == 1){
$val = self::getAttrValue($meta);
}else{
$val = self::getAttrValueMin($meta);
}
array_push(
$newAttrs,
[
'attr_id' => $item,
'val' => $val,
]);
}
}
$rand_attr = $attr = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
if (!$rand_attr){
foreach ($newAttrs as $item){
array_push(
$rand_attr,
[
'attr_id' => $item['attr_id'],
'val' => 1+$item['val'],
]);
}
public static function addRandAttr($meta,$type){
if ($type == 1){
$attr = array(
array(
'attr_id' => kHAT_Hp,
'val' => self::getAttrValue($meta)
),
array(
'attr_id' => kHAT_Atk,
'val' => self::getAttrValue($meta)
),
array(
'attr_id' => kHAT_Def,
'val' => self::getAttrValue($meta)
),
);
}else{
foreach ($rand_attr as &$item){
foreach ($newAttrs as $v){
if ($item['attr_id'] == $v['attr_id']){
$item['val'] = $item['val']*(1+$v['val']);
}
}
}
$attr = array(
array(
'attr_id' => kHAT_Hp,
'val' => self::getAttrValueMin($meta)
),
array(
'attr_id' => kHAT_Atk,
'val' => self::getAttrValueMin($meta)
),
array(
'attr_id' => kHAT_Def,
'val' => self::getAttrValueMin($meta)
),
);
}
return $rand_attr;
return $attr;
}
public static function addRandAttr($level, &$dbAttrs)
{
$newAttrs = array();
foreach (self::getMetaList() as $meta) {
if ($meta['level'] == $level) {
if (in_array(
$meta['type'],
array(
kHAT_ABS_VAL,
kHAT_RATE_VAL
)
)) {
$val = self::getAttrValue($meta);
if ($val > 0) {
array_push(
$newAttrs,
array(
'attr_id' => $meta['attr_id'],
'type' => $meta['type'],
'val' => $val,
));
}
}
}
}
AttrHelper::mergeAttr($dbAttrs, $newAttrs);
return true;
}
protected static function getAttrValue($meta)
{
@ -191,29 +99,6 @@ class HeroLevelAttr {
return self::$metaList;
}
protected static function mustBeLevelHash()
{
if (!self::$levelHash) {
self::$levelHash = array();
foreach (self::getMetaList() as $meta) {
self::$levelHash[$meta['level']] = $meta;
}
}
}
protected static function mustBeCoefficientHash($list)
{
if (!self::$coefficientHash) {
self::$coefficientHash = array();
foreach ($list as $val) {
self::$coefficientHash[$val['attr_id']] = $val;
}
}
}
protected static $metaList;
protected static $levelHash;
protected static $coefficientHash;
}