선전포고 추가, 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
@@ -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;
}
}