Files
core/hwe/sammo/Command/Nation/che_백성동원.php
T
Hide_D c5ceff6fb5 feat,refac: 게임 로직 내 '랜덤'을 RandUtil을 활용하여 재설정
- 기존의 랜덤 코드는 deprecated 처리
- 서버 시작 시 랜덤하게 정해진 hiddenSeed를 활용
- 랜덤 생성 단위
  - 월 실행
  - 사령턴 실행 결과
  - 커맨드 실행 결과
  - 작위 보상
  - 부대장 생성
  - 유니크 획득 시도
  - 설문 조사
  - 장수 생성
  - NPC국 생성, NPC 생성, NPC의 토너먼트 베팅
  - 전투
  - 도시 점령
  - 자율 행동 선택
  - 랜덤 턴 변경
- 거래장, 토너먼트 등 구 랜덤 코드를 이용하는 잔여 코드 있음
2022-05-17 03:46:59 +09:00

182 lines
5.3 KiB
PHP

<?php
namespace sammo\Command\Nation;
use \sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
MessageTarget,
Message,
CityConst
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_백성동원 extends Command\NationCommand
{
static protected $actionName = '백성동원';
static public $reqArg = true;
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if (!key_exists('destCityID', $this->arg)) {
return false;
}
if (CityConst::byID($this->arg['destCityID']) === null) {
return false;
}
$destCityID = $this->arg['destCityID'];
$this->arg = [
'destCityID' => $destCityID,
];
return true;
}
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->minConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand()
];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
$this->setDestNation($this->destCity['nation']);
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::OccupiedDestCity(),
ConstraintHelper::AvailableStrategicCommand()
];
}
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(재사용 대기 $postReqTurn)";
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount * 4) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief(): string
{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
return "【{$destCityName}】에 {$commandName}";
}
public function run(\Sammo\RandUtil $rng): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$destCity = $this->destCity;
$destCityID = $destCity['city'];
$destCityName = $destCity['name'];
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$logger->pushGeneralActionLog("백성동원 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$josaYi = JosaUtil::pick($generalName, '이');
$broadcastMessage = "<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>백성동원</>을 하였습니다.";
$targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach ($targetGeneralList as $targetGeneralID) {
$targetLogger = new ActionLogger($targetGeneralID, $nationID, $year, $month);
$targetLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$targetLogger->flush();
}
$db->update('city', [
'def' => $db->sqleval('GREATEST(def_max * 0.8, def)'),
'wall' => $db->sqleval('GREATEST(wall_max * 0.8, wall)'),
], 'city=%i', $destCityID);
$logger->pushGeneralHistoryLog('<M>백성동원</>을 발동');
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>백성동원</>을 발동");
$db->update('nation', [
'strategic_cmd_limit' => $this->generalObj->onCalcStrategic($this->getName(), 'globalDelay', 9)
], 'nation=%i', $nationID);
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
public function exportJSVars(): array
{
return [
'procRes' => [
'cities' => \sammo\JSOptionsForCities(),
'distanceList' => new \stdClass(),
],
];
}
}