1
This commit is contained in:
parent
9bbce80633
commit
74da8ff34d
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user