선전포고 추가, DisallowDiplomacyStatus 구현 변경

This commit is contained in:
2018-11-22 02:13:23 +09:00
parent 58eb6d4210
commit 36093eccaf
8 changed files with 271 additions and 27 deletions
+6 -2
View File
@@ -64,8 +64,12 @@ class ConstraintHelper{
return [__FUNCTION__];
}
static function DisallowDiplomacyStatus(array $disallowStatus, string $failMessage):array{
return [__FUNCTION__, $disallowStatus, $failMessage];
static function DisallowDiplomacyBetweenStatus(array $disallowList):array{
return [__FUNCTION__, $disallowList];
}
static function DisallowDiplomacyStatus(int $nationID, array $disallowList):array{
return [__FUNCTION__, $nationID, $disallowList];
}
static function ExistsAllowJoinNation(int $relYear, array $excludeNationList):array{
@@ -0,0 +1,55 @@
<?php
namespace sammo\Constraint;
use \sammo\JosaUtil;
use \sammo\DB;
class DisallowDiplomacyBetweenStatus extends Constraint{
const REQ_VALUES = Constraint::REQ_ARRAY_ARG|Constraint::REQ_NATION|Constraint::REQ_DEST_NATION;
protected $nationID;
protected $destNationID;
protected $disallowStatus = [];
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
$this->nationID = $this->nation['nation'];
$this->destNationID = $this->destNation['nation'];
$this->disallowStatus = $this->arg;
foreach($this->disallowStatus as $dipCode => $errMsg){
if(!is_int($dipCode)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("dipCode $dipCode must be int");
}
if(!is_string($errMsg)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("dipCode $errMsg must be string");
}
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
$db = DB::db();
$state = $db->queryFirstField(
'SELECT state FROM diplomacy WHERE me = %i AND you = %i AND `state` IN %li LIMIT 1',
$this->nationID,
$this->destNationID,
array_keys($this->disallowStatus)
);
if($state === null){
return true;
}
$this->msg = $this->disallowStatus[$state];
return false;
}
}
@@ -4,11 +4,11 @@ namespace sammo\Constraint;
use \sammo\JosaUtil;
use \sammo\DB;
class NotDiplomacyStatus extends Constraint{
const REQ_VALUES = Constraint::REQ_ARG|Constraint::REQ_NATION;
class DisallowDiplomacyStatus extends Constraint{
const REQ_VALUES = Constraint::REQ_ARRAY_ARG;
protected $disallowStatus;
protected $msg;
protected $nationID;
protected $disallowStatus = [];
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
@@ -17,28 +17,30 @@ class NotDiplomacyStatus extends Constraint{
if(count($this->arg) != 2){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require disallowDipStatusArray, message in args");
throw new \InvalidArgumentException("require nationID, disallowStatus pair");
}
if(!is_array($this->arg[0])){
[$this->nationID, $this->disallowStatus] = $this->arg;
if(!is_int($this->nationID)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("disallowDipStatusArray must be array");
throw new \InvalidArgumentException("nationID {$this->nationID} must be int");
}
if(!is_string($this->arg[1])){
if(!is_array($this->disallowStatus)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("message must be string");
throw new \InvalidArgumentException("disallowStatus {$this->disallowStatus} must be array");
}
$this->disallowStatus = [];
foreach($this->arg[0] as $status){
if(!is_int($status)){
foreach($this->disallowStatus as $dipCode => $errMsg){
if(!is_int($dipCode)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("{$status} must be int");
throw new \InvalidArgumentException("dipCode $dipCode must be int");
}
if(!is_string($errMsg)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("dipCode $errMsg must be string");
}
$this->disallowStatus[] = $status;
}
$this->msg = $this->arg[1];
return true;
}
@@ -49,15 +51,15 @@ class NotDiplomacyStatus extends Constraint{
$db = DB::db();
$disallowCnt = $db->queryFirstField(
'SELECT count(*) FROM diplomacy WHERE me = %i AND `state` IN %li',
$this->nation['nation'],
$this->disallowStatus
$state = $db->queryFirstField(
'SELECT state FROM diplomacy WHERE me = %i AND `state` IN %li LIMIT 1',
$this->nationID,
array_keys($this->disallowStatus)
);
if($disallowCnt == 0){
if($state === null){
return true;
}
$this->msg = "민심이 낮아 주민들이 도망갑니다.";
$this->msg = $this->disallowStatus[$state];
return false;
}
}
+1 -1
View File
@@ -21,7 +21,7 @@ class ExistsDestNation extends Constraint{
return true;
}
$this->reason = "없는 국가입니다.";
$this->reason = "멸망한 국가입니다.";
return false;
}
}