forked from devsam/core
refac: Betting 시작 코드를 모듈로 이동
This commit is contained in:
@@ -10,6 +10,27 @@ class Betting
|
||||
|
||||
private BettingInfo $info;
|
||||
|
||||
public CONST LAST_BETTING_ID_KEY = 'last_betting_id';
|
||||
|
||||
static public function genNextBettingID(): int{
|
||||
$db = DB::db();
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$gameStor->invalidateCacheValue(self::LAST_BETTING_ID_KEY);
|
||||
$bettingID = ($gameStor->getValue(self::LAST_BETTING_ID_KEY) ?? 0) + 1;
|
||||
|
||||
$gameStor->setValue(self::LAST_BETTING_ID_KEY, $bettingID);
|
||||
|
||||
return $bettingID;
|
||||
}
|
||||
|
||||
static public function openBetting(BettingInfo $info){
|
||||
$db = DB::db();
|
||||
$bettingID = $info->id;
|
||||
$bettingStor = KVStorage::getStorage($db, 'betting');
|
||||
$bettingStor->setValue("id_{$bettingID}", $info->toArray());
|
||||
}
|
||||
|
||||
public function __construct(private $bettingID)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use sammo\Betting;
|
||||
use \sammo\GameConst;
|
||||
use \sammo\Util;
|
||||
use \sammo\DB;
|
||||
@@ -28,12 +29,6 @@ class OpenNationBetting extends \sammo\Event\Action
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$gameStor->invalidateCacheValue('last_betting_id');
|
||||
$bettingID = ($gameStor->getValue('last_betting_id') ?? 0) + 1;
|
||||
$gameStor->setValue('last_betting_id', $bettingID);
|
||||
|
||||
$bettingStor = KVStorage::getStorage($db, 'betting');
|
||||
[$year, $month] = [$env['year'], $env['month']];
|
||||
|
||||
if ($this->nationCnt == 1) {
|
||||
@@ -77,8 +72,9 @@ class OpenNationBetting extends \sammo\Event\Action
|
||||
aux: $nationRaw,
|
||||
);
|
||||
}
|
||||
|
||||
$bettingInfo = new BettingInfo(
|
||||
|
||||
$bettingID = \sammo\Betting::genNextBettingID();
|
||||
Betting::openBetting(new BettingInfo(
|
||||
id: $bettingID,
|
||||
type: 'bettingNation',
|
||||
name: "{$name} 예상",
|
||||
@@ -88,8 +84,7 @@ class OpenNationBetting extends \sammo\Event\Action
|
||||
openYearMonth: $openYearMonth,
|
||||
closeYearMonth: $closeYearMonth,
|
||||
candidates: $candidates,
|
||||
);
|
||||
$bettingStor->setValue("id_{$bettingID}", $bettingInfo->toArray());
|
||||
));
|
||||
|
||||
$db->insert('event', [
|
||||
'target' => 'DESTROY_NATION',
|
||||
|
||||
Reference in New Issue
Block a user