feat,refac: 게임 로직 내 '랜덤'을 RandUtil을 활용하여 재설정
- 기존의 랜덤 코드는 deprecated 처리 - 서버 시작 시 랜덤하게 정해진 hiddenSeed를 활용 - 랜덤 생성 단위 - 월 실행 - 사령턴 실행 결과 - 커맨드 실행 결과 - 작위 보상 - 부대장 생성 - 유니크 획득 시도 - 설문 조사 - 장수 생성 - NPC국 생성, NPC 생성, NPC의 토너먼트 베팅 - 전투 - 도시 점령 - 자율 행동 선택 - 랜덤 턴 변경 - 거래장, 토너먼트 등 구 랜덤 코드를 이용하는 잔여 코드 있음
This commit is contained in:
@@ -1,37 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use \sammo\GameConst;
|
||||
use \sammo\Util;
|
||||
use \sammo\DB;
|
||||
use sammo\LiteHashDRBG;
|
||||
use sammo\RandUtil;
|
||||
use sammo\UniqueConst;
|
||||
|
||||
use function sammo\pickGeneralFromPool;
|
||||
|
||||
//기존 event_3.php
|
||||
class CreateManyNPC extends \sammo\Event\Action{
|
||||
class CreateManyNPC extends \sammo\Event\Action
|
||||
{
|
||||
protected $npcCount;
|
||||
protected $fillCnt;
|
||||
protected $avgGen;
|
||||
public function __construct($npcCount = 10, $fillCnt = 0){
|
||||
public function __construct($npcCount = 10, $fillCnt = 0)
|
||||
{
|
||||
$this->npcCount = $npcCount;
|
||||
$this->fillCnt = $fillCnt;
|
||||
}
|
||||
|
||||
protected function generateNPC($env, int $cnt){
|
||||
$pickTypeList = ['무'=>1, '지'=>1];
|
||||
protected function generateNPC($env, int $cnt)
|
||||
{
|
||||
$pickTypeList = ['무' => 1, '지' => 1];
|
||||
|
||||
$age = Util::randRangeInt(20, 25);
|
||||
$rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||
UniqueConst::$hiddenSeed,
|
||||
'CreateManyNPC',
|
||||
$env['year'],
|
||||
$env['month']
|
||||
)));
|
||||
$age = $rng->nextRangeInt(20, 25);
|
||||
$birthYear = $env['year'] - $age;
|
||||
$deathYear = $env['year'] + Util::randRangeInt(10, 50);
|
||||
$deathYear = $env['year'] + $rng->nextRangeInt(10, 50);
|
||||
|
||||
$result = [];
|
||||
foreach(pickGeneralFromPool(DB::db(), 0, $cnt) as $pickedNPC){
|
||||
foreach (pickGeneralFromPool(DB::db(), $rng, 0, $cnt) as $pickedNPC) {
|
||||
$newNPC = $pickedNPC->getGeneralBuilder();
|
||||
$newNPC->setNationID(0)
|
||||
->setNPCType(3)
|
||||
->setMoney(1000, 1000)
|
||||
->setExpDed(0, 0)
|
||||
->setLifeSpan($birthYear, $deathYear);
|
||||
if($newNPC->getStat()[0]===null){
|
||||
->setNPCType(3)
|
||||
->setMoney(1000, 1000)
|
||||
->setExpDed(0, 0)
|
||||
->setLifeSpan($birthYear, $deathYear);
|
||||
if ($newNPC->getStat()[0] === null) {
|
||||
$newNPC->fillRandomStat($pickTypeList);
|
||||
}
|
||||
$newNPC->fillRemainSpecAsZero($env);
|
||||
@@ -45,14 +59,15 @@ class CreateManyNPC extends \sammo\Event\Action{
|
||||
}
|
||||
|
||||
|
||||
public function run(array $env){
|
||||
if($this->npcCount <= 0 && $this->fillCnt <= 0){
|
||||
public function run(array $env)
|
||||
{
|
||||
if ($this->npcCount <= 0 && $this->fillCnt <= 0) {
|
||||
return [__CLASS__, []];
|
||||
}
|
||||
|
||||
|
||||
$moreGenCnt = 0;
|
||||
if($this->fillCnt){
|
||||
if ($this->fillCnt) {
|
||||
$db = DB::db();
|
||||
$nations = $db->queryFirstColumn('SELECT nation FROM general WHERE npc < 3 AND officer_level = 12');
|
||||
$regGens = $db->queryFirstField('SELECT count(*) FROM general WHERE nation IN %li AND npc < 4', $nations);
|
||||
@@ -63,12 +78,11 @@ class CreateManyNPC extends \sammo\Event\Action{
|
||||
|
||||
$logger = new \sammo\ActionLogger(0, 0, $env['year'], $env['month']);
|
||||
$genCnt = count($result);
|
||||
if($genCnt == 1){
|
||||
if ($genCnt == 1) {
|
||||
$npcName = $result[0][0];
|
||||
$josaRa = \sammo\JosaUtil::pick($npcName, '라');
|
||||
$logger->pushGlobalActionLog("<Y>$npcName</>{$josaRa}는 장수가 <S>등장</>하였습니다.");
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$logger->pushGlobalActionLog("장수 <C>{$genCnt}</>명이 <S>등장</>하였습니다.");
|
||||
}
|
||||
$logger->pushGlobalHistoryLog("장수 <C>{$genCnt}</>명이 <S>등장</>했습니다.", \sammo\ActionLogger::NOTICE_YEAR_MONTH);
|
||||
@@ -76,4 +90,4 @@ class CreateManyNPC extends \sammo\Event\Action{
|
||||
|
||||
return [__CLASS__, $result];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user