- 기존의 랜덤 코드는 deprecated 처리 - 서버 시작 시 랜덤하게 정해진 hiddenSeed를 활용 - 랜덤 생성 단위 - 월 실행 - 사령턴 실행 결과 - 커맨드 실행 결과 - 작위 보상 - 부대장 생성 - 유니크 획득 시도 - 설문 조사 - 장수 생성 - NPC국 생성, NPC 생성, NPC의 토너먼트 베팅 - 전투 - 도시 점령 - 자율 행동 선택 - 랜덤 턴 변경 - 거래장, 토너먼트 등 구 랜덤 코드를 이용하는 잔여 코드 있음
94 lines
2.9 KiB
PHP
94 lines
2.9 KiB
PHP
<?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
|
|
{
|
|
protected $npcCount;
|
|
protected $fillCnt;
|
|
protected $avgGen;
|
|
public function __construct($npcCount = 10, $fillCnt = 0)
|
|
{
|
|
$this->npcCount = $npcCount;
|
|
$this->fillCnt = $fillCnt;
|
|
}
|
|
|
|
protected function generateNPC($env, int $cnt)
|
|
{
|
|
$pickTypeList = ['무' => 1, '지' => 1];
|
|
|
|
$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'] + $rng->nextRangeInt(10, 50);
|
|
|
|
$result = [];
|
|
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) {
|
|
$newNPC->fillRandomStat($pickTypeList);
|
|
}
|
|
$newNPC->fillRemainSpecAsZero($env);
|
|
$newNPC->build($env);
|
|
$pickedNPC->occupyGeneralName();
|
|
$result[] = [
|
|
$newNPC->getGeneralName(), $newNPC->getGeneralID()
|
|
];
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
|
|
public function run(array $env)
|
|
{
|
|
if ($this->npcCount <= 0 && $this->fillCnt <= 0) {
|
|
return [__CLASS__, []];
|
|
}
|
|
|
|
|
|
$moreGenCnt = 0;
|
|
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);
|
|
$moreGenCnt = count($nations) * $this->fillCnt - $regGens;
|
|
}
|
|
|
|
$result = $this->generateNPC($env, $this->npcCount + $moreGenCnt);
|
|
|
|
$logger = new \sammo\ActionLogger(0, 0, $env['year'], $env['month']);
|
|
$genCnt = count($result);
|
|
if ($genCnt == 1) {
|
|
$npcName = $result[0][0];
|
|
$josaRa = \sammo\JosaUtil::pick($npcName, '라');
|
|
$logger->pushGlobalActionLog("<Y>$npcName</>{$josaRa}는 장수가 <S>등장</>하였습니다.");
|
|
} else {
|
|
$logger->pushGlobalActionLog("장수 <C>{$genCnt}</>명이 <S>등장</>하였습니다.");
|
|
}
|
|
$logger->pushGlobalHistoryLog("장수 <C>{$genCnt}</>명이 <S>등장</>했습니다.", \sammo\ActionLogger::NOTICE_YEAR_MONTH);
|
|
$logger->flush();
|
|
|
|
return [__CLASS__, $result];
|
|
}
|
|
}
|