diff --git a/hwe/_admin_force_rehall.php b/hwe/_admin_force_rehall.php index 9b7971f9..26a118ef 100644 --- a/hwe/_admin_force_rehall.php +++ b/hwe/_admin_force_rehall.php @@ -26,5 +26,7 @@ foreach ($db->queryFirstColumn( } foreach(General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc = 0')) as $genObj){ - $genObj->mergeTotalInheritancePoint(); + $genObj->mergeTotalInheritancePoint(true); + applyInheritanceUser($genObj->getID()); + $genObj->clearInheritancePoint(); } \ No newline at end of file diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 52417964..67d7cd58 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -1028,7 +1028,9 @@ function checkEmperior() $genObj->increaseInheritancePoint('unifier', 2000); }; } - $genObj->mergeTotalInheritancePoint(); + $genObj->mergeTotalInheritancePoint(true); + applyInheritanceUser($genObj->getID()); + $genObj->clearInheritancePoint(); } $gameStor->isunited = 2; @@ -1182,8 +1184,10 @@ function checkEmperior() LogHistory(); } -function resetInheritanceUser(int $userID, bool $isRebirth = false): float +function applyInheritanceUser(int $userID, bool $isRebirth = false): float { + //FIXME: 은퇴, 사망, 천통 시점에 바로 반영한다면 여기가 아니라 general class로 이동하는 것이 옳음 + //또한 굳이 merge, apply, clean 3단계를 거쳐야 할 이유도 없음 $rebirthDegraded = [ 'dex' => 0.5, ]; diff --git a/hwe/j_select_npc.php b/hwe/j_select_npc.php index d8a2f176..e810f1dc 100644 --- a/hwe/j_select_npc.php +++ b/hwe/j_select_npc.php @@ -73,6 +73,8 @@ if ($gencount >= $maxgeneral) { ]); } +$genAux = Json::decode($db->queryFirstField('SELECT aux FROM general WHERE no = %i', $pick)??'{}'); +$genAux['pickYearMonth'] = Util::joinYearMonth($year, $month); //등록 시작 $db->update('general', [ 'owner_name'=>$userNick, @@ -81,6 +83,7 @@ $db->update('general', [ 'defence_train'=>80, 'permission'=>'normal', 'owner'=>$userID, + 'aux'=>Json::encode($genAux) ], 'owner <= 0 AND npc = 2 AND no = %i', $pick); if(!$db->affectedRows()){ diff --git a/hwe/sammo/API/General/Join.php b/hwe/sammo/API/General/Join.php index f4243490..d2d804e4 100644 --- a/hwe/sammo/API/General/Join.php +++ b/hwe/sammo/API/General/Join.php @@ -26,7 +26,7 @@ use function sammo\cutTurn; use function sammo\getGeneralSpecialWarName; use function sammo\getRandTurn; use function sammo\pushAdminLog; -use function sammo\resetInheritanceUser; +use function sammo\applyInheritanceUser; class Join extends \sammo\BaseAPI { @@ -155,7 +155,7 @@ class Join extends \sammo\BaseAPI $admin = $gameStor->getValues(['scenario', 'turnterm', 'turntime', 'show_img_level', 'startyear', 'year', 'month']); - $inheritTotalPoint = resetInheritanceUser($userID); + $inheritTotalPoint = applyInheritanceUser($userID); $inheritRequiredPoint = 0; $userLogger = new UserLogger($userID, $admin['year'], $admin['month'], false); diff --git a/hwe/sammo/DummyGeneral.php b/hwe/sammo/DummyGeneral.php index ba004103..612a56ef 100644 --- a/hwe/sammo/DummyGeneral.php +++ b/hwe/sammo/DummyGeneral.php @@ -54,7 +54,7 @@ class DummyGeneral extends General{ return; } - public function mergeTotalInheritancePoint(){ + public function mergeTotalInheritancePoint(bool $isEnd=false){ return; } diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 17d87c1c..bd4d2c28 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -652,6 +652,8 @@ class General implements iAction } $this->mergeTotalInheritancePoint(); + applyInheritanceUser($this->getID()); + $this->clearInheritancePoint(); } @@ -711,7 +713,8 @@ class General implements iAction $ownerID = $this->getVar('owner'); if ($ownerID) { $this->mergeTotalInheritancePoint(); - resetInheritanceUser($ownerID, true); + applyInheritanceUser($ownerID, true); + $this->clearInheritancePoint(); } $this->multiplyVarWithLimit('leadership', 0.85, 10); @@ -1320,7 +1323,7 @@ class General implements iAction return 0; } - if ($this->getVar('npc') != 0) { + if ($this->getVar('npc') >= 2) { return 0; } @@ -1443,7 +1446,7 @@ class General implements iAction return; } - if ($this->getVar('npc') != 0) { + if ($this->getVar('npc') >= 2) { return; } @@ -1463,17 +1466,58 @@ class General implements iAction $inheritStor->setValue($key, [$newValue, $aux]); } - public function mergeTotalInheritancePoint() + 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); + } + + public function mergeTotalInheritancePoint(bool $isEnd=false) { $ownerID = $this->getVar('owner'); if (!$ownerID) { return; } - if ($this->getVar('npc') != 0) { + 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,,]) { @@ -1486,7 +1530,6 @@ class General implements iAction } $oldInheritStor = KVStorage::getStorage(DB::db(), "inheritance_result"); - $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); $serverID = UniqueConst::$serverID; $year = $gameStor->year; $month = $gameStor->month; diff --git a/hwe/v_join.php b/hwe/v_join.php index c6db78da..75233fe4 100644 --- a/hwe/v_join.php +++ b/hwe/v_join.php @@ -38,7 +38,7 @@ if ($gencount >= $admin['maxgeneral']) { die(WebUtil::errorBackMsg("더 이상 등록할 수 없습니다.")); } -$inheritTotalPoint = resetInheritanceUser($userID); +$inheritTotalPoint = applyInheritanceUser($userID); $nationList = $db->query('SELECT nation,`name`,color,scout FROM nation'); $nationList = Util::convertArrayToDict($nationList, 'nation');