feat: 전역 아이템 망실 이벤트 추가
This commit is contained in:
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\Event\Action;
|
||||||
|
|
||||||
|
use sammo\ActionLogger;
|
||||||
|
use sammo\CityConst;
|
||||||
|
use sammo\DB;
|
||||||
|
use sammo\KVStorage;
|
||||||
|
use sammo\Util;
|
||||||
|
use sammo\General;
|
||||||
|
use sammo\JosaUtil;
|
||||||
|
use sammo\LiteHashDRBG;
|
||||||
|
use sammo\RandUtil;
|
||||||
|
use sammo\UniqueConst;
|
||||||
|
|
||||||
|
class LostUniqueItem extends \sammo\Event\Action
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private float $lostProb = 0.1,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run(array $env)
|
||||||
|
{
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$generalIDList = $db->queryFirstColumn("SELECT `no` FROM general WHERE npc <= 1");
|
||||||
|
if(!$generalIDList){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$generals = General::createGeneralObjListFromDB($generalIDList);
|
||||||
|
|
||||||
|
$lostItems = [];
|
||||||
|
$lostCnt = 0;
|
||||||
|
|
||||||
|
$year = $env['year'];
|
||||||
|
$month = $env['month'];
|
||||||
|
$rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||||
|
UniqueConst::$hiddenSeed,
|
||||||
|
'LostUniqueItem',
|
||||||
|
$year,
|
||||||
|
$month,
|
||||||
|
)));
|
||||||
|
|
||||||
|
foreach ($generals as $general) {
|
||||||
|
$itemList = $general->getItems();
|
||||||
|
$didLoseItem = false;
|
||||||
|
foreach ($itemList as $itemType => $item) {
|
||||||
|
if ($item->isBuyable()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$logger = $general->getLogger();
|
||||||
|
|
||||||
|
if ($rng->nextBool($this->lostProb)) {
|
||||||
|
$itemName = $item->getName();
|
||||||
|
$itemRawName = $item->getRawName();
|
||||||
|
$josaUl = JosaUtil::pick($itemRawName, '을');
|
||||||
|
$lostItems[$itemName] = 1;
|
||||||
|
$lostCnt++;
|
||||||
|
$general->setItem($itemType, 'None');
|
||||||
|
$didLoseItem = true;
|
||||||
|
$logger->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 잃었습니다.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($didLoseItem) {
|
||||||
|
$general->applyDB($db);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$logger = new ActionLogger(0, 0, $year, $month);
|
||||||
|
if($lostCnt == 0){
|
||||||
|
$logger->pushGlobalHistoryLog("<R><b>【망실】</b></>어떤 아이템도 잃지 않았습니다!");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$logger->pushGlobalHistoryLog("<R><b>【망실】</b></>총 <C>{$lostCnt}</>개의 아이템을 잃었습니다!");
|
||||||
|
}
|
||||||
|
$logger->flush();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user