From 606fa4a922af54546be341eef44d6024589e63b4 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Wed, 8 Jun 2022 01:22:31 +0900 Subject: [PATCH] =?UTF-8?q?feat,wip:=20=EC=9C=A0=EB=8B=88=ED=81=AC=20?= =?UTF-8?q?=EA=B2=BD=EB=A7=A4=20=EC=8B=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func.php | 218 ------------------ .../API/InheritAction/BuySpecificUnique.php | 104 --------- hwe/sammo/Enums/ResourceType.php | 2 +- hwe/sammo/General.php | 18 +- hwe/ts/PageInheritPoint.vue | 30 +-- hwe/ts/SammoAPI.ts | 4 - 6 files changed, 18 insertions(+), 358 deletions(-) delete mode 100644 hwe/sammo/API/InheritAction/BuySpecificUnique.php diff --git a/hwe/func.php b/hwe/func.php index 0e7b550b..1dbc29ab 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -1673,215 +1673,6 @@ function giveRandomUniqueItem(RandUtil $rng, General $general, string $acquireTy return true; } -function rollbackInheritUniqueTrial(General $general, string $itemKey, string $reason) -{ - - $ownerID = $general->getVar('owner'); - - $db = DB::db(); - - $itemTrials = $general->getAuxVar('inheritUniqueTrial'); - LogText("선택유니크 롤백:{$ownerID}", [$itemKey, $itemTrials]); - unset($itemTrials[$itemKey]); - if (count($itemTrials) == 0) { - $itemTrials = null; - } - $general->setAuxVar('inheritUniqueTrial', $itemTrials); - - - $trialStor = KVStorage::getStorage($db, "ut_{$itemKey}"); - $ownTrial = $trialStor->getValue("u{$ownerID}"); - - $itemObj = buildItemClass($itemKey); - $itemName = $itemObj->getName(); - - if ($ownTrial) { - //두 값이 general, KVStorage 둘다 있고, 이중에선 KVStorage 값을 기준으로 하자 따르자 - [,, $amount] = $ownTrial; - $trialStor->deleteValue("u{$ownerID}"); - $general->increaseInheritancePoint(InheritanceKey::previous, $amount); - $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, -$amount); - LogText("선택유니크 롤백포인트:{$ownerID}", $amount); - - $userLogger = new UserLogger($ownerID); - $userLogger->push("{$itemName} 입찰에 사용한 {$amount} 포인트 반환", "inheritPoint"); - } - - //메시지 - - $staticNation = $general->getStaticNation(); - - $unlimited = new \DateTime('9999-12-31'); - $src = new MessageTarget(0, '', 0, 'System', '#000000'); - $dest = new MessageTarget($general->getID(), $general->getName(), $general->getNationID(), $staticNation['name'], $staticNation['color'], GetImageURL($general->getVar('imgsvr'), $general->getVar('picture'))); - $josaUl = JosaUtil::pick($itemName, '을'); - $msg = new Message( - Message::MSGTYPE_PRIVATE, - $src, - $dest, - "{$itemName}{$josaUl} 얻지 못했습니다. {$reason}", - new DateTime(), - $unlimited, - [] - ); - - $general->applyDB($db); - $msg->send(true); -} - -function tryRollbackInheritUniqueItem(RandUtil $rng, General $general): void -{ - tryInheritUniqueItem($rng, $general, 'Rollback', true); -} - -function tryInheritUniqueItem(RandUtil $rng, General $general, string $acquireType = '아이템', bool $justRollback = false): bool -{ - $ownerID = $general->getVar('owner'); - if (!$ownerID) { - LogText("선택유니크 실패???: {$ownerID}", $general->getName()); - return false; - } - - $itemTrials = $general->getAuxVar('inheritUniqueTrial') ?? []; - arsort($itemTrials); - LogText("선택유니크항목: {$ownerID}", $itemTrials); - - $db = DB::db(); - - $ownTarget = null; - $ownType = null; - - foreach ($itemTrials as $itemKey => $amount) { - $availableItemTypes = []; - $reasons = []; - foreach (GameConst::$allItems as $itemType => $itemList) { - //아직은 그런 경우는 없지만 동일 유니크를 여러 부위에 장착할 수 있을지도 모름 - if (!key_exists($itemKey, $itemList)) { - continue; - } - - $ownItem = $general->getItem($itemType); - if ($ownItem->getRawClassName() == $itemKey) { - $reasons[] = '이미 그 유니크를 가지고 있습니다.'; - continue; - } - - if (!$ownItem->isBuyable()) { - $reasons[] = '이미 다른 유니크를 가지고 있습니다.'; - continue; - } - - $availableCnt = $itemList[$itemKey]; - $occupiedCnt = $db->queryFirstField('SELECT count(*) FROM general WHERE %b = %s', $itemType, $itemKey); - if ($occupiedCnt >= $availableCnt) { - $reasons[] = '그 유니크는 모두 점유되었습니다.'; - continue; - } - $availableItemTypes[] = $itemType; - } - - if (!$availableItemTypes) { - rollbackInheritUniqueTrial($general, $itemKey, join(' ', $reasons)); - continue; - } - $reasons = []; - - $itemType = $rng->choice($availableItemTypes); - - $trialStor = KVStorage::getStorage($db, "ut_{$itemKey}"); //혹시 itemKey의 크기가 37이 넘을 수 있을까? - $anyTrials = $trialStor->getAll(); - if (!$anyTrials) { - //순서가 꼬였던 모양, 실제 값은 storage를 우선시하자 - rollbackInheritUniqueTrial($general, $itemKey, '절차상의 오류입니다.'); - continue; - } - - //XXX: 정렬할 필요 없지 않나? - usort($anyTrials, function ($lhsTrial, $rhsTrial) { - [,, $lhsAmount] = $lhsTrial; - [,, $rhsAmount] = $rhsTrial; - return $rhsAmount <=> $lhsAmount; //큰 값이 앞에 오도록 - }); - - LogText("선택유니크상태 {$ownerID} {$itemKey}", $anyTrials); - - //공동 1등인데 본인이 있을 수도 있다. - [,, $topAmount] = $anyTrials[0]; - if ($amount < $topAmount) { - $compAmount = $topAmount / $amount; - if ($compAmount > 2.0) { - $compText = '엄청난 차이로 '; - } else if ($compAmount > 1.2) { - $compText = '큰 차이로 '; - } else if ($compAmount > 1.05) { - $compText = ''; - } else { - $compText = '아슬아슬한 차이로 '; - } - rollbackInheritUniqueTrial($general, $itemKey, "{$compText}상위 입찰한 장수가 있습니다."); - continue; - } - - //내가 1위다 - if ($ownTarget !== null) { - //이미 다른 아이템을 얻기로 되어있다. - continue; - } - $ownTarget = $itemKey; - $ownType = $itemType; - } - unset($itemKey); - unset($itemType); - - if ($ownTarget === null) { - return false; - } - if ($justRollback) { - return false; - } - - LogText("선택유니크획득{$ownerID}", $ownTarget); - - $trialStor = KVStorage::getStorage($db, "ut_{$ownTarget}"); - $trialStor->deleteValue("u{$ownerID}"); - - //rollbackInheritUniqueTrial 과정 때문에 새로 받아와야함 - $itemTrials = $general->getAuxVar('inheritUniqueTrial'); - unset($itemTrials[$ownTarget]); - $general->setAuxVar('inheritUniqueTrial', $itemTrials); - - $nationName = $general->getStaticNation()['name']; - $generalName = $general->getName(); - $josaYi = JosaUtil::pick($generalName, '이'); - $itemObj = buildItemClass($ownTarget); - $itemName = $itemObj->getName(); - $itemRawName = $itemObj->getRawName(); - $josaUl = JosaUtil::pick($itemRawName, '을'); - - - $general->setVar($ownType, $ownTarget); - - - $logger = $general->getLogger(); - - $logger->pushGeneralActionLog("{$itemName}{$josaUl} 습득했습니다!"); - $logger->pushGeneralHistoryLog("{$itemName}{$josaUl} 습득"); - $logger->pushGlobalActionLog("{$generalName}{$josaYi} {$itemName}{$josaUl} 습득했습니다!"); - $logger->pushGlobalHistoryLog("【{$acquireType}】{$nationName}{$generalName}{$josaYi} {$itemName}{$josaUl} 습득했습니다!"); - - $general->applyDB($db); - - $gameStor = KVStorage::getStorage($db, 'game_env'); - $givenUnique =$gameStor->getValue('givenUnique') ?? []; - $givenUnique[$ownTarget] = ($givenUnique[$ownTarget] ?? 0) + 1; - $gameStor->setValue('givenUnique', $givenUnique); - - //같은 종류의 유니크를 입찰했을 수 있으니 한번 더 검사한다. - tryRollbackInheritUniqueItem($rng, $general); - - return true; -} - function tryUniqueItemLottery(RandUtil $rng, General $general, string $acquireType = '아이템'): bool { $db = DB::db(); @@ -1927,18 +1718,9 @@ function tryUniqueItemLottery(RandUtil $rng, General $general, string $acquireTy $userLogger = new UserLogger($general->getVar('owner')); $userLogger->push(sprintf("유니크를 얻을 공간이 없어 %d 포인트 반환", GameConst::$inheritItemRandomPoint), "inheritPoint"); } - tryRollbackInheritUniqueItem($rng, $general); return false; } - $inheritUnique = $general->getAuxVar('inheritUniqueTrial'); - if ($acquireType != '설문조사' && $inheritUnique && count($inheritUnique) && $availableBuyUnique) { - $trialResult = tryInheritUniqueItem($rng, $general, $acquireType); - if ($trialResult) { - return true; - } - } - $scenario = $gameStor->scenario; $genCount = $db->queryFirstField('SELECT count(*) FROM general WHERE npc<2'); diff --git a/hwe/sammo/API/InheritAction/BuySpecificUnique.php b/hwe/sammo/API/InheritAction/BuySpecificUnique.php deleted file mode 100644 index 3b3f7071..00000000 --- a/hwe/sammo/API/InheritAction/BuySpecificUnique.php +++ /dev/null @@ -1,104 +0,0 @@ - $amount) { - if ($amount == 0) { - continue; - } - $availableItems[$itemKey] = $amount; - } - } - - $v = new Validator($this->args); - $v->rule('required', [ - 'item', - 'amount', - ]) - ->rule('int', 'amount') - ->rule('min', 'amount', GameConst::$inheritItemUniqueMinPoint) - ->rule('keyExists', 'item', $availableItems); - - if (!$v->validate()) { - return $v->errorStr(); - } - return null; - } - - public function getRequiredSessionMode(): int - { - //KVStrorage, General.aux 모두 쓰므로 lock; - return static::REQ_GAME_LOGIN; - } - - public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag) - { - $itemKey = $this->args['item']; - $amount = $this->args['amount']; - - $userID = $session->userID; - $generalID = $session->generalID; - - $general = General::createGeneralObjFromDB($generalID); - if ($userID != $general->getVar('owner')) { - return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; - } - - $itemTrials = $general->getAuxVar('inheritUniqueTrial') ?? []; - if (key_exists($itemKey, $itemTrials)) { - return '이미 입찰한 아이템입니다. 다음 턴에 시도해 주세요.'; - } - - foreach(GameConst::$allItems as $itemType => $items){ - if(!key_exists($itemKey, $items)){ - continue; - } - - $prevItem = $general->getItem($itemType); - if(!$prevItem->isBuyable()){ - return '이미 같은 자리에 유니크를 보유하고 있습니다.'; - } - - break; - } - - $db = DB::db(); - $inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}"); - $trialStor = KVStorage::getStorage($db, "ut_{$itemKey}"); - $previousPoint = ($inheritStor->getValue('previous') ?? [0, 0])[0]; - if ($previousPoint < $amount) { - return '충분한 유산 포인트를 가지고 있지 않습니다.'; - } - - $itemObj = buildItemClass($itemKey); - $userLogger = new UserLogger($userID); - $userLogger->push("{$amount} 포인트로 유니크 {$itemObj->getName()} 구입 시도", "inheritPoint"); - $userLogger->flush(); - - $itemTrials[$itemKey] = $amount; - $general->setAuxVar('inheritUniqueTrial', $itemTrials); - $inheritStor->setValue('previous', [$previousPoint - $amount, null]); - $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $amount); - $trialStor->setValue("u{$userID}", [$userID, $generalID, $amount]); - $general->applyDB($db); - return null; - } -} diff --git a/hwe/sammo/Enums/ResourceType.php b/hwe/sammo/Enums/ResourceType.php index ca0f0348..ad40456b 100644 --- a/hwe/sammo/Enums/ResourceType.php +++ b/hwe/sammo/Enums/ResourceType.php @@ -5,7 +5,7 @@ enum ResourceType: string { case gold = 'gold'; case rice = 'rice'; - case inheritancePoint = 'inheritancePoint'; + case inheritancePoint = 'inheritPoint'; public function getName(): string { diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index cb9bab77..c5a5257c 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -610,23 +610,7 @@ class General implements iAction $refundPoint += GameConst::$inheritItemRandomPoint; } - $itemTrials = $this->getAuxVar('inheritUniqueTrial') ?? []; - foreach (array_keys($itemTrials) as $itemKey) { - $trialStor = KVStorage::getStorage($db, "ut_{$itemKey}"); - $ownTrial = $trialStor->getValue("u{$userID}"); - - $itemObj = buildItemClass($itemKey); - $itemName = $itemObj->getName(); - - if (!$ownTrial) { - continue; - } - - [,, $amount] = $ownTrial; - $trialStor->deleteValue("u{$userID}"); - $userLogger->push("사망으로 {$itemName} 입찰에 사용한 {$amount} 포인트 반환", "inheritPoint"); - $refundPoint += $amount; - } + //TODO: 경매 최우선 입찰자인경우 반환 if ($this->getAuxVar('inheritSpecificSpecialWar')) { $this->setAuxVar('inheritSpecificSpecialWar', null); diff --git a/hwe/ts/PageInheritPoint.vue b/hwe/ts/PageInheritPoint.vue index 2bfef428..e97ef8f2 100644 --- a/hwe/ts/PageInheritPoint.vue +++ b/hwe/ts/PageInheritPoint.vue @@ -62,12 +62,12 @@ >
- 구입 + 구입
-
유니크 입찰
+
유니크 경매