건국 조건 설정
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
|
||||
class BeOpeningPart extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_INT_ARG;
|
||||
|
||||
protected $relYear;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->relYear = $this->arg;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
if($relYear < GameConst::$openingPartYear){
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->reason = "초반이 지났습니다.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
use \sammo\DB;
|
||||
|
||||
class CheckNationNameDuplicate extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_NATION|Constraint::REQ_STRING_ARG;
|
||||
|
||||
protected $relYear;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!key_exists('nation', $this->nation)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require nation in nation");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$exists = $db->queryFirstField('SELECT count(*) FROM nation WHERE name = %s AND nation != %i', $this->arg, $this->nation['nation']);
|
||||
|
||||
if($exists == 0){
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->reason = '존재하는 국가명입니다.';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
|
||||
class ConstructableCity extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_CITY;
|
||||
|
||||
protected $relYear;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!key_exists('nation', $this->city)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require nation in city");
|
||||
}
|
||||
|
||||
if(!key_exists('level', $this->city)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require nation in city");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
$city = $this->city();
|
||||
|
||||
if($city['nation'] != 0){
|
||||
$this->reason = '공백지가 아닙니다.';
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!in_array($city['level'], [5, 6])){
|
||||
$this->reason = '중, 소 도시에만 가능합니다.';
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
|
||||
class WanderingNation extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_NATION;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!key_exists('level', $this->nation)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require level in nation");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
if($this->nation['level'] == 0){
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->reason = "방랑군이어야 합니다";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user