명령 입력턴에 select2 적용
This commit is contained in:
@@ -1,287 +1,287 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use\sammo\{
|
||||
DB,
|
||||
Util,
|
||||
JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
GameUnitConst,
|
||||
LastTurn,
|
||||
Command,
|
||||
Json
|
||||
};
|
||||
|
||||
|
||||
use function\sammo\{
|
||||
tryUniqueItemLottery,
|
||||
getAllNationStaticInfo
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
use function sammo\buildNationTypeClass;
|
||||
use function sammo\refreshNationStaticInfo;
|
||||
use function sammo\GetNationColors;
|
||||
use function sammo\newColor;
|
||||
|
||||
|
||||
class che_건국 extends Command\GeneralCommand
|
||||
{
|
||||
static protected $actionName = '건국';
|
||||
static public $reqArg = true;
|
||||
|
||||
protected function argTest(): bool
|
||||
{
|
||||
if ($this->arg === null) {
|
||||
return false;
|
||||
}
|
||||
$nationName = $this->arg['nationName'] ?? null;
|
||||
$nationType = $this->arg['nationType'] ?? null;
|
||||
$colorType = $this->arg['colorType'] ?? null;
|
||||
|
||||
if ($nationName === null || $nationType === null || $colorType === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_string($nationName) || !is_string($nationType) || !is_int($colorType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mb_strwidth($nationName) > 18 || $nationName == '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!key_exists($colorType, GetNationColors())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$nationTypeClass = buildNationTypeClass($nationType);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->arg = [
|
||||
'nationName' => $nationName,
|
||||
'nationType' => $nationType,
|
||||
'colorType' => $colorType
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$env = $this->env;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation(['gennum', 'aux']);
|
||||
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
|
||||
$this->minConditionConstraints = [
|
||||
ConstraintHelper::BeOpeningPart($relYear + 1),
|
||||
ConstraintHelper::ReqNationValue('level', '국가규모', '==', 0, '정식 국가가 아니어야합니다.')
|
||||
];
|
||||
}
|
||||
|
||||
protected function initWithArg()
|
||||
{
|
||||
$env = $this->env;
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
|
||||
$nationName = $this->arg['nationName'];
|
||||
$nationType = $this->arg['nationType'];
|
||||
$colorType = $this->arg['colorType'];
|
||||
|
||||
$this->fullConditionConstraints = [
|
||||
ConstraintHelper::BeLord(),
|
||||
ConstraintHelper::WanderingNation(),
|
||||
ConstraintHelper::ReqNationValue('gennum', '수하 장수', '>=', 2),
|
||||
ConstraintHelper::BeOpeningPart($relYear + 1),
|
||||
ConstraintHelper::CheckNationNameDuplicate($nationName),
|
||||
ConstraintHelper::AllowJoinAction(),
|
||||
ConstraintHelper::ConstructableCity(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getBrief(): string
|
||||
{
|
||||
$nationName = $this->arg['nationName'];
|
||||
$josaUl = JosaUtil::pick($nationName, '을');
|
||||
return "【{$nationName}】{$josaUl} 건국";
|
||||
}
|
||||
|
||||
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->hasFullConditionMet()) {
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$env = $this->env;
|
||||
|
||||
$general = $this->generalObj;
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
$generalName = $general->getName();
|
||||
$josaYi = JosaUtil::pick($generalName, '이');
|
||||
|
||||
$nationName = $this->arg['nationName'];
|
||||
$nationType = $this->arg['nationType'];
|
||||
$colorType = GetNationColors()[$this->arg['colorType']];
|
||||
|
||||
$cityName = $this->city['name'];
|
||||
|
||||
$josaUl = JosaUtil::pick($nationName, '을');
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$nationTypeClass = buildNationTypeClass($nationType);
|
||||
$nationTypeName = $nationTypeClass->getName();
|
||||
|
||||
|
||||
$logger->pushGeneralActionLog("<D><b>{$nationName}</b></>{$josaUl} 건국하였습니다. <1>$date</>");
|
||||
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <G><b>{$cityName}</b></>에 국가를 건설하였습니다.");
|
||||
|
||||
$josaNationYi = JosaUtil::pick($nationName, '이');
|
||||
$logger->pushGlobalHistoryLog("<Y><b>【건국】</b></>{$nationTypeName} <D><b>{$nationName}</b></>{$josaNationYi} 새로이 등장하였습니다.");
|
||||
$logger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>{$josaUl} 건국");
|
||||
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <D><b>{$nationName}</b></>{$josaUl} 건국");
|
||||
|
||||
$exp = 1000;
|
||||
$ded = 1000;
|
||||
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
|
||||
$aux = Json::decode($this->nation['aux'])??[];
|
||||
$aux['can_국기변경'] = 1;
|
||||
|
||||
$db->update('city', [
|
||||
'nation' => $general->getNationID(),
|
||||
'conflict' => '{}'
|
||||
], 'city=%i', $general->getCityID());
|
||||
|
||||
$db->update('nation', [
|
||||
'name' => $nationName,
|
||||
'color' => $colorType,
|
||||
'level' => 1,
|
||||
'type' => $nationType,
|
||||
'capital' => $general->getCityID(),
|
||||
'aux' => Json::encode($aux)
|
||||
], 'nation=%i', $general->getNationID());
|
||||
|
||||
refreshNationStaticInfo();
|
||||
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general, '건국');
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getJSFiles(): array
|
||||
{
|
||||
return [
|
||||
'js/colorSelect.js'
|
||||
];
|
||||
}
|
||||
|
||||
public function getForm(): string
|
||||
{
|
||||
|
||||
if (count(getAllNationStaticInfo()) >= $this->env['maxnation']) {
|
||||
return '더 이상 건국은 불가능합니다.';
|
||||
}
|
||||
|
||||
|
||||
//NOTE: 새로운 방법이 생기기 전까진 아무색이나 선택 가능하도록 하자.
|
||||
/*
|
||||
foreach(GetNationColors() as $color){
|
||||
$colorUsed[$color] = 0;
|
||||
}
|
||||
|
||||
foreach(getAllNationStaticInfo() as $nation){
|
||||
if($nation['level'] <= 0){
|
||||
continue;
|
||||
}
|
||||
$colorUsed[$nation['color']]++;
|
||||
}
|
||||
|
||||
$colorUsedCnt = 0;
|
||||
foreach($colorUsed as $color=>$used){
|
||||
if($used){
|
||||
continue;
|
||||
}
|
||||
$colorUsedCnt += 1;
|
||||
}
|
||||
|
||||
//색깔이 다 쓰였으면 그냥 모두 허용
|
||||
if($colorUsedCnt === count($colorUsed)){
|
||||
foreach(array_keys($colorUsed) as $color){
|
||||
$colorUsed[$color] = 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
현재 도시에서 나라를 세웁니다. 중, 소도시에서만 가능합니다.<br>
|
||||
|
||||
<?php foreach (GameConst::$availableNationType as $nationType) :
|
||||
$nationClass = buildNationTypeClass($nationType);
|
||||
|
||||
[$name, $pros, $cons] = [$nationClass->getName(), $nationClass::$pros, $nationClass::$cons];
|
||||
?>
|
||||
|
||||
- <?= $name ?> : <span style='color:cyan;'><?= $pros ?></span> <span style='color:magenta;'><?= $cons ?></span><br>
|
||||
<?php endforeach; ?>
|
||||
<br>
|
||||
국명 : <input type='text' class='formInput' name="nationName" id="nationName" size='18' maxlength='18' style='color:white;background-color:black;'>
|
||||
색상 : <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; ?>
|
||||
</select>
|
||||
성향 : <select class='formInput' name='nationType' id='nationType' size='1'>
|
||||
|
||||
<?php foreach (GameConst::$availableNationType as $nationType) :
|
||||
$nationTypeName = buildNationTypeClass($nationType)->getName();
|
||||
?>
|
||||
<option value='<?= $nationType ?>' style=background-color:black;color:white;><?= $nationTypeName ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<input type=button id="commonSubmit" value="<?= $this->getName() ?>">
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use\sammo\{
|
||||
DB,
|
||||
Util,
|
||||
JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
GameUnitConst,
|
||||
LastTurn,
|
||||
Command,
|
||||
Json
|
||||
};
|
||||
|
||||
|
||||
use function\sammo\{
|
||||
tryUniqueItemLottery,
|
||||
getAllNationStaticInfo
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
use sammo\CityConst;
|
||||
use function sammo\buildNationTypeClass;
|
||||
use function sammo\refreshNationStaticInfo;
|
||||
use function sammo\GetNationColors;
|
||||
use function sammo\newColor;
|
||||
|
||||
|
||||
class che_건국 extends Command\GeneralCommand
|
||||
{
|
||||
static protected $actionName = '건국';
|
||||
static public $reqArg = true;
|
||||
|
||||
protected function argTest(): bool
|
||||
{
|
||||
if ($this->arg === null) {
|
||||
return false;
|
||||
}
|
||||
$nationName = $this->arg['nationName'] ?? null;
|
||||
$nationType = $this->arg['nationType'] ?? null;
|
||||
$colorType = $this->arg['colorType'] ?? null;
|
||||
|
||||
if ($nationName === null || $nationType === null || $colorType === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_string($nationName) || !is_string($nationType) || !is_int($colorType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mb_strwidth($nationName) > 18 || $nationName == '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!key_exists($colorType, GetNationColors())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$nationTypeClass = buildNationTypeClass($nationType);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->arg = [
|
||||
'nationName' => $nationName,
|
||||
'nationType' => $nationType,
|
||||
'colorType' => $colorType
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$env = $this->env;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation(['gennum', 'aux']);
|
||||
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
|
||||
$this->minConditionConstraints = [
|
||||
ConstraintHelper::BeOpeningPart($relYear + 1),
|
||||
ConstraintHelper::ReqNationValue('level', '국가규모', '==', 0, '정식 국가가 아니어야합니다.')
|
||||
];
|
||||
}
|
||||
|
||||
protected function initWithArg()
|
||||
{
|
||||
$env = $this->env;
|
||||
$relYear = $env['year'] - $env['startyear'];
|
||||
|
||||
$nationName = $this->arg['nationName'];
|
||||
$nationType = $this->arg['nationType'];
|
||||
$colorType = $this->arg['colorType'];
|
||||
|
||||
$this->fullConditionConstraints = [
|
||||
ConstraintHelper::BeLord(),
|
||||
ConstraintHelper::WanderingNation(),
|
||||
ConstraintHelper::ReqNationValue('gennum', '수하 장수', '>=', 2),
|
||||
ConstraintHelper::BeOpeningPart($relYear + 1),
|
||||
ConstraintHelper::CheckNationNameDuplicate($nationName),
|
||||
ConstraintHelper::AllowJoinAction(),
|
||||
ConstraintHelper::ConstructableCity(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getBrief(): string
|
||||
{
|
||||
$nationName = $this->arg['nationName'];
|
||||
$josaUl = JosaUtil::pick($nationName, '을');
|
||||
return "【{$nationName}】{$josaUl} 건국";
|
||||
}
|
||||
|
||||
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->hasFullConditionMet()) {
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$env = $this->env;
|
||||
|
||||
$general = $this->generalObj;
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
$generalName = $general->getName();
|
||||
$josaYi = JosaUtil::pick($generalName, '이');
|
||||
|
||||
$nationName = $this->arg['nationName'];
|
||||
$nationType = $this->arg['nationType'];
|
||||
$colorType = GetNationColors()[$this->arg['colorType']];
|
||||
|
||||
$cityName = $this->city['name'];
|
||||
|
||||
$josaUl = JosaUtil::pick($nationName, '을');
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$nationTypeClass = buildNationTypeClass($nationType);
|
||||
$nationTypeName = $nationTypeClass->getName();
|
||||
|
||||
|
||||
$logger->pushGeneralActionLog("<D><b>{$nationName}</b></>{$josaUl} 건국하였습니다. <1>$date</>");
|
||||
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <G><b>{$cityName}</b></>에 국가를 건설하였습니다.");
|
||||
|
||||
$josaNationYi = JosaUtil::pick($nationName, '이');
|
||||
$logger->pushGlobalHistoryLog("<Y><b>【건국】</b></>{$nationTypeName} <D><b>{$nationName}</b></>{$josaNationYi} 새로이 등장하였습니다.");
|
||||
$logger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>{$josaUl} 건국");
|
||||
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <D><b>{$nationName}</b></>{$josaUl} 건국");
|
||||
|
||||
$exp = 1000;
|
||||
$ded = 1000;
|
||||
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
|
||||
$aux = Json::decode($this->nation['aux'])??[];
|
||||
$aux['can_국기변경'] = 1;
|
||||
|
||||
$db->update('city', [
|
||||
'nation' => $general->getNationID(),
|
||||
'conflict' => '{}'
|
||||
], 'city=%i', $general->getCityID());
|
||||
|
||||
$db->update('nation', [
|
||||
'name' => $nationName,
|
||||
'color' => $colorType,
|
||||
'level' => 1,
|
||||
'type' => $nationType,
|
||||
'capital' => $general->getCityID(),
|
||||
'aux' => Json::encode($aux)
|
||||
], 'nation=%i', $general->getNationID());
|
||||
|
||||
refreshNationStaticInfo();
|
||||
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
tryUniqueItemLottery($general, '건국');
|
||||
$general->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getJSFiles(): array
|
||||
{
|
||||
return [
|
||||
'js/colorSelect.js'
|
||||
];
|
||||
}
|
||||
|
||||
public function getForm(): string
|
||||
{
|
||||
|
||||
if (count(getAllNationStaticInfo()) >= $this->env['maxnation']) {
|
||||
return '더 이상 건국은 불가능합니다.';
|
||||
}
|
||||
|
||||
|
||||
//NOTE: 새로운 방법이 생기기 전까진 아무색이나 선택 가능하도록 하자.
|
||||
/*
|
||||
foreach(GetNationColors() as $color){
|
||||
$colorUsed[$color] = 0;
|
||||
}
|
||||
|
||||
foreach(getAllNationStaticInfo() as $nation){
|
||||
if($nation['level'] <= 0){
|
||||
continue;
|
||||
}
|
||||
$colorUsed[$nation['color']]++;
|
||||
}
|
||||
|
||||
$colorUsedCnt = 0;
|
||||
foreach($colorUsed as $color=>$used){
|
||||
if($used){
|
||||
continue;
|
||||
}
|
||||
$colorUsedCnt += 1;
|
||||
}
|
||||
|
||||
//색깔이 다 쓰였으면 그냥 모두 허용
|
||||
if($colorUsedCnt === count($colorUsed)){
|
||||
foreach(array_keys($colorUsed) as $color){
|
||||
$colorUsed[$color] = 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
현재 도시에서 나라를 세웁니다. 중, 소도시에서만 가능합니다.<br>
|
||||
|
||||
<?php foreach (GameConst::$availableNationType as $nationType) :
|
||||
$nationClass = buildNationTypeClass($nationType);
|
||||
|
||||
[$name, $pros, $cons] = [$nationClass->getName(), $nationClass::$pros, $nationClass::$cons];
|
||||
?>
|
||||
|
||||
- <?= $name ?> : <span style='color:cyan;'><?= $pros ?></span> <span style='color:magenta;'><?= $cons ?></span><br>
|
||||
<?php endforeach; ?>
|
||||
<br>
|
||||
국명 : <input type='text' class='formInput' name="nationName" id="nationName" size='18' maxlength='18' style='color:white;background-color:black;'>
|
||||
색상 : <select class='formInput' name='colorType' id='colorType' size='1'>
|
||||
|
||||
<?php foreach (GetNationColors() as $idx => $color) :
|
||||
/*
|
||||
if($colorUsed[$color] > 0){
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
?>
|
||||
<option value="<?= $idx ?>" data-color="<?= $color ?>" data-font-color="<?=newColor($color)?>" style='background-color:<?= $color ?>;color:<?= newColor($color) ?>;'>국가명(<?=$color?>)</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
성향 : <select class='formInput' name='nationType' id='nationType' size='1'>
|
||||
|
||||
<?php foreach (GameConst::$availableNationType as $nationType) :
|
||||
$nationTypeName = buildNationTypeClass($nationType)->getName();
|
||||
?>
|
||||
<option value='<?= $nationType ?>' style=background-color:black;color:white;><?= $nationTypeName ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<input type=button id="commonSubmit" value="<?= $this->getName() ?>">
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,222 +1,222 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use\sammo\{
|
||||
DB,
|
||||
Util,
|
||||
JosaUtil,
|
||||
General,
|
||||
DummyGeneral,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command
|
||||
};
|
||||
|
||||
use function\sammo\{
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
|
||||
class che_증여 extends Command\GeneralCommand
|
||||
{
|
||||
static protected $actionName = '증여';
|
||||
static public $reqArg = true;
|
||||
|
||||
protected function argTest(): bool
|
||||
{
|
||||
if ($this->arg === null) {
|
||||
return false;
|
||||
}
|
||||
//NOTE: 사망 직전에 '증여' 턴을 넣을 수 있으므로, 존재하지 않는 장수여도 argTest에서 바로 탈락시키지 않음
|
||||
if (!key_exists('isGold', $this->arg)) {
|
||||
return false;
|
||||
}
|
||||
if (!key_exists('amount', $this->arg)) {
|
||||
return false;
|
||||
}
|
||||
if (!key_exists('destGeneralID', $this->arg)) {
|
||||
return false;
|
||||
}
|
||||
$isGold = $this->arg['isGold'];
|
||||
$amount = $this->arg['amount'];
|
||||
$destGeneralID = $this->arg['destGeneralID'];
|
||||
if (!is_numeric($amount)) {
|
||||
return false;
|
||||
}
|
||||
$amount = Util::round($amount, -2);
|
||||
$amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount);
|
||||
if ($amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (!is_bool($isGold)) {
|
||||
return false;
|
||||
}
|
||||
if (!is_int($destGeneralID)) {
|
||||
return false;
|
||||
}
|
||||
if ($destGeneralID <= 0) {
|
||||
return false;
|
||||
}
|
||||
if ($destGeneralID == $this->generalObj->getID()) {
|
||||
return false;
|
||||
}
|
||||
$this->arg = [
|
||||
'isGold' => $isGold,
|
||||
'amount' => $amount,
|
||||
'destGeneralID' => $destGeneralID
|
||||
];
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
$this->minConditionConstraints = [
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function initWithArg()
|
||||
{
|
||||
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], 1);
|
||||
$this->setDestGeneral($destGeneral);
|
||||
|
||||
$this->fullConditionConstraints = [
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ExistsDestGeneral(),
|
||||
ConstraintHelper::FriendlyDestGeneral()
|
||||
];
|
||||
if ($this->arg['isGold']) {
|
||||
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralGold(GameConst::$generalMinimumGold);
|
||||
} else {
|
||||
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralRice(GameConst::$generalMinimumRice);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCommandDetailTitle(): string
|
||||
{
|
||||
$name = $this->getName();
|
||||
return "{$name}(통솔경험)";
|
||||
}
|
||||
|
||||
public function getCost(): array
|
||||
{
|
||||
return [0, 0];
|
||||
}
|
||||
|
||||
public function getPreReqTurn(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getBrief(): string
|
||||
{
|
||||
$destGeneralName = $this->destGeneralObj->getName();
|
||||
$resText = $this->arg['isGold'] ? '금' : '쌀';
|
||||
$name = $this->getName();
|
||||
return "【{$destGeneralName}】에게 {$resText} {$this->arg['amount']}을 {$name}";
|
||||
}
|
||||
|
||||
public function run(): bool
|
||||
{
|
||||
if (!$this->hasFullConditionMet()) {
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
$isGold = $this->arg['isGold'];
|
||||
$amount = $this->arg['amount'];
|
||||
$resKey = $isGold ? 'gold' : 'rice';
|
||||
$resName = $isGold ? '금' : '쌀';
|
||||
$destGeneral = $this->destGeneralObj;
|
||||
|
||||
$amount = Util::valueFit($amount, 0, $general->getVar($resKey) - ($isGold ? GameConst::$generalMinimumGold : GameConst::$generalMinimumRice));
|
||||
$amountText = number_format($amount, 0);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$destGeneral->increaseVarWithLimit($resKey, $amount);
|
||||
$general->increaseVarWithLimit($resKey, -$amount, 0);
|
||||
|
||||
$destGeneral->getLogger()->pushGeneralActionLog("<Y>{$general->getName()}</>에게서 {$resName} <C>{$amountText}</>을 증여 받았습니다.", ActionLogger::PLAIN);
|
||||
$logger->pushGeneralActionLog("<Y>{$destGeneral->getName()}</>에게 {$resName} <C>$amountText</>을 증여했습니다. <1>$date</>");
|
||||
|
||||
$exp = 70;
|
||||
$ded = 100;
|
||||
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar('leadership_exp', 1);
|
||||
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
$destGeneral->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getForm(): string
|
||||
{
|
||||
//TODO: 암행부처럼 보여야...
|
||||
$db = DB::db();
|
||||
|
||||
$destRawGenerals = $db->query('SELECT no,name,officer_level,npc,gold,rice FROM general WHERE nation != 0 AND nation = %i AND no != %i ORDER BY npc,binary(name)', $this->generalObj->getNationID(), $this->generalObj->getID());
|
||||
ob_start();
|
||||
?>
|
||||
자신의 자금이나 군량을 다른 장수에게 증여합니다.<br>
|
||||
장수를 선택하세요.<br>
|
||||
<select class='formInput' name="destGeneralID" id="destGeneralID" size='1' style='color:white;background-color:black;'>
|
||||
<?php foreach ($destRawGenerals as $destGeneral) :
|
||||
$color = \sammo\getNameColor($destGeneral['npc']);
|
||||
if ($color) {
|
||||
$color = " style='color:{$color}'";
|
||||
}
|
||||
$name = $destGeneral['name'];
|
||||
if ($destGeneral['officer_level'] >= 5) {
|
||||
$name = "*{$name}*";
|
||||
}
|
||||
?>
|
||||
<option value='<?= $destGeneral['no'] ?>' <?= $color ?>><?= $name ?>(금:<?= $destGeneral['gold'] ?>, 쌀:<?= $destGeneral['rice'] ?>)</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<select class='formInput' name="isGold" id="isGold" size='1' style='color:white;background-color:black;'>
|
||||
<option value="true">금</option>
|
||||
<option value="false">쌀</option>
|
||||
</select>
|
||||
<select class='formInput' name="amount" id="amount" size='1' style='color:white;background-color:black;'>
|
||||
<?php foreach (GameConst::$resourceActionAmountGuide as $amount) : ?>
|
||||
<option value='<?= $amount ?>'><?= $amount ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use\sammo\{
|
||||
DB,
|
||||
Util,
|
||||
JosaUtil,
|
||||
General,
|
||||
DummyGeneral,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command
|
||||
};
|
||||
|
||||
use function\sammo\{
|
||||
getDomesticExpLevelBonus,
|
||||
CriticalRatioDomestic,
|
||||
CriticalScoreEx,
|
||||
tryUniqueItemLottery
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use \sammo\Constraint\ConstraintHelper;
|
||||
|
||||
|
||||
class che_증여 extends Command\GeneralCommand
|
||||
{
|
||||
static protected $actionName = '증여';
|
||||
static public $reqArg = true;
|
||||
|
||||
protected function argTest(): bool
|
||||
{
|
||||
if ($this->arg === null) {
|
||||
return false;
|
||||
}
|
||||
//NOTE: 사망 직전에 '증여' 턴을 넣을 수 있으므로, 존재하지 않는 장수여도 argTest에서 바로 탈락시키지 않음
|
||||
if (!key_exists('isGold', $this->arg)) {
|
||||
return false;
|
||||
}
|
||||
if (!key_exists('amount', $this->arg)) {
|
||||
return false;
|
||||
}
|
||||
if (!key_exists('destGeneralID', $this->arg)) {
|
||||
return false;
|
||||
}
|
||||
$isGold = $this->arg['isGold'];
|
||||
$amount = $this->arg['amount'];
|
||||
$destGeneralID = $this->arg['destGeneralID'];
|
||||
if (!is_numeric($amount)) {
|
||||
return false;
|
||||
}
|
||||
$amount = Util::round($amount, -2);
|
||||
$amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount);
|
||||
if ($amount <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (!is_bool($isGold)) {
|
||||
return false;
|
||||
}
|
||||
if (!is_int($destGeneralID)) {
|
||||
return false;
|
||||
}
|
||||
if ($destGeneralID <= 0) {
|
||||
return false;
|
||||
}
|
||||
if ($destGeneralID == $this->generalObj->getID()) {
|
||||
return false;
|
||||
}
|
||||
$this->arg = [
|
||||
'isGold' => $isGold,
|
||||
'amount' => $amount,
|
||||
'destGeneralID' => $destGeneralID
|
||||
];
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
|
||||
$this->minConditionConstraints = [
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function initWithArg()
|
||||
{
|
||||
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], 1);
|
||||
$this->setDestGeneral($destGeneral);
|
||||
|
||||
$this->fullConditionConstraints = [
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ExistsDestGeneral(),
|
||||
ConstraintHelper::FriendlyDestGeneral()
|
||||
];
|
||||
if ($this->arg['isGold']) {
|
||||
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralGold(GameConst::$generalMinimumGold);
|
||||
} else {
|
||||
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralRice(GameConst::$generalMinimumRice);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCommandDetailTitle(): string
|
||||
{
|
||||
$name = $this->getName();
|
||||
return "{$name}(통솔경험)";
|
||||
}
|
||||
|
||||
public function getCost(): array
|
||||
{
|
||||
return [0, 0];
|
||||
}
|
||||
|
||||
public function getPreReqTurn(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getBrief(): string
|
||||
{
|
||||
$destGeneralName = $this->destGeneralObj->getName();
|
||||
$resText = $this->arg['isGold'] ? '금' : '쌀';
|
||||
$name = $this->getName();
|
||||
return "【{$destGeneralName}】에게 {$resText} {$this->arg['amount']}을 {$name}";
|
||||
}
|
||||
|
||||
public function run(): bool
|
||||
{
|
||||
if (!$this->hasFullConditionMet()) {
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$general = $this->generalObj;
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
$isGold = $this->arg['isGold'];
|
||||
$amount = $this->arg['amount'];
|
||||
$resKey = $isGold ? 'gold' : 'rice';
|
||||
$resName = $isGold ? '금' : '쌀';
|
||||
$destGeneral = $this->destGeneralObj;
|
||||
|
||||
$amount = Util::valueFit($amount, 0, $general->getVar($resKey) - ($isGold ? GameConst::$generalMinimumGold : GameConst::$generalMinimumRice));
|
||||
$amountText = number_format($amount, 0);
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$destGeneral->increaseVarWithLimit($resKey, $amount);
|
||||
$general->increaseVarWithLimit($resKey, -$amount, 0);
|
||||
|
||||
$destGeneral->getLogger()->pushGeneralActionLog("<Y>{$general->getName()}</>에게서 {$resName} <C>{$amountText}</>을 증여 받았습니다.", ActionLogger::PLAIN);
|
||||
$logger->pushGeneralActionLog("<Y>{$destGeneral->getName()}</>에게 {$resName} <C>$amountText</>을 증여했습니다. <1>$date</>");
|
||||
|
||||
$exp = 70;
|
||||
$ded = 100;
|
||||
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar('leadership_exp', 1);
|
||||
|
||||
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
$destGeneral->applyDB($db);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getForm(): string
|
||||
{
|
||||
//TODO: 암행부처럼 보여야...
|
||||
$db = DB::db();
|
||||
|
||||
$destRawGenerals = $db->query('SELECT no,name,officer_level,npc,gold,rice FROM general WHERE nation != 0 AND nation = %i AND no != %i ORDER BY npc,binary(name)', $this->generalObj->getNationID(), $this->generalObj->getID());
|
||||
ob_start();
|
||||
?>
|
||||
자신의 자금이나 군량을 다른 장수에게 증여합니다.<br>
|
||||
장수를 선택하세요.<br>
|
||||
<select class='formInput' name="destGeneralID" id="destGeneralID" size='1' style='color:white;background-color:black;'>
|
||||
<?php foreach ($destRawGenerals as $destGeneral) :
|
||||
$color = \sammo\getNameColor($destGeneral['npc']);
|
||||
if ($color) {
|
||||
$color = " style='color:{$color}'";
|
||||
}
|
||||
$name = $destGeneral['name'];
|
||||
if ($destGeneral['officer_level'] >= 5) {
|
||||
$name = "*{$name}*";
|
||||
}
|
||||
?>
|
||||
<option value='<?= $destGeneral['no'] ?>' <?= $color ?>><?= $name ?>(금:<?= $destGeneral['gold'] ?>, 쌀:<?= $destGeneral['rice'] ?>)</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<select class='formInput' name="isGold" id="isGold" size='1' style='color:white;background-color:black;'>
|
||||
<option value="true">금</option>
|
||||
<option value="false">쌀</option>
|
||||
</select>
|
||||
<select class='formInput' name="amount" id="amount" size='1' style='color:white;background-color:black;'>
|
||||
<?php foreach (GameConst::$resourceActionAmountGuide as $amount) : ?>
|
||||
<option value='<?= $amount ?>'><?= $amount ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,191 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Command\Nation;
|
||||
|
||||
use\sammo\{
|
||||
DB,
|
||||
Util,
|
||||
JosaUtil,
|
||||
General,
|
||||
DummyGeneral,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command,
|
||||
MessageTarget,
|
||||
Message,
|
||||
CityConst,
|
||||
Json,
|
||||
};
|
||||
|
||||
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(['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
|
||||
{
|
||||
$color = GetNationColors()[$this->arg['colorType']];
|
||||
return "【<span style='color:{$color};'>국기</span>】를 변경";
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
$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, '이');
|
||||
|
||||
$aux = Json::decode($this->nation['aux']);
|
||||
$aux["can_{$actionName}"] = 0;
|
||||
|
||||
$db->update('nation', [
|
||||
'color'=>$color,
|
||||
'aux'=>Json::encode($aux)
|
||||
], '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>를 변경하였습니다.");
|
||||
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace sammo\Command\Nation;
|
||||
|
||||
use\sammo\{
|
||||
DB,
|
||||
Util,
|
||||
JosaUtil,
|
||||
General,
|
||||
DummyGeneral,
|
||||
ActionLogger,
|
||||
GameConst,
|
||||
LastTurn,
|
||||
GameUnitConst,
|
||||
Command,
|
||||
MessageTarget,
|
||||
Message,
|
||||
CityConst,
|
||||
Json,
|
||||
};
|
||||
|
||||
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(['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
|
||||
{
|
||||
$color = GetNationColors()[$this->arg['colorType']];
|
||||
return "【<span style='color:{$color};'>국기</span>】를 변경";
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
$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, '이');
|
||||
|
||||
$aux = Json::decode($this->nation['aux']);
|
||||
$aux["can_{$actionName}"] = 0;
|
||||
|
||||
$db->update('nation', [
|
||||
'color'=>$color,
|
||||
'aux'=>Json::encode($aux)
|
||||
], '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>를 변경하였습니다.");
|
||||
|
||||
$this->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 ?>" data-color=<?=$color?> data-font-color="<?=newColor($color)?>" 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user