전략 사용 방식 변경

This commit is contained in:
2020-07-13 21:54:32 +09:00
parent 189db2a051
commit a09511defb
24 changed files with 4024 additions and 3910 deletions
+34 -1
View File
@@ -17,6 +17,7 @@ use \sammo\Constraint\ConstraintHelper;
abstract class BaseCommand{
static protected $actionName = 'CommandName';
static public $reqArg = false;
static protected $isLazyCalcReqTurn = false;
public function getCommandDetailTitle():string{
return $this->getName();
@@ -54,7 +55,6 @@ abstract class BaseCommand{
static protected $isInitStatic = true;
protected static function initStatic(){
}
public function __construct(General $generalObj, array $env, $arg = null){
@@ -271,6 +271,29 @@ abstract class BaseCommand{
return $this->logger;
}
abstract protected function getNextExecuteKey():string;
abstract public function getNextAvailable():?int;
abstract public function setNextAvailable(?int $yearMonth=null);
protected function testPostReqTurn():?array{
if(!$this->getPostReqTurn()){
return null;
}
$nextAvailable = $this->getNextAvailable();
if($nextAvailable === null){
return null;
}
$yearMonth = Util::joinYearMonth($this->env['year'], $this->env['month']);
$remainTurn = $nextAvailable - $yearMonth - $this->getPreReqTurn();
if($remainTurn <= 0){
return null;
}
return ['testPostReqTurn', "{$remainTurn}턴 더 기다려야 합니다"];
}
public function testPermissionToReserve():?string{
if($this->cachedPermissionToReserve){
return $this->reasonNoPermissionToReserve;
@@ -331,6 +354,11 @@ abstract class BaseCommand{
];
[$this->reasonConstraint, $this->reasonNotMinConditionMet] = Constraint::testAll($this->minConditionConstraints??[], $constraintInput, $this->env);
if($this->reasonNotMinConditionMet === null && !self::$isLazyCalcReqTurn){
[$this->reasonConstraint, $this->reasonNotMinConditionMet] = $this->testPostReqTurn();
}
$this->cachedMinConditionMet = true;
return $this->reasonNotMinConditionMet;
@@ -364,6 +392,11 @@ abstract class BaseCommand{
];
[$this->reasonConstraint, $this->reasonNotFullConditionMet] = Constraint::testAll($this->fullConditionConstraints??[], $constraintInput, $this->env);
if($this->reasonNotFullConditionMet === null){
[$this->reasonConstraint, $this->reasonNotFullConditionMet] = $this->testPostReqTurn();
}
$this->cachedFullConditionMet = true;
return $this->reasonNotFullConditionMet;
@@ -32,24 +32,6 @@ class che_전투특기초기화 extends Command\GeneralCommand{
}
protected function init(){
$general = $this->generalObj;
$env = $this->env;
$yearMonth = Util::joinYearMonth($env['year'], $env['month']);
$auxYearMonth = $general->getAuxVar('used_'.$this->getName())??-999;
if($yearMonth < $auxYearMonth + 60 - $this->getPreReqTurn()){
$this->minConditionConstraints=[
ConstraintHelper::AlwaysFail('초기화한 지 5년이 지나야합니다')
];
$this->fullConditionConstraints=[
ConstraintHelper::AlwaysFail('초기화한 지 5년이 지나야합니다')
];
return;
}
$this->minConditionConstraints=[
ConstraintHelper::ReqGeneralValue(static::$specialType, static::$specialText, '!=', 'None', '특기가 없습니다.'),
];
@@ -57,7 +39,6 @@ class che_전투특기초기화 extends Command\GeneralCommand{
$this->fullConditionConstraints=[
ConstraintHelper::ReqGeneralValue(static::$specialType, static::$specialText, '!=', 'None', '특기가 없습니다.')
];
}
public function getCommandDetailTitle():string{
@@ -82,7 +63,7 @@ class che_전투특기초기화 extends Command\GeneralCommand{
}
public function getPostReqTurn():int{
return 0;
return 60;
}
public function getTermString():string{
@@ -113,7 +94,6 @@ class che_전투특기초기화 extends Command\GeneralCommand{
$general->setVar(static::$specialType, 'None');
$general->setVar(static::$speicalAge, $general->getVar('age') + 1);
$general->setAuxVar('used_'.$this->getName(), $yearMonth);
$logger = $general->getLogger();
+35 -5
View File
@@ -1,6 +1,36 @@
<?php
namespace sammo\Command;
abstract class GeneralCommand extends BaseCommand{
<?php
namespace sammo\Command;
use \sammo\Util;
abstract class GeneralCommand extends BaseCommand{
protected function getNextExecuteKey():string{
$turnKey = static::$actionName;
$generalID = $this->getGeneral()->getID();
$executeKey = "next_execute_{$generalID}_{$turnKey}";
return $executeKey;
}
public function getNextAvailable():?int{
if($this->isArgValid && !$this->getPostReqTurn()){
return null;
}
$db = \sammo\DB::db();
$lastExecuteStor = \sammo\KVStorage::getStorage($db, 'next_execute');
return $lastExecuteStor->getValue($this->getNextExecuteKey());
}
public function setNextAvailable(?int $yearMonth=null){
if(!$this->getPostReqTurn()){
return;
}
if($yearMonth === null){
$yearMonth = Util::joinYearMonth($this->env['year'], $this->env['month']) + $this->getPostReqTurn();
}
$db = \sammo\DB::db();
$lastExecuteStor = \sammo\KVStorage::getStorage($db, 'next_execute');
$lastExecuteStor->setValue($this->getNextExecuteKey(), $yearMonth);
}
};
+251 -251
View File
@@ -1,251 +1,251 @@
<?php
namespace sammo\Command\Nation;
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
Message,
MessageTarget
};
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
GetImageURL
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_급습 extends Command\NationCommand
{
static protected $actionName = '급습';
static public $reqArg = true;
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if (!is_int($destNationID)) {
return false;
}
if ($destNationID < 1) {
return false;
}
$this->arg = [
'destNationID' => $destNationID
];
return true;
}
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$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->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::AllowDiplomacyWithTerm(
1,
12,
'선포 12개월 이상인 상대국에만 가능합니다.'
),
ConstraintHelper::AvailableStrategicCommand(),
];
}
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount * 16) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}】에 {$commandName}";
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$env = $this->env;
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$nation = $this->nation;
$nationID = $nation['nation'];
$nationName = $nation['name'];
$destNation = $this->destNation;
$destNationID = $destNation['nation'];
$destNationName = $destNation['name'];
$josaYi = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
$commandName = $this->getName();
$josaUl = JosaUtil::pick($commandName, '을');
$logger = $general->getLogger();
$logger->pushGeneralActionLog("{$commandName} 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$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) {
$nationGeneralLogger = new ActionLogger($nationGeneralID, $nationID, $year, $month);
$nationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$nationGeneralLogger->flush();
}
$josaYiCommand = JosaUtil::pick($commandName, '이');
$broadcastMessage = "아국에 <M>{$commandName}</>{$josaYiCommand} 발동되었습니다.";
$destNationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach ($destNationGeneralList as $destNationGeneralID) {
$destNationGeneralLogger = new ActionLogger($destNationGeneralID, $destNationID, $year, $month);
$destNationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$destNationGeneralLogger->flush();
}
$destNationLogger = new ActionLogger(0, $destNationID, $year, $month);
$destNationLogger->pushNationalHistoryLog("<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국에 <M>{$commandName}</>{$josaUl} 발동");
$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),
], '(me = %i AND you = %i) OR (you = %i AND me = %i)', $nationID, $destNationID, $nationID, $destNationID);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/defaultSelectNationByMap.js'
];
}
public function getForm(): string
{
$generalObj = $this->generalObj;
$nationID = $generalObj->getNationID();
$nationList = [];
$testTurn = new LastTurn($this->getName(), null, $this->getPreReqTurn());
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->hasFullConditionMet()) {
$destNation['availableCommand'] = true;
} else {
$destNation['availableCommand'] = false;
}
$nationList[] = $destNation;
}
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
return ob_get_clean();
}
}
<?php
namespace sammo\Command\Nation;
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
Message,
MessageTarget
};
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
GetImageURL
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_급습 extends Command\NationCommand
{
static protected $actionName = '급습';
static public $reqArg = true;
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if (!is_int($destNationID)) {
return false;
}
if ($destNationID < 1) {
return false;
}
$this->arg = [
'destNationID' => $destNationID
];
return true;
}
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->minConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn()),
];
}
protected function initWithArg()
{
$this->setDestNation($this->arg['destNationID'], null);
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::AllowDiplomacyWithTerm(
1,
12,
'선포 12개월 이상인 상대국에만 가능합니다.'
),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn()),
];
}
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount * 16) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}】에 {$commandName}";
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$env = $this->env;
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$nation = $this->nation;
$nationID = $nation['nation'];
$nationName = $nation['name'];
$destNation = $this->destNation;
$destNationID = $destNation['nation'];
$destNationName = $destNation['name'];
$josaYi = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
$commandName = $this->getName();
$josaUl = JosaUtil::pick($commandName, '을');
$logger = $general->getLogger();
$logger->pushGeneralActionLog("{$commandName} 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$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) {
$nationGeneralLogger = new ActionLogger($nationGeneralID, $nationID, $year, $month);
$nationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$nationGeneralLogger->flush();
}
$josaYiCommand = JosaUtil::pick($commandName, '이');
$broadcastMessage = "아국에 <M>{$commandName}</>{$josaYiCommand} 발동되었습니다.";
$destNationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach ($destNationGeneralList as $destNationGeneralID) {
$destNationGeneralLogger = new ActionLogger($destNationGeneralID, $destNationID, $year, $month);
$destNationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$destNationGeneralLogger->flush();
}
$destNationLogger = new ActionLogger(0, $destNationID, $year, $month);
$destNationLogger->pushNationalHistoryLog("<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국에 <M>{$commandName}</>{$josaUl} 발동");
$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),
], '(me = %i AND you = %i) OR (you = %i AND me = %i)', $nationID, $destNationID, $nationID, $destNationID);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/defaultSelectNationByMap.js'
];
}
public function getForm(): string
{
$generalObj = $this->generalObj;
$nationID = $generalObj->getNationID();
$nationList = [];
$testTurn = new LastTurn($this->getName(), null, $this->getPreReqTurn());
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->hasFullConditionMet()) {
$destNation['availableCommand'] = true;
} else {
$destNation['availableCommand'] = false;
}
$nationList[] = $destNation;
}
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
return ob_get_clean();
}
}
@@ -124,9 +124,18 @@ class che_물자원조 extends Command\NationCommand{
}
public function getPostReqTurn():int{
//NOTE: 자체 postReqTurn 사용
return 12;
}
public function getNextAvailable():?int{
return null;
}
public function setNextAvailable(?int $yearMonth=null){
return;
}
public function getBrief():string{
[$goldAmount, $riceAmount] = $this->arg['amountList'];
$goldAmountText = number_format($goldAmount);
+192 -195
View File
@@ -1,196 +1,193 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
MessageTarget,
Message,
CityConst
};
use function \sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL,
getNationStaticInfo
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_백성동원 extends Command\NationCommand{
static protected $actionName = '백성동원';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
return false;
}
if(!key_exists('destCityID', $this->arg)){
return false;
}
if(CityConst::byID($this->arg['destCityID']) === null){
return false;
}
$destCityID = $this->arg['destCityID'];
$this->arg = [
'destCityID'=>$destCityID,
];
return true;
}
protected function init(){
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$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(), [
0, 1
], '전쟁중이 아닙니다.'),
ConstraintHelper::OccupiedDestCity(),
ConstraintHelper::AvailableStrategicCommand()
];
}
public function getCommandDetailTitle():string{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn()+1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 0;
}
public function getPostReqTurn():int{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount*4)*10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief():string{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
return "{$destCityName}】에 {$commandName}";
}
public function run():bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$destCity = $this->destCity;
$destCityID = $destCity['city'];
$destCityName = $destCity['name'];
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$logger->pushGeneralActionLog("백성동원 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$josaYi = JosaUtil::pick($generalName, '이');
$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){
$targetLogger = new ActionLogger($targetGeneralID, $nationID, $year, $month);
$targetLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$targetLogger->flush();
}
$db->update('city', [
'def' => $db->sqleval('GREATEST(def_max * 0.8, def)'),
'wall' => $db->sqleval('GREATEST(wall_max * 0.8, wall)'),
], 'city=%i', $destCityID);
$josaYiNation = JosaUtil::pick($nationName, '이');
$logger->pushGeneralHistoryLog('<M>백성동원</>을 발동');
$logger->pushNationalHistoryLog("<L><b>【전략】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>에 <M>백성동원</>을 하였습니다.");
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/defaultSelectCityByMap.js'
];
}
public function getForm(): string
{
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>
<?php
return ob_get_clean();
}
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
MessageTarget,
Message,
CityConst
};
use function \sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL,
getNationStaticInfo
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_백성동원 extends Command\NationCommand{
static protected $actionName = '백성동원';
static public $reqArg = true;
protected function argTest():bool{
if($this->arg === null){
return false;
}
if(!key_exists('destCityID', $this->arg)){
return false;
}
if(CityConst::byID($this->arg['destCityID']) === null){
return false;
}
$destCityID = $this->arg['destCityID'];
$this->arg = [
'destCityID'=>$destCityID,
];
return true;
}
protected function init(){
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->minConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn())
];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
$this->setDestNation($this->destCity['nation']);
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::OccupiedDestCity(),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn())
];
}
public function getCommandDetailTitle():string{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn()+1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 0;
}
public function getPostReqTurn():int{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount*4)*10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief():string{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
return "{$destCityName}】에 {$commandName}";
}
public function run():bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$destCity = $this->destCity;
$destCityID = $destCity['city'];
$destCityName = $destCity['name'];
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$logger->pushGeneralActionLog("백성동원 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$josaYi = JosaUtil::pick($generalName, '이');
$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){
$targetLogger = new ActionLogger($targetGeneralID, $nationID, $year, $month);
$targetLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$targetLogger->flush();
}
$db->update('city', [
'def' => $db->sqleval('GREATEST(def_max * 0.8, def)'),
'wall' => $db->sqleval('GREATEST(wall_max * 0.8, wall)'),
], 'city=%i', $destCityID);
$josaYiNation = JosaUtil::pick($nationName, '이');
$logger->pushGeneralHistoryLog('<M>백성동원</>을 발동');
$logger->pushNationalHistoryLog("<L><b>【전략】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>에 <M>백성동원</>을 하였습니다.");
$db->update('nation', [
'strategic_cmd_limit' => 12
], 'nation=%i', $nationID);
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/defaultSelectCityByMap.js'
];
}
public function getForm(): string
{
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>
<?php
return ob_get_clean();
}
}
+3 -3
View File
@@ -60,7 +60,7 @@ class che_수몰 extends Command\NationCommand{
$this->minConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand(),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn()),
];
}
@@ -75,7 +75,7 @@ class che_수몰 extends Command\NationCommand{
ConstraintHelper::NotNeutralDestCity(),
ConstraintHelper::NotOccupiedDestCity(),
ConstraintHelper::BattleGroundCity(),
ConstraintHelper::AvailableStrategicCommand(),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn()),
];
}
@@ -179,7 +179,7 @@ class che_수몰 extends Command\NationCommand{
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>수몰</>을 발동");
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
'strategic_cmd_limit' => 12
], 'nation=%i', $nationID);
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
+243 -243
View File
@@ -1,243 +1,243 @@
<?php
namespace sammo\Command\Nation;
use\sammo\{
DB,
Util,
JosaUtil,
General,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
KVStorage
};
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
tryUniqueItemLottery
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_의병모집 extends Command\NationCommand
{
static protected $actionName = '의병모집';
protected function argTest(): bool
{
$this->arg = null;
return true;
}
protected function init()
{
$general = $this->generalObj;
$this->setNation(['strategic_cmd_limit']);
$this->setCity();
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$this->fullConditionConstraints = [
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::AvailableStrategicCommand(),
ConstraintHelper::NotOpeningPart($relYear),
];
}
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 2;
}
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount * 10) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$env = $this->env;
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$nation = $this->nation;
$nationID = $nation['nation'];
$nationName = $nation['name'];
$commandName = $this->getName();
$josaUl = JosaUtil::pick($commandName, '을');
$genCount = $db->queryFirstField('SELECT count(no) FROM general WHERE nation=%i AND npc < 2', $nationID);
$npcCount = $db->queryFirstField('SELECT count(no) FROM general WHERE nation=%i AND npc = 3', $nationID);
$npcOtherCount = $db->queryFirstField('SELECT count(no) FROM general WHERE nation!=%i AND npc = 3', $nationID);
$genCount = Util::valueFit($genCount, 1);
$npcCount = Util::valueFit($npcCount, 1);
$npcOtherCountScore = Util::round(sqrt($npcOtherCount + 1)) - 1;
$logger = $general->getLogger();
$logger->pushGeneralActionLog("{$commandName} 발동! <1>$date</>");
$josaYi = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
$broadcastMessage = "<Y>{$generalName}</>{$josaYi} <M>{$commandName}</>{$josaUl} 발동하였습니다.";
$nationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach ($nationGeneralList as $nationGeneralID) {
$nationGeneralLogger = new ActionLogger($nationGeneralID, $nationID, $year, $month);
$nationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$nationGeneralLogger->flush();
}
$logger->pushGeneralHistoryLog("<M>{$commandName}</>{$josaUl} 발동");
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <M>{$commandName}</>{$josaUl} 발동");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$gameStor = KVStorage::getStorage($db, 'game_env'); //TODO: 차라리 env가 이거여야..?
$avgGenCnt = $db->queryFirstField('SELECT avg(gennum) FROM nation WHERE level > 0');
$createGenCnt = 5 + Util::round($avgGenCnt / 10);
$createGenIdx = $gameStor->npccount + 1;
$lastCreatGenIdx = $createGenIdx + $createGenCnt;
$pickTypeList = ['무' => 5, '지' => 5];
$avgGen = $db->queryFirstRow(
'SELECT avg(dedication) as ded,avg(experience) as exp,
avg(dex1+dex2+dex3+dex4) as dex_t, avg(age) as age, avg(dex5) as dex5
from general where nation=%i',
$nationID
);
$dexTotal = $avgGen['dex_t'];
for (; $createGenIdx <= $lastCreatGenIdx; $createGenIdx++) {
$pickType = Util::choiceRandomUsingWeight($pickTypeList);
$totalStat = GameConst::$defaultStatNPCMax * 2 + 10;
$minStat = 10;
$mainStat = GameConst::$defaultStatNPCMax - Util::randRangeInt(0, 10);
//TODO: defaultStatNPCTotal, defaultStatNPCMin 추가
$otherStat = $minStat + Util::randRangeInt(0, 5);
$subStat = $totalStat - $mainStat - $otherStat;
if ($subStat < $minStat) {
$subStat = $otherStat;
$otherStat = $minStat;
$mainStat = $totalStat - $subStat - $otherStat;
if ($mainStat) {
throw new \LogicException('기본 스탯 설정값이 잘못되어 있음');
}
}
if ($pickType == '무') {
$leadership = $subStat;
$strength = $mainStat;
$intel = $otherStat;
$dexVal = Util::choiceRandom([
[$dexTotal * 5 / 8, $dexTotal / 8, $dexTotal / 8, $dexTotal / 8],
[$dexTotal / 8, $dexTotal * 5 / 8, $dexTotal / 8, $dexTotal / 8],
[$dexTotal / 8, $dexTotal / 8, $dexTotal * 5 / 8, $dexTotal / 8],
]);
} else if ($pickType == '지') {
$leadership = $subStat;
$strength = $otherStat;
$intel = $mainStat;
$dexVal = [$dexTotal / 8, $dexTotal / 8, $dexTotal * 5 / 8, $dexTotal / 8];
} else {
$leadership = $otherStat;
$strength = $subStat;
$intel = $mainStat;
$dexVal = [$dexTotal / 4, $dexTotal / 4, $dexTotal / 4, $dexTotal / 4];
}
$leadership = Util::round($leadership);
$strength = Util::round($strength);
$intel = Util::round($intel);
$age = $avgGen['age'];
$newNPC = new \sammo\Scenario\NPC(
Util::randRangeInt(1, 150),
"의병장{$createGenIdx}",
null,
$nationID,
$general->getCityID(),
$leadership,
$strength,
$intel,
1,
$env['year'] - 20,
$env['year'] + 6,
null,
null
);
$newNPC->killturn = Util::randRangeInt(64, 70);
$newNPC->npc = 4;
$newNPC->setMoney(1000, 1000);
$newNPC->setExpDed($avgGen['exp'], $avgGen['ded']);
$newNPC->setDex(
$dexVal[0],
$dexVal[1],
$dexVal[2],
$dexVal[3],
$avgGen['dex5']
);
$newNPC->build($this->env);
}
$gameStor->npccount = $lastCreatGenIdx;
$db->update('nation', [
'gennum' => $db->sqleval('gennum + %i', $createGenCnt),
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
return true;
}
}
<?php
namespace sammo\Command\Nation;
use\sammo\{
DB,
Util,
JosaUtil,
General,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
KVStorage
};
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
tryUniqueItemLottery
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_의병모집 extends Command\NationCommand
{
static protected $actionName = '의병모집';
protected function argTest(): bool
{
$this->arg = null;
return true;
}
protected function init()
{
$general = $this->generalObj;
$this->setNation(['strategic_cmd_limit']);
$this->setCity();
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$this->fullConditionConstraints = [
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn()),
ConstraintHelper::NotOpeningPart($relYear),
];
}
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 2;
}
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount * 10) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$env = $this->env;
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$nation = $this->nation;
$nationID = $nation['nation'];
$nationName = $nation['name'];
$commandName = $this->getName();
$josaUl = JosaUtil::pick($commandName, '을');
$genCount = $db->queryFirstField('SELECT count(no) FROM general WHERE nation=%i AND npc < 2', $nationID);
$npcCount = $db->queryFirstField('SELECT count(no) FROM general WHERE nation=%i AND npc = 3', $nationID);
$npcOtherCount = $db->queryFirstField('SELECT count(no) FROM general WHERE nation!=%i AND npc = 3', $nationID);
$genCount = Util::valueFit($genCount, 1);
$npcCount = Util::valueFit($npcCount, 1);
$npcOtherCountScore = Util::round(sqrt($npcOtherCount + 1)) - 1;
$logger = $general->getLogger();
$logger->pushGeneralActionLog("{$commandName} 발동! <1>$date</>");
$josaYi = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
$broadcastMessage = "<Y>{$generalName}</>{$josaYi} <M>{$commandName}</>{$josaUl} 발동하였습니다.";
$nationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach ($nationGeneralList as $nationGeneralID) {
$nationGeneralLogger = new ActionLogger($nationGeneralID, $nationID, $year, $month);
$nationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$nationGeneralLogger->flush();
}
$logger->pushGeneralHistoryLog("<M>{$commandName}</>{$josaUl} 발동");
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <M>{$commandName}</>{$josaUl} 발동");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$gameStor = KVStorage::getStorage($db, 'game_env'); //TODO: 차라리 env가 이거여야..?
$avgGenCnt = $db->queryFirstField('SELECT avg(gennum) FROM nation WHERE level > 0');
$createGenCnt = 5 + Util::round($avgGenCnt / 10);
$createGenIdx = $gameStor->npccount + 1;
$lastCreatGenIdx = $createGenIdx + $createGenCnt;
$pickTypeList = ['무' => 5, '지' => 5];
$avgGen = $db->queryFirstRow(
'SELECT avg(dedication) as ded,avg(experience) as exp,
avg(dex1+dex2+dex3+dex4) as dex_t, avg(age) as age, avg(dex5) as dex5
from general where nation=%i',
$nationID
);
$dexTotal = $avgGen['dex_t'];
for (; $createGenIdx <= $lastCreatGenIdx; $createGenIdx++) {
$pickType = Util::choiceRandomUsingWeight($pickTypeList);
$totalStat = GameConst::$defaultStatNPCMax * 2 + 10;
$minStat = 10;
$mainStat = GameConst::$defaultStatNPCMax - Util::randRangeInt(0, 10);
//TODO: defaultStatNPCTotal, defaultStatNPCMin 추가
$otherStat = $minStat + Util::randRangeInt(0, 5);
$subStat = $totalStat - $mainStat - $otherStat;
if ($subStat < $minStat) {
$subStat = $otherStat;
$otherStat = $minStat;
$mainStat = $totalStat - $subStat - $otherStat;
if ($mainStat) {
throw new \LogicException('기본 스탯 설정값이 잘못되어 있음');
}
}
if ($pickType == '무') {
$leadership = $subStat;
$strength = $mainStat;
$intel = $otherStat;
$dexVal = Util::choiceRandom([
[$dexTotal * 5 / 8, $dexTotal / 8, $dexTotal / 8, $dexTotal / 8],
[$dexTotal / 8, $dexTotal * 5 / 8, $dexTotal / 8, $dexTotal / 8],
[$dexTotal / 8, $dexTotal / 8, $dexTotal * 5 / 8, $dexTotal / 8],
]);
} else if ($pickType == '지') {
$leadership = $subStat;
$strength = $otherStat;
$intel = $mainStat;
$dexVal = [$dexTotal / 8, $dexTotal / 8, $dexTotal * 5 / 8, $dexTotal / 8];
} else {
$leadership = $otherStat;
$strength = $subStat;
$intel = $mainStat;
$dexVal = [$dexTotal / 4, $dexTotal / 4, $dexTotal / 4, $dexTotal / 4];
}
$leadership = Util::round($leadership);
$strength = Util::round($strength);
$intel = Util::round($intel);
$age = $avgGen['age'];
$newNPC = new \sammo\Scenario\NPC(
Util::randRangeInt(1, 150),
"의병장{$createGenIdx}",
null,
$nationID,
$general->getCityID(),
$leadership,
$strength,
$intel,
1,
$env['year'] - 20,
$env['year'] + 6,
null,
null
);
$newNPC->killturn = Util::randRangeInt(64, 70);
$newNPC->npc = 4;
$newNPC->setMoney(1000, 1000);
$newNPC->setExpDed($avgGen['exp'], $avgGen['ded']);
$newNPC->setDex(
$dexVal[0],
$dexVal[1],
$dexVal[2],
$dexVal[3],
$avgGen['dex5']
);
$newNPC->build($this->env);
}
$gameStor->npccount = $lastCreatGenIdx;
$db->update('nation', [
'gennum' => $db->sqleval('gennum + %i', $createGenCnt),
'strategic_cmd_limit' => 12
], 'nation=%i', $nationID);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
return true;
}
}
+250 -250
View File
@@ -1,250 +1,250 @@
<?php
namespace sammo\Command\Nation;
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
Message,
MessageTarget
};
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
GetImageURL
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_이호경식 extends Command\NationCommand
{
static protected $actionName = '이호경식';
static public $reqArg = true;
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if (!is_int($destNationID)) {
return false;
}
if ($destNationID < 1) {
return false;
}
$this->arg = [
'destNationID' => $destNationID
];
return true;
}
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$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->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::AllowDiplomacyBetweenStatus(
[0, 1],
'선포, 전쟁중인 상대국에게만 가능합니다.'
),
ConstraintHelper::AvailableStrategicCommand(),
];
}
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount * 16) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}】에 {$commandName}";
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$env = $this->env;
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$nation = $this->nation;
$nationID = $nation['nation'];
$nationName = $nation['name'];
$destNation = $this->destNation;
$destNationID = $destNation['nation'];
$destNationName = $destNation['name'];
$josaYi = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
$commandName = $this->getName();
$josaUl = JosaUtil::pick($commandName, '을');
$logger = $general->getLogger();
$logger->pushGeneralActionLog("{$commandName} 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$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) {
$nationGeneralLogger = new ActionLogger($nationGeneralID, $nationID, $year, $month);
$nationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$nationGeneralLogger->flush();
}
$josaYiCommand = JosaUtil::pick($commandName, '이');
$broadcastMessage = "아국에 <M>{$commandName}</>{$josaYiCommand} 발동되었습니다.";
$destNationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach ($destNationGeneralList as $destNationGeneralID) {
$destNationGeneralLogger = new ActionLogger($destNationGeneralID, $destNationID, $year, $month);
$destNationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$destNationGeneralLogger->flush();
}
$destNationLogger = new ActionLogger(0, $destNationID, $year, $month);
$destNationLogger->pushNationalHistoryLog("<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국에 <M>{$commandName}</>{$josaUl} 발동");
$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,
], '(me = %i AND you = %i) OR (you = %i AND me = %i)', $nationID, $destNationID, $nationID, $destNationID);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/defaultSelectNationByMap.js'
];
}
public function getForm(): string
{
$generalObj = $this->generalObj;
$nationID = $generalObj->getNationID();
$nationList = [];
$testTurn = new LastTurn($this->getName(), null, $this->getPreReqTurn());
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->hasFullConditionMet()) {
$destNation['availableCommand'] = true;
} else {
$destNation['availableCommand'] = false;
}
$nationList[] = $destNation;
}
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
return ob_get_clean();
}
}
<?php
namespace sammo\Command\Nation;
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
Message,
MessageTarget
};
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
GetImageURL
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_이호경식 extends Command\NationCommand
{
static protected $actionName = '이호경식';
static public $reqArg = true;
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if (!is_int($destNationID)) {
return false;
}
if ($destNationID < 1) {
return false;
}
$this->arg = [
'destNationID' => $destNationID
];
return true;
}
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->minConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn()),
];
}
protected function initWithArg()
{
$this->setDestNation($this->arg['destNationID'], null);
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::AllowDiplomacyBetweenStatus(
[0, 1],
'선포, 전쟁중인 상대국에게만 가능합니다.'
),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn()),
];
}
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount * 16) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}】에 {$commandName}";
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$env = $this->env;
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$nation = $this->nation;
$nationID = $nation['nation'];
$nationName = $nation['name'];
$destNation = $this->destNation;
$destNationID = $destNation['nation'];
$destNationName = $destNation['name'];
$josaYi = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
$commandName = $this->getName();
$josaUl = JosaUtil::pick($commandName, '을');
$logger = $general->getLogger();
$logger->pushGeneralActionLog("{$commandName} 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$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) {
$nationGeneralLogger = new ActionLogger($nationGeneralID, $nationID, $year, $month);
$nationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$nationGeneralLogger->flush();
}
$josaYiCommand = JosaUtil::pick($commandName, '이');
$broadcastMessage = "아국에 <M>{$commandName}</>{$josaYiCommand} 발동되었습니다.";
$destNationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach ($destNationGeneralList as $destNationGeneralID) {
$destNationGeneralLogger = new ActionLogger($destNationGeneralID, $destNationID, $year, $month);
$destNationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$destNationGeneralLogger->flush();
}
$destNationLogger = new ActionLogger(0, $destNationID, $year, $month);
$destNationLogger->pushNationalHistoryLog("<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국에 <M>{$commandName}</>{$josaUl} 발동");
$destNationLogger->flush();
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <D><b>{$destNationName}</b></>에 <M>{$commandName}</>{$josaUl} 발동");
$db->update('nation', [
'strategic_cmd_limit' => 12
], 'nation=%i', $nationID);
$db->update('diplomacy', [
'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);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/defaultSelectNationByMap.js'
];
}
public function getForm(): string
{
$generalObj = $this->generalObj;
$nationID = $generalObj->getNationID();
$nationList = [];
$testTurn = new LastTurn($this->getName(), null, $this->getPreReqTurn());
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->hasFullConditionMet()) {
$destNation['availableCommand'] = true;
} else {
$destNation['availableCommand'] = false;
}
$nationList[] = $destNation;
}
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
return ob_get_clean();
}
}
@@ -95,9 +95,18 @@ class che_초토화 extends Command\NationCommand{
}
public function getPostReqTurn():int{
//NOTE: 자체 postReqTurn 사용
return 24;
}
public function getNextAvailable():?int{
return null;
}
public function setNextAvailable(?int $yearMonth=null){
return;
}
public function getCommandDetailTitle():string{
$name = $this->getName();
+256 -238
View File
@@ -1,239 +1,257 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
Message, MessageTarget
};
use function \sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
GetImageURL
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_피장파장 extends Command\NationCommand{
static protected $actionName = '피장파장';
static public $reqArg = true;
static public $delayCnt = 60;
protected function argTest():bool{
if($this->arg === null){
return false;
}
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('destNationID', $this->arg)){
return false;
}
$destNationID = $this->arg['destNationID'];
if(!is_int($destNationID)){
return false;
}
if($destNationID < 1){
return false;
}
$this->arg = [
'destNationID'=>$destNationID
];
return true;
}
protected function init(){
$general = $this->generalObj;
$env = $this->env;
$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->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::AllowDiplomacyBetweenStatus(
[0, 1],
'선포, 전쟁중인 상대국에게만 가능합니다.'
),
ConstraintHelper::AvailableStrategicCommand(),
];
}
public function getCommandDetailTitle():string{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn()+1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 2;
}
public function getPostReqTurn():int{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount*2)*10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief():string{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}】에 {$commandName}";
}
public function run():bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$env = $this->env;
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$nation = $this->nation;
$nationID = $nation['nation'];
$nationName = $nation['name'];
$destNation = $this->destNation;
$destNationID = $destNation['nation'];
$destNationName = $destNation['name'];
$josaYi = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
$commandName = $this->getName();
$josaUl = JosaUtil::pick($commandName, '을');
$logger = $general->getLogger();
$logger->pushGeneralActionLog("{$commandName} 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$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){
$nationGeneralLogger = new ActionLogger($nationGeneralID, $nationID, $year, $month);
$nationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$nationGeneralLogger->flush();
}
$josaYiCommand = JosaUtil::pick($commandName, '이');
$broadcastMessage = "아국에 <M>{$commandName}</>{$josaYiCommand} 발동되었습니다.";
$destNationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach($destNationGeneralList as $destNationGeneralID){
$destNationGeneralLogger = new ActionLogger($destNationGeneralID, $destNationID, $year, $month);
$destNationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$destNationGeneralLogger->flush();
}
$destNationLogger = new ActionLogger(0, $destNationID, $year, $month);
$destNationLogger->pushNationalHistoryLog("<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국에 <M>{$commandName}</>{$josaUl} 발동");
$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('nation', [
'strategic_cmd_limit' => $db->sqleval('strategic_cmd_limit + %i', static::$delayCnt)
], 'nation = %i', $destNationID);
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/defaultSelectNationByMap.js'
];
}
public function getForm(): string
{
$generalObj = $this->generalObj;
$nationID = $generalObj->getNationID();
$nationList = [];
$testTurn = new LastTurn($this->getName(), null, $this->getPreReqTurn());
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->hasFullConditionMet()){
$destNation['availableCommand'] = true;
}
else{
$destNation['availableCommand'] = false;
}
$nationList[] = $destNation;
}
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
return ob_get_clean();
}
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
Message, MessageTarget
};
use function \sammo\{
buildNationCommandClass,
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
getAllNationStaticInfo,
getNationStaticInfo,
GetImageURL
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_피장파장 extends Command\NationCommand{
static protected $actionName = '피장파장';
static public $reqArg = true;
static public $delayCnt = 60;
protected function argTest():bool{
if($this->arg === null){
return false;
}
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
if(!key_exists('destNationID', $this->arg)){
return false;
}
$destNationID = $this->arg['destNationID'];
if(!is_int($destNationID)){
return false;
}
if($destNationID < 1){
return false;
}
$this->arg = [
'destNationID'=>$destNationID
];
return true;
}
protected function init(){
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation();
$this->minConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
];
}
protected function initWithArg()
{
$this->setDestNation($this->arg['destNationID'], null);
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::AllowDiplomacyBetweenStatus(
[0, 1],
'선포, 전쟁중인 상대국에게만 가능합니다.'
),
];
}
public function getCommandDetailTitle():string{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn()+1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}";
}
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 1;
}
public function getPostReqTurn():int{
return 0;
}
public function getBrief():string{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}】에 {$commandName}";
}
public function run():bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$env = $this->env;
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$nation = $this->nation;
$nationID = $nation['nation'];
$nationName = $nation['name'];
$destNation = $this->destNation;
$destNationID = $destNation['nation'];
$destNationName = $destNation['name'];
$josaYi = JosaUtil::pick($generalName, '이');
$josaYiNation = JosaUtil::pick($nationName, '이');
$commandName = $this->getName();
$josaUl = JosaUtil::pick($commandName, '을');
$logger = $general->getLogger();
$logger->pushGeneralActionLog("{$commandName} 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$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){
$nationGeneralLogger = new ActionLogger($nationGeneralID, $nationID, $year, $month);
$nationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$nationGeneralLogger->flush();
}
$josaYiCommand = JosaUtil::pick($commandName, '이');
$broadcastMessage = "아국에 <M>{$commandName}</>{$josaYiCommand} 발동되었습니다.";
$destNationGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach($destNationGeneralList as $destNationGeneralID){
$destNationGeneralLogger = new ActionLogger($destNationGeneralID, $destNationID, $year, $month);
$destNationGeneralLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$destNationGeneralLogger->flush();
}
$destNationLogger = new ActionLogger(0, $destNationID, $year, $month);
$destNationLogger->pushNationalHistoryLog("<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국에 <M>{$commandName}</>{$josaUl} 발동");
$destNationLogger->flush();
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <D><b>{$destNationName}</b></>에 <M>{$commandName}</>{$josaUl} 발동");
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/defaultSelectNationByMap.js'
];
}
public function getForm(): string
{
$generalObj = $this->generalObj;
$nationID = $generalObj->getNationID();
$nationList = [];
$testTurn = new LastTurn($this->getName(), null, $this->getPreReqTurn());
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->hasFullConditionMet()){
$destNation['availableCommand'] = true;
}
else{
$destNation['availableCommand'] = false;
}
$nationList[] = $destNation;
}
$availableCommandTypeList = [];
$currYearMonth = Util::joinYearMonth($this->env['year'], $this->env['month']);
foreach(GameConst::$availableChiefCommand['전략'] as $commandType){
$cmd = buildNationCommandClass($commandType, $generalObj, $this->env, new LastTurn());
if($cmd->getName() == $this->getName()){
continue;
}
$cmdName = $cmd->getName();
$available = true;
$nextAvailable = $cmd->getNextAvailable();
if($nextAvailable !== null && $currYearMonth < $cmd->getNextAvailable() - $cmd->getPreReqTurn()){
$available = false;
}
$availableCommandTypeList[$commandType] = [$cmdName, $available];
}
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 국가에 피장파장을 발동합니다.<br>
지정한 전략을 상대국이 <?=static::$delayCnt?>턴 동안 사용할 수 없게됩니다.<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; ?>
<select class='formInput' name="commandType" id="commandType" size='1' style='color:white;background-color:black;'>
<?php foreach($availableCommandTypeList as $commandType=>[$cmdName, $cmdAvailable]):
/** @var \sammo\Command\NationCommand $cmdObj */
?>
<option
value='<?=$commandType?>'
style='color:white;<?=$cmdAvailable?'':'background-color:red;'?>'
>【<?=$cmdName?> 】</option>
<?php endforeach; ?>
</select>
<input type=button id="commonSubmit" value="<?=$this->getName()?>">
<?php
return ob_get_clean();
}
}
+133 -133
View File
@@ -1,134 +1,134 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
MessageTarget,
Message
};
use function \sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_필사즉생 extends Command\NationCommand{
static protected $actionName = '필사즉생';
protected function argTest():bool{
$this->arg = [];
return true;
}
protected function init(){
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AllowDiplomacyStatus($this->generalObj->getNationID(), [
0
], '전쟁중이 아닙니다.'),
ConstraintHelper::AvailableStrategicCommand()
];
}
public function getCommandDetailTitle():string{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn()+1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 2;
}
public function getPostReqTurn():int{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount*8)*10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function run():bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$logger->pushGeneralActionLog("필사즉생 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$josaYi = JosaUtil::pick($generalName, '이');
$broadcastMessage = "<Y>{$generalName}</>{$josaYi} <M>필사즉생</>을 발동하였습니다.";
$targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach(General::createGeneralObjListFromDB($targetGeneralList, ['train', 'atmos'], 1) as $targetGeneral){
$targetGeneral->getLogger()->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
if($targetGeneral->getVar('train') < 100){
$targetGeneral->setVar('train', 100);
}
if($targetGeneral->getVar('atmos') < 100){
$targetGeneral->setVar('atmos', 100);
}
$targetGeneral->applyDB($db);
}
if($general->getVar('train') < 100){
$general->setVar('train', 100);
}
if($general->getVar('atmos') < 100){
$general->setVar('atmos', 100);
}
$logger->pushGeneralHistoryLog('<M>필사즉생</>을 발동');
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <M>필사즉생</>을 발동");
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
MessageTarget,
Message
};
use function \sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_필사즉생 extends Command\NationCommand{
static protected $actionName = '필사즉생';
protected function argTest():bool{
$this->arg = [];
return true;
}
protected function init(){
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->fullConditionConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AllowDiplomacyStatus($this->generalObj->getNationID(), [
0
], '전쟁중이 아닙니다.'),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn())
];
}
public function getCommandDetailTitle():string{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn()+1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 2;
}
public function getPostReqTurn():int{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount*8)*10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function run():bool{
if(!$this->hasFullConditionMet()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$logger->pushGeneralActionLog("필사즉생 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$josaYi = JosaUtil::pick($generalName, '이');
$broadcastMessage = "<Y>{$generalName}</>{$josaYi} <M>필사즉생</>을 발동하였습니다.";
$targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach(General::createGeneralObjListFromDB($targetGeneralList, ['train', 'atmos'], 1) as $targetGeneral){
$targetGeneral->getLogger()->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
if($targetGeneral->getVar('train') < 100){
$targetGeneral->setVar('train', 100);
}
if($targetGeneral->getVar('atmos') < 100){
$targetGeneral->setVar('atmos', 100);
}
$targetGeneral->applyDB($db);
}
if($general->getVar('train') < 100){
$general->setVar('train', 100);
}
if($general->getVar('atmos') < 100){
$general->setVar('atmos', 100);
}
$logger->pushGeneralHistoryLog('<M>필사즉생</>을 발동');
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <M>필사즉생</>을 발동");
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
}
+239 -239
View File
@@ -1,239 +1,239 @@
<?php
namespace sammo\Command\Nation;
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
MessageTarget,
Message,
CityConst
};
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL,
getNationStaticInfo
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_허보 extends Command\NationCommand
{
static protected $actionName = '허보';
static public $reqArg = true;
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if (!key_exists('destCityID', $this->arg)) {
return false;
}
if (CityConst::byID($this->arg['destCityID']) === null) {
return false;
}
$destCityID = $this->arg['destCityID'];
$this->arg = [
'destCityID' => $destCityID,
];
return true;
}
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$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(),
ConstraintHelper::NotOccupiedDestCity(),
ConstraintHelper::AllowDiplomacyBetweenStatus(
[0, 1],
'선포, 전쟁중인 상대국에게만 가능합니다.'
),
ConstraintHelper::AvailableStrategicCommand(),
];
}
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 1;
}
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount * 4) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief(): string
{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
return "{$destCityName}】에 {$commandName}";
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$destCity = $this->destCity;
$destCityID = $destCity['city'];
$destCityName = $destCity['name'];
$destNationID = $destCity['nation'];
$destNationName = getNationStaticInfo($destNationID)['name'];
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$logger->pushGeneralActionLog("허보 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$josaYi = JosaUtil::pick($generalName, '이');
$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) {
$targetLogger = new ActionLogger($targetGeneralID, $nationID, $year, $month);
$targetLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$targetLogger->flush();
}
$destBroadcastMessage = "상대의 <M>허보</>에 당했다! <1>$date</>";
$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) {
$targetLogger = $targetGeneral->getLogger();
$targetLogger->pushGeneralActionLog($destBroadcastMessage, ActionLogger::PLAIN);
$moveCityID = Util::choiceRandom($destNationCityList);
if ($moveCityID == $destCityID) {
//현재도시면 다시 랜덤 추첨
$moveCityID = Util::choiceRandom($destNationCityList);
}
$targetGeneral->setVar('city', $moveCityID);
$targetGeneral->applyDB($db);
}
$destNationLogger = new ActionLogger(0, $destNationID, $year, $month);
$destNationLogger->pushNationalHistoryLog(
"<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국의 <G><b>{$destCityName}</b></>에 <M>허보</>를 발동",
ActionLogger::PLAIN
);
$destNationLogger->flush();
$db->update('city', [
'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>허보</>를 발동");
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>허보</>를 발동");
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/defaultSelectCityByMap.js'
];
}
public function getForm(): string
{
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>
<?php
return ob_get_clean();
}
}
<?php
namespace sammo\Command\Nation;
use\sammo\{
DB,
Util,
JosaUtil,
General,
DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
MessageTarget,
Message,
CityConst
};
use function\sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL,
getNationStaticInfo
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_허보 extends Command\NationCommand
{
static protected $actionName = '허보';
static public $reqArg = true;
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if (!key_exists('destCityID', $this->arg)) {
return false;
}
if (CityConst::byID($this->arg['destCityID']) === null) {
return false;
}
$destCityID = $this->arg['destCityID'];
$this->arg = [
'destCityID' => $destCityID,
];
return true;
}
protected function init()
{
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->minConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn()),
];
}
protected function initWithArg()
{
$this->setDestCity($this->arg['destCityID']);
$this->setDestNation($this->destCity['nation']);
$this->fullConditionConstraints = [
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::NotNeutralDestCity(),
ConstraintHelper::NotOccupiedDestCity(),
ConstraintHelper::AllowDiplomacyBetweenStatus(
[0, 1],
'선포, 전쟁중인 상대국에게만 가능합니다.'
),
ConstraintHelper::AvailableStrategicCommand($this->getPreReqTurn()),
];
}
public function getCommandDetailTitle(): string
{
$name = $this->getName();
$reqTurn = $this->getPreReqTurn() + 1;
$postReqTurn = $this->getPostReqTurn();
return "{$name}/{$reqTurn}턴(전략$postReqTurn)";
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 1;
}
public function getPostReqTurn(): int
{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount * 4) * 10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief(): string
{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
return "{$destCityName}】에 {$commandName}";
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$destCity = $this->destCity;
$destCityID = $destCity['city'];
$destCityName = $destCity['name'];
$destNationID = $destCity['nation'];
$destNationName = getNationStaticInfo($destNationID)['name'];
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$logger->pushGeneralActionLog("허보 발동! <1>$date</>");
$general->addExperience(5 * ($this->getPreReqTurn() + 1));
$general->addDedication(5 * ($this->getPreReqTurn() + 1));
$josaYi = JosaUtil::pick($generalName, '이');
$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) {
$targetLogger = new ActionLogger($targetGeneralID, $nationID, $year, $month);
$targetLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$targetLogger->flush();
}
$destBroadcastMessage = "상대의 <M>허보</>에 당했다! <1>$date</>";
$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) {
$targetLogger = $targetGeneral->getLogger();
$targetLogger->pushGeneralActionLog($destBroadcastMessage, ActionLogger::PLAIN);
$moveCityID = Util::choiceRandom($destNationCityList);
if ($moveCityID == $destCityID) {
//현재도시면 다시 랜덤 추첨
$moveCityID = Util::choiceRandom($destNationCityList);
}
$targetGeneral->setVar('city', $moveCityID);
$targetGeneral->applyDB($db);
}
$destNationLogger = new ActionLogger(0, $destNationID, $year, $month);
$destNationLogger->pushNationalHistoryLog(
"<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국의 <G><b>{$destCityName}</b></>에 <M>허보</>를 발동",
ActionLogger::PLAIN
);
$destNationLogger->flush();
$db->update('city', [
'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>허보</>를 발동");
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>허보</>를 발동");
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
public function getJSFiles(): array
{
return [
'js/defaultSelectCityByMap.js'
];
}
public function getForm(): string
{
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>
<?php
return ob_get_clean();
}
}
+57 -29
View File
@@ -1,30 +1,58 @@
<?php
namespace sammo\Command;
use \sammo\General;
use \sammo\LastTurn;
abstract class NationCommand extends BaseCommand{
protected $lastTurn;
protected $resultTurn;
public function __construct(General $generalObj, array $env, LastTurn $lastTurn, $arg = null){
$this->lastTurn = $lastTurn;
$this->resultTurn = $lastTurn->duplicate();
parent::__construct($generalObj, $env, $arg);
}
public function getLastTurn():LastTurn{
return $this->lastTurn;
}
public function setResultTurn(LastTurn $lastTurn){
$this->resultTurn = $lastTurn;
}
public function getResultTurn():LastTurn{
return $this->resultTurn;
}
<?php
namespace sammo\Command;
use \sammo\General;
use sammo\KVStorage;
use \sammo\LastTurn;
use \sammo\Util;
abstract class NationCommand extends BaseCommand{
protected $lastTurn;
protected $resultTurn;
public function __construct(General $generalObj, array $env, LastTurn $lastTurn, $arg = null){
$this->lastTurn = $lastTurn;
$this->resultTurn = $lastTurn->duplicate();
parent::__construct($generalObj, $env, $arg);
}
public function getLastTurn():LastTurn{
return $this->lastTurn;
}
public function setResultTurn(LastTurn $lastTurn){
$this->resultTurn = $lastTurn;
}
public function getResultTurn():LastTurn{
return $this->resultTurn;
}
protected function getNextExecuteKey():string{
$turnKey = static::$actionName;
$executeKey = "next_execute_{$turnKey}";
return $executeKey;
}
public function getNextAvailable():?int{
if($this->isArgValid && !$this->getPostReqTurn()){
return null;
}
$db = \sammo\DB::db();
$nationStor = \sammo\KVStorage::getStorage($db, $this->getNationID(), 'nation_env');
return $nationStor->getValue($this->getNextExecuteKey());
}
public function setNextAvailable(?int $yearMonth=null){
if(!$this->getPostReqTurn()){
return;
}
if($yearMonth === null){
$yearMonth = Util::joinYearMonth($this->env['year'], $this->env['month']) + $this->getPostReqTurn();
}
$db = \sammo\DB::db();
$nationStor = \sammo\KVStorage::getStorage($db, $this->getNationID(), 'nation_env');
$nationStor->setValue($this->getNextExecuteKey(), $yearMonth);
}
};