From d9f8ad9db8254f8feb8ca674340b8b7eef584ccd Mon Sep 17 00:00:00 2001 From: hide_d Date: Mon, 24 Jan 2022 03:22:57 +0900 Subject: [PATCH] =?UTF-8?q?feat(WIP):=20=EB=B2=A0=ED=8C=85=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=9E=91=EC=97=85=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/API/NationBetting/BetNation.php | 141 ++++++++++++++++++ .../API/NationBetting/GetBettingList.php | 70 +++++++++ hwe/sammo/DTO/BettingItem.php | 23 +++ hwe/sammo/DTO/NationBettingInfo.php | 36 +++++ hwe/v_nationBetting.php | 39 +++++ 5 files changed, 309 insertions(+) create mode 100644 hwe/sammo/API/NationBetting/BetNation.php create mode 100644 hwe/sammo/API/NationBetting/GetBettingList.php create mode 100644 hwe/sammo/DTO/BettingItem.php create mode 100644 hwe/sammo/DTO/NationBettingInfo.php create mode 100644 hwe/v_nationBetting.php diff --git a/hwe/sammo/API/NationBetting/BetNation.php b/hwe/sammo/API/NationBetting/BetNation.php new file mode 100644 index 00000000..e3bf85b4 --- /dev/null +++ b/hwe/sammo/API/NationBetting/BetNation.php @@ -0,0 +1,141 @@ +args); + $v->rule('required', [ + 'betting_id', + 'betting_type', + 'amount' + ]) + ->rule('integer', 'betting_id') + ->rule('integerArray', 'betting_type') + ->rule('integer', 'amount') + ->rule('min', 'amount', 1); + + if (!$v->validate()) { + return $v->errorStr(); + } + return null; + } + + public function getRequiredSessionMode(): int + { + return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY; + } + + public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag) + { + $db = DB::db(); + + /** @var int */ + $bettingID = $this->arg['betting_id']; + /** @var int[] */ + $bettingType = $this->arg['betting_type']; + /** @var int[] */ + $amount = $this->args['amount']; + + $gameStor = KVStorage::getStorage($db, 'game_env'); + $nationBettingStor = KVStorage::getStorage($db, 'nation_betting'); + $rawBettingInfo = $nationBettingStor->getValue("id_{$bettingID}"); + if($rawBettingInfo === null){ + return '해당 베팅이 없습니다'; + } + + try{ + $bettingInfo = new NationBettingInfo($rawBettingInfo); + } + catch(\Error $e){ + return $e->getMessage(); + } + + if($bettingInfo->finished){ + return '이미 종료된 베팅입니다'; + } + + [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); + $yearMonth = Util::joinYearMonth($year, $month); + + + if($bettingInfo->closeYearMonth > $yearMonth){ + return '이미 마감된 베팅입니다'; + } + + if($bettingInfo->openYearMonth > $yearMonth){ + return '아직 시작되지 않은 베팅입니다'; + } + + if(count($bettingType) != $bettingInfo->selectCnt){ + return '필요한 선택 수를 채우지 못했습니다.'; + } + + + sort($bettingType);//NOTE: key로 바로 사용하므로 중요함 + $bettingTypeKey = Json::encode($bettingType); + $nations = getAllNationStaticInfo(); + + foreach($bettingType as $bettingNationID){ + if(!key_exists($bettingNationID, $nations)){ + return '존재하지 않는 국가를 선택했습니다.'; + } + } + + $general = General::createGeneralObjFromDB($session->generalID, ['gold', 'aux'], 1); + + if($bettingInfo->reqInheritancePoint){ + if($general->getInheritancePoint('previous') < $amount){ + return '유산포인트가 충분하지 않습니다.'; + } + } + else { + if($general->getVar('gold') < GameConst::$generalMinimumGold + $amount){ + return '금이 부족합니다.'; + } + } + + $userID = $session->userID; + + $bettingItem = new BettingItem([ + 'betting_id'=>$bettingID, + 'general_id'=>$session->generalID, + 'user_id'=>$userID, + 'betting_type'=>$bettingTypeKey, + 'amount'=>$amount + ]); + + if($bettingInfo->reqInheritancePoint){ + $general->increaseInheritancePoint('previous', -$amount); + } + else{ + $general->increaseVar('gold', -$amount); + } + $db->insert('ng_betting', $bettingItem->toArray()); + if(!$db->affected_rows){ + $general->flushUpdateValues(); + return '베팅을 실패했습니다.'; + } + $general->applyDB($db); + + return [ + 'result'=>true + ]; + } +} diff --git a/hwe/sammo/API/NationBetting/GetBettingList.php b/hwe/sammo/API/NationBetting/GetBettingList.php new file mode 100644 index 00000000..efb400d1 --- /dev/null +++ b/hwe/sammo/API/NationBetting/GetBettingList.php @@ -0,0 +1,70 @@ +userID; + + $me = $db->queryFirstRow('SELECT no,nation,officer_level,con,turntime,belong,penalty,permission FROM general WHERE owner=%i', $userID); + $con = checkLimit($me['con']); + if ($con >= 2) { + return "접속 제한중입니다. 1턴 이내에 너무 많은 갱신을 하셨습니다. (다음 갱신 가능 시각 : {$me['turntime']})"; + } + + $bettingList = []; + foreach ($nationBettingStor->getAll() as $_key => $rawItem) { + $item = new NationBettingInfo($rawItem); + $bettingList[$item->id] = $rawItem; + $bettingList[$item->id]['totalAmount'] = 0; + } + + $bettingIDList = array_keys($bettingList); + // XXX: query cache만 믿고 sum을 하는 짓을 벌여도 되는가? + foreach ($db->queryAllLists( + 'SELECT betting_id, sum(amount) as total_amount FROM ng_betting WHERE betting_id IN %li GROUP BY betting_id', + $bettingIDList + ) as [$bettingID, $totalAmount]) { + if (!key_exists($bettingID, $bettingList)) { + continue; + } + $bettingList[$bettingID]['totalAmount'] = $totalAmount; + } + + [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); + + return [ + 'result' => false, + 'bettingList' => $bettingList, + 'year' => $year, + 'month' => $month, + ]; + } +} diff --git a/hwe/sammo/DTO/BettingItem.php b/hwe/sammo/DTO/BettingItem.php new file mode 100644 index 00000000..c37d8290 --- /dev/null +++ b/hwe/sammo/DTO/BettingItem.php @@ -0,0 +1,23 @@ +setReadOnly(); +$userID = Session::getUserID(); + +$db = DB::db(); +$gameStor = KVStorage::getStorage($db, 'game_env'); + +$generalID = $session->generalID; +?> + + + + + + + + <?= UniqueConst::$serverName ?>: 내무부 + [ + + ] + ], false) ?> + + + + + + + +
+ + + \ No newline at end of file