국호변경, 국기변경, string neutralize

This commit is contained in:
2020-05-05 03:44:00 +09:00
parent 76b8f8743d
commit 42b59f0471
16 changed files with 470 additions and 106 deletions
@@ -0,0 +1,182 @@
<?php
namespace sammo\Command\Nation;
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
MessageTarget,
Message,
CityConst
};
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL,
getNationStaticInfo,
GetNationColors,
newColor,
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_국기변경 extends Command\NationCommand
{
static protected $actionName = '국기변경';
static public $reqArg = true;
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if (!key_exists('colorType', $this->arg)) {
return false;
}
$colorType = $this->arg['colorType'];
if (!key_exists($colorType, GetNationColors())) {
return false;
}
$this->arg = [
'colorType' => $colorType,
];
return true;
}
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['can_change_flag']);
$this->minConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqNationValue('can_change_flag', '국기색', '>', 0, '더이상 변경이 불가능합니다.')
];
}
protected function initWithArg()
{
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqNationValue('can_change_flag', '국기색', '>', 0, '더이상 변경이 불가능합니다.')
];
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief(): string
{
$color = GetNationColors()[$this->arg['colorType']];
return "【<span style='color:{$color};'>국기</span>】를 변경";
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$colorType = $this->arg['colorType'];
$color = GetNationColors()[$colorType];
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$josaYi = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
$db->update('nation', [
'color'=>$color,
'can_change_flag' => $db->sqleval('can_change_flag - 1'),
], 'nation=%i', $nationID);
$logger->pushGeneralActionLog("<span style='color:{$color};'><b>국기</b></span>를 변경하였습니다 <1>$date</>");
$logger->pushGeneralHistoryLog("<span style='color:{$color};'><b>국기</b></span>를 변경");
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <span style='color:{$color};'><b>국기</b></span>를 변경하였습니다");
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <span style='color:{$color};'><b>국기</b></span>를 변경하였습니다");
$logger->pushGlobalHistoryLog("<S><b>【국기변경】</b></><D><b>{$nationName}</b></>{$josaYiNation} <span style='color:{$color};'><b>국기</b></span>를 변경하였습니다.");
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/colorSelect.js'
];
}
public function getForm(): string
{
ob_start();
?>
국기를 변경합니다. 단 1회 가능합니다.<br>
색상 : <select class='formInput' name='colorType' id='colorType' size='1'>
<?php foreach (GetNationColors() as $idx => $color) :
/*
if($colorUsed[$color] > 0){
continue;
}
*/
?>
<option value="<?= $idx ?>" style='background-color:<?= $color ?>;color:<?= newColor($color) ?>;'>국가명(<?=$color?>)</option>
<?php endforeach; ?> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<br>
<?php
return ob_get_clean();
}
}
@@ -0,0 +1,188 @@
<?php
namespace sammo\Command\Nation;
use\sammo\{
DB,
Util,
Json,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
MessageTarget,
Message,
CityConst
};
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL,
getNationStaticInfo,
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_국호변경 extends Command\NationCommand
{
static protected $actionName = '국호변경';
static public $reqArg = true;
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if (!key_exists('nationName', $this->arg)) {
return false;
}
$nationName = $this->arg['nationName'];
if (!is_string($nationName)) {
return false;
}
if (mb_strwidth($nationName) > 18 || $nationName == '') {
return false;
}
$this->arg = [
'nationName' => $nationName,
];
return true;
}
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['aux']);
$actionName = $this->getName();
$this->minConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqNationAuxValue("can_{$actionName}", 0, '>', 0, '더이상 변경이 불가능합니다.')
];
}
protected function initWithArg()
{
$actionName = $this->getName();
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqNationAuxValue("can_{$actionName}", 0, '>', 0, '더이상 변경이 불가능합니다.')
];
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief(): string
{
$newNationName = $this->arg['nationName'];
$josaRo = JosaUtil::pick($newNationName, '로');
return "국호를 【{$newNationName}{$josaRo} 변경";
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$actionName = $this->getName();
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$newNationName = $this->arg['nationName'];
if($db->queryFirstField('SELECT name FROM nation WHERE name = %s LIMIT 1', $newNationName)){
$text = "이미 같은 국호를 가진 곳이 있습니다. {$actionName} 실패 <1>{$date}</>";
$general->getLogger()->pushGeneralActionLog($text);
return false;
}
$josaRo = JosaUtil::pick($newNationName, '로');
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$josaYi = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
$aux = Json::decode($this->nation['aux']);
$aux["can_{$actionName}"] = 0;
$db->update('nation', [
'name'=>$newNationName,
'aux'=>Json::encode($aux)
], 'nation=%i', $nationID);
$logger->pushGeneralActionLog("국호를 <D><b>{$newNationName}</b></>{$josaRo} 변경합니다. <1>$date</>");
$logger->pushGeneralHistoryLog("국호를 <D><b>{$newNationName}</b></>{$josaRo} 변경");
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} 국호를 <D><b>{$newNationName}</b></>{$josaRo} 변경");
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} 국호를 <D><b>{$newNationName}</b></>{$josaRo} 변경합니다.");
$logger->pushGlobalHistoryLog("<S><b>【국호변경】</b></><D><b>{$nationName}</b></>{$josaYiNation} 국호를 <D><b>{$newNationName}</b></>{$josaRo} 변경합니다.");
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/colorSelect.js'
];
}
public function getForm(): string
{
ob_start();
?>
나라의 이름을 바꿉니다. 황제가 된 후 1회 가능합니다.<br>
국명 : <input type='text' class='formInput' name="nationName" id="nationName" size='18' maxlength='18' style='color:white;background-color:black;'> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<br>
<?php
return ob_get_clean();
}
}
+2 -2
View File
@@ -252,8 +252,8 @@ class ConstraintHelper{
return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal, $errMsg]];
}
static function ReqNationAuxValue($key, string $keyNick, string $comp, $reqVal, ?string $errMsg=null):array{
return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal, $errMsg]];
static function ReqNationAuxValue($key, $defaultValue, string $comp, $reqVal, string $errMsg):array{
return [__FUNCTION__, [$key, $defaultValue, $comp, $reqVal, $errMsg]];
}
static function ReqTroopMembers():array{
+63 -89
View File
@@ -9,157 +9,131 @@ use \sammo\Json;
/**
* 범용으로 사용 가능한 국가 Aux 변수 검사도구
*/
class ReqNationAuxValue extends Constraint{
const REQ_VALUES = Constraint::REQ_NATION|Constraint::REQ_ARRAY_ARG;
class ReqNationAuxValue extends Constraint
{
const REQ_VALUES = Constraint::REQ_NATION | Constraint::REQ_ARRAY_ARG;
protected $key;
protected $maxKey;
protected $keyNick;
protected $defaultValue;
protected $reqVal;
protected $comp;
protected $errMsg;
protected $auxVal;
public function checkInputValues(bool $throwExeception=true):bool{
if(!parent::checkInputValues($throwExeception) && !$throwExeception){
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 (count($this->arg) == 5) {
[$this->key, $this->defaultValue, $comp, $this->reqVal, $this->errMsg] = $this->arg;
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){
if(!$throwExeception){return false; }
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]");
} else {
if (!$throwExeception) {
return false;
}
throw new \InvalidArgumentException("require key, defaultValue, comp, reqVal, errMsg");
}
$this->comp = $comp;
$this->maxKey = $this->key.'_max';
if(!key_exists('aux', $this->nation)){
if(!$throwExeception){return false; }
$this->maxKey = $this->key . '_max';
if (!key_exists('aux', $this->nation)) {
if (!$throwExeception) {
return false;
}
throw new \InvalidArgumentException("require aux in nation");
}
if($this->nation['aux'] === null){
if(!$throwExeception){return false; }
if ($this->nation['aux'] === null) {
if (!$throwExeception) {
return false;
}
throw new \InvalidArgumentException("invalid aux in nation(null)");
}
if(is_array($this->nation['aux'])){
if (is_array($this->nation['aux'])) {
$this->auxVal = $this->nation['aux'];
}
else if(is_string($this->nation['aux'])){
} else if (is_string($this->nation['aux'])) {
$this->auxVal = Json::decode($this->nation['aux']);
}
else{
if(!$throwExeception){return false; }
} else {
if (!$throwExeception) {
return false;
}
throw new \InvalidArgumentException("inavlid aux in nation(type)");
}
if(!key_exists($this->key, $this->auxVal)){
if(!$throwExeception){return false; }
if (!key_exists($this->key, $this->auxVal) && $this->defaultValue === null) {
if (!$throwExeception) {
return false;
}
throw new \InvalidArgumentException("require {$this->key} in nation['aux']");
}
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 (!is_string($this->errMsg)) {
if (!$throwExeception) {
return false;
}
if(!key_exists($this->maxKey, $this->auxVal)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require {$this->maxKey} in nation['aux']");
}
$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");
throw new \InvalidArgumentException("{$this->errMsg} must be string");
}
return true;
}
public function test():bool{
public function test(): bool
{
$this->checkInputValues();
$this->tested = true;
$keyNick = $this->keyNick;
if ($this->isPercent) {
$reqVal = $this->auxVal[$this->maxKey] * $this->reqVal;
}
else{
$reqVal = $this->reqVal;
}
$compList = [
'<'=>function($target, $src){
return ($target < $src)?true:'너무 많습니다.';
return ($target < $src);
},
'<='=>function($target, $src){
return ($target <= $src)?true:'너무 많습니다.';
return ($target <= $src);
},
'=='=>function($target, $src)use($keyNick){
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
'=='=>function($target, $src){
return ($target == $src);
},
'!='=>function($target, $src)use($keyNick){
return ($target != $src)?true:"올바르지 않은 {$keyNick} 입니다.";
'!='=>function($target, $src){
return ($target != $src);
},
'==='=>function($target, $src)use($keyNick){
return ($target === $src)?true:"올바르지 않은 {$keyNick} 입니다.";
'==='=>function($target, $src){
return ($target === $src);
},
'!=='=>function($target, $src)use($keyNick){
return ($target !== $src)?true:"올바르지 않은 {$keyNick} 입니다.";
'!=='=>function($target, $src){
return ($target !== $src);
},
'>='=>function($target, $src){
if($target >= $src){
return true;
}
if($src == 1){
return '없습니다';
}
return '부족합니다.';
return ($target >= $src);
},
'>'=>function($target, $src){
if($target > $src){
return true;
}
if($src == 0){
return '없습니다';
}
return '부족합니다.';
return ($target > $src);
},
];
$comp = $compList[$this->comp];
$result = ($comp)($this->auxVal[$this->key], $reqVal);
$result = ($comp)($this->auxVal[$this->key]??$this->defaultValue, $this->reqVal);
if ($result === true) {
return true;
}
if($result === true){
return true;
}
if($this->errMsg){
$this->reason = $this->errMsg;
}
else{
$josaYi = JosaUtil::pick($keyNick, '이');
$this->reason = "{$keyNick}{$josaYi} {$result}";
}
$this->reason = $this->errMsg;
return false;
}
}
}
+1 -1
View File
@@ -329,7 +329,7 @@ class GameConstBase
],
'기타'=>[
'che_국기변경',
//'che_국호변경',
'che_국호변경',
]
];
public static $retirementYear = 80;