This commit is contained in:
aozhiwei 2022-05-08 22:53:55 +08:00
parent 421acd9abe
commit 57ccf77ce5
3 changed files with 61 additions and 17 deletions

View File

@ -258,4 +258,25 @@ class Gun extends BaseModel {
));
}
public static function gainGold($gunDto, $addGold)
{
$finalyAddGold = 0;
$goldLimit = 0;
$gunQualityMeta = mt\GunQuality::getByQuality($gunDto['quality']);
if ($gunQualityMeta) {
$attr = mt\AttrHelper::getAbsVal($gunDto['attr'], kHAT_LUCKY);
if ($attr) {
$goldLimit += $attr['val'];
}
$newGold = min($goldLimit, $gunDto['today_get_gold'] + $addGold);
$finalyAddGold = max(0, $newGold - $gunDto['today_get_gold']);
self::update($gunDto['gun_uniid'],
array(
'today_get_gold' => $newGold,
'last_get_gold_time' => myself()->_getNowTime()
));
}
return $finalyAddGold;
}
}

View File

@ -306,4 +306,25 @@ class Hero extends BaseModel {
));
}
public static function gainGold($heroDto, $addGold)
{
$finalyAddGold = 0;
$goldLimit = 0;
$heroQualityMeta = mt\HeroQuality::getByQuality($heroDto['quality']);
if ($heroQualityMeta) {
$attr = mt\AttrHelper::getAbsVal($heroDto['attr'], kHAT_LUCKY);
if ($attr) {
$goldLimit += $attr['val'];
}
$newGold = min($goldLimit, $heroDto['today_get_gold'] + $addGold);
$finalyAddGold = max(0, $newGold - $heroDto['today_get_gold']);
self::update($heroDto['hero_uniid'],
array(
'today_get_gold' => $newGold,
'last_get_gold_time' => myself()->_getNowTime()
));
}
return $finalyAddGold;
}
}

View File

@ -16,6 +16,7 @@ require_once('models/Season.php');
require_once('models/Battle.php');
require_once('models/Bag.php');
require_once('models/Hero.php');
require_once('models/Gun.php');
use mt;
use phpcommon\SqlHelper;
@ -23,6 +24,7 @@ use models\Season;
use models\Battle;
use models\Bag;
use models\Hero;
use models\Gun;
class BattleDataService extends BaseService {
@ -30,10 +32,11 @@ class BattleDataService extends BaseService {
public function updateBattleData()
{
$heroDb = Hero::find(getReqVal('hero_uniid', 0));
if (!$heroDb) {
$row = Hero::find(getReqVal('hero_uniid', 0));
if (!$row) {
return false;
}
$heroDb = Hero::toDto($row);
error_log(json_encode($_REQUEST));
error_log('updateBattleData1');
if (!$this->decCost($heroDb)) {
@ -354,26 +357,25 @@ class BattleDataService extends BaseService {
if ($gold > 0) {
$addGold = floor($gold / 3);
}
$finalyAddGold = 0;
if ($addGold) {
$heroQualityMeta = mt\HeroQuality::getByQuality($heroDb['quality']);
if ($heroQualityMeta) {
$goldLimit = $heroMeta['gold_limit'];
$randAttr = emptyReplace(json_decode($row['rand_attr'], true),
array());
if ($randAttr) {
$attr = mt\AttrHelper::getAbsVal($randAttr, kHAT_LUCKY);
if ($attr) {
$goldLimit += $attr['val'];
$finalyAddGold += Hero::gainGold($heroDb, $addGold);
{
for ($i = 1; $i <= 2; ++$i) {
$weaponUniid = getReqVal('weapon_uuid' . $i, 0);
if ($weaponUniid) {
$row = Gun::find($weaponUniid);
$gunDto = $gunDb ? Gun::toDto($row) : null;
if ($gunDto){
$finalyAddGold += Gun::gainGold($gunDto, $addGold);
}
}
}
$newGold = min($goldLimit, $heroDb['today_get_gold'] + $addGold);
Hero::update($heroDb['hero_uniid'],
array(
'today_get_gold' => $newGold,
'last_get_gold_time' => myself()->_getNowTime()
));
}
}
if ($finalyAddGold > 0) {
myself()->_addVirtualItem(V_ITEM_GOLD, $finalyAddGold);
}
}
}