diff --git a/hwe/_admin_force_rehall.php b/hwe/_admin_force_rehall.php index 01bb8694..9b7971f9 100644 --- a/hwe/_admin_force_rehall.php +++ b/hwe/_admin_force_rehall.php @@ -24,3 +24,7 @@ foreach ($db->queryFirstColumn( ) as $generalNo) { CheckHall($generalNo); } + +foreach(General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc = 0')) as $genObj){ + $genObj->mergeTotalInheritancePoint(); +} \ No newline at end of file diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 98c802cb..a67f2960 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -988,6 +988,10 @@ function checkEmperior() foreach ($db->queryFirstColumn('SELECT no FROM general WHERE npc<2 AND age>=%i', GameConst::$minPushHallAge) as $hallGeneralNo) { CheckHall($hallGeneralNo); } + + foreach(General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc = 0')) as $genObj){ + $genObj->mergeTotalInheritancePoint(); + } [$totalPop, $totalMaxPop] = $db->queryFirstList('SELECT SUM(pop), SUM(pop_max) FROM city'); $pop = "{$totalPop} / {$totalMaxPop}"; @@ -1132,3 +1136,14 @@ function checkEmperior() //연감 월결산 LogHistory(); } + +function resetInheritanceUser(int $userID){ + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}"); + $totalPoint = 0; + foreach($inheritStor->getAll() as [$value,]){ + $totalPoint += $value; + } + $totalPoint = Util::toInt($totalPoint); + $inheritStor->resetValues(); + $inheritStor->setValue('previous', [$totalPoint, null]); +} \ No newline at end of file diff --git a/hwe/join_post.php b/hwe/join_post.php index 423ecbf6..fbd6b58a 100644 --- a/hwe/join_post.php +++ b/hwe/join_post.php @@ -266,6 +266,8 @@ foreach(Util::range(GameConst::$maxTurn) as $turnIdx){ } $db->insert('general_turn', $turnRows); +resetInheritanceUser($userID); + $rank_data = []; foreach(array_keys(General::RANK_COLUMN) as $rankColumn){ $rank_data[] = [ diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 9c5f1a7b..342af4ce 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -553,6 +553,8 @@ class General implements iAction{ $generalName = $this->getName(); + $this->mergeTotalInheritancePoint(); + // 군주였으면 유지 이음 $officerLevel = $this->getVar('officer_level'); if($officerLevel == 12) { @@ -606,6 +608,12 @@ class General implements iAction{ $generalName = $this->getName(); + $ownerID = $this->getVar('owner'); + if($ownerID){ + $this->mergeTotalInheritancePoint(); + resetInheritanceUser($ownerID); + } + $this->multiplyVarWithLimit('leadership', 0.85, 10); $this->multiplyVarWithLimit('strength', 0.85, 10); $this->multiplyVarWithLimit('intel', 0.85, 10); @@ -1165,10 +1173,19 @@ class General implements iAction{ throw new \OutOfRangeException("{$key}는 유산 타입이 아님"); } + $ownerID = $this->getVar('owner'); + if(!$ownerID){ + return 0; + } + + if($this->getVar('npc') != 0){ + return 0; + } + [$storeType, $multiplier, ] = $inheritType; if($storeType === true){ - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$this->getID()}"); + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); [$value, $aux] = $inheritStor->getValue($key); return $value; } @@ -1235,7 +1252,21 @@ class General implements iAction{ throw new \InvalidArgumentException("{$key}는 1:1 유산 포인트가 아님"); } - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$this->getID()}"); + $ownerID = $this->getVar('owner'); + if(!$ownerID){ + return; + } + + if($this->getVar('npc') != 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]); } @@ -1254,7 +1285,21 @@ class General implements iAction{ throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님"); } - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$this->getID()}"); + $ownerID = $this->getVar('owner'); + if(!$ownerID){ + return; + } + + if($this->getVar('npc') != 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)??[0, null]; if($oldAux !== $aux){ @@ -1265,13 +1310,31 @@ class General implements iAction{ $inheritStor->setValue($key, [$newValue, $aux]); } - public function calcTotalInheritancePoint(): int{ - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$this->getID()}"); - $inheritStor->cacheAll(); - $total = 0; - foreach(array_keys(static::INHERITANCE_KEY) as $key){ - $total += $this->getInheritancePoint($key); + public function mergeTotalInheritancePoint(){ + $ownerID = $this->getVar('owner'); + if(!$ownerID){ + return; } - return Util::toInt($total); + + if($this->getVar('npc') != 0){ + return; + } + + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); + $inheritStor->cacheAll(); + foreach(static::INHERITANCE_KEY as $key=>[$storType, ,]){ + $point = $this->getInheritancePoint($key); + if($storType === true){ + continue; + } + $inheritStor->setValue($key, $point); + } + + $oldInheritStor = KVStorage::getStorage(DB::db(), "inheritance_result"); + $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); + $serverID = UniqueConst::$serverID; + $year = $gameStor->year; + $month = $gameStor->month; + $oldInheritStor->setValue("{$serverID}_{$ownerID}_{$this->getID()}_{$year}_{$month}", $inheritStor->getAll(true)); } } \ No newline at end of file