diff --git a/hwe/func.php b/hwe/func.php index 8680cf94..b697723e 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -2085,13 +2085,31 @@ function nextRuler(General $general) //npc or npc유저인 경우 후계 찾기 if (!$fiction && $general->getNPCType() > 0) { - $candidate = $db->queryFirstRow( - 'SELECT no,name,officer_level,IF(ABS(affinity-%i)>75,150-ABS(affinity-%i),ABS(affinity-%i)) as npcmatch2 from general where nation=%i and officer_level!=12 and 1 <= npc and npc<=3 order by npcmatch2,rand() LIMIT 1', + $rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( + UniqueConst::$hiddenSeed, + 'NextNPCRuler', + $year, + $month, + $general->getID(), + ))); + $rawCandidates = $db->query( + 'SELECT no,name,officer_level,IF(ABS(affinity-%i)>75,150-ABS(affinity-%i),ABS(affinity-%i)) as npcmatch2 from general where nation=%i and officer_level!=12 and 1 <= npc and npc<=3 order by npcmatch2 asc', $general->getVar('affinity'), $general->getVar('affinity'), $general->getVar('affinity'), $nationID ); + if ($rawCandidates) { + $candidates = []; + $minNPCMatch = $rawCandidates[0]['npcmatch2']; + foreach ($rawCandidates as $candidate) { + if (!$candidate['npcmatch2'] == $minNPCMatch) { + break; + } + $candidates[] = $candidate; + } + $candidate = $rng->choice($candidates); + } } if (!$candidate) { $candidate = $db->queryFirstRow( diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index da488e7c..0c7cc630 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -396,7 +396,7 @@ function postUpdateMonthly(RandUtil $rng) //약간의 랜덤치 부여 (95% ~ 105%) - $nation['power'] = Util::round($nation['power'] * (rand() % 101 + 950) / 1000); + $nation['power'] = Util::round($nation['power'] * $rng->nextRange(0.95, 1.05)); $powerValues['maxPower'] = max($powerValues['maxPower'] ?? 0, $nation['power']); $powerValues['maxCrew'] = max($powerValues['maxCrew'] ?? 0, Util::toInt($nation['totalCrew'])); diff --git a/hwe/j_get_select_npc_token.php b/hwe/j_get_select_npc_token.php index ec6d0344..0227114d 100644 --- a/hwe/j_get_select_npc_token.php +++ b/hwe/j_get_select_npc_token.php @@ -126,7 +126,7 @@ while(count($pickResult) < $pickLimit){ } } -$newNonce = mt_rand(0, 0xfffffff); +$newNonce = random_int(0, 0xfffffff); $validSecond = max(VALID_SECOND, $turnterm*40); $pickMoreSecond = max(PICK_MORE_SECOND, Util::round(pow($turnterm, 0.672)*8)); diff --git a/hwe/j_myBossInfo.php b/hwe/j_myBossInfo.php index 0e74958e..0ee36a0c 100644 --- a/hwe/j_myBossInfo.php +++ b/hwe/j_myBossInfo.php @@ -241,34 +241,43 @@ function do추방(General $general, int $myOfficerLevel):?string{ } $general->setVar('troop', 0); - if($general->getNPCType() >= 2 && Util::randBool(GameConst::$npcBanMessageProb)) { + if($general->getNPCType() >= 2){ + $rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( + UniqueConst::$hiddenSeed, + 'BanNPC', + $env['year'], + $env['month'], + $general->getID(), + ))); + if ($rng->nextBool(GameConst::$npcBanMessageProb)) { - $str = Util::choiceRandom([ - '날 버리다니... 곧 전장에서 복수해주겠다...', - '추방이라... 내가 무얼 잘못했단 말인가...', - '어디 추방해가면서 잘되나 보자... 꼭 복수하겠다...', - '인덕이 제일이거늘... 추방이 웬말인가... 저주한다!', - '날 추방했으니 그 복수로 적국에 정보를 팔아 넘겨야겠군요. 그럼 이만.' - ]); + $str = $rng->choice([ + '날 버리다니... 곧 전장에서 복수해주겠다...', + '추방이라... 내가 무얼 잘못했단 말인가...', + '어디 추방해가면서 잘되나 보자... 꼭 복수하겠다...', + '인덕이 제일이거늘... 추방이 웬말인가... 저주한다!', + '날 추방했으니 그 복수로 적국에 정보를 팔아 넘겨야겠군요. 그럼 이만.' + ]); - $src = new MessageTarget( - $generalID, - $generalName, - $nationID, - $nation['name'], - $nation['color'], - GetImageURL($general->getVar('imgsvr'), $general->getVar('picture')) - ); - $msg = new Message( - Message::MSGTYPE_PUBLIC, - $src, - $src, - $str, - new \DateTime(), - new \DateTime('9999-12-31'), - [] - ); - $msg->send(); + $src = new MessageTarget( + $generalID, + $generalName, + $nationID, + $nation['name'], + $nation['color'], + GetImageURL($general->getVar('imgsvr'), $general->getVar('picture')) + ); + $msg = new Message( + Message::MSGTYPE_PUBLIC, + $src, + $src, + $str, + new \DateTime(), + new \DateTime('9999-12-31'), + [] + ); + $msg->send(); + } } if($env['year'] < $env['startyear']+3) { diff --git a/hwe/process_war.php b/hwe/process_war.php index d910ade6..03058321 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -590,8 +590,8 @@ function ConquerCity(array $admin, General $general, array $city) $loseGeneralGold = 0; $loseGeneralRice = 0; foreach ($oldNationGenerals as $oldGeneral) { - $loseGold = intdiv($oldGeneral->getVar('gold') * (rand() % 30 + 20), 100); - $loseRice = intdiv($oldGeneral->getVar('rice') * (rand() % 30 + 20), 100); + $loseGold = Util::toInt($oldGeneral->getVar('gold') * $rng->nextRange(0.2, 0.5)); + $loseRice = Util::toInt($oldGeneral->getVar('rice') * $rng->nextRange(0.2, 0.5)); $oldGeneral->getLogger()->pushGeneralActionLog( "도주하며 금$loseGold 쌀$loseRice을 분실했습니다.", ActionLogger::PLAIN diff --git a/hwe/sammo/API/General/Join.php b/hwe/sammo/API/General/Join.php index b54cafab..ea57433a 100644 --- a/hwe/sammo/API/General/Join.php +++ b/hwe/sammo/API/General/Join.php @@ -331,7 +331,7 @@ class Join extends \sammo\BaseAPI $character = $rng->choice(GameConst::$availablePersonality); } //상성 랜덤 - $affinity = rand() % 150 + 1; + $affinity = $rng->nextRangeInt(1, 150); ########## 회원정보 테이블에 입력값을 등록한다. ########## $db->insert('general', [ diff --git a/hwe/sammo/Scenario/GeneralBuilder.php b/hwe/sammo/Scenario/GeneralBuilder.php index 190bc666..ea375958 100644 --- a/hwe/sammo/Scenario/GeneralBuilder.php +++ b/hwe/sammo/Scenario/GeneralBuilder.php @@ -652,7 +652,7 @@ class GeneralBuilder{ $killturn = $this->killturn; } else if($this->birth !== null){ - $killturn = ($this->death - $year) * 12 + mt_rand(0, 11) + $month - 1; + $killturn = ($this->death - $year) * 12 + $this->rng->nextRangeInt(0, 11) + $month - 1; } else{ throw new \InvalidArgumentException(); diff --git a/hwe/sammo/WarUnit.php b/hwe/sammo/WarUnit.php index 7ad3c665..785329a0 100644 --- a/hwe/sammo/WarUnit.php +++ b/hwe/sammo/WarUnit.php @@ -286,7 +286,7 @@ class WarUnit //최소 전투력 50 보장 $warPower = max(0, $warPower); $warPower = ($warPower + 100) / 2; - $warPower = rand($warPower, 100); + $warPower = $this->rng->nextRangeInt($warPower, 100); } $warPower *= $this->getComputedAtmos(); diff --git a/i_entrance/j_icon_change.php b/i_entrance/j_icon_change.php index 99371dfc..98cabcd8 100644 --- a/i_entrance/j_icon_change.php +++ b/i_entrance/j_icon_change.php @@ -70,7 +70,7 @@ if(!is_uploaded_file($image['tmp_name'])) { //이미지 저장 while(true){ - $newPicName = dechex(rand(0x000000f,0xfffffff)).$newExt; + $newPicName = bin2hex(random_bytes(4)).$newExt; $dest = AppConf::getUserIconPathFS().'/'.$newPicName; if(file_exists($dest)){ continue;