forked from devsam/core
refac: InheritPointManager를 Ds\Map으로 변경
This commit is contained in:
+2
-2
@@ -2015,10 +2015,10 @@ function deleteNation(General $lord, bool $applyDB): array
|
||||
// 전 장수 재야로
|
||||
foreach ($nationGeneralList as $general) {
|
||||
$general->setAuxVar(
|
||||
'max_belong',
|
||||
InheritanceKey::max_belong->value,
|
||||
max(
|
||||
$general->getVar('belong'),
|
||||
$general->getAuxVar('max_belong') ?? 0
|
||||
$general->getAuxVar(InheritanceKey::max_belong->value) ?? 0
|
||||
)
|
||||
);
|
||||
$general->setVar('belong', 0);
|
||||
|
||||
@@ -10,7 +10,7 @@ enum InheritanceKey: string
|
||||
case max_belong = 'max_belong';
|
||||
case max_domestic_critical = 'max_domestic_critical';
|
||||
case active_action = 'active_action';
|
||||
case snipe_combat = 'snipe_combat';
|
||||
//case snipe_combat = 'snipe_combat';
|
||||
case combat = 'combat';
|
||||
case sabotage = 'sabotage';
|
||||
case unifier = 'unifier';
|
||||
|
||||
@@ -1322,7 +1322,7 @@ class General implements iAction
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -2,32 +2,33 @@
|
||||
|
||||
namespace sammo;
|
||||
|
||||
use sammo\VO\InheritancePointType;;
|
||||
use sammo\VO\InheritancePointType;
|
||||
use Ds\Map;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
class InheritancePointManager
|
||||
{
|
||||
/** @var array[string]InheritancePointType */
|
||||
public readonly array $inheritanceKey;
|
||||
/** @var Map<InheritanceKey,InheritancePointType> */
|
||||
public readonly Map $inheritanceKey;
|
||||
|
||||
private static self|null $instance = null;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->inheritanceKey = [
|
||||
InheritanceKey::previous->value => new InheritancePointType(true, 1, '기존 포인트'),
|
||||
InheritanceKey::lived_month->value => new InheritancePointType(true, 1, '생존'),
|
||||
InheritanceKey::max_belong->value => new InheritancePointType(false, 10, '최대 임관년 수'),
|
||||
InheritanceKey::max_domestic_critical->value => new InheritancePointType(true, 1, '최대 연속 내정 성공'),
|
||||
InheritanceKey::active_action->value => new InheritancePointType(true, 3, '능동 행동 수'),
|
||||
//InheritanceKey::snipe_combat->value => new InheritancePointType(true, 10, '병종 상성 우위 횟수'),
|
||||
InheritanceKey::combat->value => new InheritancePointType(['rank', 'warnum'], 5, '전투 횟수'),
|
||||
InheritanceKey::sabotage->value => new InheritancePointType(['rank', 'firenum'], 20, '계략 성공 횟수'),
|
||||
InheritanceKey::unifier->value => new InheritancePointType(true, 1, '천통 기여'),
|
||||
InheritanceKey::dex->value => new InheritancePointType(false, 0.001, '숙련도'),
|
||||
InheritanceKey::tournament->value => new InheritancePointType(true, 1, '토너먼트'),
|
||||
InheritanceKey::betting->value => new InheritancePointType(false, 10, '베팅 당첨'),
|
||||
];
|
||||
$inheritanceKey = new Map();
|
||||
$inheritanceKey->put(InheritanceKey::previous, new InheritancePointType(true, 1, '기존 포인트'));
|
||||
$inheritanceKey->put(InheritanceKey::lived_month, new InheritancePointType(true, 1, '생존'));
|
||||
$inheritanceKey->put(InheritanceKey::max_belong, new InheritancePointType(false, 10, '최대 임관년 수'));
|
||||
$inheritanceKey->put(InheritanceKey::max_domestic_critical, new InheritancePointType(true, 1, '최대 연속 내정 성공'));
|
||||
$inheritanceKey->put(InheritanceKey::active_action, new InheritancePointType(true, 3, '능동 행동 수'));
|
||||
//$inheritanceKey->put(InheritanceKey::snipe_combat, new InheritancePointType(true, 10, '병종 상성 우위 횟수'));
|
||||
$inheritanceKey->put(InheritanceKey::combat, new InheritancePointType(['rank', 'warnum'], 5, '전투 횟수'));
|
||||
$inheritanceKey->put(InheritanceKey::sabotage, new InheritancePointType(['rank', 'firenum'], 20, '계략 성공 횟수'));
|
||||
$inheritanceKey->put(InheritanceKey::unifier, new InheritancePointType(true, 1, '천통 기여'));
|
||||
$inheritanceKey->put(InheritanceKey::dex, new InheritancePointType(false, 0.001, '숙련도'));
|
||||
$inheritanceKey->put(InheritanceKey::tournament, new InheritancePointType(true, 1, '토너먼트'));
|
||||
$inheritanceKey->put(InheritanceKey::betting, new InheritancePointType(false, 10, '베팅 당첨'));
|
||||
$this->inheritanceKey = $inheritanceKey;
|
||||
}
|
||||
|
||||
public static function getInstance(): self
|
||||
@@ -40,13 +41,14 @@ class InheritancePointManager
|
||||
|
||||
public function getInheritancePointType(InheritanceKey $key): InheritancePointType
|
||||
{
|
||||
if (!key_exists($key->value, $this->inheritanceKey)) {
|
||||
throw new \OutOfRangeException("{$key}는 유산 타입이 아님");
|
||||
$value = $this->inheritanceKey[$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);
|
||||
|
||||
@@ -91,7 +93,7 @@ class InheritancePointManager
|
||||
return [0, null];
|
||||
};
|
||||
switch ($key) {
|
||||
case 'dex':
|
||||
case InheritanceKey::dex:
|
||||
$extractFn = function () use ($general, $multiplier) {
|
||||
$dexLimit = Util::array_last(getDexLevelList())[0];
|
||||
$totalDex = 0;
|
||||
@@ -106,7 +108,7 @@ class InheritancePointManager
|
||||
return [$totalDex * $multiplier, null];
|
||||
};
|
||||
break;
|
||||
case 'betting':
|
||||
case InheritanceKey::betting:
|
||||
$extractFn = function () use ($general, $multiplier) {
|
||||
$betWin = $general->getRankVar('betwin');
|
||||
$betWinRate = $general->getRankVar('betwingold') / max(1, $general->getRankVar('betgold'));
|
||||
@@ -114,14 +116,14 @@ class InheritancePointManager
|
||||
return [$betWin * $multiplier * pow($betWinRate, 2), null];
|
||||
};
|
||||
break;
|
||||
case 'max_belong':
|
||||
case InheritanceKey::max_belong:
|
||||
$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];
|
||||
};
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException("{$key}는 유산 추출기를 보유하고 있지 않음");
|
||||
throw new \InvalidArgumentException("{$key->value}는 유산 추출기를 보유하고 있지 않음");
|
||||
}
|
||||
|
||||
[$value, $aux] = ($extractFn)();
|
||||
@@ -131,98 +133,99 @@ class InheritancePointManager
|
||||
|
||||
public function setInheritancePoint(General $general, InheritanceKey $key, $value, $aux = null)
|
||||
{
|
||||
if (!is_int($value) && !is_float($value)) {
|
||||
throw new \InvalidArgumentException("{$value}는 숫자가 아님");
|
||||
}
|
||||
$inheritType = InheritancePointManager::getInstance()->getInheritancePointType($key);
|
||||
if (!is_int($value) && !is_float($value)) {
|
||||
throw new \InvalidArgumentException("{$value}는 숫자가 아님");
|
||||
}
|
||||
$inheritType = InheritancePointManager::getInstance()->getInheritancePointType($key);
|
||||
|
||||
$storeType = $inheritType->storeType;
|
||||
$multiplier = $inheritType->pointCoeff;
|
||||
if ($storeType !== true) {
|
||||
throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님");
|
||||
}
|
||||
if ($multiplier != 1 && $value != 0) {
|
||||
throw new \InvalidArgumentException("{$key}는 1:1 유산 포인트가 아님");
|
||||
}
|
||||
$storeType = $inheritType->storeType;
|
||||
$multiplier = $inheritType->pointCoeff;
|
||||
if ($storeType !== true) {
|
||||
throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님");
|
||||
}
|
||||
if ($multiplier != 1 && $value != 0) {
|
||||
throw new \InvalidArgumentException("{$key}는 1:1 유산 포인트가 아님");
|
||||
}
|
||||
|
||||
$ownerID = $general->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return;
|
||||
}
|
||||
$ownerID = $general->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($general->getVar('npc') >= 2) {
|
||||
return;
|
||||
}
|
||||
if ($general->getVar('npc') >= 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gameStor = KVStorage::getStorage(DB::db(), 'game_env');
|
||||
if ($gameStor->isunited != 0) {
|
||||
return;
|
||||
}
|
||||
$gameStor = KVStorage::getStorage(DB::db(), 'game_env');
|
||||
if ($gameStor->isunited != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
$inheritStor->setValue($key, [$value, $aux]);
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
$inheritStor->setValue($key, [$value, $aux]);
|
||||
}
|
||||
|
||||
public function increaseInheritancePoint(General $general, InheritanceKey $key, $value, $aux = null)
|
||||
{
|
||||
if (!is_int($value) && !is_float($value)) {
|
||||
throw new \InvalidArgumentException("{$value}는 숫자가 아님");
|
||||
}
|
||||
if (!is_int($value) && !is_float($value)) {
|
||||
throw new \InvalidArgumentException("{$value}는 숫자가 아님");
|
||||
}
|
||||
|
||||
$inheritType = InheritancePointManager::getInstance()->getInheritancePointType($key);
|
||||
$inheritType = InheritancePointManager::getInstance()->getInheritancePointType($key);
|
||||
|
||||
$storeType = $inheritType->storeType;
|
||||
$multiplier = $inheritType->pointCoeff;
|
||||
if ($storeType !== true) {
|
||||
throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님");
|
||||
}
|
||||
$storeType = $inheritType->storeType;
|
||||
$multiplier = $inheritType->pointCoeff;
|
||||
if ($storeType !== true) {
|
||||
throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님");
|
||||
}
|
||||
|
||||
$ownerID = $general->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return;
|
||||
}
|
||||
$ownerID = $general->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($general->getVar('npc') >= 2) {
|
||||
return;
|
||||
}
|
||||
if ($general->getVar('npc') >= 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gameStor = KVStorage::getStorage(DB::db(), 'game_env');
|
||||
if ($gameStor->isunited != 0) {
|
||||
return;
|
||||
}
|
||||
$gameStor = KVStorage::getStorage(DB::db(), 'game_env');
|
||||
if ($gameStor->isunited != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
[$oldValue, $oldAux] = $inheritStor->getValue($key->value) ?? [0, null];
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
[$oldValue, $oldAux] = $inheritStor->getValue($key->value) ?? [0, null];
|
||||
|
||||
if ($oldAux !== $aux) {
|
||||
$oldValue = 0;
|
||||
}
|
||||
if ($oldAux !== $aux) {
|
||||
$oldValue = 0;
|
||||
}
|
||||
|
||||
$newValue = $oldValue + $value * $multiplier;
|
||||
$inheritStor->setValue($key->value, [$newValue, $aux]);
|
||||
$newValue = $oldValue + $value * $multiplier;
|
||||
$inheritStor->setValue($key->value, [$newValue, $aux]);
|
||||
}
|
||||
|
||||
public function clearInheritancePoint(General $general){
|
||||
public function clearInheritancePoint(General $general)
|
||||
{
|
||||
$ownerID = $general->getVar('owner');
|
||||
if(!$ownerID){
|
||||
return;
|
||||
if (!$ownerID) {
|
||||
return;
|
||||
}
|
||||
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
$allPoints = $inheritStor->getAll();
|
||||
if (!$allPoints || count($allPoints) == 0) {
|
||||
//비었으므로 리셋 안함
|
||||
return;
|
||||
//비었으므로 리셋 안함
|
||||
return;
|
||||
}
|
||||
if (count($allPoints) == 1 && key_exists(InheritanceKey::previous->value, $allPoints)) {
|
||||
//이미 리셋되었으므로 리셋 안함
|
||||
return;
|
||||
//이미 리셋되었으므로 리셋 안함
|
||||
return;
|
||||
}
|
||||
|
||||
$previousPointInfo = $allPoints[InheritanceKey::previous->value];
|
||||
$inheritStor->resetValues();
|
||||
$inheritStor->setValue(InheritanceKey::previous->value, $previousPointInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public function mergeTotalInheritancePoint(General $general, bool $isEnd = false)
|
||||
{
|
||||
@@ -256,8 +259,7 @@ class InheritancePointManager
|
||||
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
$inheritStor->cacheAll();
|
||||
foreach ($this->inheritanceKey as $rKey => $keyObj) {
|
||||
$key = InheritanceKey::from($rKey);
|
||||
foreach ($this->inheritanceKey as $key => $keyObj) {
|
||||
$storeType = $keyObj->storeType;
|
||||
$aux = null;
|
||||
$point = $general->getInheritancePoint($key, $aux, true);
|
||||
@@ -321,6 +323,4 @@ class InheritancePointManager
|
||||
$inheritStor->setValue(InheritanceKey::previous->value, [$totalPoint, null]);
|
||||
return $totalPoint;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ foreach (GameConst::$allItems as $subItems) {
|
||||
|
||||
$items = [];
|
||||
foreach (InheritanceKey::cases() as $key) {
|
||||
$items[$key] = $me->getInheritancePoint($key) ?? 0;
|
||||
$items[$key->value] = $me->getInheritancePoint($key) ?? 0;
|
||||
}
|
||||
|
||||
$resetTurnTimeLevel = ($me->getAuxVar('inheritResetTurnTime') ?? -1) + 1;
|
||||
|
||||
Reference in New Issue
Block a user