등용 수락 변경, Aux 처리 추가

nations->aux.joinedNations
dummyGeneral에 exp,ded 추가
scheme에서 nations 제거
This commit is contained in:
2020-03-13 01:44:18 +09:00
parent 3d6b99c004
commit cb246e859e
20 changed files with 560 additions and 247 deletions
+11 -6
View File
@@ -14,6 +14,16 @@ class AllowJoinDestNation extends Constraint{
return false;
}
if(!key_exists('auxVar', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require auxVar in general");
}
if(!key_exists('joinedNations', $this->general['auxVar'])){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require joinedNations in general['auxVar']");
}
if(!key_exists('scout', $this->destNation)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require scout in nation");
@@ -24,11 +34,6 @@ class AllowJoinDestNation extends Constraint{
throw new \InvalidArgumentException("require gennum in nation");
}
if(!key_exists('nations', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require nations in nation");
}
$this->relYear = $this->arg;
return true;
@@ -50,7 +55,7 @@ class AllowJoinDestNation extends Constraint{
return false;
}
$joinedNations = \sammo\Json::decode($this->general['nations']);
$joinedNations = $this->general['auxVar']['joinedNations'];
if(in_array($this->destNation['nation'], $joinedNations)){
$this->reason = "이미 임관했었던 국가입니다.";
return false;
+10 -2
View File
@@ -68,6 +68,10 @@ class ConstraintHelper{
return [__FUNCTION__];
}
static function DifferentDestNation():array{
return [__FUNCTION__];
}
static function DisallowDiplomacyBetweenStatus(array $disallowList):array{
return [__FUNCTION__, $disallowList];
}
@@ -176,6 +180,10 @@ class ConstraintHelper{
return [__FUNCTION__, $npcType];
}
static function ReqDestNationValue($key, string $keyNick, string $comp, $reqVal, ?string $errMsg=null):array{
return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal, $errMsg]];
}
static function ReqEnvValue($key, string $comp, $reqVal, string $failMessage):array{
return [__FUNCTION__, [$key, $comp, $reqVal, $failMessage]];
}
@@ -204,8 +212,8 @@ class ConstraintHelper{
return [__FUNCTION__, $maxTrain];
}
static function ReqGeneralValue($key, string $keyNick, string $comp, $reqVal):array{
return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal]];
static function ReqGeneralValue($key, string $keyNick, string $comp, $reqVal, ?string $errMsg=null):array{
return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal, $errMsg]];
}
static function ReqNationGold(int $reqGold):array{
@@ -0,0 +1,32 @@
<?php
namespace sammo\Constraint;
class DifferentDestNation extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_DEST_NATION;
public function checkInputValues(bool $throwExeception=true):bool{
if(!parent::checkInputValues($throwExeception) && !$throwExeception){
return false;
}
if(!key_exists('nation', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require nation in general");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
if($this->destNation['nation'] != $this->general['nation']){
return true;
}
$this->reason = "이미 같은 국가입니다.";
return false;
}
}
@@ -3,6 +3,7 @@
namespace sammo\Constraint;
use \sammo\DB;
use \sammo\GameConst;
use \sammo\Json;
class AllowJoinDestNation extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_ARRAY_ARG;
@@ -14,9 +15,14 @@ class AllowJoinDestNation extends Constraint{
return false;
}
if(!key_exists('nations', $this->general)){
if(!key_exists('auxVar', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require nations in nation");
throw new \InvalidArgumentException("require auxVar in general");
}
if(!key_exists('joinedNations', $this->general['auxVar'])){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require joinedNations in general['auxVar']");
}
if(!is_int($this->arg[0])){
@@ -41,7 +47,7 @@ class AllowJoinDestNation extends Constraint{
$db = DB::db();
$relYear = $this->arg[0];
$notIn = array_merge(Json::decode($this->general['nations']), $this->arg[1]);
$notIn = array_merge($this->general['auxVar']['joinedNations'], $this->arg[1]);
//이걸 호출하는 경우 분명 동일한 쿼리를 한번 더 부를 것. 쿼리 캐시를 기대함
$nations = $db->queryFirstColumn(
'SELECT nation, name, gennum, scout FROM nation WHERE scout=0 AND gennum < %i AND no NOT IN %li',
+139
View File
@@ -0,0 +1,139 @@
<?php
namespace sammo\Constraint;
use \sammo\JosaUtil;
use \sammo\Util;
/**
* 범용으로 사용 가능한 국가 변수 검사도구
*/
class ReqDestNationValue extends Constraint{
const REQ_VALUES = Constraint::REQ_DEST_NATION|Constraint::REQ_ARRAY_ARG;
protected $key;
protected $maxKey;
protected $keyNick;
protected $reqVal;
protected $comp;
protected $errMsg;
public function checkInputValues(bool $throwExeception=true):bool{
if(!parent::checkInputValues($throwExeception) && !$throwExeception){
return false;
}
if(count($this->arg) == 5){
[$this->key, $this->keyNick, $comp, $this->reqVal, $this->errMsg] = $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[, errMsg]");
}
$this->comp = $comp;
$this->maxKey = $this->key.'2';
if(!key_exists($this->key, $this->destNation)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require {$this->key} in destNation");
}
if(is_numeric($this->reqVal)){
$this->isPercent = false;
}
else if(is_string($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->destNation)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require {$this->maxKey} in destNation");
}
$this->isPercent = true;
}
if($this->errMsg!==null && !is_string($this->errMsg)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("{$this->errMsg} must be string or null");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
$keyNick = $this->keyNick;
if ($this->isPercent) {
$reqVal = $this->destNation[$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($target, $src)use($keyNick){
return ($target != $src)?true:"올바르지 않은 {$keyNick} 입니다.";
},
'==='=>function($target, $src)use($keyNick){
return ($target === $src)?true:"올바르지 않은 {$keyNick} 입니다.";
},
'!=='=>function($target, $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->destNation[$this->key], $reqVal);
if($result === true){
return true;
}
if($this->errMsg){
$this->reason = $this->errMsg;
}
else{
$josaYi = JosaUtil::pick($keyNick, '이');
$this->reason = "{$keyNick}{$josaYi} {$result}";
}
return false;
}
}
+17 -6
View File
@@ -16,14 +16,15 @@ class ReqGeneralValue extends Constraint{
protected $keyNick;
protected $reqVal;
protected $comp;
protected $errMsg;
public function checkInputValues(bool $throwExeception=true):bool{
if(!parent::checkInputValues($throwExeception) && !$throwExeception){
return false;
}
if(count($this->arg) == 4){
[$this->key, $this->keyNick, $comp, $this->reqVal] = $this->arg;
if(count($this->arg) == 5){
[$this->key, $this->keyNick, $comp, $this->reqVal, $this->errMsg] = $this->arg;
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){
if(!$throwExeception){return false; }
@@ -32,7 +33,7 @@ class ReqGeneralValue extends Constraint{
}
else{
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require key, keyNick, comp, reqVal");
throw new \InvalidArgumentException("require key, keyNick, comp, reqVal[, errMsg]");
}
$this->comp = $comp;
@@ -47,7 +48,7 @@ class ReqGeneralValue extends Constraint{
if(is_numeric($this->reqVal)){
$this->isPercent = false;
}
else if(is_str($this->reqVal)){
else if(is_string($this->reqVal)){
$this->reqVal = Util::convPercentStrToFloat($this->reqVal);
if($this->reqVal === null){
if(!$throwExeception){return false; }
@@ -61,6 +62,11 @@ class ReqGeneralValue extends Constraint{
$this->isPercent = true;
}
if($this->errMsg!==null && !is_string($this->errMsg)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("{$this->errMsg} must be string or null");
}
return true;
}
@@ -120,8 +126,13 @@ class ReqGeneralValue extends Constraint{
return true;
}
$josaYi = JosaUtil::pick($keyNick, '이');
$this->reason = "{$keyNick}{$josaYi} {$result}";
if($this->errMsg){
$this->reason = $this->errMsg;
}
else{
$josaYi = JosaUtil::pick($keyNick, '이');
$this->reason = "{$keyNick}{$josaYi} {$result}";
}
return false;
}
+6 -1
View File
@@ -62,6 +62,11 @@ class ReqNationValue extends Constraint{
$this->isPercent = true;
}
if($this->errMsg!==null && !is_string($this->errMsg)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("{$this->errMsg} must be string or null");
}
return true;
}
@@ -121,11 +126,11 @@ class ReqNationValue extends Constraint{
return true;
}
$josaYi = JosaUtil::pick($keyNick, '이');
if($this->errMsg){
$this->reason = $this->errMsg;
}
else{
$josaYi = JosaUtil::pick($keyNick, '이');
$this->reason = "{$keyNick}{$josaYi} {$result}";
}