feat(WIP): 베팅 개시 타입 변경
-candidate를 미리 추가. -이를 통해 betting을 중립적으로 운용 가능
This commit is contained in:
@@ -8,7 +8,7 @@ use sammo\DB;
|
|||||||
use Sammo\DTO\BettingItem;
|
use Sammo\DTO\BettingItem;
|
||||||
use sammo\Validator;
|
use sammo\Validator;
|
||||||
use sammo\Json;
|
use sammo\Json;
|
||||||
use sammo\DTO\NationBettingInfo;
|
use sammo\DTO\BettingInfo;
|
||||||
use sammo\GameConst;
|
use sammo\GameConst;
|
||||||
use sammo\General;
|
use sammo\General;
|
||||||
use sammo\KVStorage;
|
use sammo\KVStorage;
|
||||||
@@ -54,14 +54,14 @@ class BetNation extends \sammo\BaseAPI
|
|||||||
$amount = $this->args['amount'];
|
$amount = $this->args['amount'];
|
||||||
|
|
||||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||||
$nationBettingStor = KVStorage::getStorage($db, 'nation_betting');
|
$bettingStor = KVStorage::getStorage($db, 'betting');
|
||||||
$rawBettingInfo = $nationBettingStor->getValue("id_{$bettingID}");
|
$rawBettingInfo = $bettingStor->getValue("id_{$bettingID}");
|
||||||
if($rawBettingInfo === null){
|
if($rawBettingInfo === null){
|
||||||
return '해당 베팅이 없습니다';
|
return '해당 베팅이 없습니다';
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$bettingInfo = new NationBettingInfo($rawBettingInfo);
|
$bettingInfo = new BettingInfo($rawBettingInfo);
|
||||||
}
|
}
|
||||||
catch(\Error $e){
|
catch(\Error $e){
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
@@ -88,16 +88,20 @@ class BetNation extends \sammo\BaseAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sort($bettingType);//NOTE: key로 바로 사용하므로 중요함
|
$bettingType = array_unique($bettingType, SORT_NUMERIC);//NOTE: key로 바로 사용하므로 중요함
|
||||||
$bettingTypeKey = Json::encode($bettingType);
|
if(count($bettingType) != $bettingInfo->selectCnt){
|
||||||
$nations = getAllNationStaticInfo();
|
return '중복된 값이 있습니다.';
|
||||||
|
|
||||||
foreach($bettingType as $bettingNationID){
|
|
||||||
if(!key_exists($bettingNationID, $nations)){
|
|
||||||
return '존재하지 않는 국가를 선택했습니다.';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($bettingType[0] < 0){
|
||||||
|
return '올바르지 않은 값이 있습니다.(0 미만)';
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Util::array_last($bettingType) >= count($bettingInfo->candidates)){
|
||||||
|
return '올바르지 않은 값이 있습니다.(초과)';
|
||||||
|
}
|
||||||
|
|
||||||
|
$bettingTypeKey = Json::encode($bettingType);
|
||||||
$general = General::createGeneralObjFromDB($session->generalID, ['gold', 'aux'], 1);
|
$general = General::createGeneralObjFromDB($session->generalID, ['gold', 'aux'], 1);
|
||||||
|
|
||||||
if($bettingInfo->reqInheritancePoint){
|
if($bettingInfo->reqInheritancePoint){
|
||||||
+4
-4
@@ -5,7 +5,7 @@ namespace sammo\API\NationBetting;
|
|||||||
use sammo\Session;
|
use sammo\Session;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use sammo\DB;
|
use sammo\DB;
|
||||||
use sammo\DTO\NationBettingInfo;
|
use sammo\DTO\BettingInfo;
|
||||||
use sammo\General;
|
use sammo\General;
|
||||||
use sammo\KVStorage;
|
use sammo\KVStorage;
|
||||||
use sammo\Validator;
|
use sammo\Validator;
|
||||||
@@ -42,14 +42,14 @@ class GetBettingDetail extends \sammo\BaseAPI
|
|||||||
$bettingID = $this->arg['betting_id'];
|
$bettingID = $this->arg['betting_id'];
|
||||||
|
|
||||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||||
$nationBettingStor = KVStorage::getStorage($db, 'nation_betting');
|
$bettingStor = KVStorage::getStorage($db, 'betting');
|
||||||
$rawBettingInfo = $nationBettingStor->getValue("id_{$bettingID}");
|
$rawBettingInfo = $bettingStor->getValue("id_{$bettingID}");
|
||||||
if($rawBettingInfo === null){
|
if($rawBettingInfo === null){
|
||||||
return '해당 베팅이 없습니다';
|
return '해당 베팅이 없습니다';
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
$bettingInfo = new NationBettingInfo($rawBettingInfo);
|
$bettingInfo = new BettingInfo($rawBettingInfo);
|
||||||
}
|
}
|
||||||
catch(\Error $e){
|
catch(\Error $e){
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
+5
-5
@@ -5,7 +5,7 @@ namespace sammo\API\NationBetting;
|
|||||||
use sammo\Session;
|
use sammo\Session;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use sammo\DB;
|
use sammo\DB;
|
||||||
use sammo\DTO\NationBettingInfo;
|
use sammo\DTO\BettingInfo;
|
||||||
use sammo\KVStorage;
|
use sammo\KVStorage;
|
||||||
|
|
||||||
use function sammo\checkLimit;
|
use function sammo\checkLimit;
|
||||||
@@ -27,10 +27,10 @@ class GetBettingList extends \sammo\BaseAPI
|
|||||||
{
|
{
|
||||||
$db = DB::db();
|
$db = DB::db();
|
||||||
|
|
||||||
increaseRefresh("국가베팅장", 1);
|
increaseRefresh("베팅장", 1);
|
||||||
|
|
||||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||||
$nationBettingStor = KVStorage::getStorage($db, 'nation_betting');
|
$bettingStor = KVStorage::getStorage($db, 'betting');
|
||||||
$userID = $session->userID;
|
$userID = $session->userID;
|
||||||
|
|
||||||
$me = $db->queryFirstRow('SELECT no,nation,officer_level,con,turntime,belong,penalty,permission FROM general WHERE owner=%i', $userID);
|
$me = $db->queryFirstRow('SELECT no,nation,officer_level,con,turntime,belong,penalty,permission FROM general WHERE owner=%i', $userID);
|
||||||
@@ -40,8 +40,8 @@ class GetBettingList extends \sammo\BaseAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
$bettingList = [];
|
$bettingList = [];
|
||||||
foreach ($nationBettingStor->getAll() as $_key => $rawItem) {
|
foreach ($bettingStor->getAll() as $_key => $rawItem) {
|
||||||
$item = new NationBettingInfo($rawItem);
|
$item = new BettingInfo($rawItem);
|
||||||
$bettingList[$item->id] = $rawItem;
|
$bettingList[$item->id] = $rawItem;
|
||||||
$bettingList[$item->id]['totalAmount'] = 0;
|
$bettingList[$item->id]['totalAmount'] = 0;
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace sammo\DTO;
|
namespace sammo\DTO;
|
||||||
|
|
||||||
|
use Sammo\DTO\SelectItem;
|
||||||
|
use Spatie\DataTransferObject\Attributes\CastWith;
|
||||||
use Spatie\DataTransferObject\Attributes\Strict;
|
use Spatie\DataTransferObject\Attributes\Strict;
|
||||||
use Spatie\DataTransferObject\DataTransferObject;
|
use Spatie\DataTransferObject\DataTransferObject;
|
||||||
|
|
||||||
@@ -10,15 +12,20 @@ use Spatie\DataTransferObject\DataTransferObject;
|
|||||||
|
|
||||||
|
|
||||||
#[Strict]
|
#[Strict]
|
||||||
class NationBettingInfo extends DataTransferObject
|
class BettingInfo extends DataTransferObject
|
||||||
{
|
{
|
||||||
public int $id;
|
public int $id;
|
||||||
|
public string $type;
|
||||||
public string $name;
|
public string $name;
|
||||||
public bool $finished;
|
public bool $finished;
|
||||||
public int $selectCnt;
|
public int $selectCnt;
|
||||||
public bool $reqInheritancePoint;
|
public bool $reqInheritancePoint;
|
||||||
public int $openYearMonth;
|
public int $openYearMonth;
|
||||||
public int $closeYearMonth;
|
public int $closeYearMonth;
|
||||||
|
|
||||||
|
/** @var \sammo\DTO\SelectItem[] */
|
||||||
|
#[CastWith(ArrayCaster::class, itemType: SelectItem::class)]
|
||||||
|
public array $candidates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Sammo\DTO;
|
||||||
|
|
||||||
|
use Spatie\DataTransferObject\Attributes\Strict;
|
||||||
|
use Spatie\DataTransferObject\DataTransferObject;
|
||||||
|
|
||||||
|
#[Strict]
|
||||||
|
class SelectItem extends DataTransferObject
|
||||||
|
{
|
||||||
|
public string $title;
|
||||||
|
public ?string $info;
|
||||||
|
public ?bool $isHtml;
|
||||||
|
public ?array $aux;
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ namespace sammo\Event\Action;
|
|||||||
use \sammo\GameConst;
|
use \sammo\GameConst;
|
||||||
use \sammo\Util;
|
use \sammo\Util;
|
||||||
use \sammo\DB;
|
use \sammo\DB;
|
||||||
use sammo\DTO\NationBettingInfo;
|
use sammo\DTO\BettingInfo;
|
||||||
use sammo\Json;
|
use sammo\Json;
|
||||||
use sammo\KVStorage;
|
use sammo\KVStorage;
|
||||||
|
|
||||||
@@ -20,14 +20,17 @@ class FinishNationBetting extends \sammo\Event\Action
|
|||||||
$db = DB::db();
|
$db = DB::db();
|
||||||
[$year, $month] = [$env['year'], $env['month']];
|
[$year, $month] = [$env['year'], $env['month']];
|
||||||
|
|
||||||
$nationBettingStor = KVStorage::getStorage($db, 'nation_betting');
|
$bettingStor = KVStorage::getStorage($db, 'betting');
|
||||||
$bettingInfoRaw = $nationBettingStor->getValue("id_{$this->bettingID}");
|
$bettingInfoRaw = $bettingStor->getValue("id_{$this->bettingID}");
|
||||||
if($bettingInfoRaw === null){
|
if($bettingInfoRaw === null){
|
||||||
return [__CLASS__, true];
|
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;
|
$bettingInfo->finished = true;
|
||||||
$nationBettingStor->setValue("id_{$this->bettingID}", $bettingInfo->toArray());
|
$bettingStor->setValue("id_{$this->bettingID}", $bettingInfo->toArray());
|
||||||
|
|
||||||
//TODO: 포인트를 배분해주어야 함
|
//TODO: 포인트를 배분해주어야 함
|
||||||
//TODO: 이후 토너먼트 베팅 결과도 같이 처리할 것이므로, 별도의 함수나 모듈을 생성하여 처리!
|
//TODO: 이후 토너먼트 베팅 결과도 같이 처리할 것이므로, 별도의 함수나 모듈을 생성하여 처리!
|
||||||
|
|||||||
@@ -5,10 +5,13 @@ namespace sammo\Event\Action;
|
|||||||
use \sammo\GameConst;
|
use \sammo\GameConst;
|
||||||
use \sammo\Util;
|
use \sammo\Util;
|
||||||
use \sammo\DB;
|
use \sammo\DB;
|
||||||
use sammo\DTO\NationBettingInfo;
|
use sammo\DTO\BettingInfo;
|
||||||
|
use Sammo\DTO\SelectItem;
|
||||||
use sammo\Json;
|
use sammo\Json;
|
||||||
use sammo\KVStorage;
|
use sammo\KVStorage;
|
||||||
|
|
||||||
|
use function sammo\getAllNationStaticInfo;
|
||||||
|
|
||||||
class OpenNationBetting extends \sammo\Event\Action
|
class OpenNationBetting extends \sammo\Event\Action
|
||||||
{
|
{
|
||||||
public function __construct(private int $nationCnt = 1, private int $bonusPoint = 0)
|
public function __construct(private int $nationCnt = 1, private int $bonusPoint = 0)
|
||||||
@@ -16,7 +19,7 @@ class OpenNationBetting extends \sammo\Event\Action
|
|||||||
if ($nationCnt < 1) {
|
if ($nationCnt < 1) {
|
||||||
throw new \RuntimeException("1 미만의 숫자");
|
throw new \RuntimeException("1 미만의 숫자");
|
||||||
}
|
}
|
||||||
if ($bonusPoint < 0){
|
if ($bonusPoint < 0) {
|
||||||
throw new \RuntimeException("0 미만의 보너스 포인트");
|
throw new \RuntimeException("0 미만의 보너스 포인트");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +33,7 @@ class OpenNationBetting extends \sammo\Event\Action
|
|||||||
$bettingID = ($gameStor->getValue('last_betting_id') ?? 0) + 1;
|
$bettingID = ($gameStor->getValue('last_betting_id') ?? 0) + 1;
|
||||||
$gameStor->setValue('last_betting_id', $bettingID);
|
$gameStor->setValue('last_betting_id', $bettingID);
|
||||||
|
|
||||||
$nationBettingStor = KVStorage::getStorage($db, 'nation_betting');
|
$bettingStor = KVStorage::getStorage($db, 'betting');
|
||||||
[$year, $month] = [$env['year'], $env['month']];
|
[$year, $month] = [$env['year'], $env['month']];
|
||||||
|
|
||||||
if ($this->nationCnt == 1) {
|
if ($this->nationCnt == 1) {
|
||||||
@@ -43,16 +46,45 @@ class OpenNationBetting extends \sammo\Event\Action
|
|||||||
$openYearMonth = Util::joinYearMonth($year, $month);
|
$openYearMonth = Util::joinYearMonth($year, $month);
|
||||||
$closeYearMonth = $openYearMonth + 24;
|
$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,
|
id: $bettingID,
|
||||||
|
type: 'bettingNation',
|
||||||
name: "[{$year}년 {$month}월] {$name} 예상 베팅",
|
name: "[{$year}년 {$month}월] {$name} 예상 베팅",
|
||||||
finished: false,
|
finished: false,
|
||||||
selectCnt: $this->nationCnt,
|
selectCnt: $this->nationCnt,
|
||||||
reqInheritancePoint: true,
|
reqInheritancePoint: true,
|
||||||
openYearMonth: $openYearMonth,
|
openYearMonth: $openYearMonth,
|
||||||
closeYearMonth: $closeYearMonth,
|
closeYearMonth: $closeYearMonth,
|
||||||
|
candidates: $candidates,
|
||||||
);
|
);
|
||||||
$nationBettingStor->setValue("id_{$bettingID}", $bettingInfo->toArray());
|
$bettingStor->setValue("id_{$bettingID}", $bettingInfo->toArray());
|
||||||
|
|
||||||
$db->insert('event', [
|
$db->insert('event', [
|
||||||
'target' => 'DESTROY_NATION',
|
'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', [
|
$db->insert('ng_betting', [
|
||||||
'betting_id' => $bettingID,
|
'betting_id' => $bettingID,
|
||||||
'general_id' => 0,
|
'general_id' => 0,
|
||||||
'betting_type' => '0',
|
'betting_type' => '[-1]',
|
||||||
'amount' => $this->bonusPoint
|
'amount' => $this->bonusPoint
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$logger = new \sammo\ActionLogger(0, 0, $year, $month);
|
$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();
|
$logger->flush();
|
||||||
|
|
||||||
return [__CLASS__, true];
|
return [__CLASS__, true];
|
||||||
|
|||||||
Reference in New Issue
Block a user