커맨드 유효성을 2개에서 3개구성으로 변경

This commit is contained in:
2020-05-04 19:51:11 +09:00
parent dbba6fa942
commit 76ac6cf5b5
100 changed files with 4124 additions and 3420 deletions
+91 -63
View File
@@ -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,
processWar
};
@@ -22,38 +26,58 @@ 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(['war', 'gennum', 'tech', 'gold', 'rice', 'color', 'type', 'level', 'capital']);
$this->setDestCity($this->arg['destCityID'], null);
[$reqGold, $reqRice] = $this->getCost();
$relYear = $this->env['year'] - $this->env['startyear'];
$this->minConditionConstraints = [
ConstraintHelper::NotOpeningPart($relYear+1),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralCrew(),
ConstraintHelper::ReqGeneralRice($reqRice),
];
$this->runnableConstraints=[
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
[$reqGold, $reqRice] = $this->getCost();
$relYear = $this->env['year'] - $this->env['startyear'];
$this->fullConditionConstraints = [
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::NotSameDestCity(),
ConstraintHelper::NotBeNeutral(),
@@ -65,36 +89,42 @@ class che_출병 extends Command\GeneralCommand{
];
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
//[$reqGold, $reqRice] = $this->getCost();
return "{$name}(통솔경험, 병종숙련, 군량↓)";
}
public function getCost():array{
return [0, Util::round($this->generalObj->getVar('crew')/100)];
public function getCost(): array
{
return [0, Util::round($this->generalObj->getVar('crew') / 100)];
}
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;
@@ -102,8 +132,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('불가능한 커맨드를 강제로 실행 시도');
}
@@ -117,10 +148,10 @@ class che_출병 extends Command\GeneralCommand{
$attackerCityID = $general->getCityID();
$finalTargetCityID = $this->destCity['city'];
$finalTargetCityName = $this->destCity['name'];
$logger = $general->getLogger();
@@ -136,62 +167,61 @@ class che_출병 extends Command\GeneralCommand{
do {
//1: 최단 거리 도시 중 공격 대상이 있는가 확인
//2: 최단 거리 + 1 도시 중 공격 대상이 있는가 확인
foreach($distanceList as $dist => $distCitiesInfo){
if($dist > $minDist + 1){
foreach ($distanceList as $dist => $distCitiesInfo) {
if ($dist > $minDist + 1) {
break;
}
$currDist = $dist;
foreach($distCitiesInfo as [$distCityID, $distCityNation]){
if($distCityNation !== $attackerNationID){
foreach ($distCitiesInfo as [$distCityID, $distCityNation]) {
if ($distCityNation !== $attackerNationID) {
$candidateCities[] = $distCityID;
}
}
if($candidateCities){
if ($candidateCities) {
break 2;
}
}
//3: 최단 거리 도시 중 아군 도시 선택
foreach($distanceList[$minDist] as [$distCityID, $distCityNation]){
if($distCityNation === $attackerNationID){
foreach ($distanceList[$minDist] as [$distCityID, $distCityNation]) {
if ($distCityNation === $attackerNationID) {
$candidateCities[] = $distCityID;
}
}
}while(false);
$defenderCityID = (int)Util::choiceRandom($candidateCities);
} while (false);
$defenderCityID = (int) Util::choiceRandom($candidateCities);
$defenderCityName = $this->destCity['name'];
$this->setDestCity($defenderCityID, null);
$this->setDestCity($defenderCityID);
$josaRo = JosaUtil::pick($defenderCityName, '로');
if($attackerNationID == $defenderNationID){
$logger->pushGeneralActionLog("본국입니다. <G><b>{$defenderCityName}</b></>{$josaRo} 으로 이동합니다. <1>$date</>");
$this->alternative = new che_이동($general, $this->env, ['destCityID'=>$defenderCityID]);
if ($attackerNationID == $defenderNationID) {
$logger->pushGeneralActionLog("본국입니다. <G><b>{$defenderCityName}</b></>{$josaRo} 으로 이동합니다. <1>$date</>");
$this->alternative = new che_이동($general, $this->env, ['destCityID' => $defenderCityID]);
return false;
}
if($finalTargetCityID !== $defenderCityID){
if ($finalTargetCityID !== $defenderCityID) {
$josaRo = JosaUtil::pick($finalTargetCityName, '로');
$josaUl = JosaUtil::pick($defenderCityName, '을');
if($minDist == $currDist){
if ($minDist == $currDist) {
$logger->pushGeneralActionLog("<G><b>{$finalTargetCityName}</b></>{$josaRo} 가기 위해 <G><b>{$defenderCityName}</b></>{$josaUl} 거쳐야 합니다. <1>$date</>");
}
else{
} else {
$logger->pushGeneralActionLog("<G><b>{$finalTargetCityName}</b></>{$josaRo} 가는 도중 <G><b>{$defenderCityName}</b></>{$josaUl} 거치기로 합니다. <1>$date</>");
}
}
$db->update('city', [
'state'=>43,
'term'=>3
'state' => 43,
'term' => 3
], 'city=%i', $defenderCityID);
$this->destCity['state'] = 43;
$this->destCity['term'] = 3;
$general->addDex($general->getCrewTypeObj(), $general->getVar('crew')/100);
$general->addDex($general->getCrewTypeObj(), $general->getVar('crew') / 100);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
@@ -200,7 +230,7 @@ class che_출병 extends Command\GeneralCommand{
tryUniqueItemLottery($general);
$general->applyDB($db);
return true;
}
@@ -216,17 +246,15 @@ class che_출병 extends Command\GeneralCommand{
$srcCityName = \sammo\CityConst::byID($this->generalObj->getCityID())->name;
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 도시를 향해 침공을 합니다.<br>
침공 경로에 적군의 도시가 있다면 전투를 벌입니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<?=$srcCityName?> =><select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'>
<?=\sammo\optionsForCities()?><br>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<br>
<?= \sammo\getMapHtml() ?><br>
선택된 도시를 향해 침공을 합니다.<br>
침공 경로에 적군의 도시가 있다면 전투를 벌입니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<?= $srcCityName ?> =><select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'>
<?= \sammo\optionsForCities() ?><br>
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<br>
<?php
return ob_get_clean();
return ob_get_clean();
}
}
}