diff --git a/hwe/j_set_general_command.php b/hwe/j_set_general_command.php index 9c9a4ed6..52dbcc90 100644 --- a/hwe/j_set_general_command.php +++ b/hwe/j_set_general_command.php @@ -20,11 +20,11 @@ if(!$action){ $defaultCheck = [ 'string'=>[ - 'nationName', 'optionText', 'itemType' + 'nationName', 'optionText', 'itemType', 'nationType' ], 'integer'=>[ 'crewType', 'destGeneralID', 'destCityID', 'destNationID', - 'amount', 'colorType', 'nationType', 'itemCode' + 'amount', 'colorType', 'itemCode' ], 'boolean'=>[ 'isGold', 'buyRice', @@ -37,6 +37,9 @@ $defaultCheck = [ ], 'integerArray'=>[ 'destNationIDList', 'destGeneralIDList' + ], + 'lengthBetween'=>[ + ['nationName', 1, 9] ] ]; diff --git a/hwe/sammo/Command/General/che_건국.php b/hwe/sammo/Command/General/che_건국.php new file mode 100644 index 00000000..6d453103 --- /dev/null +++ b/hwe/sammo/Command/General/che_건국.php @@ -0,0 +1,147 @@ +arg['nationName']??null; + $nationType = $this->arg['nationType']??null; + $colorType = $this->arg['colotType']??null; + + if($nationName === null || $nationType === null || $colorType === null){ + return false; + } + + if(!is_string($nationName) || !is_string($nationType) || !is_int($colorType)){ + return false; + } + + return true; + } + + protected function init(){ + + $general = $this->generalObj; + $env = $this->env; + + $this->setCity(); + $this->setNation(); + + $destGeneralID = $this->arg['destGeneralID']??null; + $destNationID = $this->arg['destNationID']??null; + if($destGeneralID !== null){ + $this->setDestGeneral($destGeneralID); + $this->setDestNation($this->destGeneralObj->getVar('nation')); + } + else{ + $this->setDestNation($destNationID, ['gennum', 'scout']); + } + + $relYear = $env['year'] - $env['startyear']; + + $this->runnableConstraints=[ + ['BeNeutral'], + ['ExistsDestNation'], + ['AllowJoinDestNation', $relYear], + ['AllowJoinAction'] + ]; + } + + public function getCost():array{ + return [0, 0]; + } + + public function getPreReqTurn():int{ + return 0; + } + + public function getPostReqTurn():int{ + return 0; + } + + public function run():bool{ + if(!$this->isRunnable()){ + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + $env = $this->env; + + $general = $this->generalObj; + $date = substr($general->getVar('turntime'),11,5); + $generalName = $general->getName(); + $josaYi = JosaUtil::pick($generalName, '이'); + + $destNation = $this->destNation; + $gennum = $destNation['gennum']; + $destNationID = $destNation['nation']; + $destNationName = $destNation['name']; + + $logger = $general->getLogger(); + + $logger->pushGeneralActionLog("{$destNationName}에 임관했습니다. <1>$date"); + $logger->pushGeneralHistoryLog("{$destNationName}에 임관"); + $logger->pushGlobalActionLog("{$generalName}{$josaYi} {$destNationName}임관했습니다."); + + if($gennum < GameConst::$initialNationGenLimit) { + $exp = 700; + } + else { + $exp = 100; + } + + $exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp); + $general->setVar('nation', $destNationID); + $general->setVar('level', 1); + $general->setVar('belong', 1); + + if($this->destGeneralObj !== null){ + $general->setVar('city', $this->destGeneralObj->getCityID()); + } + else{ + $targetCityID = $db->queryFirstField('SELECT city FROM nation WHERE nation = %i AND level=12', $destNationID); + $general->setVar('city', $targetCityID); + } + + $db->update('nation', [ + 'gennum'=>$db->sqleval('gennum + 1') + ], 'nation=%i', $destNationID); + + $relYear = $env['year'] - $env['startyear']; + if($general->getVar('npc') == 1 || $relYear >= 3){ + $joinedNations = Join::decode($general->getVar('nations')); + $joinedNations[] = $destNationID; + $general->setVar('nations', Join::encode($joinedNations)); + } + + $general->increaseVar('experience', $exp); + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->checkStatChange(); + tryUniqueItemLottery($general); + $general->applyDB($db); + + return true; + } + + +} \ No newline at end of file diff --git a/hwe/sammo/Command/General/che_하야.php b/hwe/sammo/Command/General/che_하야.php index f56d0f12..89726132 100644 --- a/hwe/sammo/Command/General/che_하야.php +++ b/hwe/sammo/Command/General/che_하야.php @@ -20,8 +20,8 @@ use sammo\CityConst; -class che_임관 extends Command\GeneralCommand{ - static protected $actionName = '임관'; +class che_하야 extends Command\GeneralCommand{ + static protected $actionName = '하야'; protected function argTest():bool{ $this->arg = null; @@ -108,7 +108,7 @@ class che_임관 extends Command\GeneralCommand{ $db->update('nation', [ 'gold'=>$db->sqleval('gold + %i', $lostGold), - 'gold'=>$db->sqleval('gold + %i', $lostRice), + 'rice'=>$db->sqleval('rice + %i', $lostRice), 'gennum'=>$db->sqleval('gennum - 1') ], 'nation=%i', $nationID); diff --git a/src/sammo/Validator.php b/src/sammo/Validator.php index 24b9d1f4..dcd7fb74 100644 --- a/src/sammo/Validator.php +++ b/src/sammo/Validator.php @@ -53,4 +53,49 @@ class Validator extends \Valitron\Validator } return true; } + + /** + * 문자열의 '최대 너비'를 확인함. mb_strwidth 기반 + * + * @param string $field + * @param mixed $value + * @return bool + */ + protected function validateStringWidthMax($field, $value, $params){ + if(!is_string($value)){ + return false; + } + $width = mb_strwidth($value); + return $width <= $params[0]; + } + + /** + * 문자열의 '최소 너비'를 확인함. mb_strwidth 기반 + * + * @param string $field + * @param mixed $value + * @return bool + */ + protected function validateStringWidthMin($field, $value, $params){ + if(!is_string($value)){ + return false; + } + $width = mb_strwidth($value); + return $width >= $params[0]; + } + + /** + * 문자열의 '너비'를 확인함. mb_strwidth 기반 + * + * @param string $field + * @param mixed $value + * @return bool + */ + protected function validateStringWidthBetween($field, $value, $params){ + if(!is_string($value)){ + return false; + } + $width = mb_strwidth($value); + return $params[0] <= $width && $width <= $params[1]; + } }