feat: 무작위건국, 무작위수도이전 커맨드 추가

This commit is contained in:
2022-10-30 21:47:24 +09:00
parent b14f9a638f
commit 81bd5c1914
4 changed files with 495 additions and 0 deletions
@@ -0,0 +1,246 @@
<?php
namespace sammo\Command\General;
use \sammo\DB;
use \sammo\Util;
use \sammo\JosaUtil;
use \sammo\General;
use \sammo\ActionLogger;
use \sammo\GameConst;
use \sammo\GameUnitConst;
use \sammo\LastTurn;
use \sammo\Command;
use \sammo\Json;
use function \sammo\tryUniqueItemLottery;
use function \sammo\getAllNationStaticInfo;
use \sammo\Constraint\ConstraintHelper;
use sammo\Enums\InheritanceKey;
use function sammo\buildNationTypeClass;
use function sammo\genGenericUniqueRNGFromGeneral;
use function sammo\refreshNationStaticInfo;
use function sammo\GetNationColors;
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->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(),
];
}
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(\Sammo\RandUtil $rng): 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();
$logger = $general->getLogger();
$initYearMonth = Util::joinYearMonth($env['init_year'], $env['init_month']);
$yearMonth = Util::joinYearMonth($env['year'], $env['month']);
if($yearMonth <= $initYearMonth){
$logger->pushGeneralActionLog("다음 턴부터 건국할 수 있습니다. <1>$date</>");
$this->alternative = new che_인재탐색($general, $this->env, null);
return false;
}
$cities = $db->queryFirstColumn('SELECT city FROM city where `level`>=5 and `level`<=6 and nation=0');
if(!$cities){
$logger->pushGeneralActionLog("건국할 수 있는 도시가 없습니다. <1>$date</>");
$this->alternative = new che_해산($general, $this->env, null);
return false;
}
$cityID = $rng->choice($cities);
if($general->getCityID() == $cityID){
$this->setCity();
}
else{
$this->generalObj->setVar('city', $cityID);
$this->setCity();
$db->update('general', [
'city' => $cityID
], 'nation = %i', $general->getNationID());
}
$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, '을');
$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;
$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();
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
tryUniqueItemLottery(genGenericUniqueRNGFromGeneral($general), $general, '건국');
$general->applyDB($db);
return true;
}
public function exportJSVars(): array
{
$nationTypes = [];
foreach (GameConst::$availableNationType as $nationType) {
$nationClass = buildNationTypeClass($nationType);
$nationTypes[$nationType] = [
'type' => $nationType,
'name' => $nationClass->getName(),
'pros' => $nationClass::$pros,
'cons' => $nationClass::$cons
];
}
return [
'procRes' => [
'available건국' => count(getAllNationStaticInfo()) < $this->env['maxnation'],
'nationTypes' => $nationTypes,
'colors' => GetNationColors(),
]
];
}
}
@@ -0,0 +1,165 @@
<?php
namespace sammo\Command\Nation;
use \sammo\DB;
use \sammo\Util;
use \sammo\JosaUtil;
use \sammo\General;
use \sammo\DummyGeneral;
use \sammo\ActionLogger;
use \sammo\GameConst;
use \sammo\LastTurn;
use \sammo\GameUnitConst;
use \sammo\Command;
use \sammo\MessageTarget;
use \sammo\Message;
use \sammo\CityConst;
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Enums\InheritanceKey;
use sammo\Event\Action;
use sammo\Json;
class che_무작위수도이전 extends Command\NationCommand
{
static protected $actionName = '무작위 수도 이전';
protected function argTest(): bool
{
$this->arg = [];
return true;
}
protected function init()
{
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$this->setCity();
$this->setNation(['capital', 'aux']);
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeLord(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::BeOpeningPart($relYear + 1),
ConstraintHelper::ReqNationAuxValue("can_무작위수도이전", 0, '>', 0, '더이상 변경이 불가능합니다.')
];
}
public function getCommandDetailTitle():string{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn()+1;
return "{$name}/{$reqTurn}";
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 1;
}
public function getPostReqTurn(): int
{
return 0;
}
public function run(\Sammo\RandUtil $rng): 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);
$year = $this->env['year'];
$month = $this->env['month'];
$logger = $general->getLogger();
$oldCityID = $this->nation['capital'];
$cities = $db->queryFirstColumn('SELECT city FROM city where `level`>=5 and `level`<=6 and nation=0');
if (!$cities) {
$logger->pushGeneralActionLog("이동할 수 있는 도시가 없습니다. <1>$date</>");
return false;
}
$destCityID = $rng->choice($cities);
$this->setDestCity($destCityID, true);
$destCity = $this->destCity;
$destCityID = $destCity['city'];
$destCityName = $destCity['name'];
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$josaRo = JosaUtil::pick($destCityName, '로');
$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_무작위수도이전"] -= 1;
$db->update('city', [
'nation' => $nationID,
'conflict' => '{}'
], 'city=%i', $destCityID);
$db->update('nation', [
'capital' => $destCityID,
'aux'=>Json::encode($aux),
], 'nation=%i', $nationID);
$db->update('city', [
'nation' => 0,
'front' => 0,
'conflict' => '{}',
'officer_set' => 0,
], 'city=%i', $oldCityID);
$general->setVar('city', $destCityID);
$generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID());
if ($generalList) {
$db->update('general', [
'city' => $destCityID
], 'no IN %li', $generalList);
}
foreach ($generalList as $targetGeneralID) {
$targetLogger = new ActionLogger($targetGeneralID, $general->getNationID(), $year, $month);
$targetLogger->pushGeneralActionLog("국가 수도를 <G><b>{$destCityName}</b></>{$josaRo} 옮겼습니다.", ActionLogger::PLAIN);
$targetLogger->flush();
}
\sammo\refreshNationStaticInfo();
$general->increaseInheritancePoint(InheritanceKey::active_action, 1);
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>{$josaRo} 국가를 옮겼습니다. <1>$date</>");
$logger->pushGeneralHistoryLog("<G><b>{$destCityName}</b></>{$josaRo} <M>무작위 수도 이전</>");
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>{$josaRo} <M>무작위 수도 이전</>");
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>{$josaRo} <M>수도 이전</>하였습니다.");
$logger->pushGlobalHistoryLog("<S><b>【무작위 수도 이전】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>{$josaRo} <M>수도 이전</>하였습니다.");
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
}
@@ -0,0 +1,82 @@
<template>
<TopBackBar :title="commandName" />
<div v-if="!available건국" class="bg0"> 이상 건국은 불가능합니다.</div>
<div v-else class="bg0">
<div>무작위 공백지 , 소도시에서 나라를 세웁니다.</div>
<ul>
<li v-for="nationType in nationTypes" :key="nationType.type" class="row">
<div class="col-2 col-md-1">- {{ nationType.name }}</div>
<div class="col-4 col-md-2">
: <span style="color: cyan">{{ nationType.pros }}</span
>,
</div>
<div class="col-4 col-md-2">
<span style="color: magenta">{{ nationType.cons }}</span>
</div>
</li>
</ul>
<div class="row">
<div class="col-4 col-md-2">국명 : <b-form-input v-model="destNationName" maxlength="18" /></div>
<div class="col-3 col-md-2">색상 : <ColorSelect v-model="selectedColorID" :colors="colors" /></div>
<div class="col-3 col-md-2">
<label>성향 :</label>
<b-form-select v-model="selectedNationType" :options="nationTypesOption" />
</div>
<div class="col-2 col-md-2 d-grid">
<b-button @click="submit">
{{ commandName }}
</b-button>
</div>
</div>
</div>
<BottomBar :title="commandName" />
</template>
<script lang="ts">
declare const staticValues: {
commandName: string;
};
declare const procRes: {
available건국: boolean;
colors: string[];
nationTypes: procNationTypeList;
};
</script>
<script setup lang="ts">
import ColorSelect from "@/processing/SelectColor.vue";
import { ref } from "vue";
import { unwrap } from "@/util/unwrap";
import type { Args } from "@/processing/args";
import TopBackBar from "@/components/TopBackBar.vue";
import BottomBar from "@/components/BottomBar.vue";
import type { procNationTypeList } from "../processingRes";
const commandName = staticValues.commandName;
const { nationTypes, available건국, colors } = procRes;
const destNationName = ref("");
const selectedColorID = ref(0);
const selectedNationType = ref(Object.values(procRes.nationTypes)[0].type);
async function submit(e: Event) {
const event = new CustomEvent<Args>("customSubmit", {
detail: {
colorType: selectedColorID.value,
nationName: destNationName.value,
nationType: selectedNationType.value,
},
});
unwrap(e.target).dispatchEvent(event);
}
const nationTypesOption: { html: string; value: string }[] = [];
for (const nationType of Object.values(procRes.nationTypes)) {
nationTypesOption.push({
html: nationType.name,
value: nationType.type,
});
}
</script>
+2
View File
@@ -1,4 +1,5 @@
import { default as che_건국 } from "./che_건국.vue";
import { default as che_무작위건국 } from "./che_무작위건국.vue";
import { default as che_군량매매 } from "./che_군량매매.vue";
import { default as che_등용 } from "./che_등용.vue";
import { default as che_선양 } from "./che_선양.vue";
@@ -19,6 +20,7 @@ export const commandMap: Record<string, typeof ProcessCity> = {
che_강행: ProcessCity,
che_군량매매,
che_건국,
che_무작위건국,
che_등용,
che_모병: che_징병,
che_선동: ProcessCity,