feat: 아이템 유산포인트로 입찰한 경우 최종적으로 얻는 기능 추가
This commit is contained in:
+182
-4
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
use sammo\Event\Action;
|
use sammo\Event\Action;
|
||||||
|
|
||||||
require_once 'process_war.php';
|
require_once 'process_war.php';
|
||||||
@@ -1607,6 +1608,177 @@ function giveRandomUniqueItem(General $general, string $acquireType): bool
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function rollbackInheritUniqueTrial(General $general, string $itemKey, string $reason)
|
||||||
|
{
|
||||||
|
$ownerID = $general->getVar('owner');
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$itemTrials = $general->getAuxVar('inheritUniqueTrial');
|
||||||
|
unset($itemTrials[$itemKey]);
|
||||||
|
$general->setAuxVar('inheritUniqueTrial', $itemTrials);
|
||||||
|
|
||||||
|
$trialStor = KVStorage::getStorage($db, "ut_{$itemKey}");
|
||||||
|
$ownTrial = $trialStor->getValue("u{$ownerID}");
|
||||||
|
|
||||||
|
if ($ownTrial) {
|
||||||
|
//두 값이 general, KVStorage 둘다 있고, 이중에선 KVStorage 값을 기준으로 하자 따르자
|
||||||
|
[,, $amount] = $ownTrial;
|
||||||
|
$trialStor->deleteValue("u{$ownerID}");
|
||||||
|
$general->increaseInheritancePoint('previous', $amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemObj = buildItemClass($itemKey);
|
||||||
|
$itemName = $itemObj->getName();
|
||||||
|
//메시지
|
||||||
|
|
||||||
|
$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'], $general->getVar('icon'));
|
||||||
|
$josaUl = JosaUtil::pick($itemName, '을');
|
||||||
|
$msg = new Message(
|
||||||
|
Message::MSGTYPE_PRIVATE,
|
||||||
|
$src,
|
||||||
|
$dest,
|
||||||
|
"{$itemName}{$josaUl} 얻지 못했습니다. {$reason}",
|
||||||
|
new DateTime(),
|
||||||
|
$unlimited,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
$msg->send(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function tryInheritUniqueItem(General $general, string $acquireType = '아이템'): bool
|
||||||
|
{
|
||||||
|
$ownerID = $general->getVar('owner');
|
||||||
|
if (!$ownerID) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemTrials = $general->getAuxVar('inheritUniqueTrial') ?? [];
|
||||||
|
arsort($itemTrials);
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$acquireTarget = null;
|
||||||
|
$acquireType = 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 = Util::choiceRandom($availableItemTypes);
|
||||||
|
|
||||||
|
$trialStor = KVStorage::getStorage($db, "ut_{$itemKey}"); //혹시 itemKey의 크기가 37이 넘을 수 있을까?
|
||||||
|
$anyTrials = $trialStor->getAll();
|
||||||
|
if (!$anyTrials) {
|
||||||
|
//순서가 꼬였던 모양, 실제 값은 storage를 우선시하자
|
||||||
|
rollbackInheritUniqueTrial($general, $itemKey, '절차상의 오류입니다.');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
usort($anyTrials, function ($lhsTrial, $rhsTrial) {
|
||||||
|
[,, $lhsAmount] = $lhsTrial;
|
||||||
|
[,, $rhsAmount] = $rhsTrial;
|
||||||
|
return $rhsAmount <=> $lhsAmount; //큰 값이 앞에 오도록
|
||||||
|
});
|
||||||
|
|
||||||
|
//공동 1등인데 본인이 있을 수도 있다.
|
||||||
|
[,, $topAmount] = $anyTrials;
|
||||||
|
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 (!$acquireTarget) {
|
||||||
|
//이미 다른 아이템을 얻기로 되어있다.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$acquireTarget = $itemKey;
|
||||||
|
$acquireType = $itemType;
|
||||||
|
}
|
||||||
|
unset($itemKey);
|
||||||
|
unset($itemType);
|
||||||
|
|
||||||
|
if (!$acquireTarget) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$trialStor = KVStorage::getStorage($db, "ut_{$acquireTarget}");
|
||||||
|
$trialStor->deleteValue("u{$ownerID}");
|
||||||
|
|
||||||
|
//rollbackInheritUniqueTrial 과정 때문에 새로 받아와야함
|
||||||
|
$itemTrials = $general->getAuxVar('inheritUniqueTrial');
|
||||||
|
unset($itemTrials[$acquireTarget]);
|
||||||
|
$general->setAuxVar('inheritUniqueTrial', $itemTrials);
|
||||||
|
|
||||||
|
$nationName = $general->getStaticNation()['name'];
|
||||||
|
$generalName = $general->getName();
|
||||||
|
$josaYi = JosaUtil::pick($generalName, '이');
|
||||||
|
$itemObj = buildItemClass($acquireTarget);
|
||||||
|
$itemName = $itemObj->getName();
|
||||||
|
$itemRawName = $itemObj->getRawName();
|
||||||
|
$josaUl = JosaUtil::pick($itemRawName, '을');
|
||||||
|
|
||||||
|
|
||||||
|
$general->setVar($acquireType, $acquireTarget);
|
||||||
|
|
||||||
|
|
||||||
|
$logger = $general->getLogger();
|
||||||
|
|
||||||
|
$logger->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 습득했습니다!");
|
||||||
|
$logger->pushGeneralHistoryLog("<C>{$itemName}</>{$josaUl} 습득");
|
||||||
|
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <C>{$itemName}</>{$josaUl} 습득했습니다!");
|
||||||
|
$logger->pushGlobalHistoryLog("<C><b>【{$acquireType}】</b></><D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} <C>{$itemName}</>{$josaUl} 습득했습니다!");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function tryUniqueItemLottery(General $general, string $acquireType = '아이템'): bool
|
function tryUniqueItemLottery(General $general, string $acquireType = '아이템'): bool
|
||||||
{
|
{
|
||||||
$db = DB::db();
|
$db = DB::db();
|
||||||
@@ -1616,8 +1788,12 @@ function tryUniqueItemLottery(General $general, string $acquireType = '아이템
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($general->getNPCType() > 6) {
|
$inheritUnique = $general->getAuxVar('inheritUniqueTrial');
|
||||||
return false;
|
if (count($inheritUnique)) {
|
||||||
|
$trialResult = tryInheritUniqueItem($general, $acquireType);
|
||||||
|
if ($trialResult) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemTypeCnt = count(GameConst::$allItems);
|
$itemTypeCnt = count(GameConst::$allItems);
|
||||||
@@ -1706,7 +1882,8 @@ function deleteNation(General $lord, bool $applyDB):array
|
|||||||
$nationID,
|
$nationID,
|
||||||
$lordID
|
$lordID
|
||||||
),
|
),
|
||||||
['npc', 'gold', 'rice', 'experience', 'explevel', 'dedication', 'dedlevel', 'belong', 'aux'], 1
|
['npc', 'gold', 'rice', 'experience', 'explevel', 'dedication', 'dedlevel', 'belong', 'aux'],
|
||||||
|
1
|
||||||
);
|
);
|
||||||
$nationGeneralList[$lordID] = $lord;
|
$nationGeneralList[$lordID] = $lord;
|
||||||
|
|
||||||
@@ -1723,7 +1900,8 @@ function deleteNation(General $lord, bool $applyDB):array
|
|||||||
|
|
||||||
// 전 장수 재야로
|
// 전 장수 재야로
|
||||||
foreach ($nationGeneralList as $general) {
|
foreach ($nationGeneralList as $general) {
|
||||||
$general->setAuxVar('max_belong',
|
$general->setAuxVar(
|
||||||
|
'max_belong',
|
||||||
max(
|
max(
|
||||||
$general->getVar('belong'),
|
$general->getVar('belong'),
|
||||||
$general->getAuxVar('max_belong') ?? 0
|
$general->getAuxVar('max_belong') ?? 0
|
||||||
|
|||||||
Reference in New Issue
Block a user