인재탐색 추가. gencount, npc_id 관련 수정
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
use \sammo\DB;
|
||||
use \sammo\GameConst;
|
||||
|
||||
class AllowJoinDestNation extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_ARRAY_ARG;
|
||||
|
||||
protected $relYear;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!key_exists('nations', $this->general)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require nations in nation");
|
||||
}
|
||||
|
||||
if(!is_int($this->arg[0])){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("first arg must be int(relYear)");
|
||||
}
|
||||
|
||||
if(!is_array($this->arg[1])){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("first arg must be array(exludeList)");
|
||||
}
|
||||
|
||||
$this->relYear = $this->arg;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$relYear = $this->arg[0];
|
||||
$notIn = array_merge(Json::decode($this->general['nations']), $this->arg[1]);
|
||||
//이걸 호출하는 경우 분명 동일한 쿼리를 한번 더 부를 것. 쿼리 캐시를 기대함
|
||||
$nations = $db->queryFirstColumn(
|
||||
'SELECT nation, name, gennum, scout FROM nation WHERE scout=0 AND gennum < %i AND no NOT IN %li',
|
||||
$relYear<3?GameConst::$initialNationGenLimit:GameConst::$defaultMaxGeneral,
|
||||
$notIn
|
||||
);
|
||||
|
||||
if($nations){
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->reason = "임관할 국가가 없습니다.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ namespace sammo\Constraint;
|
||||
use \sammo\JosaUtil;
|
||||
use \sammo\Util;
|
||||
|
||||
/**
|
||||
* 범용으로 사용 가능한 장수 변수 검사도구
|
||||
*/
|
||||
class RegGeneralValue extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_ARRAY_ARG;
|
||||
|
||||
@@ -18,13 +21,26 @@ class RegGeneralValue extends Constraint{
|
||||
return false;
|
||||
}
|
||||
|
||||
[$this->key, $this->keyNick, $this->reqVal] = $this->arg;
|
||||
if(count($this->arg) == 4){
|
||||
[$this->key, $this->keyNick, $comp, $this->reqVal] = $this->arg;
|
||||
|
||||
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!='])){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("invalid comparator");
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require key, keyNick, comp, reqVal");
|
||||
}
|
||||
|
||||
$this->comp = $comp;
|
||||
|
||||
$this->maxKey = $this->key.'2';
|
||||
|
||||
if(!key_exists($this->key, $this->city)){
|
||||
if(!key_exists($this->key, $this->general)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require {$this->key} in city");
|
||||
throw new \InvalidArgumentException("require {$this->key} in general");
|
||||
}
|
||||
|
||||
if(is_numeric($this->reqVal)){
|
||||
@@ -37,7 +53,7 @@ class RegGeneralValue extends Constraint{
|
||||
throw new \InvalidArgumentException("require valid reqVal(percentStr|numeric) format");
|
||||
}
|
||||
|
||||
if(!key_exists($this->maxKey, $this->city)){
|
||||
if(!key_exists($this->maxKey, $this->general)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require {$this->maxKey} in general");
|
||||
}
|
||||
@@ -51,26 +67,53 @@ class RegGeneralValue extends Constraint{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
if($this->isPercent){
|
||||
if($this->general[$this->key] >= $this->general[$this->maxKey] * $this->reqVal){
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->isPercent) {
|
||||
$reqVal = $this->general[$this->maxKey] * $this->reqVal;
|
||||
}
|
||||
else{
|
||||
if($this->general[$this->key] >= $this->reqVal){
|
||||
return true;
|
||||
}
|
||||
$reqVal = $this->reqVal;
|
||||
}
|
||||
|
||||
if($this->reqVal === 1){
|
||||
$josaYi = JosaUtil::pick($keyNick, '이');
|
||||
$this->reason = "{$keyNick}{$josaUn} 없습니다.";
|
||||
}
|
||||
else{
|
||||
$josaYi = JosaUtil::pick($keyNick, '이');
|
||||
$this->reason = "{$keyNick}{$josaUn} 부족합니다.";
|
||||
$compList = [
|
||||
'<'=>function($target, $src){
|
||||
return ($target < $src)?true:'너무 많습니다.';
|
||||
},
|
||||
'<='=>function($target, $src){
|
||||
return ($target <= $src)?true:'너무 많습니다.';
|
||||
},
|
||||
'=='=>function($target, $src)use($keyNick){
|
||||
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||
},
|
||||
'!='=>function($targeta, $src)use($keyNick){
|
||||
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||
},
|
||||
'>='=>function($target, $src){
|
||||
if($target >= $src){
|
||||
return true;
|
||||
}
|
||||
if($src == 1){
|
||||
return '없습니다';
|
||||
}
|
||||
return '부족합니다.';
|
||||
},
|
||||
'>'=>function($target, $src){
|
||||
return $target >= $src;
|
||||
if($src == 0){
|
||||
return '없습니다';
|
||||
}
|
||||
return '부족합니다.';
|
||||
},
|
||||
];
|
||||
|
||||
$comp = $compList[$this->comp];
|
||||
$result = ($comp)($this->general[$this->key], $reqVal);
|
||||
|
||||
if($result === true){
|
||||
return true;
|
||||
}
|
||||
|
||||
$josaYi = JosaUtil::pick($keyNick, '이');
|
||||
$this->reason = "{$keyNick}{$josaYi} {$result}";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Constraint;
|
||||
|
||||
use \sammo\JosaUtil;
|
||||
use \sammo\Util;
|
||||
|
||||
/**
|
||||
* 범용으로 사용 가능한 국가 변수 검사도구
|
||||
*/
|
||||
class RegGeneralValue extends Constraint{
|
||||
const REQ_VALUES = Constraint::REQ_NATION|Constraint::REQ_ARRAY_ARG;
|
||||
|
||||
protected $key;
|
||||
protected $maxKey;
|
||||
protected $keyNick;
|
||||
protected $reqVal;
|
||||
|
||||
public function checkInputValues(bool $throwExeception=true){
|
||||
if(!parent::checkInputValues($throwExeception) && !$throwException){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(count($this->arg) == 4){
|
||||
[$this->key, $this->keyNick, $this->reqVal, $comp] = $this->arg;
|
||||
|
||||
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!='])){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("invalid comparator");
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require key, keyNick, comp, reqVal");
|
||||
}
|
||||
|
||||
$this->comp = $comp;
|
||||
|
||||
$this->maxKey = $this->key.'2';
|
||||
|
||||
if(!key_exists($this->key, $this->nation)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require {$this->key} in nation");
|
||||
}
|
||||
|
||||
if(is_numeric($this->reqVal)){
|
||||
$this->isPercent = false;
|
||||
}
|
||||
else if(is_str($this->reqVal)){
|
||||
$this->reqVal = Util::convPercentStrToFloat($this->reqVal);
|
||||
if($this->reqVal === null){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require valid reqVal(percentStr|numeric) format");
|
||||
}
|
||||
|
||||
if(!key_exists($this->maxKey, $this->nation)){
|
||||
if(!$throwExeception){return false; }
|
||||
throw new \InvalidArgumentException("require {$this->maxKey} in nation");
|
||||
}
|
||||
$this->isPercent = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function test():bool{
|
||||
$this->checkInputValues();
|
||||
$this->tested = true;
|
||||
|
||||
if ($this->isPercent) {
|
||||
$reqVal = $this->nation[$this->maxKey] * $this->reqVal;
|
||||
}
|
||||
else{
|
||||
$reqVal = $this->reqVal;
|
||||
}
|
||||
|
||||
$compList = [
|
||||
'<'=>function($target, $src){
|
||||
return ($target < $src)?true:'너무 많습니다.';
|
||||
},
|
||||
'<='=>function($target, $src){
|
||||
return ($target <= $src)?true:'너무 많습니다.';
|
||||
},
|
||||
'=='=>function($target, $src)use($keyNick){
|
||||
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||
},
|
||||
'!='=>function($targeta, $src)use($keyNick){
|
||||
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||
},
|
||||
'>='=>function($target, $src){
|
||||
if($target >= $src){
|
||||
return true;
|
||||
}
|
||||
if($src == 1){
|
||||
return '없습니다';
|
||||
}
|
||||
return '부족합니다.';
|
||||
},
|
||||
'>'=>function($target, $src){
|
||||
return $target >= $src;
|
||||
if($src == 0){
|
||||
return '없습니다';
|
||||
}
|
||||
return '부족합니다.';
|
||||
},
|
||||
];
|
||||
|
||||
$comp = $compList[$this->comp];
|
||||
$result = ($comp)($this->nation[$this->key], $reqVal);
|
||||
|
||||
if($result === true){
|
||||
return true;
|
||||
}
|
||||
|
||||
$josaYi = JosaUtil::pick($keyNick, '이');
|
||||
$this->reason = "{$keyNick}{$josaYi} {$result}";
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user