feat,refac: 게임 로직 내 '랜덤'을 RandUtil을 활용하여 재설정
- 기존의 랜덤 코드는 deprecated 처리 - 서버 시작 시 랜덤하게 정해진 hiddenSeed를 활용 - 랜덤 생성 단위 - 월 실행 - 사령턴 실행 결과 - 커맨드 실행 결과 - 작위 보상 - 부대장 생성 - 유니크 획득 시도 - 설문 조사 - 장수 생성 - NPC국 생성, NPC 생성, NPC의 토너먼트 베팅 - 전투 - 도시 점령 - 자율 행동 선택 - 랜덤 턴 변경 - 거래장, 토너먼트 등 구 랜덤 코드를 이용하는 잔여 코드 있음
This commit is contained in:
@@ -4,6 +4,7 @@ namespace sammo\GeneralPool;
|
||||
use MeekroDB;
|
||||
use sammo\AbsGeneralPool;
|
||||
use sammo\GameConst;
|
||||
use sammo\RandUtil;
|
||||
use sammo\Util;
|
||||
|
||||
|
||||
@@ -26,67 +27,14 @@ class RandomNameGeneral extends AbsGeneralPool{
|
||||
return $db->affectedRows()!=0;
|
||||
}
|
||||
|
||||
public function giveGeneralSpec(array $pickTypeList, array $avgGen, array $env){
|
||||
//do Nothing
|
||||
$dexTotal = $avgGen['dex_t'];
|
||||
|
||||
$pickType = Util::choiceRandomUsingWeight($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));
|
||||
$subStat = $totalStat - $mainStat - $otherStat;
|
||||
if ($subStat < $minStat) {
|
||||
$subStat = $otherStat;
|
||||
$otherStat = $minStat;
|
||||
$mainStat = $totalStat - $subStat - $otherStat;
|
||||
if ($mainStat) {
|
||||
throw new \LogicException('기본 스탯 설정값이 잘못되어 있음');
|
||||
}
|
||||
}
|
||||
|
||||
if ($pickType == '무') {
|
||||
$leadership = $subStat;
|
||||
$strength = $mainStat;
|
||||
$intel = $otherStat;
|
||||
$dexVal = Util::choiceRandom([
|
||||
[$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],
|
||||
]);
|
||||
} else if ($pickType == '지') {
|
||||
$leadership = $subStat;
|
||||
$strength = $otherStat;
|
||||
$intel = $mainStat;
|
||||
$dexVal = [$dexTotal / 8, $dexTotal / 8, $dexTotal / 8, $dexTotal * 5 / 8];
|
||||
} else {
|
||||
$leadership = $otherStat;
|
||||
$strength = $subStat;
|
||||
$intel = $mainStat;
|
||||
$dexVal = [$dexTotal / 4, $dexTotal / 4, $dexTotal / 4, $dexTotal / 4];
|
||||
}
|
||||
|
||||
$leadership = Util::round($leadership);
|
||||
$strength = Util::round($strength);
|
||||
$intel = Util::round($intel);
|
||||
|
||||
$builder = $this->getGeneralBuilder();
|
||||
$builder->setStat($leadership, $strength, $intel);
|
||||
$builder->setDex($dexVal[0], $dexVal[1], $dexVal[2], $dexVal[3], $avgGen['dex5']);
|
||||
$builder->setCityID(Util::choiceRandom(array_keys(\sammo\CityConst::all())));
|
||||
|
||||
$builder->setExpDed($avgGen['exp'], $avgGen['ded']);
|
||||
}
|
||||
|
||||
static protected function pickGeneral1FromPool(\MeekroDB $db, int $owner, ?string $prefix=null):self{
|
||||
static protected function pickGeneral1FromPool(\MeekroDB $db, RandUtil $rng, int $owner, ?string $prefix=null):self{
|
||||
|
||||
$loopCnt = 0;
|
||||
while(true){
|
||||
|
||||
$firstname = Util::choiceRandom(GameConst::$randGenFirstName);
|
||||
$middlename = Util::choiceRandom(GameConst::$randGenMiddleName);
|
||||
$lastname = Util::choiceRandom(GameConst::$randGenLastName);
|
||||
$firstname = $rng->choice(GameConst::$randGenFirstName);
|
||||
$middlename = $rng->choice(GameConst::$randGenMiddleName);
|
||||
$lastname = $rng->choice(GameConst::$randGenLastName);
|
||||
|
||||
$generalName = "{$firstname}{$middlename}{$lastname}";
|
||||
if($prefix){
|
||||
@@ -106,7 +54,7 @@ class RandomNameGeneral extends AbsGeneralPool{
|
||||
|
||||
$uniqueName = $generalName;
|
||||
|
||||
return new static($db, [
|
||||
return new static($db, $rng, [
|
||||
'uniqueName'=>$uniqueName,
|
||||
'generalName'=>$generalName,
|
||||
'imgsvr'=>0,
|
||||
@@ -114,17 +62,17 @@ class RandomNameGeneral extends AbsGeneralPool{
|
||||
], '9999-12-31 12:00:00');
|
||||
}
|
||||
|
||||
static public function pickGeneralFromPool(MeekroDB $db, int $owner, int $pickCnt, ?string $prefix = null): array
|
||||
static public function pickGeneralFromPool(MeekroDB $db, RandUtil $rng, int $owner, int $pickCnt, ?string $prefix = null): array
|
||||
{
|
||||
/** @var RandomNameGeneral[] */
|
||||
$result = [];
|
||||
$dbInsert = [];
|
||||
|
||||
$oNow = new \DateTimeImmutable();
|
||||
|
||||
|
||||
|
||||
|
||||
for($i=0;$i<$pickCnt;$i++){
|
||||
$result[] = static::pickGeneral1FromPool($db, $owner, $prefix);
|
||||
$result[] = static::pickGeneral1FromPool($db, $rng, $owner, $prefix);
|
||||
}
|
||||
|
||||
if($owner){
|
||||
|
||||
Reference in New Issue
Block a user