feat,refac: 게임 로직 내 '랜덤'을 RandUtil을 활용하여 재설정
- 기존의 랜덤 코드는 deprecated 처리 - 서버 시작 시 랜덤하게 정해진 hiddenSeed를 활용 - 랜덤 생성 단위 - 월 실행 - 사령턴 실행 결과 - 커맨드 실행 결과 - 작위 보상 - 부대장 생성 - 유니크 획득 시도 - 설문 조사 - 장수 생성 - NPC국 생성, NPC 생성, NPC의 토너먼트 베팅 - 전투 - 도시 점령 - 자율 행동 선택 - 랜덤 턴 변경 - 거래장, 토너먼트 등 구 랜덤 코드를 이용하는 잔여 코드 있음
This commit is contained in:
@@ -122,7 +122,7 @@ class SpecialityHelper{
|
||||
return $myCond;
|
||||
}
|
||||
|
||||
private static function calcCondDexterity(array $general) : int {
|
||||
private static function calcCondDexterity(RandUtil $rng, array $general) : int {
|
||||
$dex = [
|
||||
static::ARMY_FOOTMAN => $general['dex1']??0,
|
||||
static::ARMY_ARCHER => $general['dex2']??0,
|
||||
@@ -134,19 +134,19 @@ class SpecialityHelper{
|
||||
$dexSum = array_sum($dex);
|
||||
$dexBase = Util::round(sqrt($dexSum) / 4);
|
||||
|
||||
if(Util::randBool(0.8)){
|
||||
if($rng->nextBool(0.8)){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(mt_rand(0, 99) < $dexBase){
|
||||
if($rng->nextRangeInt(0, 99) < $dexBase){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!$dexSum){
|
||||
return array_rand($dex);
|
||||
return $rng->choice($dex);
|
||||
}
|
||||
|
||||
return Util::choiceRandom(array_keys($dex, max($dex)));
|
||||
return $rng->choice(array_keys($dex, max($dex)));
|
||||
}
|
||||
|
||||
/** @return BaseSpecial[] */
|
||||
@@ -195,7 +195,7 @@ class SpecialityHelper{
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function pickSpecialDomestic(array $general, array $prevSpecials=[]) : string{
|
||||
public static function pickSpecialDomestic(RandUtil $rng, array $general, array $prevSpecials=[]) : string{
|
||||
$pAbs = [];
|
||||
$pRel = [];
|
||||
|
||||
@@ -234,31 +234,31 @@ class SpecialityHelper{
|
||||
if($pRel){
|
||||
$pAbs[0] = max(0, 100 - array_sum($pAbs));
|
||||
}
|
||||
$id = Util::choiceRandomUsingWeight($pAbs);
|
||||
$id = $rng->choiceUsingWeight($pAbs);
|
||||
if($id){
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
$id = Util::choiceRandomUsingWeight($pRel);
|
||||
$id = $rng->choiceUsingWeight($pRel);
|
||||
if($id){
|
||||
return $id;
|
||||
}
|
||||
|
||||
if($prevSpecials){
|
||||
return static::pickSpecialDomestic($general, []);
|
||||
return static::pickSpecialDomestic($rng, $general, []);
|
||||
}
|
||||
|
||||
throw new MustNotBeReachedException("{$general['name']}, {$myCond}");
|
||||
}
|
||||
|
||||
public static function pickSpecialWar(array $general, array $prevSpecials=[]) : string{
|
||||
public static function pickSpecialWar(RandUtil $rng, array $general, array $prevSpecials=[]) : string{
|
||||
$reqDex = [];
|
||||
$pAbs = [];
|
||||
$pRel = [];
|
||||
|
||||
$myCond = static::calcCondGeneric($general);
|
||||
$myCond |= static::calcCondDexterity($general);
|
||||
$myCond |= static::calcCondDexterity($rng, $general);
|
||||
$myCond |= static::REQ_DEXTERITY;
|
||||
|
||||
foreach(static::getSpecialWarList() as $specialID=>$specialObj){
|
||||
@@ -294,26 +294,26 @@ class SpecialityHelper{
|
||||
}
|
||||
|
||||
if($reqDex){
|
||||
return Util::choiceRandomUsingWeight($reqDex);
|
||||
return $rng->choiceUsingWeight($reqDex);
|
||||
}
|
||||
|
||||
if($pAbs){
|
||||
if($pRel){
|
||||
$pAbs[0] = max(0, 100 - array_sum($pAbs));
|
||||
}
|
||||
$id = Util::choiceRandomUsingWeight($pAbs);
|
||||
$id = $rng->choiceUsingWeight($pAbs);
|
||||
if($id){
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
$id = Util::choiceRandomUsingWeight($pRel);
|
||||
$id = $rng->choiceUsingWeight($pRel);
|
||||
if($id){
|
||||
return $id;
|
||||
}
|
||||
|
||||
if($prevSpecials){
|
||||
return static::pickSpecialWar($general, []);
|
||||
return static::pickSpecialWar($rng, $general, []);
|
||||
}
|
||||
|
||||
throw new MustNotBeReachedException();
|
||||
|
||||
Reference in New Issue
Block a user