feat,refac: 게임 로직 내 '랜덤'을 RandUtil을 활용하여 재설정

- 기존의 랜덤 코드는 deprecated 처리
- 서버 시작 시 랜덤하게 정해진 hiddenSeed를 활용
- 랜덤 생성 단위
  - 월 실행
  - 사령턴 실행 결과
  - 커맨드 실행 결과
  - 작위 보상
  - 부대장 생성
  - 유니크 획득 시도
  - 설문 조사
  - 장수 생성
  - NPC국 생성, NPC 생성, NPC의 토너먼트 베팅
  - 전투
  - 도시 점령
  - 자율 행동 선택
  - 랜덤 턴 변경
- 거래장, 토너먼트 등 구 랜덤 코드를 이용하는 잔여 코드 있음
This commit is contained in:
2022-05-17 03:46:59 +09:00
parent 2cb697f3dc
commit c5ceff6fb5
136 changed files with 1000 additions and 784 deletions
+22 -20
View File
@@ -8,6 +8,7 @@ use \sammo\GameUnitConst;
use \sammo\CityConst;
use sammo\Enums\RankColumn;
use \sammo\GameConst;
use sammo\RandUtil;
use \sammo\SpecialityHelper;
use sammo\TimeUtil;
class GeneralBuilder{
@@ -67,6 +68,7 @@ class GeneralBuilder{
protected $aux = [];
public function __construct(
public readonly RandUtil $rng,
string $name,
bool $isDynamicImageSvr,
$picturePath,
@@ -109,17 +111,17 @@ class GeneralBuilder{
'intel'=>$this->intel
];
if($option === '랜덤전특'){
$this->specialWar = SpecialityHelper::pickSpecialWar($general);
$this->specialWar = SpecialityHelper::pickSpecialWar($this->rng, $general);
}
else if($option === '랜덤내특'){
$this->specialDomestic = SpecialityHelper::pickSpecialDomestic($general);
$this->specialDomestic = SpecialityHelper::pickSpecialDomestic($this->rng, $general);
}
else if($option === '랜덤'){
if(Util::randBool(2/3)){
$this->specialWar = SpecialityHelper::pickSpecialWar($general);
if($this->rng->nextBool(2/3)){
$this->specialWar = SpecialityHelper::pickSpecialWar($this->rng, $general);
}
else{
$this->specialDomestic = SpecialityHelper::pickSpecialDomestic($general);
$this->specialDomestic = SpecialityHelper::pickSpecialDomestic($this->rng, $general);
}
}
return $this;
@@ -165,7 +167,7 @@ class GeneralBuilder{
public function setAffinity(int $affinity):self{
if($affinity < 1){
$this->affinity = Util::randRangeInt(1, 150);
$this->affinity = $this->rng->nextRangeInt(1, 150);
}
else if($affinity >= 900){
$this->affinity = 999;
@@ -302,11 +304,11 @@ class GeneralBuilder{
}
public function fillRandomStat(array $pickTypeList, &$pickedType=null):self{
$pickType = Util::choiceRandomUsingWeight($pickTypeList);
$pickType = $this->rng->choiceUsingWeight($pickTypeList);
$totalStat = GameConst::$defaultStatNPCTotal;
$minStat = GameConst::$defaultStatNPCMin;
$mainStat = GameConst::$defaultStatNPCMax - Util::randRangeInt(0, GameConst::$defaultStatNPCMin);
$otherStat = $minStat + Util::randRangeInt(0, Util::toInt(GameConst::$defaultStatNPCMin/2));
$mainStat = GameConst::$defaultStatNPCMax - $this->rng->nextRangeInt(0, GameConst::$defaultStatNPCMin);
$otherStat = $minStat + $this->rng->nextRangeInt(0, Util::toInt(GameConst::$defaultStatNPCMin/2));
$subStat = $totalStat - $mainStat - $otherStat;
if ($subStat < $minStat) {
$subStat = $otherStat;
@@ -341,7 +343,7 @@ class GeneralBuilder{
}
if($this->affinity === null || $this->affinity === 0){
$this->affinity = Util::randRangeInt(1, 150);
$this->affinity = $this->rng->nextRangeInt(1, 150);
}
if($this->birth === null){
@@ -371,7 +373,7 @@ class GeneralBuilder{
}
if($this->ego === null){
$this->ego = Util::choiceRandom(GameConst::$availablePersonality);
$this->ego = $this->rng->choice(GameConst::$availablePersonality);
}
if($this->specialDomestic === null){
@@ -401,12 +403,12 @@ class GeneralBuilder{
}
if($this->affinity === null || $this->affinity === 0 || $isFictionMode){
$this->affinity = Util::randRangeInt(1, 150);
$this->affinity = $this->rng->nextRangeInt(1, 150);
}
if($this->birth === null){
$this->birth = $env['year']+Util::randRange(-5, 5);
$this->death = $this->birth+Util::randRangeInt(60, 80);
$this->birth = $env['year']+$this->rng->nextRange(-5, 5);
$this->death = $this->birth+$this->rng->nextRangeInt(60, 80);
}
@@ -443,7 +445,7 @@ class GeneralBuilder{
$pickType = '무';
break;
}
$pickType = Util::choiceRandomUsingWeight([
$pickType = $this->rng->choiceUsingWeight([
'무'=>$strength,
'지'=>$intel
]);
@@ -463,7 +465,7 @@ class GeneralBuilder{
if(!$this->dex1 && key_exists('dex_t', $avgGen)){
$dexTotal = $avgGen['dex_t'];
if ($pickType == '무') {
$dexVal = Util::choiceRandom([
$dexVal = $this->rng->choice([
[$dexTotal * 5 / 8, $dexTotal / 8, $dexTotal / 8, $dexTotal / 8],
[$dexTotal / 8, $dexTotal * 5 / 8, $dexTotal / 8, $dexTotal / 8],
[$dexTotal / 8, $dexTotal / 8, $dexTotal * 5 / 8, $dexTotal / 8],
@@ -477,7 +479,7 @@ class GeneralBuilder{
}
if($this->ego === null || $isFictionMode){
$this->ego = Util::choiceRandom(GameConst::$availablePersonality);
$this->ego = $this->rng->choice(GameConst::$availablePersonality);
}
if($this->experience === null){
@@ -628,10 +630,10 @@ class GeneralBuilder{
if($this->cityID === null){
if($nationID == 0 || !CityHelper::getAllNationCities($nationID)){
$cityObj = Util::choiceRandom(CityHelper::getAllCities());
$cityObj = $this->rng->choice(CityHelper::getAllCities());
}
else{
$cityObj = Util::choiceRandom(CityHelper::getAllNationCities($nationID));
$cityObj = $this->rng->choice(CityHelper::getAllNationCities($nationID));
}
'@phan-var array<string,string|int> $cityObj';
$this->cityID = $cityObj['id'];
@@ -644,7 +646,7 @@ class GeneralBuilder{
$officerLevel = $nationID?1:0;
}
$turntime = \sammo\getRandTurn($env['turnterm'], new \DateTimeImmutable($env['turntime']));
$turntime = \sammo\getRandTurn($this->rng, $env['turnterm'], new \DateTimeImmutable($env['turntime']));
if($this->killturn){
$killturn = $this->killturn;