턴 수행 constraint를 상세하게 분리, argTest 추가. 턴 커맨드 실행용 클래스, ajax 파일 준비

This commit is contained in:
2018-09-16 22:16:08 +09:00
parent 9dcafaaa38
commit 777ec39bd9
14 changed files with 164 additions and 38 deletions
+55 -19
View File
@@ -27,11 +27,18 @@ abstract class BaseCommand{
protected $destCity = null;
protected $destNation = null;
protected $available = null;
protected $reason = null;
protected $runnable = null;
protected $reservable = null;
protected $constraints = null;
protected $constraintsLight = null;
protected $isArgValid=false;
protected $reasonNotRunnable = null;
protected $reasonNotReservable = null;
protected $runnableConstraints = null;
protected $reservableConstraints = null;
protected $logger;
@@ -40,12 +47,20 @@ abstract class BaseCommand{
$this->logger = $generalObj->getLogger();
$this->env = $env;
$this->arg = $arg;
if ($this->argTest()) {
return;
}
$this->isArgValid = true;
$this->init();
}
protected function resetTestCache():void{
$this->reason = null;
$this->available = null;
$this->runnable = null;
$this->reservable = null;
$this->reasonNotRunnable = null;
$this->reasonNotReservable = null;
}
protected function setCity(array $args=null){
@@ -110,6 +125,7 @@ abstract class BaseCommand{
}
abstract protected function init();
abstract protected function argTest():bool;
public function getName():string {
return static::$name;
@@ -119,13 +135,24 @@ abstract class BaseCommand{
return $this->logger;
}
public function test(bool $fullCheck):?string{
if($this->constraints === null){
public function testReservable():?string{
}
public function testRunnable():?string{
if(!$this->isArgValid()){
throw new \InvalidArgumentException('인자가 제대로 설정되지 않았습니다');
}
if($this->runnableConstraints === null){
throw new \InvalidArgumentException('runnableConstraits가 제대로 설정되지 않았습니다');
}
if($this->reason){
return $this->reason;
if(!$this->isReservable()){
return $this->testReservable();
}
if($this->reasonNotRunnable){
return $this->reasonNotRunnable;
}
$constraintInput = [
@@ -139,21 +166,30 @@ abstract class BaseCommand{
'destNation'=>$this->destNation,
];
if(!$fullCheck && $this->constraintsLight){
return Constraint::testAll($this->constraintsLight, $constraintInput);
if(!$fullCheck && $this->reservableConstraints){
return Constraint::testAll($this->reservableConstraints, $constraintInput);
}
$this->reason = Constraint::testAll($this->constraints, $constraintInput);
$this->available = $this->reason === null;
$this->reasonNotRunnable = Constraint::testAll($this->runnableConstraints, $constraintInput);
$this->runnable = $this->reason === null;
return $this->reason;
}
public function isAvailable(bool $fullCheck=true):bool {
if($this->available !== null){
return $this->available;
}
return $this->test($fullCheck) === null;
public function isReservable():bool{
}
public function isArgValid():bool{
return $this->isArgValid;
}
public function isRunnable():bool {
if($this->runnable !== null){
return $this->runnable;
}
return $this->testRunnable() === null;
}
abstract public function getCost():array;
+6 -2
View File
@@ -32,7 +32,7 @@ class che_기술연구 extends che_상업투자{
$develCost = $this->env['develcost'];
$reqGold = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
$this->constraints=[
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['OccupiedCity'],
@@ -43,8 +43,12 @@ class che_기술연구 extends che_상업투자{
$this->reqGold = $reqGold;
}
protected function argTest():bool{
return true;
}
public function run():bool{
if(!$this->isAvailable()){
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+6 -2
View File
@@ -33,7 +33,7 @@ class che_상업투자 extends BaseCommand{
$develCost = $this->env['develcost'];
$reqGold = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
$this->constraints=[
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['OccupiedCity'],
@@ -45,6 +45,10 @@ class che_상업투자 extends BaseCommand{
$this->reqGold = $reqGold;
}
protected function argTest():bool{
return true;
}
protected function calcBaseScore():float{
$trust = Util::valueFit($this->city['trust'], 50);
$general = $this->generalObj;
@@ -71,7 +75,7 @@ class che_상업투자 extends BaseCommand{
}
public function run():bool{
if(!$this->isAvailable()){
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+6 -2
View File
@@ -33,7 +33,7 @@ class che_상업투자 extends BaseCommand{
$develCost = $this->env['develcost'] * 2;
$reqRice = $general->onCalcDomestic(static::$actionKey, 'cost', $reqRice);
$this->constraints=[
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['OccupiedCity'],
@@ -45,6 +45,10 @@ class che_상업투자 extends BaseCommand{
$this->reqRice = $reqRice;
}
protected function argTest():bool{
return true;
}
protected function calcBaseScore():float{
$general = $this->generalObj;
@@ -63,7 +67,7 @@ class che_상업투자 extends BaseCommand{
}
public function run():bool{
if(!$this->isAvailable()){
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+6 -2
View File
@@ -33,7 +33,7 @@ class che_주민선정 extends BaseCommand{
$develCost = $this->env['develcost'] * 2;
$reqRice = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
$this->constraints=[
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['OccupiedCity'],
@@ -45,6 +45,10 @@ class che_주민선정 extends BaseCommand{
$this->reqRice = $reqRice;
}
protected function argTest():bool{
return true;
}
protected function calcBaseScore():float{
$general = $this->generalObj;
@@ -64,7 +68,7 @@ class che_주민선정 extends BaseCommand{
}
public function run():bool{
if(!$this->isAvailable()){
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+30
View File
@@ -0,0 +1,30 @@
<?php
namespace sammo\Command;
use \sammo\Util;
use \sammo\JosaUtil;
class 휴식 extends BaseCommand{
protected function init(){
//아무것도 하지 않음
}
protected function argTest():bool{
return true;
}
public function getCost():array{
return [0, 0];
}
public function run():bool{
$general = $this->generalObj;
$logger = $general->getLogger();
$date = substr($general->getVar('turntime'),11,5);
$logger->pushGeneralActionLog("아무것도 실행하지 않았습니다. <1>$date</>");
$general->increaseVar('killturn', -1);
$general->applyDB(DB::db());
return true;
}
}
+2 -8
View File
@@ -162,15 +162,9 @@ abstract class Constraint{
return true;
}
public function reason($withTest=true):?string{
public function reason():?string{
if(!$this->tested === false){
if($withTest){
$this->test();
}
else{
throw new \RuntimeException('test가 실행되지 않음');
}
throw new \RuntimeException('test가 실행되지 않음');
}
return $this->reason;
}
+14
View File
@@ -0,0 +1,14 @@
<?php
namespace sammo;
class TurnExecutionHelper
{
protected $generalID;
protected $generalObj;
public function __construct(int $generalID, int $year, int $month)
{
$db = DB::db();
$this->generalObj = new General();
}
}