diff --git a/hwe/sammo/Event/Action/RaiseInvader.php b/hwe/sammo/Event/Action/RaiseInvader.php index c58c069b..b1772f36 100644 --- a/hwe/sammo/Event/Action/RaiseInvader.php +++ b/hwe/sammo/Event/Action/RaiseInvader.php @@ -12,6 +12,8 @@ use sammo\LiteHashDRBG; use sammo\RandUtil; use sammo\Scenario\GeneralBuilder; use sammo\Scenario\Nation; +use sammo\ServerEnv; +use sammo\ServerTool; use sammo\UniqueConst; use sammo\Util; @@ -112,6 +114,9 @@ class RaiseInvader extends \sammo\Event\Action $gameStor = KVStorage::getStorage($db, 'game_env'); $gameStor->setValue('isunited', 1); + $turnterm = $gameStor->turnterm; + $generalCnt = $db->queryFirstField('SELECT count(*) FROM general'); + if ($npcEachCount < 0) { $npcEachCount = $db->queryFirstField('SELECT count(no) from general where npc < 4') / count($cities); @@ -119,6 +124,19 @@ class RaiseInvader extends \sammo\Event\Action } $npcEachCount = max(10, Util::toInt($npcEachCount)); + + $totalGenerals = $npcEachCount * count($cities) + $generalCnt; + if ($totalGenerals > ServerEnv::$maxGeneralsPerMinute * $turnterm) { + foreach ([1, 2, 5, 10, 20, 30, 60, 120] as $nextTurnterm) { + if ($totalGenerals > ServerEnv::$maxGeneralsPerMinute * $nextTurnterm) { + continue; + } + + ServerTool::changeServerTerm($nextTurnterm); + break; + } + } + $specAvg = $this->specAvg; if ($specAvg < 0) { $specAvg = $db->queryFirstField('SELECT avg((`leadership` + `strength` + `intel`)) from general where npc < 4');