전략 구현

This commit is contained in:
2020-05-03 17:30:43 +09:00
parent 44305b9abf
commit 50c30b7cd0
11 changed files with 554 additions and 13 deletions
+3 -3
View File
@@ -1633,7 +1633,7 @@ function nextRuler(General $general) {
//npc or npc유저인 경우 후계 찾기
if($general->getVar('npc') > 0) {
$candidate = $db->queryFirstRow(
'SELECT no,name,officer_level,IF(ABS(affinity-%i)>75,150-ABS(affinity-%i),ABS(affinity-%i)) as npcmatch2 from general where nation=%i and officer_level!=12 and npc>0 order by npcmatch2,rand() LIMIT 1',
'SELECT no,name,officer_level,IF(ABS(affinity-%i)>75,150-ABS(affinity-%i),ABS(affinity-%i)) as npcmatch2 from general where nation=%i and officer_level!=12 and 1 <= npc and npc<=3 order by npcmatch2,rand() LIMIT 1',
$general->getVar('affinity'),
$general->getVar('affinity'),
$general->getVar('affinity'),
@@ -1642,13 +1642,13 @@ function nextRuler(General $general) {
}
if(!$candidate){
$candidate = $db->queryFirstRow(
'SELECT no,name,npc,officer_level FROM general WHERE nation=%i and officer_level!= 12 AND officer_level >= 9 ORDER BY officer_level DESC LIMIT 1',
'SELECT no,name,npc,officer_level FROM general WHERE nation=%i and officer_level!= 12 AND officer_level >= 9 and npc != 5 ORDER BY officer_level DESC LIMIT 1',
$nationID
);
}
if(!$candidate){
$candidate = $db->queryFirstRow(
'SELECT no,name,npc,officer_level FROM general WHERE nation=%i and officer_level!= 12 ORDER BY dedication DESC LIMIT 1',
'SELECT no,name,npc,officer_level FROM general WHERE nation=%i and officer_level!= 12 and npc != 5 ORDER BY dedication DESC LIMIT 1',
$nationID
);
}
+230
View File
@@ -0,0 +1,230 @@
<?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->setDestNation($this->arg['destNationID'], null);
$this->runnableConstraints=[
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->isRunnable()){
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);
$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->isRunnable()){
$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();
}
}
@@ -150,7 +150,9 @@ class che_백성동원 extends Command\NationCommand{
$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);
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
+3 -1
View File
@@ -169,7 +169,9 @@ class che_수몰 extends Command\NationCommand{
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>수몰</>을 발동");
$logger->pushGlobalHistoryLog("<L><b>【전략】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>에 <M>수몰</>을 발동하였습니다.");
$db->update('nation', ['strategic_cmd_limit' => $this->getPostReqTurn()], 'nation=%i', $nationID);
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
@@ -0,0 +1,231 @@
<?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->setDestNation($this->arg['destNationID'], null);
$this->runnableConstraints=[
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->isRunnable()){
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);
$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->isRunnable()){
$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();
}
}
@@ -65,6 +65,7 @@ class che_피장파장 extends Command\NationCommand{
$this->runnableConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::AllowDiplomacyBetweenStatus(
[0, 1],
'선포, 전쟁중인 상대국에게만 가능합니다.'
@@ -167,6 +168,9 @@ class che_피장파장 extends Command\NationCommand{
$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);
@@ -123,11 +123,9 @@ class che_필사즉생 extends Command\NationCommand{
$logger->pushGeneralHistoryLog('<M>필사즉생</>을 발동');
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <M>필사즉생</>을 발동");
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount*8)*10);
$nextTerm = $general->onCalcStrategic($this->getName(), 'delay', $nextTerm);
$db->update('nation', ['strategic_cmd_limit' => $nextTerm], 'nation=%i', $nationID);
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
+3 -1
View File
@@ -180,7 +180,9 @@ class che_허보 extends Command\NationCommand{
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>허보</>를 발동");
$logger->pushGlobalHistoryLog("<L><b>【전략】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>에 <M>허보</>를 발동하였습니다.");
$db->update('nation', ['strategic_cmd_limit' => $this->getPostReqTurn()], 'nation=%i', $nationID);
$db->update('nation', [
'strategic_cmd_limit' => $this->getPostReqTurn()
], 'nation=%i', $nationID);
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
@@ -0,0 +1,68 @@
<?php
namespace sammo\Constraint;
use \sammo\JosaUtil;
use \sammo\DB;
class AllowDiplomacyWithTerm extends Constraint{
const REQ_VALUES = Constraint::REQ_ARRAY_ARG|Constraint::REQ_NATION|Constraint::REQ_DEST_NATION;
protected $nationID;
protected $destNationID;
protected $allowDipCode;
protected $allowMinTerm;
protected $errMsg = '';
public function checkInputValues(bool $throwExeception=true):bool{
if(!parent::checkInputValues($throwExeception) && !$throwExeception){
return false;
}
if(count($this->arg) != 3){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require allowDipCode, term, errMsg tuple");
}
$this->nationID = $this->nation['nation'];
$this->destNationID = $this->destNation['nation'];
[$this->allowDipCode, $this->allowMinTerm, $this->errMsg] = $this->arg;
if(!is_int($this->allowDipCode)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("dipCode {$this->allowDipCode} must be int");
}
if(!is_int($this->allowMinTerm)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("term {$this->allowMinTerm} must be int");
}
if($this->allowMinTerm < 0){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("term {$this->allowMinTerm} must be not negative");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
$db = DB::db();
$valid = false;
$state = $db->queryFirstField(
'SELECT state FROM diplomacy WHERE me = %i AND you = %i AND `state` = %i AND `term` >= %i',
$this->nationID,
$this->destNationID,
$this->allowDipCode,
$this->allowMinTerm
);
if($state !== null){
return true;
}
$this->reason = $this->errMsg;
return false;
}
}
@@ -15,6 +15,10 @@ class ConstraintHelper{
static function AllowDiplomacyBetweenStatus(array $allowDipCodeList, string $errMsg):array{
return [__FUNCTION__, [$allowDipCodeList, $errMsg]];
}
static function AllowDiplomacyWithTerm(int $allowDipCode, int $allowMinTerm, string $errMsg):array{
return [__FUNCTION__, [$allowDipCode, $allowMinTerm, $errMsg]];
}
static function AllowJoinAction():array{
return [__FUNCTION__];
+2 -2
View File
@@ -324,8 +324,8 @@ class GameConstBase
'che_허보',
'che_피장파장',
'che_의병모집',
//'che_이호경식',
//'che_급습',
'che_이호경식',
'che_급습',
],
'기타'=>[
//'che_국기변경',