From f59449c15bc7463ea568965d3e96f57b8a6705f0 Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 26 Jan 2022 23:10:55 +0900 Subject: [PATCH] =?UTF-8?q?feat(WIP):=20=EB=B2=A0=ED=8C=85=20=EA=B0=9C?= =?UTF-8?q?=EC=8B=9C=20=ED=83=80=EC=9E=85=20=EB=B3=80=EA=B2=BD=20-candidat?= =?UTF-8?q?e=EB=A5=BC=20=EB=AF=B8=EB=A6=AC=20=EC=B6=94=EA=B0=80.=20-?= =?UTF-8?q?=EC=9D=B4=EB=A5=BC=20=ED=86=B5=ED=95=B4=20betting=EC=9D=84=20?= =?UTF-8?q?=EC=A4=91=EB=A6=BD=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EC=9A=B4?= =?UTF-8?q?=EC=9A=A9=20=EA=B0=80=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BetNation.php => Betting/Bet.php} | 28 +++++----- .../GetBettingDetail.php | 8 +-- .../GetBettingList.php | 10 ++-- ...{NationBettingInfo.php => BettingInfo.php} | 9 +++- hwe/sammo/DTO/SelectItem.php | 15 ++++++ .../Event/Action/FinishNationBetting.php | 13 +++-- hwe/sammo/Event/Action/OpenNationBetting.php | 53 ++++++++++++++++--- 7 files changed, 101 insertions(+), 35 deletions(-) rename hwe/sammo/API/{NationBetting/BetNation.php => Betting/Bet.php} (82%) rename hwe/sammo/API/{NationBetting => Betting}/GetBettingDetail.php (91%) rename hwe/sammo/API/{NationBetting => Betting}/GetBettingList.php (87%) rename hwe/sammo/DTO/{NationBettingInfo.php => BettingInfo.php} (65%) create mode 100644 hwe/sammo/DTO/SelectItem.php diff --git a/hwe/sammo/API/NationBetting/BetNation.php b/hwe/sammo/API/Betting/Bet.php similarity index 82% rename from hwe/sammo/API/NationBetting/BetNation.php rename to hwe/sammo/API/Betting/Bet.php index 40f3b6f4..4fa82448 100644 --- a/hwe/sammo/API/NationBetting/BetNation.php +++ b/hwe/sammo/API/Betting/Bet.php @@ -8,7 +8,7 @@ use sammo\DB; use Sammo\DTO\BettingItem; use sammo\Validator; use sammo\Json; -use sammo\DTO\NationBettingInfo; +use sammo\DTO\BettingInfo; use sammo\GameConst; use sammo\General; use sammo\KVStorage; @@ -54,14 +54,14 @@ class BetNation extends \sammo\BaseAPI $amount = $this->args['amount']; $gameStor = KVStorage::getStorage($db, 'game_env'); - $nationBettingStor = KVStorage::getStorage($db, 'nation_betting'); - $rawBettingInfo = $nationBettingStor->getValue("id_{$bettingID}"); + $bettingStor = KVStorage::getStorage($db, 'betting'); + $rawBettingInfo = $bettingStor->getValue("id_{$bettingID}"); if($rawBettingInfo === null){ return '해당 베팅이 없습니다'; } try{ - $bettingInfo = new NationBettingInfo($rawBettingInfo); + $bettingInfo = new BettingInfo($rawBettingInfo); } catch(\Error $e){ return $e->getMessage(); @@ -88,16 +88,20 @@ class BetNation extends \sammo\BaseAPI } - sort($bettingType);//NOTE: key로 바로 사용하므로 중요함 - $bettingTypeKey = Json::encode($bettingType); - $nations = getAllNationStaticInfo(); - - foreach($bettingType as $bettingNationID){ - if(!key_exists($bettingNationID, $nations)){ - return '존재하지 않는 국가를 선택했습니다.'; - } + $bettingType = array_unique($bettingType, SORT_NUMERIC);//NOTE: key로 바로 사용하므로 중요함 + if(count($bettingType) != $bettingInfo->selectCnt){ + 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); if($bettingInfo->reqInheritancePoint){ diff --git a/hwe/sammo/API/NationBetting/GetBettingDetail.php b/hwe/sammo/API/Betting/GetBettingDetail.php similarity index 91% rename from hwe/sammo/API/NationBetting/GetBettingDetail.php rename to hwe/sammo/API/Betting/GetBettingDetail.php index e3a4d5e8..1195fca1 100644 --- a/hwe/sammo/API/NationBetting/GetBettingDetail.php +++ b/hwe/sammo/API/Betting/GetBettingDetail.php @@ -5,7 +5,7 @@ namespace sammo\API\NationBetting; use sammo\Session; use DateTimeInterface; use sammo\DB; -use sammo\DTO\NationBettingInfo; +use sammo\DTO\BettingInfo; use sammo\General; use sammo\KVStorage; use sammo\Validator; @@ -42,14 +42,14 @@ class GetBettingDetail extends \sammo\BaseAPI $bettingID = $this->arg['betting_id']; $gameStor = KVStorage::getStorage($db, 'game_env'); - $nationBettingStor = KVStorage::getStorage($db, 'nation_betting'); - $rawBettingInfo = $nationBettingStor->getValue("id_{$bettingID}"); + $bettingStor = KVStorage::getStorage($db, 'betting'); + $rawBettingInfo = $bettingStor->getValue("id_{$bettingID}"); if($rawBettingInfo === null){ return '해당 베팅이 없습니다'; } try{ - $bettingInfo = new NationBettingInfo($rawBettingInfo); + $bettingInfo = new BettingInfo($rawBettingInfo); } catch(\Error $e){ return $e->getMessage(); diff --git a/hwe/sammo/API/NationBetting/GetBettingList.php b/hwe/sammo/API/Betting/GetBettingList.php similarity index 87% rename from hwe/sammo/API/NationBetting/GetBettingList.php rename to hwe/sammo/API/Betting/GetBettingList.php index 8f3bf0b2..0a80ae7b 100644 --- a/hwe/sammo/API/NationBetting/GetBettingList.php +++ b/hwe/sammo/API/Betting/GetBettingList.php @@ -5,7 +5,7 @@ namespace sammo\API\NationBetting; use sammo\Session; use DateTimeInterface; use sammo\DB; -use sammo\DTO\NationBettingInfo; +use sammo\DTO\BettingInfo; use sammo\KVStorage; use function sammo\checkLimit; @@ -27,10 +27,10 @@ class GetBettingList extends \sammo\BaseAPI { $db = DB::db(); - increaseRefresh("국가베팅장", 1); + increaseRefresh("베팅장", 1); $gameStor = KVStorage::getStorage($db, 'game_env'); - $nationBettingStor = KVStorage::getStorage($db, 'nation_betting'); + $bettingStor = KVStorage::getStorage($db, 'betting'); $userID = $session->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 = []; - foreach ($nationBettingStor->getAll() as $_key => $rawItem) { - $item = new NationBettingInfo($rawItem); + foreach ($bettingStor->getAll() as $_key => $rawItem) { + $item = new BettingInfo($rawItem); $bettingList[$item->id] = $rawItem; $bettingList[$item->id]['totalAmount'] = 0; } diff --git a/hwe/sammo/DTO/NationBettingInfo.php b/hwe/sammo/DTO/BettingInfo.php similarity index 65% rename from hwe/sammo/DTO/NationBettingInfo.php rename to hwe/sammo/DTO/BettingInfo.php index 2d10b293..984a8955 100644 --- a/hwe/sammo/DTO/NationBettingInfo.php +++ b/hwe/sammo/DTO/BettingInfo.php @@ -2,6 +2,8 @@ namespace sammo\DTO; +use Sammo\DTO\SelectItem; +use Spatie\DataTransferObject\Attributes\CastWith; use Spatie\DataTransferObject\Attributes\Strict; use Spatie\DataTransferObject\DataTransferObject; @@ -10,15 +12,20 @@ use Spatie\DataTransferObject\DataTransferObject; #[Strict] -class NationBettingInfo extends DataTransferObject +class BettingInfo extends DataTransferObject { public int $id; + public string $type; public string $name; public bool $finished; public int $selectCnt; public bool $reqInheritancePoint; public int $openYearMonth; public int $closeYearMonth; + + /** @var \sammo\DTO\SelectItem[] */ + #[CastWith(ArrayCaster::class, itemType: SelectItem::class)] + public array $candidates; } diff --git a/hwe/sammo/DTO/SelectItem.php b/hwe/sammo/DTO/SelectItem.php new file mode 100644 index 00000000..2ff8cffe --- /dev/null +++ b/hwe/sammo/DTO/SelectItem.php @@ -0,0 +1,15 @@ +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: 이후 토너먼트 베팅 결과도 같이 처리할 것이므로, 별도의 함수나 모듈을 생성하여 처리! diff --git a/hwe/sammo/Event/Action/OpenNationBetting.php b/hwe/sammo/Event/Action/OpenNationBetting.php index feea37d2..880cba06 100644 --- a/hwe/sammo/Event/Action/OpenNationBetting.php +++ b/hwe/sammo/Event/Action/OpenNationBetting.php @@ -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("
", $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("【내기】천하통일을 염원하는 내기가 진행중입니다! 호사가의 참여를 기다립니다!"); + if ($this->nationCnt > 1) { + $logger->pushGlobalHistoryLog("【내기】중원의 강자를 점치는 내기가 진행중입니다! 호사가의 참여를 기다립니다!"); + } else { + $logger->pushGlobalHistoryLog("【내기】천하통일 후보를 점치는 내기가 진행중입니다! 호사가의 참여를 기다립니다!"); + } + $logger->flush(); return [__CLASS__, true];