From 055e5765aeb4439c67ff117cbdf37d352614918c Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 27 Jul 2023 16:25:49 +0000 Subject: [PATCH 01/19] refac, wip: GeneralLite --- hwe/sammo/General.php | 5 +- hwe/sammo/GeneralLite.php | 1368 +++++++++++++++++++++++++++++++++++++ 2 files changed, 1369 insertions(+), 4 deletions(-) create mode 100644 hwe/sammo/GeneralLite.php diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 698bc580..7c617a35 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -10,11 +10,8 @@ use sammo\Enums\InheritanceKey; use sammo\Enums\RankColumn; use sammo\WarUnitTrigger as WarUnitTrigger; -class General implements iAction +class General extends GeneralLite implements iAction { - use LazyVarUpdater; - - protected $raw = []; protected $rawCity = null; diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php new file mode 100644 index 00000000..15a58a5c --- /dev/null +++ b/hwe/sammo/GeneralLite.php @@ -0,0 +1,1368 @@ + */ + protected Map $rankVarRead; + /** @var Map */ + protected Map $rankVarIncrease; + /** @var Map */ + protected Map $rankVarSet; + + /** @var Map */ + protected ?Map $accessLogRead; + + /** @var \sammo\ActionLogger */ + protected $logger; + + protected $activatedSkill = []; + protected $logActivatedSkill = []; + protected $isFinished = false; + + /** @var ?iAction */ + protected $nationType = null; + /** @var ?iAction */ + protected $officerLevelObj = null; + /** @var ?iAction */ + protected $specialDomesticObj = null; + /** @var ?iAction */ + protected $specialWarObj = null; + /** @var ?iAction */ + protected $personalityObj = null; + /** @var ?iAction[] */ + protected $itemObjs = []; + /** @var ?iAction */ + protected $inheritBuffObj = null; + /** @var ?GameUnitDetail */ + protected $crewType = null; + + protected $lastTurn = null; + protected $resultTurn = null; + + const TURNTIME_FULL_MS = -1; + const TURNTIME_FULL = 0; + const TURNTIME_HMS = 1; + const TURNTIME_HM = 2; + + protected $calcCache = []; + + protected static $prohibitedDirectUpdateVars = [ + //Reason: iAction + 'leadership' => 1, + 'power' => 1, + 'intel' => 1, + 'nation' => 2, + 'officer_level' => 1, + //NOTE: officerLevelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남. + 'special' => 1, + 'special2' => 1, + 'personal' => 1, + 'horse' => 1, + 'weapon' => 1, + 'book' => 1, + 'item' => 1 + ]; + + + /** + * @param array $raw DB row값. + * @param null|Map $rawRank + * @param null|Map $rawAccessLog + * @param null|array $city DB city 테이블의 row값 + * @param int|null $year 게임 연도 + * @param int|null $month 게임 월 + * @param bool $fullConstruct iAction, 및 ActionLogger 초기화 여부, false인 경우 no, name, city, nation, officer_level 정도로 초기화 가능 + */ + public function __construct(array $raw, ?Map $rawRank, ?Map $rawAccessLog, ?array $city, ?array $nation, ?int $year, ?int $month, bool $fullConstruct = true) + { + //TODO: 밖에서 가져오도록 하면 버그 확률이 높아짐. 필요한 raw 값을 직접 구해야함. + + if ($nation === null) { + $nation = getNationStaticInfo($raw['nation']); + } + + $this->raw = $raw; + $this->rawCity = $city; + + $this->resultTurn = new LastTurn(); + if (key_exists('last_turn', $this->raw)) { + $this->lastTurn = LastTurn::fromJson($this->raw['last_turn']); + $this->resultTurn = $this->lastTurn->duplicate(); + } + + if ($year !== null && $month !== null) { + $this->initLogger($year, $month); + } + + if ($rawRank) { + $this->rankVarRead = $rawRank; + } else { + $this->rankVarRead = new Map(); + } + + $this->accessLogRead = $rawAccessLog; + + + $this->rankVarIncrease = new Map(); + $this->rankVarSet = new Map(); + + if (!$fullConstruct) { + return; + } + + $this->nationType = buildNationTypeClass($nation['type']); + $this->officerLevelObj = new TriggerOfficerLevel($this->raw, $nation['level']); + + $this->specialDomesticObj = buildGeneralSpecialDomesticClass($raw['special']); + $this->specialWarObj = buildGeneralSpecialWarClass($raw['special2']); + + $this->personalityObj = buildPersonalityClass($raw['personal']); + + $this->crewType = GameUnitConst::byID($raw['crewtype'] ?? GameUnitConst::DEFAULT_CREWTYPE); + + $this->itemObjs['horse'] = buildItemClass($raw['horse']); + $this->itemObjs['weapon'] = buildItemClass($raw['weapon']); + $this->itemObjs['book'] = buildItemClass($raw['book']); + $this->itemObjs['item'] = buildItemClass($raw['item']); + + if (key_exists('aux', $this->raw)) { + $rawInheritBuff = $this->getAuxVar('inheritBuff'); + if ($rawInheritBuff !== null) { + $this->inheritBuffObj = new TriggerInheritBuff($rawInheritBuff); + } + } + } + + function initLogger(int $year, int $month) + { + $this->logger = new ActionLogger( + $this->getVar('no'), + $this->getVar('nation'), + $year, + $month, + false + ); + } + + function getTurnTime(int $short = self::TURNTIME_FULL_MS) + { + return [ + self::TURNTIME_FULL_MS => function ($turntime) { + return $turntime; + }, + self::TURNTIME_FULL => function ($turntime) { + return substr($turntime, 0, 19); + }, + self::TURNTIME_HMS => function ($turntime) { + return substr($turntime, 11, 8); + }, + self::TURNTIME_HM => function ($turntime) { + return substr($turntime, 11, 5); + }, + ][$short]($this->getVar('turntime')); + } + + function setItem(string $itemKey = 'item', ?string $itemCode) + { + if ($itemCode === null) { + $this->deleteItem($itemKey); + return; + } + + $this->setVar($itemKey, $itemCode); + $this->itemObjs[$itemKey] = buildItemClass($itemCode); + } + + function deleteItem(string $itemKey = 'item') + { + $this->setVar($itemKey, 'None'); + $this->itemObjs[$itemKey] = new ActionItem\None(); + } + + function getItem(string $itemKey = 'item'): BaseItem + { + return $this->itemObjs[$itemKey]; + } + + function getNPCType(): int + { + return $this->raw['npc']; + } + + /** @return BaseItem[] */ + function getItems(): array + { + return $this->itemObjs; + } + + function getPersonality(): iAction + { + return $this->personalityObj; + } + + function getSpecialDomestic(): iAction + { + return $this->specialDomesticObj; + } + + function getSpecialWar(): iAction + { + return $this->specialWarObj; + } + + function getLastTurn(): LastTurn + { + return $this->lastTurn; + } + + function _setResultTurn(LastTurn $resultTurn) + { + $this->resultTurn = $resultTurn; + } + + function getResultTurn(): LastTurn + { + return $this->resultTurn; + } + + function clearActivatedSkill() + { + foreach ($this->activatedSkill as $skillName => $state) { + if (!$state) { + continue; + } + + if (!key_exists($skillName, $this->logActivatedSkill)) { + $this->logActivatedSkill[$skillName] = 1; + } else { + $this->logActivatedSkill[$skillName] += 1; + } + } + $this->activatedSkill = []; + } + + function getActivatedSkillLog(): array + { + return $this->logActivatedSkill; + } + + function hasActivatedSkill(string $skillName): bool + { + return $this->activatedSkill[$skillName] ?? false; + } + + function activateSkill(...$skillNames) + { + foreach ($skillNames as $skillName) { + $this->activatedSkill[$skillName] = true; + } + } + + function deactivateSkill(...$skillNames) + { + foreach ($skillNames as $skillName) { + $this->activatedSkill[$skillName] = false; + } + } + + function getName(): string + { + return $this->raw['name']; + } + + function getInfo(): string + { + //iAction용 info로는 적절하지 않음 + return ''; + } + + function getID(): int + { + return $this->raw['no']; + } + + function getRawCity(): ?array + { + return $this->rawCity; + } + + function setRawCity(?array $city) + { + $this->rawCity = $city; + } + + function getCityID(): int + { + return $this->raw['city']; + } + + function getNationID(): int + { + return $this->raw['nation']; + } + + function getStaticNation(): array + { + return getNationStaticInfo($this->raw['nation']); + } + + function getLogger(): ?ActionLogger + { + return $this->logger; + } + + public function getNationTypeObj(): iAction + { + return $this->nationType; + } + + public function getOfficerLevelObj(): iAction + { + return $this->officerLevelObj; + } + + function getCrewTypeObj(): GameUnitDetail + { + if ($this->crewType === null) { + throw new \InvalidArgumentException('Invalid CrewType:' . $this->getVar('crewtype')); + } + return $this->crewType; + } + + function calcRecentWarTurn(int $turnTerm): int + { + $cacheKey = "recent_war_turn_{$turnTerm}"; + if (key_exists($cacheKey, $this->calcCache)) { + return $this->calcCache[$cacheKey]; + } + if (!$this->getVar('recent_war')) { + $result = 12 * 1000; + $this->calcCache[$cacheKey] = $result; + return $result; + } + $recwar = new \DateTimeImmutable($this->getVar('recent_war')); + $turnNow = new \DateTimeImmutable($this->getVar('turntime')); + $secDiff = TimeUtil::DateIntervalToSeconds($recwar->diff($turnNow)); + + if ($secDiff <= 0) { + $this->calcCache[$cacheKey] = 0; + return 0; + } + + $result = intdiv(Util::toInt($secDiff), 60 * $turnTerm); + $this->calcCache[$cacheKey] = $result; + return $result; + } + + function getReservedTurn(int $turnIdx, array $env): GeneralCommand + { + $db = DB::db(); + $rawCmd = $db->queryFirstRow('SELECT * FROM general_turn WHERE general_id = %i AND turn_idx = %i', $this->getID(), $turnIdx); + if (!$rawCmd) { + return buildGeneralCommandClass(null, $this, $env); + } + return buildGeneralCommandClass($rawCmd['action'], $this, $env, Json::decode($rawCmd['arg'] ?? null)); + } + + /** + * @param General[] $generalList + * @param int $turnIdxFrom [$turnIdxFrom, $turnIdxTo) + * @param int $turnIdxTo [$turnIdxFrom, $turnIdxTo) + * @param array $env + * @return GeneralCommand[] + */ + public function getReservedTurnList(int $turnIdxFrom, int $turnIdxTo, array $env) + { + if ($turnIdxFrom < 0 || $turnIdxFrom >= GameConst::$maxTurn) { + throw new \OutOfRangeException('$turnIdxFrom 범위 초과' . $turnIdxFrom); + } + + if ($turnIdxTo <= $turnIdxFrom || GameConst::$maxTurn < $turnIdxTo) { + throw new \OutOfRangeException('$turnIdxTo 범위 초과' . $turnIdxTo); + } + + $db = DB::db(); + + $generalID = $this->getID(); + + $result = []; + + $rawCmds = $db->queryFirstRow('SELECT * FROM general_turn WHERE general_id = %i AND %i <= turn_idx AND turn_idx < %i ORDER BY turn_idx ASC', $generalID, $turnIdxFrom, $turnIdxTo); + + if (!$rawCmds) { + foreach (Util::range($turnIdxFrom, $turnIdxTo) as $turnIdx) { + $result[$turnIdx] = buildGeneralCommandClass(null, $this, $env); + } + return $result; + } + + foreach ($rawCmds as $turnIdx => $rawCmd) { + $result[$turnIdx] = buildGeneralCommandClass($rawCmd['action'], $this, $env, Json::decode($rawCmd['arg'] ?? null)); + } + + return $result; + } + + /** + * 장수의 스탯을 계산해옴 + * + * @param string $statName 스탯값, leadership, strength, intel 가능 + * @param bool $withInjury 부상값 사용 여부 + * @param bool $withIActionObj 아이템, 특성, 성격 등 보정치 적용 여부 + * @param bool $withStatAdjust 능력치간 보정 사용 여부 + * @param bool $useFloor 내림 사용 여부, false시 float 값을 반환할 수도 있음 + * + * @return float 계산된 능력치 + */ + + protected function getStatValue(string $statName, $withInjury = true, $withIActionObj = true, $withStatAdjust = true, $useFloor = true): float + { + $cKey = "{$statName}_{$withInjury}_{$withIActionObj}_{$withStatAdjust}"; + if (key_exists($cKey, $this->calcCache)) { + $statValue = $this->calcCache[$cKey]; + if ($useFloor) { + return Util::toInt($statValue); + } + return $statValue; + } + + $statValue = $this->getVar($statName); + + if ($withInjury) { + $statValue *= (100 - $this->getVar('injury')) / 100; + } + + if ($withStatAdjust) { + if ($statName === 'strength') { + $statValue += Util::round($this->getStatValue('intel', $withInjury, $withIActionObj, false, false) / 4); + } else if ($statName === 'intel') { + $statValue += Util::round($this->getStatValue('strength', $withInjury, $withIActionObj, false, false) / 4); + } + } + + $statValue = Util::clamp($statValue, 0, GameConst::$maxLevel); + + if ($withIActionObj) { + foreach ([ + $this->nationType, + $this->officerLevelObj, + $this->specialDomesticObj, + $this->specialWarObj, + $this->personalityObj, + $this->inheritBuffObj, + ] as $actionObj) { + if ($actionObj !== null) { + $statValue = $actionObj->onCalcStat($this, $statName, $statValue); + } + } + + foreach ($this->itemObjs as $actionObj) { + if ($actionObj !== null) { + $statValue = $actionObj->onCalcStat($this, $statName, $statValue); + } + } + } + + $this->calcCache[$cKey] = $statValue; + + $statValue = Util::clamp($statValue, 0, GameConst::$maxLevel); + + if ($useFloor) { + return Util::toInt($statValue); + } + + return $statValue; + } + + function getDex(GameUnitDetail $crewType) + { + $armType = $crewType->armType; + + if ($armType == GameUnitConst::T_CASTLE) { + $armType = GameUnitConst::T_SIEGE; + } + + return $this->getVar("dex{$armType}"); + } + + function addDex(GameUnitDetail $crewType, float $exp, bool $affectTrainAtmos = false) + { + $armType = $crewType->armType; + + if ($armType == GameUnitConst::T_CASTLE) { + $armType = GameUnitConst::T_SIEGE; + } + + if ($armType < 0) { + return; + } + + if ($armType == GameUnitConst::T_WIZARD) { + $exp *= 0.9; + } else if ($armType == GameUnitConst::T_SIEGE) { + $exp *= 0.9; + } + + if ($affectTrainAtmos) { + $exp *= ($this->getVar('train') + $this->getVar('atmos')) / 200; + } + + $dexType = "dex{$armType}"; + $exp = $this->onCalcStat($this, 'addDex', $exp, ['armType' => $armType]); + + $this->increaseVar($dexType, $exp); + } + + function addExperience(float $experience, bool $affectTrigger = true) + { + if ($affectTrigger) { + $experience = $this->onCalcStat($this, 'experience', $experience); + } + + $this->increaseVar('experience', $experience); + $nextExpLevel = getExpLevel($this->getVar('experience')); + $comp = $nextExpLevel <=> $this->getVar('explevel'); + if ($comp === 0) { + return; + } + + $this->updateVar('explevel', $nextExpLevel); + + $josaRo = JosaUtil::pick($nextExpLevel, '로'); + if ($comp > 0) { + $this->getLogger()->pushGeneralActionLog("Lv {$nextExpLevel}{$josaRo} 레벨업!", ActionLogger::PLAIN); + } else { + $this->getLogger()->pushGeneralActionLog("Lv {$nextExpLevel}{$josaRo} 레벨다운!", ActionLogger::PLAIN); + } + } + + function addDedication(float $dedication, bool $affectTrigger = true) + { + if ($affectTrigger) { + $dedication = $this->onCalcStat($this, 'dedication', $dedication); + } + + $this->increaseVar('dedication', $dedication); + $nextDedLevel = getDedLevel($this->getVar('dedication')); + $comp = $nextDedLevel <=> $this->getVar('dedlevel'); + if ($comp === 0) { + return; + } + + $this->updateVar('dedlevel', $nextDedLevel); + + $dedLevelText = getDedLevelText($nextDedLevel); + $billText = number_format(getBillByLevel($nextDedLevel)); + $josaRoDed = JosaUtil::pick($dedLevelText, '로'); + $josaRoBill = JosaUtil::pick($billText, '로'); + if ($comp > 0) { + $this->getLogger()->pushGeneralActionLog("{$dedLevelText}{$josaRoDed} 승급하여 봉록이 {$billText}{$josaRoBill} 상승했습니다!", ActionLogger::PLAIN); + } else { + $this->getLogger()->pushGeneralActionLog("{$dedLevelText}{$josaRoDed} 강등되어 봉록이 {$billText}{$josaRoBill} 하락했습니다!", ActionLogger::PLAIN); + } + } + + function updateVar(string $key, $value) + { + if (($this->raw[$key] ?? null) === $value) { + return; + } + if (!key_exists($key, $this->updatedVar)) { + $this->updatedVar[$key] = true; + } + $this->raw[$key] = $value; + $this->calcCache = []; + } + + /** + * @param \MeekroDB $db + */ + function kill($db, bool $sendDyingMessage = true, ?string $dyingMessage = null) + { + $generalID = $this->getID(); + $logger = $this->getLogger(); + + $generalName = $this->getName(); + + //유산포인트 관련 항목 환불 + if ($this->getNPCType() < 2) { + + $refundPoint = 0; + $userID = $this->getVar('owner'); + $userLogger = new UserLogger($userID); + if ($this->getAuxVar('inheritRandomUnique')) { + $this->setAuxVar('inheritRandomUnique', null); + $userLogger->push(sprintf("사망으로 랜덤 유니크 구입 %d 포인트 반환", GameConst::$inheritItemRandomPoint), "inheritPoint"); + $refundPoint += GameConst::$inheritItemRandomPoint; + } + + //TODO: 경매 최우선 입찰자인경우 반환 + + if ($this->getAuxVar('inheritSpecificSpecialWar')) { + $this->setAuxVar('inheritSpecificSpecialWar', null); + $userLogger->push(sprintf("사망으로 전투 특기 지정 %d 포인트 반환", GameConst::$inheritSpecificSpecialPoint), "inheritPoint"); + $refundPoint += GameConst::$inheritSpecificSpecialPoint; + } + + if ($refundPoint > 0) { + $this->increaseInheritancePoint(InheritanceKey::previous, $refundPoint); + $this->increaseRankVar(RankColumn::inherit_point_spent_dynamic, -$refundPoint); + } + + $inheritPointManager = InheritancePointManager::getInstance(); + $inheritPointManager->mergeTotalInheritancePoint($this); + $inheritPointManager->applyInheritanceUser($this->getVar('owner')); + } + + + // 군주였으면 유지 이음 + $officerLevel = $this->getVar('officer_level'); + if ($officerLevel == 12) { + nextRuler($this); + $this->setVar('officer_level', 1); + } + + // 부대 처리 + $troopLeaderID = $this->getVar('troop'); + if ($troopLeaderID == $generalID) { + //부대장일 경우 + // 모두 탈퇴 + $db->update('general', [ + 'troop' => 0 + ], 'troop=%i', $troopLeaderID); + // 부대 삭제 + $db->delete('troop', 'troop_leader=%i', $troopLeaderID); + } + + + if ($sendDyingMessage) { + if ($dyingMessage) { + $logger->pushGlobalActionLog($dyingMessage); + } else { + $dyingMessageObj = new TextDecoration\DyingMessage($this); + $logger->pushGlobalActionLog($dyingMessageObj->getText()); + } + $logger->flush(); + } + + $db->update('select_pool', [ + 'general_id' => null, + 'owner' => null, + 'reserved_until' => null, + ], 'general_id=%i', $generalID); + + storeOldGeneral($generalID, $logger->getYear(), $logger->getMonth()); + + $db->delete('general', 'no=%i', $generalID); + $db->delete('general_turn', 'general_id=%i', $generalID); + $db->delete('rank_data', 'general_id=%i', $generalID); + $db->delete('general_access_log', 'general_id=%i', $generalID); + $this->updatedVar = []; + + $db->update('nation', [ + 'gennum' => $db->sqleval('gennum - 1') + ], 'nation=%i', $this->getVar('nation')); + } + + function rebirth() + { + $logger = $this->getLogger(); + + $generalName = $this->getName(); + + $inheritPointManager = InheritancePointManager::getInstance(); + + $ownerID = $this->getVar('owner'); + if ($ownerID) { + $inheritPointManager->mergeTotalInheritancePoint($this, true); + $inheritPointManager->applyInheritanceUser($ownerID, true); + } + + $this->multiplyVarWithLimit('leadership', 0.85, 10); + $this->multiplyVarWithLimit('strength', 0.85, 10); + $this->multiplyVarWithLimit('intel', 0.85, 10); + $this->setVar('injury', 0); + $this->multiplyVar('experience', 0.5); + $this->multiplyVar('dedication', 0.5); + $this->setVar('age', 20); + $this->setVar('specage', 0); + $this->setVar('specage2', 0); + $this->multiplyVar('dex1', 0.5); + $this->multiplyVar('dex2', 0.5); + $this->multiplyVar('dex3', 0.5); + $this->multiplyVar('dex4', 0.5); + $this->multiplyVar('dex5', 0.5); + + foreach (RankColumn::cases() as $rankKey) { + $this->setRankVar($rankKey, 0); + } + + $josaYi = JosaUtil::pick($generalName, '이'); + $logger->pushGlobalActionLog("{$generalName}{$josaYi} 은퇴하고 그 자손이 유지를 이어받았습니다."); + $logger->pushGeneralActionLog('나이가 들어 은퇴하고 자손에게 자리를 물려줍니다.', ActionLogger::PLAIN); + $logger->pushGeneralHistoryLog('나이가 들어 은퇴하고, 자손에게 관직을 물려줌'); + } + + function increaseRankVar(RankColumn $key, int $value) + { + if ($this->rankVarSet->hasKey($key)) { + $this->rankVarSet[$key] += $value; + return; + } + + if ($this->rankVarRead->hasKey($key)) { + $this->rankVarSet[$key] = $this->rankVarRead[$key] + $value; + $this->rankVarRead->remove($key); + return; + } + + if ($this->rankVarIncrease->hasKey($key)) { + $this->rankVarIncrease[$key] += $value; + return; + } + + $this->rankVarIncrease[$key] = $value; + } + + function setRankVar(RankColumn $key, int $value) + { + if ($this->rankVarRead->hasKey($key)) { + $this->rankVarRead->remove($key); + } else if ($this->rankVarIncrease->hasKey($key)) { + $this->rankVarIncrease->remove($key); + } + $this->rankVarSet[$key] = $value; + } + + function getRankVar(RankColumn $key, $defaultValue = null): int + { + if ($this->rankVarSet->hasKey($key)) { + return $this->rankVarSet[$key]; + } + + if (!$this->rankVarRead->hasKey($key)) { + if ($defaultValue === null) { + throw new \RuntimeException('인자가 없음 : ' . $key->value); + } + return $defaultValue; + } + + return $this->rankVarRead[$key]; + } + + function getAccessLogVar(GeneralAccessLogColumn $key, $defaultValue = null): int | string | null + { + if (!$this->accessLogRead) { + return $defaultValue; + } + + if (!$this->accessLogRead->hasKey($key)) { + return $defaultValue; + } + + return $this->accessLogRead[$key]; + } + + /** + * @param \MeekroDB $db + */ + function applyDB($db): bool + { + if ($this->lastTurn && $this->getLastTurn() != $this->getResultTurn()) { + $this->setVar('last_turn', $this->getResultTurn()->toJson()); + } + $updateVals = $this->getUpdatedValues(); + + + $generalID = $this->getID(); + $result = false; + + if ($updateVals) { + $db->update('general', $updateVals, 'no=%i', $generalID); + $result = $result || $db->affectedRows() > 0; + if (key_exists('nation', $updateVals)) { + $db->update('rank_data', [ + 'nation_id' => $updateVals['nation'] + ], 'general_id = %i', $generalID); + $result = true; + } + $this->flushUpdateValues(); + } + + if ($this->rankVarIncrease->count()) { + foreach ($this->rankVarIncrease as $rankKey => $rankVal) { + $db->update('rank_data', [ + 'value' => $db->sqleval('value + %i', $rankVal) + ], 'general_id = %i AND type = %s', $generalID, $rankKey->value); + } + $result = true; + } + + if ($this->rankVarSet->count()) { + foreach ($this->rankVarSet as $rankKey => $rankVal) { + $db->update('rank_data', [ + 'value' => $rankVal + ], 'general_id = %i AND type = %s', $generalID, $rankKey->value); + $this->rankVarRead[$rankKey] = $rankVal; + } + $result = true; + } + + $this->rankVarIncrease = new Map(); + $this->rankVarSet = new Map(); + + $this->getLogger()->flush(); + return $result; + } + + function checkStatChange(): bool + { + $logger = $this->getLogger(); + $limit = GameConst::$upgradeLimit; + + $table = [ + ['통솔', 'leadership'], + ['무력', 'strength'], + ['지력', 'intel'], + ]; + + $result = false; + + foreach ($table as [$statNickName, $statName]) { + $statExpName = $statName . '_exp'; + + if ($this->getVar($statExpName) < 0) { + $logger->pushGeneralActionLog("{$statNickName}이 1 떨어졌습니다!", ActionLogger::PLAIN); + $this->increaseVar($statExpName, $limit); + $this->increaseVar($statName, -1); + $result = true; + } else if ($this->getVar($statExpName) >= $limit) { + if ($this->getVar($statName) < GameConst::$maxLevel) { + $logger->pushGeneralActionLog("{$statNickName}이 1 올랐습니다!", ActionLogger::PLAIN); + $this->increaseVar($statName, 1); + } + $this->increaseVar($statExpName, -$limit); + $result = true; + } + } + + return $result; + } + + protected function getActionList(): array + { + return array_merge([ + $this->nationType, + $this->officerLevelObj, + $this->specialDomesticObj, + $this->specialWarObj, + $this->personalityObj, + $this->crewType, + $this->inheritBuffObj, + ], $this->itemObjs); + } + + public function getPreTurnExecuteTriggerList(General $general): ?GeneralTriggerCaller + { + $caller = new GeneralTriggerCaller(); + foreach ($this->getActionList() as $iObj) { + + if (!$iObj) { + continue; + } + /** @var iAction $iObj */ + $caller->merge($iObj->getPreTurnExecuteTriggerList($general)); + } + + return $caller; + } + public function onCalcDomestic(string $turnType, string $varType, float $value, $aux = null): float + { + foreach ($this->getActionList() as $iObj) { + if (!$iObj) { + continue; + } + /** @var iAction $iObj */ + $value = $iObj->onCalcDomestic($turnType, $varType, $value, $aux); + } + return $value; + } + + public function onCalcStat(General $general, string $statName, $value, $aux = null) + { + //xxx: $general? + foreach ($this->getActionList() as $iObj) { + if (!$iObj) { + continue; + } + /** @var iAction $iObj */ + $value = $iObj->onCalcStat($this, $statName, $value, $aux); + } + return $value; + } + + public function onCalcOpposeStat(General $general, string $statName, $value, $aux = null) + { + //xxx: $general? + foreach ($this->getActionList() as $iObj) { + if (!$iObj) { + continue; + } + /** @var iAction $iObj */ + $value = $iObj->onCalcOpposeStat($this, $statName, $value, $aux); + } + return $value; + } + + public function onCalcStrategic(string $turnType, string $varType, $value) + { + foreach ($this->getActionList() as $iObj) { + if (!$iObj) { + continue; + } + /** @var iAction $iObj */ + $value = $iObj->onCalcStrategic($turnType, $varType, $value); + } + return $value; + } + + public function onCalcNationalIncome(string $type, $amount) + { + foreach ($this->getActionList() as $iObj) { + if (!$iObj) { + continue; + } + /** @var iAction $iObj */ + $amount = $iObj->onCalcNationalIncome($type, $amount); + } + return $amount; + } + + public function onArbitraryAction(General $general, RandUtil $rng, string $actionType, ?string $phase = null, $aux = null): null|array + { + foreach ($this->getActionList() as $iObj) { + if (!$iObj) { + continue; + } + /** @var iAction $iObj */ + $aux = $iObj->onArbitraryAction($general, $rng, $actionType, $phase, $aux); + } + return $aux; + } + + public function getWarPowerMultiplier(WarUnit $unit): array + { + //xxx:$unit + $att = 1; + $def = 1; + foreach ($this->getActionList() as $iObj) { + if (!$iObj) { + continue; + } + /** @var iAction $iObj */ + [$attV, $defV] = $iObj->getWarPowerMultiplier($unit); + $att *= $attV; + $def *= $defV; + } + return [$att, $def]; + } + public function getBattleInitSkillTriggerList(WarUnit $unit): ?WarUnitTriggerCaller + { + $caller = new WarUnitTriggerCaller(); + foreach ($this->getActionList() as $iObj) { + if (!$iObj) { + continue; + } + /** @var iAction $iObj */ + $caller->merge($iObj->getBattleInitSkillTriggerList($unit)); + } + + return $caller; + } + public function getBattlePhaseSkillTriggerList(WarUnit $unit): ?WarUnitTriggerCaller + { + $caller = new WarUnitTriggerCaller( + new WarUnitTrigger\che_필살시도($unit), + new WarUnitTrigger\che_필살발동($unit), + new WarUnitTrigger\che_회피시도($unit), + new WarUnitTrigger\che_회피발동($unit), + new WarUnitTrigger\che_계략시도($unit), + new WarUnitTrigger\che_계략발동($unit), + new WarUnitTrigger\che_계략실패($unit) + ); + foreach ($this->getActionList() as $iObj) { + if (!$iObj) { + continue; + } + /** @var iAction $iObj */ + $caller->merge($iObj->getBattlePhaseSkillTriggerList($unit)); + } + + return $caller; + } + + static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array + { + $minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city']; + $defaultEventColumn = [ + 'no', 'name', 'npc', 'owner', 'city', 'nation', 'officer_level', 'officer_city', + 'special', 'special2', 'personal', + 'horse', 'weapon', 'book', 'item', 'last_turn', 'aux', 'turntime', + ]; + $fullColumn = [ + 'no', 'name', 'owner', 'owner_name', 'picture', 'imgsvr', 'nation', 'city', 'troop', 'injury', 'affinity', + 'leadership', 'leadership_exp', 'strength', 'strength_exp', 'intel', 'intel_exp', 'weapon', 'book', 'horse', 'item', + 'experience', 'dedication', 'officer_level', 'officer_city', 'gold', 'rice', 'crew', 'crewtype', 'train', 'atmos', 'turntime', + 'makelimit', 'killturn', 'block', 'dedlevel', 'explevel', 'age', 'startage', 'belong', + 'personal', 'special', 'special2', 'defence_train', 'tnmt', 'npc', 'npc_org', 'deadyear', 'npcmsg', + 'dex1', 'dex2', 'dex3', 'dex4', 'dex5', 'betray', + 'recent_war', 'last_turn', 'myset', + 'specage', 'specage2', 'aux', 'permission', 'penalty', + ]; + $fullAcessLogColumn = [ + GeneralAccessLogColumn::refreshScore, + GeneralAccessLogColumn::refreshScoreTotal, + ]; + + if ($reqColumns === null) { + switch ($queryMode) { + case GeneralQueryMode::Core: + return [$minimumColumn, [], []]; + case GeneralQueryMode::Lite: + return [$defaultEventColumn, [], []]; + case GeneralQueryMode::FullWithoutIAction: + case GeneralQueryMode::Full: + return [$fullColumn, RankColumn::cases(), []]; + case GeneralQueryMode::FullWithAccessLog: + return [$fullColumn, RankColumn::cases(), $fullAcessLogColumn]; + } + } + + /** @var RankColumn[] */ + $rankColumn = []; + $subColumn = []; + $accessLogColumn = []; + foreach ($reqColumns as $column) { + if ($column instanceof RankColumn) { + $rankColumn[] = $column; + continue; + } + if ($column instanceof GeneralAccessLogColumn) { + $accessLogColumn[] = $column; + continue; + } + + + $enumKey = RankColumn::tryFrom($column); + if ($enumKey !== null) { + $rankColumn[] = $enumKey; + continue; + } + $enumKey = GeneralAccessLogColumn::tryFrom($column); + if ($enumKey !== null) { + $accessLogColumn[] = $enumKey; + continue; + } + $subColumn[] = $column; + } + + switch ($queryMode) { + case GeneralQueryMode::Core: + return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralQueryMode::Lite: + return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralQueryMode::FullWithoutIAction: + case GeneralQueryMode::Full: + return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralQueryMode::FullWithAccessLog: + return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, array_unique(array_merge($fullAcessLogColumn, $accessLogColumn))]; + default: + throw new \RuntimeException('invalid query mode'); + } + } + + /** + * @param ?int[] $generalIDList + * @param null|array $column + * @param GeneralQueryMode $queryMode + * @return \sammo\General[] + * @throws MustNotBeReachedException + */ + static public function createGeneralObjListFromDB(?array $generalIDList, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array + { + if ($generalIDList === []) { + return []; + } + + $db = DB::db(); + if ($queryMode->value > 0) { + $gameStor = KVStorage::getStorage($db, 'game_env'); + [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); + } else { + $year = null; + $month = null; + } + + /** + * @var string[] $column + * @var RankColumn[] $rankColumn + * @var GeneralAccessLogColumn[] $accessLogColumn + */ + [$column, $rankColumn, $accessLogColumn] = static::mergeQueryColumn($column, $queryMode); + + if ($generalIDList === null) { + $rawGenerals = Util::convertArrayToDict( + $db->query('SELECT %l FROM general WHERE 1', Util::formatListOfBackticks($column)), + 'no' + ); + + $generalIDList = array_keys($rawGenerals); + } else { + $rawGenerals = Util::convertArrayToDict( + $db->query('SELECT %l FROM general WHERE no IN %li', Util::formatListOfBackticks($column), $generalIDList), + 'no' + ); + } + + + /** @var Map> */ + $rawRanks = new Map(); + if ($rankColumn) { + $rawValue = $db->queryAllLists( + 'SELECT `general_id`, `type`, `value` FROM rank_data WHERE general_id IN %li AND `type` IN %ls', + $generalIDList, + array_map(fn (\BackedEnum $e) => $e->value, $rankColumn) + ); + foreach ($rawValue as [$generalID, $rawRankType, $rankValue]) { + if (!$rawRanks->hasKey($generalID)) { + $rawRanks[$generalID] = new Map(); + } + + $rankType = RankColumn::from($rawRankType); + $rawRanks[$generalID][$rankType] = $rankValue; + } + } + + $rawAccessLogs = new Map(); + if ($accessLogColumn) { + $rawValue = $db->query( + 'SELECT `general_id`, %l FROM general_access_log WHERE general_id IN %li', + Util::formatListOfBackticks($accessLogColumn), + $generalIDList + ); + foreach ($rawValue as $rawLog) { + $generalID = $rawLog['general_id']; + $logValue = new Map(); + foreach ($rawLog as $key => $value) { + $logValue[GeneralAccessLogColumn::from($key)] = $value; + } + $rawAccessLogs[$generalID] = $logValue; + } + } + + $result = []; + foreach ($generalIDList as $generalID) { + if (!key_exists($generalID, $rawGenerals)) { + $result[$generalID] = new DummyGeneral($queryMode->value > 0); + continue; + } + if ($rawRanks->hasKey($generalID) && $rawRanks[$generalID]->count() !== count($rankColumn)) { + throw new \RuntimeException('column의 수가 일치하지 않음 : ' . $generalID); + } + $result[$generalID] = new static($rawGenerals[$generalID], $rawRanks[$generalID] ?? null, $rawAccessLogs[$generalID] ?? null, null, null, $year, $month, $queryMode->value >= GeneralQueryMode::Full->value); + } + + return $result; + } + + static public function createGeneralObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): self + { + $db = DB::db(); + if ($queryMode->value > 0) { + $gameStor = KVStorage::getStorage($db, 'game_env'); + [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); + } else { + $year = null; + $month = null; + } + + /** + * @var string[] $column + * @var RankColumn[] $rankColumn + * @var GeneralAccessLogCoumn[] $accessLogColumn + */ + [$column, $rankColumn, $accessLogColumn] = static::mergeQueryColumn($column, $queryMode); + + /** @var Map|null */ + $rawAccessLog = null; + + if (!$accessLogColumn) { + $rawGeneral = $db->queryFirstRow('SELECT %l FROM general WHERE no = %i', Util::formatListOfBackticks($column), $generalID); + } else { + $rawGeneral = $db->queryFirstRow( + 'SELECT %l, %l FROM `general` LEFT JOIN general_access_log + ON general.no = general_access_log.general_id WHERE no = %i', + Util::formatListOfBackticks($column), + Util::formatListOfBackticks($accessLogColumn), + $generalID + ); + + $rawAccessLog = new Map(); + foreach ($accessLogColumn as $accessLogKey) { + if (!key_exists($accessLogKey->value, $rawGeneral)) { + continue; + } + $rawAccessLog[$accessLogKey] = $rawGeneral[$accessLogKey->value]; + unset($rawGeneral[$accessLogKey->value]); + } + if ($rawAccessLog->count() === 0) { + $rawAccessLog = null; + } + } + + if (!$rawGeneral) { + return new DummyGeneral($queryMode->value > 0); + } + + $rawRankValues = new Map(); + if ($rankColumn) { + $rawValue = $db->queryAllLists( + 'SELECT `type`, `value` FROM rank_data WHERE general_id = %i AND `type` IN %ls', + $generalID, + array_map(fn (\BackedEnum $e) => $e->value, $rankColumn) + ); + foreach ($rawValue as [$rawRankType, $rankValue]) { + $rankType = RankColumn::tryFrom($rawRankType); + $rawRankValues->put($rankType, $rankValue); + } + } + + + $general = new static($rawGeneral, $rawRankValues, $rawAccessLog, null, null, $year, $month, $queryMode->value >= GeneralQueryMode::Full->value); + + return $general; + } + + /** + * @param General[] $generalList + * @param int $turnIdx + * @param array $env + * @return GeneralCommand[] + */ + static public function getReservedTurnByGeneralList(array $generalList, int $turnIdx, array $env) + { + if (!$generalList) { + return []; + } + + $generalIDList = array_map(function (General $general) { + return $general->getID(); + }, $generalList); + + $db = DB::db(); + $result = []; + $rawCmds = Util::convertArrayToDict($db->query('SELECT * FROM general_turn WHERE general_id IN %li AND turn_idx = %i', $generalIDList, $turnIdx), 'general_id'); + foreach ($generalList as $general) { + $generalID = $general->getID(); + if (!key_exists($generalID, $rawCmds)) { + $result[$generalID] = buildGeneralCommandClass(null, $general, $env); + continue; + } + $rawCmd = $rawCmds[$generalID]; + $result[$generalID] = buildGeneralCommandClass($rawCmd['action'], $general, $env, Json::decode($rawCmd['arg'])); + } + return $result; + } + + /** + * @param General[] $generalList + * @param int $turnIdxFrom [$turnIdxFrom, $turnIdxTo) + * @param int $turnIdxTo [$turnIdxFrom, $turnIdxTo) + * @param array $env + * @return GeneralCommand[][] + */ + static public function getReservedTurnListByGeneralList(array $generalList, int $turnIdxFrom, int $turnIdxTo, array $env) + { + //XXX: static인데 return값이 General이 아니라고?? GeneralCommandHelper같은게 있어야하지 않을까? + if (!$generalList) { + return []; + } + + if ($turnIdxFrom < 0 || $turnIdxFrom >= GameConst::$maxTurn) { + throw new \OutOfRangeException('$turnIdxFrom 범위 초과' . $turnIdxFrom); + } + + if ($turnIdxTo <= $turnIdxFrom || GameConst::$maxTurn < $turnIdxTo) { + throw new \OutOfRangeException('$turnIdxTo 범위 초과' . $turnIdxTo); + } + + $generalIDList = array_map(function (General $general) { + return $general->getID(); + }, $generalList); + + $db = DB::db(); + + $rawCmds = $db->queryFirstRow('SELECT * FROM general_turn WHERE general_id IN %i AND %i <= turn_idx AND turn_idx < %i ORDER BY general_id ASC, turn_idx ASC', $generalIDList, $turnIdxFrom, $turnIdxTo); + $orderedRawCmds = []; + foreach ($rawCmds as $rawCmd) { + $generalID = $rawCmd['general_id']; + $turnIdx = $rawCmd['turn_idx']; + if (!key_exists($generalID, $orderedRawCmds)) { + $orderedRawCmds[$generalID] = []; + } + $orderedRawCmds[$generalID][$turnIdx] = $rawCmd; + } + + $result = []; + foreach ($generalList as $general) { + $generalID = $general->getID(); + $result[$generalID] = []; + if (!key_exists($generalID, $orderedRawCmds)) { + foreach (Util::range($turnIdxFrom, $turnIdxTo) as $turnIdx) { + $result[$generalID][$turnIdx] = buildGeneralCommandClass(null, $general, $env); + } + continue; + } + foreach ($orderedRawCmds[$generalID] as $turnIdx => $rawCmd) { + $result[$generalID][$turnIdx] = buildGeneralCommandClass($rawCmd['action'], $general, $env, Json::decode($rawCmd['arg'])); + } + } + return $result; + } + + public function getInheritancePoint(InheritanceKey $key, &$aux = null, bool $forceCalc = false): int|float|null + { + return InheritancePointManager::getInstance()->getInheritancePoint($this, $key, $aux, $forceCalc); + } + + public function setInheritancePoint(InheritanceKey $key, $value, $aux = null) + { + return InheritancePointManager::getInstance()->setInheritancePoint($this, $key, $value, $aux); + } + + public function increaseInheritancePoint(InheritanceKey $key, $value, $aux = null) + { + return InheritancePointManager::getInstance()->increaseInheritancePoint($this, $key, $value, $aux); + } + + public function mergeTotalInheritancePoint(bool $isRebirth = false) + { + InheritancePointManager::getInstance()->mergeTotalInheritancePoint($this, $isRebirth); + } +} -- 2.54.0 From d72c3e4c4117856522956682dbe297d44baec2c6 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 27 Jul 2023 16:51:33 +0000 Subject: [PATCH 02/19] =?UTF-8?q?refac,=20wip:=20GeneralLite,=20General=20?= =?UTF-8?q?=EC=9D=B4=EC=9B=90=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/General.php | 234 +-------- hwe/sammo/GeneralLite.php | 1007 +------------------------------------ 2 files changed, 40 insertions(+), 1201 deletions(-) diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 7c617a35..ce9b2144 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -52,31 +52,8 @@ class General extends GeneralLite implements iAction protected $lastTurn = null; protected $resultTurn = null; - const TURNTIME_FULL_MS = -1; - const TURNTIME_FULL = 0; - const TURNTIME_HMS = 1; - const TURNTIME_HM = 2; - protected $calcCache = []; - protected static $prohibitedDirectUpdateVars = [ - //Reason: iAction - 'leadership' => 1, - 'power' => 1, - 'intel' => 1, - 'nation' => 2, - 'officer_level' => 1, - //NOTE: officerLevelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남. - 'special' => 1, - 'special2' => 1, - 'personal' => 1, - 'horse' => 1, - 'weapon' => 1, - 'book' => 1, - 'item' => 1 - ]; - - /** * @param array $raw DB row값. * @param null|Map $rawRank @@ -84,9 +61,8 @@ class General extends GeneralLite implements iAction * @param null|array $city DB city 테이블의 row값 * @param int|null $year 게임 연도 * @param int|null $month 게임 월 - * @param bool $fullConstruct iAction, 및 ActionLogger 초기화 여부, false인 경우 no, name, city, nation, officer_level 정도로 초기화 가능 */ - public function __construct(array $raw, ?Map $rawRank, ?Map $rawAccessLog, ?array $city, ?array $nation, ?int $year, ?int $month, bool $fullConstruct = true) + public function __construct(array $raw, ?Map $rawRank, ?Map $rawAccessLog, ?array $city, ?array $nation, int $year, int $month) { //TODO: 밖에서 가져오도록 하면 버그 확률이 높아짐. 필요한 raw 값을 직접 구해야함. @@ -103,9 +79,7 @@ class General extends GeneralLite implements iAction $this->resultTurn = $this->lastTurn->duplicate(); } - if ($year !== null && $month !== null) { - $this->initLogger($year, $month); - } + $this->initLogger($year, $month); if ($rawRank) { $this->rankVarRead = $rawRank; @@ -119,10 +93,6 @@ class General extends GeneralLite implements iAction $this->rankVarIncrease = new Map(); $this->rankVarSet = new Map(); - if (!$fullConstruct) { - return; - } - $this->nationType = buildNationTypeClass($nation['type']); $this->officerLevelObj = new TriggerOfficerLevel($this->raw, $nation['level']); @@ -138,43 +108,12 @@ class General extends GeneralLite implements iAction $this->itemObjs['book'] = buildItemClass($raw['book']); $this->itemObjs['item'] = buildItemClass($raw['item']); - if (key_exists('aux', $this->raw)) { - $rawInheritBuff = $this->getAuxVar('inheritBuff'); - if ($rawInheritBuff !== null) { - $this->inheritBuffObj = new TriggerInheritBuff($rawInheritBuff); - } + $rawInheritBuff = $this->getAuxVar('inheritBuff'); + if ($rawInheritBuff !== null) { + $this->inheritBuffObj = new TriggerInheritBuff($rawInheritBuff); } } - function initLogger(int $year, int $month) - { - $this->logger = new ActionLogger( - $this->getVar('no'), - $this->getVar('nation'), - $year, - $month, - false - ); - } - - function getTurnTime(int $short = self::TURNTIME_FULL_MS) - { - return [ - self::TURNTIME_FULL_MS => function ($turntime) { - return $turntime; - }, - self::TURNTIME_FULL => function ($turntime) { - return substr($turntime, 0, 19); - }, - self::TURNTIME_HMS => function ($turntime) { - return substr($turntime, 11, 8); - }, - self::TURNTIME_HM => function ($turntime) { - return substr($turntime, 11, 5); - }, - ][$short]($this->getVar('turntime')); - } - function setItem(string $itemKey = 'item', ?string $itemCode) { if ($itemCode === null) { @@ -197,11 +136,6 @@ class General extends GeneralLite implements iAction return $this->itemObjs[$itemKey]; } - function getNPCType(): int - { - return $this->raw['npc']; - } - /** @return BaseItem[] */ function getItems(): array { @@ -278,48 +212,13 @@ class General extends GeneralLite implements iAction } } - function getName(): string - { - return $this->raw['name']; - } - function getInfo(): string { //iAction용 info로는 적절하지 않음 return ''; } - function getID(): int - { - return $this->raw['no']; - } - - function getRawCity(): ?array - { - return $this->rawCity; - } - - function setRawCity(?array $city) - { - $this->rawCity = $city; - } - - function getCityID(): int - { - return $this->raw['city']; - } - - function getNationID(): int - { - return $this->raw['nation']; - } - - function getStaticNation(): array - { - return getNationStaticInfo($this->raw['nation']); - } - - function getLogger(): ?ActionLogger + function getLogger(): ActionLogger { return $this->logger; } @@ -502,17 +401,6 @@ class General extends GeneralLite implements iAction return $this->getStatValue('intel', $withInjury, $withIActionObj, $withStatAdjust, $useFloor); } - function getDex(GameUnitDetail $crewType) - { - $armType = $crewType->armType; - - if ($armType == GameUnitConst::T_CASTLE) { - $armType = GameUnitConst::T_SIEGE; - } - - return $this->getVar("dex{$armType}"); - } - function addDex(GameUnitDetail $crewType, float $exp, bool $affectTrainAtmos = false) { $armType = $crewType->armType; @@ -1029,86 +917,6 @@ class General extends GeneralLite implements iAction return $caller; } - static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array - { - $minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city']; - $defaultEventColumn = [ - 'no', 'name', 'npc', 'owner', 'city', 'nation', 'officer_level', 'officer_city', - 'special', 'special2', 'personal', - 'horse', 'weapon', 'book', 'item', 'last_turn', 'aux', 'turntime', - ]; - $fullColumn = [ - 'no', 'name', 'owner', 'owner_name', 'picture', 'imgsvr', 'nation', 'city', 'troop', 'injury', 'affinity', - 'leadership', 'leadership_exp', 'strength', 'strength_exp', 'intel', 'intel_exp', 'weapon', 'book', 'horse', 'item', - 'experience', 'dedication', 'officer_level', 'officer_city', 'gold', 'rice', 'crew', 'crewtype', 'train', 'atmos', 'turntime', - 'makelimit', 'killturn', 'block', 'dedlevel', 'explevel', 'age', 'startage', 'belong', - 'personal', 'special', 'special2', 'defence_train', 'tnmt', 'npc', 'npc_org', 'deadyear', 'npcmsg', - 'dex1', 'dex2', 'dex3', 'dex4', 'dex5', 'betray', - 'recent_war', 'last_turn', 'myset', - 'specage', 'specage2', 'aux', 'permission', 'penalty', - ]; - $fullAcessLogColumn = [ - GeneralAccessLogColumn::refreshScore, - GeneralAccessLogColumn::refreshScoreTotal, - ]; - - if ($reqColumns === null) { - switch ($queryMode) { - case GeneralQueryMode::Core: - return [$minimumColumn, [], []]; - case GeneralQueryMode::Lite: - return [$defaultEventColumn, [], []]; - case GeneralQueryMode::FullWithoutIAction: - case GeneralQueryMode::Full: - return [$fullColumn, RankColumn::cases(), []]; - case GeneralQueryMode::FullWithAccessLog: - return [$fullColumn, RankColumn::cases(), $fullAcessLogColumn]; - } - } - - /** @var RankColumn[] */ - $rankColumn = []; - $subColumn = []; - $accessLogColumn = []; - foreach ($reqColumns as $column) { - if ($column instanceof RankColumn) { - $rankColumn[] = $column; - continue; - } - if ($column instanceof GeneralAccessLogColumn) { - $accessLogColumn[] = $column; - continue; - } - - - $enumKey = RankColumn::tryFrom($column); - if ($enumKey !== null) { - $rankColumn[] = $enumKey; - continue; - } - $enumKey = GeneralAccessLogColumn::tryFrom($column); - if ($enumKey !== null) { - $accessLogColumn[] = $enumKey; - continue; - } - $subColumn[] = $column; - } - - switch ($queryMode) { - case GeneralQueryMode::Core: - return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::Lite: - return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::FullWithoutIAction: - case GeneralQueryMode::Full: - return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::FullWithAccessLog: - return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, array_unique(array_merge($fullAcessLogColumn, $accessLogColumn))]; - default: - throw new \RuntimeException('invalid query mode'); - } - } - /** * @param ?int[] $generalIDList * @param null|array $column @@ -1122,15 +930,14 @@ class General extends GeneralLite implements iAction return []; } - $db = DB::db(); - if ($queryMode->value > 0) { - $gameStor = KVStorage::getStorage($db, 'game_env'); - [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); - } else { - $year = null; - $month = null; + if($queryMode < GeneralQueryMode::Full){ + throw new \InvalidArgumentException('충분하지 않은 queryMode:' . $queryMode); } + $db = DB::db(); + $gameStor = KVStorage::getStorage($db, 'game_env'); + [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); + /** * @var string[] $column * @var RankColumn[] $rankColumn @@ -1197,7 +1004,7 @@ class General extends GeneralLite implements iAction if ($rawRanks->hasKey($generalID) && $rawRanks[$generalID]->count() !== count($rankColumn)) { throw new \RuntimeException('column의 수가 일치하지 않음 : ' . $generalID); } - $result[$generalID] = new static($rawGenerals[$generalID], $rawRanks[$generalID] ?? null, $rawAccessLogs[$generalID] ?? null, null, null, $year, $month, $queryMode->value >= GeneralQueryMode::Full->value); + $result[$generalID] = new static($rawGenerals[$generalID], $rawRanks[$generalID] ?? null, $rawAccessLogs[$generalID] ?? null, null, null, $year, $month); } return $result; @@ -1205,15 +1012,14 @@ class General extends GeneralLite implements iAction static public function createGeneralObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): self { - $db = DB::db(); - if ($queryMode->value > 0) { - $gameStor = KVStorage::getStorage($db, 'game_env'); - [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); - } else { - $year = null; - $month = null; + if($queryMode < GeneralQueryMode::Full){ + throw new \InvalidArgumentException('충분하지 않은 queryMode:' . $queryMode); } + $db = DB::db(); + $gameStor = KVStorage::getStorage($db, 'game_env'); + [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); + /** * @var string[] $column * @var RankColumn[] $rankColumn @@ -1266,7 +1072,7 @@ class General extends GeneralLite implements iAction } - $general = new static($rawGeneral, $rawRankValues, $rawAccessLog, null, null, $year, $month, $queryMode->value >= GeneralQueryMode::Full->value); + $general = new static($rawGeneral, $rawRankValues, $rawAccessLog, null, null, $year, $month); return $general; } diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php index 15a58a5c..fda9136b 100644 --- a/hwe/sammo/GeneralLite.php +++ b/hwe/sammo/GeneralLite.php @@ -17,51 +17,14 @@ class GeneralLite protected $raw = []; protected $rawCity = null; - - /** @var Map */ - protected Map $rankVarRead; - /** @var Map */ - protected Map $rankVarIncrease; - /** @var Map */ - protected Map $rankVarSet; - - /** @var Map */ - protected ?Map $accessLogRead; - /** @var \sammo\ActionLogger */ protected $logger; - protected $activatedSkill = []; - protected $logActivatedSkill = []; - protected $isFinished = false; - - /** @var ?iAction */ - protected $nationType = null; - /** @var ?iAction */ - protected $officerLevelObj = null; - /** @var ?iAction */ - protected $specialDomesticObj = null; - /** @var ?iAction */ - protected $specialWarObj = null; - /** @var ?iAction */ - protected $personalityObj = null; - /** @var ?iAction[] */ - protected $itemObjs = []; - /** @var ?iAction */ - protected $inheritBuffObj = null; - /** @var ?GameUnitDetail */ - protected $crewType = null; - - protected $lastTurn = null; - protected $resultTurn = null; - const TURNTIME_FULL_MS = -1; const TURNTIME_FULL = 0; const TURNTIME_HMS = 1; const TURNTIME_HM = 2; - protected $calcCache = []; - protected static $prohibitedDirectUpdateVars = [ //Reason: iAction 'leadership' => 1, @@ -82,17 +45,12 @@ class GeneralLite /** * @param array $raw DB row값. - * @param null|Map $rawRank - * @param null|Map $rawAccessLog * @param null|array $city DB city 테이블의 row값 * @param int|null $year 게임 연도 * @param int|null $month 게임 월 - * @param bool $fullConstruct iAction, 및 ActionLogger 초기화 여부, false인 경우 no, name, city, nation, officer_level 정도로 초기화 가능 */ - public function __construct(array $raw, ?Map $rawRank, ?Map $rawAccessLog, ?array $city, ?array $nation, ?int $year, ?int $month, bool $fullConstruct = true) + public function __construct(array $raw, ?array $city, ?array $nation, ?int $year, ?int $month) { - //TODO: 밖에서 가져오도록 하면 버그 확률이 높아짐. 필요한 raw 값을 직접 구해야함. - if ($nation === null) { $nation = getNationStaticInfo($raw['nation']); } @@ -100,53 +58,9 @@ class GeneralLite $this->raw = $raw; $this->rawCity = $city; - $this->resultTurn = new LastTurn(); - if (key_exists('last_turn', $this->raw)) { - $this->lastTurn = LastTurn::fromJson($this->raw['last_turn']); - $this->resultTurn = $this->lastTurn->duplicate(); - } - if ($year !== null && $month !== null) { $this->initLogger($year, $month); } - - if ($rawRank) { - $this->rankVarRead = $rawRank; - } else { - $this->rankVarRead = new Map(); - } - - $this->accessLogRead = $rawAccessLog; - - - $this->rankVarIncrease = new Map(); - $this->rankVarSet = new Map(); - - if (!$fullConstruct) { - return; - } - - $this->nationType = buildNationTypeClass($nation['type']); - $this->officerLevelObj = new TriggerOfficerLevel($this->raw, $nation['level']); - - $this->specialDomesticObj = buildGeneralSpecialDomesticClass($raw['special']); - $this->specialWarObj = buildGeneralSpecialWarClass($raw['special2']); - - $this->personalityObj = buildPersonalityClass($raw['personal']); - - $this->crewType = GameUnitConst::byID($raw['crewtype'] ?? GameUnitConst::DEFAULT_CREWTYPE); - - $this->itemObjs['horse'] = buildItemClass($raw['horse']); - $this->itemObjs['weapon'] = buildItemClass($raw['weapon']); - $this->itemObjs['book'] = buildItemClass($raw['book']); - $this->itemObjs['item'] = buildItemClass($raw['item']); - - if (key_exists('aux', $this->raw)) { - $rawInheritBuff = $this->getAuxVar('inheritBuff'); - if ($rawInheritBuff !== null) { - $this->inheritBuffObj = new TriggerInheritBuff($rawInheritBuff); - } - } } function initLogger(int $year, int $month) @@ -160,8 +74,12 @@ class GeneralLite ); } - function getTurnTime(int $short = self::TURNTIME_FULL_MS) + function getTurnTime(int $short = self::TURNTIME_FULL_MS): ?string { + if(!key_exists('turntime', $this->raw)){ + return null; + } + return [ self::TURNTIME_FULL_MS => function ($turntime) { return $turntime; @@ -178,120 +96,16 @@ class GeneralLite ][$short]($this->getVar('turntime')); } - function setItem(string $itemKey = 'item', ?string $itemCode) - { - if ($itemCode === null) { - $this->deleteItem($itemKey); - return; - } - - $this->setVar($itemKey, $itemCode); - $this->itemObjs[$itemKey] = buildItemClass($itemCode); - } - - function deleteItem(string $itemKey = 'item') - { - $this->setVar($itemKey, 'None'); - $this->itemObjs[$itemKey] = new ActionItem\None(); - } - - function getItem(string $itemKey = 'item'): BaseItem - { - return $this->itemObjs[$itemKey]; - } - function getNPCType(): int { return $this->raw['npc']; } - /** @return BaseItem[] */ - function getItems(): array - { - return $this->itemObjs; - } - - function getPersonality(): iAction - { - return $this->personalityObj; - } - - function getSpecialDomestic(): iAction - { - return $this->specialDomesticObj; - } - - function getSpecialWar(): iAction - { - return $this->specialWarObj; - } - - function getLastTurn(): LastTurn - { - return $this->lastTurn; - } - - function _setResultTurn(LastTurn $resultTurn) - { - $this->resultTurn = $resultTurn; - } - - function getResultTurn(): LastTurn - { - return $this->resultTurn; - } - - function clearActivatedSkill() - { - foreach ($this->activatedSkill as $skillName => $state) { - if (!$state) { - continue; - } - - if (!key_exists($skillName, $this->logActivatedSkill)) { - $this->logActivatedSkill[$skillName] = 1; - } else { - $this->logActivatedSkill[$skillName] += 1; - } - } - $this->activatedSkill = []; - } - - function getActivatedSkillLog(): array - { - return $this->logActivatedSkill; - } - - function hasActivatedSkill(string $skillName): bool - { - return $this->activatedSkill[$skillName] ?? false; - } - - function activateSkill(...$skillNames) - { - foreach ($skillNames as $skillName) { - $this->activatedSkill[$skillName] = true; - } - } - - function deactivateSkill(...$skillNames) - { - foreach ($skillNames as $skillName) { - $this->activatedSkill[$skillName] = false; - } - } - function getName(): string { return $this->raw['name']; } - function getInfo(): string - { - //iAction용 info로는 적절하지 않음 - return ''; - } - function getID(): int { return $this->raw['no']; @@ -327,169 +141,6 @@ class GeneralLite return $this->logger; } - public function getNationTypeObj(): iAction - { - return $this->nationType; - } - - public function getOfficerLevelObj(): iAction - { - return $this->officerLevelObj; - } - - function getCrewTypeObj(): GameUnitDetail - { - if ($this->crewType === null) { - throw new \InvalidArgumentException('Invalid CrewType:' . $this->getVar('crewtype')); - } - return $this->crewType; - } - - function calcRecentWarTurn(int $turnTerm): int - { - $cacheKey = "recent_war_turn_{$turnTerm}"; - if (key_exists($cacheKey, $this->calcCache)) { - return $this->calcCache[$cacheKey]; - } - if (!$this->getVar('recent_war')) { - $result = 12 * 1000; - $this->calcCache[$cacheKey] = $result; - return $result; - } - $recwar = new \DateTimeImmutable($this->getVar('recent_war')); - $turnNow = new \DateTimeImmutable($this->getVar('turntime')); - $secDiff = TimeUtil::DateIntervalToSeconds($recwar->diff($turnNow)); - - if ($secDiff <= 0) { - $this->calcCache[$cacheKey] = 0; - return 0; - } - - $result = intdiv(Util::toInt($secDiff), 60 * $turnTerm); - $this->calcCache[$cacheKey] = $result; - return $result; - } - - function getReservedTurn(int $turnIdx, array $env): GeneralCommand - { - $db = DB::db(); - $rawCmd = $db->queryFirstRow('SELECT * FROM general_turn WHERE general_id = %i AND turn_idx = %i', $this->getID(), $turnIdx); - if (!$rawCmd) { - return buildGeneralCommandClass(null, $this, $env); - } - return buildGeneralCommandClass($rawCmd['action'], $this, $env, Json::decode($rawCmd['arg'] ?? null)); - } - - /** - * @param General[] $generalList - * @param int $turnIdxFrom [$turnIdxFrom, $turnIdxTo) - * @param int $turnIdxTo [$turnIdxFrom, $turnIdxTo) - * @param array $env - * @return GeneralCommand[] - */ - public function getReservedTurnList(int $turnIdxFrom, int $turnIdxTo, array $env) - { - if ($turnIdxFrom < 0 || $turnIdxFrom >= GameConst::$maxTurn) { - throw new \OutOfRangeException('$turnIdxFrom 범위 초과' . $turnIdxFrom); - } - - if ($turnIdxTo <= $turnIdxFrom || GameConst::$maxTurn < $turnIdxTo) { - throw new \OutOfRangeException('$turnIdxTo 범위 초과' . $turnIdxTo); - } - - $db = DB::db(); - - $generalID = $this->getID(); - - $result = []; - - $rawCmds = $db->queryFirstRow('SELECT * FROM general_turn WHERE general_id = %i AND %i <= turn_idx AND turn_idx < %i ORDER BY turn_idx ASC', $generalID, $turnIdxFrom, $turnIdxTo); - - if (!$rawCmds) { - foreach (Util::range($turnIdxFrom, $turnIdxTo) as $turnIdx) { - $result[$turnIdx] = buildGeneralCommandClass(null, $this, $env); - } - return $result; - } - - foreach ($rawCmds as $turnIdx => $rawCmd) { - $result[$turnIdx] = buildGeneralCommandClass($rawCmd['action'], $this, $env, Json::decode($rawCmd['arg'] ?? null)); - } - - return $result; - } - - /** - * 장수의 스탯을 계산해옴 - * - * @param string $statName 스탯값, leadership, strength, intel 가능 - * @param bool $withInjury 부상값 사용 여부 - * @param bool $withIActionObj 아이템, 특성, 성격 등 보정치 적용 여부 - * @param bool $withStatAdjust 능력치간 보정 사용 여부 - * @param bool $useFloor 내림 사용 여부, false시 float 값을 반환할 수도 있음 - * - * @return float 계산된 능력치 - */ - - protected function getStatValue(string $statName, $withInjury = true, $withIActionObj = true, $withStatAdjust = true, $useFloor = true): float - { - $cKey = "{$statName}_{$withInjury}_{$withIActionObj}_{$withStatAdjust}"; - if (key_exists($cKey, $this->calcCache)) { - $statValue = $this->calcCache[$cKey]; - if ($useFloor) { - return Util::toInt($statValue); - } - return $statValue; - } - - $statValue = $this->getVar($statName); - - if ($withInjury) { - $statValue *= (100 - $this->getVar('injury')) / 100; - } - - if ($withStatAdjust) { - if ($statName === 'strength') { - $statValue += Util::round($this->getStatValue('intel', $withInjury, $withIActionObj, false, false) / 4); - } else if ($statName === 'intel') { - $statValue += Util::round($this->getStatValue('strength', $withInjury, $withIActionObj, false, false) / 4); - } - } - - $statValue = Util::clamp($statValue, 0, GameConst::$maxLevel); - - if ($withIActionObj) { - foreach ([ - $this->nationType, - $this->officerLevelObj, - $this->specialDomesticObj, - $this->specialWarObj, - $this->personalityObj, - $this->inheritBuffObj, - ] as $actionObj) { - if ($actionObj !== null) { - $statValue = $actionObj->onCalcStat($this, $statName, $statValue); - } - } - - foreach ($this->itemObjs as $actionObj) { - if ($actionObj !== null) { - $statValue = $actionObj->onCalcStat($this, $statName, $statValue); - } - } - } - - $this->calcCache[$cKey] = $statValue; - - $statValue = Util::clamp($statValue, 0, GameConst::$maxLevel); - - if ($useFloor) { - return Util::toInt($statValue); - } - - return $statValue; - } - function getDex(GameUnitDetail $crewType) { $armType = $crewType->armType; @@ -501,83 +152,6 @@ class GeneralLite return $this->getVar("dex{$armType}"); } - function addDex(GameUnitDetail $crewType, float $exp, bool $affectTrainAtmos = false) - { - $armType = $crewType->armType; - - if ($armType == GameUnitConst::T_CASTLE) { - $armType = GameUnitConst::T_SIEGE; - } - - if ($armType < 0) { - return; - } - - if ($armType == GameUnitConst::T_WIZARD) { - $exp *= 0.9; - } else if ($armType == GameUnitConst::T_SIEGE) { - $exp *= 0.9; - } - - if ($affectTrainAtmos) { - $exp *= ($this->getVar('train') + $this->getVar('atmos')) / 200; - } - - $dexType = "dex{$armType}"; - $exp = $this->onCalcStat($this, 'addDex', $exp, ['armType' => $armType]); - - $this->increaseVar($dexType, $exp); - } - - function addExperience(float $experience, bool $affectTrigger = true) - { - if ($affectTrigger) { - $experience = $this->onCalcStat($this, 'experience', $experience); - } - - $this->increaseVar('experience', $experience); - $nextExpLevel = getExpLevel($this->getVar('experience')); - $comp = $nextExpLevel <=> $this->getVar('explevel'); - if ($comp === 0) { - return; - } - - $this->updateVar('explevel', $nextExpLevel); - - $josaRo = JosaUtil::pick($nextExpLevel, '로'); - if ($comp > 0) { - $this->getLogger()->pushGeneralActionLog("Lv {$nextExpLevel}{$josaRo} 레벨업!", ActionLogger::PLAIN); - } else { - $this->getLogger()->pushGeneralActionLog("Lv {$nextExpLevel}{$josaRo} 레벨다운!", ActionLogger::PLAIN); - } - } - - function addDedication(float $dedication, bool $affectTrigger = true) - { - if ($affectTrigger) { - $dedication = $this->onCalcStat($this, 'dedication', $dedication); - } - - $this->increaseVar('dedication', $dedication); - $nextDedLevel = getDedLevel($this->getVar('dedication')); - $comp = $nextDedLevel <=> $this->getVar('dedlevel'); - if ($comp === 0) { - return; - } - - $this->updateVar('dedlevel', $nextDedLevel); - - $dedLevelText = getDedLevelText($nextDedLevel); - $billText = number_format(getBillByLevel($nextDedLevel)); - $josaRoDed = JosaUtil::pick($dedLevelText, '로'); - $josaRoBill = JosaUtil::pick($billText, '로'); - if ($comp > 0) { - $this->getLogger()->pushGeneralActionLog("{$dedLevelText}{$josaRoDed} 승급하여 봉록이 {$billText}{$josaRoBill} 상승했습니다!", ActionLogger::PLAIN); - } else { - $this->getLogger()->pushGeneralActionLog("{$dedLevelText}{$josaRoDed} 강등되어 봉록이 {$billText}{$josaRoBill} 하락했습니다!", ActionLogger::PLAIN); - } - } - function updateVar(string $key, $value) { if (($this->raw[$key] ?? null) === $value) { @@ -587,196 +161,6 @@ class GeneralLite $this->updatedVar[$key] = true; } $this->raw[$key] = $value; - $this->calcCache = []; - } - - /** - * @param \MeekroDB $db - */ - function kill($db, bool $sendDyingMessage = true, ?string $dyingMessage = null) - { - $generalID = $this->getID(); - $logger = $this->getLogger(); - - $generalName = $this->getName(); - - //유산포인트 관련 항목 환불 - if ($this->getNPCType() < 2) { - - $refundPoint = 0; - $userID = $this->getVar('owner'); - $userLogger = new UserLogger($userID); - if ($this->getAuxVar('inheritRandomUnique')) { - $this->setAuxVar('inheritRandomUnique', null); - $userLogger->push(sprintf("사망으로 랜덤 유니크 구입 %d 포인트 반환", GameConst::$inheritItemRandomPoint), "inheritPoint"); - $refundPoint += GameConst::$inheritItemRandomPoint; - } - - //TODO: 경매 최우선 입찰자인경우 반환 - - if ($this->getAuxVar('inheritSpecificSpecialWar')) { - $this->setAuxVar('inheritSpecificSpecialWar', null); - $userLogger->push(sprintf("사망으로 전투 특기 지정 %d 포인트 반환", GameConst::$inheritSpecificSpecialPoint), "inheritPoint"); - $refundPoint += GameConst::$inheritSpecificSpecialPoint; - } - - if ($refundPoint > 0) { - $this->increaseInheritancePoint(InheritanceKey::previous, $refundPoint); - $this->increaseRankVar(RankColumn::inherit_point_spent_dynamic, -$refundPoint); - } - - $inheritPointManager = InheritancePointManager::getInstance(); - $inheritPointManager->mergeTotalInheritancePoint($this); - $inheritPointManager->applyInheritanceUser($this->getVar('owner')); - } - - - // 군주였으면 유지 이음 - $officerLevel = $this->getVar('officer_level'); - if ($officerLevel == 12) { - nextRuler($this); - $this->setVar('officer_level', 1); - } - - // 부대 처리 - $troopLeaderID = $this->getVar('troop'); - if ($troopLeaderID == $generalID) { - //부대장일 경우 - // 모두 탈퇴 - $db->update('general', [ - 'troop' => 0 - ], 'troop=%i', $troopLeaderID); - // 부대 삭제 - $db->delete('troop', 'troop_leader=%i', $troopLeaderID); - } - - - if ($sendDyingMessage) { - if ($dyingMessage) { - $logger->pushGlobalActionLog($dyingMessage); - } else { - $dyingMessageObj = new TextDecoration\DyingMessage($this); - $logger->pushGlobalActionLog($dyingMessageObj->getText()); - } - $logger->flush(); - } - - $db->update('select_pool', [ - 'general_id' => null, - 'owner' => null, - 'reserved_until' => null, - ], 'general_id=%i', $generalID); - - storeOldGeneral($generalID, $logger->getYear(), $logger->getMonth()); - - $db->delete('general', 'no=%i', $generalID); - $db->delete('general_turn', 'general_id=%i', $generalID); - $db->delete('rank_data', 'general_id=%i', $generalID); - $db->delete('general_access_log', 'general_id=%i', $generalID); - $this->updatedVar = []; - - $db->update('nation', [ - 'gennum' => $db->sqleval('gennum - 1') - ], 'nation=%i', $this->getVar('nation')); - } - - function rebirth() - { - $logger = $this->getLogger(); - - $generalName = $this->getName(); - - $inheritPointManager = InheritancePointManager::getInstance(); - - $ownerID = $this->getVar('owner'); - if ($ownerID) { - $inheritPointManager->mergeTotalInheritancePoint($this, true); - $inheritPointManager->applyInheritanceUser($ownerID, true); - } - - $this->multiplyVarWithLimit('leadership', 0.85, 10); - $this->multiplyVarWithLimit('strength', 0.85, 10); - $this->multiplyVarWithLimit('intel', 0.85, 10); - $this->setVar('injury', 0); - $this->multiplyVar('experience', 0.5); - $this->multiplyVar('dedication', 0.5); - $this->setVar('age', 20); - $this->setVar('specage', 0); - $this->setVar('specage2', 0); - $this->multiplyVar('dex1', 0.5); - $this->multiplyVar('dex2', 0.5); - $this->multiplyVar('dex3', 0.5); - $this->multiplyVar('dex4', 0.5); - $this->multiplyVar('dex5', 0.5); - - foreach (RankColumn::cases() as $rankKey) { - $this->setRankVar($rankKey, 0); - } - - $josaYi = JosaUtil::pick($generalName, '이'); - $logger->pushGlobalActionLog("{$generalName}{$josaYi} 은퇴하고 그 자손이 유지를 이어받았습니다."); - $logger->pushGeneralActionLog('나이가 들어 은퇴하고 자손에게 자리를 물려줍니다.', ActionLogger::PLAIN); - $logger->pushGeneralHistoryLog('나이가 들어 은퇴하고, 자손에게 관직을 물려줌'); - } - - function increaseRankVar(RankColumn $key, int $value) - { - if ($this->rankVarSet->hasKey($key)) { - $this->rankVarSet[$key] += $value; - return; - } - - if ($this->rankVarRead->hasKey($key)) { - $this->rankVarSet[$key] = $this->rankVarRead[$key] + $value; - $this->rankVarRead->remove($key); - return; - } - - if ($this->rankVarIncrease->hasKey($key)) { - $this->rankVarIncrease[$key] += $value; - return; - } - - $this->rankVarIncrease[$key] = $value; - } - - function setRankVar(RankColumn $key, int $value) - { - if ($this->rankVarRead->hasKey($key)) { - $this->rankVarRead->remove($key); - } else if ($this->rankVarIncrease->hasKey($key)) { - $this->rankVarIncrease->remove($key); - } - $this->rankVarSet[$key] = $value; - } - - function getRankVar(RankColumn $key, $defaultValue = null): int - { - if ($this->rankVarSet->hasKey($key)) { - return $this->rankVarSet[$key]; - } - - if (!$this->rankVarRead->hasKey($key)) { - if ($defaultValue === null) { - throw new \RuntimeException('인자가 없음 : ' . $key->value); - } - return $defaultValue; - } - - return $this->rankVarRead[$key]; - } - - function getAccessLogVar(GeneralAccessLogColumn $key, $defaultValue = null): int | string | null - { - if (!$this->accessLogRead) { - return $defaultValue; - } - - if (!$this->accessLogRead->hasKey($key)) { - return $defaultValue; - } - - return $this->accessLogRead[$key]; } /** @@ -784,9 +168,6 @@ class GeneralLite */ function applyDB($db): bool { - if ($this->lastTurn && $this->getLastTurn() != $this->getResultTurn()) { - $this->setVar('last_turn', $this->getResultTurn()->toJson()); - } $updateVals = $this->getUpdatedValues(); @@ -805,218 +186,10 @@ class GeneralLite $this->flushUpdateValues(); } - if ($this->rankVarIncrease->count()) { - foreach ($this->rankVarIncrease as $rankKey => $rankVal) { - $db->update('rank_data', [ - 'value' => $db->sqleval('value + %i', $rankVal) - ], 'general_id = %i AND type = %s', $generalID, $rankKey->value); - } - $result = true; - } - - if ($this->rankVarSet->count()) { - foreach ($this->rankVarSet as $rankKey => $rankVal) { - $db->update('rank_data', [ - 'value' => $rankVal - ], 'general_id = %i AND type = %s', $generalID, $rankKey->value); - $this->rankVarRead[$rankKey] = $rankVal; - } - $result = true; - } - - $this->rankVarIncrease = new Map(); - $this->rankVarSet = new Map(); - $this->getLogger()->flush(); return $result; } - function checkStatChange(): bool - { - $logger = $this->getLogger(); - $limit = GameConst::$upgradeLimit; - - $table = [ - ['통솔', 'leadership'], - ['무력', 'strength'], - ['지력', 'intel'], - ]; - - $result = false; - - foreach ($table as [$statNickName, $statName]) { - $statExpName = $statName . '_exp'; - - if ($this->getVar($statExpName) < 0) { - $logger->pushGeneralActionLog("{$statNickName}이 1 떨어졌습니다!", ActionLogger::PLAIN); - $this->increaseVar($statExpName, $limit); - $this->increaseVar($statName, -1); - $result = true; - } else if ($this->getVar($statExpName) >= $limit) { - if ($this->getVar($statName) < GameConst::$maxLevel) { - $logger->pushGeneralActionLog("{$statNickName}이 1 올랐습니다!", ActionLogger::PLAIN); - $this->increaseVar($statName, 1); - } - $this->increaseVar($statExpName, -$limit); - $result = true; - } - } - - return $result; - } - - protected function getActionList(): array - { - return array_merge([ - $this->nationType, - $this->officerLevelObj, - $this->specialDomesticObj, - $this->specialWarObj, - $this->personalityObj, - $this->crewType, - $this->inheritBuffObj, - ], $this->itemObjs); - } - - public function getPreTurnExecuteTriggerList(General $general): ?GeneralTriggerCaller - { - $caller = new GeneralTriggerCaller(); - foreach ($this->getActionList() as $iObj) { - - if (!$iObj) { - continue; - } - /** @var iAction $iObj */ - $caller->merge($iObj->getPreTurnExecuteTriggerList($general)); - } - - return $caller; - } - public function onCalcDomestic(string $turnType, string $varType, float $value, $aux = null): float - { - foreach ($this->getActionList() as $iObj) { - if (!$iObj) { - continue; - } - /** @var iAction $iObj */ - $value = $iObj->onCalcDomestic($turnType, $varType, $value, $aux); - } - return $value; - } - - public function onCalcStat(General $general, string $statName, $value, $aux = null) - { - //xxx: $general? - foreach ($this->getActionList() as $iObj) { - if (!$iObj) { - continue; - } - /** @var iAction $iObj */ - $value = $iObj->onCalcStat($this, $statName, $value, $aux); - } - return $value; - } - - public function onCalcOpposeStat(General $general, string $statName, $value, $aux = null) - { - //xxx: $general? - foreach ($this->getActionList() as $iObj) { - if (!$iObj) { - continue; - } - /** @var iAction $iObj */ - $value = $iObj->onCalcOpposeStat($this, $statName, $value, $aux); - } - return $value; - } - - public function onCalcStrategic(string $turnType, string $varType, $value) - { - foreach ($this->getActionList() as $iObj) { - if (!$iObj) { - continue; - } - /** @var iAction $iObj */ - $value = $iObj->onCalcStrategic($turnType, $varType, $value); - } - return $value; - } - - public function onCalcNationalIncome(string $type, $amount) - { - foreach ($this->getActionList() as $iObj) { - if (!$iObj) { - continue; - } - /** @var iAction $iObj */ - $amount = $iObj->onCalcNationalIncome($type, $amount); - } - return $amount; - } - - public function onArbitraryAction(General $general, RandUtil $rng, string $actionType, ?string $phase = null, $aux = null): null|array - { - foreach ($this->getActionList() as $iObj) { - if (!$iObj) { - continue; - } - /** @var iAction $iObj */ - $aux = $iObj->onArbitraryAction($general, $rng, $actionType, $phase, $aux); - } - return $aux; - } - - public function getWarPowerMultiplier(WarUnit $unit): array - { - //xxx:$unit - $att = 1; - $def = 1; - foreach ($this->getActionList() as $iObj) { - if (!$iObj) { - continue; - } - /** @var iAction $iObj */ - [$attV, $defV] = $iObj->getWarPowerMultiplier($unit); - $att *= $attV; - $def *= $defV; - } - return [$att, $def]; - } - public function getBattleInitSkillTriggerList(WarUnit $unit): ?WarUnitTriggerCaller - { - $caller = new WarUnitTriggerCaller(); - foreach ($this->getActionList() as $iObj) { - if (!$iObj) { - continue; - } - /** @var iAction $iObj */ - $caller->merge($iObj->getBattleInitSkillTriggerList($unit)); - } - - return $caller; - } - public function getBattlePhaseSkillTriggerList(WarUnit $unit): ?WarUnitTriggerCaller - { - $caller = new WarUnitTriggerCaller( - new WarUnitTrigger\che_필살시도($unit), - new WarUnitTrigger\che_필살발동($unit), - new WarUnitTrigger\che_회피시도($unit), - new WarUnitTrigger\che_회피발동($unit), - new WarUnitTrigger\che_계략시도($unit), - new WarUnitTrigger\che_계략발동($unit), - new WarUnitTrigger\che_계략실패($unit) - ); - foreach ($this->getActionList() as $iObj) { - if (!$iObj) { - continue; - } - /** @var iAction $iObj */ - $caller->merge($iObj->getBattlePhaseSkillTriggerList($unit)); - } - - return $caller; - } - static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array { $minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city']; @@ -1101,15 +274,19 @@ class GeneralLite * @param ?int[] $generalIDList * @param null|array $column * @param GeneralQueryMode $queryMode - * @return \sammo\General[] + * @return \sammo\Generalite[] * @throws MustNotBeReachedException */ - static public function createGeneralObjListFromDB(?array $generalIDList, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array + static public function createGeneralLiteObjListFromDB(?array $generalIDList, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::FullWithoutIAction): array { if ($generalIDList === []) { return []; } + if($queryMode > GeneralQueryMode::FullWithoutIAction){ + throw new \InvalidArgumentException('지원하지 않는 queryMode:' . $queryMode); + } + $db = DB::db(); if ($queryMode->value > 0) { $gameStor = KVStorage::getStorage($db, 'game_env'); @@ -1191,8 +368,12 @@ class GeneralLite return $result; } - static public function createGeneralObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): self + static public function createGeneralLiteObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::FullWithoutIAction): self { + if($queryMode > GeneralQueryMode::FullWithoutIAction){ + throw new \InvalidArgumentException('지원하지 않는 queryMode:' . $queryMode); + } + $db = DB::db(); if ($queryMode->value > 0) { $gameStor = KVStorage::getStorage($db, 'game_env'); @@ -1204,165 +385,17 @@ class GeneralLite /** * @var string[] $column - * @var RankColumn[] $rankColumn - * @var GeneralAccessLogCoumn[] $accessLogColumn */ - [$column, $rankColumn, $accessLogColumn] = static::mergeQueryColumn($column, $queryMode); + [$column,,] = static::mergeQueryColumn($column, $queryMode); - /** @var Map|null */ - $rawAccessLog = null; - - if (!$accessLogColumn) { - $rawGeneral = $db->queryFirstRow('SELECT %l FROM general WHERE no = %i', Util::formatListOfBackticks($column), $generalID); - } else { - $rawGeneral = $db->queryFirstRow( - 'SELECT %l, %l FROM `general` LEFT JOIN general_access_log - ON general.no = general_access_log.general_id WHERE no = %i', - Util::formatListOfBackticks($column), - Util::formatListOfBackticks($accessLogColumn), - $generalID - ); - - $rawAccessLog = new Map(); - foreach ($accessLogColumn as $accessLogKey) { - if (!key_exists($accessLogKey->value, $rawGeneral)) { - continue; - } - $rawAccessLog[$accessLogKey] = $rawGeneral[$accessLogKey->value]; - unset($rawGeneral[$accessLogKey->value]); - } - if ($rawAccessLog->count() === 0) { - $rawAccessLog = null; - } - } + $rawGeneral = $db->queryFirstRow('SELECT %l FROM general WHERE no = %i', Util::formatListOfBackticks($column), $generalID); if (!$rawGeneral) { return new DummyGeneral($queryMode->value > 0); } - $rawRankValues = new Map(); - if ($rankColumn) { - $rawValue = $db->queryAllLists( - 'SELECT `type`, `value` FROM rank_data WHERE general_id = %i AND `type` IN %ls', - $generalID, - array_map(fn (\BackedEnum $e) => $e->value, $rankColumn) - ); - foreach ($rawValue as [$rawRankType, $rankValue]) { - $rankType = RankColumn::tryFrom($rawRankType); - $rawRankValues->put($rankType, $rankValue); - } - } - - - $general = new static($rawGeneral, $rawRankValues, $rawAccessLog, null, null, $year, $month, $queryMode->value >= GeneralQueryMode::Full->value); + $general = new static($rawGeneral, null, null, $year, $month); return $general; } - - /** - * @param General[] $generalList - * @param int $turnIdx - * @param array $env - * @return GeneralCommand[] - */ - static public function getReservedTurnByGeneralList(array $generalList, int $turnIdx, array $env) - { - if (!$generalList) { - return []; - } - - $generalIDList = array_map(function (General $general) { - return $general->getID(); - }, $generalList); - - $db = DB::db(); - $result = []; - $rawCmds = Util::convertArrayToDict($db->query('SELECT * FROM general_turn WHERE general_id IN %li AND turn_idx = %i', $generalIDList, $turnIdx), 'general_id'); - foreach ($generalList as $general) { - $generalID = $general->getID(); - if (!key_exists($generalID, $rawCmds)) { - $result[$generalID] = buildGeneralCommandClass(null, $general, $env); - continue; - } - $rawCmd = $rawCmds[$generalID]; - $result[$generalID] = buildGeneralCommandClass($rawCmd['action'], $general, $env, Json::decode($rawCmd['arg'])); - } - return $result; - } - - /** - * @param General[] $generalList - * @param int $turnIdxFrom [$turnIdxFrom, $turnIdxTo) - * @param int $turnIdxTo [$turnIdxFrom, $turnIdxTo) - * @param array $env - * @return GeneralCommand[][] - */ - static public function getReservedTurnListByGeneralList(array $generalList, int $turnIdxFrom, int $turnIdxTo, array $env) - { - //XXX: static인데 return값이 General이 아니라고?? GeneralCommandHelper같은게 있어야하지 않을까? - if (!$generalList) { - return []; - } - - if ($turnIdxFrom < 0 || $turnIdxFrom >= GameConst::$maxTurn) { - throw new \OutOfRangeException('$turnIdxFrom 범위 초과' . $turnIdxFrom); - } - - if ($turnIdxTo <= $turnIdxFrom || GameConst::$maxTurn < $turnIdxTo) { - throw new \OutOfRangeException('$turnIdxTo 범위 초과' . $turnIdxTo); - } - - $generalIDList = array_map(function (General $general) { - return $general->getID(); - }, $generalList); - - $db = DB::db(); - - $rawCmds = $db->queryFirstRow('SELECT * FROM general_turn WHERE general_id IN %i AND %i <= turn_idx AND turn_idx < %i ORDER BY general_id ASC, turn_idx ASC', $generalIDList, $turnIdxFrom, $turnIdxTo); - $orderedRawCmds = []; - foreach ($rawCmds as $rawCmd) { - $generalID = $rawCmd['general_id']; - $turnIdx = $rawCmd['turn_idx']; - if (!key_exists($generalID, $orderedRawCmds)) { - $orderedRawCmds[$generalID] = []; - } - $orderedRawCmds[$generalID][$turnIdx] = $rawCmd; - } - - $result = []; - foreach ($generalList as $general) { - $generalID = $general->getID(); - $result[$generalID] = []; - if (!key_exists($generalID, $orderedRawCmds)) { - foreach (Util::range($turnIdxFrom, $turnIdxTo) as $turnIdx) { - $result[$generalID][$turnIdx] = buildGeneralCommandClass(null, $general, $env); - } - continue; - } - foreach ($orderedRawCmds[$generalID] as $turnIdx => $rawCmd) { - $result[$generalID][$turnIdx] = buildGeneralCommandClass($rawCmd['action'], $general, $env, Json::decode($rawCmd['arg'])); - } - } - return $result; - } - - public function getInheritancePoint(InheritanceKey $key, &$aux = null, bool $forceCalc = false): int|float|null - { - return InheritancePointManager::getInstance()->getInheritancePoint($this, $key, $aux, $forceCalc); - } - - public function setInheritancePoint(InheritanceKey $key, $value, $aux = null) - { - return InheritancePointManager::getInstance()->setInheritancePoint($this, $key, $value, $aux); - } - - public function increaseInheritancePoint(InheritanceKey $key, $value, $aux = null) - { - return InheritancePointManager::getInstance()->increaseInheritancePoint($this, $key, $value, $aux); - } - - public function mergeTotalInheritancePoint(bool $isRebirth = false) - { - InheritancePointManager::getInstance()->mergeTotalInheritancePoint($this, $isRebirth); - } } -- 2.54.0 From e960446638ff0865de75523d48d9cd76dd81bea6 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 27 Jul 2023 17:03:19 +0000 Subject: [PATCH 03/19] =?UTF-8?q?wip:=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/b_currentCity.php | 3 +-- hwe/sammo/General.php | 16 ++++++++-------- hwe/sammo/GeneralLite.php | 6 +++--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/hwe/b_currentCity.php b/hwe/b_currentCity.php index 7728a5fd..4762892c 100644 --- a/hwe/b_currentCity.php +++ b/hwe/b_currentCity.php @@ -327,8 +327,7 @@ $templates = new \League\Plates\Engine('templates'); if ($ourGeneral && !$isNPC) { $turnText = []; - $generalObj = new General($general, null, null, null, null, null, null, false); - foreach ($generalTurnList[$generalObj->getID()] as $turnRawIdx => $turn) { + foreach ($generalTurnList[$general['no']] as $turnRawIdx => $turn) { $turnIdx = $turnRawIdx + 1; $turnText[] = "{$turnIdx} : $turn"; } diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index ce9b2144..9d4a6ad8 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -15,14 +15,14 @@ class General extends GeneralLite implements iAction protected $rawCity = null; - /** @var Map */ + /** @var Map */ protected Map $rankVarRead; - /** @var Map */ + /** @var Map */ protected Map $rankVarIncrease; - /** @var Map */ + /** @var Map */ protected Map $rankVarSet; - /** @var Map */ + /** @var Map */ protected ?Map $accessLogRead; /** @var \sammo\ActionLogger */ @@ -59,8 +59,8 @@ class General extends GeneralLite implements iAction * @param null|Map $rawRank * @param null|Map $rawAccessLog * @param null|array $city DB city 테이블의 row값 - * @param int|null $year 게임 연도 - * @param int|null $month 게임 월 + * @param int $year 게임 연도 + * @param int $month 게임 월 */ public function __construct(array $raw, ?Map $rawRank, ?Map $rawAccessLog, ?array $city, ?array $nation, int $year, int $month) { @@ -931,7 +931,7 @@ class General extends GeneralLite implements iAction } if($queryMode < GeneralQueryMode::Full){ - throw new \InvalidArgumentException('충분하지 않은 queryMode:' . $queryMode); + throw new \InvalidArgumentException('충분하지 않은 queryMode:' . $queryMode->name); } $db = DB::db(); @@ -1013,7 +1013,7 @@ class General extends GeneralLite implements iAction static public function createGeneralObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): self { if($queryMode < GeneralQueryMode::Full){ - throw new \InvalidArgumentException('충분하지 않은 queryMode:' . $queryMode); + throw new \InvalidArgumentException('충분하지 않은 queryMode:' . $queryMode->name); } $db = DB::db(); diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php index fda9136b..5c761890 100644 --- a/hwe/sammo/GeneralLite.php +++ b/hwe/sammo/GeneralLite.php @@ -274,7 +274,7 @@ class GeneralLite * @param ?int[] $generalIDList * @param null|array $column * @param GeneralQueryMode $queryMode - * @return \sammo\Generalite[] + * @return \sammo\GeneralLite[] * @throws MustNotBeReachedException */ static public function createGeneralLiteObjListFromDB(?array $generalIDList, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::FullWithoutIAction): array @@ -284,7 +284,7 @@ class GeneralLite } if($queryMode > GeneralQueryMode::FullWithoutIAction){ - throw new \InvalidArgumentException('지원하지 않는 queryMode:' . $queryMode); + throw new \InvalidArgumentException('지원하지 않는 queryMode:' . $queryMode->name); } $db = DB::db(); @@ -371,7 +371,7 @@ class GeneralLite static public function createGeneralLiteObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::FullWithoutIAction): self { if($queryMode > GeneralQueryMode::FullWithoutIAction){ - throw new \InvalidArgumentException('지원하지 않는 queryMode:' . $queryMode); + throw new \InvalidArgumentException('지원하지 않는 queryMode:' . $queryMode->name); } $db = DB::db(); -- 2.54.0 From ac7c3c25b3fb1744018482bace5859546d8d9530 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 27 Jul 2023 17:14:48 +0000 Subject: [PATCH 04/19] =?UTF-8?q?fix:=20=EC=A4=80=EB=B9=84=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/GeneralLite.php | 45 ++------------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php index 5c761890..0412d01a 100644 --- a/hwe/sammo/GeneralLite.php +++ b/hwe/sammo/GeneralLite.php @@ -298,10 +298,8 @@ class GeneralLite /** * @var string[] $column - * @var RankColumn[] $rankColumn - * @var GeneralAccessLogColumn[] $accessLogColumn */ - [$column, $rankColumn, $accessLogColumn] = static::mergeQueryColumn($column, $queryMode); + [$column,,] = static::mergeQueryColumn($column, $queryMode); if ($generalIDList === null) { $rawGenerals = Util::convertArrayToDict( @@ -317,52 +315,13 @@ class GeneralLite ); } - - /** @var Map> */ - $rawRanks = new Map(); - if ($rankColumn) { - $rawValue = $db->queryAllLists( - 'SELECT `general_id`, `type`, `value` FROM rank_data WHERE general_id IN %li AND `type` IN %ls', - $generalIDList, - array_map(fn (\BackedEnum $e) => $e->value, $rankColumn) - ); - foreach ($rawValue as [$generalID, $rawRankType, $rankValue]) { - if (!$rawRanks->hasKey($generalID)) { - $rawRanks[$generalID] = new Map(); - } - - $rankType = RankColumn::from($rawRankType); - $rawRanks[$generalID][$rankType] = $rankValue; - } - } - - $rawAccessLogs = new Map(); - if ($accessLogColumn) { - $rawValue = $db->query( - 'SELECT `general_id`, %l FROM general_access_log WHERE general_id IN %li', - Util::formatListOfBackticks($accessLogColumn), - $generalIDList - ); - foreach ($rawValue as $rawLog) { - $generalID = $rawLog['general_id']; - $logValue = new Map(); - foreach ($rawLog as $key => $value) { - $logValue[GeneralAccessLogColumn::from($key)] = $value; - } - $rawAccessLogs[$generalID] = $logValue; - } - } - $result = []; foreach ($generalIDList as $generalID) { if (!key_exists($generalID, $rawGenerals)) { $result[$generalID] = new DummyGeneral($queryMode->value > 0); continue; } - if ($rawRanks->hasKey($generalID) && $rawRanks[$generalID]->count() !== count($rankColumn)) { - throw new \RuntimeException('column의 수가 일치하지 않음 : ' . $generalID); - } - $result[$generalID] = new static($rawGenerals[$generalID], $rawRanks[$generalID] ?? null, $rawAccessLogs[$generalID] ?? null, null, null, $year, $month, $queryMode->value >= GeneralQueryMode::Full->value); + $result[$generalID] = new static($rawGenerals[$generalID], null, null, $year, $month); } return $result; -- 2.54.0 From af8a417dc102cfefbb1199248b4ee50c840de6ce Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 27 Jul 2023 17:23:11 +0000 Subject: [PATCH 05/19] =?UTF-8?q?refac,=20wip:=20GeneralLite=EC=97=90?= =?UTF-8?q?=EB=8A=94=20RankVar=EA=B0=80=20=EC=9D=BD=EA=B8=B0=EC=A0=84?= =?UTF-8?q?=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=ED=95=84=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/GeneralLite.php | 65 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php index 0412d01a..d692f75d 100644 --- a/hwe/sammo/GeneralLite.php +++ b/hwe/sammo/GeneralLite.php @@ -17,6 +17,9 @@ class GeneralLite protected $raw = []; protected $rawCity = null; + /** @var Map */ + protected Map $rankVarRead; + /** @var \sammo\ActionLogger */ protected $logger; @@ -49,7 +52,7 @@ class GeneralLite * @param int|null $year 게임 연도 * @param int|null $month 게임 월 */ - public function __construct(array $raw, ?array $city, ?array $nation, ?int $year, ?int $month) + public function __construct(array $raw, ?Map $rawRank, ?array $city, ?array $nation, ?int $year, ?int $month) { if ($nation === null) { $nation = getNationStaticInfo($raw['nation']); @@ -61,6 +64,12 @@ class GeneralLite if ($year !== null && $month !== null) { $this->initLogger($year, $month); } + + if ($rawRank) { + $this->rankVarRead = $rawRank; + } else { + $this->rankVarRead = new Map(); + } } function initLogger(int $year, int $month) @@ -163,6 +172,20 @@ class GeneralLite $this->raw[$key] = $value; } + + function getRankVar(RankColumn $key, $defaultValue = null): int + { + if (!$this->rankVarRead->hasKey($key)) { + if ($defaultValue === null) { + throw new \RuntimeException('인자가 없음 : ' . $key->value); + } + return $defaultValue; + } + + return $this->rankVarRead[$key]; + } + + /** * @param \MeekroDB $db */ @@ -299,7 +322,7 @@ class GeneralLite /** * @var string[] $column */ - [$column,,] = static::mergeQueryColumn($column, $queryMode); + [$column, $rankColumn,] = static::mergeQueryColumn($column, $queryMode); if ($generalIDList === null) { $rawGenerals = Util::convertArrayToDict( @@ -315,13 +338,31 @@ class GeneralLite ); } + /** @var Map> */ + $rawRanks = new Map(); + if ($rankColumn) { + $rawValue = $db->queryAllLists( + 'SELECT `general_id`, `type`, `value` FROM rank_data WHERE general_id IN %li AND `type` IN %ls', + $generalIDList, + array_map(fn (\BackedEnum $e) => $e->value, $rankColumn) + ); + foreach ($rawValue as [$generalID, $rawRankType, $rankValue]) { + if (!$rawRanks->hasKey($generalID)) { + $rawRanks[$generalID] = new Map(); + } + + $rankType = RankColumn::from($rawRankType); + $rawRanks[$generalID][$rankType] = $rankValue; + } + } + $result = []; foreach ($generalIDList as $generalID) { if (!key_exists($generalID, $rawGenerals)) { $result[$generalID] = new DummyGeneral($queryMode->value > 0); continue; } - $result[$generalID] = new static($rawGenerals[$generalID], null, null, $year, $month); + $result[$generalID] = new static($rawGenerals[$generalID], $rawRanks[$generalID] ?? null, null, null, $year, $month); } return $result; @@ -344,8 +385,9 @@ class GeneralLite /** * @var string[] $column + * @var RankColumn[] $rankColumn */ - [$column,,] = static::mergeQueryColumn($column, $queryMode); + [$column, $rankColumn,] = static::mergeQueryColumn($column, $queryMode); $rawGeneral = $db->queryFirstRow('SELECT %l FROM general WHERE no = %i', Util::formatListOfBackticks($column), $generalID); @@ -353,7 +395,20 @@ class GeneralLite return new DummyGeneral($queryMode->value > 0); } - $general = new static($rawGeneral, null, null, $year, $month); + $rawRankValues = new Map(); + if ($rankColumn) { + $rawValue = $db->queryAllLists( + 'SELECT `type`, `value` FROM rank_data WHERE general_id = %i AND `type` IN %ls', + $generalID, + array_map(fn (\BackedEnum $e) => $e->value, $rankColumn) + ); + foreach ($rawValue as [$rawRankType, $rankValue]) { + $rankType = RankColumn::tryFrom($rawRankType); + $rawRankValues->put($rankType, $rankValue); + } + } + + $general = new static($rawGeneral, $rawRankValues, null, null, $year, $month); return $general; } -- 2.54.0 From 07035b5a1271fac7eb997cff2ca52907f967aa0d Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 27 Jul 2023 17:26:43 +0000 Subject: [PATCH 06/19] =?UTF-8?q?wip:=20=EA=B0=92=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/General.php | 5 ++++- hwe/sammo/GeneralLite.php | 12 ------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 9d4a6ad8..d7643d88 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -478,8 +478,11 @@ class General extends GeneralLite implements iAction } } - function updateVar(string $key, $value) + function updateVar(string|\BackedEnum $key, $value) { + if($key instanceof \BackedEnum){ + $key = $key->value; + } if (($this->raw[$key] ?? null) === $value) { return; } diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php index d692f75d..90bd1cb9 100644 --- a/hwe/sammo/GeneralLite.php +++ b/hwe/sammo/GeneralLite.php @@ -161,18 +161,6 @@ class GeneralLite return $this->getVar("dex{$armType}"); } - function updateVar(string $key, $value) - { - if (($this->raw[$key] ?? null) === $value) { - return; - } - if (!key_exists($key, $this->updatedVar)) { - $this->updatedVar[$key] = true; - } - $this->raw[$key] = $value; - } - - function getRankVar(RankColumn $key, $defaultValue = null): int { if (!$this->rankVarRead->hasKey($key)) { -- 2.54.0 From 982ce86ad814019f8e7722c1a03325e06dd45c2c Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 29 Jul 2023 18:25:45 +0000 Subject: [PATCH 07/19] =?UTF-8?q?misc:=20phan=20=EA=B2=BD=EA=B3=A0=20?= =?UTF-8?q?=EC=88=98=EC=A4=80=EC=9D=84=20CRITICAL=EB=A1=9C=20-=20General?= =?UTF-8?q?=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=ED=98=B8=ED=99=98=EC=9A=A9?= =?UTF-8?q?=EB=8F=84=EB=A1=9C=EB=8A=94=20=EC=9D=B4=EC=A0=95=EB=8F=84?= =?UTF-8?q?=EB=A1=9C=20=EC=B6=A9=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .phan/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.phan/config.php b/.phan/config.php index 4f979335..935a411f 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -18,7 +18,7 @@ return [ "target_php_version" => '8.1', "minimum_target_php_version" => '8.1', 'backward_compatibility_checks ' => true, - 'minimum_severity' => \Phan\Issue::SEVERITY_NORMAL, + 'minimum_severity' => \Phan\Issue::SEVERITY_CRITICAL, 'file_list' => [ 'f_config/config.php', -- 2.54.0 From ed035ab75f088bc6bbc9289e9f8ad371ab8ab113 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 29 Jul 2023 18:35:54 +0000 Subject: [PATCH 08/19] =?UTF-8?q?fix:=20Phan=20Critical=20=EA=B2=BD?= =?UTF-8?q?=EA=B3=A0=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/Constraint/ReqGeneralCrewMargin.php | 2 +- hwe/sammo/General.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/hwe/sammo/Constraint/ReqGeneralCrewMargin.php b/hwe/sammo/Constraint/ReqGeneralCrewMargin.php index 1f8f5e8d..0896bb1f 100644 --- a/hwe/sammo/Constraint/ReqGeneralCrewMargin.php +++ b/hwe/sammo/Constraint/ReqGeneralCrewMargin.php @@ -39,7 +39,7 @@ class ReqGeneralCrewMargin extends Constraint{ //XXX: 왜 General -> obj -> General 변환을 하고 있나? //FIXME: RankVar, city에 따라 통솔이 바뀐다면 이 부분에 문제가 발생. - $generalObj = new General($this->general, null, null, null, null, null, null, true); + $generalObj = new General($this->general, null, null, null, null, 180, 1); if($reqCrewType->id != $generalObj->getCrewTypeObj()->id){ return true; diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index d7643d88..0012c40a 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -1004,10 +1004,14 @@ class General extends GeneralLite implements iAction $result[$generalID] = new DummyGeneral($queryMode->value > 0); continue; } - if ($rawRanks->hasKey($generalID) && $rawRanks[$generalID]->count() !== count($rankColumn)) { + /** @var Map */ + $generalRankValues = $rawRanks[$generalID] ?? new Map(); + if ($generalRankValues->count() !== count($rankColumn)) { throw new \RuntimeException('column의 수가 일치하지 않음 : ' . $generalID); } - $result[$generalID] = new static($rawGenerals[$generalID], $rawRanks[$generalID] ?? null, $rawAccessLogs[$generalID] ?? null, null, null, $year, $month); + + $generalAccessLog = $rawAccessLogs[$generalID] ?? new Map(); + $result[$generalID] = new static($rawGenerals[$generalID], $generalRankValues, $generalAccessLog, null, null, $year, $month); } return $result; -- 2.54.0 From 0c53d77e61fa175b4cbca958e07f51a0bf7e2b62 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 29 Jul 2023 18:50:11 +0000 Subject: [PATCH 09/19] =?UTF-8?q?refac:=20General=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EA=B4=80=EB=A0=A8=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func.php | 3 +-- hwe/func_time_event.php | 9 ++++++++- hwe/process_war.php | 2 +- hwe/sammo/AutorunNationPolicy.php | 2 +- hwe/v_NPCControl.php | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/hwe/func.php b/hwe/func.php index adae4f2f..0dbc7e78 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -149,7 +149,7 @@ function getRandGenName(RandUtil $rng) -function cityInfo(General $generalObj) +function cityInfo(GeneralLite $generalObj) { $db = DB::db(); @@ -1721,7 +1721,6 @@ function deleteNation(General $lord, bool $applyDB): array $lordID ), ['npc', 'owner', 'gold', 'rice', 'experience', 'explevel', 'dedication', 'dedlevel', 'belong', 'aux'], - GeneralQueryMode::Lite, ); $nationGeneralList[$lordID] = $lord; diff --git a/hwe/func_time_event.php b/hwe/func_time_event.php index 22086dd8..bd1086b4 100644 --- a/hwe/func_time_event.php +++ b/hwe/func_time_event.php @@ -364,7 +364,14 @@ function disaster(RandUtil $rng) { $logger->flush(); if (!$isGood) { - $generalListByCity = Util::arrayGroupBy($db->query('SELECT no, name, nation, city, officer_level, injury, leadership, strength, intel, horse, weapon, book, item, crew, crewtype, atmos, train, special, special2 FROM general WHERE city IN %li', Util::squeezeFromArray($targetCityList, 'city')), 'city'); + [$queryColumns,,] = General::mergeQueryColumn(); + $generalListByCity = Util::arrayGroupBy( + $db->query( + 'SELECT %l FROM general WHERE city IN %li', + Util::formatListOfBackticks($queryColumns), + Util::squeezeFromArray($targetCityList, 'city') + ), + 'city'); //NOTE: 쿼리 1번이지만 복잡하기 vs 쿼리 여러번이지만 조금 더 깔끔하기 foreach ($targetCityList as $city) { $affectRatio = Util::valueFit($city['secu'] / $city['secu_max'] / 0.8, 0, 1); diff --git a/hwe/process_war.php b/hwe/process_war.php index c7789a69..1d65d37c 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -599,7 +599,7 @@ function ConquerCity(array $admin, General $general, array $city) Util::formatListOfBackticks(General::mergeQueryColumn(['npc', 'gold', 'rice', 'experience', 'explevel', 'belong', 'dedication', 'dedlevel', 'aux'], GeneralQueryMode::Lite)[0]), $defenderNationID, 12 - ), null, null, $city, $loseNation, $year, $month, false); + ), null, null, $city, $loseNation, $year, $month); $josaUl = JosaUtil::pick($defenderNationName, '을'); $attackerLogger->pushNationalHistoryLog("{$defenderNationName}{$josaUl} 정복"); diff --git a/hwe/sammo/AutorunNationPolicy.php b/hwe/sammo/AutorunNationPolicy.php index 86748efa..3323041d 100644 --- a/hwe/sammo/AutorunNationPolicy.php +++ b/hwe/sammo/AutorunNationPolicy.php @@ -179,7 +179,7 @@ class AutorunNationPolicy { 'cureThreshold'=>10, ]; - function __construct(General $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env) + function __construct(GeneralLite $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env) { foreach(static::$defaultPolicy as $policy=>$value){ $this->{$policy} = $value; diff --git a/hwe/v_NPCControl.php b/hwe/v_NPCControl.php index c9307359..59946efd 100644 --- a/hwe/v_NPCControl.php +++ b/hwe/v_NPCControl.php @@ -43,7 +43,7 @@ $nationStor = KVStorage::getStorage($db, $nationID, 'nation_env'); $nationStor->cacheValues(['npc_nation_policy', 'npc_general_policy']); $gameStor->cacheAll(); -$general = new General($me, null, null, null, $nation, $gameStor->year, $gameStor->month, false); +$general = General::createGeneralObjFromDB($me['no']); $rawServerPolicy = $gameStor->getValue('npc_nation_policy') ?? []; $rawNationPolicy = $nationStor->getValue('npc_nation_policy') ?? []; -- 2.54.0 From f7e5a93fb992f657a50b5850f77d106252c3b100 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 30 Jul 2023 12:51:53 +0000 Subject: [PATCH 10/19] misc: phan setting --- .phan/config.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 935a411f..6d7666c1 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -15,9 +15,8 @@ return [ // Note that the **only** effect of choosing `'5.6'` is to infer // that functions removed in php 7.0 exist. // (See `backward_compatibility_checks` for additional options) - "target_php_version" => '8.1', - "minimum_target_php_version" => '8.1', - 'backward_compatibility_checks ' => true, + "target_php_version" => '8.2', + "minimum_target_php_version" => '8.2', 'minimum_severity' => \Phan\Issue::SEVERITY_CRITICAL, 'file_list' => [ -- 2.54.0 From 822b5d312552f2762eb920772f04a9f29d6ecb31 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 30 Jul 2023 13:05:19 +0000 Subject: [PATCH 11/19] =?UTF-8?q?refac:=20GeneralBase,=20GeneralLite,=20Ge?= =?UTF-8?q?neral=20-=20GeneralLite=20->=20General=20=EA=B5=AC=EC=A1=B0?= =?UTF-8?q?=EB=8A=94=20PHP=EC=97=90=EC=84=9C=20=EA=B2=BD=EA=B3=A0=EB=A5=BC?= =?UTF-8?q?=20=EC=95=88=EB=9D=84=EC=9B=9F=EC=84=9C=20=ED=8F=AC=EA=B8=B0=20?= =?UTF-8?q?-=20GeneralBase=EC=97=90=EC=84=9C=20=EA=B0=81=EA=B0=81=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=ED=95=98=EB=8A=94=20=ED=98=95=ED=83=9C?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20-=20=EC=97=AC=EC=A0=84?= =?UTF-8?q?=ED=9E=88=20GeneralBase=EB=A5=BC=20=EC=9D=B8=EC=9E=90=EB=A1=9C?= =?UTF-8?q?=20=EB=B0=9B=EB=8A=94=20=ED=95=A8=EC=88=98=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=20=20GeneralLite=EB=A5=BC=20=EC=9A=94=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EA=B1=B0=EB=82=98,=20General=EC=9D=84=20=EC=9A=94=EA=B5=AC?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=ED=95=A8=EC=88=98=EB=A5=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EB=A1=9C=20=ED=98=B8=EC=B6=9C=ED=95=A0=20=EB=95=8C=20?= =?UTF-8?q?=20=20=EA=B2=BD=EA=B3=A0=EA=B0=80=20=EC=97=86=EC=9C=BC=EB=AF=80?= =?UTF-8?q?=EB=A1=9C=20=ED=8A=B9=ED=9E=88=20=EC=A3=BC=EC=9D=98=ED=95=B4?= =?UTF-8?q?=EC=95=BC=20=ED=95=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/AutorunGeneralPolicy.php | 18 +-- hwe/sammo/AutorunNationPolicy.php | 2 +- hwe/sammo/General.php | 8 +- hwe/sammo/GeneralBase.php | 228 +++++++++++++++++++++++++++++ hwe/sammo/GeneralLite.php | 222 +--------------------------- 5 files changed, 240 insertions(+), 238 deletions(-) create mode 100644 hwe/sammo/GeneralBase.php diff --git a/hwe/sammo/AutorunGeneralPolicy.php b/hwe/sammo/AutorunGeneralPolicy.php index ac3b8cfc..6b5419fb 100644 --- a/hwe/sammo/AutorunGeneralPolicy.php +++ b/hwe/sammo/AutorunGeneralPolicy.php @@ -19,7 +19,7 @@ class AutorunGeneralPolicy{ static $소집해제 = '소집해제'; static $출병 = '출병'; - + //static $NPC증여 = 'NPC증여'; static $NPC헌납 = 'NPC헌납'; static $NPC사망대비 = 'NPC사망대비'; @@ -31,12 +31,12 @@ class AutorunGeneralPolicy{ static $귀환 = '귀환'; //static $전투이동 = '전투이동'; //static $내정이동 = '내정이동'; - + static $국가선택 = '국가선택'; static $집합 = '집합'; static $건국 = '건국'; static $선양 = '선양'; - + static public array $default_priority = [ @@ -74,7 +74,7 @@ class AutorunGeneralPolicy{ public $can소집해제 = true; public $can출병 = true; - + //public $canNPC증여 = true; public $canNPC헌납 = true; @@ -91,7 +91,7 @@ class AutorunGeneralPolicy{ public array $priority; - function doNPCState(General $general){ + function doNPCState(GeneralBase $general){ $npc = $general->getNPCType(); $nationID = $general->getNationID(); @@ -115,7 +115,7 @@ class AutorunGeneralPolicy{ } - function __construct(General $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env){ + function __construct(GeneralBase $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env){ $this->priority = static::$default_priority; if($serverPolicy && key_exists('priority', $serverPolicy)){ @@ -165,7 +165,7 @@ class AutorunGeneralPolicy{ $this->can전투준비 = false; $this->can출병 = false; - + //$this->canNPC증여 = false; $this->canNPC헌납 = false; @@ -194,9 +194,9 @@ class AutorunGeneralPolicy{ $this->can금쌀구매 = true; $this->can상인무시 = true; break; - case 'recruit_high': + case 'recruit_high': $this->can모병 = true; - case 'recruit': + case 'recruit': $this->can징병 = true; $this->can소집해제 = true; $this->can금쌀구매 = true; diff --git a/hwe/sammo/AutorunNationPolicy.php b/hwe/sammo/AutorunNationPolicy.php index 3323041d..836fdd5e 100644 --- a/hwe/sammo/AutorunNationPolicy.php +++ b/hwe/sammo/AutorunNationPolicy.php @@ -179,7 +179,7 @@ class AutorunNationPolicy { 'cureThreshold'=>10, ]; - function __construct(GeneralLite $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env) + function __construct(GeneralBase $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env) { foreach(static::$defaultPolicy as $policy=>$value){ $this->{$policy} = $value; diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 0012c40a..47c8f772 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -10,11 +10,8 @@ use sammo\Enums\InheritanceKey; use sammo\Enums\RankColumn; use sammo\WarUnitTrigger as WarUnitTrigger; -class General extends GeneralLite implements iAction +class General extends GeneralBase implements iAction { - protected $rawCity = null; - - /** @var Map */ protected Map $rankVarRead; /** @var Map */ @@ -25,9 +22,6 @@ class General extends GeneralLite implements iAction /** @var Map */ protected ?Map $accessLogRead; - /** @var \sammo\ActionLogger */ - protected $logger; - protected $activatedSkill = []; protected $logActivatedSkill = []; protected $isFinished = false; diff --git a/hwe/sammo/GeneralBase.php b/hwe/sammo/GeneralBase.php new file mode 100644 index 00000000..865e10f2 --- /dev/null +++ b/hwe/sammo/GeneralBase.php @@ -0,0 +1,228 @@ + */ + protected Map $rankVarRead; + + /** @var \sammo\ActionLogger */ + protected $logger; + + const TURNTIME_FULL_MS = -1; + const TURNTIME_FULL = 0; + const TURNTIME_HMS = 1; + const TURNTIME_HM = 2; + + protected static $prohibitedDirectUpdateVars = [ + //Reason: iAction + 'leadership' => 1, + 'power' => 1, + 'intel' => 1, + 'nation' => 2, + 'officer_level' => 1, + //NOTE: officerLevelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남. + 'special' => 1, + 'special2' => 1, + 'personal' => 1, + 'horse' => 1, + 'weapon' => 1, + 'book' => 1, + 'item' => 1 + ]; + + function initLogger(int $year, int $month) + { + $this->logger = new ActionLogger( + $this->getVar('no'), + $this->getVar('nation'), + $year, + $month, + false + ); + } + + function getTurnTime(int $short = self::TURNTIME_FULL_MS): ?string + { + if(!key_exists('turntime', $this->raw)){ + return null; + } + + return [ + self::TURNTIME_FULL_MS => function ($turntime) { + return $turntime; + }, + self::TURNTIME_FULL => function ($turntime) { + return substr($turntime, 0, 19); + }, + self::TURNTIME_HMS => function ($turntime) { + return substr($turntime, 11, 8); + }, + self::TURNTIME_HM => function ($turntime) { + return substr($turntime, 11, 5); + }, + ][$short]($this->getVar('turntime')); + } + + function getNPCType(): int + { + return $this->raw['npc']; + } + + function getName(): string + { + return $this->raw['name']; + } + + function getID(): int + { + return $this->raw['no']; + } + + function getRawCity(): ?array + { + return $this->rawCity; + } + + function setRawCity(?array $city) + { + $this->rawCity = $city; + } + + function getCityID(): int + { + return $this->raw['city']; + } + + function getNationID(): int + { + return $this->raw['nation']; + } + + function getStaticNation(): array + { + return getNationStaticInfo($this->raw['nation']); + } + + function getLogger(): ?ActionLogger + { + return $this->logger; + } + + function getDex(GameUnitDetail $crewType) + { + $armType = $crewType->armType; + + if ($armType == GameUnitConst::T_CASTLE) { + $armType = GameUnitConst::T_SIEGE; + } + + return $this->getVar("dex{$armType}"); + } + + function getRankVar(RankColumn $key, $defaultValue = null): int + { + if (!$this->rankVarRead->hasKey($key)) { + if ($defaultValue === null) { + throw new \RuntimeException('인자가 없음 : ' . $key->value); + } + return $defaultValue; + } + + return $this->rankVarRead[$key]; + } + + abstract function applyDB($db): bool; + + static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array + { + $minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city']; + $defaultEventColumn = [ + 'no', 'name', 'npc', 'owner', 'city', 'nation', 'officer_level', 'officer_city', + 'special', 'special2', 'personal', + 'horse', 'weapon', 'book', 'item', 'last_turn', 'aux', 'turntime', + ]; + $fullColumn = [ + 'no', 'name', 'owner', 'owner_name', 'picture', 'imgsvr', 'nation', 'city', 'troop', 'injury', 'affinity', + 'leadership', 'leadership_exp', 'strength', 'strength_exp', 'intel', 'intel_exp', 'weapon', 'book', 'horse', 'item', + 'experience', 'dedication', 'officer_level', 'officer_city', 'gold', 'rice', 'crew', 'crewtype', 'train', 'atmos', 'turntime', + 'makelimit', 'killturn', 'block', 'dedlevel', 'explevel', 'age', 'startage', 'belong', + 'personal', 'special', 'special2', 'defence_train', 'tnmt', 'npc', 'npc_org', 'deadyear', 'npcmsg', + 'dex1', 'dex2', 'dex3', 'dex4', 'dex5', 'betray', + 'recent_war', 'last_turn', 'myset', + 'specage', 'specage2', 'aux', 'permission', 'penalty', + ]; + $fullAcessLogColumn = [ + GeneralAccessLogColumn::refreshScore, + GeneralAccessLogColumn::refreshScoreTotal, + ]; + + if ($reqColumns === null) { + switch ($queryMode) { + case GeneralQueryMode::Core: + return [$minimumColumn, [], []]; + case GeneralQueryMode::Lite: + return [$defaultEventColumn, [], []]; + case GeneralQueryMode::FullWithoutIAction: + case GeneralQueryMode::Full: + return [$fullColumn, RankColumn::cases(), []]; + case GeneralQueryMode::FullWithAccessLog: + return [$fullColumn, RankColumn::cases(), $fullAcessLogColumn]; + } + } + + /** @var RankColumn[] */ + $rankColumn = []; + $subColumn = []; + $accessLogColumn = []; + foreach ($reqColumns as $column) { + if ($column instanceof RankColumn) { + $rankColumn[] = $column; + continue; + } + if ($column instanceof GeneralAccessLogColumn) { + $accessLogColumn[] = $column; + continue; + } + + + $enumKey = RankColumn::tryFrom($column); + if ($enumKey !== null) { + $rankColumn[] = $enumKey; + continue; + } + $enumKey = GeneralAccessLogColumn::tryFrom($column); + if ($enumKey !== null) { + $accessLogColumn[] = $enumKey; + continue; + } + $subColumn[] = $column; + } + + switch ($queryMode) { + case GeneralQueryMode::Core: + return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralQueryMode::Lite: + return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralQueryMode::FullWithoutIAction: + case GeneralQueryMode::Full: + return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralQueryMode::FullWithAccessLog: + return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, array_unique(array_merge($fullAcessLogColumn, $accessLogColumn))]; + default: + throw new \RuntimeException('invalid query mode'); + } + } + +} diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php index 90bd1cb9..96c55500 100644 --- a/hwe/sammo/GeneralLite.php +++ b/hwe/sammo/GeneralLite.php @@ -3,49 +3,11 @@ namespace sammo; use Ds\Map; -use sammo\Command\GeneralCommand; -use sammo\Enums\GeneralAccessLogColumn; use sammo\Enums\GeneralQueryMode; -use sammo\Enums\InheritanceKey; use sammo\Enums\RankColumn; -use sammo\WarUnitTrigger as WarUnitTrigger; -class GeneralLite +class GeneralLite extends GeneralBase { - use LazyVarUpdater; - - protected $raw = []; - protected $rawCity = null; - - /** @var Map */ - protected Map $rankVarRead; - - /** @var \sammo\ActionLogger */ - protected $logger; - - const TURNTIME_FULL_MS = -1; - const TURNTIME_FULL = 0; - const TURNTIME_HMS = 1; - const TURNTIME_HM = 2; - - protected static $prohibitedDirectUpdateVars = [ - //Reason: iAction - 'leadership' => 1, - 'power' => 1, - 'intel' => 1, - 'nation' => 2, - 'officer_level' => 1, - //NOTE: officerLevelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남. - 'special' => 1, - 'special2' => 1, - 'personal' => 1, - 'horse' => 1, - 'weapon' => 1, - 'book' => 1, - 'item' => 1 - ]; - - /** * @param array $raw DB row값. * @param null|array $city DB city 테이블의 row값 @@ -72,108 +34,6 @@ class GeneralLite } } - function initLogger(int $year, int $month) - { - $this->logger = new ActionLogger( - $this->getVar('no'), - $this->getVar('nation'), - $year, - $month, - false - ); - } - - function getTurnTime(int $short = self::TURNTIME_FULL_MS): ?string - { - if(!key_exists('turntime', $this->raw)){ - return null; - } - - return [ - self::TURNTIME_FULL_MS => function ($turntime) { - return $turntime; - }, - self::TURNTIME_FULL => function ($turntime) { - return substr($turntime, 0, 19); - }, - self::TURNTIME_HMS => function ($turntime) { - return substr($turntime, 11, 8); - }, - self::TURNTIME_HM => function ($turntime) { - return substr($turntime, 11, 5); - }, - ][$short]($this->getVar('turntime')); - } - - function getNPCType(): int - { - return $this->raw['npc']; - } - - function getName(): string - { - return $this->raw['name']; - } - - function getID(): int - { - return $this->raw['no']; - } - - function getRawCity(): ?array - { - return $this->rawCity; - } - - function setRawCity(?array $city) - { - $this->rawCity = $city; - } - - function getCityID(): int - { - return $this->raw['city']; - } - - function getNationID(): int - { - return $this->raw['nation']; - } - - function getStaticNation(): array - { - return getNationStaticInfo($this->raw['nation']); - } - - function getLogger(): ?ActionLogger - { - return $this->logger; - } - - function getDex(GameUnitDetail $crewType) - { - $armType = $crewType->armType; - - if ($armType == GameUnitConst::T_CASTLE) { - $armType = GameUnitConst::T_SIEGE; - } - - return $this->getVar("dex{$armType}"); - } - - function getRankVar(RankColumn $key, $defaultValue = null): int - { - if (!$this->rankVarRead->hasKey($key)) { - if ($defaultValue === null) { - throw new \RuntimeException('인자가 없음 : ' . $key->value); - } - return $defaultValue; - } - - return $this->rankVarRead[$key]; - } - - /** * @param \MeekroDB $db */ @@ -201,86 +61,6 @@ class GeneralLite return $result; } - static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array - { - $minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city']; - $defaultEventColumn = [ - 'no', 'name', 'npc', 'owner', 'city', 'nation', 'officer_level', 'officer_city', - 'special', 'special2', 'personal', - 'horse', 'weapon', 'book', 'item', 'last_turn', 'aux', 'turntime', - ]; - $fullColumn = [ - 'no', 'name', 'owner', 'owner_name', 'picture', 'imgsvr', 'nation', 'city', 'troop', 'injury', 'affinity', - 'leadership', 'leadership_exp', 'strength', 'strength_exp', 'intel', 'intel_exp', 'weapon', 'book', 'horse', 'item', - 'experience', 'dedication', 'officer_level', 'officer_city', 'gold', 'rice', 'crew', 'crewtype', 'train', 'atmos', 'turntime', - 'makelimit', 'killturn', 'block', 'dedlevel', 'explevel', 'age', 'startage', 'belong', - 'personal', 'special', 'special2', 'defence_train', 'tnmt', 'npc', 'npc_org', 'deadyear', 'npcmsg', - 'dex1', 'dex2', 'dex3', 'dex4', 'dex5', 'betray', - 'recent_war', 'last_turn', 'myset', - 'specage', 'specage2', 'aux', 'permission', 'penalty', - ]; - $fullAcessLogColumn = [ - GeneralAccessLogColumn::refreshScore, - GeneralAccessLogColumn::refreshScoreTotal, - ]; - - if ($reqColumns === null) { - switch ($queryMode) { - case GeneralQueryMode::Core: - return [$minimumColumn, [], []]; - case GeneralQueryMode::Lite: - return [$defaultEventColumn, [], []]; - case GeneralQueryMode::FullWithoutIAction: - case GeneralQueryMode::Full: - return [$fullColumn, RankColumn::cases(), []]; - case GeneralQueryMode::FullWithAccessLog: - return [$fullColumn, RankColumn::cases(), $fullAcessLogColumn]; - } - } - - /** @var RankColumn[] */ - $rankColumn = []; - $subColumn = []; - $accessLogColumn = []; - foreach ($reqColumns as $column) { - if ($column instanceof RankColumn) { - $rankColumn[] = $column; - continue; - } - if ($column instanceof GeneralAccessLogColumn) { - $accessLogColumn[] = $column; - continue; - } - - - $enumKey = RankColumn::tryFrom($column); - if ($enumKey !== null) { - $rankColumn[] = $enumKey; - continue; - } - $enumKey = GeneralAccessLogColumn::tryFrom($column); - if ($enumKey !== null) { - $accessLogColumn[] = $enumKey; - continue; - } - $subColumn[] = $column; - } - - switch ($queryMode) { - case GeneralQueryMode::Core: - return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::Lite: - return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::FullWithoutIAction: - case GeneralQueryMode::Full: - return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::FullWithAccessLog: - return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, array_unique(array_merge($fullAcessLogColumn, $accessLogColumn))]; - default: - throw new \RuntimeException('invalid query mode'); - } - } - /** * @param ?int[] $generalIDList * @param null|array $column -- 2.54.0 From 6b91a800fa74df523011da2e34889277ae931cc2 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 30 Jul 2023 13:08:50 +0000 Subject: [PATCH 12/19] refac: DummyGeneralLite --- hwe/sammo/DummyGeneralLite.php | 45 ++++++++++++++++++++++++++++++++++ hwe/sammo/GeneralLite.php | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 hwe/sammo/DummyGeneralLite.php diff --git a/hwe/sammo/DummyGeneralLite.php b/hwe/sammo/DummyGeneralLite.php new file mode 100644 index 00000000..f4134cd5 --- /dev/null +++ b/hwe/sammo/DummyGeneralLite.php @@ -0,0 +1,45 @@ + 0, + 'name' => 'Dummy', + 'npc' => 3, + 'city' => 0, + 'nation' => 0, + 'officer_level' => 0, + 'crewtype' => -1, + 'turntime' => '2012-03-04 05:06:07.000000', + 'experience' => 0, + 'dedication' => 0, + 'gold' => 0, + 'rice' => 0, + 'leadership' => 10, + 'strength' => 10, + 'intel' => 10, + 'imgsvr' => 0, + 'picture' => 'default.jpg', + ]; + + $this->raw = $raw; + + if ($initLogger) { + $this->initLogger(1, 1); + } + } + + function applyDB($db): bool + { + if ($this->logger) { + $this->initLogger($this->logger->getYear(), $this->logger->getMonth()); + } + return true; + } +} diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php index 96c55500..0a310d70 100644 --- a/hwe/sammo/GeneralLite.php +++ b/hwe/sammo/GeneralLite.php @@ -160,7 +160,7 @@ class GeneralLite extends GeneralBase $rawGeneral = $db->queryFirstRow('SELECT %l FROM general WHERE no = %i', Util::formatListOfBackticks($column), $generalID); if (!$rawGeneral) { - return new DummyGeneral($queryMode->value > 0); + return new DummyGeneralLite($queryMode->value > 0); } $rawRankValues = new Map(); -- 2.54.0 From 29273d7a8b25a491d4d86c8d795d8f695a7c6ac3 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 30 Jul 2023 13:17:53 +0000 Subject: [PATCH 13/19] =?UTF-8?q?refac,wip:=20GeneralQueryMode=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC=20-=20GeneralQueryMode=20-=20General=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9A=A9=20-=20GeneralLiteQueryMode=20-=20GeneralLite?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=EC=9A=A9=20-=20=EC=9D=B4=EB=A5=BC=20?= =?UTF-8?q?=ED=86=B5=ED=95=B4=20=ED=99=95=EC=8B=A4=ED=95=9C=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20=EB=82=B4?= =?UTF-8?q?=EC=A4=84=20=EA=B2=83=EC=9C=BC=EB=A1=9C..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/b_betting.php | 2 +- hwe/sammo/Enums/GeneralLiteQueryMode.php | 14 ++++++++++++++ hwe/sammo/Enums/GeneralQueryMode.php | 6 ------ hwe/sammo/General.php | 8 -------- hwe/sammo/GeneralBase.php | 15 ++++++++------- hwe/sammo/GeneralLite.php | 14 +++++--------- 6 files changed, 28 insertions(+), 31 deletions(-) create mode 100644 hwe/sammo/Enums/GeneralLiteQueryMode.php diff --git a/hwe/b_betting.php b/hwe/b_betting.php index 35b4fae8..a024be23 100644 --- a/hwe/b_betting.php +++ b/hwe/b_betting.php @@ -569,7 +569,7 @@ if ($str3) { [$prizeColumn->value, $gameColumn->value, $winColumn->value, $drawColumn->value, $loseColumn->value, 'leadership', 'strength', 'intel', 'no', 'npc', 'name'], GeneralQueryMode::Core ); - usort($tournamentRankerList, function (General $lhs, General $rhs) use ($gameColumn, $winColumn, $drawColumn, $loseColumn) { + usort($tournamentRankerList, function (GeneralLite $lhs, GeneralLite $rhs) use ($gameColumn, $winColumn, $drawColumn, $loseColumn) { $result = - ($lhs->getRankVar($gameColumn) <=> $rhs->getRankVar($gameColumn)); if ($result !== 0) return $result; $result = - ( diff --git a/hwe/sammo/Enums/GeneralLiteQueryMode.php b/hwe/sammo/Enums/GeneralLiteQueryMode.php new file mode 100644 index 00000000..e449cc34 --- /dev/null +++ b/hwe/sammo/Enums/GeneralLiteQueryMode.php @@ -0,0 +1,14 @@ +name); - } - $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); @@ -1013,10 +1009,6 @@ class General extends GeneralBase implements iAction static public function createGeneralObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): self { - if($queryMode < GeneralQueryMode::Full){ - throw new \InvalidArgumentException('충분하지 않은 queryMode:' . $queryMode->name); - } - $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); diff --git a/hwe/sammo/GeneralBase.php b/hwe/sammo/GeneralBase.php index 865e10f2..9b9c6757 100644 --- a/hwe/sammo/GeneralBase.php +++ b/hwe/sammo/GeneralBase.php @@ -4,6 +4,7 @@ namespace sammo; use Ds\Map; use sammo\Enums\GeneralAccessLogColumn; +use sammo\Enums\GeneralLiteQueryMode; use sammo\Enums\GeneralQueryMode; use sammo\Enums\RankColumn; @@ -145,7 +146,7 @@ abstract class GeneralBase abstract function applyDB($db): bool; - static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array + static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode|GeneralLiteQueryMode $queryMode = GeneralQueryMode::Full): array { $minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city']; $defaultEventColumn = [ @@ -170,11 +171,11 @@ abstract class GeneralBase if ($reqColumns === null) { switch ($queryMode) { - case GeneralQueryMode::Core: + case GeneralLiteQueryMode::Core: return [$minimumColumn, [], []]; - case GeneralQueryMode::Lite: + case GeneralLiteQueryMode::Lite: return [$defaultEventColumn, [], []]; - case GeneralQueryMode::FullWithoutIAction: + case GeneralLiteQueryMode::Full: case GeneralQueryMode::Full: return [$fullColumn, RankColumn::cases(), []]; case GeneralQueryMode::FullWithAccessLog: @@ -211,11 +212,11 @@ abstract class GeneralBase } switch ($queryMode) { - case GeneralQueryMode::Core: + case GeneralLiteQueryMode::Core: return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::Lite: + case GeneralLiteQueryMode::Lite: return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::FullWithoutIAction: + case GeneralLiteQueryMode::Full: case GeneralQueryMode::Full: return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn]; case GeneralQueryMode::FullWithAccessLog: diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php index 0a310d70..93b664b8 100644 --- a/hwe/sammo/GeneralLite.php +++ b/hwe/sammo/GeneralLite.php @@ -3,7 +3,7 @@ namespace sammo; use Ds\Map; -use sammo\Enums\GeneralQueryMode; +use sammo\Enums\GeneralLiteQueryMode; use sammo\Enums\RankColumn; class GeneralLite extends GeneralBase @@ -64,17 +64,17 @@ class GeneralLite extends GeneralBase /** * @param ?int[] $generalIDList * @param null|array $column - * @param GeneralQueryMode $queryMode + * @param GeneralLiteQueryMode $queryMode * @return \sammo\GeneralLite[] * @throws MustNotBeReachedException */ - static public function createGeneralLiteObjListFromDB(?array $generalIDList, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::FullWithoutIAction): array + static public function createGeneralLiteObjListFromDB(?array $generalIDList, ?array $column = null, GeneralLiteQueryMode $queryMode = GeneralLiteQueryMode::Full): array { if ($generalIDList === []) { return []; } - if($queryMode > GeneralQueryMode::FullWithoutIAction){ + if($queryMode > GeneralLiteQueryMode::Full){ throw new \InvalidArgumentException('지원하지 않는 queryMode:' . $queryMode->name); } @@ -136,12 +136,8 @@ class GeneralLite extends GeneralBase return $result; } - static public function createGeneralLiteObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::FullWithoutIAction): self + static public function createGeneralLiteObjFromDB(int $generalID, ?array $column = null, GeneralLiteQueryMode $queryMode = GeneralLiteQueryMode::Full): self { - if($queryMode > GeneralQueryMode::FullWithoutIAction){ - throw new \InvalidArgumentException('지원하지 않는 queryMode:' . $queryMode->name); - } - $db = DB::db(); if ($queryMode->value > 0) { $gameStor = KVStorage::getStorage($db, 'game_env'); -- 2.54.0 From 55fca2337d7af4bbae54c7c867f3e94b1f973b42 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 30 Jul 2023 13:25:53 +0000 Subject: [PATCH 14/19] =?UTF-8?q?refac:=20General=20create=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/_admin2_submit.php | 2 +- hwe/_admin7.php | 2 +- hwe/_admin_force_rehall.php | 2 +- hwe/b_betting.php | 5 +++-- hwe/b_myPage.php | 2 +- hwe/func.php | 4 ++-- hwe/func_command.php | 4 ++-- hwe/func_gamerule.php | 4 ++-- hwe/func_tournament.php | 4 ++-- hwe/j_myBossInfo.php | 7 ++++--- hwe/j_set_my_setting.php | 2 +- hwe/j_update_picked_general.php | 2 +- hwe/old_index.php | 2 +- hwe/process_war.php | 2 +- hwe/sammo/API/Auction/BidBuyRiceAuction.php | 2 +- hwe/sammo/API/Auction/BidSellRiceAuction.php | 2 +- hwe/sammo/API/Auction/BidUniqueAuction.php | 2 +- hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php | 2 +- hwe/sammo/API/Auction/OpenBuyRiceAuction.php | 2 +- hwe/sammo/API/Auction/OpenSellRiceAuction.php | 2 +- hwe/sammo/API/Auction/OpenUniqueAuction.php | 2 +- hwe/sammo/API/General/BuildNationCandidate.php | 2 +- hwe/sammo/API/General/DieOnPrestart.php | 2 +- hwe/sammo/API/General/DropItem.php | 2 +- hwe/sammo/API/General/GetCommandTable.php | 2 +- hwe/sammo/API/General/GetFrontInfo.php | 2 +- hwe/sammo/API/InheritAction/BuyHiddenBuff.php | 2 +- hwe/sammo/API/InheritAction/BuyRandomUnique.php | 2 +- hwe/sammo/API/InheritAction/ResetSpecialWar.php | 2 +- hwe/sammo/API/InheritAction/ResetTurnTime.php | 2 +- hwe/sammo/API/InheritAction/SetNextSpecialWar.php | 2 +- hwe/sammo/API/Nation/GetNationInfo.php | 2 +- hwe/sammo/API/NationCommand/GetReservedCommand.php | 2 +- hwe/sammo/API/Vote/AddComment.php | 2 +- hwe/sammo/API/Vote/Vote.php | 2 +- hwe/sammo/Auction.php | 4 ++-- hwe/sammo/AuctionBasicResource.php | 6 +++--- hwe/sammo/Betting.php | 2 +- hwe/sammo/Command/General/che_등용.php | 6 +----- hwe/sammo/Command/General/che_등용수락.php | 2 +- hwe/sammo/Command/General/che_모반시도.php | 2 +- hwe/sammo/Command/General/che_선양.php | 2 +- hwe/sammo/Command/General/che_장수대상임관.php | 2 +- hwe/sammo/Command/General/che_증여.php | 2 +- hwe/sammo/Command/General/che_화계.php | 2 +- hwe/sammo/Command/Nation/che_몰수.php | 2 +- hwe/sammo/Command/Nation/che_발령.php | 2 +- hwe/sammo/Command/Nation/che_불가침수락.php | 2 +- hwe/sammo/Command/Nation/che_불가침파기수락.php | 2 +- hwe/sammo/Command/Nation/che_종전수락.php | 2 +- hwe/sammo/Command/Nation/che_포상.php | 2 +- hwe/sammo/Command/Nation/che_필사즉생.php | 2 +- hwe/sammo/Command/Nation/che_허보.php | 2 +- hwe/sammo/DiplomaticMessage.php | 6 +++--- hwe/sammo/Event/Action/LostUniqueItem.php | 2 +- hwe/sammo/Event/Action/MergeInheritPointRank.php | 2 +- hwe/sammo/Event/Action/ProvideNPCTroopLeader.php | 2 +- hwe/sammo/Event/Action/UpdateNationLevel.php | 4 ++-- hwe/sammo/General.php | 4 ++-- hwe/sammo/GeneralAI.php | 2 +- hwe/sammo/GeneralLite.php | 4 ++-- hwe/sammo/RaiseInvaderMessage.php | 2 +- hwe/sammo/ScoutMessage.php | 6 +++--- hwe/sammo/TurnExecutionHelper.php | 2 +- hwe/v_NPCControl.php | 2 +- hwe/v_chiefCenter.php | 2 +- hwe/v_inheritPoint.php | 2 +- hwe/v_processing.php | 2 +- 68 files changed, 87 insertions(+), 89 deletions(-) diff --git a/hwe/_admin2_submit.php b/hwe/_admin2_submit.php index 968d34d4..1f946345 100644 --- a/hwe/_admin2_submit.php +++ b/hwe/_admin2_submit.php @@ -33,7 +33,7 @@ $src = MessageTarget::buildQuick($session->generalID); $genObjList = []; $env = []; if ($genlist) { - $genObjList = General::createGeneralObjListFromDB($genlist); + $genObjList = General::createObjListFromDB($genlist); $env = $gameStor->cacheAll(); } switch ($btn) { diff --git a/hwe/_admin7.php b/hwe/_admin7.php index e5035cb3..f62cad85 100644 --- a/hwe/_admin7.php +++ b/hwe/_admin7.php @@ -76,7 +76,7 @@ if (!$gen) { $gen = $generalBasicList[0]['no']; } -$generalObj = General::createGeneralObjFromDB($gen, null, GeneralQueryMode::FullWithAccessLog); +$generalObj = General::createObjFromDB($gen, null, GeneralQueryMode::FullWithAccessLog); ?> diff --git a/hwe/_admin_force_rehall.php b/hwe/_admin_force_rehall.php index b4bce2b8..3f64f3ac 100644 --- a/hwe/_admin_force_rehall.php +++ b/hwe/_admin_force_rehall.php @@ -26,7 +26,7 @@ foreach ($db->queryFirstColumn( } $inheritPointManager = InheritancePointManager::getInstance(); -foreach(General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc = 0')) as $genObj){ +foreach(General::createObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc = 0')) as $genObj){ $inheritPointManager->mergeTotalInheritancePoint($genObj); $inheritPointManager->applyInheritanceUser($genObj->getVar('owner')); } \ No newline at end of file diff --git a/hwe/b_betting.php b/hwe/b_betting.php index a024be23..d6b234c3 100644 --- a/hwe/b_betting.php +++ b/hwe/b_betting.php @@ -2,6 +2,7 @@ namespace sammo; +use sammo\Enums\GeneralLiteQueryMode; use sammo\Enums\GeneralQueryMode; use sammo\Enums\RankColumn; @@ -564,10 +565,10 @@ if ($str3) { $winColumn = RankColumn::from("{$rankColumn}w"); $drawColumn = RankColumn::from("{$rankColumn}d"); $loseColumn = RankColumn::from("{$rankColumn}l"); - $tournamentRankerList = General::createGeneralObjListFromDB( + $tournamentRankerList = GeneralLite::createObjListFromDB( $db->queryFirstColumn('SELECT general_id FROM rank_data WHERE `type`= %s ORDER BY value DESC LIMIT 40', $gameColumn->value), [$prizeColumn->value, $gameColumn->value, $winColumn->value, $drawColumn->value, $loseColumn->value, 'leadership', 'strength', 'intel', 'no', 'npc', 'name'], - GeneralQueryMode::Core + GeneralLiteQueryMode::Core ); usort($tournamentRankerList, function (GeneralLite $lhs, GeneralLite $rhs) use ($gameColumn, $winColumn, $drawColumn, $loseColumn) { $result = - ($lhs->getRankVar($gameColumn) <=> $rhs->getRankVar($gameColumn)); diff --git a/hwe/b_myPage.php b/hwe/b_myPage.php index 9859e0e2..110bc8cb 100644 --- a/hwe/b_myPage.php +++ b/hwe/b_myPage.php @@ -24,7 +24,7 @@ $gameStor->cacheValues(['turntime', 'opentime', 'autorun_user', 'npcmode']); increaseRefresh("내정보", 1); -$me = General::createGeneralObjFromDB($generalID, null, GeneralQueryMode::FullWithAccessLog); +$me = General::createObjFromDB($generalID, null, GeneralQueryMode::FullWithAccessLog); $myset = $me->getVar('myset'); if ($myset > 0) { diff --git a/hwe/func.php b/hwe/func.php index 0dbc7e78..e8b198e9 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -1324,7 +1324,7 @@ function CheckHall($no) ["betrate", 'calc'], ]; - $generalObj = General::createGeneralObjFromDB($no); + $generalObj = General::createObjFromDB($no); $ttw = $generalObj->getRankVar(RankColumn::ttw); $ttd = $generalObj->getRankVar(RankColumn::ttd); @@ -1714,7 +1714,7 @@ function deleteNation(General $lord, bool $applyDB): array $logger->pushGlobalHistoryLog("【멸망】{$nationName}{$josaUn} 멸망했습니다."); - $nationGeneralList = General::createGeneralObjListFromDB( + $nationGeneralList = General::createObjListFromDB( $db->queryFirstColumn( 'SELECT `no` FROM general WHERE nation=%i AND no != %i', $nationID, diff --git a/hwe/func_command.php b/hwe/func_command.php index dbdf1b31..eebd0ca2 100644 --- a/hwe/func_command.php +++ b/hwe/func_command.php @@ -350,7 +350,7 @@ function setGeneralCommand(int $generalID, array $rawTurnList, string $command, $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); $env = $gameStor->getAll(); - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); try{ $commandObj = buildGeneralCommandClass($command, $general, $env, $arg); @@ -425,7 +425,7 @@ function setNationCommand(int $generalID, array $turnList, string $command, ?arr $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); $env = $gameStor->getAll(); - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if($general->getVar('officer_level') < 5){ return [ diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 465c97eb..fdfae574 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -451,7 +451,7 @@ function checkWander(RandUtil $rng) $wanderers = $db->queryFirstColumn('SELECT general.`no` FROM general LEFT JOIN nation ON general.nation = nation.nation WHERE nation.`level` = 0 AND general.`officer_level` = 12'); - foreach (General::createGeneralObjListFromDB($wanderers) as $wanderer) { + foreach (General::createObjListFromDB($wanderers) as $wanderer) { $wanderCmd = buildGeneralCommandClass('che_해산', $wanderer, $admin); if ($wanderCmd->hasFullConditionMet()) { $logger = $wanderer->getLogger(); @@ -743,7 +743,7 @@ function checkEmperior() } $inheritPointManager = InheritancePointManager::getInstance(); - $allUserGenerals = General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc < 2')); + $allUserGenerals = General::createObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc < 2')); foreach ($allUserGenerals as $genObj) { if ($genObj->getNationID() == $nationID) { if ($genObj->getVar('officer_level') > 4) { diff --git a/hwe/func_tournament.php b/hwe/func_tournament.php index 4973f31a..9cac4a1b 100644 --- a/hwe/func_tournament.php +++ b/hwe/func_tournament.php @@ -882,7 +882,7 @@ function setGift($tnmt_type, $tnmt, $phase) //포상 장수 이름, 금액 $resultHelper[$generalID]['reward'] += $cost; $resultHelper[$generalID]['msg'] = "4강 진출"; - General::createGeneralObjFromDB($generalID)->increaseInheritancePoint(InheritanceKey::tournament, 10); + General::createObjFromDB($generalID)->increaseInheritancePoint(InheritanceKey::tournament, 10); } //결승자 명성 돈 $cost = $admin['develcost'] * 6; @@ -946,7 +946,7 @@ function setGift($tnmt_type, $tnmt, $phase) $winnerLogger->pushGlobalHistoryLog("【대회】{$tp} 대회에서 {$winner['name']}{$josaYiWinner} 우승, {$runnerUp['name']}{$josaYiRunnerUp} 준우승을 차지하여 천하에 이름을 떨칩니다!", ActionLogger::EVENT_YEAR_MONTH); $winnerLogger->pushGlobalHistoryLog("【대회】{$tp} 대회의 우승자에게는 {$winnerRewardText}, 준우승자에겐 {$runnerUpRewardText}의 상금과 약간의 명성이 주어집니다!", ActionLogger::EVENT_YEAR_MONTH); - $generalObjList = General::createGeneralObjListFromDB(array_keys($resultHelper)); + $generalObjList = General::createObjListFromDB(array_keys($resultHelper)); foreach ($resultHelper as $generalID => $general) { $rewardText = number_format($general['reward']); diff --git a/hwe/j_myBossInfo.php b/hwe/j_myBossInfo.php index 53f69dfd..867668cb 100644 --- a/hwe/j_myBossInfo.php +++ b/hwe/j_myBossInfo.php @@ -1,6 +1,7 @@ setVar('nation', $nationID); } else{ - $general = General::createGeneralObjFromDB($destGeneralID, [ + $general = GeneralLite::createObjFromDB($destGeneralID, [ 'name', 'leadership', 'strength', 'intel', 'gold','rice', 'troop','officer_level','npc','picture','imgsvr', 'permission','penalty','belong', 'crewtype', 'experience', 'dedication', 'betray', 'dedlevel', 'explevel', 'makelimit', 'aux', - ], GeneralQueryMode::Lite); + ], GeneralLiteQueryMode::Lite); - if($general instanceof DummyGeneral){ + if($general instanceof DummyGeneralLite){ Json::die([ 'result'=>false, 'reason'=>'올바르지 않은 장수입니다.' diff --git a/hwe/j_set_my_setting.php b/hwe/j_set_my_setting.php index 04d4e2b3..422b6670 100644 --- a/hwe/j_set_my_setting.php +++ b/hwe/j_set_my_setting.php @@ -36,7 +36,7 @@ if($tnmt < 0 || $tnmt > 1){ } $db = DB::db(); -$me = General::createGeneralObjFromDB($generalID); +$me = General::createObjFromDB($generalID); if($defence_train !== $me->getVar('defence_train')){ diff --git a/hwe/j_update_picked_general.php b/hwe/j_update_picked_general.php index 56c7a3fc..e5aac0d0 100644 --- a/hwe/j_update_picked_general.php +++ b/hwe/j_update_picked_general.php @@ -66,7 +66,7 @@ if(!$ownerInfo){ $info = Json::decode($info); -$generalObj = General::createGeneralObjFromDB($generalID); +$generalObj = General::createObjFromDB($generalID); $oldGeneralName = $generalObj->getName(); $db->update('select_pool', [ 'general_id'=>-$generalID, diff --git a/hwe/old_index.php b/hwe/old_index.php index a7b7d263..901a775c 100644 --- a/hwe/old_index.php +++ b/hwe/old_index.php @@ -59,7 +59,7 @@ if ($limitState >= 2) { exit(); } -$generalObj = General::createGeneralObjFromDB($me['no'], null, GeneralQueryMode::FullWithAccessLog); +$generalObj = General::createObjFromDB($me['no'], null, GeneralQueryMode::FullWithAccessLog); $generalObj->setRawCity($db->queryFirstRow('SELECT * FROM city WHERE city = %i', $generalObj->getCityID())); $scenario = $gameStor->scenario_text; diff --git a/hwe/process_war.php b/hwe/process_war.php index 1d65d37c..83a17c7c 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -38,7 +38,7 @@ function processWar(string $warSeed, General $attackerGeneral, array $rawAttacke $city = new WarUnitCity($rng, $rawDefenderCity, $rawDefenderNation, $year, $month, $startYear); $defenderIDList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND city=%i AND nation!=0 and crew > 0 and rice>(crew/100) and train>=defence_train and atmos>=defence_train', $city->getVar('nation'), $city->getVar('city')); - $defenderGeneralList = General::createGeneralObjListFromDB($defenderIDList, null); + $defenderGeneralList = General::createObjListFromDB($defenderIDList, null); /** @var WarUnit[] */ $defenderList = []; diff --git a/hwe/sammo/API/Auction/BidBuyRiceAuction.php b/hwe/sammo/API/Auction/BidBuyRiceAuction.php index 0771d7a1..249e9591 100644 --- a/hwe/sammo/API/Auction/BidBuyRiceAuction.php +++ b/hwe/sammo/API/Auction/BidBuyRiceAuction.php @@ -39,7 +39,7 @@ class BidBuyRiceAuction extends \sammo\BaseAPI $amount = $this->args['amount']; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $auction = new AuctionBuyRice($auctionID, $general); $result = $auction->bid($amount, true); diff --git a/hwe/sammo/API/Auction/BidSellRiceAuction.php b/hwe/sammo/API/Auction/BidSellRiceAuction.php index 11549c42..66a78f54 100644 --- a/hwe/sammo/API/Auction/BidSellRiceAuction.php +++ b/hwe/sammo/API/Auction/BidSellRiceAuction.php @@ -38,7 +38,7 @@ class BidSellRiceAuction extends \sammo\BaseAPI $amount = $this->args['amount']; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $auction = new AuctionSellRice($auctionID, $general); $result = $auction->bid($amount, true); diff --git a/hwe/sammo/API/Auction/BidUniqueAuction.php b/hwe/sammo/API/Auction/BidUniqueAuction.php index de637442..d026ad3a 100644 --- a/hwe/sammo/API/Auction/BidUniqueAuction.php +++ b/hwe/sammo/API/Auction/BidUniqueAuction.php @@ -41,7 +41,7 @@ class BidUniqueAuction extends \sammo\BaseAPI $tryExtendCloseDate = $this->args['extendCloseDate'] ?? false; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $auction = new AuctionUniqueItem($auctionID, $general); $result = $auction->bid($amount, $tryExtendCloseDate); diff --git a/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php b/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php index b3f36e6f..16222fb9 100644 --- a/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php +++ b/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php @@ -77,7 +77,7 @@ class GetUniqueItemAuctionDetail extends \sammo\BaseAPI $inheritMgr = InheritancePointManager::getInstance(); //preveious라서 column을 최대한 비울 수 있다. $remainPoint = $inheritMgr->getInheritancePoint( - General::createGeneralObjFromDB($generalID, ['owner'], GeneralQueryMode::Core), + General::createObjFromDB($generalID, ['owner'], GeneralQueryMode::Core), InheritanceKey::previous ); diff --git a/hwe/sammo/API/Auction/OpenBuyRiceAuction.php b/hwe/sammo/API/Auction/OpenBuyRiceAuction.php index d9c71f1a..cc7e999d 100644 --- a/hwe/sammo/API/Auction/OpenBuyRiceAuction.php +++ b/hwe/sammo/API/Auction/OpenBuyRiceAuction.php @@ -66,7 +66,7 @@ class OpenBuyRiceAuction extends \sammo\BaseAPI $finishBidAmount = $this->args['finishBidAmount']; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/API/Auction/OpenSellRiceAuction.php b/hwe/sammo/API/Auction/OpenSellRiceAuction.php index 9eab113e..5ee12653 100644 --- a/hwe/sammo/API/Auction/OpenSellRiceAuction.php +++ b/hwe/sammo/API/Auction/OpenSellRiceAuction.php @@ -66,7 +66,7 @@ class OpenSellRiceAuction extends \sammo\BaseAPI $finishBidAmount = $this->args['finishBidAmount']; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/API/Auction/OpenUniqueAuction.php b/hwe/sammo/API/Auction/OpenUniqueAuction.php index 1b4425d3..955504a8 100644 --- a/hwe/sammo/API/Auction/OpenUniqueAuction.php +++ b/hwe/sammo/API/Auction/OpenUniqueAuction.php @@ -57,7 +57,7 @@ class OpenUniqueAuction extends \sammo\BaseAPI $generalID = $session->generalID; $itemObj = buildItemClass($itemID); - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/API/General/BuildNationCandidate.php b/hwe/sammo/API/General/BuildNationCandidate.php index 8ce2e797..5a4b2d1b 100644 --- a/hwe/sammo/API/General/BuildNationCandidate.php +++ b/hwe/sammo/API/General/BuildNationCandidate.php @@ -59,7 +59,7 @@ class BuildNationCandidate extends \sammo\BaseAPI $env = $gameStor->getAll(); - $generalObj = General::createGeneralObjFromDB($general['no']); + $generalObj = General::createObjFromDB($general['no']); $validCmd = false; foreach(GameConst::$availableGeneralCommand as $cmdList){ diff --git a/hwe/sammo/API/General/DieOnPrestart.php b/hwe/sammo/API/General/DieOnPrestart.php index ce5fa56b..e2c8552b 100644 --- a/hwe/sammo/API/General/DieOnPrestart.php +++ b/hwe/sammo/API/General/DieOnPrestart.php @@ -68,7 +68,7 @@ class DieOnPrestart extends \sammo\BaseAPI return "아직 삭제할 수 없습니다. {$targetTimeShort} 부터 가능합니다."; } - $generalObj = General::createGeneralObjFromDB($general['no']); + $generalObj = General::createObjFromDB($general['no']); if ($generalObj instanceof DummyGeneral) { trigger_error("올바르지 않은 삭제 프로세스 $userID", E_USER_WARNING); } diff --git a/hwe/sammo/API/General/DropItem.php b/hwe/sammo/API/General/DropItem.php index 1ab36005..cd4fc7e2 100644 --- a/hwe/sammo/API/General/DropItem.php +++ b/hwe/sammo/API/General/DropItem.php @@ -37,7 +37,7 @@ class DropItem extends \sammo\BaseAPI public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag): null | string | array | APIRecoveryType { $generalID = $session->generalID; - $me = General::createGeneralObjFromDB($generalID); + $me = General::createObjFromDB($generalID); $itemType = $this->args['itemType']; $item = $me->getItem($itemType); diff --git a/hwe/sammo/API/General/GetCommandTable.php b/hwe/sammo/API/General/GetCommandTable.php index 7e0a4ee2..6acff92b 100644 --- a/hwe/sammo/API/General/GetCommandTable.php +++ b/hwe/sammo/API/General/GetCommandTable.php @@ -21,7 +21,7 @@ class GetCommandTable extends \sammo\BaseAPI{ public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag): null | string | array | APIRecoveryType { $generalID = $session->generalID; - $me = General::createGeneralObjFromDB($generalID); + $me = General::createObjFromDB($generalID); $commandTable = getCommandTable($me); return [ diff --git a/hwe/sammo/API/General/GetFrontInfo.php b/hwe/sammo/API/General/GetFrontInfo.php index c0805c57..c36cd570 100644 --- a/hwe/sammo/API/General/GetFrontInfo.php +++ b/hwe/sammo/API/General/GetFrontInfo.php @@ -534,7 +534,7 @@ class GetFrontInfo extends \sammo\BaseAPI { $generalID = $session->generalID; //NOTE: 이 경우 staticNation 정보를 조회한다. - $general = General::createGeneralObjFromDB($generalID, null, GeneralQueryMode::FullWithAccessLog); + $general = General::createObjFromDB($generalID, null, GeneralQueryMode::FullWithAccessLog); $nationID = $general->getNationID(); $cityID = $general->getCityID(); diff --git a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php index 91ce0917..097a260c 100644 --- a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php +++ b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php @@ -49,7 +49,7 @@ class BuyHiddenBuff extends \sammo\BaseAPI $type = $this->args['type']; $level = $this->args['level']; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if ($userID != $general->getVar('owner')) { return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; } diff --git a/hwe/sammo/API/InheritAction/BuyRandomUnique.php b/hwe/sammo/API/InheritAction/BuyRandomUnique.php index 4a18a557..6e907b2e 100644 --- a/hwe/sammo/API/InheritAction/BuyRandomUnique.php +++ b/hwe/sammo/API/InheritAction/BuyRandomUnique.php @@ -31,7 +31,7 @@ class BuyRandomUnique extends \sammo\BaseAPI $userID = $session->userID; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if($userID != $general->getVar('owner')){ return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; } diff --git a/hwe/sammo/API/InheritAction/ResetSpecialWar.php b/hwe/sammo/API/InheritAction/ResetSpecialWar.php index 428e9c55..e888b385 100644 --- a/hwe/sammo/API/InheritAction/ResetSpecialWar.php +++ b/hwe/sammo/API/InheritAction/ResetSpecialWar.php @@ -31,7 +31,7 @@ class ResetSpecialWar extends \sammo\BaseAPI $userID = $session->userID; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if ($userID != $general->getVar('owner')) { return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; } diff --git a/hwe/sammo/API/InheritAction/ResetTurnTime.php b/hwe/sammo/API/InheritAction/ResetTurnTime.php index ba39d6bf..3ecb5c5f 100644 --- a/hwe/sammo/API/InheritAction/ResetTurnTime.php +++ b/hwe/sammo/API/InheritAction/ResetTurnTime.php @@ -36,7 +36,7 @@ class ResetTurnTime extends \sammo\BaseAPI $userID = $session->userID; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if ($userID != $general->getVar('owner')) { return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; } diff --git a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php index 8d490f82..0e074ac9 100644 --- a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php +++ b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php @@ -44,7 +44,7 @@ class SetNextSpecialWar extends \sammo\BaseAPI $type = $this->args['type']; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if ($userID != $general->getVar('owner')) { return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; } diff --git a/hwe/sammo/API/Nation/GetNationInfo.php b/hwe/sammo/API/Nation/GetNationInfo.php index 0dc1423f..be4a3d86 100644 --- a/hwe/sammo/API/Nation/GetNationInfo.php +++ b/hwe/sammo/API/Nation/GetNationInfo.php @@ -58,7 +58,7 @@ class GetNationInfo extends \sammo\BaseAPI ]; } - $generalObj = General::createGeneralObjFromDB($session->generalID, null, GeneralQueryMode::FullWithoutIAction); + $generalObj = General::createObjFromDB($session->generalID, null, GeneralQueryMode::FullWithoutIAction); $gameStor = KVStorage::getStorage($db, 'game_env'); $gameEnv = $gameStor->getValues(['year', 'month', 'startyear']); diff --git a/hwe/sammo/API/NationCommand/GetReservedCommand.php b/hwe/sammo/API/NationCommand/GetReservedCommand.php index 42f8a9ca..2523a05c 100644 --- a/hwe/sammo/API/NationCommand/GetReservedCommand.php +++ b/hwe/sammo/API/NationCommand/GetReservedCommand.php @@ -113,7 +113,7 @@ class GetReservedCommand extends \sammo\BaseAPI ]; } - $generalObj = General::createGeneralObjFromDB($session->generalID, null, GeneralQueryMode::FullWithoutIAction); + $generalObj = General::createObjFromDB($session->generalID, null, GeneralQueryMode::FullWithoutIAction); return [ diff --git a/hwe/sammo/API/Vote/AddComment.php b/hwe/sammo/API/Vote/AddComment.php index 417dd5de..5c386579 100644 --- a/hwe/sammo/API/Vote/AddComment.php +++ b/hwe/sammo/API/Vote/AddComment.php @@ -41,7 +41,7 @@ class AddComment extends \sammo\BaseAPI $text = mb_substr($this->args['text'], 0, 200); $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID, null, GeneralQueryMode::Core); + $general = General::createObjFromDB($generalID, null, GeneralQueryMode::Core); $generalName = $general->getName(); $nationID = $general->getNationID(); $nationName = $general->getStaticNation()['name']; diff --git a/hwe/sammo/API/Vote/Vote.php b/hwe/sammo/API/Vote/Vote.php index 090ad87c..fea230c3 100644 --- a/hwe/sammo/API/Vote/Vote.php +++ b/hwe/sammo/API/Vote/Vote.php @@ -106,7 +106,7 @@ class Vote extends \sammo\BaseAPI $gameStor = KVStorage::getStorage($db, 'game_env'); $voteReward = $gameStor->getValue('develcost') * 5; - $general = General::createGeneralObjFromDB($generalID, null, GeneralQueryMode::Full); + $general = General::createObjFromDB($generalID, null, GeneralQueryMode::Full); $general->increaseVar('gold', $voteReward); $uniqueRng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( UniqueConst::$hiddenSeed, diff --git a/hwe/sammo/Auction.php b/hwe/sammo/Auction.php index 7c393d84..b656ad64 100644 --- a/hwe/sammo/Auction.php +++ b/hwe/sammo/Auction.php @@ -218,7 +218,7 @@ abstract class Auction if ($bidItem->generalID === $this->general->getID()) { $oldBidder = $this->general; } else { - $oldBidder = General::createGeneralObjFromDB($bidItem->generalID); + $oldBidder = General::createObjFromDB($bidItem->generalID); } if ($this->info->reqResource === ResourceType::inheritancePoint) { @@ -485,7 +485,7 @@ abstract class Auction } } - $bidder = General::createGeneralObjFromDB($highestBid->generalID); + $bidder = General::createObjFromDB($highestBid->generalID); $failReason = $this->finishAuction($highestBid, $bidder); if ($failReason === null) { $this->closeAuction(); diff --git a/hwe/sammo/AuctionBasicResource.php b/hwe/sammo/AuctionBasicResource.php index dbc5dce5..4302a1b8 100644 --- a/hwe/sammo/AuctionBasicResource.php +++ b/hwe/sammo/AuctionBasicResource.php @@ -116,7 +116,7 @@ abstract class AuctionBasicResource extends Auction } else if ($this->info->hostGeneralID == 0) { $auctionHost = $this->genDummy(); } else { - $auctionHost = General::createGeneralObjFromDB($this->info->hostGeneralID); + $auctionHost = General::createObjFromDB($this->info->hostGeneralID); } $hostRes = static::$hostRes; @@ -164,7 +164,7 @@ abstract class AuctionBasicResource extends Auction } else if ($this->info->hostGeneralID == 0) { $auctionHost = $this->genDummy(); } else { - $auctionHost = General::createGeneralObjFromDB($this->info->hostGeneralID); + $auctionHost = General::createObjFromDB($this->info->hostGeneralID); } $highestBid = $this->getHighestBid(); @@ -175,7 +175,7 @@ abstract class AuctionBasicResource extends Auction if ($this->general->getID() === $highestBid->generalID) { $bidder = $this->general; } else { - $bidder = General::createGeneralObjFromDB($highestBid->generalID); + $bidder = General::createObjFromDB($highestBid->generalID); } $hostRes = static::$hostRes; diff --git a/hwe/sammo/Betting.php b/hwe/sammo/Betting.php index 4f7b9edf..2fab052a 100644 --- a/hwe/sammo/Betting.php +++ b/hwe/sammo/Betting.php @@ -402,7 +402,7 @@ class Betting $userLogger->flush(); } } else { - $generalList = General::createGeneralObjListFromDB(array_unique(Util::squeezeFromArray($rewardList, 'generalID')), ['gold', 'npc', 'betgold'], GeneralQueryMode::Lite); + $generalList = General::createObjListFromDB(array_unique(Util::squeezeFromArray($rewardList, 'generalID')), ['gold', 'npc', 'betgold'], GeneralQueryMode::Lite); foreach ($rewardList as $rewardItem) { $gambler = $generalList[$rewardItem['generalID']]; $reward = Util::round($rewardItem['amount']); diff --git a/hwe/sammo/Command/General/che_등용.php b/hwe/sammo/Command/General/che_등용.php index 0b4b035e..d8216008 100644 --- a/hwe/sammo/Command/General/che_등용.php +++ b/hwe/sammo/Command/General/che_등용.php @@ -7,11 +7,7 @@ use \sammo\{ Util, JosaUtil, General, - DummyGeneral, - ActionLogger, - GameConst, LastTurn, - GameUnitConst, Command, ScoutMessage }; @@ -77,7 +73,7 @@ class che_등용 extends Command\GeneralCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['nation', 'experience', 'dedication'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); [$reqGold, $reqRice] = $this->getCost(); diff --git a/hwe/sammo/Command/General/che_등용수락.php b/hwe/sammo/Command/General/che_등용수락.php index 959e66a0..dc608383 100644 --- a/hwe/sammo/Command/General/che_등용수락.php +++ b/hwe/sammo/Command/General/che_등용수락.php @@ -68,7 +68,7 @@ class che_등용수락 extends Command\GeneralCommand{ protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], null); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID'], ['gennum', 'scout']); diff --git a/hwe/sammo/Command/General/che_모반시도.php b/hwe/sammo/Command/General/che_모반시도.php index c5e0d005..8e533cc7 100644 --- a/hwe/sammo/Command/General/che_모반시도.php +++ b/hwe/sammo/Command/General/che_모반시도.php @@ -67,7 +67,7 @@ class che_모반시도 extends Command\GeneralCommand{ $lordID = $db->queryFirstField('SELECT no FROM general WHERE nation = %i AND officer_level = 12', $nationID); - $lordGeneral = General::createGeneralObjFromDB($lordID); + $lordGeneral = General::createObjFromDB($lordID); $generalName = $general->getName(); $lordName = $lordGeneral->getName(); diff --git a/hwe/sammo/Command/General/che_선양.php b/hwe/sammo/Command/General/che_선양.php index 23be46a6..2c4d4ecf 100644 --- a/hwe/sammo/Command/General/che_선양.php +++ b/hwe/sammo/Command/General/che_선양.php @@ -66,7 +66,7 @@ class che_선양 extends Command\GeneralCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], GeneralQueryMode::Lite); $this->setDestGeneral($destGeneral); $this->fullConditionConstraints = [ diff --git a/hwe/sammo/Command/General/che_장수대상임관.php b/hwe/sammo/Command/General/che_장수대상임관.php index 70bd734b..f33b8850 100644 --- a/hwe/sammo/Command/General/che_장수대상임관.php +++ b/hwe/sammo/Command/General/che_장수대상임관.php @@ -84,7 +84,7 @@ class che_장수대상임관 extends Command\GeneralCommand{ protected function initWithArg() { $destGeneralID = $this->arg['destGeneralID']; - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], ['nation'], GeneralQueryMode::Lite); $this->setDestGeneral($destGeneral); $this->setDestNation($this->destGeneralObj->getVar('nation'), ['gennum', 'scout']); diff --git a/hwe/sammo/Command/General/che_증여.php b/hwe/sammo/Command/General/che_증여.php index c38493b4..97365920 100644 --- a/hwe/sammo/Command/General/che_증여.php +++ b/hwe/sammo/Command/General/che_증여.php @@ -87,7 +87,7 @@ class che_증여 extends Command\GeneralCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], GeneralQueryMode::Lite); $this->setDestGeneral($destGeneral); $this->fullConditionConstraints = [ diff --git a/hwe/sammo/Command/General/che_화계.php b/hwe/sammo/Command/General/che_화계.php index 1be84a5c..b07c77ef 100644 --- a/hwe/sammo/Command/General/che_화계.php +++ b/hwe/sammo/Command/General/che_화계.php @@ -269,7 +269,7 @@ class che_화계 extends Command\GeneralCommand $destCityGeneralList = []; $cityGeneralID = $db->queryFirstColumn('SELECT no FROM general WHERE city = %i AND nation = %i', $destCityID, $destNationID); - $destCityGeneralList = General::createGeneralObjListFromDB($cityGeneralID, ['name', 'city', 'nation', 'officer_level', 'leadership', 'horse', 'strength', 'weapon', 'intel', 'book', 'item', 'last_turn', 'injury', 'special', 'special2', 'injury', 'crewtype', 'crew', 'atmos', 'train']); + $destCityGeneralList = General::createObjListFromDB($cityGeneralID, ['name', 'city', 'nation', 'officer_level', 'leadership', 'horse', 'strength', 'weapon', 'intel', 'book', 'item', 'last_turn', 'injury', 'special', 'special2', 'injury', 'crewtype', 'crew', 'atmos', 'train']); foreach ($destCityGeneralList as &$destCityGeneral) { $destCityGeneral->setRawCity($this->destCity); unset($destCityGeneral); diff --git a/hwe/sammo/Command/Nation/che_몰수.php b/hwe/sammo/Command/Nation/che_몰수.php index 8b51bd94..df4ab98c 100644 --- a/hwe/sammo/Command/Nation/che_몰수.php +++ b/hwe/sammo/Command/Nation/che_몰수.php @@ -92,7 +92,7 @@ class che_몰수 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'npc', 'nation', 'imgsvr', 'picture'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'npc', 'nation', 'imgsvr', 'picture'], GeneralQueryMode::Lite); $this->setDestGeneral($destGeneral); $env = $this->env; diff --git a/hwe/sammo/Command/Nation/che_발령.php b/hwe/sammo/Command/Nation/che_발령.php index ddc3369a..f7e6439a 100644 --- a/hwe/sammo/Command/Nation/che_발령.php +++ b/hwe/sammo/Command/Nation/che_발령.php @@ -72,7 +72,7 @@ class che_발령 extends Command\NationCommand { $this->setDestCity($this->arg['destCityID']); - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); $this->setDestGeneral($destGeneral); if ($this->arg['destGeneralID'] == $this->getGeneral()->getID()) { diff --git a/hwe/sammo/Command/Nation/che_불가침수락.php b/hwe/sammo/Command/Nation/che_불가침수락.php index ec348ecd..75b1edc4 100644 --- a/hwe/sammo/Command/Nation/che_불가침수락.php +++ b/hwe/sammo/Command/Nation/che_불가침수락.php @@ -104,7 +104,7 @@ class che_불가침수락 extends Command\NationCommand $env = $this->env; $relYear = $env['year'] - $env['startyear']; - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID']); diff --git a/hwe/sammo/Command/Nation/che_불가침파기수락.php b/hwe/sammo/Command/Nation/che_불가침파기수락.php index a6962c7e..6f397ca6 100644 --- a/hwe/sammo/Command/Nation/che_불가침파기수락.php +++ b/hwe/sammo/Command/Nation/che_불가침파기수락.php @@ -78,7 +78,7 @@ class che_불가침파기수락 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID']); diff --git a/hwe/sammo/Command/Nation/che_종전수락.php b/hwe/sammo/Command/Nation/che_종전수락.php index 9e42ac30..a5a4ae43 100644 --- a/hwe/sammo/Command/Nation/che_종전수락.php +++ b/hwe/sammo/Command/Nation/che_종전수락.php @@ -87,7 +87,7 @@ class che_종전수락 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID']); diff --git a/hwe/sammo/Command/Nation/che_포상.php b/hwe/sammo/Command/Nation/che_포상.php index 790fd504..bded0d39 100644 --- a/hwe/sammo/Command/Nation/che_포상.php +++ b/hwe/sammo/Command/Nation/che_포상.php @@ -82,7 +82,7 @@ class che_포상 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], GeneralQueryMode::Lite); $this->setDestGeneral($destGeneral); if($this->arg['destGeneralID'] == $this->getGeneral()->getID()){ diff --git a/hwe/sammo/Command/Nation/che_필사즉생.php b/hwe/sammo/Command/Nation/che_필사즉생.php index 9d56addb..4383eab4 100644 --- a/hwe/sammo/Command/Nation/che_필사즉생.php +++ b/hwe/sammo/Command/Nation/che_필사즉생.php @@ -95,7 +95,7 @@ class che_필사즉생 extends Command\NationCommand{ $broadcastMessage = "{$generalName}{$josaYi} 필사즉생을 발동하였습니다."; $targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID); - foreach(General::createGeneralObjListFromDB($targetGeneralList, ['train', 'atmos'], GeneralQueryMode::Lite) as $targetGeneral){ + foreach(General::createObjListFromDB($targetGeneralList, ['train', 'atmos'], GeneralQueryMode::Lite) as $targetGeneral){ $targetGeneral->getLogger()->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN); if($targetGeneral->getVar('train') < 100){ $targetGeneral->setVar('train', 100); diff --git a/hwe/sammo/Command/Nation/che_허보.php b/hwe/sammo/Command/Nation/che_허보.php index b3c201b7..c0b1ff38 100644 --- a/hwe/sammo/Command/Nation/che_허보.php +++ b/hwe/sammo/Command/Nation/che_허보.php @@ -163,7 +163,7 @@ class che_허보 extends Command\NationCommand $destNationCityList = $db->queryFirstColumn('SELECT city FROM city WHERE nation = %i AND supply = 1', $destNationID); $targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND city=%i', $destNationID, $destCityID); - foreach (General::createGeneralObjListFromDB($targetGeneralList) as $targetGeneralID => $targetGeneral) { + foreach (General::createObjListFromDB($targetGeneralList) as $targetGeneralID => $targetGeneral) { $targetLogger = $targetGeneral->getLogger(); $targetLogger->pushGeneralActionLog($destBroadcastMessage, ActionLogger::PLAIN); diff --git a/hwe/sammo/DiplomaticMessage.php b/hwe/sammo/DiplomaticMessage.php index 1df2c596..dc08c81f 100644 --- a/hwe/sammo/DiplomaticMessage.php +++ b/hwe/sammo/DiplomaticMessage.php @@ -76,7 +76,7 @@ class DiplomaticMessage extends Message{ $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $destGeneralObj = General::createGeneralObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); + $destGeneralObj = General::createObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); $commandObj = buildNationCommandClass('che_불가침수락', $destGeneralObj, $gameStor->getAll(true), new LastTurn(), [ 'destNationID'=>$this->src->nationID, @@ -100,7 +100,7 @@ class DiplomaticMessage extends Message{ protected function cancelNA(){ $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $destGeneralObj = General::createGeneralObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); + $destGeneralObj = General::createObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); $commandObj = buildNationCommandClass('che_불가침파기수락', $destGeneralObj, $gameStor->getAll(true), new LastTurn(), [ 'destNationID'=>$this->src->nationID, @@ -122,7 +122,7 @@ class DiplomaticMessage extends Message{ protected function stopWar(){ $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $destGeneralObj = General::createGeneralObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); + $destGeneralObj = General::createObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); $commandObj = buildNationCommandClass('che_종전수락', $destGeneralObj, $gameStor->getAll(true), new LastTurn(), [ 'destNationID'=>$this->src->nationID, diff --git a/hwe/sammo/Event/Action/LostUniqueItem.php b/hwe/sammo/Event/Action/LostUniqueItem.php index f3c9450a..21fbf7c8 100644 --- a/hwe/sammo/Event/Action/LostUniqueItem.php +++ b/hwe/sammo/Event/Action/LostUniqueItem.php @@ -28,7 +28,7 @@ class LostUniqueItem extends \sammo\Event\Action if (!$generalIDList) { return; } - $generals = General::createGeneralObjListFromDB($generalIDList); + $generals = General::createObjListFromDB($generalIDList); $lostItems = []; $totalLostCnt = 0; diff --git a/hwe/sammo/Event/Action/MergeInheritPointRank.php b/hwe/sammo/Event/Action/MergeInheritPointRank.php index 47a07880..7a8d75a1 100644 --- a/hwe/sammo/Event/Action/MergeInheritPointRank.php +++ b/hwe/sammo/Event/Action/MergeInheritPointRank.php @@ -18,7 +18,7 @@ class MergeInheritPointRank extends \sammo\Event\Action { $db = DB::db(); - $generals = General::createGeneralObjListFromDB(null, null); + $generals = General::createObjListFromDB(null, null); $points = new Map(); $points->allocate(count($generals)); diff --git a/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php b/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php index d8d4ab9f..50e06030 100644 --- a/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php +++ b/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php @@ -84,7 +84,7 @@ class ProvideNPCTroopLeader extends \sammo\Event\Action 'troop' => $npcID ], 'no=%i', $npcID); - $cmd = buildGeneralCommandClass('che_집합', General::createGeneralObjFromDB($npcID), $env); + $cmd = buildGeneralCommandClass('che_집합', General::createObjFromDB($npcID), $env); _setGeneralCommand($cmd, iterator_to_array(Util::range(GameConst::$maxTurn))); $NPCTroopLeaderCnt += 1; $gameStor->lastNPCTroopLeaderID = $lastNPCTroopLeaderID; diff --git a/hwe/sammo/Event/Action/UpdateNationLevel.php b/hwe/sammo/Event/Action/UpdateNationLevel.php index 72b7bc26..d92de942 100644 --- a/hwe/sammo/Event/Action/UpdateNationLevel.php +++ b/hwe/sammo/Event/Action/UpdateNationLevel.php @@ -140,7 +140,7 @@ class UpdateNationLevel extends \sammo\Event\Action $nation['nation'], $targetKillTurn ); - $nationGenList = General::createGeneralObjListFromDB($nationGenIDList, ['belong', 'npc', 'aux']); + $nationGenList = General::createObjListFromDB($nationGenIDList, ['belong', 'npc', 'aux']); $chiefID = null; $uniqueLotteryWeightList = []; @@ -215,7 +215,7 @@ class UpdateNationLevel extends \sammo\Event\Action } if ($chiefID) { - $chiefObj = General::createGeneralObjFromDB($chiefID, ['belong', 'npc', 'aux'], GeneralQueryMode::Lite); + $chiefObj = General::createObjFromDB($chiefID, ['belong', 'npc', 'aux'], GeneralQueryMode::Lite); $chiefObj->increaseInheritancePoint(InheritanceKey::unifier, 250 * $levelDiff); $chiefObj->applyDB($db); } diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 3535600e..31a38b10 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -921,7 +921,7 @@ class General extends GeneralBase implements iAction * @return \sammo\General[] * @throws MustNotBeReachedException */ - static public function createGeneralObjListFromDB(?array $generalIDList, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array + static public function createObjListFromDB(?array $generalIDList, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array { if ($generalIDList === []) { return []; @@ -1007,7 +1007,7 @@ class General extends GeneralBase implements iAction return $result; } - static public function createGeneralObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): self + static public function createObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): self { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index 0a8a5018..7afb068a 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -3514,7 +3514,7 @@ class GeneralAI $db = DB::db(); $generalIDList = $db->queryFirstColumn('SELECT no FROM general WHERE nation = %i AND no != %i', $nationID, $this->general->getID()); - $nationGenerals = General::createGeneralObjListFromDB($generalIDList); + $nationGenerals = General::createObjListFromDB($generalIDList); $lastWar = \PHP_INT_MAX; foreach ($nationGenerals as $nationGeneral) { diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php index 93b664b8..7a2b6626 100644 --- a/hwe/sammo/GeneralLite.php +++ b/hwe/sammo/GeneralLite.php @@ -68,7 +68,7 @@ class GeneralLite extends GeneralBase * @return \sammo\GeneralLite[] * @throws MustNotBeReachedException */ - static public function createGeneralLiteObjListFromDB(?array $generalIDList, ?array $column = null, GeneralLiteQueryMode $queryMode = GeneralLiteQueryMode::Full): array + static public function createObjListFromDB(?array $generalIDList, ?array $column = null, GeneralLiteQueryMode $queryMode = GeneralLiteQueryMode::Full): array { if ($generalIDList === []) { return []; @@ -136,7 +136,7 @@ class GeneralLite extends GeneralBase return $result; } - static public function createGeneralLiteObjFromDB(int $generalID, ?array $column = null, GeneralLiteQueryMode $queryMode = GeneralLiteQueryMode::Full): self + static public function createObjFromDB(int $generalID, ?array $column = null, GeneralLiteQueryMode $queryMode = GeneralLiteQueryMode::Full): self { $db = DB::db(); if ($queryMode->value > 0) { diff --git a/hwe/sammo/RaiseInvaderMessage.php b/hwe/sammo/RaiseInvaderMessage.php index 33b65e89..e70fee8e 100644 --- a/hwe/sammo/RaiseInvaderMessage.php +++ b/hwe/sammo/RaiseInvaderMessage.php @@ -66,7 +66,7 @@ class RaiseInvaderMessage extends Message } $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $general = \sammo\General::createGeneralObjFromDB($receiverID); + $general = \sammo\General::createObjFromDB($receiverID); $logger = $general->getLogger(); diff --git a/hwe/sammo/ScoutMessage.php b/hwe/sammo/ScoutMessage.php index bf954234..6b847d64 100644 --- a/hwe/sammo/ScoutMessage.php +++ b/hwe/sammo/ScoutMessage.php @@ -68,7 +68,7 @@ class ScoutMessage extends Message } $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $general = \sammo\General::createGeneralObjFromDB($receiverID); + $general = \sammo\General::createObjFromDB($receiverID); $logger = $general->getLogger(); @@ -125,8 +125,8 @@ class ScoutMessage extends Message $now = TimeUtil::now(); //XXX: 뭔가 기존 쿼리가 애매하다. invalid 관련해서 다른 옵션이 가능한가? $rawMsgList = Util::convertArrayToDict($db->query( - 'SELECT * FROM `message` WHERE - `mailbox` = %i AND `type` = "private" AND `dest` = `mailbox` AND `valid_until` > %s AND + 'SELECT * FROM `message` WHERE + `mailbox` = %i AND `type` = "private" AND `dest` = `mailbox` AND `valid_until` > %s AND JSON_VALUE(message, "$.option.action") = %s', $generalID, $now, diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index ca17ad71..482839b3 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -239,7 +239,7 @@ class TurnExecutionHelper return [true, $currentTurn]; } - $general = General::createGeneralObjFromDB($rawGeneral['no']); + $general = General::createObjFromDB($rawGeneral['no']); $nationStor = KVStorage::getStorage($db, $general->getNationID(), 'nation_env'); $turnObj = new static($general); diff --git a/hwe/v_NPCControl.php b/hwe/v_NPCControl.php index 59946efd..0ab1df23 100644 --- a/hwe/v_NPCControl.php +++ b/hwe/v_NPCControl.php @@ -43,7 +43,7 @@ $nationStor = KVStorage::getStorage($db, $nationID, 'nation_env'); $nationStor->cacheValues(['npc_nation_policy', 'npc_general_policy']); $gameStor->cacheAll(); -$general = General::createGeneralObjFromDB($me['no']); +$general = General::createObjFromDB($me['no']); $rawServerPolicy = $gameStor->getValue('npc_nation_policy') ?? []; $rawNationPolicy = $nationStor->getValue('npc_nation_policy') ?? []; diff --git a/hwe/v_chiefCenter.php b/hwe/v_chiefCenter.php index 6193047b..c807f83d 100644 --- a/hwe/v_chiefCenter.php +++ b/hwe/v_chiefCenter.php @@ -7,7 +7,7 @@ include "func.php"; //로그인 검사 $session = Session::requireGameLogin()->setReadOnly(); $userID = Session::getUserID(); -$generalObj = General::createGeneralObjFromDB($session->generalID); +$generalObj = General::createObjFromDB($session->generalID); ?> diff --git a/hwe/v_inheritPoint.php b/hwe/v_inheritPoint.php index 24eeccd7..5acdef88 100644 --- a/hwe/v_inheritPoint.php +++ b/hwe/v_inheritPoint.php @@ -14,7 +14,7 @@ $generalID = $session->generalID; $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); -$me = General::createGeneralObjFromDB($generalID); +$me = General::createObjFromDB($generalID); diff --git a/hwe/v_processing.php b/hwe/v_processing.php index 15914ac4..eda86878 100644 --- a/hwe/v_processing.php +++ b/hwe/v_processing.php @@ -42,7 +42,7 @@ if ($isChiefTurn && !in_array($commandType, Util::array_flatten(GameConst::$avai $gameStor = KVStorage::getStorage($db, 'game_env')->turnOnCache(); $env = $gameStor->getAll(); -$general = General::createGeneralObjFromDB($session->generalID); +$general = General::createObjFromDB($session->generalID); if (!$isChiefTurn) { $commandObj = buildGeneralCommandClass($commandType, $general, $env); -- 2.54.0 From ad233985920e6d420f9f75119e9f20b8f6daa85c Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 30 Jul 2023 13:39:32 +0000 Subject: [PATCH 15/19] =?UTF-8?q?refac:=20General=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD=20-=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=ED=95=9C=20GeneralQueryMode=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=9D=BC=20Lite=EA=B0=80=20=EB=B6=88=EA=B0=80=EB=8A=A5=20-=20L?= =?UTF-8?q?ite=EC=97=AC=EB=8F=84=20=EB=90=9C=EB=8B=A4=EB=A9=B4=20GeneralLi?= =?UTF-8?q?te=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=20-=20=EA=B7=B8=EB=A0=87=EC=A7=80=20=EC=95=8A=EB=8B=A4?= =?UTF-8?q?=EB=A9=B4=20General=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20-=20=EB=82=B4=EB=B6=80=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EC=96=B4=EB=96=A0=ED=95=9C=20=EC=97=B0=EC=82=B0=EC=9D=84=20?= =?UTF-8?q?=ED=95=A0=20=EC=A7=80=20=EC=95=8C=20=EC=88=98=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=EB=8D=B0,=20=20=20=EA=B5=AC=ED=98=84=20=EC=8B=9C?= =?UTF-8?q?=EC=A0=90=EC=97=90=EC=84=9C=20=ED=8E=B8=EC=9D=98=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=9D=BC=20column=20=EC=97=AC=EB=B6=80=EA=B0=80=20?= =?UTF-8?q?=EC=B0=A8=EC=9D=B4=EB=82=98=EB=A9=B4=20=20=20=EC=9D=B4=ED=9B=84?= =?UTF-8?q?=EC=97=90=20=EB=AC=B8=EC=A0=9C=EA=B0=80=20=EB=90=A0=20=EC=88=98?= =?UTF-8?q?=20=EC=9E=88=EC=9D=8C=20-=20=EC=97=94=EC=A7=84=EC=9D=B4=20?= =?UTF-8?q?=EC=82=B4=EC=A7=9D=20=EB=AC=B4=EA=B1=B0=EC=9B=8C=20=EC=A7=88=20?= =?UTF-8?q?=EA=B2=83=EC=9C=BC=EB=A1=9C=20=EB=B3=B4=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/process_war.php | 2 +- hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php | 2 +- hwe/sammo/API/Nation/GeneralList.php | 4 +++- hwe/sammo/API/Nation/GetNationInfo.php | 2 +- hwe/sammo/API/NationCommand/GetReservedCommand.php | 2 +- hwe/sammo/API/Vote/AddComment.php | 4 +++- hwe/sammo/Betting.php | 2 +- hwe/sammo/Command/General/che_선양.php | 2 +- hwe/sammo/Command/General/che_장수대상임관.php | 2 +- hwe/sammo/Command/General/che_증여.php | 2 +- hwe/sammo/Command/Nation/che_몰수.php | 2 +- hwe/sammo/Command/Nation/che_발령.php | 2 +- hwe/sammo/Command/Nation/che_불가침수락.php | 2 +- hwe/sammo/Command/Nation/che_불가침파기수락.php | 2 +- hwe/sammo/Command/Nation/che_종전수락.php | 2 +- hwe/sammo/Command/Nation/che_포상.php | 2 +- hwe/sammo/Command/Nation/che_필사즉생.php | 2 +- hwe/sammo/DiplomaticMessage.php | 6 +++--- hwe/sammo/Event/Action/UpdateNationLevel.php | 2 +- 19 files changed, 25 insertions(+), 21 deletions(-) diff --git a/hwe/process_war.php b/hwe/process_war.php index 83a17c7c..444e1370 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -596,7 +596,7 @@ function ConquerCity(array $admin, General $general, array $city) $lord = new General($db->queryFirstRow( 'SELECT %l FROM general WHERE nation = %i AND officer_level = %i LIMIT 1', - Util::formatListOfBackticks(General::mergeQueryColumn(['npc', 'gold', 'rice', 'experience', 'explevel', 'belong', 'dedication', 'dedlevel', 'aux'], GeneralQueryMode::Lite)[0]), + Util::formatListOfBackticks(General::mergeQueryColumn()[0]), $defenderNationID, 12 ), null, null, $city, $loseNation, $year, $month); diff --git a/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php b/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php index 16222fb9..782995f3 100644 --- a/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php +++ b/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php @@ -77,7 +77,7 @@ class GetUniqueItemAuctionDetail extends \sammo\BaseAPI $inheritMgr = InheritancePointManager::getInstance(); //preveious라서 column을 최대한 비울 수 있다. $remainPoint = $inheritMgr->getInheritancePoint( - General::createObjFromDB($generalID, ['owner'], GeneralQueryMode::Core), + General::createObjFromDB($generalID), InheritanceKey::previous ); diff --git a/hwe/sammo/API/Nation/GeneralList.php b/hwe/sammo/API/Nation/GeneralList.php index 4a740589..dcf25d37 100644 --- a/hwe/sammo/API/Nation/GeneralList.php +++ b/hwe/sammo/API/Nation/GeneralList.php @@ -5,8 +5,10 @@ namespace sammo\API\Nation; use ArrayObject; use sammo\DB; use sammo\Enums\APIRecoveryType; +use sammo\Enums\GeneralLiteQueryMode; use sammo\Enums\GeneralQueryMode; use sammo\General; +use sammo\GeneralLite; use sammo\Session; use sammo\Util; @@ -165,7 +167,7 @@ class GeneralList extends \sammo\BaseAPI - [$queryColumns, $rankColumns, $accessLogColumns] = General::mergeQueryColumn(array_keys(static::$viewColumns), GeneralQueryMode::Lite); + [$queryColumns, $rankColumns, $accessLogColumns] = GeneralLite::mergeQueryColumn(array_keys(static::$viewColumns), GeneralLiteQueryMode::Lite); $rawGeneralList = Util::convertArrayToDict( $db->query( diff --git a/hwe/sammo/API/Nation/GetNationInfo.php b/hwe/sammo/API/Nation/GetNationInfo.php index be4a3d86..5133bfd0 100644 --- a/hwe/sammo/API/Nation/GetNationInfo.php +++ b/hwe/sammo/API/Nation/GetNationInfo.php @@ -58,7 +58,7 @@ class GetNationInfo extends \sammo\BaseAPI ]; } - $generalObj = General::createObjFromDB($session->generalID, null, GeneralQueryMode::FullWithoutIAction); + $generalObj = General::createObjFromDB($session->generalID); $gameStor = KVStorage::getStorage($db, 'game_env'); $gameEnv = $gameStor->getValues(['year', 'month', 'startyear']); diff --git a/hwe/sammo/API/NationCommand/GetReservedCommand.php b/hwe/sammo/API/NationCommand/GetReservedCommand.php index 2523a05c..660bb252 100644 --- a/hwe/sammo/API/NationCommand/GetReservedCommand.php +++ b/hwe/sammo/API/NationCommand/GetReservedCommand.php @@ -113,7 +113,7 @@ class GetReservedCommand extends \sammo\BaseAPI ]; } - $generalObj = General::createObjFromDB($session->generalID, null, GeneralQueryMode::FullWithoutIAction); + $generalObj = General::createObjFromDB($session->generalID); return [ diff --git a/hwe/sammo/API/Vote/AddComment.php b/hwe/sammo/API/Vote/AddComment.php index 5c386579..40b1899f 100644 --- a/hwe/sammo/API/Vote/AddComment.php +++ b/hwe/sammo/API/Vote/AddComment.php @@ -6,8 +6,10 @@ use DateTimeInterface; use sammo\DB; use sammo\DTO\VoteComment; use sammo\Enums\APIRecoveryType; +use sammo\Enums\GeneralLiteQueryMode; use sammo\Enums\GeneralQueryMode; use sammo\General; +use sammo\GeneralLite; use sammo\Session; use sammo\TimeUtil; use sammo\Validator; @@ -41,7 +43,7 @@ class AddComment extends \sammo\BaseAPI $text = mb_substr($this->args['text'], 0, 200); $generalID = $session->generalID; - $general = General::createObjFromDB($generalID, null, GeneralQueryMode::Core); + $general = GeneralLite::createObjFromDB($generalID, null, GeneralLiteQueryMode::Core); $generalName = $general->getName(); $nationID = $general->getNationID(); $nationName = $general->getStaticNation()['name']; diff --git a/hwe/sammo/Betting.php b/hwe/sammo/Betting.php index 2fab052a..15619fc1 100644 --- a/hwe/sammo/Betting.php +++ b/hwe/sammo/Betting.php @@ -402,7 +402,7 @@ class Betting $userLogger->flush(); } } else { - $generalList = General::createObjListFromDB(array_unique(Util::squeezeFromArray($rewardList, 'generalID')), ['gold', 'npc', 'betgold'], GeneralQueryMode::Lite); + $generalList = General::createObjListFromDB(array_unique(Util::squeezeFromArray($rewardList, 'generalID'))); foreach ($rewardList as $rewardItem) { $gambler = $generalList[$rewardItem['generalID']]; $reward = Util::round($rewardItem['amount']); diff --git a/hwe/sammo/Command/General/che_선양.php b/hwe/sammo/Command/General/che_선양.php index 2c4d4ecf..9c2ec45e 100644 --- a/hwe/sammo/Command/General/che_선양.php +++ b/hwe/sammo/Command/General/che_선양.php @@ -66,7 +66,7 @@ class che_선양 extends Command\GeneralCommand protected function initWithArg() { - $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $this->fullConditionConstraints = [ diff --git a/hwe/sammo/Command/General/che_장수대상임관.php b/hwe/sammo/Command/General/che_장수대상임관.php index f33b8850..5f97b9c9 100644 --- a/hwe/sammo/Command/General/che_장수대상임관.php +++ b/hwe/sammo/Command/General/che_장수대상임관.php @@ -84,7 +84,7 @@ class che_장수대상임관 extends Command\GeneralCommand{ protected function initWithArg() { $destGeneralID = $this->arg['destGeneralID']; - $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], ['nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($destGeneralID); $this->setDestGeneral($destGeneral); $this->setDestNation($this->destGeneralObj->getVar('nation'), ['gennum', 'scout']); diff --git a/hwe/sammo/Command/General/che_증여.php b/hwe/sammo/Command/General/che_증여.php index 97365920..e6e2e6f9 100644 --- a/hwe/sammo/Command/General/che_증여.php +++ b/hwe/sammo/Command/General/che_증여.php @@ -87,7 +87,7 @@ class che_증여 extends Command\GeneralCommand protected function initWithArg() { - $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $this->fullConditionConstraints = [ diff --git a/hwe/sammo/Command/Nation/che_몰수.php b/hwe/sammo/Command/Nation/che_몰수.php index df4ab98c..9658a6ff 100644 --- a/hwe/sammo/Command/Nation/che_몰수.php +++ b/hwe/sammo/Command/Nation/che_몰수.php @@ -92,7 +92,7 @@ class che_몰수 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'npc', 'nation', 'imgsvr', 'picture'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $env = $this->env; diff --git a/hwe/sammo/Command/Nation/che_발령.php b/hwe/sammo/Command/Nation/che_발령.php index f7e6439a..7917f796 100644 --- a/hwe/sammo/Command/Nation/che_발령.php +++ b/hwe/sammo/Command/Nation/che_발령.php @@ -72,7 +72,7 @@ class che_발령 extends Command\NationCommand { $this->setDestCity($this->arg['destCityID']); - $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); if ($this->arg['destGeneralID'] == $this->getGeneral()->getID()) { diff --git a/hwe/sammo/Command/Nation/che_불가침수락.php b/hwe/sammo/Command/Nation/che_불가침수락.php index 75b1edc4..2056900d 100644 --- a/hwe/sammo/Command/Nation/che_불가침수락.php +++ b/hwe/sammo/Command/Nation/che_불가침수락.php @@ -104,7 +104,7 @@ class che_불가침수락 extends Command\NationCommand $env = $this->env; $relYear = $env['year'] - $env['startyear']; - $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID']); diff --git a/hwe/sammo/Command/Nation/che_불가침파기수락.php b/hwe/sammo/Command/Nation/che_불가침파기수락.php index 6f397ca6..4b5efebe 100644 --- a/hwe/sammo/Command/Nation/che_불가침파기수락.php +++ b/hwe/sammo/Command/Nation/che_불가침파기수락.php @@ -78,7 +78,7 @@ class che_불가침파기수락 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID']); diff --git a/hwe/sammo/Command/Nation/che_종전수락.php b/hwe/sammo/Command/Nation/che_종전수락.php index a5a4ae43..2441ee5a 100644 --- a/hwe/sammo/Command/Nation/che_종전수락.php +++ b/hwe/sammo/Command/Nation/che_종전수락.php @@ -87,7 +87,7 @@ class che_종전수락 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID']); diff --git a/hwe/sammo/Command/Nation/che_포상.php b/hwe/sammo/Command/Nation/che_포상.php index bded0d39..73791692 100644 --- a/hwe/sammo/Command/Nation/che_포상.php +++ b/hwe/sammo/Command/Nation/che_포상.php @@ -82,7 +82,7 @@ class che_포상 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); if($this->arg['destGeneralID'] == $this->getGeneral()->getID()){ diff --git a/hwe/sammo/Command/Nation/che_필사즉생.php b/hwe/sammo/Command/Nation/che_필사즉생.php index 4383eab4..ed7662f1 100644 --- a/hwe/sammo/Command/Nation/che_필사즉생.php +++ b/hwe/sammo/Command/Nation/che_필사즉생.php @@ -95,7 +95,7 @@ class che_필사즉생 extends Command\NationCommand{ $broadcastMessage = "{$generalName}{$josaYi} 필사즉생을 발동하였습니다."; $targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID); - foreach(General::createObjListFromDB($targetGeneralList, ['train', 'atmos'], GeneralQueryMode::Lite) as $targetGeneral){ + foreach(General::createObjListFromDB($targetGeneralList) as $targetGeneral){ $targetGeneral->getLogger()->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN); if($targetGeneral->getVar('train') < 100){ $targetGeneral->setVar('train', 100); diff --git a/hwe/sammo/DiplomaticMessage.php b/hwe/sammo/DiplomaticMessage.php index dc08c81f..7d9a2596 100644 --- a/hwe/sammo/DiplomaticMessage.php +++ b/hwe/sammo/DiplomaticMessage.php @@ -76,7 +76,7 @@ class DiplomaticMessage extends Message{ $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $destGeneralObj = General::createObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); + $destGeneralObj = General::createObjFromDB($this->dest->generalID); $commandObj = buildNationCommandClass('che_불가침수락', $destGeneralObj, $gameStor->getAll(true), new LastTurn(), [ 'destNationID'=>$this->src->nationID, @@ -100,7 +100,7 @@ class DiplomaticMessage extends Message{ protected function cancelNA(){ $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $destGeneralObj = General::createObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); + $destGeneralObj = General::createObjFromDB($this->dest->generalID); $commandObj = buildNationCommandClass('che_불가침파기수락', $destGeneralObj, $gameStor->getAll(true), new LastTurn(), [ 'destNationID'=>$this->src->nationID, @@ -122,7 +122,7 @@ class DiplomaticMessage extends Message{ protected function stopWar(){ $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $destGeneralObj = General::createObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); + $destGeneralObj = General::createObjFromDB($this->dest->generalID); $commandObj = buildNationCommandClass('che_종전수락', $destGeneralObj, $gameStor->getAll(true), new LastTurn(), [ 'destNationID'=>$this->src->nationID, diff --git a/hwe/sammo/Event/Action/UpdateNationLevel.php b/hwe/sammo/Event/Action/UpdateNationLevel.php index d92de942..88751956 100644 --- a/hwe/sammo/Event/Action/UpdateNationLevel.php +++ b/hwe/sammo/Event/Action/UpdateNationLevel.php @@ -215,7 +215,7 @@ class UpdateNationLevel extends \sammo\Event\Action } if ($chiefID) { - $chiefObj = General::createObjFromDB($chiefID, ['belong', 'npc', 'aux'], GeneralQueryMode::Lite); + $chiefObj = General::createObjFromDB($chiefID); $chiefObj->increaseInheritancePoint(InheritanceKey::unifier, 250 * $levelDiff); $chiefObj->applyDB($db); } -- 2.54.0 From 8aeb4883ff3de8ae7b925c226a7210a9442faa71 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Mon, 31 Jul 2023 07:22:05 +0000 Subject: [PATCH 16/19] =?UTF-8?q?refac:=20LazyVarAndAuxUpdater=20-=20LazyV?= =?UTF-8?q?arUpdater=EC=97=90=EB=8B=A4=EA=B0=80=20aux=20var=20=EB=8C=80?= =?UTF-8?q?=EC=9D=91=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/General.php | 2 + hwe/sammo/LazyVarAndAuxUpdater.php | 73 ++++++++++++++++++++++++++++++ hwe/sammo/LazyVarUpdater.php | 52 +-------------------- 3 files changed, 76 insertions(+), 51 deletions(-) create mode 100644 hwe/sammo/LazyVarAndAuxUpdater.php diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 31a38b10..0cf70ebb 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -12,6 +12,8 @@ use sammo\WarUnitTrigger as WarUnitTrigger; class General extends GeneralBase implements iAction { + use LazyVarAndAuxUpdater; + /** @var Map */ protected Map $rankVarRead; /** @var Map */ diff --git a/hwe/sammo/LazyVarAndAuxUpdater.php b/hwe/sammo/LazyVarAndAuxUpdater.php new file mode 100644 index 00000000..497698e7 --- /dev/null +++ b/hwe/sammo/LazyVarAndAuxUpdater.php @@ -0,0 +1,73 @@ +getAuxVar(''); + + } + return $this->raw; + } + + function unpackAux(){ + if(!key_exists('auxVar', $this->raw)){ + if(!key_exists('aux', $this->raw)){ + throw new \RuntimeException('aux is not set'); + } + $this->raw['auxVar'] = Json::decode($this->raw['aux']??'{}'); + } + } + + function getAuxVar(string|\BackedEnum $key){ + if($key instanceof \BackedEnum){ + $key = $key->value; + } + $this->unpackAux(); + return $this->raw['auxVar'][$key]??null; + } + + function setAuxVar(string|\BackedEnum $key, $var){ + if($key instanceof \BackedEnum){ + $key = $key->value; + } + $oldVar = $this->getAuxVar($key); + + if($oldVar === $var){ + return; + } + + if($var === null){ + unset($this->raw['auxVar'][$key]); + $this->auxUpdated = true; + return; + } + $this->raw['auxVar'][$key] = $var; + $this->auxUpdated = true; + } + + function getUpdatedValues():array { + if($this->auxUpdated){ + $this->setVar('aux', Json::encode($this->raw['auxVar'])); + $this->auxUpdated = false; + } + $updateVals = []; + foreach(array_keys($this->updatedVar) as $key){ + $updateVals[$key] = $this->raw[$key]; + } + return $updateVals; + } + + function flushUpdateValues():void { + $this->updatedVar = []; + if(key_exists('auxVar', $this->raw)){ + $this->auxUpdated = false; + unset($this->raw['auxVar']); + } + } +} \ No newline at end of file diff --git a/hwe/sammo/LazyVarUpdater.php b/hwe/sammo/LazyVarUpdater.php index b53891b6..988d20a9 100644 --- a/hwe/sammo/LazyVarUpdater.php +++ b/hwe/sammo/LazyVarUpdater.php @@ -4,14 +4,8 @@ namespace sammo; trait LazyVarUpdater{ protected $raw = []; protected $updatedVar = []; - protected $auxVar = null; - protected $auxUpdated = false; - function getRaw(bool $extractAux=false):array{ - if($extractAux){ - $this->getAuxVar(''); - - } + function getRaw():array{ return $this->raw; } @@ -38,15 +32,6 @@ trait LazyVarUpdater{ return true; } - function unpackAux(){ - if(!key_exists('auxVar', $this->raw)){ - if(!key_exists('aux', $this->raw)){ - throw new \RuntimeException('aux is not set'); - } - $this->raw['auxVar'] = Json::decode($this->raw['aux']??'{}'); - } - } - function setVar(string|\BackedEnum $key, $value){ if($key instanceof \BackedEnum){ $key = $key->value; @@ -54,33 +39,6 @@ trait LazyVarUpdater{ return $this->updateVar($key, $value); } - function getAuxVar(string|\BackedEnum $key){ - if($key instanceof \BackedEnum){ - $key = $key->value; - } - $this->unpackAux(); - return $this->raw['auxVar'][$key]??null; - } - - function setAuxVar(string|\BackedEnum $key, $var){ - if($key instanceof \BackedEnum){ - $key = $key->value; - } - $oldVar = $this->getAuxVar($key); - - if($oldVar === $var){ - return; - } - - if($var === null){ - unset($this->raw['auxVar'][$key]); - $this->auxUpdated = true; - return; - } - $this->raw['auxVar'][$key] = $var; - $this->auxUpdated = true; - } - function updateVar(string|\BackedEnum $key, $value){ if($key instanceof \BackedEnum){ $key = $key->value; @@ -160,10 +118,6 @@ trait LazyVarUpdater{ } function getUpdatedValues():array { - if($this->auxUpdated){ - $this->setVar('aux', Json::encode($this->raw['auxVar'])); - $this->auxUpdated = false; - } $updateVals = []; foreach(array_keys($this->updatedVar) as $key){ $updateVals[$key] = $this->raw[$key]; @@ -173,9 +127,5 @@ trait LazyVarUpdater{ function flushUpdateValues():void { $this->updatedVar = []; - if(key_exists('auxVar', $this->raw)){ - $this->auxUpdated = false; - unset($this->raw['auxVar']); - } } } \ No newline at end of file -- 2.54.0 From a6ff79d14863523b08974abb4f34e89875c33358 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Mon, 31 Jul 2023 07:28:01 +0000 Subject: [PATCH 17/19] =?UTF-8?q?fix:=20General=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9A=A9=20=EC=9D=B8=EC=9E=90=20=EC=88=98=EC=A0=95=20-=20Gener?= =?UTF-8?q?al=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=8A=94=20=ED=95=AD=EC=83=81?= =?UTF-8?q?=20=EB=AA=A8=EB=93=A0=EA=B1=B8=20=EC=9A=94=EA=B5=AC=ED=95=A8=20?= =?UTF-8?q?-=20=EC=9E=A5=EA=B8=B0=EC=A0=81=EC=9C=BC=EB=A1=9C=20=EB=B0=94?= =?UTF-8?q?=EB=9E=8C=EC=A7=81=20=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9D=8C=20?= =?UTF-8?q?=20=20-=20new=20General=20=ED=98=B8=EC=B6=9C=EC=9D=B4=20?= =?UTF-8?q?=EA=B7=B8=EB=83=A5=20=EA=B0=80=EB=8A=A5=ED=95=B4=EC=84=A0=20?= =?UTF-8?q?=EC=95=88=20=EB=90=A0=20=EA=B2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/Event/Action/ProcessIncome.php | 3 ++- hwe/sammo/Event/Action/RaiseDisaster.php | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hwe/sammo/Event/Action/ProcessIncome.php b/hwe/sammo/Event/Action/ProcessIncome.php index 7173070f..e90b39ca 100644 --- a/hwe/sammo/Event/Action/ProcessIncome.php +++ b/hwe/sammo/Event/Action/ProcessIncome.php @@ -39,7 +39,8 @@ class ProcessIncome extends \sammo\Event\Action $nationList = $db->query('SELECT name,nation,capital,gold,level,rate_tmp,bill,type from nation'); $cityListByNation = Util::arrayGroupBy($db->query('SELECT * FROM city'), 'nation'); - $generalRawListByNation = Util::arrayGroupBy($db->query('SELECT no,name,nation,gold,officer_level,dedication,city FROM general WHERE npc != 5'), 'nation'); + //FIXME: factory 형태로 바꿔야함 + $generalRawListByNation = Util::arrayGroupBy($db->query('SELECT %l FROM general WHERE npc != 5', Util::formatListOfBackticks(General::mergeQueryColumn()[0])), 'nation'); //국가별 처리 foreach ($nationList as $nation) { diff --git a/hwe/sammo/Event/Action/RaiseDisaster.php b/hwe/sammo/Event/Action/RaiseDisaster.php index da7cb8b0..793b279a 100644 --- a/hwe/sammo/Event/Action/RaiseDisaster.php +++ b/hwe/sammo/Event/Action/RaiseDisaster.php @@ -112,7 +112,12 @@ class RaiseDisaster extends \sammo\Event\Action $logger->flush(); if (!$isGood) { - $generalListByCity = Util::arrayGroupBy($db->query('SELECT no, name, nation, city, officer_level, injury, leadership, strength, intel, horse, weapon, book, item, crew, crewtype, atmos, train, special, special2 FROM general WHERE city IN %li', Util::squeezeFromArray($targetCityList, 'city')), 'city'); + //FIXME: factory 형태로 바꿔야함 + $generalListByCity = Util::arrayGroupBy($db->query( + 'SELECT %l FROM general WHERE city IN %li', + Util::formatListOfBackticks(General::mergeQueryColumn()[0]), + Util::squeezeFromArray($targetCityList, 'city')), + 'city'); //NOTE: 쿼리 1번이지만 복잡하기 vs 쿼리 여러번이지만 조금 더 깔끔하기 foreach ($targetCityList as $city) { $affectRatio = Util::valueFit($city['secu'] / $city['secu_max'] / 0.8, 0, 1); -- 2.54.0 From 8990436e2debdbfb8b9d3e050ce4b58e60a9154a Mon Sep 17 00:00:00 2001 From: Hide_D Date: Mon, 31 Jul 2023 07:33:03 +0000 Subject: [PATCH 18/19] =?UTF-8?q?fix:=20=EB=88=84=EB=9D=BD=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/Event/Action/ProcessIncome.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hwe/sammo/Event/Action/ProcessIncome.php b/hwe/sammo/Event/Action/ProcessIncome.php index e90b39ca..599fc9fc 100644 --- a/hwe/sammo/Event/Action/ProcessIncome.php +++ b/hwe/sammo/Event/Action/ProcessIncome.php @@ -40,7 +40,10 @@ class ProcessIncome extends \sammo\Event\Action $nationList = $db->query('SELECT name,nation,capital,gold,level,rate_tmp,bill,type from nation'); $cityListByNation = Util::arrayGroupBy($db->query('SELECT * FROM city'), 'nation'); //FIXME: factory 형태로 바꿔야함 - $generalRawListByNation = Util::arrayGroupBy($db->query('SELECT %l FROM general WHERE npc != 5', Util::formatListOfBackticks(General::mergeQueryColumn()[0])), 'nation'); + $generalRawListByNation = Util::arrayGroupBy($db->query( + 'SELECT %l FROM general WHERE npc != 5', + Util::formatListOfBackticks(General::mergeQueryColumn()[0]) + ), 'nation'); //국가별 처리 foreach ($nationList as $nation) { @@ -120,7 +123,11 @@ class ProcessIncome extends \sammo\Event\Action $nationList = $db->query('SELECT name,level,nation,capital,rice,rate_tmp,bill,type from nation'); $cityListByNation = Util::arrayGroupBy($db->query('SELECT * FROM city'), 'nation'); - $generalRawListByNation = Util::arrayGroupBy($db->query('SELECT no,name,nation,rice,officer_level,dedication,city FROM general WHERE npc != 5'), 'nation'); + //FIXME: factory 형태로 바꿔야함 + $generalRawListByNation = Util::arrayGroupBy($db->query( + 'SELECT %l FROM general WHERE npc != 5', + Util::formatListOfBackticks(General::mergeQueryColumn()[0]) + ), 'nation'); //국가별 처리 foreach ($nationList as $nation) { -- 2.54.0 From 3d5f249c1706ccdbe884a694e20218a91ac4d68c Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 3 Aug 2023 10:08:41 +0000 Subject: [PATCH 19/19] =?UTF-8?q?misc:=20Phan=20Severity=20=EB=B3=B5?= =?UTF-8?q?=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .phan/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.phan/config.php b/.phan/config.php index 6d7666c1..41e33801 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -17,7 +17,7 @@ return [ // (See `backward_compatibility_checks` for additional options) "target_php_version" => '8.2', "minimum_target_php_version" => '8.2', - 'minimum_severity' => \Phan\Issue::SEVERITY_CRITICAL, + 'minimum_severity' => \Phan\Issue::SEVERITY_NORMAL, 'file_list' => [ 'f_config/config.php', -- 2.54.0