refac: InheritPointManager를 Ds\Map으로 변경

This commit is contained in:
2022-05-08 20:11:38 +09:00
parent 5164585360
commit 282b413553
5 changed files with 95 additions and 95 deletions
+2 -2
View File
@@ -2015,10 +2015,10 @@ function deleteNation(General $lord, bool $applyDB): array
// 전 장수 재야로 // 전 장수 재야로
foreach ($nationGeneralList as $general) { foreach ($nationGeneralList as $general) {
$general->setAuxVar( $general->setAuxVar(
'max_belong', InheritanceKey::max_belong->value,
max( max(
$general->getVar('belong'), $general->getVar('belong'),
$general->getAuxVar('max_belong') ?? 0 $general->getAuxVar(InheritanceKey::max_belong->value) ?? 0
) )
); );
$general->setVar('belong', 0); $general->setVar('belong', 0);
+1 -1
View File
@@ -10,7 +10,7 @@ enum InheritanceKey: string
case max_belong = 'max_belong'; case max_belong = 'max_belong';
case max_domestic_critical = 'max_domestic_critical'; case max_domestic_critical = 'max_domestic_critical';
case active_action = 'active_action'; case active_action = 'active_action';
case snipe_combat = 'snipe_combat'; //case snipe_combat = 'snipe_combat';
case combat = 'combat'; case combat = 'combat';
case sabotage = 'sabotage'; case sabotage = 'sabotage';
case unifier = 'unifier'; case unifier = 'unifier';
+1 -1
View File
@@ -1322,7 +1322,7 @@ class General implements iAction
return $result; return $result;
} }
public function getInheritancePoint(InheritanceKey $key, &$aux = null, bool $forceCalc = false): int|float public function getInheritancePoint(InheritanceKey $key, &$aux = null, bool $forceCalc = false): int|float|null
{ {
return InheritancePointManager::getInstance()->getInheritancePoint($this, $key, $aux, $forceCalc); return InheritancePointManager::getInstance()->getInheritancePoint($this, $key, $aux, $forceCalc);
} }
+33 -33
View File
@@ -2,32 +2,33 @@
namespace sammo; namespace sammo;
use sammo\VO\InheritancePointType;; use sammo\VO\InheritancePointType;
use Ds\Map;
use sammo\Enums\InheritanceKey; use sammo\Enums\InheritanceKey;
class InheritancePointManager class InheritancePointManager
{ {
/** @var array[string]InheritancePointType */ /** @var Map<InheritanceKey,InheritancePointType> */
public readonly array $inheritanceKey; public readonly Map $inheritanceKey;
private static self|null $instance = null; private static self|null $instance = null;
private function __construct() private function __construct()
{ {
$this->inheritanceKey = [ $inheritanceKey = new Map();
InheritanceKey::previous->value => new InheritancePointType(true, 1, '기존 포인트'), $inheritanceKey->put(InheritanceKey::previous, new InheritancePointType(true, 1, '기존 포인트'));
InheritanceKey::lived_month->value => new InheritancePointType(true, 1, '생존'), $inheritanceKey->put(InheritanceKey::lived_month, new InheritancePointType(true, 1, '생존'));
InheritanceKey::max_belong->value => new InheritancePointType(false, 10, '최대 임관년 수'), $inheritanceKey->put(InheritanceKey::max_belong, new InheritancePointType(false, 10, '최대 임관년 수'));
InheritanceKey::max_domestic_critical->value => new InheritancePointType(true, 1, '최대 연속 내정 성공'), $inheritanceKey->put(InheritanceKey::max_domestic_critical, new InheritancePointType(true, 1, '최대 연속 내정 성공'));
InheritanceKey::active_action->value => new InheritancePointType(true, 3, '능동 행동 수'), $inheritanceKey->put(InheritanceKey::active_action, new InheritancePointType(true, 3, '능동 행동 수'));
//InheritanceKey::snipe_combat->value => new InheritancePointType(true, 10, '병종 상성 우위 횟수'), //$inheritanceKey->put(InheritanceKey::snipe_combat, new InheritancePointType(true, 10, '병종 상성 우위 횟수'));
InheritanceKey::combat->value => new InheritancePointType(['rank', 'warnum'], 5, '전투 횟수'), $inheritanceKey->put(InheritanceKey::combat, new InheritancePointType(['rank', 'warnum'], 5, '전투 횟수'));
InheritanceKey::sabotage->value => new InheritancePointType(['rank', 'firenum'], 20, '계략 성공 횟수'), $inheritanceKey->put(InheritanceKey::sabotage, new InheritancePointType(['rank', 'firenum'], 20, '계략 성공 횟수'));
InheritanceKey::unifier->value => new InheritancePointType(true, 1, '천통 기여'), $inheritanceKey->put(InheritanceKey::unifier, new InheritancePointType(true, 1, '천통 기여'));
InheritanceKey::dex->value => new InheritancePointType(false, 0.001, '숙련도'), $inheritanceKey->put(InheritanceKey::dex, new InheritancePointType(false, 0.001, '숙련도'));
InheritanceKey::tournament->value => new InheritancePointType(true, 1, '토너먼트'), $inheritanceKey->put(InheritanceKey::tournament, new InheritancePointType(true, 1, '토너먼트'));
InheritanceKey::betting->value => new InheritancePointType(false, 10, '베팅 당첨'), $inheritanceKey->put(InheritanceKey::betting, new InheritancePointType(false, 10, '베팅 당첨'));
]; $this->inheritanceKey = $inheritanceKey;
} }
public static function getInstance(): self public static function getInstance(): self
@@ -40,13 +41,14 @@ class InheritancePointManager
public function getInheritancePointType(InheritanceKey $key): InheritancePointType public function getInheritancePointType(InheritanceKey $key): InheritancePointType
{ {
if (!key_exists($key->value, $this->inheritanceKey)) { $value = $this->inheritanceKey[$key];
throw new \OutOfRangeException("{$key}는 유산 타입이 아님"); if ($value === null) {
throw new \OutOfRangeException("{$key->value}는 유산 타입이 아님");
} }
return $this->inheritanceKey[$key->value]; return $value;
} }
public function getInheritancePoint(General $general, InheritanceKey $key, &$aux = null, bool $forceCalc = false) public function getInheritancePoint(General $general, InheritanceKey $key, &$aux = null, bool $forceCalc = false): int|float|null
{ {
$inheritType = $this->getInheritancePointType($key); $inheritType = $this->getInheritancePointType($key);
@@ -91,7 +93,7 @@ class InheritancePointManager
return [0, null]; return [0, null];
}; };
switch ($key) { switch ($key) {
case 'dex': case InheritanceKey::dex:
$extractFn = function () use ($general, $multiplier) { $extractFn = function () use ($general, $multiplier) {
$dexLimit = Util::array_last(getDexLevelList())[0]; $dexLimit = Util::array_last(getDexLevelList())[0];
$totalDex = 0; $totalDex = 0;
@@ -106,7 +108,7 @@ class InheritancePointManager
return [$totalDex * $multiplier, null]; return [$totalDex * $multiplier, null];
}; };
break; break;
case 'betting': case InheritanceKey::betting:
$extractFn = function () use ($general, $multiplier) { $extractFn = function () use ($general, $multiplier) {
$betWin = $general->getRankVar('betwin'); $betWin = $general->getRankVar('betwin');
$betWinRate = $general->getRankVar('betwingold') / max(1, $general->getRankVar('betgold')); $betWinRate = $general->getRankVar('betwingold') / max(1, $general->getRankVar('betgold'));
@@ -114,14 +116,14 @@ class InheritancePointManager
return [$betWin * $multiplier * pow($betWinRate, 2), null]; return [$betWin * $multiplier * pow($betWinRate, 2), null];
}; };
break; break;
case 'max_belong': case InheritanceKey::max_belong:
$extractFn = function () use ($general, $multiplier) { $extractFn = function () use ($general, $multiplier) {
$maxBelong = max($general->getVar('belong'), $general->getAuxVar('max_belong') ?? 0); $maxBelong = max($general->getVar('belong'), $general->getAuxVar(InheritanceKey::max_belong->value) ?? 0);
return [$maxBelong * $multiplier, null]; return [$maxBelong * $multiplier, null];
}; };
break; break;
default: default:
throw new \InvalidArgumentException("{$key}는 유산 추출기를 보유하고 있지 않음"); throw new \InvalidArgumentException("{$key->value}는 유산 추출기를 보유하고 있지 않음");
} }
[$value, $aux] = ($extractFn)(); [$value, $aux] = ($extractFn)();
@@ -202,9 +204,10 @@ class InheritancePointManager
$inheritStor->setValue($key->value, [$newValue, $aux]); $inheritStor->setValue($key->value, [$newValue, $aux]);
} }
public function clearInheritancePoint(General $general){ public function clearInheritancePoint(General $general)
{
$ownerID = $general->getVar('owner'); $ownerID = $general->getVar('owner');
if(!$ownerID){ if (!$ownerID) {
return; return;
} }
@@ -222,7 +225,7 @@ class InheritancePointManager
$previousPointInfo = $allPoints[InheritanceKey::previous->value]; $previousPointInfo = $allPoints[InheritanceKey::previous->value];
$inheritStor->resetValues(); $inheritStor->resetValues();
$inheritStor->setValue(InheritanceKey::previous->value, $previousPointInfo); $inheritStor->setValue(InheritanceKey::previous->value, $previousPointInfo);
} }
public function mergeTotalInheritancePoint(General $general, bool $isEnd = false) public function mergeTotalInheritancePoint(General $general, bool $isEnd = false)
{ {
@@ -256,8 +259,7 @@ class InheritancePointManager
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
$inheritStor->cacheAll(); $inheritStor->cacheAll();
foreach ($this->inheritanceKey as $rKey => $keyObj) { foreach ($this->inheritanceKey as $key => $keyObj) {
$key = InheritanceKey::from($rKey);
$storeType = $keyObj->storeType; $storeType = $keyObj->storeType;
$aux = null; $aux = null;
$point = $general->getInheritancePoint($key, $aux, true); $point = $general->getInheritancePoint($key, $aux, true);
@@ -321,6 +323,4 @@ class InheritancePointManager
$inheritStor->setValue(InheritanceKey::previous->value, [$totalPoint, null]); $inheritStor->setValue(InheritanceKey::previous->value, [$totalPoint, null]);
return $totalPoint; return $totalPoint;
} }
} }
+1 -1
View File
@@ -61,7 +61,7 @@ foreach (GameConst::$allItems as $subItems) {
$items = []; $items = [];
foreach (InheritanceKey::cases() as $key) { foreach (InheritanceKey::cases() as $key) {
$items[$key] = $me->getInheritancePoint($key) ?? 0; $items[$key->value] = $me->getInheritancePoint($key) ?? 0;
} }
$resetTurnTimeLevel = ($me->getAuxVar('inheritResetTurnTime') ?? -1) + 1; $resetTurnTimeLevel = ($me->getAuxVar('inheritResetTurnTime') ?? -1) + 1;