feat(WIP): 베팅 개시 타입 변경
-candidate를 미리 추가. -이를 통해 betting을 중립적으로 운용 가능
This commit is contained in:
@@ -5,7 +5,7 @@ namespace sammo\Event\Action;
|
||||
use \sammo\GameConst;
|
||||
use \sammo\Util;
|
||||
use \sammo\DB;
|
||||
use sammo\DTO\NationBettingInfo;
|
||||
use sammo\DTO\BettingInfo;
|
||||
use sammo\Json;
|
||||
use sammo\KVStorage;
|
||||
|
||||
@@ -20,14 +20,17 @@ class FinishNationBetting extends \sammo\Event\Action
|
||||
$db = DB::db();
|
||||
[$year, $month] = [$env['year'], $env['month']];
|
||||
|
||||
$nationBettingStor = KVStorage::getStorage($db, 'nation_betting');
|
||||
$bettingInfoRaw = $nationBettingStor->getValue("id_{$this->bettingID}");
|
||||
$bettingStor = KVStorage::getStorage($db, 'betting');
|
||||
$bettingInfoRaw = $bettingStor->getValue("id_{$this->bettingID}");
|
||||
if($bettingInfoRaw === null){
|
||||
return [__CLASS__, true];
|
||||
}
|
||||
$bettingInfo = new NationBettingInfo($bettingInfoRaw);
|
||||
$bettingInfo = new BettingInfo($bettingInfoRaw);
|
||||
if($bettingInfo->type != 'nationBetting'){
|
||||
return [__CLASS__, false, 'invalid type', $bettingInfo->type];
|
||||
}
|
||||
$bettingInfo->finished = true;
|
||||
$nationBettingStor->setValue("id_{$this->bettingID}", $bettingInfo->toArray());
|
||||
$bettingStor->setValue("id_{$this->bettingID}", $bettingInfo->toArray());
|
||||
|
||||
//TODO: 포인트를 배분해주어야 함
|
||||
//TODO: 이후 토너먼트 베팅 결과도 같이 처리할 것이므로, 별도의 함수나 모듈을 생성하여 처리!
|
||||
|
||||
@@ -5,10 +5,13 @@ namespace sammo\Event\Action;
|
||||
use \sammo\GameConst;
|
||||
use \sammo\Util;
|
||||
use \sammo\DB;
|
||||
use sammo\DTO\NationBettingInfo;
|
||||
use sammo\DTO\BettingInfo;
|
||||
use Sammo\DTO\SelectItem;
|
||||
use sammo\Json;
|
||||
use sammo\KVStorage;
|
||||
|
||||
use function sammo\getAllNationStaticInfo;
|
||||
|
||||
class OpenNationBetting extends \sammo\Event\Action
|
||||
{
|
||||
public function __construct(private int $nationCnt = 1, private int $bonusPoint = 0)
|
||||
@@ -16,7 +19,7 @@ class OpenNationBetting extends \sammo\Event\Action
|
||||
if ($nationCnt < 1) {
|
||||
throw new \RuntimeException("1 미만의 숫자");
|
||||
}
|
||||
if ($bonusPoint < 0){
|
||||
if ($bonusPoint < 0) {
|
||||
throw new \RuntimeException("0 미만의 보너스 포인트");
|
||||
}
|
||||
}
|
||||
@@ -30,7 +33,7 @@ class OpenNationBetting extends \sammo\Event\Action
|
||||
$bettingID = ($gameStor->getValue('last_betting_id') ?? 0) + 1;
|
||||
$gameStor->setValue('last_betting_id', $bettingID);
|
||||
|
||||
$nationBettingStor = KVStorage::getStorage($db, 'nation_betting');
|
||||
$bettingStor = KVStorage::getStorage($db, 'betting');
|
||||
[$year, $month] = [$env['year'], $env['month']];
|
||||
|
||||
if ($this->nationCnt == 1) {
|
||||
@@ -43,16 +46,45 @@ class OpenNationBetting extends \sammo\Event\Action
|
||||
$openYearMonth = Util::joinYearMonth($year, $month);
|
||||
$closeYearMonth = $openYearMonth + 24;
|
||||
|
||||
$bettingInfo = new NationBettingInfo(
|
||||
$citiesCnt = [];
|
||||
foreach ($db->queryAllLists('SELECT nation, COUNT(*) AS cnt FROM city WHERE nation > 0 GROUP BY nation') as [$nationID, $cnt]) {
|
||||
$citiesCnt[$nationID] = $cnt;
|
||||
}
|
||||
|
||||
/** @var \sammo\DTO\SelectItem[] */
|
||||
$candidates = [];
|
||||
|
||||
foreach (getAllNationStaticInfo() as $nationRaw) {
|
||||
$nationID = $nationRaw['nation'];
|
||||
$cityCnt = $citiesCnt[$nationID] ?? 0;
|
||||
$nationRaw['city_cnt'] = $cityCnt;
|
||||
$info = [
|
||||
"국력: {$nationRaw['power']}",
|
||||
"장수 수: {$nationRaw['gennum']}",
|
||||
"도시 수: {$cityCnt}",
|
||||
];
|
||||
|
||||
//NOTE: 도시 정보도 추가?
|
||||
$candidates[] = new SelectItem(
|
||||
title: $nationRaw['name'],
|
||||
info: join("<br>", $info),
|
||||
isHtml: true,
|
||||
aux: $nationRaw,
|
||||
);
|
||||
}
|
||||
|
||||
$bettingInfo = new BettingInfo(
|
||||
id: $bettingID,
|
||||
type: 'bettingNation',
|
||||
name: "[{$year}년 {$month}월] {$name} 예상 베팅",
|
||||
finished: false,
|
||||
selectCnt: $this->nationCnt,
|
||||
reqInheritancePoint: true,
|
||||
openYearMonth: $openYearMonth,
|
||||
closeYearMonth: $closeYearMonth,
|
||||
candidates: $candidates,
|
||||
);
|
||||
$nationBettingStor->setValue("id_{$bettingID}", $bettingInfo->toArray());
|
||||
$bettingStor->setValue("id_{$bettingID}", $bettingInfo->toArray());
|
||||
|
||||
$db->insert('event', [
|
||||
'target' => 'DESTROY_NATION',
|
||||
@@ -66,17 +98,22 @@ class OpenNationBetting extends \sammo\Event\Action
|
||||
]),
|
||||
]);
|
||||
|
||||
if($this->bonusPoint > 0){
|
||||
if ($this->bonusPoint > 0) {
|
||||
$db->insert('ng_betting', [
|
||||
'betting_id' => $bettingID,
|
||||
'general_id' => 0,
|
||||
'betting_type' => '0',
|
||||
'betting_type' => '[-1]',
|
||||
'amount' => $this->bonusPoint
|
||||
]);
|
||||
}
|
||||
|
||||
$logger = new \sammo\ActionLogger(0, 0, $year, $month);
|
||||
$logger->pushGlobalHistoryLog("<B><b>【내기】</b></>천하통일을 염원하는 <C>내기</>가 진행중입니다! 호사가의 참여를 기다립니다!");
|
||||
if ($this->nationCnt > 1) {
|
||||
$logger->pushGlobalHistoryLog("<B><b>【내기】</b></>중원의 강자를 점치는 <C>내기</>가 진행중입니다! 호사가의 참여를 기다립니다!");
|
||||
} else {
|
||||
$logger->pushGlobalHistoryLog("<B><b>【내기】</b></>천하통일 후보를 점치는 <C>내기</>가 진행중입니다! 호사가의 참여를 기다립니다!");
|
||||
}
|
||||
|
||||
$logger->flush();
|
||||
|
||||
return [__CLASS__, true];
|
||||
|
||||
Reference in New Issue
Block a user