This commit is contained in:
aozhiwei 2022-09-19 18:55:00 +08:00
parent 9bbce80633
commit 74da8ff34d
2 changed files with 41 additions and 2 deletions

View File

@ -10,17 +10,30 @@ class FragmentPool extends BaseModel {
public static function dropHero()
{
$items = self::internalGet(0);
if (count($items)) {
$idx = array_rand($items, 1);
$fragmentId = $items[$idx]['fragment_id'];
self::decNum($fragmentId);
return $fragmentId;
}
return 0;
}
public static function dropGun()
{
$items = self::internalGet(1);
if (count($items)) {
$idx = array_rand($items, 1);
$fragmentId = $items[$idx]['fragment_id'];
self::decNum($fragmentId);
return $fragmentId;
}
return 0;
}
private static function internalGet($type)
{
$allocTime = myself()->_getNowDaySeconds() +
intval((myself()->_getNowTime() - myself()->_getNowDaySeconds()) / 3600) * 3600;
$allocTime = self::getAllocTime();
$rows = SqlHelper::ormSelect
(myself()->_getMysql($targetId),
't_fragment_pool',
@ -40,4 +53,29 @@ class FragmentPool extends BaseModel {
return $items;
}
private static function decNum($itemId)
{
$allocTime = self::getAllocTime();
SqlHelper::update
(myself()->_getMysql($targetId),
't_fragment_pool',
array(
'fragment_id' => $itemId,
'alloc_time' => $allocTime,
),
array(
'fragment_num' => function () {
return 'GREATEST(0, fragment_num - 1)';
},
)
);
}
private static function getAllocTime()
{
$allocTime = myself()->_getNowDaySeconds() +
intval((myself()->_getNowTime() - myself()->_getNowDaySeconds()) / 3600) * 3600;
return $allocTime;
}
}

View File

@ -34,6 +34,7 @@ use models\Bag;
use models\Hero;
use models\Gun;
use models\RealtimeData;
use models\FragmentPool;
use services\FormulaService;
class BattleDataService extends BaseService {