커맨드 유효성을 2개에서 3개구성으로 변경

This commit is contained in:
2020-05-04 19:51:11 +09:00
parent f25f5008f1
commit 77248ad4d8
100 changed files with 4124 additions and 3420 deletions
+90 -78
View File
@@ -2,7 +2,8 @@
namespace sammo;
class ActionLogger{
class ActionLogger
{
//TODO: global을 따로 뗴어내고, 장수 Logger를 상속해서 받는 형식으로.
protected $generalID;
protected $nationID;
@@ -10,7 +11,7 @@ class ActionLogger{
protected $year = null;
protected $month = null;
protected $generalHistoryLog = [];
protected $generalActionLog = [];
protected $generalBattleResultLog = [];
@@ -37,7 +38,8 @@ class ActionLogger{
/** <R>★</>{$year}년 {$month}월: */
const NOTICE_YEAR_MONTH = 8;
public function __construct(int $generalID, int $nationID, int $year, int $month, bool $autoFlush = true){
public function __construct(int $generalID, int $nationID, int $year, int $month, bool $autoFlush = true)
{
$this->generalID = $generalID;
$this->nationID = $nationID;
$this->year = $year;
@@ -45,23 +47,25 @@ class ActionLogger{
$this->autoFlush = $autoFlush;
}
public function __destruct(){
if($this->autoFlush){
public function __destruct()
{
if ($this->autoFlush) {
$this->flush();
}
}
public function rollback(){
public function rollback()
{
$backup = [
'generalHistoryLog'=>$this->generalHistoryLog,
'generalActionLog'=>$this->generalActionLog,
'generalBattleResultLog'=>$this->generalBattleResultLog,
'generalBattleDetailLog'=>$this->generalBattleDetailLog,
'nationalHistoryLog'=>$this->nationalHistoryLog,
'globalHistoryLog'=>$this->globalHistoryLog,
'globalActionLog'=>$this->globalActionLog,
'generalHistoryLog' => $this->generalHistoryLog,
'generalActionLog' => $this->generalActionLog,
'generalBattleResultLog' => $this->generalBattleResultLog,
'generalBattleDetailLog' => $this->generalBattleDetailLog,
'nationalHistoryLog' => $this->nationalHistoryLog,
'globalHistoryLog' => $this->globalHistoryLog,
'globalActionLog' => $this->globalActionLog,
];
$this->generalHistoryLog = [];
$this->generalActionLog = [];
$this->generalBattleResultLog = [];
@@ -73,50 +77,52 @@ class ActionLogger{
return $backup;
}
public function flush(){
if($this->generalHistoryLog && $this->generalID){
public function flush()
{
if ($this->generalHistoryLog && $this->generalID) {
pushGeneralHistory($this->generalID, $this->generalHistoryLog, $this->year, $this->month);
$this->generalHistoryLog = [];
}
if($this->generalActionLog && $this->generalID){
if ($this->generalActionLog && $this->generalID) {
pushGenLog($this->generalID, $this->generalActionLog, $this->year, $this->month);
$this->generalActionLog = [];
}
if($this->generalBattleResultLog && $this->generalID){
if ($this->generalBattleResultLog && $this->generalID) {
pushBatRes($this->generalID, $this->generalBattleResultLog, $this->year, $this->month);
$this->generalBattleResultLog = [];
}
if($this->generalBattleDetailLog && $this->generalID){
if ($this->generalBattleDetailLog && $this->generalID) {
pushBatLog($this->generalID, $this->generalBattleDetailLog, $this->year, $this->month);
$this->generalBattleDetailLog = [];
}
if($this->nationID && $this->nationalHistoryLog){
if ($this->nationID && $this->nationalHistoryLog) {
pushNationHistory($this->nationID, $this->nationalHistoryLog, $this->year, $this->month);
$this->nationalHistoryLog = [];
}
if($this->globalHistoryLog){
if ($this->globalHistoryLog) {
pushWorldHistory($this->globalHistoryLog, $this->year, $this->month);
$this->globalHistoryLog = [];
}
if($this->globalActionLog){
if ($this->globalActionLog) {
pushGeneralPublicRecord($this->globalActionLog, $this->year, $this->month);
$this->globalActionLog = [];
}
}
public function pushGeneralHistoryLog($text, int $formatType = self::YEAR_MONTH){
if(!$text){
public function pushGeneralHistoryLog($text, int $formatType = self::YEAR_MONTH)
{
if (!$text) {
return;
}
if(is_array($text)){
foreach($text as $textItem){
if (is_array($text)) {
foreach ($text as $textItem) {
$this->pushGeneralHistoryLog($textItem);
}
return;
@@ -126,12 +132,13 @@ class ActionLogger{
$this->generalHistoryLog[] = $text;
}
public function pushGeneralActionLog($text, int $formatType = self::MONTH){
if(!$text){
public function pushGeneralActionLog($text, int $formatType = self::MONTH)
{
if (!$text) {
return;
}
if(is_array($text)){
foreach($text as $textItem){
if (is_array($text)) {
foreach ($text as $textItem) {
$this->pushGeneralActionLog($textItem);
}
return;
@@ -141,12 +148,13 @@ class ActionLogger{
$this->generalActionLog[] = $text;
}
public function pushGeneralBattleResultLog($text, int $formatType = self::RAWTEXT){
if(!$text){
public function pushGeneralBattleResultLog($text, int $formatType = self::RAWTEXT)
{
if (!$text) {
return;
}
if(is_array($text)){
foreach($text as $textItem){
if (is_array($text)) {
foreach ($text as $textItem) {
$this->pushGeneralBattleResultLog($textItem);
}
return;
@@ -156,12 +164,13 @@ class ActionLogger{
$this->generalBattleResultLog[] = $text;
}
public function pushGeneralBattleDetailLog($text, int $formatType = self::PLAIN){
if(!$text){
public function pushGeneralBattleDetailLog($text, int $formatType = self::PLAIN)
{
if (!$text) {
return;
}
if(is_array($text)){
foreach($text as $textItem){
if (is_array($text)) {
foreach ($text as $textItem) {
$this->pushGeneralBattleDetailLog($textItem);
}
return;
@@ -171,12 +180,13 @@ class ActionLogger{
$this->generalBattleDetailLog[] = $text;
}
public function pushNationalHistoryLog($text, int $formatType = self::YEAR_MONTH){
if(!$text){
public function pushNationalHistoryLog($text, int $formatType = self::YEAR_MONTH)
{
if (!$text) {
return;
}
if(is_array($text)){
foreach($text as $textItem){
if (is_array($text)) {
foreach ($text as $textItem) {
$this->pushNationalHistoryLog($textItem);
}
return;
@@ -186,12 +196,13 @@ class ActionLogger{
$this->nationalHistoryLog[] = $text;
}
public function pushGlobalActionLog($text, int $formatType = self::MONTH){
if(!$text){
public function pushGlobalActionLog($text, int $formatType = self::MONTH)
{
if (!$text) {
return;
}
if(is_array($text)){
foreach($text as $textItem){
if (is_array($text)) {
foreach ($text as $textItem) {
$this->pushGlobalActionLog($textItem);
}
return;
@@ -201,12 +212,13 @@ class ActionLogger{
$this->globalActionLog[] = $text;
}
public function pushGlobalHistoryLog($text, int $formatType = self::YEAR_MONTH){
if(!$text){
public function pushGlobalHistoryLog($text, int $formatType = self::YEAR_MONTH)
{
if (!$text) {
return;
}
if(is_array($text)){
foreach($text as $textItem){
if (is_array($text)) {
foreach ($text as $textItem) {
$this->pushGlobalHistoryLog($textItem);
}
return;
@@ -216,55 +228,56 @@ class ActionLogger{
$this->globalHistoryLog[] = $text;
}
public function formatText(string $text, int $formatType):string{
if($formatType === self::RAWTEXT){
public function formatText(string $text, int $formatType): string
{
if ($formatType === self::RAWTEXT) {
return $text;
}
if($formatType === self::PLAIN){
if ($formatType === self::PLAIN) {
return "<C>●</>{$text}";
}
if($formatType === self::YEAR_MONTH){
if ($formatType === self::YEAR_MONTH) {
return "<C>●</>{$this->year}{$this->month}월:{$text}";
}
if($formatType === self::YEAR){
if ($formatType === self::YEAR) {
return "<C>●</>{$this->year}년:{$text}";
}
if($formatType === self::MONTH){
if ($formatType === self::MONTH) {
return "<C>●</>{$this->month}월:{$text}";
}
if($formatType === self::EVENT_PLAIN){
if ($formatType === self::EVENT_PLAIN) {
return "<S>◆</>{$text}";
}
if($formatType === self::EVENT_YEAR_MONTH){
if ($formatType === self::EVENT_YEAR_MONTH) {
return "<S>◆</>{$this->year}{$this->month}월:{$text}";
}
if($formatType === self::NOTICE){
if ($formatType === self::NOTICE) {
return "<R>★</>{$text}";
}
if($formatType === self::NOTICE_YEAR_MONTH){
if ($formatType === self::NOTICE_YEAR_MONTH) {
return "<R>★</>{$this->year}{$this->month}월:{$text}";
}
return $text;
}
public function pushBattleResultTemplate(
WarUnit $me,
WarUnit $oppose
){
if($me instanceof WarUnitCity){
) {
if ($me instanceof WarUnitCity) {
return;
}
$templates = new \League\Plates\Engine(__DIR__.'/../templates');
$templates = new \League\Plates\Engine(__DIR__ . '/../templates');
$render_me = [
'crewtype' => $me->getCrewTypeShortName(),
@@ -280,24 +293,22 @@ class ActionLogger{
'killed_crew' => -$oppose->getDeadCurrentBattle()
];
if(!$me->isAttacker()){
if (!$me->isAttacker()) {
$warType = 'defense';
$warTypeStr = '←';
}
else if($oppose instanceof WarUnitCity){
} else if ($oppose instanceof WarUnitCity) {
$warType = 'siege';
$warTypeStr = '→';
}
else{
} else {
$warType = 'attack';
$warTypeStr = '→';
}
$res = str_replace(["\r\n", "\r", "\n"], '', $templates->render('small_war_log',[
'year'=>$this->year,
'month'=>$this->month,
'war_type'=>$warType,
'war_type_str'=>$warTypeStr,
$res = str_replace(["\r\n", "\r", "\n"], '', $templates->render('small_war_log', [
'year' => $this->year,
'month' => $this->month,
'war_type' => $warType,
'war_type_str' => $warTypeStr,
'me' => $render_me,
'you' => $render_oppose,
]));
@@ -307,12 +318,13 @@ class ActionLogger{
$this->pushGeneralActionLog($res, self::EVENT_YEAR_MONTH);
}
public function getYear():int{
public function getYear(): int
{
return $this->year;
}
public function getMonth():int{
public function getMonth(): int
{
return $this->month;
}
}
}
+140 -86
View File
@@ -5,7 +5,8 @@ use \sammo\{
Util, JosaUtil, DB,
General, GameConst,
ActionLogger,
LastTurn
LastTurn,
NotInheritedMethodException
};
use function \sammo\getNationStaticInfo;
@@ -33,16 +34,19 @@ abstract class BaseCommand{
protected $destCity = null;
protected $destNation = null;
protected $runnable = null;
protected $reservable = null;
protected $cachedPermissionToReserve = false;
protected $cachedMinConditionMet = false;
protected $cachedFullConditionMet = false;
protected $isArgValid=false;
protected $reasonNotRunnable = null;
protected $reasonNotReservable = null;
protected $reasonNotFullConditionMet = null;
protected $reasonNotMinConditionMet = null;
protected $reasonNoPermissionToReserve = null;
protected $runnableConstraints = null;
protected $reservableConstraints = null;
protected $fullConditionConstraints = null;
protected $minConditionConstraints = null;
protected $permissionConstraints = null;
protected $logger;
@@ -63,57 +67,48 @@ abstract class BaseCommand{
$this->logger = $generalObj->getLogger();
$this->env = $env;
$this->arg = $arg;
if (!$this->argTest()) {
return;
}
$this->isArgValid = true;
$this->init();
$this->init();
if ($this->argTest()) {
$this->isArgValid = true;
if(static::$reqArg){
$this->initWithArg();
}
}
else{
$this->isArgValid = false;
}
}
protected function resetTestCache():void{
$this->runnable = null;
$this->reservable = null;
$this->cachedFullConditionMet = false;
$this->cachedMinConditionMet = false;
$this->cachedPermissionToReserve = false;
$this->reasonNotRunnable = null;
$this->reasonNotReservable = null;
$this->reasonNotFullConditionMet = null;
$this->reasonNotMinConditionMet = null;
$this->reasonNoPermissionToReserve = null;
}
protected function setCity(?array $args=null){
protected function setCity(){
$this->resetTestCache();
$db = DB::db();
if($args === null){
$this->city = $this->generalObj->getRawCity();
if($this->city){
return;
}
$this->city = $db->queryFirstRow('SELECT * FROM city WHERE city=%i', $this->generalObj->getVar('city'));
$this->generalObj->setRawCity($this->city);
return;
}
$this->city = $this->generalObj->getRawCity();
$hasArgs = true;
foreach($args as $arg){
if(!key_exists($arg, $this->city)){
$hasArgs = false;
break;
}
}
if($hasArgs){
if($this->city){
return;
}
$this->city = $db->queryFirstRow('SELECT %l FROM city WHERE city=%i', Util::formatListOfBackticks($args), $this->generalObj->getVar('city'));
if($this->generalObj->getRawCity() === null){
$this->generalObj->setRawCity($this->city);
}
$this->city = $db->queryFirstRow('SELECT * FROM city WHERE city=%i', $this->generalObj->getVar('city'));
$this->generalObj->setRawCity($this->city);
return;
}
protected function setNation(?array $args = null){
$this->resetTestCache();
if($args === null){
$this->nation = $this->generalObj->getStaticNation();
if(!$this->nation){
$this->nation = $this->generalObj->getStaticNation();
}
return;
}
@@ -143,7 +138,18 @@ abstract class BaseCommand{
'gennum'=>1
];
if($this->nation && $this->nation['nation'] === $nationID){
$allArgExists = true;
foreach($args as $arg){
if(!key_exists($arg, $this->nation)){
$allArgExists = false;
break;
}
}
if($allArgExists){
return;
}
}
$db = DB::db();
$nation = $db->queryFirstRow('SELECT %l FROM nation WHERE nation=%i', Util::formatListOfBackticks($args), $nationID);
@@ -153,7 +159,14 @@ abstract class BaseCommand{
$nation[$arg] = $defaultValues[$arg];
}
}
$this->nation = $nation;
if($this->nation){
//NOTE: 이 순서 맞다! https://www.php.net/manual/en/language.operators.array.php
$this->nation = $nation + $this->nation;
}
else{
$this->nation = $nation;
}
}
protected function setDestGeneral(General $destGeneralObj){
@@ -161,19 +174,19 @@ abstract class BaseCommand{
$this->destGeneralObj = $destGeneralObj;
}
protected function setDestCity(int $cityNo, ?array $args){
protected function setDestCity(int $cityNo, bool $onlyName=false){
$this->resetTestCache();
$db = DB::db();
if($args === []){
if($onlyName){
$cityObj = \sammo\CityConst::byID($cityNo);
$this->destCity = ['city'=>$cityNo, 'name'=>$cityObj->name];
$this->destCity = [
'city'=>$cityNo,
'name'=>$cityObj->name,
'region'=>$cityObj->region,
];
return;
}
if($args === null){
$this->destCity = $db->queryFirstRow('SELECT * FROM city WHERE city=%i', $cityNo);
return;
}
$this->destCity = $db->queryFirstRow('SELECT %l FROM city WHERE city=%i', Util::formatListOfBackticks($args), $cityNo);
$this->destCity = $db->queryFirstRow('SELECT * FROM city WHERE city=%i', $cityNo);
}
protected function setDestNation(int $nationID, ?array $args = null){
@@ -208,6 +221,11 @@ abstract class BaseCommand{
}
abstract protected function init();
protected function initWithArg(){
if(static::$reqArg){
throw new NotInheritedMethodException();
}
}
abstract protected function argTest():bool;
public function getArg():?array{
@@ -253,13 +271,19 @@ abstract class BaseCommand{
return $this->logger;
}
public function testReservable():?string{
if($this->reservableConstraints === null){
public function testPermissionToReserve():?string{
if(!$this->isArgValid()){
$this->reasonNoPermissionToReserve = '인자가 올바르지 않습니다.';
$this->cachedPermissionToReserve = true;
return $this->reasonNoPermissionToReserve;
}
if($this->permissionConstraints === null){
return null;
}
if($this->reasonNotReservable){
return $this->reasonNotReservable;
if($this->reasonNoPermissionToReserve){
return $this->reasonNoPermissionToReserve;
}
$this->generalObj->unpackAux();
@@ -274,27 +298,29 @@ abstract class BaseCommand{
'destNation'=>$this->destNation,
];
[$this->reasonConstraint, $this->reasonNotReservable] = Constraint::testAll($this->reservableConstraints??[], $constraintInput, $this->env);
$this->reservable = $this->reasonNotReservable === null;
return $this->reasonNotReservable;
[$this->reasonConstraint, $this->reasonNoPermissionToReserve] = Constraint::testAll($this->permissionConstraints??[], $constraintInput, $this->env);
$this->cachedPermissionToReserve = true;
return $this->reasonNoPermissionToReserve;
}
public function canDisplay():bool{
return true;
return $this->hasPermissionToReserve();
}
public function testRunnable():?string{
if(!$this->isArgValid()){
$this->reasonNotReservable = '인자가 올바르지 않습니다.';
$this->reservable = false;
return $this->reasonNotReservable;
}
if($this->runnableConstraints === null){
throw new \InvalidArgumentException('runnableConstraits가 제대로 설정되지 않았습니다');
public function testMinConditionMet():?string{
if(!static::$reqArg){
if($this->minConditionConstraints){
throw new \LogicException('reqArg==false인데 minCondition이 설정됨');
}
return $this->testFullConditionMet();
}
if($this->reasonNotRunnable){
return $this->reasonNotRunnable;
if($this->minConditionConstraints === null){
throw new \InvalidArgumentException('minConditionConstraints가 제대로 설정되지 않았습니다');
}
if($this->cachedMinConditionMet){
return $this->reasonNotMinConditionMet;
}
$this->generalObj->unpackAux();
@@ -309,9 +335,42 @@ abstract class BaseCommand{
'destNation'=>$this->destNation,
];
[$this->reasonConstraint, $this->reasonNotRunnable] = Constraint::testAll($this->runnableConstraints??[], $constraintInput, $this->env);
$this->runnable = $this->reasonNotRunnable === null;
return $this->reasonNotRunnable;
[$this->reasonConstraint, $this->reasonNotMinConditionMet] = Constraint::testAll($this->minConditionConstraints??[], $constraintInput, $this->env);
$this->cachedMinConditionMet = true;
return $this->reasonNotMinConditionMet;
}
public function testFullConditionMet():?string{
if(!$this->isArgValid()){
$this->reasonNotFullConditionMet = '인자가 올바르지 않습니다.';
$this->cachedFullConditionMet = true;
return $this->reasonNotFullConditionMet;
}
if($this->fullConditionConstraints === null){
throw new \InvalidArgumentException('fullConditionConstraints가 제대로 설정되지 않았습니다');
}
if($this->cachedFullConditionMet){
return $this->reasonNotFullConditionMet;
}
$this->generalObj->unpackAux();
$constraintInput = [
'general'=>$this->generalObj->getRaw(),
'city'=>$this->city,
'nation'=>$this->nation,
'cmd_arg'=>$this->arg,
'destGeneral'=>$this->destGeneralObj?$this->destGeneralObj->getRaw():null,
'destCity'=>$this->destCity,
'destNation'=>$this->destNation,
];
[$this->reasonConstraint, $this->reasonNotFullConditionMet] = Constraint::testAll($this->fullConditionConstraints??[], $constraintInput, $this->env);
$this->cachedFullConditionMet = true;
return $this->reasonNotFullConditionMet;
}
@@ -350,30 +409,25 @@ abstract class BaseCommand{
return true;
}
public function isReservable():bool{
if($this->reservable !== null){
return $this->reservable;
}
$this->reservable = $this->testReservable() === null;
return $this->reservable;
public function hasPermissionToReserve():bool{
return $this->testPermissionToReserve() === null;
}
public function isArgValid():bool{
return $this->isArgValid;
}
public function isRunnable():bool {
if($this->runnable !== null){
return $this->runnable;
}
return $this->testRunnable() === null;
public function hasMinConditionMet():bool {
return $this->testMinConditionMet() === null;
}
public function hasFullConditionMet():bool {
return $this->testFullConditionMet() === null;
}
public function getFailString():string{
$commandName = $this->getName();
$failReason = $this->testRunnable();
$failReason = $this->testFullConditionMet();
if($failReason === null){
throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집');
}
+3 -7
View File
@@ -48,11 +48,11 @@ class che_NPC능동 extends Command\GeneralCommand{
$this->setNation();
$this->reservableConstraints=[
$this->permissionConstraints=[
ConstraintHelper::MustBeNPC()
];
$this->runnableConstraints=[
$this->fullConditionConstraints=[
];
@@ -70,12 +70,8 @@ class che_NPC능동 extends Command\GeneralCommand{
return 0;
}
public function canDisplay():bool{
return false;
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+66 -52
View File
@@ -1,17 +1,21 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
use\sammo\{
DB,
Util,
JosaUtil,
General,
ActionLogger,
GameConst, GameUnitConst,
GameConst,
GameUnitConst,
LastTurn,
Command
};
use function \sammo\{
use function\sammo\{
tryUniqueItemLottery,
printCitiesBasedOnDistance
};
@@ -22,83 +26,95 @@ use sammo\CityConst;
class che_강행 extends Command\GeneralCommand{
class che_강행 extends Command\GeneralCommand
{
static protected $actionName = '강행';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('destCityID', $this->arg)){
if (!key_exists('destCityID', $this->arg)) {
return false;
}
if(!key_exists($this->arg['destCityID'], CityConst::all())){
if (!key_exists($this->arg['destCityID'], CityConst::all())) {
return false;
}
$this->arg = [
'destCityID'=>$this->arg['destCityID']
'destCityID' => $this->arg['destCityID']
];
return true;
}
protected function init(){
$general = $this->generalObj;
protected function init()
{
$this->setCity();
$this->setNation();
$this->setDestCity($this->arg['destCityID'], []);
$this->minConditionConstraints = [];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID'], true);
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
ConstraintHelper::NotSameDestCity(),
$this->fullConditionConstraints = [
ConstraintHelper::NotSameDestCity(),
ConstraintHelper::NearCity(3),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
[$reqGold, $reqRice] = $this->getCost();
$title = "{$name}(통솔경험";
if($reqGold > 0){
if ($reqGold > 0) {
$title .= ", 자금{$reqGold}";
}
if($reqRice > 0){
if ($reqRice > 0) {
$title .= ", 군량{$reqRice}";
}
$title .= ', 병력,훈련,사기↓)';
return $title;
}
public function getCost():array{
public function getCost(): array
{
$env = $this->env;
return [$env['develcost'] * 5, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
$josaRo = JosaUtil::pick($destCityName, '로');
return "{$destCityName}{$josaRo} {$commandName}";
}
public function getFailString():string{
public function getFailString(): string
{
$commandName = $this->getName();
$failReason = $this->testRunnable();
if($failReason === null){
$failReason = $this->testFullConditionMet();
if ($failReason === null) {
throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집');
}
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
@@ -106,8 +122,9 @@ class che_강행 extends Command\GeneralCommand{
return "{$failReason} <G><b>{$destCityName}</b></>{$josaRo} {$commandName} 실패.";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -128,16 +145,16 @@ class che_강행 extends Command\GeneralCommand{
$exp = 100;
$general->setVar('city', $destCityID);
if($general->getVar('officer_level') == 12 && $this->nation['level'] == 0){
if ($general->getVar('officer_level') == 12 && $this->nation['level'] == 0) {
$generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID());
if($generalList){
if ($generalList) {
$db->update('general', [
'city'=>$destCityID
'city' => $destCityID
], 'no IN %li and nation=%i', $generalList, $general->getNationID());
}
foreach($generalList as $targetGeneralID){
foreach ($generalList as $targetGeneralID) {
$targetLogger = new ActionLogger($targetGeneralID, $general->getNationID(), $env['year'], $env['month']);
$targetLogger->pushGeneralActionLog("방랑군 세력이 <G><b>{$destCityName}</b></>{$josaRo} 강행했습니다.", ActionLogger::PLAIN);
$targetLogger->flush();
@@ -153,7 +170,6 @@ class che_강행 extends Command\GeneralCommand{
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
@@ -170,19 +186,17 @@ class che_강행 extends Command\GeneralCommand{
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 도시로 강행합니다.<br>
최대 3칸내 도시로만 강행이 가능합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<?=$currentCityName?> => <select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
<?=\sammo\optionsForCities()?><br>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<br>
<br>
<?=printCitiesBasedOnDistance($currentCityID, 3)?>
<?= \sammo\getMapHtml() ?><br>
선택된 도시로 강행합니다.<br>
최대 3칸내 도시로만 강행이 가능합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<?= $currentCityName ?> => <select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
<?= \sammo\optionsForCities() ?><br>
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<br>
<br>
<?= printCitiesBasedOnDistance($currentCityID, 3) ?>
<?php
return ob_get_clean();
}
}
}
+4 -3
View File
@@ -30,7 +30,8 @@ class che_거병 extends Command\GeneralCommand{
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
@@ -40,7 +41,7 @@ class che_거병 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::BeNeutral(),
ConstraintHelper::BeOpeningPart($relYear+1),
ConstraintHelper::AllowJoinAction(),
@@ -60,7 +61,7 @@ class che_거병 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+92 -73
View File
@@ -1,17 +1,21 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
use\sammo\{
DB,
Util,
JosaUtil,
General,
ActionLogger,
GameConst, GameUnitConst,
GameConst,
GameUnitConst,
LastTurn,
Command
};
use function \sammo\{
use function\sammo\{
tryUniqueItemLottery,
getAllNationStaticInfo
};
@@ -25,69 +29,80 @@ use function sammo\GetNationColors;
use function sammo\newColor;
class che_건국 extends Command\GeneralCommand{
class che_건국 extends Command\GeneralCommand
{
static protected $actionName = '건국';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
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;
$nationName = $this->arg['nationName'] ?? null;
$nationType = $this->arg['nationType'] ?? null;
$colorType = $this->arg['colorType'] ?? null;
if($nationName === null || $nationType === null || $colorType === null){
if ($nationName === null || $nationType === null || $colorType === null) {
return false;
}
if(!is_string($nationName) || !is_string($nationType) || !is_int($colorType)){
if (!is_string($nationName) || !is_string($nationType) || !is_int($colorType)) {
return false;
}
if(mb_strwidth($nationName) > 18 || $nationName == ''){
if (mb_strwidth($nationName) > 18 || $nationName == '') {
return false;
}
if(!key_exists($colorType, GetNationColors())){
if (!key_exists($colorType, GetNationColors())) {
return false;
}
try{
try {
$nationTypeClass = buildNationTypeClass($nationType);
}
catch(\InvalidArgumentException $e){
} catch (\InvalidArgumentException $e) {
return false;
}
$this->arg = [
'nationName'=>$nationName,
'nationType'=>$nationType,
'colorType'=>$colorType
'nationName' => $nationName,
'nationType' => $nationType,
'colorType' => $colorType
];
return true;
}
protected function init(){
$general = $this->generalObj;
protected function init()
{
$env = $this->env;
$nationName = $this->arg['nationName'];
$nationType = $this->arg['nationType'];
$colorType = $this->arg['colorType'];
$this->setCity();
$this->setNation(['gennum']);
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
$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::BeOpeningPart($relYear + 1),
ConstraintHelper::CheckNationNameDuplicate($nationName),
ConstraintHelper::AllowJoinAction(),
ConstraintHelper::ConstructableCity(),
@@ -101,20 +116,24 @@ class che_건국 extends Command\GeneralCommand{
return "{$nationName}{$josaUl} 건국";
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -155,16 +174,16 @@ class che_건국 extends Command\GeneralCommand{
$general->addDedication($ded);
$db->update('city', [
'nation'=>$general->getNationID(),
'conflict'=>'{}'
'nation' => $general->getNationID(),
'conflict' => '{}'
], 'city=%i', $general->getCityID());
$db->update('nation', [
'name'=>$nationName,
'color'=>$colorType,
'level'=>1,
'type'=>$nationType,
'capital'=>$general->getCityID()
'name' => $nationName,
'color' => $colorType,
'level' => 1,
'type' => $nationType,
'capital' => $general->getCityID()
], 'nation=%i', $general->getNationID());
refreshNationStaticInfo();
@@ -180,7 +199,7 @@ class che_건국 extends Command\GeneralCommand{
public function getForm(): string
{
if(count(getAllNationStaticInfo()) >= $this->env['maxnation']){
if (count(getAllNationStaticInfo()) >= $this->env['maxnation']) {
return '더 이상 건국은 불가능합니다.';
}
@@ -213,44 +232,44 @@ class che_건국 extends Command\GeneralCommand{
}
}
*/
ob_start();
?>
현재 도시에서 나라를 세웁니다. 중, 소도시에서만 가능합니다.<br>
현재 도시에서 나라를 세웁니다. 중, 소도시에서만 가능합니다.<br>
<?php foreach(GameConst::$availableNationType as $nationType):
$nationClass = buildNationTypeClass($nationType);
<?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'>
[$name, $pros, $cons] = [$nationClass->getName(), $nationClass::$pros, $nationClass::$cons];
?>
<?php foreach(GetNationColors() as $idx=>$color):
/*
- <?= $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)?>';>국가명</option>
<?php endforeach; ?>
</select>
성향 : <select class='formInput' name='nationType' id='nationType' size='1'>
?>
<option value="<?= $idx ?>" style='background-color:<?= $color ?>;color:<?= newColor($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 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();
}
}
}
+4 -3
View File
@@ -28,11 +28,12 @@ class che_견문 extends Command\GeneralCommand{
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->runnableConstraints=[
$this->fullConditionConstraints=[
];
}
@@ -55,7 +56,7 @@ class che_견문 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+17 -5
View File
@@ -56,24 +56,36 @@ class che_군량매매 extends Command\GeneralCommand{
return "군량 {$this->arg['amount']}{$buyRiceText}";
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$this->minConditionConstraints=[
ConstraintHelper::ReqCityTrader($general->getVar('npc')),
ConstraintHelper::OccupiedCity(true),
ConstraintHelper::SuppliedCity(),
];
}
protected function initWithArg()
{
$general = $this->generalObj;
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::ReqCityTrader($general->getVar('npc')),
ConstraintHelper::OccupiedCity(true),
ConstraintHelper::SuppliedCity(),
];
if($this->arg['buyRice']){
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralGold(1);
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralGold(1);
}
else{
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralRice(1);
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralRice(1);
}
}
@@ -90,7 +102,7 @@ class che_군량매매 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+4 -3
View File
@@ -30,7 +30,8 @@ class che_귀환 extends Command\GeneralCommand{
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
@@ -39,7 +40,7 @@ class che_귀환 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::NotCapital(true),
@@ -64,7 +65,7 @@ class che_귀환 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -31,7 +31,8 @@ class che_기술연구 extends che_상업투자{
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
@@ -40,7 +41,7 @@ class che_기술연구 extends che_상업투자{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
@@ -53,7 +54,7 @@ class che_기술연구 extends che_상업투자{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+4 -3
View File
@@ -28,7 +28,8 @@ class che_단련 extends Command\GeneralCommand{
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
@@ -37,7 +38,7 @@ class che_단련 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::ReqGeneralCrew(),
ConstraintHelper::ReqGeneralValue('train', '훈련', '>=', GameConst::$defaultTrainLow),
@@ -77,7 +78,7 @@ class che_단련 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+25 -7
View File
@@ -53,21 +53,39 @@ class che_등용 extends Command\GeneralCommand{
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation(['gennum', 'scout']);
$relYear = $this->env['year'] - $this->env['startyear'];
$this->permissionConstraints=[
ConstraintHelper::ReqEnvValue('join_mode', '!=', 'onlyRandom', '랜덤 임관만 가능합니다'),
];
$this->minConditionConstraints=[
ConstraintHelper::ReqEnvValue('join_mode', '!=', 'onlyRandom', '랜덤 임관만 가능합니다'),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
];
}
protected function initWithArg()
{
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['nation'], 0);
$this->setDestGeneral($destGeneral);
[$reqGold, $reqRice] = $this->getCost();
$relYear = $this->env['year'] - $this->env['startyear'];
$this->runnableConstraints=[
ConstraintHelper::ReqEnvValue('join_mode', '==', 'onlyRandom', '랜덤 임관만 가능합니다'),
$this->fullConditionConstraints=[
ConstraintHelper::ReqEnvValue('join_mode', '!=', 'onlyRandom', '랜덤 임관만 가능합니다'),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::OccupiedCity(),
@@ -77,9 +95,9 @@ class che_등용 extends Command\GeneralCommand{
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
if($this->destGeneralObj->getVar('officer_level') == 12){
$this->runnableConstraints[] = ConstraintHelper::AlwaysFail('군주에게는 등용장을 보낼 수 없습니다.');
$this->fullConditionConstraints[] = ConstraintHelper::AlwaysFail('군주에게는 등용장을 보낼 수 없습니다.');
}
}
@@ -113,7 +131,7 @@ class che_등용 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+11 -7
View File
@@ -70,22 +70,26 @@ class che_등용수락 extends Command\GeneralCommand{
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setNation(['gennum', 'scout']);
$this->permissionConstraints = [
ConstraintHelper::AlwaysFail('예약 불가능 커맨드')
];
}
protected function initWithArg()
{
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['nation'], 0);
$this->setDestGeneral($destGeneral);
$this->setDestNation($this->arg['destNationID'], ['gennum', 'scout']);
$relYear = $this->env['year'] - $this->env['startyear'];
$this->reservableConstraints = [
ConstraintHelper::AlwaysFail('예약 불가능 커맨드')
];
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::ReqEnvValue('join_mode', '==', 'onlyRandom', '랜덤 임관만 가능합니다'),
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::ExistsDestNation(),
@@ -109,7 +113,7 @@ class che_등용수락 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -26,7 +26,6 @@ use sammo\MustNotBeReachedException;
class che_랜덤임관 extends Command\GeneralCommand{
static protected $actionName = '랜덤임관';
static public $reqArg = false;
protected function argTest():bool{
$this->arg = null;
@@ -61,7 +60,8 @@ class che_랜덤임관 extends Command\GeneralCommand{
return true;*/
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
@@ -71,14 +71,14 @@ class che_랜덤임관 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::BeNeutral(),
ConstraintHelper::AllowJoinAction(),
];
/*
if($this->arg['destNationIDList']??false){
$this->runnableConstraints[] = ConstraintHelper::ExistsAllowJoinNation($relYear, $this->arg['destNationIDList']);
$this->fullConditionConstraints[] = ConstraintHelper::ExistsAllowJoinNation($relYear, $this->arg['destNationIDList']);
}
*/
}
@@ -96,7 +96,7 @@ class che_랜덤임관 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -29,14 +29,15 @@ class che_모반시도 extends Command\GeneralCommand{
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::BeChief(),
ConstraintHelper::OccupiedCity(),
@@ -59,7 +60,7 @@ class che_모반시도 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -30,14 +30,15 @@ class che_물자조달 extends Command\GeneralCommand{
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
@@ -63,7 +64,7 @@ class che_물자조달 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+2 -2
View File
@@ -40,7 +40,7 @@ class che_방랑 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::BeLord(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::NotOpeningPart($relYear),
@@ -63,7 +63,7 @@ class che_방랑 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -36,7 +36,7 @@ class che_사기진작 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
@@ -69,7 +69,7 @@ class che_사기진작 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -45,7 +45,7 @@ class che_상업투자 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
@@ -128,7 +128,7 @@ class che_상업투자 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+60 -42
View File
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -11,9 +15,9 @@ use \sammo\{
Command
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
tryUniqueItemLottery
};
@@ -22,45 +26,55 @@ use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_선양 extends Command\GeneralCommand{
class che_선양 extends Command\GeneralCommand
{
static protected $actionName = '선양';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 사망 직전에 '선양' 턴을 넣을 수 있으므로, 존재하지 않는 장수여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('destGeneralID', $this->arg)){
if (!key_exists('destGeneralID', $this->arg)) {
return false;
}
$destGeneralID = $this->arg['destGeneralID'];
if(!is_int($destGeneralID)){
if (!is_int($destGeneralID)) {
return false;
}
if($destGeneralID <= 0){
if ($destGeneralID <= 0) {
return false;
}
if($destGeneralID == $this->generalObj->getID()){
if ($destGeneralID == $this->generalObj->getID()) {
return false;
}
$this->arg = [
'destGeneralID'=>$destGeneralID
'destGeneralID' => $destGeneralID
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setNation();
$this->minConditionConstraints = [
ConstraintHelper::BeLord()
];
}
protected function initWithArg()
{
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], 1);
$this->setDestGeneral($destGeneral);
$this->runnableConstraints=[
ConstraintHelper::BeLord(),
$this->fullConditionConstraints = [
ConstraintHelper::BeLord(),
ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::FriendlyDestGeneral(),
ConstraintHelper::DisallowDiplomacyStatus(
@@ -70,15 +84,18 @@ class che_선양 extends Command\GeneralCommand{
];
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
@@ -89,8 +106,9 @@ class che_선양 extends Command\GeneralCommand{
return "{$destGeneralName}】에게 {$name}";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -105,7 +123,7 @@ class che_선양 extends Command\GeneralCommand{
$destGeneralName = $destGeneral->getName();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$destLogger = $destGeneral->getLogger();
@@ -138,26 +156,26 @@ class che_선양 extends Command\GeneralCommand{
//TODO: 암행부처럼 보여야...
$db = DB::db();
$destRawGenerals = $db->query('SELECT no,name,officer_level,npc FROM general WHERE nation != 0 AND nation = %i AND no != %i ORDER BY npc,binary(name)',$this->generalObj->getNationID(), $this->generalObj->getID());
$destRawGenerals = $db->query('SELECT no,name,officer_level,npc 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?></option>
<?php endforeach; ?>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
군주의 자리를 다른 장수에게 물려줍니다.<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 ?></option>
<?php endforeach; ?>
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<?php
return ob_get_clean();
}
}
}
@@ -33,7 +33,7 @@ class che_소집해제 extends Command\GeneralCommand{
$this->setCity();
$this->setNation();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::ReqGeneralCrew(),
];
@@ -58,7 +58,7 @@ class che_소집해제 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+81 -56
View File
@@ -1,18 +1,24 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil, Session, KVStorage,
General,
use\sammo\{
DB,
Util,
JosaUtil,
Session,
KVStorage,
General,
ActionLogger,
GameConst, GameUnitConst,
GameConst,
GameUnitConst,
LastTurn,
Command,
ServConfig
};
use function \sammo\{
use function\sammo\{
getDexCall,
getTechCall,
tryUniqueItemLottery,
@@ -24,7 +30,8 @@ use \sammo\Constraint\ConstraintHelper;
class che_숙련전환 extends Command\GeneralCommand{
class che_숙련전환 extends Command\GeneralCommand
{
static protected $actionName = '숙련전환';
static public $reqArg = true;
@@ -36,103 +43,121 @@ class che_숙련전환 extends Command\GeneralCommand{
protected $destArmType;
/** @var string */
protected $destArmTypeName;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('srcArmType', $this->arg)){
if (!key_exists('srcArmType', $this->arg)) {
return false;
}
if(!key_exists('destArmType', $this->arg)){
if (!key_exists('destArmType', $this->arg)) {
return false;
}
$srcArmType = $this->arg['srcArmType'];
$destArmType = $this->arg['destArmType'];
if(!is_int($srcArmType)){
if (!is_int($srcArmType)) {
return false;
}
if(!key_exists($srcArmType, GameUnitConst::allType())){
if (!key_exists($srcArmType, GameUnitConst::allType())) {
return false;
}
if(!is_int($destArmType)){
if (!is_int($destArmType)) {
return false;
}
if(!key_exists($destArmType, GameUnitConst::allType())){
if (!key_exists($destArmType, GameUnitConst::allType())) {
return false;
}
if($srcArmType === $destArmType){
if ($srcArmType === $destArmType) {
return false;
}
$this->arg = [
'srcArmType'=>$srcArmType,
'destArmType'=>$destArmType
'srcArmType' => $srcArmType,
'destArmType' => $destArmType
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation();
[$reqGold, $reqRice] = $this->getCost();
$this->minConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
protected function initWithArg()
{
$this->srcArmType = $this->arg['srcArmType'];
$this->srcArmTypeName = GameUnitConst::allType()[$this->srcArmType];
$this->destArmType = $this->arg['destArmType'];
$this->destArmTypeName = GameUnitConst::allType()[$this->destArmType];
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
ConstraintHelper::NotBeNeutral(),
$this->fullConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
public function getBrief():string{
public function getBrief(): string
{
return "{$this->srcArmTypeName}】숙련을 【{$this->destArmTypeName}】숙련으로 전환";
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
[$reqGold, $reqRice] = $this->getCost();
$title = "{$name}(통솔경험";
if($reqGold > 0){
if ($reqGold > 0) {
$title .= ", 자금{$reqGold}";
}
if($reqRice > 0){
if ($reqRice > 0) {
$title .= ", 군량{$reqRice}";
}
$title .= ')';
return $title;
}
public function getCost():array{
public function getCost(): array
{
$env = $this->env;
return [$env['develcost'], $env['develcost']];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -143,14 +168,14 @@ class che_숙련전환 extends Command\GeneralCommand{
$logger = $general->getLogger();
$srcDex = $general->getVar('dex'.$this->srcArmType);
$srcDex = $general->getVar('dex' . $this->srcArmType);
$cutDex = Util::toInt($srcDex * 0.3);
$cutDexText = number_format($cutDex);
$addDex = Util::toInt($cutDex * 2 / 3);
$addDexText = number_format($addDex);
$general->increaseVar('dex'.$this->srcArmType, -$cutDex);
$general->increaseVar('dex'.$this->destArmType, $addDex);
$general->increaseVar('dex' . $this->srcArmType, -$cutDex);
$general->increaseVar('dex' . $this->destArmType, $addDex);
$josaUl = JosaUtil::pick($cutDex, '을');
$josaRo = JosaUtil::pick($addDex, '로');
@@ -170,17 +195,17 @@ class che_숙련전환 extends Command\GeneralCommand{
return true;
}
public function getForm(): string
{
$db = DB::db();
$general = $this->generalObj;
$dexSrcTexts = [];
$dexDestTexts = [];
foreach(GameUnitConst::allType() as $armType => $armName){
$dexVal = $general->getVar('dex'.$armType);
foreach (GameUnitConst::allType() as $armType => $armName) {
$dexVal = $general->getVar('dex' . $armType);
$dexValText = number_format($dexVal);
$cutDex = Util::toInt($dexVal * 0.3);
$addDex = Util::toInt($cutDex * 2 / 3);
@@ -195,23 +220,23 @@ class che_숙련전환 extends Command\GeneralCommand{
ob_start();
?>
본인의 특정 병종 숙련을 30% 줄이고, 줄어든 숙련 중 2/3(20%p)를 다른 병종 숙련으로 전환합니다.<br>
본인의 특정 병종 숙련을 30% 줄이고, 줄어든 숙련 중 2/3(20%p)를 다른 병종 숙련으로 전환합니다.<br>
<select class='formInput' name="srcArmType" id="srcArmType" size='1' style='color:white;background-color:black;'>
<?php foreach($dexSrcTexts as $armType=>$infoText): ?>
<option value="<?=$armType?>"><?=$infoText?></option>
<?php endforeach; ?>
</select>
숙련을
<select class='formInput' name="srcArmType" id="srcArmType" size='1' style='color:white;background-color:black;'>
<?php foreach ($dexSrcTexts as $armType => $infoText) : ?>
<option value="<?= $armType ?>"><?= $infoText ?></option>
<?php endforeach; ?>
</select>
숙련을
<select class='formInput' name="destArmType" id="destArmType" size='1' style='color:white;background-color:black;'>
<?php foreach($dexDestTexts as $armType=>$infoText): ?>
<option value="<?=$armType?>"><?=$infoText?></option>
<?php endforeach; ?>
</select>
숙련으로 <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<select class='formInput' name="destArmType" id="destArmType" size='1' style='color:white;background-color:black;'>
<?php foreach ($dexDestTexts as $armType => $infoText) : ?>
<option value="<?= $armType ?>"><?= $infoText ?></option>
<?php endforeach; ?>
</select>
숙련으로 <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<?php
return ob_get_clean();
}
}
}
+2 -2
View File
@@ -34,7 +34,7 @@ class che_요양 extends Command\GeneralCommand{
$this->setNation();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
];
}
@@ -52,7 +52,7 @@ class che_요양 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+69 -44
View File
@@ -1,17 +1,21 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
use\sammo\{
DB,
Util,
JosaUtil,
General,
ActionLogger,
GameConst, GameUnitConst,
GameConst,
GameUnitConst,
LastTurn,
Command
};
use function \sammo\{
use function\sammo\{
tryUniqueItemLottery,
printCitiesBasedOnDistance
};
@@ -22,83 +26,103 @@ use sammo\CityConst;
class che_이동 extends Command\GeneralCommand{
class che_이동 extends Command\GeneralCommand
{
static protected $actionName = '이동';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('destCityID', $this->arg)){
if (!key_exists('destCityID', $this->arg)) {
return false;
}
if(!key_exists($this->arg['destCityID'], CityConst::all())){
if (!key_exists($this->arg['destCityID'], CityConst::all())) {
return false;
}
$this->arg = [
'destCityID'=>$this->arg['destCityID']
'destCityID' => $this->arg['destCityID']
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$this->setDestCity($this->arg['destCityID'], []);
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
ConstraintHelper::NotSameDestCity(),
$this->minConditionConstraints = [
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID'], true);
[$reqGold, $reqRice] = $this->getCost();
$this->fullConditionConstraints = [
ConstraintHelper::NotSameDestCity(),
ConstraintHelper::NearCity(1),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
[$reqGold, $reqRice] = $this->getCost();
$title = "{$name}(통솔경험";
if($reqGold > 0){
if ($reqGold > 0) {
$title .= ", 자금{$reqGold}";
}
if($reqRice > 0){
if ($reqRice > 0) {
$title .= ", 군량{$reqRice}";
}
$title .= ', 사기↓)';
return $title;
}
public function getCost():array{
public function getCost(): array
{
$env = $this->env;
return [$env['develcost'], 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
$josaRo = JosaUtil::pick($destCityName, '로');
return "{$destCityName}{$josaRo} {$commandName}";
}
public function getFailString():string{
public function getFailString(): string
{
$commandName = $this->getName();
$failReason = $this->testRunnable();
if($failReason === null){
$failReason = $this->testFullConditionMet();
if ($failReason === null) {
throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집');
}
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
@@ -106,8 +130,9 @@ class che_이동 extends Command\GeneralCommand{
return "{$failReason} <G><b>{$destCityName}</b></>{$josaRo} {$commandName} 실패.";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -129,14 +154,14 @@ class che_이동 extends Command\GeneralCommand{
$general->setVar('city', $destCityID);
if($general->getVar('officer_level') == 12 && $this->nation['level'] == 0){
if ($general->getVar('officer_level') == 12 && $this->nation['level'] == 0) {
$generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID());
if($generalList){
if ($generalList) {
$db->update('general', [
'city'=>$destCityID
'city' => $destCityID
], 'no IN %li', $generalList);
}
foreach($generalList as $targetGeneralID){
foreach ($generalList as $targetGeneralID) {
$targetLogger = new ActionLogger($targetGeneralID, $general->getNationID(), $env['year'], $env['month']);
$targetLogger->pushGeneralActionLog("방랑군 세력이 <G><b>{$destCityName}</b></>{$josaRo} 이동했습니다.", ActionLogger::PLAIN);
$targetLogger->flush();
@@ -168,17 +193,17 @@ class che_이동 extends Command\GeneralCommand{
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 도시로 이동합니다.<br>
인접 도시로만 이동이 가능합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<?=$currentCityName?> => <select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
<?=\sammo\optionsForCities()?><br>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<br>
<br>
<?=printCitiesBasedOnDistance($currentCityID, 1)?>
<?= \sammo\getMapHtml() ?><br>
선택된 도시로 이동합니다.<br>
인접 도시로만 이동이 가능합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<?= $currentCityName ?> => <select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
<?= \sammo\optionsForCities() ?><br>
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<br>
<br>
<?= printCitiesBasedOnDistance($currentCityID, 1) ?>
<?php
return ob_get_clean();
}
}
}
@@ -40,7 +40,7 @@ class che_인재탐색 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::ReqGeneralGold($reqGold),
@@ -51,7 +51,7 @@ class che_인재탐색 extends Command\GeneralCommand{
if($this->nation['nation'] != 0 && $relYear < 3 && $this->nation['gennum'] >= GameConst::$initialNationGenLimit){
$nationName = $this->nation['name'];
$josaUn = JosaUtil::pick($nationName, '은');
$this->runnableConstraints[] = ConstraintHelper::AlwaysFail("현재 <D>{$nationName}</>{$josaUn} 탐색이 제한되고 있습니다.");
$this->fullConditionConstraints[] = ConstraintHelper::AlwaysFail("현재 <D>{$nationName}</>{$josaUn} 탐색이 제한되고 있습니다.");
}
}
@@ -84,7 +84,7 @@ class che_인재탐색 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+19 -12
View File
@@ -82,6 +82,22 @@ class che_임관 extends Command\GeneralCommand{
$this->setCity();
$this->setNation();
$relYear = $env['year'] - $env['startyear'];
$this->permissionConstraints=[
ConstraintHelper::ReqEnvValue('join_mode', '!=', 'onlyRandom', '랜덤 임관만 가능합니다')
];
$this->minConditionConstraints=[
ConstraintHelper::ReqEnvValue('join_mode', '!=', 'onlyRandom', '랜덤 임관만 가능합니다'),
ConstraintHelper::BeNeutral(),
ConstraintHelper::AllowJoinAction()
];
}
protected function initWithArg()
{
$destGeneralID = $this->arg['destGeneralID']??null;
$destNationID = $this->arg['destNationID']??null;
if($destGeneralID !== null){
@@ -92,13 +108,9 @@ class che_임관 extends Command\GeneralCommand{
$this->setDestNation($destNationID, ['gennum', 'scout']);
}
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$this->reservableConstraints=[
ConstraintHelper::ReqEnvValue('join_mode', '!=', 'onlyRandom', '랜덤 임관만 가능합니다')
];
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::ReqEnvValue('join_mode', '!=', 'onlyRandom', '랜덤 임관만 가능합니다'),
ConstraintHelper::BeNeutral(),
ConstraintHelper::ExistsDestNation(),
@@ -107,11 +119,6 @@ class che_임관 extends Command\GeneralCommand{
];
}
public function canDisplay(): bool
{
return ($this->env['join_mode']??'') != 'onlyRandom';
}
public function getCost():array{
return [0, 0];
}
@@ -132,7 +139,7 @@ class che_임관 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+15 -7
View File
@@ -63,14 +63,23 @@ class che_장비매매 extends Command\GeneralCommand{
$this->setCity();
$this->setNation();
$this->minConditionConstraints=[
ConstraintHelper::ReqCityTrader($general->getVar('npc')),
];
}
protected function initWithArg()
{
$general = $this->generalObj;
$itemType = $this->arg['itemType'];
$itemTypeName = static::$itemMap[$itemType];
$itemCode = $this->arg['itemCode'];
$itemClass = buildItemClass($itemCode);
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::ReqCityTrader($general->getVar('npc')),
ConstraintHelper::ReqCityCapacity('secu', '치안 수치', $itemClass->getReqSecu()),
ConstraintHelper::ReqGeneralGold($reqGold),
@@ -78,15 +87,14 @@ class che_장비매매 extends Command\GeneralCommand{
];
if($itemCode === 'None'){
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralValue($itemType, $itemTypeName, '!=', 'None');
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralValue($itemType, $itemTypeName, '!=', 'None');
}
else if($itemCode == $general->getVar($itemType)){
$this->runnableConstraints[] = ConstraintHelper::AlwaysFail('이미 가지고 있습니다.');
$this->fullConditionConstraints[] = ConstraintHelper::AlwaysFail('이미 가지고 있습니다.');
}
else if($itemType != 'item' && !buildItemClass($general->getVar($itemType))->isBuyable()){
$this->runnableConstraints[] = ConstraintHelper::AlwaysFail('이미 진귀한 것을 가지고 있습니다.');
$this->fullConditionConstraints[] = ConstraintHelper::AlwaysFail('이미 진귀한 것을 가지고 있습니다.');
}
}
public function getCost():array{
@@ -128,7 +136,7 @@ class che_장비매매 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -37,7 +37,7 @@ class che_전투태세 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
@@ -65,7 +65,7 @@ class che_전투태세 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -44,7 +44,7 @@ class che_정착장려 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
@@ -118,7 +118,7 @@ class che_정착장려 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -44,7 +44,7 @@ class che_주민선정 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
@@ -119,7 +119,7 @@ class che_주민선정 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+89 -70
View File
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -11,9 +15,9 @@ use \sammo\{
Command
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
tryUniqueItemLottery
};
@@ -22,108 +26,123 @@ use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_증여 extends Command\GeneralCommand{
class che_증여 extends Command\GeneralCommand
{
static protected $actionName = '증여';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 사망 직전에 '증여' 턴을 넣을 수 있으므로, 존재하지 않는 장수여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('isGold', $this->arg)){
if (!key_exists('isGold', $this->arg)) {
return false;
}
if(!key_exists('amount', $this->arg)){
if (!key_exists('amount', $this->arg)) {
return false;
}
if(!key_exists('destGeneralID', $this->arg)){
if (!key_exists('destGeneralID', $this->arg)) {
return false;
}
$isGold = $this->arg['isGold'];
$amount = $this->arg['amount'];
$destGeneralID = $this->arg['destGeneralID'];
if(!is_numeric($amount)){
if (!is_numeric($amount)) {
return false;
}
$amount = Util::round($amount, -2);
$amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount);
if($amount <= 0){
if ($amount <= 0) {
return false;
}
if(!is_bool($isGold)){
if (!is_bool($isGold)) {
return false;
}
if(!is_int($destGeneralID)){
if (!is_int($destGeneralID)) {
return false;
}
if($destGeneralID <= 0){
if ($destGeneralID <= 0) {
return false;
}
if($destGeneralID == $this->generalObj->getID()){
if ($destGeneralID == $this->generalObj->getID()) {
return false;
}
$this->arg = [
'isGold'=>$isGold,
'amount'=>$amount,
'destGeneralID'=>$destGeneralID
'isGold' => $isGold,
'amount' => $amount,
'destGeneralID' => $destGeneralID
];
return true;
}
protected function init(){
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->runnableConstraints=[
ConstraintHelper::NotBeNeutral(),
$this->fullConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::FriendlyDestGeneral()
];
if($this->arg['isGold']){
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralGold(GameConst::$generalMinimumGold);
if ($this->arg['isGold']) {
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralGold(GameConst::$generalMinimumGold);
} else {
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralRice(GameConst::$generalMinimumRice);
}
else{
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralRice(GameConst::$generalMinimumRice);
}
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
return "{$name}(통솔경험)";
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief(): string
{
$destGeneralName = $this->destGeneralObj->getName();
$resText = $this->arg['isGold']?'금':'쌀';
$resText = $this->arg['isGold'] ? '금' : '쌀';
$name = $this->getName();
return "{$destGeneralName}】에게 {$resText} {$this->arg['amount']}{$name}";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -134,13 +153,13 @@ class che_증여 extends Command\GeneralCommand{
$isGold = $this->arg['isGold'];
$amount = $this->arg['amount'];
$resKey = $isGold?'gold':'rice';
$resName = $isGold?'금':'쌀';
$resKey = $isGold ? 'gold' : 'rice';
$resName = $isGold ? '금' : '쌀';
$destGeneral = $this->destGeneralObj;
$amount = Util::valueFit($amount, 0, $general->getVar($resKey) - ($isGold?GameConst::$generalMinimumGold:GameConst::$generalMinimumRice));
$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);
@@ -169,35 +188,35 @@ class che_증여 extends Command\GeneralCommand{
//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());
$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>
자신의 자금이나 군량을 다른 장수에게 증여합니다.<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();
}
}
}
+2 -2
View File
@@ -38,7 +38,7 @@ class che_집합 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
@@ -65,7 +65,7 @@ class che_집합 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+178 -167
View File
@@ -1,18 +1,24 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil, Session, KVStorage,
General,
use\sammo\{
DB,
Util,
JosaUtil,
Session,
KVStorage,
General,
ActionLogger,
GameConst, GameUnitConst,
GameConst,
GameUnitConst,
LastTurn,
Command,
ServConfig
};
use function \sammo\{
use function\sammo\{
getTechCall,
tryUniqueItemLottery,
getTechAbil
@@ -23,7 +29,8 @@ use \sammo\Constraint\ConstraintHelper;
class che_징병 extends Command\GeneralCommand{
class che_징병 extends Command\GeneralCommand
{
static protected $actionName = '징병';
static protected $costOffset = 1;
static public $reqArg = true;
@@ -37,7 +44,7 @@ class che_징병 extends Command\GeneralCommand{
protected $reqCrewType;
/** @var \sammo\GameUnitDetail */
protected $currCrewType;
static protected $isInitStatic = false;
protected static function initStatic()
{
@@ -45,52 +52,64 @@ class che_징병 extends Command\GeneralCommand{
static::$defaultAtmos = GameConst::$defaultAtmosLow;
}
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('crewType', $this->arg)){
if (!key_exists('crewType', $this->arg)) {
return false;
}
if(!key_exists('amount', $this->arg)){
if (!key_exists('amount', $this->arg)) {
return false;
}
$crewType = $this->arg['crewType'];
$amount = $this->arg['amount'];
if(!is_int($crewType)){
if (!is_int($crewType)) {
return false;
}
if(!is_numeric($amount)){
if (!is_numeric($amount)) {
return false;
}
$amount = (int)$amount;
$amount = (int) $amount;
if(GameUnitConst::byID($crewType) === null){
if (GameUnitConst::byID($crewType) === null) {
return false;
}
if($amount < 0){
if ($amount < 0) {
return false;
}
$this->arg = [
'crewType'=>$crewType,
'amount'=>$amount
'crewType' => $crewType,
'amount' => $amount
];
return true;
}
protected function init(){
$general = $this->generalObj;
protected function init()
{
$this->setCity();
$this->setNation(['tech']);
$this->minConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqCityCapacity('pop', '주민', GameConst::$minAvailableRecruitPop + 100),
ConstraintHelper::ReqCityTrust(20),
];
}
protected function initWithArg()
{
$general = $this->generalObj;
$leadership = $general->getLeadership(false);
$currCrewType = $general->getCrewTypeObj();
$maxCrew = $leadership * 100;
$reqCrewType = GameUnitConst::byID($this->arg['crewType']);
if($reqCrewType->id == $currCrewType->id){
if ($reqCrewType->id == $currCrewType->id) {
$maxCrew -= $general->getVar('crew');
}
$this->maxCrew = Util::valueFit($this->arg['amount'], 100, $maxCrew);
@@ -100,9 +119,9 @@ class che_징병 extends Command\GeneralCommand{
$this->currCrewType = $currCrewType;
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
ConstraintHelper::NotBeNeutral(),
$this->fullConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqCityCapacity('pop', '주민', GameConst::$minAvailableRecruitPop + $reqCrew),
ConstraintHelper::ReqCityTrust(20),
@@ -111,26 +130,28 @@ class che_징병 extends Command\GeneralCommand{
ConstraintHelper::ReqGeneralCrewMargin($reqCrewType->id),
ConstraintHelper::AvailableRecruitCrewType($reqCrewType->id)
];
}
public function getBrief():string{
public function getBrief(): string
{
$crewTypeName = $this->reqCrewType->name;
$amount = $this->reqCrew;
$commandName = static::getName();
return "{$crewTypeName}{$amount}{$commandName}";
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
return "{$this->getName()}(통솔경험)";
}
public function getCost():array{
if(!$this->isArgValid){
public function getCost(): array
{
if (!$this->isArgValid) {
return [0, 0];
}
$reqGold = $this->reqCrewType->costWithTech($this->nation['tech'], $this->maxCrew);
$reqGold = $this->generalObj->onCalcDomestic('징병', 'cost', $reqGold, ['armType'=>$this->reqCrewType->armType]);
$reqGold = $this->generalObj->onCalcDomestic('징병', 'cost', $reqGold, ['armType' => $this->reqCrewType->armType]);
$reqGold *= static::$costOffset;
$reqRice = $this->maxCrew / 100;
@@ -138,17 +159,20 @@ class che_징병 extends Command\GeneralCommand{
$reqRice = Util::round($reqRice);
return [$reqGold, $reqRice];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -168,7 +192,7 @@ class che_징병 extends Command\GeneralCommand{
$logger = $general->getLogger();
if($reqCrewType->id == $currCrewType->id && $currCrew > 0){
if ($reqCrewType->id == $currCrewType->id && $currCrew > 0) {
$logger->pushGeneralActionLog("{$crewTypeName} <C>{$reqCrewText}</>명을 추가{$this->getName()}했습니다. <1>$date</>");
$train = ($currCrew * $general->getVar('train') + $reqCrew * static::$defaultTrain) / ($currCrew + $reqCrew);
$atmos = ($currCrew * $general->getVar('atmos') + $reqCrew * static::$defaultAtmos) / ($currCrew + $reqCrew);
@@ -176,8 +200,7 @@ class che_징병 extends Command\GeneralCommand{
$general->increaseVar('crew', $reqCrew);
$general->setVar('train', $train);
$general->setVar('atmos', $atmos);
}
else{
} else {
$logger->pushGeneralActionLog("{$crewTypeName} <C>{$reqCrewText}</>명을 {$this->getName()}했습니다. <1>$date</>");
$general->setVar('crewtype', $reqCrewType->id);
$general->setVar('crew', $reqCrew);
@@ -188,10 +211,10 @@ class che_징병 extends Command\GeneralCommand{
$newTrust = Util::valueFit($this->city['trust'] - ($reqCrew / $this->city['pop']) / static::$costOffset * 100, 0);
$db->update('city', [
'trust'=>$newTrust,
'pop'=>$this->city['pop'] - $reqCrew
'trust' => $newTrust,
'pop' => $this->city['pop'] - $reqCrew
], 'city=%i', $general->getCityID());
$exp = Util::round($reqCrew / 100);
$ded = Util::round($reqCrew / 100);
@@ -219,7 +242,7 @@ class che_징병 extends Command\GeneralCommand{
'js/recruitCrewForm.js'
];
}
public function getForm(): string
{
$db = DB::db();
@@ -227,74 +250,72 @@ class che_징병 extends Command\GeneralCommand{
$general = $this->generalObj;
[$nationLevel, $tech] = $db->queryFirstList('SELECT level,tech FROM nation WHERE nation=%i', $general->getNationID());
if(!$nationLevel){
if (!$nationLevel) {
$nationLevel = 0;
}
if(!$tech){
if (!$tech) {
$tech = 0;
}
$ownCities = [];
$ownRegions = [];
$year = $this->env['year'];
$startyear = $this->env['startyear'];
$relativeYear = $year - $startyear;
foreach(DB::db()->query('SELECT city, region from city where nation = %i', $general->getNationID()) as $city){
foreach (DB::db()->query('SELECT city, region from city where nation = %i', $general->getNationID()) as $city) {
$ownCities[$city['city']] = 1;
$ownRegions[$city['region']] = 1;
}
$leadership = $general->getLeadership();
$fullLeadership = $general->getLeadership(false);
$abil = getTechAbil($tech);
$armTypes = [];
foreach(GameUnitConst::allType() as $armType => $armName){
foreach (GameUnitConst::allType() as $armType => $armName) {
$armTypeCrews = [];
foreach(GameUnitConst::byType($armType) as $unit){
foreach (GameUnitConst::byType($armType) as $unit) {
$crewObj = new \stdClass;
$crewObj->showDefault = 'true';
$crewObj->id = $unit->id;
if($unit->reqTech == 0){
if ($unit->reqTech == 0) {
$crewObj->bgcolor = 'green';
}
else{
} else {
$crewObj->bgcolor = 'limegreen';
}
if(!$unit->isValid($ownCities, $ownRegions, $relativeYear, $tech)){
if (!$unit->isValid($ownCities, $ownRegions, $relativeYear, $tech)) {
$crewObj->showDefault = 'false';
$crewObj->bgcolor = 'red';
}
$crewObj->baseRice = $general->onCalcDomestic($this->getName(), 'rice', $unit->riceWithTech($tech), ['armType'=>$unit->armType]);
$crewObj->baseCost = $general->onCalcDomestic($this->getName(), 'cost', $unit->costWithTech($tech), ['armType'=>$unit->armType]);
$crewObj->baseRice = $general->onCalcDomestic($this->getName(), 'rice', $unit->riceWithTech($tech), ['armType' => $unit->armType]);
$crewObj->baseCost = $general->onCalcDomestic($this->getName(), 'cost', $unit->costWithTech($tech), ['armType' => $unit->armType]);
$crewObj->name = $unit->name;
$crewObj->attack = $unit->attack + $abil;
$crewObj->defence = $unit->defence + $abil;
$crewObj->speed = $unit->speed;
$crewObj->avoid = $unit->avoid;
if($this->env['show_img_level'] < 2) {
$crewObj->img = ServConfig::$sharedIconPath."/default.jpg";
if ($this->env['show_img_level'] < 2) {
$crewObj->img = ServConfig::$sharedIconPath . "/default.jpg";
} else {
$crewObj->img = ServConfig::$gameImagePath . "/crewtype" . $unit->id . ".png";
}
else{
$crewObj->img = ServConfig::$gameImagePath."/crewtype".$unit->id.".png";
}
$crewObj->baseRiceShort = round($crewObj->baseRice, 1);
$crewObj->baseCostShort = round($crewObj->baseCost, 1);
$crewObj->info = join('<br>', $unit->info);
$armTypeCrews[] = $crewObj;
}
$armTypes[] = [$armName, $armTypeCrews];
@@ -310,100 +331,90 @@ class che_징병 extends Command\GeneralCommand{
ob_start();
?>
<font size=2>병사를 모집합니다.
<?php if($commandName=='징병'): ?>
훈련과 사기치는 낮지만 가격이 저렴합니다.<br>
<?php else: ?>
훈련과 사기치는 높지만 자금이 많이 듭니다.
<?php endif; ?>
가능한 수보다 많게 입력하면 가능한 최대 병사를 모집합니다.<br>
이미 병사가 있는 경우 추가<?=$commandName?>되며, 병종이 다를경우는 기존의 병사는 소집해제됩니다.<br>
현재 <?=$commandName?> 가능한 병종은 <font color=green>녹색</font>으로 표시되며,<br>
현재 <?=$commandName?> 가능한 특수병종은 <font color=limegreen>초록색</font>으로 표시됩니다.<br>
<font size=2>병사를 모집합니다.
<?php if ($commandName == '징병') : ?>
훈련과 사기치는 낮지만 가격이 저렴합니다.<br>
<?php else : ?>
훈련과 사기치는 높지만 자금이 많이 듭니다.
<?php endif; ?>
가능한 수보다 많게 입력하면 가능한 최대 병사를 모집합니다.<br>
이미 병사가 있는 경우 추가<?= $commandName ?>되며, 병종이 다를경우는 기존의 병사는 소집해제됩니다.<br>
현재 <?= $commandName ?> 가능한 병종은 <font color=green>녹색</font>으로 표시되며,<br>
현재 <?= $commandName ?> 가능한 특수병종은 <font color=limegreen>초록색</font>으로 표시됩니다.<br>
<table class='tb_layout' style='margin:auto;'>
<thead>
<tr><td colspan=11><div style='float:right'><input type='checkbox' id="show_unavailable_troops">불가능한 병종 표시</input></div>
<?php if($commandName=='모병'): ?>
<div style='text-align:center;'>모병은 가격 2배의 자금이 소요됩니다.</div>
<?php endif; ?>
</td></tr>
<tr>
<td colspan=11 align=center class='bg2'>
현재 기술력 : <?=$techLevelText?>
현재 통솔 : <?=$leadership?><?=($leadership!=$fullLeadership)?"({$fullLeadership})":''?>
현재 병종 : <?=$crewTypeObj->name?>
현재 병사 : <?=$crew?>
현재 자금 : <?=$gold?>
</td>
</tr>
<tr>
<td width=64 align=center class='bg1'>사진</td>
<td width=64 align=center class='bg1'>병종</td>
<td width=40 align=center class='bg1'>공격</td>
<td width=40 align=center class='bg1'>방어</td>
<td width=40 align=center class='bg1'>기동</td>
<td width=40 align=center class='bg1'>회피</td>
<td width=40 align=center class='bg1'>가격</td>
<td width=40 align=center class='bg1'>군량</td>
<td width=180 align=center class='bg1'>병사수</td>
<td width=50 align=center class='bg1'>행동</td>
<td width=300 align=center class='bg1'>특징</td>
</tr>
</thead>
<tbody>
<?php foreach($armTypes as [$armName,$armTypeCrews]): ?>
<tr><td colspan=11><?=$armName?> 계열</td></tr>
<?php foreach($armTypeCrews as $crewObj): ?>
<tr
id="crewType<?=$crewObj->id?>"
class="show_default_<?=$crewObj->showDefault?>"
style='height:64px;background-color:<?=$crewObj->bgcolor?>'
data-rice="<?=$crewObj->baseRice?>"
data-cost="<?=$crewObj->baseCost?>"
>
<td style='background:#222222 no-repeat center url("<?=$crewObj->img?>");background-size:64px'></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->name?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->attack?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->defence?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->speed?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->avoid?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->baseCostShort?></td>
<td style='text-align:center;vertical-align:middle;'><?=$crewObj->baseRiceShort?></td>
<td style='text-align:center;vertical-align:middle;' class='input_form' data-crewtype='<?=$crewObj->id?>'>
<input type=button value='절반' class='btn_half'
><input type=button value='채우기' class='btn_fill'
><input type=button value='가득' class='btn_full'
><br>
<input type=text data-crewtype='<?=$crewObj->id?>' class=form_double name=double maxlength=3 size=3
style=text-align:right;color:white;background-color:black
>00명
<input type=text class=form_cost name=cost maxlength=5 size=5 readonly
style=text-align:right;color:white;background-color:black>원
</td>
<td style='position:relative;height:64px;'><input
type=submit value='<?=$commandName?>' class='submit_btn'
style='width:100%;height:44px;margin:10px 0;display:block;position: absolute;left:0;top:0;'
></td>
<td><?=$crewObj->info?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
<input type='hidden' id='amount' value='1'>
<input type='hidden' id='crewType' value='<?=$crewTypeObj->id?>'>
<script>
window.currentTech = <?=$tech?>;
window.leadership = <?=$leadership?>;
window.fullLeadership = <?=$fullLeadership?>;
window.currentCrewType = <?=$crewTypeObj->id?>;
window.currentCrew = <?=$crew?>;
window.currentGold = <?=$gold?>;
window.is모병 = <?=($this->getName()=='모병')?'true':'false'?>;
</script>
<?php
<table class='tb_layout' style='margin:auto;'>
<thead>
<tr>
<td colspan=11>
<div style='float:right'><input type='checkbox' id="show_unavailable_troops">불가능한 병종 표시</input></div>
<?php if ($commandName == '모병') : ?>
<div style='text-align:center;'>모병은 가격 2배의 자금이 소요됩니다.</div>
<?php endif; ?>
</td>
</tr>
<tr>
<td colspan=11 align=center class='bg2'>
현재 기술력 : <?= $techLevelText ?>
현재 통솔 : <?= $leadership ?><?= ($leadership != $fullLeadership) ? "({$fullLeadership})" : '' ?>
현재 병종 : <?= $crewTypeObj->name ?>
현재 병사 : <?= $crew ?>
현재 자금 : <?= $gold ?>
</td>
</tr>
<tr>
<td width=64 align=center class='bg1'>사진</td>
<td width=64 align=center class='bg1'>병종</td>
<td width=40 align=center class='bg1'>공격</td>
<td width=40 align=center class='bg1'>방어</td>
<td width=40 align=center class='bg1'>기동</td>
<td width=40 align=center class='bg1'>회피</td>
<td width=40 align=center class='bg1'>가격</td>
<td width=40 align=center class='bg1'>군량</td>
<td width=180 align=center class='bg1'>병사수</td>
<td width=50 align=center class='bg1'>행동</td>
<td width=300 align=center class='bg1'>특징</td>
</tr>
</thead>
<tbody>
<?php foreach ($armTypes as [$armName, $armTypeCrews]) : ?>
<tr>
<td colspan=11><?= $armName ?> 계열</td>
</tr>
<?php foreach ($armTypeCrews as $crewObj) : ?>
<tr id="crewType<?= $crewObj->id ?>" class="show_default_<?= $crewObj->showDefault ?>" style='height:64px;background-color:<?= $crewObj->bgcolor ?>' data-rice="<?= $crewObj->baseRice ?>" data-cost="<?= $crewObj->baseCost ?>">
<td style='background:#222222 no-repeat center url("<?= $crewObj->img ?>");background-size:64px'></td>
<td style='text-align:center;vertical-align:middle;'><?= $crewObj->name ?></td>
<td style='text-align:center;vertical-align:middle;'><?= $crewObj->attack ?></td>
<td style='text-align:center;vertical-align:middle;'><?= $crewObj->defence ?></td>
<td style='text-align:center;vertical-align:middle;'><?= $crewObj->speed ?></td>
<td style='text-align:center;vertical-align:middle;'><?= $crewObj->avoid ?></td>
<td style='text-align:center;vertical-align:middle;'><?= $crewObj->baseCostShort ?></td>
<td style='text-align:center;vertical-align:middle;'><?= $crewObj->baseRiceShort ?></td>
<td style='text-align:center;vertical-align:middle;' class='input_form' data-crewtype='<?= $crewObj->id ?>'>
<input type=button value='절반' class='btn_half'><input type=button value='채우기' class='btn_fill'><input type=button value='가득' class='btn_full'><br>
<input type=text data-crewtype='<?= $crewObj->id ?>' class=form_double name=double maxlength=3 size=3 style=text-align:right;color:white;background-color:black>00명
<input type=text class=form_cost name=cost maxlength=5 size=5 readonly style=text-align:right;color:white;background-color:black>원
</td>
<td style='position:relative;height:64px;'><input type=submit value='<?= $commandName ?>' class='submit_btn' style='width:100%;height:44px;margin:10px 0;display:block;position: absolute;left:0;top:0;'></td>
<td><?= $crewObj->info ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
<input type='hidden' id='amount' value='1'>
<input type='hidden' id='crewType' value='<?= $crewTypeObj->id ?>'>
<script>
window.currentTech = <?= $tech ?>;
window.leadership = <?= $leadership ?>;
window.fullLeadership = <?= $fullLeadership ?>;
window.currentCrewType = <?= $crewTypeObj->id ?>;
window.currentCrew = <?= $crew ?>;
window.currentGold = <?= $gold ?>;
window.is모병 = <?= ($this->getName() == '모병') ? 'true' : 'false' ?>;
</script>
<?php
return ob_get_clean();
}
}
}
+80 -63
View File
@@ -1,17 +1,21 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
use\sammo\{
DB,
Util,
JosaUtil,
General,
ActionLogger,
GameConst, GameUnitConst,
GameConst,
GameUnitConst,
LastTurn,
Command
};
use function \sammo\{
use function\sammo\{
tryUniqueItemLottery,
searchDistance,
printCitiesBasedOnDistance
@@ -23,89 +27,111 @@ use sammo\CityConst;
class che_첩보 extends Command\GeneralCommand{
class che_첩보 extends Command\GeneralCommand
{
static protected $actionName = '첩보';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('destCityID', $this->arg)){
if (!key_exists('destCityID', $this->arg)) {
return false;
}
if(!key_exists($this->arg['destCityID'], CityConst::all())){
if (!key_exists($this->arg['destCityID'], CityConst::all())) {
return false;
}
$this->arg = [
'destCityID'=>$this->arg['destCityID']
'destCityID' => $this->arg['destCityID']
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation(['tech']);
$this->setDestCity($this->arg['destCityID'], null);
$this->setDestNation($this->destCity['nation'], ['tech']);
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->minConditionConstraints = [
ConstraintHelper::NotOccupiedDestCity(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
public function getBrief():string{
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
$this->setDestNation($this->destCity['nation'], ['tech']);
[$reqGold, $reqRice] = $this->getCost();
$this->fullConditionConstraints = [
ConstraintHelper::NotOccupiedDestCity(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
public function getBrief(): string
{
$cityName = $this->destCity['name'];
return "{$cityName}】에 {$this->getName()} 실행";
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
[$reqGold, $reqRice] = $this->getCost();
$title = "{$name}(통솔경험";
if($reqGold > 0){
if ($reqGold > 0) {
$title .= ", 자금{$reqGold}";
}
if($reqRice > 0){
if ($reqRice > 0) {
$title .= ", 군량{$reqRice}";
}
$title .= ')';
return $title;
}
public function getCost():array{
public function getCost(): array
{
$env = $this->env;
return [$env['develcost'], $env['develcost']];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getFailString():string{
public function getFailString(): string
{
$commandName = $this->getName();
$failReason = $this->testRunnable();
if($failReason === null){
$failReason = $this->testFullConditionMet();
if ($failReason === null) {
throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집');
}
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
return "{$failReason} <G><b>{$destCityName}</b></>에 {$commandName} 실패.";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -124,13 +150,13 @@ class che_첩보 extends Command\GeneralCommand{
$logger = $general->getLogger();
$dist = searchDistance($general->getCityID(), 2, false)[$destCityID]??3;
$dist = searchDistance($general->getCityID(), 2, false)[$destCityID] ?? 3;
$destCityGeneralList = $db->query('SELECT crew, crewtype FROM general WHERE city = %i AND nation = %i', $destCityID, $destNationID);
$totalCrew = Util::arraySum($destCityGeneralList, 'crew');
$totalGenCnt = count($destCityGeneralList);
$byCrewType = Util::arrayGroupBy($destCityGeneralList, 'crewtype');
$popText = number_format($destCity['pop']);
$trustText = number_format($destCity['trust'], 1);
$agriText = number_format($destCity['agri']);
@@ -143,50 +169,43 @@ class che_첩보 extends Command\GeneralCommand{
$cityDevel = "【<M>첩보</>】농업:{$agriText}, 상업:{$commText}, 치안:{$secuText}, 수비:{$defText}, 성벽:{$wallText}";
$logger->pushGeneralActionLog("누군가가 <G><b>{$destCityName}</b></>{$josaUl} 살피는 것 같습니다.");
if($dist < 1){
if ($dist < 1) {
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>의 정보를 많이 얻었습니다. <1>$date</>");
$logger->pushGeneralActionLog($cityBrief, ActionLogger::RAWTEXT);
$logger->pushGeneralActionLog($cityDevel, ActionLogger::RAWTEXT);
$logger->pushGeneralActionLog('【<S>병종</>】 '. join(' ', Util::mapWithKey(function($crewType, $value){
$logger->pushGeneralActionLog('【<S>병종</>】 ' . join(' ', Util::mapWithKey(function ($crewType, $value) {
$crewTypeText = mb_substr(GameUnitConst::byID($crewType)->name, 0, 2);
$cnt = count($value);
return "{$crewTypeText}:{$cnt}";
}, $destCityGeneralList)), ActionLogger::RAWTEXT);
if($this->destNation['nation'] && $general->getNationID()){
if ($this->destNation['nation'] && $general->getNationID()) {
$techDiff = floor($this->destNation['tech']) - floor($this->nation['tech']);
if($techDiff >= 1000){
if ($techDiff >= 1000) {
$techText = '<M>↑</>압도';
}
else if($techDiff >= 250){
} else if ($techDiff >= 250) {
$techText = '<Y>▲</>우위';
}
else if($techDiff >= -250){
} else if ($techDiff >= -250) {
$techText = '<W>↕</>대등';
}
else if($techDiff >= -1000){
} else if ($techDiff >= -1000) {
$techText = '<G>▼</>열위';
}
else{
} else {
$techText = '<C>↓</>미미';
}
$logger->pushGeneralActionLog("【<span class='ev_notice'>{$this->destNation['name']}</span>】아국대비기술:{$techText}");
}
}
else if($dist == 2){
} else if ($dist == 2) {
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>의 정보를 어느 정도 얻었습니다. <1>$date</>");
$logger->pushGeneralActionLog($cityBrief, ActionLogger::RAWTEXT);
$logger->pushGeneralActionLog($cityDevel, ActionLogger::RAWTEXT);
}
else{
} else {
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>의 소문만 들을 수 있었습니다. <1>$date</>");
$logger->pushGeneralActionLog($cityBrief, ActionLogger::RAWTEXT);
}
$exp = Util::randRangeInt(1, 100);
$ded = Util::randRangeInt(1, 70);
[$reqGold, $reqRice] = $this->getCost();
$general->increaseVarWithLimit('gold', -$reqGold, 0);
$general->increaseVarWithLimit('rice', -$reqRice, 0);
@@ -212,19 +231,17 @@ class che_첩보 extends Command\GeneralCommand{
$currentCityID = $this->generalObj->getCityID();
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 도시에 첩보를 실행합니다.<br>
인접도시일 경우 많은 정보를 얻을 수 있습니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
<?=\sammo\optionsForCities()?><br>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<br>
<br>
<?=printCitiesBasedOnDistance($currentCityID, 3)?>
<?= \sammo\getMapHtml() ?><br>
선택된 도시에 첩보를 실행합니다.<br>
인접도시일 경우 많은 정보를 얻을 수 있습니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
<?= \sammo\optionsForCities() ?><br>
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<br>
<br>
<?= printCitiesBasedOnDistance($currentCityID, 3) ?>
<?php
return ob_get_clean();
return ob_get_clean();
}
}
}
+91 -63
View File
@@ -1,17 +1,21 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
use\sammo\{
DB,
Util,
JosaUtil,
General,
ActionLogger,
GameConst, GameUnitConst,
GameConst,
GameUnitConst,
LastTurn,
Command
};
use function \sammo\{
use function\sammo\{
tryUniqueItemLottery,
processWar
};
@@ -22,38 +26,58 @@ use sammo\CityConst;
class che_출병 extends Command\GeneralCommand{
class che_출병 extends Command\GeneralCommand
{
static protected $actionName = '출병';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('destCityID', $this->arg)){
if (!key_exists('destCityID', $this->arg)) {
return false;
}
if(!key_exists($this->arg['destCityID'], CityConst::all())){
if (!key_exists($this->arg['destCityID'], CityConst::all())) {
return false;
}
$this->arg = [
'destCityID'=>$this->arg['destCityID']
'destCityID' => $this->arg['destCityID']
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation(['war', 'gennum', 'tech', 'gold', 'rice', 'color', 'type', 'level', 'capital']);
$this->setDestCity($this->arg['destCityID'], null);
[$reqGold, $reqRice] = $this->getCost();
$relYear = $this->env['year'] - $this->env['startyear'];
$this->minConditionConstraints = [
ConstraintHelper::NotOpeningPart($relYear+1),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralCrew(),
ConstraintHelper::ReqGeneralRice($reqRice),
];
$this->runnableConstraints=[
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
[$reqGold, $reqRice] = $this->getCost();
$relYear = $this->env['year'] - $this->env['startyear'];
$this->fullConditionConstraints = [
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::NotSameDestCity(),
ConstraintHelper::NotBeNeutral(),
@@ -65,36 +89,42 @@ class che_출병 extends Command\GeneralCommand{
];
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
//[$reqGold, $reqRice] = $this->getCost();
return "{$name}(통솔경험, 병종숙련, 군량↓)";
}
public function getCost():array{
return [0, Util::round($this->generalObj->getVar('crew')/100)];
public function getCost(): array
{
return [0, Util::round($this->generalObj->getVar('crew') / 100)];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
$josaRo = JosaUtil::pick($destCityName, '로');
return "{$destCityName}{$josaRo} {$commandName}";
}
public function getFailString():string{
public function getFailString(): string
{
$commandName = $this->getName();
$failReason = $this->testRunnable();
if($failReason === null){
$failReason = $this->testFullConditionMet();
if ($failReason === null) {
throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집');
}
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
@@ -102,8 +132,9 @@ class che_출병 extends Command\GeneralCommand{
return "{$failReason} <G><b>{$destCityName}</b></>{$josaRo} {$commandName} 실패.";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -117,10 +148,10 @@ class che_출병 extends Command\GeneralCommand{
$attackerCityID = $general->getCityID();
$finalTargetCityID = $this->destCity['city'];
$finalTargetCityName = $this->destCity['name'];
$logger = $general->getLogger();
@@ -136,62 +167,61 @@ class che_출병 extends Command\GeneralCommand{
do {
//1: 최단 거리 도시 중 공격 대상이 있는가 확인
//2: 최단 거리 + 1 도시 중 공격 대상이 있는가 확인
foreach($distanceList as $dist => $distCitiesInfo){
if($dist > $minDist + 1){
foreach ($distanceList as $dist => $distCitiesInfo) {
if ($dist > $minDist + 1) {
break;
}
$currDist = $dist;
foreach($distCitiesInfo as [$distCityID, $distCityNation]){
if($distCityNation !== $attackerNationID){
foreach ($distCitiesInfo as [$distCityID, $distCityNation]) {
if ($distCityNation !== $attackerNationID) {
$candidateCities[] = $distCityID;
}
}
if($candidateCities){
if ($candidateCities) {
break 2;
}
}
//3: 최단 거리 도시 중 아군 도시 선택
foreach($distanceList[$minDist] as [$distCityID, $distCityNation]){
if($distCityNation === $attackerNationID){
foreach ($distanceList[$minDist] as [$distCityID, $distCityNation]) {
if ($distCityNation === $attackerNationID) {
$candidateCities[] = $distCityID;
}
}
}while(false);
$defenderCityID = (int)Util::choiceRandom($candidateCities);
} while (false);
$defenderCityID = (int) Util::choiceRandom($candidateCities);
$defenderCityName = $this->destCity['name'];
$this->setDestCity($defenderCityID, null);
$this->setDestCity($defenderCityID);
$josaRo = JosaUtil::pick($defenderCityName, '로');
if($attackerNationID == $defenderNationID){
$logger->pushGeneralActionLog("본국입니다. <G><b>{$defenderCityName}</b></>{$josaRo} 으로 이동합니다. <1>$date</>");
$this->alternative = new che_이동($general, $this->env, ['destCityID'=>$defenderCityID]);
if ($attackerNationID == $defenderNationID) {
$logger->pushGeneralActionLog("본국입니다. <G><b>{$defenderCityName}</b></>{$josaRo} 으로 이동합니다. <1>$date</>");
$this->alternative = new che_이동($general, $this->env, ['destCityID' => $defenderCityID]);
return false;
}
if($finalTargetCityID !== $defenderCityID){
if ($finalTargetCityID !== $defenderCityID) {
$josaRo = JosaUtil::pick($finalTargetCityName, '로');
$josaUl = JosaUtil::pick($defenderCityName, '을');
if($minDist == $currDist){
if ($minDist == $currDist) {
$logger->pushGeneralActionLog("<G><b>{$finalTargetCityName}</b></>{$josaRo} 가기 위해 <G><b>{$defenderCityName}</b></>{$josaUl} 거쳐야 합니다. <1>$date</>");
}
else{
} else {
$logger->pushGeneralActionLog("<G><b>{$finalTargetCityName}</b></>{$josaRo} 가는 도중 <G><b>{$defenderCityName}</b></>{$josaUl} 거치기로 합니다. <1>$date</>");
}
}
$db->update('city', [
'state'=>43,
'term'=>3
'state' => 43,
'term' => 3
], 'city=%i', $defenderCityID);
$this->destCity['state'] = 43;
$this->destCity['term'] = 3;
$general->addDex($general->getCrewTypeObj(), $general->getVar('crew')/100);
$general->addDex($general->getCrewTypeObj(), $general->getVar('crew') / 100);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
@@ -200,7 +230,7 @@ class che_출병 extends Command\GeneralCommand{
tryUniqueItemLottery($general);
$general->applyDB($db);
return true;
}
@@ -216,17 +246,15 @@ class che_출병 extends Command\GeneralCommand{
$srcCityName = \sammo\CityConst::byID($this->generalObj->getCityID())->name;
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 도시를 향해 침공을 합니다.<br>
침공 경로에 적군의 도시가 있다면 전투를 벌입니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<?=$srcCityName?> =><select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'>
<?=\sammo\optionsForCities()?><br>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<br>
<?= \sammo\getMapHtml() ?><br>
선택된 도시를 향해 침공을 합니다.<br>
침공 경로에 적군의 도시가 있다면 전투를 벌입니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<?= $srcCityName ?> =><select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'>
<?= \sammo\optionsForCities() ?><br>
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<br>
<?php
return ob_get_clean();
return ob_get_clean();
}
}
}
+2 -2
View File
@@ -38,7 +38,7 @@ class che_하야 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::NotLord(),
@@ -58,7 +58,7 @@ class che_하야 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+2 -2
View File
@@ -40,7 +40,7 @@ class che_해산 extends Command\GeneralCommand{
$this->setCity();
$this->setNation(['gennum']);
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::BeLord(),
ConstraintHelper::WanderingNation(),
];
@@ -59,7 +59,7 @@ class che_해산 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+65 -47
View File
@@ -1,9 +1,12 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
use\sammo\{
DB,
Util,
JosaUtil,
General,
ActionLogger,
GameConst,
LastTurn,
@@ -11,9 +14,9 @@ use \sammo\{
Command
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
tryUniqueItemLottery
};
@@ -22,84 +25,99 @@ use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_헌납 extends Command\GeneralCommand{
class che_헌납 extends Command\GeneralCommand
{
static protected $actionName = '헌납';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('isGold', $this->arg)){
if (!key_exists('isGold', $this->arg)) {
return false;
}
if(!key_exists('amount', $this->arg)){
if (!key_exists('amount', $this->arg)) {
return false;
}
$isGold = $this->arg['isGold'];
$amount = $this->arg['amount'];
if(!is_numeric($amount)){
if (!is_numeric($amount)) {
return false;
}
$amount = Util::round($amount, -2);
$amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount);
if(!is_bool($isGold)){
if (!is_bool($isGold)) {
return false;
}
$this->arg = [
'isGold'=>$isGold,
'amount'=>$amount
'isGold' => $isGold,
'amount' => $amount
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$this->runnableConstraints=[
ConstraintHelper::NotBeNeutral(),
$this->minConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
];
if($this->arg['isGold']){
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralGold(GameConst::$generalMinimumGold);
}
else{
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralRice(GameConst::$generalMinimumRice);
}
}
protected function initWithArg()
{
$this->fullConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
];
if ($this->arg['isGold']) {
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralGold(GameConst::$generalMinimumGold);
} else {
$this->fullConditionConstraints[] = ConstraintHelper::ReqGeneralRice(GameConst::$generalMinimumRice);
}
}
public function getBrief(): string
{
$resText = $this->arg['isGold']?'금':'쌀';
$resText = $this->arg['isGold'] ? '금' : '쌀';
$name = $this->getName();
return "{$resText} {$this->arg['amount']}{$name}";
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
return "{$name}(통솔경험)";
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -110,16 +128,16 @@ class che_헌납 extends Command\GeneralCommand{
$isGold = $this->arg['isGold'];
$amount = $this->arg['amount'];
$resKey = $isGold?'gold':'rice';
$resName = $isGold?'금':'쌀';
$resKey = $isGold ? 'gold' : 'rice';
$resName = $isGold ? '금' : '쌀';
$amount = Util::valueFit($amount, 0, $general->getVar($resKey));
$amountText = number_format($amount, 0);
$logger = $general->getLogger();
$db->update('nation', [
$resKey=>$db->sqleval('%b + %i', $resKey, $amount)
$resKey => $db->sqleval('%b + %i', $resKey, $amount)
], 'nation=%i', $general->getNationID());
$general->increaseVarWithLimit($resKey, -$amount, 0);
@@ -144,17 +162,17 @@ class che_헌납 extends Command\GeneralCommand{
{
ob_start();
?>
자신의 자금이나 군량을 국가 재산으로 헌납합니다.<br>
<select id='isGold' name="isGold" size=1 style=color:white;background-color:black>
<option value='true'>금</option>
<option value='false'>쌀</option>
</select>
<select name=amount id='amount' size=1 style=text-align:right;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>
자신의 자금이나 군량을 국가 재산으로 헌납합니다.<br>
<select id='isGold' name="isGold" size=1 style=color:white;background-color:black>
<option value='true'>금</option>
<option value='false'>쌀</option>
</select>
<select name=amount id='amount' size=1 style=text-align:right;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();
}
}
}
+101 -76
View File
@@ -1,17 +1,21 @@
<?php
namespace sammo\Command\General;
use \sammo\{
DB, Util, JosaUtil,
General,
use\sammo\{
DB,
Util,
JosaUtil,
General,
ActionLogger,
GameConst, GameUnitConst,
GameConst,
GameUnitConst,
LastTurn,
Command
};
use function \sammo\{
use function\sammo\{
searchDistance,
printCitiesBasedOnDistance
};
@@ -22,44 +26,44 @@ use sammo\CityConst;
class che_화계 extends Command\GeneralCommand{
class che_화계 extends Command\GeneralCommand
{
static protected $actionName = '화계';
static public $reqArg = true;
static protected $statType = 'intel';
static protected $injuryGeneral = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('destCityID', $this->arg)){
if (!key_exists('destCityID', $this->arg)) {
return false;
}
if(!key_exists($this->arg['destCityID'], CityConst::all())){
if (!key_exists($this->arg['destCityID'], CityConst::all())) {
return false;
}
$this->arg = [
'destCityID'=>$this->arg['destCityID']
'destCityID' => $this->arg['destCityID']
];
return true;
}
protected function calcSabotageAttackProb():float{
protected function calcSabotageAttackProb(): float
{
$statType = static::$statType;
$general = $this->generalObj;
$nation = $this->nation;
if($statType === 'leadership'){
if ($statType === 'leadership') {
$genScore = $general->getLeadership();
}
else if($statType === 'strength'){
} else if ($statType === 'strength') {
$genScore = $general->getStrength();
}
else if($statType === 'intel'){
} else if ($statType === 'intel') {
$genScore = $general->getIntel();
}
else{
} else {
throw new \sammo\MustNotBeReachedException();
}
@@ -68,29 +72,27 @@ class che_화계 extends Command\GeneralCommand{
return $prob;
}
protected function calcSabotageDefenceProb(array $destCityGeneralList):float{
protected function calcSabotageDefenceProb(array $destCityGeneralList): float
{
$statType = static::$statType;
$destCity = $this->destCity;
$destNation = $this->destNation;
$destNationID = $destNation['nation'];
$maxGenScore = 0;
foreach($destCityGeneralList as $destGeneral){
foreach ($destCityGeneralList as $destGeneral) {
/** @var General $destGeneral */
if($destGeneral->getNationID() != $destNationID){
if ($destGeneral->getNationID() != $destNationID) {
continue;
}
if($statType === 'leadership'){
if ($statType === 'leadership') {
$genScore = $destGeneral->getLeadership();
}
else if($statType === 'strength'){
} else if ($statType === 'strength') {
$genScore = $destGeneral->getStrength();
}
else if($statType === 'intel'){
} else if ($statType === 'intel') {
$genScore = $destGeneral->getIntel();
}
else{
} else {
throw new \sammo\MustNotBeReachedException();
}
$maxGenScore = max($maxGenScore, $genScore);
@@ -103,17 +105,35 @@ class che_화계 extends Command\GeneralCommand{
return $prob;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setDestCity($this->arg['destCityID'], null); //xxx: 이대로라면 메인 페이지 갱신시마다 DB query를 하게 된다.
[$reqGold, $reqRice] = $this->getCost();
$this->minConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
$this->setDestNation($this->destCity['nation']);
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
@@ -128,58 +148,65 @@ class che_화계 extends Command\GeneralCommand{
];
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$statTypeBase = [
'leadership'=>'통솔경험',
'strength'=>'무력경험',
'intel'=>'지력경험',
'leadership' => '통솔경험',
'strength' => '무력경험',
'intel' => '지력경험',
];
$statType = $statTypeBase[static::$statType];
[$reqGold, $reqRice] = $this->getCost();
$title = "{$name}({$statType}";
if($reqGold > 0){
if ($reqGold > 0) {
$title .= ", 자금{$reqGold}";
}
if($reqRice > 0){
if ($reqRice > 0) {
$title .= ", 군량{$reqRice}";
}
$title .= ')';
return $title;
}
public function getCost():array{
public function getCost(): array
{
$env = $this->env;
$cost = $env['develcost'] * 5;
return [$cost, $cost];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
return "{$destCityName}】에 {$commandName}실행";
}
public function getFailString():string{
public function getFailString(): string
{
$commandName = $this->getName();
$failReason = $this->testRunnable();
if($failReason === null){
$failReason = $this->testFullConditionMet();
if ($failReason === null) {
throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집');
}
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
return "{$failReason} <G><b>{$destCityName}</b></>에 {$commandName} 실패.";
}
protected function affectDestCity(int $injuryCount){
protected function affectDestCity(int $injuryCount)
{
$general = $this->generalObj;
$date = $general->getTurnTime($general::TURNTIME_HM);
@@ -198,9 +225,9 @@ class che_화계 extends Command\GeneralCommand{
$destCity['comm'] -= $commAmount;
DB::db()->update('city', [
'state'=>32,
'agri'=>$destCity['agri'],
'comm'=>$destCity['comm']
'state' => 32,
'agri' => $destCity['agri'],
'comm' => $destCity['comm']
], 'city=%i', $destCityID);
$agriAmountText = number_format($agriAmount);
@@ -217,8 +244,9 @@ class che_화계 extends Command\GeneralCommand{
);
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -239,13 +267,13 @@ class che_화계 extends Command\GeneralCommand{
$logger = $general->getLogger();
$dist = searchDistance($general->getCityID(), 5, false)[$destCityID]??99;
$dist = searchDistance($general->getCityID(), 5, false)[$destCityID] ?? 99;
$destCityGeneralList = [];
$cityGeneralID = $db->queryFirstColumn('SELECT no FROM general WHERE city = %i AND nation = %i', $destCityID, $destNationID);
$destCityGeneralList = General::createGeneralObjListFromDB($cityGeneralID, ['name', 'city', 'nation', 'officer_level', 'leadership', 'horse', 'strength', 'weapon', 'intel', 'book', 'item', 'last_turn', 'injury', 'special', 'special2', 'injury', 'crew', 'atmos', 'train'], 2);
foreach($destCityGeneralList as &$destCityGeneral){
foreach ($destCityGeneralList as &$destCityGeneral) {
$destCityGeneral->setRawCity($this->destCity);
unset($destCityGeneral);
}
@@ -255,7 +283,7 @@ class che_화계 extends Command\GeneralCommand{
$prob = GameConst::$sabotageDefaultProb + $this->calcSabotageAttackProb() - $this->calcSabotageDefenceProb($destCityGeneralList);
$prob /= $dist;
if(!Util::randBool($prob)){
if (!Util::randBool($prob)) {
$josaYi = JosaUtil::pick($commandName, '이');
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>에 {$commandName}{$josaYi} 실패했습니다. <1>$date</>");
@@ -267,7 +295,7 @@ class che_화계 extends Command\GeneralCommand{
$general->increaseVarWithLimit('rice', -$reqRice, 0);
$general->addExperience($exp);
$general->addDedication($ded);
$general->increaseVar($statType.'_exp', 1);
$general->increaseVar($statType . '_exp', 1);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
@@ -275,17 +303,16 @@ class che_화계 extends Command\GeneralCommand{
return false;
}
if(static::$injuryGeneral){
if (static::$injuryGeneral) {
$injuryCount = \sammo\SabotageInjury($destCityGeneralList, '계략');
}
else{
} else {
$injuryCount = 0;
}
$this->affectDestCity($injuryCount);
$itemObj = $general->getItem();
if($itemObj->isConsumableNow('GeneralCommand', '계략') && $itemObj->isConsumableNow('GeneralCommand', '계략')){
if ($itemObj->isConsumableNow('GeneralCommand', '계략') && $itemObj->isConsumableNow('GeneralCommand', '계략')) {
$itemName = $itemObj->getName();
$itemRawName = $itemObj->getRawName();
$josaUl = JosaUtil::pick($itemRawName, '을');
@@ -295,13 +322,13 @@ class che_화계 extends Command\GeneralCommand{
$exp = Util::randRangeInt(201, 300);
$ded = Util::randRangeInt(141, 210);
[$reqGold, $reqRice] = $this->getCost();
$general->increaseVarWithLimit('gold', -$reqGold, 0);
$general->increaseVarWithLimit('rice', -$reqRice, 0);
$general->addExperience($exp);
$general->addDedication($ded);
$general->increaseVar($statType.'_exp', 1);
$general->increaseVar($statType . '_exp', 1);
$general->increaseRankVar('firenum', 1);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
@@ -325,18 +352,16 @@ class che_화계 extends Command\GeneralCommand{
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 도시에 <?=$commandName?><?=$josaUl?> 실행합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
<?=\sammo\optionsForCities()?><br>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<br>
<br>
<?=printCitiesBasedOnDistance($currentCityID, 2)?>
<?= \sammo\getMapHtml() ?><br>
선택된 도시에 <?= $commandName ?><?= $josaUl ?> 실행합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
<?= \sammo\optionsForCities() ?><br>
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<br>
<br>
<?= printCitiesBasedOnDistance($currentCityID, 2) ?>
<?php
return ob_get_clean();
}
}
}
+2 -2
View File
@@ -35,7 +35,7 @@ class che_훈련 extends Command\GeneralCommand{
$this->setCity();
$this->setNation();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
@@ -73,7 +73,7 @@ class che_훈련 extends Command\GeneralCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+4 -2
View File
@@ -14,8 +14,10 @@ class 휴식 extends Command\GeneralCommand{
return true;
}
protected function init(){
$this->runnableConstraints=[];
protected function init()
{
$this->minConditionConstraints=[];
$this->fullConditionConstraints=[];
}
public function getCost():array{
+5 -6
View File
@@ -29,7 +29,6 @@ use sammo\Event\Action;
class che_감축 extends Command\NationCommand{
static protected $actionName = '감축';
static public $reqArg = false;
protected function argTest():bool{
$this->arg = [];
@@ -43,10 +42,10 @@ class che_감축 extends Command\NationCommand{
$env = $this->env;
if($general->getNationID()===0){
$this->reservableConstraints=[
$this->permissionConstraints=[
ConstraintHelper::NotBeNeutral(),
];
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
];
return;
@@ -54,13 +53,13 @@ class che_감축 extends Command\NationCommand{
$this->setCity();
$this->setNation(['gold', 'rice', 'capset', 'capital']);
$this->setDestCity($this->nation['capital'], null);
$this->setDestCity($this->nation['capital']);
[$reqGold, $reqRice] = $this->getCost();
$origCityLevel = CityConst::byID($this->nation['capital'])->level;
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
@@ -136,7 +135,7 @@ class che_감축 extends Command\NationCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+76 -55
View File
@@ -1,20 +1,25 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
Message, MessageTarget
Message,
MessageTarget
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
@@ -24,34 +29,37 @@ use function \sammo\{
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_급습 extends Command\NationCommand{
class che_급습 extends Command\NationCommand
{
static protected $actionName = '급습';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('destNationID', $this->arg)){
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if(!is_int($destNationID)){
if (!is_int($destNationID)) {
return false;
}
if($destNationID < 1){
if ($destNationID < 1) {
return false;
}
$this->arg = [
'destNationID'=>$destNationID
'destNationID' => $destNationID
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
@@ -59,54 +67,71 @@ class che_급습 extends Command\NationCommand{
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->minConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand(),
];
}
protected function initWithArg()
{
$this->setDestNation($this->arg['destNationID'], null);
$this->runnableConstraints=[
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::AllowDiplomacyWithTerm(
1, 12,
1,
12,
'선포 12개월 이상인 상대국에만 가능합니다.'
),
ConstraintHelper::AvailableStrategicCommand(),
];
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn()+1;
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount*16)*10);
$nextTerm = Util::round(sqrt($genCount * 16) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}】에 {$commandName}";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -144,7 +169,7 @@ class che_급습 extends Command\NationCommand{
$broadcastMessage = "<Y>{$generalName}</>{$josaYi} <G><b>{$destNationName}</b></>에 <M>{$commandName}</>{$josaUl} 발동하였습니다.";
$nationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach($nationGeneralList as $nationGeneralID){
foreach ($nationGeneralList as $nationGeneralID) {
$nationGeneralLogger = new ActionLogger($nationGeneralID, $nationID, $year, $month);
$nationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$nationGeneralLogger->flush();
@@ -155,7 +180,7 @@ class che_급습 extends Command\NationCommand{
$broadcastMessage = "아국에 <M>{$commandName}</>{$josaYiCommand} 발동되었습니다.";
$destNationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach($destNationGeneralList as $destNationGeneralID){
foreach ($destNationGeneralList as $destNationGeneralID) {
$destNationGeneralLogger = new ActionLogger($destNationGeneralID, $destNationID, $year, $month);
$destNationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$destNationGeneralLogger->flush();
@@ -166,12 +191,12 @@ class che_급습 extends Command\NationCommand{
$destNationLogger->flush();
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <D><b>{$destNationName}</b></>에 <M>{$commandName}</>{$josaUl} 발동");
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$db->update('diplomacy', [
'term'=>$db->sqleval('`term` - %i', 3),
'term' => $db->sqleval('`term` - %i', 3),
], '(me = %i AND you = %i) OR (you = %i AND me = %i)', $nationID, $destNationID, $nationID, $destNationID);
$general->applyDB($db);
@@ -192,39 +217,35 @@ class che_급습 extends Command\NationCommand{
$nationID = $generalObj->getNationID();
$nationList = [];
$testTurn = new LastTurn($this->getName(), null, $this->getPreReqTurn());
foreach(getAllNationStaticInfo() as $destNation){
if($destNation['nation'] == $nationID){
foreach (getAllNationStaticInfo() as $destNation) {
if ($destNation['nation'] == $nationID) {
continue;
}
$testTurn->setArg(['destNationID'=>$destNation['nation']]);
$testCommand = new static($generalObj, $this->env, $testTurn, ['destNationID'=>$destNation['nation']]);
if($testCommand->isRunnable()){
$testTurn->setArg(['destNationID' => $destNation['nation']]);
$testCommand = new static($generalObj, $this->env, $testTurn, ['destNationID' => $destNation['nation']]);
if ($testCommand->hasFullConditionMet()) {
$destNation['availableCommand'] = true;
}
else{
} else {
$destNation['availableCommand'] = false;
}
$nationList[] = $destNation;
}
ob_start();
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 국가에 급습을 발동합니다.<br>
선포, 전쟁중인 상대국에만 가능합니다.<br>
상대 국가를 목록에서 선택하세요.<br>
배경색은 현재 급습 불가능 국가는 <font color=red>붉은색</font>으로 표시됩니다.<br>
<select class='formInput' name="destNationID" id="destNationID" size='1' style='color:white;background-color:black;'>
<?php foreach($nationList as $nation): ?>
<option
value='<?=$nation['nation']?>'
style='color:<?=$nation['color']?>;<?=$nation['availableCommand']?'':'background-color:red;'?>'
>【<?=$nation['name']?> 】</option>
<?php endforeach; ?>
<input type=button id="commonSubmit" value="<?=$this->getName()?>">
<?php
<?= \sammo\getMapHtml() ?><br>
선택된 국가에 급습을 발동합니다.<br>
선포, 전쟁중인 상대국에만 가능합니다.<br>
상대 국가를 목록에서 선택하세요.<br>
배경색은 현재 급습 불가능 국가는 <font color=red>붉은색</font>으로 표시됩니다.<br>
<select class='formInput' name="destNationID" id="destNationID" size='1' style='color:white;background-color:black;'>
<?php foreach ($nationList as $nation) : ?>
<option value='<?= $nation['nation'] ?>' style='color:<?= $nation['color'] ?>;<?= $nation['availableCommand'] ? '' : 'background-color:red;' ?>'>【<?= $nation['name'] ?> 】</option>
<?php endforeach; ?>
<input type=button id="commonSubmit" value="<?= $this->getName() ?>">
<?php
return ob_get_clean();
}
}
}
+96 -70
View File
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -13,9 +17,9 @@ use \sammo\{
Message
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL
};
@@ -23,56 +27,59 @@ use function \sammo\{
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_몰수 extends Command\NationCommand{
class che_몰수 extends Command\NationCommand
{
static protected $actionName = '몰수';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 사망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 장수여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('isGold', $this->arg)){
if (!key_exists('isGold', $this->arg)) {
return false;
}
if(!key_exists('amount', $this->arg)){
if (!key_exists('amount', $this->arg)) {
return false;
}
if(!key_exists('destGeneralID', $this->arg)){
if (!key_exists('destGeneralID', $this->arg)) {
return false;
}
$isGold = $this->arg['isGold'];
$amount = $this->arg['amount'];
$destGeneralID = $this->arg['destGeneralID'];
if(!is_numeric($amount)){
if (!is_numeric($amount)) {
return false;
}
$amount = Util::round($amount, -2);
$amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount);
if($amount <= 0){
if ($amount <= 0) {
return false;
}
if(!is_bool($isGold)){
if (!is_bool($isGold)) {
return false;
}
if(!is_int($destGeneralID)){
if (!is_int($destGeneralID)) {
return false;
}
if($destGeneralID <= 0){
if ($destGeneralID <= 0) {
return false;
}
if($destGeneralID == $this->generalObj->getID()){
if ($destGeneralID == $this->generalObj->getID()) {
return false;
}
$this->arg = [
'isGold'=>$isGold,
'amount'=>$amount,
'destGeneralID'=>$destGeneralID
'isGold' => $isGold,
'amount' => $amount,
'destGeneralID' => $destGeneralID
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
@@ -80,13 +87,27 @@ class che_몰수 extends Command\NationCommand{
$this->setCity();
$this->setNation(['gold', 'rice']);
$relYear = $env['year'] - $env['startyear'];
$this->minConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::SuppliedCity(),
];
}
protected function initWithArg()
{
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'npc', 'nation', 'imgsvr', 'picture'], 1);
$this->setDestGeneral($destGeneral);
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
ConstraintHelper::NotBeNeutral(),
$this->fullConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::NotOpeningPart($relYear),
@@ -95,32 +116,37 @@ class che_몰수 extends Command\NationCommand{
ConstraintHelper::FriendlyDestGeneral()
];
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$isGold = $this->arg['isGold'];
$amount = $this->arg['amount'];
$amountText = number_format($amount, 0);
$resName = $isGold?'금':'쌀';
$resName = $isGold ? '금' : '쌀';
$destGeneral = $this->destGeneralObj;
$commandName = $this->getName();
return "{$destGeneral->getName()}{$resName} $amountText {$commandName}";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -134,10 +160,10 @@ class che_몰수 extends Command\NationCommand{
$isGold = $this->arg['isGold'];
$amount = $this->arg['amount'];
$resKey = $isGold?'gold':'rice';
$resName = $isGold?'금':'쌀';
$resKey = $isGold ? 'gold' : 'rice';
$resName = $isGold ? '금' : '쌀';
$destGeneral = $this->destGeneralObj;
$amount = Util::valueFit(
$amount,
0,
@@ -145,17 +171,17 @@ class che_몰수 extends Command\NationCommand{
);
$amountText = number_format($amount, 0);
if($destGeneral->getVar('npc') >= 2 && Util::randBool(0.01)){
if ($destGeneral->getVar('npc') >= 2 && Util::randBool(0.01)) {
$npcTexts = [
'몰수를 하다니... 이것이 윗사람이 할 짓이란 말입니까...',
'사유재산까지 몰수해가면서 이 나라가 잘 될거라 믿습니까? 정말 이해할 수가 없군요...',
'내 돈 내놔라! 내 돈! 몰수가 왠 말이냐!',
'몰수해간 내 자금... 언젠가 몰래 다시 빼내올 것이다...',
'몰수로 인한 사기 저하는 몰수로 얻은 물자보다 더 손해란걸 모른단 말인가!'
'몰수로 인한 사기 저하는 몰수로 얻은 물자보다 더 손해란걸 모른단 말인가!'
];
$text = Util::choiceRandom($npcTexts);
$src = new MessageTarget(
$destGeneral->getID(),
$destGeneral->getID(),
$destGeneral->getName(),
$nationID,
$nation['name'],
@@ -163,7 +189,7 @@ class che_몰수 extends Command\NationCommand{
GetImageURL($destGeneral->getVar('imgsvr'), $destGeneral->getVar('picture'))
);
$msg = new Message(
Message::MSGTYPE_PUBLIC,
Message::MSGTYPE_PUBLIC,
$src,
$src,
$text,
@@ -173,12 +199,12 @@ class che_몰수 extends Command\NationCommand{
);
$msg->send();
}
$logger = $general->getLogger();
$destGeneral->increaseVarWithLimit($resKey, -$amount, 0);
$db->update('nation', [
$resKey=>$db->sqleval('%b + %i', $resKey, $amount)
$resKey => $db->sqleval('%b + %i', $resKey, $amount)
], 'nation=%i', $nationID);
$destGeneral->getLogger()->pushGeneralActionLog("{$resName} {$amountText}을 몰수 당했습니다.", ActionLogger::PLAIN);
@@ -196,48 +222,48 @@ class che_몰수 extends Command\NationCommand{
//TODO: 암행부처럼 보여야...
$db = DB::db();
$destRawGenerals = $db->query('SELECT no,name,officer_level,npc,gold,rice FROM general WHERE nation = %i AND no != %i ORDER BY npc,binary(name)',$this->generalObj->getNationID(), $this->generalObj->getID());
$destRawGenerals = $db->query('SELECT no,name,officer_level,npc,gold,rice FROM general WHERE nation = %i AND no != %i ORDER BY npc,binary(name)', $this->generalObj->getNationID(), $this->generalObj->getID());
$destGeneralList = [];
foreach($destRawGenerals as $destGeneral){
foreach ($destRawGenerals as $destGeneral) {
$nameColor = \sammo\getNameColor($destGeneral['npc']);
if($nameColor){
if ($nameColor) {
$nameColor = " style='color:{$nameColor}'";
}
$name = $destGeneral['name'];
if($destGeneral['officer_level'] >= 5){
if ($destGeneral['officer_level'] >= 5) {
$name = "*{$name}*";
}
$destGeneralList[] = [
'no'=>$destGeneral['no'],
'color'=>$nameColor,
'name'=>$name,
'gold'=>$destGeneral['gold'],
'rice'=>$destGeneral['rice']
'no' => $destGeneral['no'],
'color' => $nameColor,
'name' => $name,
'gold' => $destGeneral['gold'],
'rice' => $destGeneral['rice']
];
}
ob_start();
?>
장수의 자금이나 군량을 몰수합니다.<br>
몰수한것은 국가재산으로 귀속됩니다.<br>
<select class='formInput' name="destGeneralID" id="destGeneralID" size='1' style='color:white;background-color:black;'>
<?php foreach($destGeneralList as $destGeneral): ?>
<option value='<?=$destGeneral['no']?>' <?=$destGeneral['color']?>><?=$destGeneral['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>
<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>
<br>
장수의 자금이나 군량을 몰수합니다.<br>
몰수한것은 국가재산으로 귀속됩니다.<br>
<select class='formInput' name="destGeneralID" id="destGeneralID" size='1' style='color:white;background-color:black;'>
<?php foreach ($destGeneralList as $destGeneral) : ?>
<option value='<?= $destGeneral['no'] ?>' <?= $destGeneral['color'] ?>><?= $destGeneral['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>
<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>
<br>
<?php
return ob_get_clean();
}
}
}
+14 -4
View File
@@ -80,6 +80,16 @@ class che_물자원조 extends Command\NationCommand{
$this->setCity();
$this->setNation(['gold', 'rice', 'surlimit']);
$this->minConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqNationValue('surlimit', '외교제한', '==', 0, '외교제한중입니다.'),
];
}
protected function initWithArg()
{
$destNationID = $this->arg['destNationID'];
$this->setDestNation($destNationID, ['gold', 'rice', 'surlimit']);
@@ -87,13 +97,13 @@ class che_물자원조 extends Command\NationCommand{
$limit = $this->nation['level'] * GameConst::$coefAidAmount;
if($goldAmount > $limit || $riceAmount > $limit){
$this->runnableConstraints[
$this->fullConditionConstraints[
ConstraintHelper::AlwaysFail('작위 제한량 이상은 보낼 수 없습니다.')
];
return;
}
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
@@ -128,7 +138,7 @@ class che_물자원조 extends Command\NationCommand{
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+15 -5
View File
@@ -59,13 +59,23 @@ class che_발령 extends Command\NationCommand{
$this->setCity();
$this->setNation();
$this->minConditionConstraints=[
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
];
}
$this->setDestCity($this->arg['destCityID'], null);
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null, 1);
$this->setDestGeneral($destGeneral);
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
@@ -79,7 +89,7 @@ class che_발령 extends Command\NationCommand{
public function getFailString():string{
$commandName = $this->getName();
$failReason = $this->testRunnable();
$failReason = $this->testFullConditionMet();
if($failReason === null){
throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집');
}
@@ -109,7 +119,7 @@ class che_발령 extends Command\NationCommand{
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+14 -4
View File
@@ -56,10 +56,20 @@ class che_백성동원 extends Command\NationCommand{
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->setDestCity($this->arg['destCityID'], null);
$this->setDestNation($this->destCity['nation']);
$this->runnableConstraints=[
$this->minConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand()
];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
$this->setDestNation($this->destCity['nation']);
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AllowDiplomacyStatus($this->generalObj->getNationID(), [
@@ -101,7 +111,7 @@ class che_백성동원 extends Command\NationCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -14,9 +18,9 @@ use \sammo\{
Message,
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
@@ -26,75 +30,85 @@ use function \sammo\{
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_불가침수락 extends Command\NationCommand{
class che_불가침수락 extends Command\NationCommand
{
static protected $actionName = '불가침 수락';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('destNationID', $this->arg)){
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if(!is_int($destNationID)){
if (!is_int($destNationID)) {
return false;
}
if($destNationID < 1){
if ($destNationID < 1) {
return false;
}
if(!key_exists('destGeneralID', $this->arg)){
if (!key_exists('destGeneralID', $this->arg)) {
return false;
}
$destGeneralID = $this->arg['destGeneralID'];
if(!is_int($destGeneralID)){
if (!is_int($destGeneralID)) {
return false;
}
if($destGeneralID <= 0){
if ($destGeneralID <= 0) {
return false;
}
if($destGeneralID == $this->generalObj->getID()){
if ($destGeneralID == $this->generalObj->getID()) {
return false;
}
if(!key_exists('year', $this->arg) || !key_exists('month', $this->arg) ){
if (!key_exists('year', $this->arg) || !key_exists('month', $this->arg)) {
return false;
}
$year = $this->arg['year'];
$month = $this->arg['month'];
if(!is_int($year) || !is_int($month)){
if (!is_int($year) || !is_int($month)) {
return false;
}
if($month < 1 || 12 < $month){
if ($month < 1 || 12 < $month) {
return false;
}
if($year < $this->env['startyear']){
if ($year < $this->env['startyear']) {
return false;
}
$this->arg = [
'destNationID'=>$destNationID,
'destGeneralID'=>$destGeneralID,
'year'=>$year,
'month'=>$month,
'destNationID' => $destNationID,
'destGeneralID' => $destGeneralID,
'year' => $year,
'month' => $month,
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$this->setCity();
$this->setNation();
$this->permissionConstraints = [
ConstraintHelper::AlwaysFail('예약 불가능 커맨드')
];
}
protected function initWithArg()
{
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], [], 1);
$this->setDestGeneral($destGeneral);
$this->setDestNation($this->arg['destNationID']);
@@ -104,24 +118,20 @@ class che_불가침수락 extends Command\NationCommand{
$month = $this->arg['month'];
$currentMonth = $env['year'] * 12 + $env['month'] - 1;
$reqMonth = $year *12 + $month - 1;
$reqMonth = $year * 12 + $month - 1;
$nationID = $this->nation['nation'];
$this->reservableConstraints = [
ConstraintHelper::AlwaysFail('예약 불가능 커맨드')
];
if ($reqMonth <= $currentMonth) {
$this->runnableConstraints = [
$this->fullConditionConstraints = [
ConstraintHelper::AlwaysFail('이미 기한이 지났습니다.')
];
return;
}
}
$this->runnableConstraints=[
$this->fullConditionConstraints = [
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ExistsDestNation(),
@@ -136,22 +146,25 @@ class che_불가침수락 extends Command\NationCommand{
6 => '아국과 외교 진행중입니다.',
]),
];
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
$year = $this->arg['year'];
@@ -159,8 +172,9 @@ class che_불가침수락 extends Command\NationCommand{
return "{$year}{$month}월까지 불가침 합의";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -182,17 +196,22 @@ class che_불가침수락 extends Command\NationCommand{
$logger = $general->getLogger();
$destLogger = $this->destGeneralObj->getLogger();
$currentMonth = $env['year'] * 12 + $env['month'] - 1;
$reqMonth = $year *12 + $month - 1;
$db->update('diplomacy',[
'state'=>7,
'term'=>$reqMonth - $currentMonth
],
'(me=%i AND you=%i) OR (you=%i AND me=%i)',
$nationID, $destNationID,
$nationID, $destNationID);
$currentMonth = $env['year'] * 12 + $env['month'] - 1;
$reqMonth = $year * 12 + $month - 1;
$db->update(
'diplomacy',
[
'state' => 7,
'term' => $reqMonth - $currentMonth
],
'(me=%i AND you=%i) OR (you=%i AND me=%i)',
$nationID,
$destNationID,
$nationID,
$destNationID
);
$josaWa = JosaUtil::pick($destNationName, '와');
$logger->pushGeneralActionLog("<D><b>{$destNationName}</b></>{$josaWa} <C>$year</>년 <C>{$month}</>월까지 불가침에 성공했습니다.", ActionLogger::PLAIN);
@@ -208,4 +227,4 @@ class che_불가침수락 extends Command\NationCommand{
return true;
}
}
}
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -14,9 +18,9 @@ use \sammo\{
Message,
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
@@ -26,85 +30,98 @@ use function \sammo\{
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_불가침제의 extends Command\NationCommand{
class che_불가침제의 extends Command\NationCommand
{
static protected $actionName = '불가침 제의';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('destNationID', $this->arg)){
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if(!is_int($destNationID)){
if (!is_int($destNationID)) {
return false;
}
if($destNationID < 1){
if ($destNationID < 1) {
return false;
}
if(!key_exists('year', $this->arg) || !key_exists('month', $this->arg) ){
if (!key_exists('year', $this->arg) || !key_exists('month', $this->arg)) {
return false;
}
$year = $this->arg['year'];
$month = $this->arg['month'];
if(!is_int($year) || !is_int($month)){
if (!is_int($year) || !is_int($month)) {
return false;
}
if($month < 1 || 12 < $month){
if ($month < 1 || 12 < $month) {
return false;
}
if($year < $this->env['startyear']){
if ($year < $this->env['startyear']) {
return false;
}
$this->arg = [
'destNationID'=>$destNationID,
'year'=>$year,
'month'=>$month,
'destNationID' => $destNationID,
'year' => $year,
'month' => $month,
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$this->setCity();
$this->setNation();
$this->minConditionConstraints = [
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
];
}
protected function initWithArg()
{
$this->setDestNation($this->arg['destNationID'], null);
//NOTE: 개월에서 기한으로 바뀜
$year = $this->arg['year'];
$month = $this->arg['month'];
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$currentMonth = $env['year'] * 12 + $env['month'] - 1;
$reqMonth = $year *12 + $month - 1;
$reqMonth = $year * 12 + $month - 1;
$nationID = $this->nation['nation'];
if ($reqMonth < $currentMonth + 12) {
$this->reservableConstraints = [
$this->permissionConstraints = [
ConstraintHelper::AlwaysFail('기한은 1년 이상이어야 합니다.')
];
$this->runnableConstraints = [
$this->fullConditionConstraints = [
ConstraintHelper::AlwaysFail('기한은 1년 이상이어야 합니다.')
];
return;
}
}
$this->runnableConstraints=[
$this->fullConditionConstraints = [
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::DisallowDiplomacyBetweenStatus([
0 => '아국과 이미 교전중입니다.',
@@ -115,22 +132,25 @@ class che_불가침제의 extends Command\NationCommand{
6 => '아국과 외교 진행중입니다.',
]),
];
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
$year = $this->arg['year'];
@@ -139,8 +159,9 @@ class che_불가침제의 extends Command\NationCommand{
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -169,7 +190,7 @@ class che_불가침제의 extends Command\NationCommand{
// 상대에게 발송
$src = new MessageTarget(
$general->getID(),
$general->getID(),
$general->getName(),
$nationID,
$nationName,
@@ -186,7 +207,7 @@ class che_불가침제의 extends Command\NationCommand{
$now = new \DateTime($date);
$validUntil = new \DateTime($date);
$validMinutes = max(30, $env['turnterm']*3);
$validMinutes = max(30, $env['turnterm'] * 3);
$validUntil->add(new \DateInterval("PT{$validMinutes}M"));
$josaWa = JosaUtil::pick($nationName, '와');
@@ -199,9 +220,9 @@ class che_불가침제의 extends Command\NationCommand{
$now,
$validUntil,
[
'action'=>DiplomaticMessage::TYPE_NO_AGGRESSION,
'year'=>$year,
'month'=>$month,
'action' => DiplomaticMessage::TYPE_NO_AGGRESSION,
'year' => $year,
'month' => $month,
]
);
$msg->send();
@@ -224,7 +245,7 @@ class che_불가침제의 extends Command\NationCommand{
{
$generalObj = $this->generalObj;
$nationID = $generalObj->getNationID();
$db = DB::db();
$currYear = $this->env['year'];
@@ -235,57 +256,52 @@ class che_불가침제의 extends Command\NationCommand{
);
$nationList = [];
foreach(getAllNationStaticInfo() as $destNation){
if($destNation['nation'] == $nationID){
foreach (getAllNationStaticInfo() as $destNation) {
if ($destNation['nation'] == $nationID) {
continue;
}
$testCommand = new static($generalObj, $this->env, $this->getLastTurn(), [
'destNationID'=>$destNation['nation'],
'year'=>$currYear+1,
'month'=>12
'destNationID' => $destNation['nation'],
'year' => $currYear + 1,
'month' => 12
]);
if(!$testCommand->isRunnable()){
if (!$testCommand->hasFullConditionMet()) {
$destNation['cssBgColor'] = 'background-color:red;';
}
else if($diplomacyStatus[$destNation['nation']]['state'] == 7){
} else if ($diplomacyStatus[$destNation['nation']]['state'] == 7) {
$destNation['cssBgColor'] = 'background-color:blue;';
}
else{
} else {
$destNation['cssBgColor'] = '';
}
$nationList[] = $destNation;
}
ob_start();
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
타국에게 불가침을 제의합니다.<br>
제의할 국가를 목록에서 선택하세요.<br>
불가침 기한 다음 달부터 선포 가능합니다.<br>
배경색은 현재 제의가 불가능한 국가는 <font color=red>붉은색</font>, 현재 불가침중인 국가는 <font color=blue>푸른색</font>으로 표시됩니다.<br>
<br>
<select class='formInput' name="destNationID" id="destNationID" size='1' style='color:white;background-color:black;'>
<?php foreach($nationList as $nation): ?>
<option
value='<?=$nation['nation']?>'
style='color:<?=$nation['color']?>;<?=$nation['cssBgColor']?>'
>【<?=$nation['name']?> 】</option>
<?php endforeach; ?>
</select>에게
<select class='formInput' name="year" id="year" size='1' style='color:white;background-color:black;'>
<?php foreach(Util::range($currYear+1, $currYear+20+1) as $formYear): ?>
<option value='<?=$formYear?>'><?=$formYear?></option>
<?php endforeach; ?>
</select>년
<select class='formInput' name="month" id="month" size='1' style='color:white;background-color:black;'>
<?php foreach(Util::range(1, 12+1) as $formMonth): ?>
<option value='<?=$formMonth?>'><?=$formMonth?></option>
<?php endforeach; ?>
</select>월까지
<input type=button id="commonSubmit" value="<?=$this->getName()?>">
<?= \sammo\getMapHtml() ?><br>
타국에게 불가침을 제의합니다.<br>
제의할 국가를 목록에서 선택하세요.<br>
불가침 기한 다음 달부터 선포 가능합니다.<br>
배경색은 현재 제의가 불가능한 국가는 <font color=red>붉은색</font>, 현재 불가침중인 국가는 <font color=blue>푸른색</font>으로 표시됩니다.<br>
<br>
<select class='formInput' name="destNationID" id="destNationID" size='1' style='color:white;background-color:black;'>
<?php foreach ($nationList as $nation) : ?>
<option value='<?= $nation['nation'] ?>' style='color:<?= $nation['color'] ?>;<?= $nation['cssBgColor'] ?>'>【<?= $nation['name'] ?> 】</option>
<?php endforeach; ?>
</select>에게
<select class='formInput' name="year" id="year" size='1' style='color:white;background-color:black;'>
<?php foreach (Util::range($currYear + 1, $currYear + 20 + 1) as $formYear) : ?>
<option value='<?= $formYear ?>'><?= $formYear ?></option>
<?php endforeach; ?>
</select>년
<select class='formInput' name="month" id="month" size='1' style='color:white;background-color:black;'>
<?php foreach (Util::range(1, 12 + 1) as $formMonth) : ?>
<option value='<?= $formMonth ?>'><?= $formMonth ?></option>
<?php endforeach; ?>
</select>월까지
<input type=button id="commonSubmit" value="<?= $this->getName() ?>">
<?php
return ob_get_clean();
}
}
}
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -14,9 +18,9 @@ use \sammo\{
Message,
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
@@ -26,69 +30,69 @@ use function \sammo\{
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_불가침파기수락 extends Command\NationCommand{
class che_불가침파기수락 extends Command\NationCommand
{
static protected $actionName = '불가침 파기 수락';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('destNationID', $this->arg)){
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if(!is_int($destNationID)){
if (!is_int($destNationID)) {
return false;
}
if($destNationID < 1){
if ($destNationID < 1) {
return false;
}
if(!key_exists('destGeneralID', $this->arg)){
if (!key_exists('destGeneralID', $this->arg)) {
return false;
}
$destGeneralID = $this->arg['destGeneralID'];
if(!is_int($destGeneralID)){
if (!is_int($destGeneralID)) {
return false;
}
if($destGeneralID <= 0){
if ($destGeneralID <= 0) {
return false;
}
if($destGeneralID == $this->generalObj->getID()){
if ($destGeneralID == $this->generalObj->getID()) {
return false;
}
$this->arg = [
'destNationID'=>$destNationID,
'destGeneralID'=>$destGeneralID,
'destNationID' => $destNationID,
'destGeneralID' => $destGeneralID,
];
return true;
}
protected function init(){
$general = $this->generalObj;
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
protected function init()
{
$this->setCity();
$this->setNation();
$this->permissionConstraints = [
ConstraintHelper::AlwaysFail('예약 불가능 커맨드')
];
}
protected function initWithArg()
{
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], [], 1);
$this->setDestGeneral($destGeneral);
$this->setDestNation($this->arg['destNationID']);
$nationID = $this->nation['nation'];
$this->reservableConstraints = [
ConstraintHelper::AlwaysFail('예약 불가능 커맨드')
];
$this->runnableConstraints=[
$this->fullConditionConstraints = [
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::ReqDestNationValue('nation', '소속', '==', $this->destGeneralObj->getNationID(), '제의 장수가 국가 소속이 아닙니다'),
@@ -97,29 +101,33 @@ class che_불가침파기수락 extends Command\NationCommand{
'불가침 중인 상대국에게만 가능합니다.'
),
];
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}국과 불가침 파기 합의";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -140,13 +148,18 @@ class che_불가침파기수락 extends Command\NationCommand{
$logger = $general->getLogger();
$destLogger = $this->destGeneralObj->getLogger();
$db->update('diplomacy',[
'state'=>2,
'term'=>0
],
'(me=%i AND you=%i) OR (you=%i AND me=%i)',
$nationID, $destNationID,
$nationID, $destNationID);
$db->update(
'diplomacy',
[
'state' => 2,
'term' => 0
],
'(me=%i AND you=%i) OR (you=%i AND me=%i)',
$nationID,
$destNationID,
$nationID,
$destNationID
);
$josaYiGeneral = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
@@ -168,4 +181,4 @@ class che_불가침파기수락 extends Command\NationCommand{
return true;
}
}
}
@@ -60,9 +60,21 @@ class che_불가침파기제의 extends Command\NationCommand{
$this->setCity();
$this->setNation();
$this->minConditionConstraints=[
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
];
}
protected function initWithArg()
{
$this->setDestNation($this->arg['destNationID'], null);
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
@@ -96,7 +108,7 @@ class che_불가침파기제의 extends Command\NationCommand{
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+77 -61
View File
@@ -1,20 +1,25 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
Message, MessageTarget
Message,
MessageTarget
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
@@ -24,56 +29,67 @@ use function \sammo\{
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_선전포고 extends Command\NationCommand{
class che_선전포고 extends Command\NationCommand
{
static protected $actionName = '선전포고';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('destNationID', $this->arg)){
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if(!is_int($destNationID)){
if (!is_int($destNationID)) {
return false;
}
if($destNationID < 1){
if ($destNationID < 1) {
return false;
}
$this->arg = [
'destNationID'=>$destNationID
'destNationID' => $destNationID
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$this->setCity();
$this->setNation();
$this->setDestNation($this->arg['destNationID'], null);
if($relYear < 3 - 2){
$this->runnableConstraints = [
ConstraintHelper::AlwaysFail('초반제한 해제 2년전부터 가능합니다.')
];
return;
}
$this->runnableConstraints=[
$startYear = $this->env['startyear'];
$this->minConditionConstraints = [
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqEnvValue('year', '>=', $startYear + 1, '초반제한 해제 2년전부터 가능합니다.'),
];
}
protected function initWithArg()
{
$startYear = $this->env['startyear'];
$this->setDestNation($this->arg['destNationID'], null);
$this->fullConditionConstraints = [
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqEnvValue('year', '>=', $startYear + 1, '초반제한 해제 2년전부터 가능합니다.'),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::NearNation(),
ConstraintHelper::DisallowDiplomacyBetweenStatus([
@@ -86,30 +102,34 @@ class che_선전포고 extends Command\NationCommand{
5 => '상대국이 외교 진행중입니다.'
]),
];
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}】에 {$commandName}";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -143,15 +163,15 @@ class che_선전포고 extends Command\NationCommand{
$logger->pushGlobalHistoryLog("<R><b>【선포】</b></><D><b>{$nationName}</b></>{$josaYiNation} <D><b>{$destNationName}</b></>에 선전 포고 하였습니다.");
$db->update('diplomacy', [
'state'=>1,
'term'=>24
'state' => 1,
'term' => 24
], '(me=%i AND you=%i) OR (me=%i AND you=%i)', $nationID, $destNationID, $destNationID, $nationID);
//국메로 저장
$text = "【외교】{$env['year']}{$env['month']}월:{$nationName}에서 {$destNationName}에 선전포고";
$src = new MessageTarget(
$general->getID(),
$general->getID(),
$general->getName(),
$nationID,
$nationName,
@@ -166,7 +186,7 @@ class che_선전포고 extends Command\NationCommand{
$destNation['color']
);
$msg = new Message(
Message::MSGTYPE_NATIONAL,
Message::MSGTYPE_NATIONAL,
$src,
$dest,
$text,
@@ -197,40 +217,36 @@ class che_선전포고 extends Command\NationCommand{
$startYear = $this->env['startyear'];
$availableYear = $startYear + 1;
$nationList = [];
foreach(getAllNationStaticInfo() as $destNation){
if($destNation['nation'] == $nationID){
foreach (getAllNationStaticInfo() as $destNation) {
if ($destNation['nation'] == $nationID) {
continue;
}
$testCommand = new static($generalObj, $this->env, $this->getLastTurn(), ['destNationID'=>$destNation['nation']]);
if($testCommand->isRunnable()){
$testCommand = new static($generalObj, $this->env, $this->getLastTurn(), ['destNationID' => $destNation['nation']]);
if ($testCommand->hasFullConditionMet()) {
$destNation['availableWar'] = true;
}
else{
} else {
$destNation['availableWar'] = false;
}
$nationList[] = $destNation;
}
ob_start();
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
타국에게 선전 포고합니다.<br>
선전 포고할 국가를 목록에서 선택하세요.<br>
고립되지 않은 아국 도시에서 인접한 국가에 선포 가능합니다.<br>
초반제한 해제 2년전부터 선포가 가능합니다. (<?=$availableYear?>년 1월부터 가능)<br>
현재 선포가 불가능한 국가는 배경색이 <font color=red>붉은색</font>으로 표시됩니다.<br>
<select class='formInput' name="destNationID" id="destNationID" size='1' style='color:white;background-color:black;'>
<?php foreach($nationList as $nation): ?>
<option
value='<?=$nation['nation']?>'
style='color:<?=$nation['color']?>;<?=$nation['availableWar']?'':'background-color:red;'?>'
>【<?=$nation['name']?> 】</option>
<?php endforeach; ?>
</select>
<input type=button id="commonSubmit" value="<?=$this->getName()?>">
<?= \sammo\getMapHtml() ?><br>
타국에게 선전 포고합니다.<br>
선전 포고할 국가를 목록에서 선택하세요.<br>
고립되지 않은 아국 도시에서 인접한 국가에 선포 가능합니다.<br>
초반제한 해제 2년전부터 선포가 가능합니다. (<?= $availableYear ?>년 1월부터 가능)<br>
현재 선포가 불가능한 국가는 배경색이 <font color=red>붉은색</font>으로 표시됩니다.<br>
<select class='formInput' name="destNationID" id="destNationID" size='1' style='color:white;background-color:black;'>
<?php foreach ($nationList as $nation) : ?>
<option value='<?= $nation['nation'] ?>' style='color:<?= $nation['color'] ?>;<?= $nation['availableWar'] ? '' : 'background-color:red;' ?>'>【<?= $nation['name'] ?> 】</option>
<?php endforeach; ?>
</select>
<input type=button id="commonSubmit" value="<?= $this->getName() ?>">
<?php
return ob_get_clean();
}
}
}
+13 -3
View File
@@ -56,10 +56,20 @@ class che_수몰 extends Command\NationCommand{
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->setDestCity($this->arg['destCityID'], null);
$this->minConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand(),
];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
$this->setDestNation($this->destCity['nation']);
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::NotNeutralDestCity(),
@@ -101,7 +111,7 @@ class che_수몰 extends Command\NationCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -25,7 +25,6 @@ use \sammo\Constraint\ConstraintHelper;
class che_의병모집 extends Command\NationCommand{
static protected $actionName = '의병모집';
static public $reqArg = false;
protected function argTest():bool{
$this->arg = null;
@@ -41,7 +40,7 @@ class che_의병모집 extends Command\NationCommand{
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
@@ -75,7 +74,7 @@ class che_의병모집 extends Command\NationCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+73 -55
View File
@@ -1,20 +1,25 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
Message, MessageTarget
Message,
MessageTarget
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
@@ -24,34 +29,37 @@ use function \sammo\{
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_이호경식 extends Command\NationCommand{
class che_이호경식 extends Command\NationCommand
{
static protected $actionName = '이호경식';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('destNationID', $this->arg)){
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if(!is_int($destNationID)){
if (!is_int($destNationID)) {
return false;
}
if($destNationID < 1){
if ($destNationID < 1) {
return false;
}
$this->arg = [
'destNationID'=>$destNationID
'destNationID' => $destNationID
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
@@ -59,9 +67,18 @@ class che_이호경식 extends Command\NationCommand{
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->minConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand(),
];
}
protected function initWithArg()
{
$this->setDestNation($this->arg['destNationID'], null);
$this->runnableConstraints=[
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::ExistsDestNation(),
@@ -71,42 +88,47 @@ class che_이호경식 extends Command\NationCommand{
),
ConstraintHelper::AvailableStrategicCommand(),
];
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn()+1;
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount*16)*10);
$nextTerm = Util::round(sqrt($genCount * 16) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}】에 {$commandName}";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -144,7 +166,7 @@ class che_이호경식 extends Command\NationCommand{
$broadcastMessage = "<Y>{$generalName}</>{$josaYi} <G><b>{$destNationName}</b></>에 <M>{$commandName}</>{$josaUl} 발동하였습니다.";
$nationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach($nationGeneralList as $nationGeneralID){
foreach ($nationGeneralList as $nationGeneralID) {
$nationGeneralLogger = new ActionLogger($nationGeneralID, $nationID, $year, $month);
$nationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$nationGeneralLogger->flush();
@@ -155,7 +177,7 @@ class che_이호경식 extends Command\NationCommand{
$broadcastMessage = "아국에 <M>{$commandName}</>{$josaYiCommand} 발동되었습니다.";
$destNationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach($destNationGeneralList as $destNationGeneralID){
foreach ($destNationGeneralList as $destNationGeneralID) {
$destNationGeneralLogger = new ActionLogger($destNationGeneralID, $destNationID, $year, $month);
$destNationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$destNationGeneralLogger->flush();
@@ -166,13 +188,13 @@ class che_이호경식 extends Command\NationCommand{
$destNationLogger->flush();
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <D><b>{$destNationName}</b></>에 <M>{$commandName}</>{$josaUl} 발동");
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$db->update('diplomacy', [
'term'=>$db->sqleval('IF(`state`=0, %i, `term`+ %i)', 3, 3),
'state'=>1,
'term' => $db->sqleval('IF(`state`=0, %i, `term`+ %i)', 3, 3),
'state' => 1,
], '(me = %i AND you = %i) OR (you = %i AND me = %i)', $nationID, $destNationID, $nationID, $destNationID);
$general->applyDB($db);
@@ -193,39 +215,35 @@ class che_이호경식 extends Command\NationCommand{
$nationID = $generalObj->getNationID();
$nationList = [];
$testTurn = new LastTurn($this->getName(), null, $this->getPreReqTurn());
foreach(getAllNationStaticInfo() as $destNation){
if($destNation['nation'] == $nationID){
foreach (getAllNationStaticInfo() as $destNation) {
if ($destNation['nation'] == $nationID) {
continue;
}
$testTurn->setArg(['destNationID'=>$destNation['nation']]);
$testCommand = new static($generalObj, $this->env, $testTurn, ['destNationID'=>$destNation['nation']]);
if($testCommand->isRunnable()){
$testTurn->setArg(['destNationID' => $destNation['nation']]);
$testCommand = new static($generalObj, $this->env, $testTurn, ['destNationID' => $destNation['nation']]);
if ($testCommand->hasFullConditionMet()) {
$destNation['availableCommand'] = true;
}
else{
} else {
$destNation['availableCommand'] = false;
}
$nationList[] = $destNation;
}
ob_start();
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 국가에 이호경식을 발동합니다.<br>
선포, 전쟁중인 상대국에만 가능합니다.<br>
상대 국가를 목록에서 선택하세요.<br>
배경색은 현재 이호경식 불가능 국가는 <font color=red>붉은색</font>으로 표시됩니다.<br>
<select class='formInput' name="destNationID" id="destNationID" size='1' style='color:white;background-color:black;'>
<?php foreach($nationList as $nation): ?>
<option
value='<?=$nation['nation']?>'
style='color:<?=$nation['color']?>;<?=$nation['availableCommand']?'':'background-color:red;'?>'
>【<?=$nation['name']?> 】</option>
<?php endforeach; ?>
<input type=button id="commonSubmit" value="<?=$this->getName()?>">
<?php
<?= \sammo\getMapHtml() ?><br>
선택된 국가에 이호경식을 발동합니다.<br>
선포, 전쟁중인 상대국에만 가능합니다.<br>
상대 국가를 목록에서 선택하세요.<br>
배경색은 현재 이호경식 불가능 국가는 <font color=red>붉은색</font>으로 표시됩니다.<br>
<select class='formInput' name="destNationID" id="destNationID" size='1' style='color:white;background-color:black;'>
<?php foreach ($nationList as $nation) : ?>
<option value='<?= $nation['nation'] ?>' style='color:<?= $nation['color'] ?>;<?= $nation['availableCommand'] ? '' : 'background-color:red;' ?>'>【<?= $nation['name'] ?> 】</option>
<?php endforeach; ?>
<input type=button id="commonSubmit" value="<?= $this->getName() ?>">
<?php
return ob_get_clean();
}
}
}
+62 -42
View File
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -14,9 +18,9 @@ use \sammo\{
Message,
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
@@ -26,48 +30,51 @@ use function \sammo\{
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_종전수락 extends Command\NationCommand{
class che_종전수락 extends Command\NationCommand
{
static protected $actionName = '종전 수락';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('destNationID', $this->arg)){
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if(!is_int($destNationID)){
if (!is_int($destNationID)) {
return false;
}
if($destNationID < 1){
if ($destNationID < 1) {
return false;
}
if(!key_exists('destGeneralID', $this->arg)){
if (!key_exists('destGeneralID', $this->arg)) {
return false;
}
$destGeneralID = $this->arg['destGeneralID'];
if(!is_int($destGeneralID)){
if (!is_int($destGeneralID)) {
return false;
}
if($destGeneralID <= 0){
if ($destGeneralID <= 0) {
return false;
}
if($destGeneralID == $this->generalObj->getID()){
if ($destGeneralID == $this->generalObj->getID()) {
return false;
}
$this->arg = [
'destNationID'=>$destNationID,
'destGeneralID'=>$destGeneralID,
'destNationID' => $destNationID,
'destGeneralID' => $destGeneralID,
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
@@ -76,19 +83,23 @@ class che_종전수락 extends Command\NationCommand{
$this->setCity();
$this->setNation();
$nationID = $this->nation['nation'];
$this->permissionConstraints = [
ConstraintHelper::AlwaysFail('예약 불가능 커맨드')
];
}
protected function initWithArg()
{
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], [], 1);
$this->setDestGeneral($destGeneral);
$this->setDestNation($this->arg['destNationID']);
$nationID = $this->nation['nation'];
$this->reservableConstraints = [
ConstraintHelper::AlwaysFail('예약 불가능 커맨드')
];
$this->runnableConstraints=[
$this->fullConditionConstraints = [
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::ReqDestNationValue('nation', '소속', '==', $this->destGeneralObj->getNationID(), '제의 장수가 국가 소속이 아닙니다'),
@@ -97,29 +108,33 @@ class che_종전수락 extends Command\NationCommand{
'상대국과 선포, 전쟁중이지 않습니다.'
),
];
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}국과 종전 합의";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -140,13 +155,18 @@ class che_종전수락 extends Command\NationCommand{
$logger = $general->getLogger();
$destLogger = $this->destGeneralObj->getLogger();
$db->update('diplomacy',[
'state'=>2,
'term'=>0
],
'(me=%i AND you=%i) OR (you=%i AND me=%i)',
$nationID, $destNationID,
$nationID, $destNationID);
$db->update(
'diplomacy',
[
'state' => 2,
'term' => 0
],
'(me=%i AND you=%i) OR (you=%i AND me=%i)',
$nationID,
$destNationID,
$nationID,
$destNationID
);
$josaYiGeneral = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
@@ -168,4 +188,4 @@ class che_종전수락 extends Command\NationCommand{
return true;
}
}
}
+13 -3
View File
@@ -60,9 +60,20 @@ class che_종전제의 extends Command\NationCommand{
$this->setCity();
$this->setNation();
$this->minConditionConstraints=[
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
];
}
protected function initWithArg()
{
$this->setDestNation($this->arg['destNationID'], null);
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
@@ -73,7 +84,6 @@ class che_종전제의 extends Command\NationCommand{
'선포, 전쟁중인 상대국에게만 가능합니다.'
),
];
}
public function getCost():array{
@@ -96,7 +106,7 @@ class che_종전제의 extends Command\NationCommand{
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+5 -6
View File
@@ -28,7 +28,6 @@ use sammo\Event\Action;
class che_증축 extends Command\NationCommand{
static protected $actionName = '증축';
static public $reqArg = false;
protected function argTest():bool{
$this->arg = [];
@@ -42,10 +41,10 @@ class che_증축 extends Command\NationCommand{
$env = $this->env;
if($general->getNationID()===0){
$this->reservableConstraints=[
$this->permissionConstraints=[
ConstraintHelper::NotBeNeutral(),
];
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::NotBeNeutral(),
];
return;
@@ -53,11 +52,11 @@ class che_증축 extends Command\NationCommand{
$this->setCity();
$this->setNation(['gold', 'rice', 'capset', 'capital']);
$this->setDestCity($this->nation['capital'], null);
$this->setDestCity($this->nation['capital']);
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
@@ -135,7 +134,7 @@ class che_증축 extends Command\NationCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+76 -53
View File
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -14,110 +18,127 @@ use \sammo\{
CityConst
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL,
getNationStaticInfo
getNationStaticInfo
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_천도 extends Command\NationCommand{
class che_천도 extends Command\NationCommand
{
static protected $actionName = '천도';
static public $reqArg = true;
private $cachedDist = null;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('destCityID', $this->arg)){
if (!key_exists('destCityID', $this->arg)) {
return false;
}
if(CityConst::byID($this->arg['destCityID']) === null){
if (CityConst::byID($this->arg['destCityID']) === null) {
return false;
}
$destCityID = $this->arg['destCityID'];
$this->arg = [
'destCityID'=>$destCityID,
'destCityID' => $destCityID,
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['capset', 'gold', 'rice', 'capital']);
$this->setDestCity($this->arg['destCityID'], null);
$this->minConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
[$reqGold, $reqRice] = $this->getCost();
if($this->getDistance() === null){
$this->runnableConstraints[
ConstraintHelper::AlwaysFail('천도 대상으로 도달할 방법이 없습니다.')
];
if ($this->getDistance() === null) {
$this->fullConditionConstraints[ConstraintHelper::AlwaysFail('천도 대상으로 도달할 방법이 없습니다.')];
return;
}
$this->runnableConstraints=[
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::OccupiedDestCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::SuppliedDestCity(),
ConstraintHelper::ReqNationValue('capital', '수도', '!=', $this->destCity['city'], '이미 수도입니다.'),
ConstraintHelper::ReqNationGold(GameConst::$basegold+$reqGold),
ConstraintHelper::ReqNationRice(GameConst::$baserice+$reqRice),
ConstraintHelper::ReqNationGold(GameConst::$basegold + $reqGold),
ConstraintHelper::ReqNationRice(GameConst::$baserice + $reqRice),
];
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$amount = number_format($this->env['develcost'] * 5);
return "{$name}/1+거리×2턴(금쌀 {$amount}×2^거리)";
}
public function getCost():array{
public function getCost(): array
{
$amount = $this->env['develcost'] * 5;
$amount *= 2**$this->getDistance()??50;
$amount *= 2 ** $this->getDistance() ?? 50;
return [$amount, $amount];
}
private function getDistance():?int{
if($this->cachedDist !== null){
private function getDistance(): ?int
{
if ($this->cachedDist !== null) {
return $this->cachedDist;
}
$srcCityID = $this->nation['capital'];
$destCityID = $this->arg['destCityID'];
$nationID = $this->nation['nation'];
$distance = \sammo\calcCityDistance($srcCityID, $destCityID, [$nationID])??50;
$distance = \sammo\calcCityDistance($srcCityID, $destCityID, [$nationID]) ?? 50;
$this->cachedDist = $distance;
return $distance;
}
public function getPreReqTurn():int{
return $this->getDistance()*2;
public function getPreReqTurn(): int
{
return $this->getDistance() * 2;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function addTermStack():bool{
public function addTermStack(): bool
{
$lastTurn = $this->getLastTurn();
$commandName = $this->getName();
@@ -126,7 +147,7 @@ class che_천도 extends Command\NationCommand{
$nationID = $general->getNationID();
$nationStor->setValue("last천도Trial_{$nationID}", [$general->getVar('officer_level'), $general->getTurnTime()]);
if($lastTurn->getCommand() != $commandName || $lastTurn->getArg() !== $this->arg){
if ($lastTurn->getCommand() != $commandName || $lastTurn->getArg() !== $this->arg) {
$this->setResultTurn(new LastTurn(
$commandName,
$this->arg,
@@ -136,7 +157,7 @@ class che_천도 extends Command\NationCommand{
return false;
}
if($lastTurn->getSeq() < $this->nation['capset']){
if ($lastTurn->getSeq() < $this->nation['capset']) {
//NOTE: 최근에 천도, 증축이 일어났으면 리셋됨
$this->setResultTurn(new LastTurn(
$commandName,
@@ -147,7 +168,7 @@ class che_천도 extends Command\NationCommand{
return false;
}
if($lastTurn->getTerm() < $this->getPreReqTurn()){
if ($lastTurn->getTerm() < $this->getPreReqTurn()) {
$this->setResultTurn(new LastTurn(
$commandName,
$this->arg,
@@ -160,15 +181,17 @@ class che_천도 extends Command\NationCommand{
return true;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
$josaRo = JosaUtil::pick($destCityName, '로');
return "{$destCityName}{$josaRo} {$commandName}";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -192,7 +215,7 @@ class che_천도 extends Command\NationCommand{
$josaRo = JosaUtil::pick($destCityName, '로');
$logger = $general->getLogger();
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
@@ -204,7 +227,7 @@ class che_천도 extends Command\NationCommand{
'capital' => $destCityID,
'capset' => $db->sqleval('capset + 1'),
], 'nation=%i', $nationID);
$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>천도</> 명령");
@@ -228,15 +251,15 @@ class che_천도 extends Command\NationCommand{
{
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 도시로 천도합니다.<br>
현재 수도에서 연결된 도시만 가능하며, 1+2×거리만큼의 턴이 필요합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'>
<?=\sammo\optionsForCities()?><br>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<br>
<?= \sammo\getMapHtml() ?><br>
선택된 도시로 천도합니다.<br>
현재 수도에서 연결된 도시만 가능하며, 1+2×거리만큼의 턴이 필요합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'>
<?= \sammo\optionsForCities() ?><br>
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<br>
<?php
return ob_get_clean();
}
}
}
+14 -3
View File
@@ -58,9 +58,20 @@ class che_초토화 extends Command\NationCommand{
$this->setCity();
$this->setNation(['surlimit', 'gold', 'rice', 'capital']);
$this->setDestCity($this->arg['destCityID'], null);
$this->runnableConstraints=[
$this->minConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqNationValue('surlimit', '제한 턴', '==', 0, '외교제한 턴이 남아있습니다.'),
];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::OccupiedDestCity(),
ConstraintHelper::BeChief(),
@@ -102,7 +113,7 @@ class che_초토화 extends Command\NationCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+95 -74
View File
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -11,114 +15,131 @@ use \sammo\{
Command
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_포상 extends Command\NationCommand{
class che_포상 extends Command\NationCommand
{
static protected $actionName = '포상';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 사망 직전에 '포상' 턴을 넣을 수 있으므로, 존재하지 않는 장수여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('isGold', $this->arg)){
if (!key_exists('isGold', $this->arg)) {
return false;
}
if(!key_exists('amount', $this->arg)){
if (!key_exists('amount', $this->arg)) {
return false;
}
if(!key_exists('destGeneralID', $this->arg)){
if (!key_exists('destGeneralID', $this->arg)) {
return false;
}
$isGold = $this->arg['isGold'];
$amount = $this->arg['amount'];
$destGeneralID = $this->arg['destGeneralID'];
if(!is_numeric($amount)){
if (!is_numeric($amount)) {
return false;
}
$amount = Util::round($amount, -2);
$amount = Util::valueFit($amount, 100, GameConst::$maxResourceActionAmount);
if($amount <= 0){
if ($amount <= 0) {
return false;
}
if(!is_bool($isGold)){
if (!is_bool($isGold)) {
return false;
}
if(!is_int($destGeneralID)){
if (!is_int($destGeneralID)) {
return false;
}
if($destGeneralID <= 0){
if ($destGeneralID <= 0) {
return false;
}
if($destGeneralID == $this->generalObj->getID()){
if ($destGeneralID == $this->generalObj->getID()) {
return false;
}
$this->arg = [
'isGold'=>$isGold,
'amount'=>$amount,
'destGeneralID'=>$destGeneralID
'isGold' => $isGold,
'amount' => $amount,
'destGeneralID' => $destGeneralID
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation(['gold', 'rice']);
$this->minConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
];
}
protected function initWithArg()
{
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], 1);
$this->setDestGeneral($destGeneral);
$this->runnableConstraints=[
ConstraintHelper::NotBeNeutral(),
$this->fullConditionConstraints = [
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::FriendlyDestGeneral()
];
if($this->arg['isGold']){
$this->runnableConstraints[] = ConstraintHelper::ReqNationGold(1+GameConst::$basegold);
}
else{
$this->runnableConstraints[] = ConstraintHelper::ReqNationRice(1+GameConst::$baserice);
if ($this->arg['isGold']) {
$this->fullConditionConstraints[] = ConstraintHelper::ReqNationGold(1 + GameConst::$basegold);
} else {
$this->fullConditionConstraints[] = ConstraintHelper::ReqNationRice(1 + GameConst::$baserice);
}
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief():string{
public function getBrief(): string
{
$isGold = $this->arg['isGold'];
$amount = $this->arg['amount'];
$amountText = number_format($amount, 0);
$resName = $isGold?'금':'쌀';
$resName = $isGold ? '금' : '쌀';
$destGeneral = $this->destGeneralObj;
$commandName = $this->getName();
return "{$destGeneral->getName()}{$resName} $amountText {$commandName}";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -132,22 +153,22 @@ class che_포상 extends Command\NationCommand{
$isGold = $this->arg['isGold'];
$amount = $this->arg['amount'];
$resKey = $isGold?'gold':'rice';
$resName = $isGold?'금':'쌀';
$resKey = $isGold ? 'gold' : 'rice';
$resName = $isGold ? '금' : '쌀';
$destGeneral = $this->destGeneralObj;
$amount = Util::valueFit(
$amount,
0,
$nation[$resKey] - ($isGold?GameConst::$basegold:GameConst::$baserice)
$amount,
0,
$nation[$resKey] - ($isGold ? GameConst::$basegold : GameConst::$baserice)
);
$amountText = number_format($amount, 0);
$logger = $general->getLogger();
$destGeneral->increaseVar($resKey, $amount);
$db->update('nation', [
$resKey=>$db->sqleval('%b - %i', $resKey, $amount)
$resKey => $db->sqleval('%b - %i', $resKey, $amount)
], 'nation=%i', $nationID);
$destGeneral->getLogger()->pushGeneralActionLog("{$resName} <C>{$amountText}</>을 포상으로 받았습니다.", ActionLogger::PLAIN);
@@ -160,53 +181,53 @@ class che_포상 extends Command\NationCommand{
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 = %i AND no != %i ORDER BY npc,binary(name)',$this->generalObj->getNationID(), $this->generalObj->getID());
$destRawGenerals = $db->query('SELECT no,name,officer_level,npc,gold,rice FROM general WHERE nation = %i AND no != %i ORDER BY npc,binary(name)', $this->generalObj->getNationID(), $this->generalObj->getID());
$destGeneralList = [];
foreach($destRawGenerals as $destGeneral){
foreach ($destRawGenerals as $destGeneral) {
$nameColor = \sammo\getNameColor($destGeneral['npc']);
if($nameColor){
if ($nameColor) {
$nameColor = " style='color:{$nameColor}'";
}
$name = $destGeneral['name'];
if($destGeneral['officer_level'] >= 5){
if ($destGeneral['officer_level'] >= 5) {
$name = "*{$name}*";
}
$destGeneralList[] = [
'no'=>$destGeneral['no'],
'color'=>$nameColor,
'name'=>$name,
'gold'=>$destGeneral['gold'],
'rice'=>$destGeneral['rice']
'no' => $destGeneral['no'],
'color' => $nameColor,
'name' => $name,
'gold' => $destGeneral['gold'],
'rice' => $destGeneral['rice']
];
}
ob_start();
?>
국고로 장수에게 자금이나 군량을 지급합니다.<br>
<select class='formInput' name="destGeneralID" id="destGeneralID" size='1' style='color:white;background-color:black;'>
<?php foreach($destGeneralList as $destGeneral): ?>
<option value='<?=$destGeneral['no']?>' <?=$destGeneral['color']?>><?=$destGeneral['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>
<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>
<br>
국고로 장수에게 자금이나 군량을 지급합니다.<br>
<select class='formInput' name="destGeneralID" id="destGeneralID" size='1' style='color:white;background-color:black;'>
<?php foreach ($destGeneralList as $destGeneral) : ?>
<option value='<?= $destGeneral['no'] ?>' <?= $destGeneral['color'] ?>><?= $destGeneral['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>
<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>
<br>
<?php
return ob_get_clean();
}
}
}
+12 -4
View File
@@ -60,9 +60,18 @@ class che_피장파장 extends Command\NationCommand{
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->minConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand(),
];
}
protected function initWithArg()
{
$this->setDestNation($this->arg['destNationID'], null);
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::ExistsDestNation(),
@@ -72,7 +81,6 @@ class che_피장파장 extends Command\NationCommand{
),
ConstraintHelper::AvailableStrategicCommand(),
];
}
public function getCommandDetailTitle():string{
@@ -107,7 +115,7 @@ class che_피장파장 extends Command\NationCommand{
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -200,7 +208,7 @@ class che_피장파장 extends Command\NationCommand{
$testTurn->setArg(['destNationID'=>$destNation['nation']]);
$testCommand = new static($generalObj, $this->env, $testTurn, ['destNationID'=>$destNation['nation']]);
if($testCommand->isRunnable()){
if($testCommand->hasFullConditionMet()){
$destNation['availableCommand'] = true;
}
else{
@@ -26,7 +26,6 @@ use sammo\Event\Action;
class che_필사즉생 extends Command\NationCommand{
static protected $actionName = '필사즉생';
static public $reqArg = false;
protected function argTest():bool{
$this->arg = [];
@@ -42,7 +41,7 @@ class che_필사즉생 extends Command\NationCommand{
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->runnableConstraints=[
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AllowDiplomacyStatus($this->generalObj->getNationID(), [
@@ -77,7 +76,7 @@ class che_필사즉생 extends Command\NationCommand{
}
public function run():bool{
if(!$this->isRunnable()){
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
+66 -42
View File
@@ -1,9 +1,13 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
@@ -14,52 +18,65 @@ use \sammo\{
CityConst
};
use function \sammo\{
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL,
getNationStaticInfo
getNationStaticInfo
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_허보 extends Command\NationCommand{
class che_허보 extends Command\NationCommand
{
static protected $actionName = '허보';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if(!key_exists('destCityID', $this->arg)){
if (!key_exists('destCityID', $this->arg)) {
return false;
}
if(CityConst::byID($this->arg['destCityID']) === null){
if (CityConst::byID($this->arg['destCityID']) === null) {
return false;
}
$destCityID = $this->arg['destCityID'];
$this->arg = [
'destCityID'=>$destCityID,
'destCityID' => $destCityID,
];
return true;
}
protected function init(){
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->setDestCity($this->arg['destCityID'], null);
$this->setDestNation($this->destCity['nation']);
$this->runnableConstraints=[
$this->minConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand(),
];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
$this->setDestNation($this->destCity['nation']);
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::NotNeutralDestCity(),
@@ -72,38 +89,44 @@ class che_허보 extends Command\NationCommand{
];
}
public function getCommandDetailTitle():string{
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn()+1;
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost():array{
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn():int{
public function getPreReqTurn(): int
{
return 1;
}
public function getPostReqTurn():int{
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount*4)*10);
$nextTerm = Util::round(sqrt($genCount * 4) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief():string{
public function getBrief(): string
{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
return "{$destCityName}】에 {$commandName}";
}
public function run():bool{
if(!$this->isRunnable()){
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
@@ -123,7 +146,7 @@ class che_허보 extends Command\NationCommand{
$destNationID = $destCity['nation'];
$destNationName = getNationStaticInfo($destNationID)['name'];
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
@@ -138,7 +161,7 @@ class che_허보 extends Command\NationCommand{
$broadcastMessage = "<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>허보</>를 발동하였습니다.";
$targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach($targetGeneralList as $targetGeneralID){
foreach ($targetGeneralList as $targetGeneralID) {
$targetLogger = new ActionLogger($targetGeneralID, $nationID, $year, $month);
$targetLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$targetLogger->flush();
@@ -148,12 +171,12 @@ class che_허보 extends Command\NationCommand{
$destNationCityList = $db->queryFirstColumn('SELECT city FROM city WHERE nation = %i AND supply = 1', $destNationID);
$targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND city=%i', $destNationID, $destCityID);
foreach(General::createGeneralObjListFromDB($targetGeneralList) as $targetGeneralID => $targetGeneral){
foreach (General::createGeneralObjListFromDB($targetGeneralList) as $targetGeneralID => $targetGeneral) {
$targetLogger = $targetGeneral->getLogger();
$targetLogger->pushGeneralActionLog($destBroadcastMessage, ActionLogger::PLAIN);
$moveCityID = Util::choiceRandom($destNationCityList);
if($moveCityID == $destCityID){
if ($moveCityID == $destCityID) {
//현재도시면 다시 랜덤 추첨
$moveCityID = Util::choiceRandom($destNationCityList);
}
@@ -164,7 +187,8 @@ class che_허보 extends Command\NationCommand{
$destNationLogger = new ActionLogger(0, $destNationID, $year, $month);
$destNationLogger->pushNationalHistoryLog(
"<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국의 <G><b>{$destCityName}</b></>에 <M>허보</>를 발동", ActionLogger::PLAIN
"<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국의 <G><b>{$destCityName}</b></>에 <M>허보</>를 발동",
ActionLogger::PLAIN
);
$destNationLogger->flush();
@@ -173,7 +197,7 @@ class che_허보 extends Command\NationCommand{
'def' => $db->sqleval('def * 0.2'),
'wall' => $db->sqleval('wall * 0.2'),
], 'city=%i', $destCityID);
$josaYiNation = JosaUtil::pick($nationName, '이');
$logger->pushGeneralHistoryLog("<G><b>{$destCityName}</b></>에 <M>허보</>를 발동");
@@ -202,15 +226,15 @@ class che_허보 extends Command\NationCommand{
{
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 도시에 허보를 발동합니다.<br>
전쟁중인 상대국 도시만 가능합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'>
<?=\sammo\optionsForCities()?><br>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<br>
<?= \sammo\getMapHtml() ?><br>
선택된 도시에 허보를 발동합니다.<br>
전쟁중인 상대국 도시만 가능합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'>
<?= \sammo\optionsForCities() ?><br>
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
<br>
<?php
return ob_get_clean();
}
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ class 휴식 extends Command\NationCommand{
protected function init(){
//아무것도 하지 않음
$this->runnableConstraints=[];
$this->fullConditionConstraints=[];
}
+3 -3
View File
@@ -88,7 +88,7 @@ class DiplomaticMessage extends Message{
$this->diplomacyDetail = $commandObj->getBrief();
if(!$commandObj->isRunnable()){
if(!$commandObj->hasFullConditionMet()){
return [self::DECLINED, $commandObj->getFailString()];
}
@@ -109,7 +109,7 @@ class DiplomaticMessage extends Message{
$this->diplomacyDetail = $commandObj->getBrief();
if(!$commandObj->isRunnable()){
if(!$commandObj->hasFullConditionMet()){
return [self::DECLINED, $commandObj->getFailString()];
}
@@ -130,7 +130,7 @@ class DiplomaticMessage extends Message{
$this->diplomacyDetail = $commandObj->getBrief();
if(!$commandObj->isRunnable()){
if(!$commandObj->hasFullConditionMet()){
return [self::DECLINED, $commandObj->getFailString()];
}
+62 -62
View File
@@ -344,7 +344,7 @@ class GeneralAI
}
$cmd = buildNationCommandClass('che_발령', $this->general, $this->env, $lastTurn, Util::choiceRandom($troopCandidate));
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -433,7 +433,7 @@ class GeneralAI
'destCityID'=>Util::choiceRandom($cityCandidates)['city']
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -544,7 +544,7 @@ class GeneralAI
'destCityID'=>Util::choiceRandom($cityCandidates)['city']
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -615,7 +615,7 @@ class GeneralAI
'destCityID'=>Util::choiceRandom($cityCandidates)['city']
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -666,7 +666,7 @@ class GeneralAI
return null;
}
$cmd = buildNationCommandClass('che_발령', $this->general, $this->env, $lastTurn, Util::choiceRandom($args));
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
return null;
@@ -722,7 +722,7 @@ class GeneralAI
'destCityID'=>Util::choiceRandomUsingWeight($cityCandidates)
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -794,7 +794,7 @@ class GeneralAI
'destCityID'=>$destCity['city']
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -869,7 +869,7 @@ class GeneralAI
'destCityID'=>Util::choiceRandom($cityCandidates)['city']
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -899,7 +899,7 @@ class GeneralAI
return null;
}
$cmd = buildNationCommandClass('che_발령', $this->general, $this->env, $lastTurn, Util::choiceRandom($args));
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
return null;
@@ -955,7 +955,7 @@ class GeneralAI
'destCityID'=>Util::choiceRandomUsingWeight($cityCandidates)
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -1023,7 +1023,7 @@ class GeneralAI
'destCityID'=>$destCity['city']
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -1101,7 +1101,7 @@ class GeneralAI
'che_포상', $this->general, $this->env, $lastTurn,
Util::choiceRandomUsingWeightPair($candidateArgs)
);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -1203,7 +1203,7 @@ class GeneralAI
'che_포상', $this->general, $this->env, $lastTurn,
Util::choiceRandomUsingWeightPair($candidateArgs)
);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -1287,7 +1287,7 @@ class GeneralAI
'che_포상', $this->general, $this->env, $lastTurn,
Util::choiceRandomUsingWeightPair($candidateArgs)
);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -1398,7 +1398,7 @@ class GeneralAI
'che_포상', $this->general, $this->env, $lastTurn,
Util::choiceRandomUsingWeightPair($candidateArgs)
);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -1528,7 +1528,7 @@ class GeneralAI
'che_몰수', $this->general, $this->env, $lastTurn,
Util::choiceRandomUsingWeightPair($candidateArgs)
);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -1635,7 +1635,7 @@ class GeneralAI
$cmd = buildNationCommandClass('che_선전포고', $this->general, $this->env, $lastTurn, [
'destNationID' => Util::choiceRandomUsingWeight($nations)
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -1654,7 +1654,7 @@ class GeneralAI
//천도를 한턴 넣었다면 계속 넣는다.
if($lastTurn->getCommand() === '천도' && $lastTurn->getArg()['destCityID'] != $this->nation['capital']){
$cmd = buildNationCommandClass('che_천도', $this->general, $this->env, $lastTurn, $lastTurn->getArg());
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$nationStor->setValue("last천도Trial_{$this->nation['nation']}", [$general->getVar('officer_level'), $general->getTurnTime()]);
return $cmd;
}
@@ -1771,7 +1771,7 @@ class GeneralAI
'destCityID'=>$targetCityID
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -1802,13 +1802,13 @@ class GeneralAI
if ($genType & self::t통솔장) {
if ($develRate['trust'] < 0.95) {
$cmd = buildGeneralCommandClass('che_주민선정', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, $leadership / Util::valueFit($develRate['trust']-0.2, 0.001) * 2];
}
}
if ($develRate['pop'] < 0.8) {
$cmd = buildGeneralCommandClass('che_정착장려', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, $leadership / Util::valueFit($develRate['pop'], 0.001)];
}
}
@@ -1817,19 +1817,19 @@ class GeneralAI
if($genType & self::t무장){
if($develRate['def'] < 1){
$cmd = buildGeneralCommandClass('che_수비강화', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, $strength / Util::valueFit($develRate['def'], 0.001)];
}
}
if($develRate['wall'] < 1){
$cmd = buildGeneralCommandClass('che_성벽보수', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, $strength / Util::valueFit($develRate['wall'], 0.001)];
}
}
if($develRate['secu'] < 0.9){
$cmd = buildGeneralCommandClass('che_치안강화', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, $strength / Util::valueFit($develRate['comm'] / 0.8, 0.001, 1)];
}
}
@@ -1838,7 +1838,7 @@ class GeneralAI
if($genType & self::t지장){
if (!TechLimit($env['startyear'], $env['year'], $nation['tech'])) {
$cmd = buildGeneralCommandClass('che_기술연구', $general, $env);
if ($cmd->isRunnable()) {
if ($cmd->hasFullConditionMet()) {
$nextTech = $nation['tech'] % 1000 + 1;
if (!TechLimit($env['startyear'], $env['year'], $nation['tech'] + 1000)) {
//한등급 이상 뒤쳐져 있다면, 조금 더 열심히 하자.
@@ -1850,13 +1850,13 @@ class GeneralAI
}
if ($develRate['agri'] < 1) {
$cmd = buildGeneralCommandClass('che_농지개간', $general, $env);
if ($cmd->isRunnable()) {
if ($cmd->hasFullConditionMet()) {
$cmdList[] = [$cmd, ($isSpringSummer?1.2:0.8) * $intel / Util::valueFit($develRate['agri'], 0.001, 1)];
}
}
if ($develRate['comm'] < 1) {
$cmd = buildGeneralCommandClass('che_상업투자', $general, $env);
if ($cmd->isRunnable()) {
if ($cmd->hasFullConditionMet()) {
$cmdList[] = [$cmd, ($isSpringSummer?0.8:1.2) * $intel / Util::valueFit($develRate['comm'], 0.001, 1)];
}
}
@@ -1887,14 +1887,14 @@ class GeneralAI
if($city['trust'] < 70 && Util::randBool($leadership / GameConst::$chiefStatMin)){
$cmd = buildGeneralCommandClass('che_주민선정', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
return $cmd;
}
}
if($city['pop'] < $this->nationPolicy->minNPCRecruitCityPopulation && Util::randBool($leadership / GameConst::$chiefStatMin / 2)){
$cmd = buildGeneralCommandClass('che_정착장려', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
return $cmd;
}
}
@@ -1927,13 +1927,13 @@ class GeneralAI
if ($genType & self::t통솔장) {
if ($develRate['trust'] < 0.95) {
$cmd = buildGeneralCommandClass('che_주민선정', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, $leadership / Util::valueFit($develRate['trust']-0.2, 0.001) * 2];
}
}
if ($develRate['pop'] < 0.8) {
$cmd = buildGeneralCommandClass('che_정착장려', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
if (in_array($city['front'], [1, 3])) {
$cmdList[] = [$cmd, $leadership / Util::valueFit($develRate['pop'], 0.001)];
}
@@ -1947,19 +1947,19 @@ class GeneralAI
if($genType & self::t무장){
if($develRate['def'] < 0.5){
$cmd = buildGeneralCommandClass('che_수비강화', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, $strength / Util::valueFit($develRate['def'], 0.001) / 2];
}
}
if($develRate['wall'] < 0.5){
$cmd = buildGeneralCommandClass('che_성벽보수', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, $strength / Util::valueFit($develRate['wall'], 0.001) / 2];
}
}
if($develRate['secu'] < 0.5){
$cmd = buildGeneralCommandClass('che_치안강화', $general, $env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, $strength / Util::valueFit($develRate['secu'] / 0.8, 0.001, 1) / 4];
}
}
@@ -1968,7 +1968,7 @@ class GeneralAI
if($genType & self::t지장){
if (!TechLimit($env['startyear'], $env['year'], $nation['tech'])) {
$cmd = buildGeneralCommandClass('che_기술연구', $general, $env);
if ($cmd->isRunnable()) {
if ($cmd->hasFullConditionMet()) {
$nextTech = $nation['tech'] % 1000 + 1;
if (!TechLimit($env['startyear'], $env['year'], $nation['tech'] + 1000)) {
//한등급 이상 뒤쳐져 있다면, 조금 더 열심히 하자. 전쟁중이면 더더욱
@@ -1980,7 +1980,7 @@ class GeneralAI
}
if ($develRate['agri'] < 0.5) {
$cmd = buildGeneralCommandClass('che_농지개간', $general, $env);
if ($cmd->isRunnable()) {
if ($cmd->hasFullConditionMet()) {
if (in_array($city['front'], [1, 3])) {
$cmdList[] = [$cmd, ($isSpringSummer?1.2:0.8) * $intel / 4 / Util::valueFit($develRate['agri'], 0.001, 1)];
}
@@ -1991,7 +1991,7 @@ class GeneralAI
}
if ($develRate['comm'] < 0.5) {
$cmd = buildGeneralCommandClass('che_상업투자', $general, $env);
if ($cmd->isRunnable()) {
if ($cmd->hasFullConditionMet()) {
if (in_array($city['front'], [1, 3])) {
$cmdList[] = [$cmd, ($isSpringSummer?0.8:1.2) * $intel / 4 / Util::valueFit($develRate['comm'], 0.001, 1)];
}
@@ -2055,7 +2055,7 @@ class GeneralAI
'amount' => Util::valueFit(Util::toInt($general->getVar('gold') - $avgAmount), 100, GameConst::$maxResourceActionAmount)
]
);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
return $cmd;
}
}
@@ -2067,7 +2067,7 @@ class GeneralAI
'amount' => Util::valueFit(Util::toInt($general->getVar('rice') - $avgAmount), 100, GameConst::$maxResourceActionAmount)
]
);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
return $cmd;
}
}
@@ -2081,7 +2081,7 @@ class GeneralAI
'amount' => Util::valueFit(Util::toInt($general->getVar('gold') - $avgAmount), 100, GameConst::$maxResourceActionAmount)
]
);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
return $cmd;
}
}
@@ -2093,7 +2093,7 @@ class GeneralAI
'amount' => Util::valueFit(Util::toInt($general->getVar('rice') - $avgAmount), 100, GameConst::$maxResourceActionAmount)
]
);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
return $cmd;
}
}
@@ -2250,7 +2250,7 @@ class GeneralAI
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
return $cmd;
@@ -2269,14 +2269,14 @@ class GeneralAI
if($train < $this->nationPolicy->properWarTrainAtmos){
$cmd = buildGeneralCommandClass('che_훈련', $general, $this->env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, GameConst::$maxTrainByCommand / Util::valueFit($train, 1)];
}
}
if($atmos < $this->nationPolicy->properWarTrainAtmos){
$cmd = buildGeneralCommandClass('che_사기진작', $general, $this->env);
if($cmd->isRunnable()){
if($cmd->hasFullConditionMet()){
$cmdList[] = [$cmd, GameConst::$maxAtmosByCommand / Util::valueFit($atmos, 1)];
}
}
@@ -2302,7 +2302,7 @@ class GeneralAI
return null;
}
$cmd = buildGeneralCommandClass('che_소집해제', $this->general, $this->env);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
return $cmd;
@@ -2369,7 +2369,7 @@ class GeneralAI
}
$cmd = buildGeneralCommandClass('che_출병', $general, $this->env, ['destCityID' => Util::choiceRandom($attackableCities)]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2441,7 +2441,7 @@ class GeneralAI
}
$cmd = buildGeneralCommandClass('che_헌납', $general, $this->env, Util::choiceRandomUsingWeightPair($args));
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
return $cmd;
@@ -2518,7 +2518,7 @@ class GeneralAI
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2565,7 +2565,7 @@ class GeneralAI
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2634,7 +2634,7 @@ class GeneralAI
'optionText' => '순간이동',
'destCityID' => Util::choiceRandomUsingWeight($candidateCities),
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2651,7 +2651,7 @@ class GeneralAI
}
$cmd = buildGeneralCommandClass('che_귀환', $this->general, $this->env);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2723,7 +2723,7 @@ class GeneralAI
$cmd = buildGeneralCommandClass('che_이동', $general, $this->env, [
'destCityID'=>Util::choiceRandomUsingWeight($targetCity)
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2756,7 +2756,7 @@ class GeneralAI
}
$cmd = buildGeneralCommandClass('che_거병', $general, $this->env, null);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2766,7 +2766,7 @@ class GeneralAI
protected function do해산(): ?GeneralCommand
{
$cmd = buildGeneralCommandClass('che_해산', $this->general, $this->env, null);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2782,7 +2782,7 @@ class GeneralAI
'nationType' => $nationType,
'colorType' => $nationColor
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2796,7 +2796,7 @@ class GeneralAI
'destGeneralID' => $db->queryFirstField('SELECT `no` FROM general WHERE nation = %i AND npc != 5 ORDER BY RAND() LIMIT 1', $this->general->getNationID())
]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2820,7 +2820,7 @@ class GeneralAI
if ($rulerNation) {
$cmd = buildGeneralCommandClass('che_임관', $general, $env, ['destNationID' => $rulerNation]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2849,7 +2849,7 @@ class GeneralAI
//랜임 커맨드 입력.
$cmd = buildGeneralCommandClass('che_랜덤임관', $general, $env);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2860,7 +2860,7 @@ class GeneralAI
$paths = array_keys(CityConst::byID($city['city'])->path);
$cmd = buildGeneralCommandClass('che_이동', $general, $env, ['destCityID' => Util::choiceRandom($paths)]);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return null;
}
@@ -2919,7 +2919,7 @@ class GeneralAI
$cmd = buildGeneralCommandClass(Util::choiceRandom($candidate), $this->general, $this->env);
if(!$cmd->isRunnable()){
if(!$cmd->hasFullConditionMet()){
return buildGeneralCommandClass('che_물자조달', $this->general, $this->env);
}
return $cmd;
@@ -3105,7 +3105,7 @@ class GeneralAI
}
if(!($reservedCommand instanceof Command\Nation\휴식)){
if($reservedCommand->isRunnable()){
if($reservedCommand->hasFullConditionMet()){
$reservedCommand->reason = 'reserved';
return $reservedCommand;
}
@@ -3136,7 +3136,7 @@ class GeneralAI
}
public function chooseInstantNationTurn(NationCommand $reservedCommand): ?NationCommand{
if($reservedCommand->isRunnable()){
if($reservedCommand->hasFullConditionMet()){
return $reservedCommand;
}
+1 -1
View File
@@ -84,7 +84,7 @@ class ScoutMessage extends Message{
'month'=>$this->msgOption['month']
]);
if(!$commandObj->isRunnable()){
if(!$commandObj->hasFullConditionMet()){
$logger->pushGeneralActionLog($commandObj->getFailString());
return self::DECLINED;
}
+2 -4
View File
@@ -67,8 +67,7 @@ class TurnExecutionHelper
$general = $this->getGeneral();
while(true){
$failReason = $commandObj->testRunnable();
if($failReason){
if($commandObj->hasFullConditionMet()){
$date = $general->getTurnTime($general::TURNTIME_HM);
$failString = $commandObj->getFailString();
$text = "{$failString} <1>{$date}</>";
@@ -110,8 +109,7 @@ class TurnExecutionHelper
$commandClassName = $commandObj->getName();
while(true){
$failReason = $commandObj->testRunnable();
if($failReason){
if($commandObj->hasFullConditionMet()){
$date = $general->getTurnTime($general::TURNTIME_HM);
$failString = $commandObj->getFailString();
$text = "{$failString} <1>{$date}</>";