턴 수행 constraint를 상세하게 분리, argTest 추가. 턴 커맨드 실행용 클래스, ajax 파일 준비
This commit is contained in:
@@ -223,7 +223,7 @@ function process_domestic(array $rawGeneral, int $type){
|
|||||||
}
|
}
|
||||||
$cmdObj = new $cmdClass($general, $env);
|
$cmdObj = new $cmdClass($general, $env);
|
||||||
|
|
||||||
if(!$cmdObj->isAvailable()){
|
if(!$cmdObj->isRunnable()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$cmdObj->run();
|
$cmdObj->run();
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ function process_domestic(array $rawGeneral, int $type){
|
|||||||
}
|
}
|
||||||
$cmdObj = new $cmdClass($general, $env);
|
$cmdObj = new $cmdClass($general, $env);
|
||||||
|
|
||||||
if(!$cmdObj->isAvailable()){
|
if(!$cmdObj->isRunnable()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$cmdObj->run();
|
$cmdObj->run();
|
||||||
|
|||||||
+8
-1
@@ -235,7 +235,14 @@ else if($session->userGrade == 4){
|
|||||||
<td style='width:700px;height:520px;' colspan=2>
|
<td style='width:700px;height:520px;' colspan=2>
|
||||||
<?=getMapHtml($mapTheme)?>
|
<?=getMapHtml($mapTheme)?>
|
||||||
</td>
|
</td>
|
||||||
<td style='width:300px;' rowspan=4><iframe seamless="seamless" name=commandlist src='commandlist.php' style='width:300px;height:700px;' frameborder=0 marginwidth=0 marginheight=0 topmargin=0 scrolling=no></iframe></td>
|
<td style='width:300px;overflow-y:scroll' rowspan=4>
|
||||||
|
<div id="reservedCommandList">
|
||||||
|
<div id="reservedCommandHeader">
|
||||||
|
</div>
|
||||||
|
<ul id="reservedCommandList">
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<form name=form2 action=preprocessing.php method=post target=commandlist>
|
<form name=form2 action=preprocessing.php method=post target=commandlist>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
namespace sammo;
|
||||||
|
|
||||||
|
include "lib.php";
|
||||||
|
include "func.php";
|
||||||
|
|
||||||
|
$session = Session::requireGameLogin([])->setReadOnly();
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$commandList = [];
|
||||||
|
|
||||||
|
$generalID = $session->generalID;
|
||||||
|
|
||||||
|
$rawTurn = $db->queryAllLists('SELECT turn_idx, action, arg FROM general_turn WHERE general_id = %i ORDER BY turn_idx ASC');
|
||||||
|
foreach($rawTurn as [$turn_idx, $action, $arg]){
|
||||||
|
$commandList[$turn_idx] = [
|
||||||
|
'action'=>$action,
|
||||||
|
'arg'=>Json::decode($arg)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::die($commandList);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
namespace sammo;
|
||||||
|
|
||||||
@@ -27,11 +27,18 @@ abstract class BaseCommand{
|
|||||||
protected $destCity = null;
|
protected $destCity = null;
|
||||||
protected $destNation = null;
|
protected $destNation = null;
|
||||||
|
|
||||||
protected $available = null;
|
protected $runnable = null;
|
||||||
protected $reason = null;
|
protected $reservable = null;
|
||||||
|
|
||||||
protected $constraints = null;
|
protected $isArgValid=false;
|
||||||
protected $constraintsLight = null;
|
|
||||||
|
protected $reasonNotRunnable = null;
|
||||||
|
protected $reasonNotReservable = null;
|
||||||
|
|
||||||
|
protected $runnableConstraints = null;
|
||||||
|
protected $reservableConstraints = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
|
||||||
@@ -40,12 +47,20 @@ abstract class BaseCommand{
|
|||||||
$this->logger = $generalObj->getLogger();
|
$this->logger = $generalObj->getLogger();
|
||||||
$this->env = $env;
|
$this->env = $env;
|
||||||
$this->arg = $arg;
|
$this->arg = $arg;
|
||||||
|
if ($this->argTest()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->isArgValid = true;
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function resetTestCache():void{
|
protected function resetTestCache():void{
|
||||||
$this->reason = null;
|
$this->runnable = null;
|
||||||
$this->available = null;
|
$this->reservable = null;
|
||||||
|
|
||||||
|
$this->reasonNotRunnable = null;
|
||||||
|
$this->reasonNotReservable = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setCity(array $args=null){
|
protected function setCity(array $args=null){
|
||||||
@@ -110,6 +125,7 @@ abstract class BaseCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract protected function init();
|
abstract protected function init();
|
||||||
|
abstract protected function argTest():bool;
|
||||||
|
|
||||||
public function getName():string {
|
public function getName():string {
|
||||||
return static::$name;
|
return static::$name;
|
||||||
@@ -119,13 +135,24 @@ abstract class BaseCommand{
|
|||||||
return $this->logger;
|
return $this->logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test(bool $fullCheck):?string{
|
public function testReservable():?string{
|
||||||
if($this->constraints === null){
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRunnable():?string{
|
||||||
|
if(!$this->isArgValid()){
|
||||||
throw new \InvalidArgumentException('인자가 제대로 설정되지 않았습니다');
|
throw new \InvalidArgumentException('인자가 제대로 설정되지 않았습니다');
|
||||||
|
}
|
||||||
|
if($this->runnableConstraints === null){
|
||||||
|
throw new \InvalidArgumentException('runnableConstraits가 제대로 설정되지 않았습니다');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->reason){
|
if(!$this->isReservable()){
|
||||||
return $this->reason;
|
return $this->testReservable();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->reasonNotRunnable){
|
||||||
|
return $this->reasonNotRunnable;
|
||||||
}
|
}
|
||||||
|
|
||||||
$constraintInput = [
|
$constraintInput = [
|
||||||
@@ -139,21 +166,30 @@ abstract class BaseCommand{
|
|||||||
'destNation'=>$this->destNation,
|
'destNation'=>$this->destNation,
|
||||||
];
|
];
|
||||||
|
|
||||||
if(!$fullCheck && $this->constraintsLight){
|
if(!$fullCheck && $this->reservableConstraints){
|
||||||
return Constraint::testAll($this->constraintsLight, $constraintInput);
|
return Constraint::testAll($this->reservableConstraints, $constraintInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->reason = Constraint::testAll($this->constraints, $constraintInput);
|
$this->reasonNotRunnable = Constraint::testAll($this->runnableConstraints, $constraintInput);
|
||||||
$this->available = $this->reason === null;
|
$this->runnable = $this->reason === null;
|
||||||
return $this->reason;
|
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;
|
abstract public function getCost():array;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class che_기술연구 extends che_상업투자{
|
|||||||
$develCost = $this->env['develcost'];
|
$develCost = $this->env['develcost'];
|
||||||
$reqGold = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
|
$reqGold = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
|
||||||
|
|
||||||
$this->constraints=[
|
$this->runnableConstraints=[
|
||||||
['NoNeutral'],
|
['NoNeutral'],
|
||||||
['NoWanderingNation'],
|
['NoWanderingNation'],
|
||||||
['OccupiedCity'],
|
['OccupiedCity'],
|
||||||
@@ -43,8 +43,12 @@ class che_기술연구 extends che_상업투자{
|
|||||||
$this->reqGold = $reqGold;
|
$this->reqGold = $reqGold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function argTest():bool{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public function run():bool{
|
public function run():bool{
|
||||||
if(!$this->isAvailable()){
|
if(!$this->isRunnable()){
|
||||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class che_상업투자 extends BaseCommand{
|
|||||||
$develCost = $this->env['develcost'];
|
$develCost = $this->env['develcost'];
|
||||||
$reqGold = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
|
$reqGold = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
|
||||||
|
|
||||||
$this->constraints=[
|
$this->runnableConstraints=[
|
||||||
['NoNeutral'],
|
['NoNeutral'],
|
||||||
['NoWanderingNation'],
|
['NoWanderingNation'],
|
||||||
['OccupiedCity'],
|
['OccupiedCity'],
|
||||||
@@ -45,6 +45,10 @@ class che_상업투자 extends BaseCommand{
|
|||||||
$this->reqGold = $reqGold;
|
$this->reqGold = $reqGold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function argTest():bool{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected function calcBaseScore():float{
|
protected function calcBaseScore():float{
|
||||||
$trust = Util::valueFit($this->city['trust'], 50);
|
$trust = Util::valueFit($this->city['trust'], 50);
|
||||||
$general = $this->generalObj;
|
$general = $this->generalObj;
|
||||||
@@ -71,7 +75,7 @@ class che_상업투자 extends BaseCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function run():bool{
|
public function run():bool{
|
||||||
if(!$this->isAvailable()){
|
if(!$this->isRunnable()){
|
||||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class che_상업투자 extends BaseCommand{
|
|||||||
$develCost = $this->env['develcost'] * 2;
|
$develCost = $this->env['develcost'] * 2;
|
||||||
$reqRice = $general->onCalcDomestic(static::$actionKey, 'cost', $reqRice);
|
$reqRice = $general->onCalcDomestic(static::$actionKey, 'cost', $reqRice);
|
||||||
|
|
||||||
$this->constraints=[
|
$this->runnableConstraints=[
|
||||||
['NoNeutral'],
|
['NoNeutral'],
|
||||||
['NoWanderingNation'],
|
['NoWanderingNation'],
|
||||||
['OccupiedCity'],
|
['OccupiedCity'],
|
||||||
@@ -45,6 +45,10 @@ class che_상업투자 extends BaseCommand{
|
|||||||
$this->reqRice = $reqRice;
|
$this->reqRice = $reqRice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function argTest():bool{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected function calcBaseScore():float{
|
protected function calcBaseScore():float{
|
||||||
$general = $this->generalObj;
|
$general = $this->generalObj;
|
||||||
|
|
||||||
@@ -63,7 +67,7 @@ class che_상업투자 extends BaseCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function run():bool{
|
public function run():bool{
|
||||||
if(!$this->isAvailable()){
|
if(!$this->isRunnable()){
|
||||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class che_주민선정 extends BaseCommand{
|
|||||||
$develCost = $this->env['develcost'] * 2;
|
$develCost = $this->env['develcost'] * 2;
|
||||||
$reqRice = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
|
$reqRice = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
|
||||||
|
|
||||||
$this->constraints=[
|
$this->runnableConstraints=[
|
||||||
['NoNeutral'],
|
['NoNeutral'],
|
||||||
['NoWanderingNation'],
|
['NoWanderingNation'],
|
||||||
['OccupiedCity'],
|
['OccupiedCity'],
|
||||||
@@ -45,6 +45,10 @@ class che_주민선정 extends BaseCommand{
|
|||||||
$this->reqRice = $reqRice;
|
$this->reqRice = $reqRice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function argTest():bool{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected function calcBaseScore():float{
|
protected function calcBaseScore():float{
|
||||||
$general = $this->generalObj;
|
$general = $this->generalObj;
|
||||||
|
|
||||||
@@ -64,7 +68,7 @@ class che_주민선정 extends BaseCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function run():bool{
|
public function run():bool{
|
||||||
if(!$this->isAvailable()){
|
if(!$this->isRunnable()){
|
||||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -162,15 +162,9 @@ abstract class Constraint{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reason($withTest=true):?string{
|
public function reason():?string{
|
||||||
if(!$this->tested === false){
|
if(!$this->tested === false){
|
||||||
if($withTest){
|
throw new \RuntimeException('test가 실행되지 않음');
|
||||||
$this->test();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
throw new \RuntimeException('test가 실행되지 않음');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return $this->reason;
|
return $this->reason;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,9 @@ namespace sammo;
|
|||||||
* @property bool $reqOTP 인증 코드 필요
|
* @property bool $reqOTP 인증 코드 필요
|
||||||
* @property array $acl 권한
|
* @property array $acl 권한
|
||||||
* @property string $tokenValidUntil 로그인 토큰 길이
|
* @property string $tokenValidUntil 로그인 토큰 길이
|
||||||
|
*
|
||||||
|
* @property int $generalID 장수 번호 (게임 로그인 필요)
|
||||||
|
* @property string $generalName 장수 이름 (게임 로그인 필요)
|
||||||
*/
|
*/
|
||||||
class Session
|
class Session
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user