커맨드 유효성을 2개에서 3개구성으로 변경
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
use\sammo\{
|
||||
DB,
|
||||
Util,
|
||||
JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst, GameUnitConst,
|
||||
GameConst,
|
||||
GameUnitConst,
|
||||
LastTurn,
|
||||
Command
|
||||
};
|
||||
|
||||
|
||||
use function \sammo\{
|
||||
use function\sammo\{
|
||||
tryUniqueItemLottery,
|
||||
printCitiesBasedOnDistance
|
||||
};
|
||||
@@ -22,83 +26,103 @@ use sammo\CityConst;
|
||||
|
||||
|
||||
|
||||
class che_이동 extends Command\GeneralCommand{
|
||||
class che_이동 extends Command\GeneralCommand
|
||||
{
|
||||
static protected $actionName = '이동';
|
||||
static public $reqArg = true;
|
||||
|
||||
protected function argTest():bool{
|
||||
if($this->arg === null){
|
||||
protected function argTest(): bool
|
||||
{
|
||||
if ($this->arg === null) {
|
||||
return false;
|
||||
}
|
||||
if(!key_exists('destCityID', $this->arg)){
|
||||
if (!key_exists('destCityID', $this->arg)) {
|
||||
return false;
|
||||
}
|
||||
if(!key_exists($this->arg['destCityID'], CityConst::all())){
|
||||
if (!key_exists($this->arg['destCityID'], CityConst::all())) {
|
||||
return false;
|
||||
}
|
||||
$this->arg = [
|
||||
'destCityID'=>$this->arg['destCityID']
|
||||
'destCityID' => $this->arg['destCityID']
|
||||
];
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
protected function init()
|
||||
{
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
$this->setDestCity($this->arg['destCityID'], []);
|
||||
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->runnableConstraints=[
|
||||
ConstraintHelper::NotSameDestCity(),
|
||||
|
||||
$this->minConditionConstraints = [
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice),
|
||||
];
|
||||
}
|
||||
|
||||
protected function initWithArg()
|
||||
{
|
||||
$this->setDestCity($this->arg['destCityID'], true);
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
$this->fullConditionConstraints = [
|
||||
ConstraintHelper::NotSameDestCity(),
|
||||
ConstraintHelper::NearCity(1),
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice),
|
||||
];
|
||||
}
|
||||
|
||||
public function getCommandDetailTitle():string{
|
||||
public function getCommandDetailTitle(): string
|
||||
{
|
||||
$name = $this->getName();
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$title = "{$name}(통솔경험";
|
||||
if($reqGold > 0){
|
||||
if ($reqGold > 0) {
|
||||
$title .= ", 자금{$reqGold}";
|
||||
}
|
||||
if($reqRice > 0){
|
||||
if ($reqRice > 0) {
|
||||
$title .= ", 군량{$reqRice}";
|
||||
}
|
||||
$title .= ', 사기↓)';
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
public function getCost(): array
|
||||
{
|
||||
$env = $this->env;
|
||||
return [$env['develcost'], 0];
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
|
||||
public function getPreReqTurn(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
public function getPostReqTurn(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getBrief():string{
|
||||
public function getBrief(): string
|
||||
{
|
||||
$commandName = $this->getName();
|
||||
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
|
||||
$josaRo = JosaUtil::pick($destCityName, '로');
|
||||
return "【{$destCityName}】{$josaRo} {$commandName}";
|
||||
}
|
||||
|
||||
public function getFailString():string{
|
||||
public function getFailString(): string
|
||||
{
|
||||
$commandName = $this->getName();
|
||||
$failReason = $this->testRunnable();
|
||||
if($failReason === null){
|
||||
$failReason = $this->testFullConditionMet();
|
||||
if ($failReason === null) {
|
||||
throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집');
|
||||
}
|
||||
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
|
||||
@@ -106,8 +130,9 @@ class che_이동 extends Command\GeneralCommand{
|
||||
return "{$failReason} <G><b>{$destCityName}</b></>{$josaRo} {$commandName} 실패.";
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->isRunnable()){
|
||||
public function run(): bool
|
||||
{
|
||||
if (!$this->hasFullConditionMet()) {
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
@@ -129,14 +154,14 @@ class che_이동 extends Command\GeneralCommand{
|
||||
|
||||
$general->setVar('city', $destCityID);
|
||||
|
||||
if($general->getVar('officer_level') == 12 && $this->nation['level'] == 0){
|
||||
if ($general->getVar('officer_level') == 12 && $this->nation['level'] == 0) {
|
||||
$generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID());
|
||||
if($generalList){
|
||||
if ($generalList) {
|
||||
$db->update('general', [
|
||||
'city'=>$destCityID
|
||||
'city' => $destCityID
|
||||
], 'no IN %li', $generalList);
|
||||
}
|
||||
foreach($generalList as $targetGeneralID){
|
||||
foreach ($generalList as $targetGeneralID) {
|
||||
$targetLogger = new ActionLogger($targetGeneralID, $general->getNationID(), $env['year'], $env['month']);
|
||||
$targetLogger->pushGeneralActionLog("방랑군 세력이 <G><b>{$destCityName}</b></>{$josaRo} 이동했습니다.", ActionLogger::PLAIN);
|
||||
$targetLogger->flush();
|
||||
@@ -168,17 +193,17 @@ class che_이동 extends Command\GeneralCommand{
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<?=\sammo\getMapHtml()?><br>
|
||||
선택된 도시로 이동합니다.<br>
|
||||
인접 도시로만 이동이 가능합니다.<br>
|
||||
목록을 선택하거나 도시를 클릭하세요.<br>
|
||||
<?=$currentCityName?> => <select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
|
||||
<?=\sammo\optionsForCities()?><br>
|
||||
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
|
||||
<br>
|
||||
<br>
|
||||
<?=printCitiesBasedOnDistance($currentCityID, 1)?>
|
||||
<?= \sammo\getMapHtml() ?><br>
|
||||
선택된 도시로 이동합니다.<br>
|
||||
인접 도시로만 이동이 가능합니다.<br>
|
||||
목록을 선택하거나 도시를 클릭하세요.<br>
|
||||
<?= $currentCityName ?> => <select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
|
||||
<?= \sammo\optionsForCities() ?><br>
|
||||
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
|
||||
<br>
|
||||
<br>
|
||||
<?= printCitiesBasedOnDistance($currentCityID, 1) ?>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user