필사즉생 구현

This commit is contained in:
2020-03-12 21:57:57 +09:00
parent 71c4a84833
commit 842942c0fe
15 changed files with 297 additions and 28 deletions
+50 -2
View File
@@ -4,7 +4,8 @@ namespace sammo\Command;
use \sammo\{
Util, JosaUtil, DB,
General, GameConst,
ActionLogger
ActionLogger,
LastTurn
};
use function \sammo\getNationStaticInfo;
@@ -124,7 +125,7 @@ abstract class BaseCommand{
return;
}
$defaultArgs = ['nation', 'name', 'color', 'type', 'level', 'capital'];
$defaultArgs = ['nation', 'name', 'color', 'type', 'level', 'capital', 'gennum'];
$args = array_unique(array_merge($defaultArgs, $args));
if($args == $defaultArgs){
$this->nation = $this->generalObj->getStaticNation();
@@ -293,6 +294,41 @@ abstract class BaseCommand{
}
public function getTermString():string{
$commandName = $this->getName();
$term = $this->getResultTurn()->getTerm();
$termMax = $this->getPreReqTurn() + 1;
return "{$commandName} 수행중... ({$term}/{$termMax})";
}
public function addTermStack():bool{
if($this->getPreReqTurn() == 0){
return true;
}
$lastTurn = $this->getLastTurn();
$commandName = $this->getName();
if($lastTurn->getCommand() != $commandName){
$this->setResultTurn(new LastTurn(
$commandName,
$this->arg,
1
));
return false;
}
if($lastTurn->getTerm() < $this->getPreReqTurn()){
$this->setResultTurn(new LastTurn(
$commandName,
$this->arg,
$lastTurn->getTerm() + 1
));
return false;
}
return true;
}
public function isReservable():bool{
if($this->reservable !== null){
return $this->reservable;
@@ -344,4 +380,16 @@ abstract class BaseCommand{
throw new \sammo\MustNotBeReachedException();
return '';
}
public function getLastTurn():LastTurn{
return $this->generalObj->getLastTurn();
}
public function setResultTurn(LastTurn $lastTurn){
$this->generalObj->setResultTurn($lastTurn);
}
public function getResultTurn():LastTurn{
return $this->generalObj->getResultTurn();
}
}
+3 -9
View File
@@ -44,15 +44,9 @@ class che_방랑 extends Command\GeneralCommand{
ConstraintHelper::BeLord(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::DisallowDiplomacyStatus($this->generalObj->getNationID(), [
0 => '방랑할 수 없는 외교상태입니다.',
1 => '방랑할 수 없는 외교상태입니다.',
3 => '방랑할 수 없는 외교상태입니다.',
4 => '방랑할 수 없는 외교상태입니다.',
5 => '방랑할 수 없는 외교상태입니다.',
6 => '방랑할 수 없는 외교상태입니다.'
]),
//TODO:diplomacy status 상수화
ConstraintHelper::AllowDiplomacyStatus($this->generalObj->getNationID(), [
2, 7
], '방랑할 수 없는 외교상태입니다.'),
];
}
+1 -1
View File
@@ -181,7 +181,7 @@ class che_몰수 extends Command\NationCommand{
$destGeneral->getLogger()->pushGeneralActionLog("{$resName} {$amountText}을 몰수 당했습니다.", ActionLogger::PLAIN);
$logger->pushGeneralActionLog("{$destGeneral->getName()}에게서 {$resName} <C>$amountText</>을 몰수했습니다. <1>$date</>");
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
$destGeneral->applyDB($db);
+1 -1
View File
@@ -133,7 +133,7 @@ class che_발령 extends Command\NationCommand{
$destGeneral->getLogger()->pushGeneralActionLog("<Y>{$generalName}</>에 의해 <G><b>{$destCityName}</b></>{$josaRo} 발령됐습니다. <1>$date</>");
$logger->pushGeneralActionLog("<Y>{$destGeneralName}</>{$josaUl} <G><b>{$destCityName}</b></>{$josaRo} 발령했습니다. <1>$date</>");
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
$destGeneral->applyDB($db);
@@ -27,7 +27,7 @@ use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_불가침제의 extends Command\NationCommand{
static protected $actionName = '불가침제의';
static protected $actionName = '불가침 제의';
static public $reqArg = true;
protected function argTest():bool{
@@ -206,7 +206,7 @@ class che_불가침제의 extends Command\NationCommand{
);
$msg->send();
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
$destLogger->flush();
@@ -176,7 +176,7 @@ class che_선전포고 extends Command\NationCommand{
);
$msg->send();
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
$destLogger->flush();
+1 -1
View File
@@ -149,7 +149,7 @@ class che_포상 extends Command\NationCommand{
$destGeneral->getLogger()->pushGeneralActionLog("{$resName} <C>{$amountText}</>을 포상으로 받았습니다.", ActionLogger::PLAIN);
$logger->pushGeneralActionLog("{$destGeneral->getName()}에게 {$resName} <C>$amountText</>을 수여했습니다. <1>$date</>");
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
$destGeneral->applyDB($db);
@@ -0,0 +1,129 @@
<?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 = '필사즉생';
static public $reqArg = false;
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->runnableConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
/*ConstraintHelper::AllowDiplomacyStatus($this->generalObj->getNationID(), [
0
], '전쟁중이 아닙니다.'),*/
ConstraintHelper::ReqNationValue('strategic_cmd_limit', '전략기한', '==', 0, '전략기한이 남았습니다.')
];
}
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 2;
}
public function getPostReqTurn():int{
return 0;
}
public function run():bool{
if(!$this->isRunnable()){
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</>");
$exp = 5 * ($this->getPreReqTurn() + 1);
$ded = 5 * ($this->getPreReqTurn() + 1);
$exp = $general->onCalcStat($general, 'experience', $exp);
$ded = $general->onCalcStat($general, 'dedication', $ded);
$josaYi = JosaUtil::pick($generalName, '이');
$broadcastMessage = "<Y>{$generalName}</>{$josaYi} <M>필사즉생</>을 발동하였습니다.";
foreach($db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID) as $targetGeneralID){
$targetGeneral = General::createGeneralObjFromDB($targetGeneralID, ['train', 'atmos'], 1);
$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>필사즉생</>을 발동");
$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);
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
}
@@ -0,0 +1,66 @@
<?php
namespace sammo\Constraint;
use \sammo\JosaUtil;
use \sammo\DB;
class AllowDiplomacyStatus extends Constraint{
const REQ_VALUES = Constraint::REQ_ARRAY_ARG;
protected $nationID;
protected $allowStatus = [];
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 nationID, allowStatus, errMsg tuple");
}
[$this->nationID, $this->allowStatus, $this->errMsg] = $this->arg;
if(!is_int($this->nationID)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("nationID {$this->nationID} must be int");
}
if(!is_array($this->allowStatus)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("allowStatus {$this->allowStatus} must be array");
}
if(!is_string($this->errMsg)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("allowStatus {$this->errMsg} must be string");
}
foreach($this->allowStatus as $dipCode){
if(!is_int($dipCode)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("dipCode $dipCode must be int");
}
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
$db = DB::db();
$state = $db->queryFirstField(
'SELECT state FROM diplomacy WHERE me = %i AND `state` IN %li LIMIT 1',
$this->nationID,
array_keys($this->allowStatus)
);
if($state !== null){
return true;
}
$this->reason = $this->errMsg;
return false;
}
}
+6 -2
View File
@@ -7,6 +7,10 @@ class ConstraintHelper{
static function AdhocCallback(callable $callback):array{
return [__FUNCTION__, $callback];
}
static function AllowDiplomacyStatus(int $nationID, array $disallowList, string $errMsg):array{
return [__FUNCTION__, [$nationID, $disallowList, $errMsg]];
}
static function AllowJoinAction():array{
return [__FUNCTION__];
@@ -212,8 +216,8 @@ class ConstraintHelper{
return [__FUNCTION__, $reqRice];
}
static function ReqNationValue($key, string $keyNick, string $comp, $reqVal):array{
return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal]];
static function ReqNationValue($key, string $keyNick, string $comp, $reqVal, ?string $errMsg=null):array{
return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal, $errMsg]];
}
static function ReqTroopMembers():array{
@@ -59,7 +59,7 @@ class DisallowDiplomacyStatus extends Constraint{
if($state === null){
return true;
}
$this->msg = $this->disallowStatus[$state];
$this->reason = $this->disallowStatus[$state];
return false;
}
}
+11 -5
View File
@@ -16,14 +16,15 @@ class ReqNationValue extends Constraint{
protected $keyNick;
protected $reqVal;
protected $comp;
protected $errMsg;
public function checkInputValues(bool $throwExeception=true):bool{
if(!parent::checkInputValues($throwExeception) && !$throwExeception){
return false;
}
if(count($this->arg) == 4){
[$this->key, $this->keyNick, $comp, $this->reqVal] = $this->arg;
if(count($this->arg) == 5){
[$this->key, $this->keyNick, $comp, $this->reqVal, $this->errMsg] = $this->arg;
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){
if(!$throwExeception){return false; }
@@ -32,7 +33,7 @@ class ReqNationValue extends Constraint{
}
else{
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require key, keyNick, comp, reqVal");
throw new \InvalidArgumentException("require key, keyNick, comp, reqVal[, errMsg]");
}
$this->comp = $comp;
@@ -47,7 +48,7 @@ class ReqNationValue extends Constraint{
if(is_numeric($this->reqVal)){
$this->isPercent = false;
}
else if(is_str($this->reqVal)){
else if(is_string($this->reqVal)){
$this->reqVal = Util::convPercentStrToFloat($this->reqVal);
if($this->reqVal === null){
if(!$throwExeception){return false; }
@@ -121,7 +122,12 @@ class ReqNationValue extends Constraint{
}
$josaYi = JosaUtil::pick($keyNick, '이');
$this->reason = "{$keyNick}{$josaYi} {$result}";
if($this->errMsg){
$this->reason = $this->errMsg;
}
else{
$this->reason = "{$keyNick}{$josaYi} {$result}";
}
return false;
}
+1 -1
View File
@@ -280,7 +280,7 @@ class GameConstBase
//'che_감축',
],
'전략'=>[
//'che_필사즉생',
'che_필사즉생',
//'che_백성동원',
//'che_수몰',
//'che_허보',
+4
View File
@@ -65,4 +65,8 @@ class LastTurn{
}
return Json::encode($result);
}
function duplicate():LastTurn{
return new static($this->command, $this->arg, $this->term);
}
}
+20 -2
View File
@@ -82,11 +82,21 @@ class TurnExecutionHelper
$general->getLogger()->pushGeneralActionLog($text);
break;
}
if(!$commandObj->addTermStack()){
$date = $general->getTurnTime($general::TURNTIME_HM);
$termString = $commandObj->getTermString();
$text = "{$termString} <1>{$date}</>";
$general->getLogger()->pushGeneralActionLog($text);
break;
}
$result = $commandObj->run();
if($result){
break;
}
$alt = $commandObj->getAlternativeCommand();
if($alt === null){
break;
@@ -117,6 +127,14 @@ class TurnExecutionHelper
break;
}
if(!$commandObj->addTermStack()){
$date = $general->getTurnTime($general::TURNTIME_HM);
$termString = $commandObj->getTermString();
$text = "{$termString} <1>{$date}</>";
$general->getLogger()->pushGeneralActionLog($text);
break;
}
$result = $commandObj->run();
if($result){
break;
@@ -147,7 +165,7 @@ class TurnExecutionHelper
$general->setVar('killturn', $killTurn);
}
return $general->getResultTurn();
return $commandObj->getResultTurn();
}
function updateTurnTime(){