refac: 유산 포인트 파트를 별도의 Manager로 분리, enum 적용
This commit is contained in:
+1
-1
@@ -15,7 +15,7 @@ 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.0',
|
||||
"target_php_version" => '8.1',
|
||||
'backward_compatibility_checks ' => true,
|
||||
'minimum_severity' => \Phan\Issue::SEVERITY_NORMAL,
|
||||
|
||||
|
||||
@@ -25,8 +25,9 @@ foreach ($db->queryFirstColumn(
|
||||
CheckHall($generalNo);
|
||||
}
|
||||
|
||||
$inheritPointManager = InheritancePointManager::getInstance();
|
||||
foreach(General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc = 0')) as $genObj){
|
||||
$genObj->mergeTotalInheritancePoint(true);
|
||||
applyInheritanceUser($genObj->getVar('owner'));
|
||||
$genObj->clearInheritancePoint();
|
||||
$inheritPointManager->mergeTotalInheritancePoint($genObj, true);
|
||||
$inheritPointManager->applyInheritanceUser($genObj->getVar('owner'));
|
||||
$inheritPointManager->clearInheritancePoint($genObj);
|
||||
}
|
||||
+4
-3
@@ -3,6 +3,7 @@
|
||||
namespace sammo;
|
||||
|
||||
use DateTime;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use sammo\Event\Action;
|
||||
|
||||
require_once 'process_war.php';
|
||||
@@ -1617,7 +1618,7 @@ function giveRandomUniqueItem(General $general, string $acquireType): bool
|
||||
if (!$availableUnique) {
|
||||
if ($general->getAuxVar('inheritRandomUnique')) {
|
||||
$general->setAuxVar('inheritRandomUnique', null);
|
||||
$general->increaseInheritancePoint('previous', GameConst::$inheritItemRandomPoint);
|
||||
$general->increaseInheritancePoint(InheritanceKey::previous, GameConst::$inheritItemRandomPoint);
|
||||
$userLogger = new UserLogger($general->getVar('owner'));
|
||||
$userLogger->push(sprintf("얻을 유니크가 없어 %d 포인트 반환", GameConst::$inheritItemRandomPoint), "inheritPoint");
|
||||
}
|
||||
@@ -1687,7 +1688,7 @@ function rollbackInheritUniqueTrial(General $general, string $itemKey, string $r
|
||||
//두 값이 general, KVStorage 둘다 있고, 이중에선 KVStorage 값을 기준으로 하자 따르자
|
||||
[,, $amount] = $ownTrial;
|
||||
$trialStor->deleteValue("u{$ownerID}");
|
||||
$general->increaseInheritancePoint('previous', $amount);
|
||||
$general->increaseInheritancePoint(InheritanceKey::previous, $amount);
|
||||
LogText("선택유니크 롤백포인트:{$ownerID}", $amount);
|
||||
|
||||
$userLogger = new UserLogger($ownerID);
|
||||
@@ -1902,7 +1903,7 @@ function tryUniqueItemLottery(General $general, string $acquireType = '아이템
|
||||
LogText("{$general->getName()}, {$general->getID()} 모든 아이템", $trialCnt);
|
||||
if ($general->getAuxVar('inheritRandomUnique')) {
|
||||
$general->setAuxVar('inheritRandomUnique', null);
|
||||
$general->increaseInheritancePoint('previous', GameConst::$inheritItemRandomPoint);
|
||||
$general->increaseInheritancePoint(InheritanceKey::previous, GameConst::$inheritItemRandomPoint);
|
||||
$userLogger = new UserLogger($general->getVar('owner'));
|
||||
$userLogger->push(sprintf("유니크를 얻을 공간이 없어 %d 포인트 반환", GameConst::$inheritItemRandomPoint), "inheritPoint");
|
||||
}
|
||||
|
||||
+11
-50
@@ -3,6 +3,7 @@
|
||||
namespace sammo;
|
||||
|
||||
use Monolog\Logger;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
/**
|
||||
* 게임 룰에 해당하는 함수 모음
|
||||
@@ -702,7 +703,7 @@ function updateNationState()
|
||||
|
||||
if ($chiefID) {
|
||||
$chiefObj = General::createGeneralObjFromDB($chiefID, ['belong', 'npc', 'aux'], 2);
|
||||
$chiefObj->increaseInheritancePoint('unifier', 250 * $levelDiff);
|
||||
$chiefObj->increaseInheritancePoint(InheritanceKey::unifier, 250 * $levelDiff);
|
||||
$chiefObj->applyDB($db);
|
||||
}
|
||||
}
|
||||
@@ -1022,15 +1023,16 @@ function checkEmperior()
|
||||
$nationLogger = new ActionLogger(0, $nationID, $admin['year'], $admin['month']);
|
||||
$nationLogger->pushNationalHistoryLog("<D><b>{$nationName}</b></>{$josaYi} 전토를 통일");
|
||||
|
||||
$inheritPointManager = InheritancePointManager::getInstance();
|
||||
foreach (General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc < 2')) as $genObj) {
|
||||
if ($genObj->getNationID() == $nationID) {
|
||||
if ($genObj->getVar('officer_level') > 4) {
|
||||
$genObj->increaseInheritancePoint('unifier', 2000);
|
||||
$genObj->increaseInheritancePoint(InheritanceKey::unifier, 2000);
|
||||
};
|
||||
}
|
||||
$genObj->mergeTotalInheritancePoint(true);
|
||||
applyInheritanceUser($genObj->getVar('owner'));
|
||||
$genObj->clearInheritancePoint();
|
||||
$inheritPointManager->mergeTotalInheritancePoint($genObj, true);
|
||||
$inheritPointManager->applyInheritanceUser($genObj->getVar('owner'));
|
||||
$inheritPointManager->clearInheritancePoint($genObj);
|
||||
}
|
||||
|
||||
$gameStor->isunited = 2;
|
||||
@@ -1184,55 +1186,14 @@ function checkEmperior()
|
||||
LogHistory();
|
||||
}
|
||||
|
||||
function applyInheritanceUser(int $userID, bool $isRebirth = false): float
|
||||
{
|
||||
//FIXME: 은퇴, 사망, 천통 시점에 바로 반영한다면 여기가 아니라 general class로 이동하는 것이 옳음
|
||||
//또한 굳이 merge, apply, clean 3단계를 거쳐야 할 이유도 없음
|
||||
$rebirthDegraded = [
|
||||
'dex' => 0.5,
|
||||
];
|
||||
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}");
|
||||
$totalPoint = 0;
|
||||
$allPoints = $inheritStor->getAll();
|
||||
if (!$allPoints || count($allPoints) == 0) {
|
||||
//비었으므로 리셋 안함
|
||||
return 0;
|
||||
}
|
||||
if (count($allPoints) == 1 && key_exists('previous', $allPoints)) {
|
||||
//이미 리셋되었으므로 리셋 안함
|
||||
return $allPoints['previous'][0];
|
||||
}
|
||||
|
||||
$userLogger = new UserLogger($userID);
|
||||
|
||||
$previousPoint = ($allPoints['previous'] ?? [0, 0])[0];
|
||||
|
||||
foreach ($allPoints as $key => [$value,]) {
|
||||
if ($isRebirth && key_exists($key, $rebirthDegraded)) {
|
||||
$value *= $rebirthDegraded[$key];
|
||||
}
|
||||
$keyText = General::INHERITANCE_KEY[$key][2];
|
||||
$userLogger->push("{$keyText} 포인트 {$value} 증가", "inheritPoint");
|
||||
$totalPoint += $value;
|
||||
}
|
||||
$totalPoint = Util::toInt($totalPoint);
|
||||
$userLogger->push("포인트 {$previousPoint} => {$totalPoint}", "inheritPoint");
|
||||
$userLogger->flush();
|
||||
|
||||
$inheritStor->resetValues();
|
||||
$inheritStor->setValue('previous', [$totalPoint, null]);
|
||||
return $totalPoint;
|
||||
}
|
||||
|
||||
function updateMaxDomesticCritical(General $general, $score)
|
||||
{
|
||||
$maxDomesticCritical = $general->getAuxVar('max_domestic_critical') ?? 0;
|
||||
$maxDomesticCritical = $general->getAuxVar(InheritanceKey::max_domestic_critical->value) ?? 0;
|
||||
$maxDomesticCritical += $score / 2;
|
||||
$general->setAuxVar('max_domestic_critical', $maxDomesticCritical);
|
||||
$general->setAuxVar(InheritanceKey::max_domestic_critical->value, $maxDomesticCritical);
|
||||
|
||||
$oldMaxDomesticCritical = $general->getInheritancePoint('max_domestic_critical');
|
||||
$oldMaxDomesticCritical = $general->getInheritancePoint(InheritanceKey::max_domestic_critical);
|
||||
if ($maxDomesticCritical > $oldMaxDomesticCritical) {
|
||||
$general->setInheritancePoint('max_domestic_critical', $maxDomesticCritical);
|
||||
$general->setInheritancePoint(InheritanceKey::max_domestic_critical, $maxDomesticCritical);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace sammo;
|
||||
|
||||
use sammo\DTO\BettingInfo;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
function processTournament()
|
||||
{
|
||||
@@ -920,7 +921,7 @@ function setGift($tnmt_type, $tnmt, $phase)
|
||||
//포상 장수 이름, 금액
|
||||
$resultHelper[$generalID]['reward'] += $cost;
|
||||
$resultHelper[$generalID]['msg'] = "<span class='ev_highlight'>4강 진출</span>";
|
||||
General::createGeneralObjFromDB($generalID)->increaseInheritancePoint('tournament', 10);
|
||||
General::createGeneralObjFromDB($generalID)->increaseInheritancePoint(InheritanceKey::tournament, 10);
|
||||
}
|
||||
//결승자 명성 돈
|
||||
$cost = $admin['develcost'] * 6;
|
||||
@@ -992,7 +993,7 @@ function setGift($tnmt_type, $tnmt, $phase)
|
||||
$logger = $general['logger'];
|
||||
$logger->pushGeneralActionLog("<C>{$tp}</> 대회의 {$general['msg']}로 <C>{$rewardText}</>의 <S>상금</>, 약간의 <S>명성</> 획득!", ActionLogger::EVENT_PLAIN);
|
||||
//TODO: 토너먼트의 다른 값이 모두 sql에 직접 입력하므로 기반을 바꿔야함.
|
||||
$generalObjList[$generalID]->increaseInheritancePoint('tournament', $general['inheritance_point']);
|
||||
$generalObjList[$generalID]->increaseInheritancePoint(InheritanceKey::tournament, $general['inheritance_point']);
|
||||
}
|
||||
|
||||
//당첨칸에 베팅한 사람들만
|
||||
|
||||
+2
-2
@@ -269,10 +269,10 @@ function processWar_NG(
|
||||
$defenderCrewTypeCoef = $defender->getCrewType()->getAttackCoef($attacker->getCrewType()) * $attacker->getCrewType()->getDefenceCoef($defender->getCrewType());
|
||||
/*
|
||||
if($attackerCrewTypeCoef > $defenderCrewTypeCoef && $attacker instanceof WarUnitGeneral){
|
||||
$attacker->getGeneral()->increaseInheritancePoint('snipe_combat', 1);
|
||||
$attacker->getGeneral()->increaseInheritancePoint(InheritanceKey::snipe_combat, 1);
|
||||
}
|
||||
if($defenderCrewTypeCoef > $attackerCrewTypeCoef && $defender instanceof WarUnitGeneral){
|
||||
$defender->getGeneral()->increaseInheritancePoint('snipe_combat', 1);
|
||||
$defender->getGeneral()->increaseInheritancePoint(InheritanceKey::snipe_combat, 1);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use sammo\DB;
|
||||
use sammo\GameConst;
|
||||
use sammo\GameUnitConst;
|
||||
use sammo\General;
|
||||
use sammo\InheritancePointManager;
|
||||
use sammo\JosaUtil;
|
||||
use sammo\Json;
|
||||
use sammo\KVStorage;
|
||||
@@ -26,7 +27,6 @@ use function sammo\cutTurn;
|
||||
use function sammo\getGeneralSpecialWarName;
|
||||
use function sammo\getRandTurn;
|
||||
use function sammo\pushAdminLog;
|
||||
use function sammo\applyInheritanceUser;
|
||||
|
||||
class Join extends \sammo\BaseAPI
|
||||
{
|
||||
@@ -155,7 +155,8 @@ class Join extends \sammo\BaseAPI
|
||||
|
||||
$admin = $gameStor->getValues(['scenario', 'turnterm', 'turntime', 'show_img_level', 'startyear', 'year', 'month']);
|
||||
|
||||
$inheritTotalPoint = applyInheritanceUser($userID);
|
||||
$inheritPointManager = InheritancePointManager::getInstance();
|
||||
$inheritTotalPoint = $inheritPointManager->applyInheritanceUser($userID);
|
||||
$inheritRequiredPoint = 0;
|
||||
|
||||
$userLogger = new UserLogger($userID, $admin['year'], $admin['month'], false);
|
||||
|
||||
@@ -14,6 +14,8 @@ use \sammo\{
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
use function sammo\refreshNationStaticInfo;
|
||||
use function sammo\getAllNationStaticInfo;
|
||||
use function sammo\tryUniqueItemLottery;
|
||||
@@ -162,7 +164,7 @@ class che_거병 extends Command\GeneralCommand{
|
||||
$exp = 100;
|
||||
$ded = 100;
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->setVar('belong', 1);
|
||||
|
||||
@@ -19,6 +19,8 @@ use function \sammo\getAllNationStaticInfo;
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
use function sammo\buildNationTypeClass;
|
||||
use function sammo\refreshNationStaticInfo;
|
||||
use function sammo\GetNationColors;
|
||||
@@ -188,7 +190,7 @@ class che_건국 extends Command\GeneralCommand
|
||||
|
||||
refreshNationStaticInfo();
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general, '건국');
|
||||
|
||||
@@ -18,7 +18,7 @@ use function \sammo\getNationStaticInfo;
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
class che_등용수락 extends Command\GeneralCommand{
|
||||
static protected $actionName = '등용 수락';
|
||||
@@ -194,7 +194,7 @@ class che_등용수락 extends Command\GeneralCommand{
|
||||
}
|
||||
$db->update('nation', $setScoutNationValues, 'nation=%i', $destNationID);
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$general->setVar('permission', 'normal');
|
||||
$general->setVar('belong', 1);
|
||||
$general->setVar('officer_level', 1);
|
||||
|
||||
@@ -19,6 +19,7 @@ use function \sammo\tryUniqueItemLottery;
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use sammo\MustNotBeReachedException;
|
||||
|
||||
|
||||
@@ -285,7 +286,7 @@ class che_랜덤임관 extends Command\GeneralCommand
|
||||
$general->setAuxVar('joinedNations', $joinedNations);
|
||||
}
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$general->addExperience($exp);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
|
||||
@@ -13,6 +13,7 @@ use \sammo\{
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
use function sammo\tryRollbackInheritUniqueItem;
|
||||
|
||||
@@ -96,7 +97,7 @@ class che_모반시도 extends Command\GeneralCommand{
|
||||
$lordLogger->pushGeneralHistoryLog("<D><b>{$generalName}</b></>의 모반으로 인해 <D><b>{$nationName}</b></>의 군주자리를 박탈당함");
|
||||
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$general->checkStatChange();
|
||||
tryRollbackInheritUniqueItem($general);
|
||||
$general->applyDB($db);
|
||||
|
||||
@@ -13,6 +13,8 @@ use \sammo\{
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
use function sammo\DeleteConflict;
|
||||
use function sammo\refreshNationStaticInfo;
|
||||
use function sammo\tryRollbackInheritUniqueItem;
|
||||
@@ -121,7 +123,7 @@ class che_방랑 extends Command\GeneralCommand{
|
||||
], 'me=%i OR you=%i', $nationID, $nationID);
|
||||
|
||||
refreshNationStaticInfo();
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
tryRollbackInheritUniqueItem($general);
|
||||
$general->applyDB($db);
|
||||
|
||||
@@ -19,6 +19,7 @@ use function\sammo\tryUniqueItemLottery;
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
use function sammo\tryRollbackInheritUniqueItem;
|
||||
|
||||
@@ -135,7 +136,7 @@ class che_선양 extends Command\GeneralCommand
|
||||
$logger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>의 군주자리를 <Y>{$destGeneralName}</>에게 선양");
|
||||
$destLogger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>의 군주자리를 물려 받음");
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryRollbackInheritUniqueItem($general);
|
||||
|
||||
@@ -17,7 +17,7 @@ use function \sammo\pickGeneralFromPool;
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
class che_인재탐색 extends Command\GeneralCommand
|
||||
{
|
||||
@@ -210,7 +210,7 @@ class che_인재탐색 extends Command\GeneralCommand
|
||||
$exp = 200;
|
||||
$ded = 300;
|
||||
|
||||
$general->increaseInheritancePoint('active_action', Util::valueFit(sqrt(1 / $foundProp), 1));
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, Util::valueFit(sqrt(1 / $foundProp), 1));
|
||||
$general->increaseVarWithLimit('gold', -$reqGold, 0);
|
||||
$general->increaseVarWithLimit('rice', -$reqRice, 0);
|
||||
$general->addExperience($exp);
|
||||
|
||||
@@ -23,8 +23,7 @@ use function \sammo\getNationStaticInfo;
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
|
||||
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
class che_임관 extends Command\GeneralCommand
|
||||
{
|
||||
@@ -183,7 +182,7 @@ class che_임관 extends Command\GeneralCommand
|
||||
$general->setAuxVar('joinedNations', $joinedNations);
|
||||
}
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$general->addExperience($exp);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
|
||||
@@ -21,6 +21,7 @@ use function \sammo\getNationStaticInfo;
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
class che_장수대상임관 extends Command\GeneralCommand{
|
||||
static protected $actionName = '장수를 따라 임관';
|
||||
@@ -175,7 +176,7 @@ class che_장수대상임관 extends Command\GeneralCommand{
|
||||
$general->setAuxVar('joinedNations', $joinedNations);
|
||||
}
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$general->addExperience($exp);
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
|
||||
@@ -20,8 +20,7 @@ use function sammo\tryRollbackInheritUniqueItem;
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
|
||||
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
class che_첩보 extends Command\GeneralCommand
|
||||
{
|
||||
@@ -211,7 +210,7 @@ class che_첩보 extends Command\GeneralCommand
|
||||
$ded = Util::randRangeInt(1, 70);
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
$general->increaseInheritancePoint('active_action', 0.5);//NOTE: 첩보만 예외!
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 0.5);//NOTE: 첩보만 예외!
|
||||
$general->increaseVarWithLimit('gold', -$reqGold, 0);
|
||||
$general->increaseVarWithLimit('rice', -$reqRice, 0);
|
||||
$general->addExperience($exp);
|
||||
|
||||
@@ -19,6 +19,7 @@ use function \sammo\processWar;
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
class che_출병 extends Command\GeneralCommand
|
||||
{
|
||||
@@ -226,7 +227,7 @@ class che_출병 extends Command\GeneralCommand
|
||||
$general->addDex($general->getCrewTypeObj(), $general->getVar('crew') / 100);
|
||||
if($general->getVar('crew') > 500 && $general->getVar('train') * $general->getVar('atmos') > 70 * 70){
|
||||
//500명 이상, 모훈출, 모사출
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
}
|
||||
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
|
||||
@@ -13,6 +13,7 @@ use \sammo\{
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
use function sammo\tryRollbackInheritUniqueItem;
|
||||
|
||||
@@ -113,7 +114,7 @@ class che_하야 extends Command\GeneralCommand{
|
||||
}
|
||||
$general->setVar('troop', 0);
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
|
||||
@@ -17,6 +17,7 @@ use \sammo\{
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use sammo\Event\Action;
|
||||
|
||||
class che_감축 extends Command\NationCommand{
|
||||
@@ -199,7 +200,7 @@ class che_감축 extends Command\NationCommand{
|
||||
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>{$josaUl} <M>감축</>하였습니다.");
|
||||
$logger->pushGlobalHistoryLog("<M><b>【감축】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>{$josaUl} <M>감축</>하였습니다.");
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
|
||||
$general->applyDB($db);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ use function \sammo\newColor;
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use sammo\Event\Action;
|
||||
|
||||
class che_국기변경 extends Command\NationCommand
|
||||
@@ -146,7 +147,7 @@ class che_국기변경 extends Command\NationCommand
|
||||
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <span style='color:{$color};'><b>국기</b></span>를 변경하였습니다");
|
||||
$logger->pushGlobalHistoryLog("<S><b>【국기변경】</b></><D><b>{$nationName}</b></>{$josaYiNation} <span style='color:{$color};'><b>국기</b></span>를 변경하였습니다.");
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
|
||||
$general->applyDB($db);
|
||||
return true;
|
||||
|
||||
@@ -19,6 +19,7 @@ use \sammo\CityConst;
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use sammo\Event\Action;
|
||||
|
||||
class che_국호변경 extends Command\NationCommand
|
||||
@@ -152,7 +153,7 @@ class che_국호변경 extends Command\NationCommand
|
||||
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} 국호를 <D><b>{$newNationName}</b></>{$josaRo} 변경합니다.");
|
||||
$logger->pushGlobalHistoryLog("<S><b>【국호변경】</b></><D><b>{$nationName}</b></>{$josaYiNation} 국호를 <D><b>{$newNationName}</b></>{$josaRo} 변경합니다.");
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
|
||||
$general->applyDB($db);
|
||||
return true;
|
||||
|
||||
@@ -16,6 +16,7 @@ use \sammo\{
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use sammo\Event\Action;
|
||||
|
||||
class che_증축 extends Command\NationCommand{
|
||||
@@ -162,7 +163,7 @@ class che_증축 extends Command\NationCommand{
|
||||
|
||||
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
|
||||
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
|
||||
$josaUl = JosaUtil::pick($destCityName, '을');
|
||||
$josaYi = JosaUtil::pick($generalName, '이');
|
||||
|
||||
@@ -17,6 +17,7 @@ use \sammo\Message;
|
||||
use \sammo\CityConst;
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use sammo\Event\Action;
|
||||
|
||||
class che_천도 extends Command\NationCommand
|
||||
@@ -219,7 +220,7 @@ class che_천도 extends Command\NationCommand
|
||||
], 'nation=%i', $nationID);
|
||||
\sammo\refreshNationStaticInfo();
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>{$josaRo} 천도했습니다. <1>$date</>");
|
||||
$logger->pushGeneralHistoryLog("<G><b>{$destCityName}</b></>{$josaRo} <M>천도</>명령");
|
||||
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>{$josaRo} <M>천도</> 명령");
|
||||
|
||||
@@ -17,6 +17,7 @@ use \sammo\{
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use sammo\Event\Action;
|
||||
|
||||
class che_초토화 extends Command\NationCommand{
|
||||
@@ -184,7 +185,7 @@ class che_초토화 extends Command\NationCommand{
|
||||
\sammo\refreshNationStaticInfo();
|
||||
\sammo\SetNationFront($nationID);
|
||||
|
||||
$general->increaseInheritancePoint('active_action', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
|
||||
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>{$josaUl} 초토화했습니다. <1>$date</>");
|
||||
$logger->pushGeneralHistoryLog("<G><b>{$destCityName}</b></>{$josaUl} <M>초토화</> 명령");
|
||||
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>{$josaUl} <M>초토화</> 명령");
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
namespace sammo;
|
||||
|
||||
trait DefaultAction{
|
||||
|
||||
public function getName():string{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace sammo;
|
||||
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
class DummyGeneral extends General{
|
||||
public function __construct(bool $initLogger=true){
|
||||
$raw = [
|
||||
@@ -46,19 +49,15 @@ class DummyGeneral extends General{
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function getInheritancePoint(string $key, &$aux = null, bool $forceCalc = false){
|
||||
public function getInheritancePoint(InheritanceKey $key, &$aux = null, bool $forceCalc = false): int|float{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function setInheritancePoint(string $key, $value, $aux = null){
|
||||
public function setInheritancePoint(InheritanceKey $key, $value, $aux = null){
|
||||
return;
|
||||
}
|
||||
|
||||
public function increaseInheritancePoint(string $key, $value, $aux = null){
|
||||
return;
|
||||
}
|
||||
|
||||
public function mergeTotalInheritancePoint(bool $isEnd=false){
|
||||
public function increaseInheritancePoint(InheritanceKey $key, $value, $aux = null){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Enums;
|
||||
|
||||
// 유산 타입, DB에서 사용하는 키
|
||||
enum InheritanceKey: string
|
||||
{
|
||||
case previous = 'previous';
|
||||
case lived_month = 'lived_month';
|
||||
case max_belong = 'max_belong';
|
||||
case max_domestic_critical = 'max_domestic_critical';
|
||||
case active_action = 'active_action';
|
||||
case snipe_combat = 'snipe_combat';
|
||||
case combat = 'combat';
|
||||
case sabotage = 'sabotage';
|
||||
case unifier = 'unifier';
|
||||
case dex = 'dex';
|
||||
case tournament = 'tournament';
|
||||
case betting = 'betting';
|
||||
}
|
||||
+19
-243
@@ -3,6 +3,8 @@
|
||||
namespace sammo;
|
||||
|
||||
use sammo\Command\GeneralCommand;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use sammo\VO\InheritancePointType;
|
||||
use sammo\WarUnitTrigger as WarUnitTrigger;
|
||||
|
||||
class General implements iAction
|
||||
@@ -53,21 +55,6 @@ class General implements iAction
|
||||
'occupied' => 1,
|
||||
];
|
||||
|
||||
const INHERITANCE_KEY = [
|
||||
'previous' => [true, 1, '기존 포인트'],
|
||||
'lived_month' => [true, 1, '생존'],
|
||||
'max_belong' => [false, 10, '최대 임관년 수'],
|
||||
'max_domestic_critical' => [true, 1, '최대 연속 내정 성공'],
|
||||
'active_action' => [true, 3, '능동 행동 수'],
|
||||
//'snipe_combat' => [true, 10, '병종 상성 우위 횟수'],
|
||||
'combat' => [['rank', 'warnum'], 5, '전투 횟수'],
|
||||
'sabotage' => [['rank', 'firenum'], 20, '계략 성공 횟수'],
|
||||
'unifier' => [true, 1, '천통 기여'],
|
||||
'dex' => [false, 0.001, '숙련도'],
|
||||
'tournament' => [true, 1, '토너먼트'],
|
||||
'betting' => [false, 10, '베팅 당첨'],
|
||||
];
|
||||
|
||||
const TURNTIME_FULL_MS = -1;
|
||||
const TURNTIME_FULL = 0;
|
||||
const TURNTIME_HMS = 1;
|
||||
@@ -650,12 +637,13 @@ class General implements iAction
|
||||
}
|
||||
|
||||
if ($refundPoint > 0) {
|
||||
$this->increaseInheritancePoint('previous', $refundPoint);
|
||||
$this->increaseInheritancePoint(InheritanceKey::previous, $refundPoint);
|
||||
}
|
||||
|
||||
$this->mergeTotalInheritancePoint();
|
||||
applyInheritanceUser($this->getVar('owner'));
|
||||
$this->clearInheritancePoint();
|
||||
$inheritPointManager = InheritancePointManager::getInstance();
|
||||
$inheritPointManager->mergeTotalInheritancePoint($this);
|
||||
$inheritPointManager->applyInheritanceUser($this->getVar('owner'));
|
||||
$inheritPointManager->clearInheritancePoint($this);
|
||||
}
|
||||
|
||||
|
||||
@@ -712,11 +700,13 @@ class General implements iAction
|
||||
|
||||
$generalName = $this->getName();
|
||||
|
||||
$inheritPointManager = InheritancePointManager::getInstance();
|
||||
|
||||
$ownerID = $this->getVar('owner');
|
||||
if ($ownerID) {
|
||||
$this->mergeTotalInheritancePoint();
|
||||
applyInheritanceUser($ownerID, true);
|
||||
$this->clearInheritancePoint();
|
||||
$inheritPointManager->mergeTotalInheritancePoint($this);
|
||||
$inheritPointManager->applyInheritanceUser($ownerID, true);
|
||||
$inheritPointManager->clearInheritancePoint($this);
|
||||
}
|
||||
|
||||
$this->multiplyVarWithLimit('leadership', 0.85, 10);
|
||||
@@ -1332,237 +1322,23 @@ class General implements iAction
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|float
|
||||
*/
|
||||
public function getInheritancePoint(string $key, &$aux = null, bool $forceCalc = false)
|
||||
public function getInheritancePoint(InheritanceKey $key, &$aux = null, bool $forceCalc = false): int|float
|
||||
{
|
||||
$inheritType = static::INHERITANCE_KEY[$key] ?? null;
|
||||
if ($inheritType === null) {
|
||||
throw new \OutOfRangeException("{$key}는 유산 타입이 아님");
|
||||
}
|
||||
|
||||
$ownerID = $this->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($this->getVar('npc') >= 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
[$storeType, $multiplier,] = $inheritType;
|
||||
|
||||
$gameStor = KVStorage::getStorage(DB::db(), 'game_env');
|
||||
if ($storeType === true || ($gameStor->isunited != 0 && !$forceCalc)) {
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
[$value, $aux] = $inheritStor->getValue($key);
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_array($storeType)) {
|
||||
[$storSubType, $storSubKey] = $storeType;
|
||||
if ($storSubType === 'rank') {
|
||||
return $this->getRankVar($storSubKey) * $multiplier;
|
||||
}
|
||||
if ($storSubType === 'raw') {
|
||||
return $this->getVar($storSubKey) * $multiplier;
|
||||
}
|
||||
if ($storSubType === 'aux') {
|
||||
return ($this->getAuxVar($storSubKey) ?? 0) * $multiplier;
|
||||
}
|
||||
throw new \InvalidArgumentException("{$storSubType}은 참조 할 수 없는 유산 세부키임");
|
||||
}
|
||||
|
||||
if ($storeType !== false) {
|
||||
throw new \InvalidArgumentException("{$storeType}은 올바르지 않은 유산 키임");
|
||||
}
|
||||
|
||||
$extractFn = function () {
|
||||
return [0, null];
|
||||
};
|
||||
switch ($key) {
|
||||
case 'dex':
|
||||
$extractFn = function () use ($multiplier) {
|
||||
$dexLimit = Util::array_last(getDexLevelList())[0];
|
||||
$totalDex = 0;
|
||||
foreach (array_keys(GameUnitConst::allType()) as $armType) {
|
||||
$subDex = $this->getVar("dex{$armType}");
|
||||
if($subDex > $dexLimit){
|
||||
$totalDex += ($subDex - $dexLimit) / 3;
|
||||
$subDex = $dexLimit;
|
||||
}
|
||||
$totalDex += $subDex;
|
||||
}
|
||||
return [$totalDex * $multiplier, null];
|
||||
};
|
||||
break;
|
||||
case 'betting':
|
||||
$extractFn = function () use ($multiplier) {
|
||||
$betWin = $this->getRankVar('betwin');
|
||||
$betWinRate = $this->getRankVar('betwingold') / max(1, $this->getRankVar('betgold'));
|
||||
|
||||
return [$betWin * $multiplier * pow($betWinRate, 2), null];
|
||||
};
|
||||
break;
|
||||
case 'max_belong':
|
||||
$extractFn = function () use ($multiplier) {
|
||||
$maxBelong = max($this->getVar('belong'), $this->getAuxVar('max_belong') ?? 0);
|
||||
return [$maxBelong * $multiplier, null];
|
||||
};
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException("{$key}는 유산 추출기를 보유하고 있지 않음");
|
||||
}
|
||||
|
||||
[$value, $aux] = ($extractFn)();
|
||||
return $value;
|
||||
return InheritancePointManager::getInstance()->getInheritancePoint($this, $key, $aux, $forceCalc);
|
||||
}
|
||||
|
||||
public function setInheritancePoint(string $key, $value, $aux = null)
|
||||
public function setInheritancePoint(InheritanceKey $key, $value, $aux = null)
|
||||
{
|
||||
if (!is_int($value) && !is_float($value)) {
|
||||
throw new \InvalidArgumentException("{$value}는 숫자가 아님");
|
||||
}
|
||||
$inheritType = static::INHERITANCE_KEY[$key] ?? null;
|
||||
if ($inheritType === null) {
|
||||
throw new \OutOfRangeException("{$key}는 유산 타입이 아님");
|
||||
}
|
||||
|
||||
[$storeType, $multiplier,] = $inheritType;
|
||||
if ($storeType !== true) {
|
||||
throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님");
|
||||
}
|
||||
if ($multiplier != 1 && $value != 0) {
|
||||
throw new \InvalidArgumentException("{$key}는 1:1 유산 포인트가 아님");
|
||||
}
|
||||
|
||||
$ownerID = $this->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->getVar('npc') >= 2) {
|
||||
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]);
|
||||
return InheritancePointManager::getInstance()->setInheritancePoint($this, $key, $value, $aux);
|
||||
}
|
||||
|
||||
public function increaseInheritancePoint(string $key, $value, $aux = null)
|
||||
public function increaseInheritancePoint(InheritanceKey $key, $value, $aux = null)
|
||||
{
|
||||
if (!is_int($value) && !is_float($value)) {
|
||||
throw new \InvalidArgumentException("{$value}는 숫자가 아님");
|
||||
}
|
||||
|
||||
$inheritType = static::INHERITANCE_KEY[$key] ?? null;
|
||||
if ($inheritType === null) {
|
||||
throw new \OutOfRangeException("{$key}는 유산 타입이 아님");
|
||||
}
|
||||
|
||||
[$storeType, $multiplier,] = $inheritType;
|
||||
if ($storeType !== true) {
|
||||
throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님");
|
||||
}
|
||||
|
||||
$ownerID = $this->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->getVar('npc') >= 2) {
|
||||
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) ?? [0, null];
|
||||
|
||||
if ($oldAux !== $aux) {
|
||||
$oldValue = 0;
|
||||
}
|
||||
|
||||
$newValue = $oldValue + $value * $multiplier;
|
||||
$inheritStor->setValue($key, [$newValue, $aux]);
|
||||
}
|
||||
|
||||
public function clearInheritancePoint(){
|
||||
$ownerID = $this->getVar('owner');
|
||||
if(!$ownerID){
|
||||
return;
|
||||
}
|
||||
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
$allPoints = $inheritStor->getAll();
|
||||
if (!$allPoints || count($allPoints) == 0) {
|
||||
//비었으므로 리셋 안함
|
||||
return;
|
||||
}
|
||||
if (count($allPoints) == 1 && key_exists('previous', $allPoints)) {
|
||||
//이미 리셋되었으므로 리셋 안함
|
||||
return;
|
||||
}
|
||||
|
||||
$previousPointInfo = $allPoints['previous'];
|
||||
$inheritStor->resetValues();
|
||||
$inheritStor->setValue('previous', $previousPointInfo);
|
||||
return InheritancePointManager::getInstance()->increaseInheritancePoint($this, $key, $value, $aux);
|
||||
}
|
||||
|
||||
public function mergeTotalInheritancePoint(bool $isEnd=false)
|
||||
{
|
||||
$ownerID = $this->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->getVar('npc') > 1){
|
||||
return;
|
||||
}
|
||||
|
||||
$gameStor = KVStorage::getStorage(DB::db(), 'game_env');
|
||||
$gameStor->cacheValues(['year', 'startyear', 'month']);
|
||||
|
||||
if ($this->getVar('npc') == 1) {
|
||||
if(!$isEnd){
|
||||
return;
|
||||
}
|
||||
|
||||
$pickYearMonth = $this->getAuxVar('pickYearMonth');
|
||||
if($pickYearMonth === null){
|
||||
return;
|
||||
}
|
||||
[$startYear, $year] = $gameStor->getValuesAsArray(['startyear', 'year']);
|
||||
|
||||
if(($year - $pickYearMonth) * 2 <= ($year - $startYear)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
$inheritStor->cacheAll();
|
||||
foreach (static::INHERITANCE_KEY as $key => [$storType,,]) {
|
||||
$aux = null;
|
||||
$point = $this->getInheritancePoint($key, $aux, true);
|
||||
if ($storType === true) {
|
||||
continue;
|
||||
}
|
||||
$inheritStor->setValue($key, [$point, $aux]);
|
||||
}
|
||||
|
||||
$oldInheritStor = KVStorage::getStorage(DB::db(), "inheritance_result");
|
||||
$serverID = UniqueConst::$serverID;
|
||||
$year = $gameStor->year;
|
||||
$month = $gameStor->month;
|
||||
$oldInheritStor->setValue("{$serverID}_{$ownerID}_{$this->getID()}_{$year}_{$month}", $inheritStor->getAll(true));
|
||||
InheritancePointManager::getInstance()->mergeTotalInheritancePoint($this, $isEnd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
namespace sammo;
|
||||
|
||||
use sammo\VO\InheritancePointType;;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
class InheritancePointManager
|
||||
{
|
||||
/** @var array[string]InheritancePointType */
|
||||
public readonly array $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, '베팅 당첨'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getInstance(): self
|
||||
{
|
||||
if (!self::$instance) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function getInheritancePointType(InheritanceKey $key): InheritancePointType
|
||||
{
|
||||
if (!key_exists($key->value, $this->inheritanceKey)) {
|
||||
throw new \OutOfRangeException("{$key}는 유산 타입이 아님");
|
||||
}
|
||||
return $this->inheritanceKey[$key->value];
|
||||
}
|
||||
|
||||
public function getInheritancePoint(General $general, InheritanceKey $key, &$aux = null, bool $forceCalc = false)
|
||||
{
|
||||
$inheritType = $this->getInheritancePointType($key);
|
||||
|
||||
$ownerID = $general->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($general->getVar('npc') >= 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$storeType = $inheritType->storeType;
|
||||
$multiplier = $inheritType->pointCoeff;
|
||||
|
||||
$gameStor = KVStorage::getStorage(DB::db(), 'game_env');
|
||||
if ($storeType === true || ($gameStor->isunited != 0 && !$forceCalc)) {
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
[$value, $aux] = $inheritStor->getValue($key);
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_array($storeType)) {
|
||||
[$storSubType, $storSubKey] = $storeType;
|
||||
if ($storSubType === 'rank') {
|
||||
return $general->getRankVar($storSubKey) * $multiplier;
|
||||
}
|
||||
if ($storSubType === 'raw') {
|
||||
return $general->getVar($storSubKey) * $multiplier;
|
||||
}
|
||||
if ($storSubType === 'aux') {
|
||||
return ($general->getAuxVar($storSubKey) ?? 0) * $multiplier;
|
||||
}
|
||||
throw new \InvalidArgumentException("{$storSubType}은 참조 할 수 없는 유산 세부키임");
|
||||
}
|
||||
|
||||
if ($storeType !== false) {
|
||||
throw new \InvalidArgumentException("{$storeType}은 올바르지 않은 유산 키임");
|
||||
}
|
||||
|
||||
$extractFn = function () {
|
||||
return [0, null];
|
||||
};
|
||||
switch ($key) {
|
||||
case 'dex':
|
||||
$extractFn = function () use ($general, $multiplier) {
|
||||
$dexLimit = Util::array_last(getDexLevelList())[0];
|
||||
$totalDex = 0;
|
||||
foreach (array_keys(GameUnitConst::allType()) as $armType) {
|
||||
$subDex = $general->getVar("dex{$armType}");
|
||||
if ($subDex > $dexLimit) {
|
||||
$totalDex += ($subDex - $dexLimit) / 3;
|
||||
$subDex = $dexLimit;
|
||||
}
|
||||
$totalDex += $subDex;
|
||||
}
|
||||
return [$totalDex * $multiplier, null];
|
||||
};
|
||||
break;
|
||||
case 'betting':
|
||||
$extractFn = function () use ($general, $multiplier) {
|
||||
$betWin = $general->getRankVar('betwin');
|
||||
$betWinRate = $general->getRankVar('betwingold') / max(1, $general->getRankVar('betgold'));
|
||||
|
||||
return [$betWin * $multiplier * pow($betWinRate, 2), null];
|
||||
};
|
||||
break;
|
||||
case 'max_belong':
|
||||
$extractFn = function () use ($general, $multiplier) {
|
||||
$maxBelong = max($general->getVar('belong'), $general->getAuxVar('max_belong') ?? 0);
|
||||
return [$maxBelong * $multiplier, null];
|
||||
};
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException("{$key}는 유산 추출기를 보유하고 있지 않음");
|
||||
}
|
||||
|
||||
[$value, $aux] = ($extractFn)();
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
if ($general->getVar('npc') >= 2) {
|
||||
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]);
|
||||
}
|
||||
|
||||
public function increaseInheritancePoint(General $general, InheritanceKey $key, $value, $aux = null)
|
||||
{
|
||||
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}는 직접 저장형 유산 포인트가 아님");
|
||||
}
|
||||
|
||||
$ownerID = $general->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($general->getVar('npc') >= 2) {
|
||||
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];
|
||||
|
||||
if ($oldAux !== $aux) {
|
||||
$oldValue = 0;
|
||||
}
|
||||
|
||||
$newValue = $oldValue + $value * $multiplier;
|
||||
$inheritStor->setValue($key->value, [$newValue, $aux]);
|
||||
}
|
||||
|
||||
public function clearInheritancePoint(General $general){
|
||||
$ownerID = $general->getVar('owner');
|
||||
if(!$ownerID){
|
||||
return;
|
||||
}
|
||||
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
$allPoints = $inheritStor->getAll();
|
||||
if (!$allPoints || count($allPoints) == 0) {
|
||||
//비었으므로 리셋 안함
|
||||
return;
|
||||
}
|
||||
if (count($allPoints) == 1 && key_exists(InheritanceKey::previous->value, $allPoints)) {
|
||||
//이미 리셋되었으므로 리셋 안함
|
||||
return;
|
||||
}
|
||||
|
||||
$previousPointInfo = $allPoints[InheritanceKey::previous->value];
|
||||
$inheritStor->resetValues();
|
||||
$inheritStor->setValue(InheritanceKey::previous->value, $previousPointInfo);
|
||||
}
|
||||
|
||||
public function mergeTotalInheritancePoint(General $general, bool $isEnd = false)
|
||||
{
|
||||
$ownerID = $general->getVar('owner');
|
||||
if (!$ownerID) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($general->getVar('npc') > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gameStor = KVStorage::getStorage(DB::db(), 'game_env');
|
||||
$gameStor->cacheValues(['year', 'startyear', 'month']);
|
||||
|
||||
if ($general->getVar('npc') == 1) {
|
||||
if (!$isEnd) {
|
||||
return;
|
||||
}
|
||||
|
||||
$pickYearMonth = $general->getAuxVar('pickYearMonth');
|
||||
if ($pickYearMonth === null) {
|
||||
return;
|
||||
}
|
||||
[$startYear, $year] = $gameStor->getValuesAsArray(['startyear', 'year']);
|
||||
|
||||
if (($year - $pickYearMonth) * 2 <= ($year - $startYear)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}");
|
||||
$inheritStor->cacheAll();
|
||||
foreach ($this->inheritanceKey as $rKey => $keyObj) {
|
||||
$key = InheritanceKey::from($rKey);
|
||||
$storeType = $keyObj->storeType;
|
||||
$aux = null;
|
||||
$point = $general->getInheritancePoint($key, $aux, true);
|
||||
if ($storeType === true) {
|
||||
continue;
|
||||
}
|
||||
$inheritStor->setValue($key, [$point, $aux]);
|
||||
}
|
||||
|
||||
$oldInheritStor = KVStorage::getStorage(DB::db(), "inheritance_result");
|
||||
$serverID = UniqueConst::$serverID;
|
||||
$year = $gameStor->year;
|
||||
$month = $gameStor->month;
|
||||
$oldInheritStor->setValue("{$serverID}_{$ownerID}_{$general->getID()}_{$year}_{$month}", $inheritStor->getAll(true));
|
||||
}
|
||||
|
||||
|
||||
function applyInheritanceUser(int $userID, bool $isRebirth = false): float
|
||||
{
|
||||
if ($userID === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//FIXME: 굳이 merge, apply, clean 3단계를 거쳐야 할 이유가 없음
|
||||
/** @var array[InheritanceKey]float */
|
||||
$rebirthDegraded = [
|
||||
InheritanceKey::dex => 0.5,
|
||||
];
|
||||
|
||||
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}");
|
||||
$totalPoint = 0;
|
||||
/** @var array[InheritanceKey][float, string|float] */
|
||||
$allPoints = $inheritStor->getAll();
|
||||
if (!$allPoints || count($allPoints) == 0) {
|
||||
//비었으므로 리셋 안함
|
||||
return 0;
|
||||
}
|
||||
if (count($allPoints) == 1 && key_exists(InheritanceKey::previous->value, $allPoints)) {
|
||||
//이미 리셋되었으므로 리셋 안함
|
||||
return $allPoints[InheritanceKey::previous->value][0];
|
||||
}
|
||||
|
||||
$userLogger = new UserLogger($userID);
|
||||
|
||||
$previousPoint = ($allPoints[InheritanceKey::previous->value] ?? [0, 0])[0];
|
||||
|
||||
foreach ($allPoints as $rKey => [$value,]) {
|
||||
$key = InheritanceKey::from($rKey);
|
||||
if ($isRebirth && key_exists($key, $rebirthDegraded)) {
|
||||
$value *= $rebirthDegraded[$key];
|
||||
}
|
||||
$keyText = $this->getInheritancePointType($key)->info;
|
||||
$userLogger->push("{$keyText} 포인트 {$value} 증가", "inheritPoint");
|
||||
$totalPoint += $value;
|
||||
}
|
||||
$totalPoint = Util::toInt($totalPoint);
|
||||
$userLogger->push("포인트 {$previousPoint} => {$totalPoint}", "inheritPoint");
|
||||
$userLogger->flush();
|
||||
|
||||
$inheritStor->resetValues();
|
||||
$inheritStor->setValue(InheritanceKey::previous->value, [$totalPoint, null]);
|
||||
return $totalPoint;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace sammo;
|
||||
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use \Symfony\Component\Lock;
|
||||
|
||||
class TurnExecutionHelper
|
||||
@@ -260,7 +261,7 @@ class TurnExecutionHelper
|
||||
$autorunMode = false;
|
||||
$ai = null;
|
||||
|
||||
$general->increaseInheritancePoint('lived_month', 1);
|
||||
$general->increaseInheritancePoint(InheritanceKey::lived_month, 1);
|
||||
|
||||
$turnObj->preprocessCommand($env);
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace sammo\VO;
|
||||
class InheritancePointType{
|
||||
public function __construct(
|
||||
public bool|array $storeType,
|
||||
public int|float $pointCoeff,
|
||||
public string $info,
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace sammo;
|
||||
|
||||
use sammo\Enums\InheritanceKey;
|
||||
|
||||
include "lib.php";
|
||||
include "func.php";
|
||||
//로그인 검사
|
||||
@@ -58,7 +60,7 @@ foreach (GameConst::$allItems as $subItems) {
|
||||
|
||||
|
||||
$items = [];
|
||||
foreach (array_keys(General::INHERITANCE_KEY) as $key) {
|
||||
foreach (InheritanceKey::cases() as $key) {
|
||||
$items[$key] = $me->getInheritancePoint($key) ?? 0;
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -38,7 +38,8 @@ if ($gencount >= $admin['maxgeneral']) {
|
||||
die(WebUtil::errorBackMsg("더 이상 등록할 수 없습니다."));
|
||||
}
|
||||
|
||||
$inheritTotalPoint = applyInheritanceUser($userID);
|
||||
$inheritPointManager = InheritancePointManager::getInstance();
|
||||
$inheritTotalPoint = $inheritPointManager->applyInheritanceUser($userID);
|
||||
|
||||
$nationList = $db->query('SELECT nation,`name`,color,scout FROM nation');
|
||||
$nationList = Util::convertArrayToDict($nationList, 'nation');
|
||||
@@ -60,7 +61,7 @@ foreach ($scoutMsgs as $destNationID => $scoutMsg) {
|
||||
<?= WebUtil::printDist('vue', 'v_join', true) ?>
|
||||
|
||||
<?= WebUtil::printStaticValues([
|
||||
'staticValues'=>[
|
||||
'staticValues' => [
|
||||
'serverID' => UniqueConst::$serverID,
|
||||
'nationList' => array_values($nationList),
|
||||
'config' => [
|
||||
@@ -72,8 +73,8 @@ foreach ($scoutMsgs as $destNationID => $scoutMsg) {
|
||||
'picture' => $member['picture'],
|
||||
'imgsvr' => $member['imgsvr'],
|
||||
],
|
||||
'inheritTotalPoint'=>$inheritTotalPoint,
|
||||
'turnterm'=>$gameStor->turnterm,
|
||||
'inheritTotalPoint' => $inheritTotalPoint,
|
||||
'turnterm' => $gameStor->turnterm,
|
||||
]
|
||||
]) ?>
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user