증축, 천도, 감축
This commit is contained in:
@@ -326,7 +326,7 @@ abstract class BaseCommand{
|
|||||||
|
|
||||||
$lastTurn = $this->getLastTurn();
|
$lastTurn = $this->getLastTurn();
|
||||||
$commandName = $this->getName();
|
$commandName = $this->getName();
|
||||||
if($lastTurn->getCommand() != $commandName){
|
if($lastTurn->getCommand() != $commandName && $lastTurn->getArg() !== $this->arg){
|
||||||
$this->setResultTurn(new LastTurn(
|
$this->setResultTurn(new LastTurn(
|
||||||
$commandName,
|
$commandName,
|
||||||
$this->arg,
|
$this->arg,
|
||||||
|
|||||||
@@ -0,0 +1,215 @@
|
|||||||
|
<?php
|
||||||
|
namespace sammo\Command\Nation;
|
||||||
|
|
||||||
|
use \sammo\{
|
||||||
|
DB, Util, JosaUtil,
|
||||||
|
General, DummyGeneral,
|
||||||
|
ActionLogger,
|
||||||
|
GameConst,
|
||||||
|
LastTurn,
|
||||||
|
GameUnitConst,
|
||||||
|
Command,
|
||||||
|
MessageTarget,
|
||||||
|
Message,
|
||||||
|
CityConst,
|
||||||
|
CityHelper
|
||||||
|
};
|
||||||
|
|
||||||
|
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 = false;
|
||||||
|
|
||||||
|
protected function argTest():bool{
|
||||||
|
$this->arg = [];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function init(){
|
||||||
|
$general = $this->generalObj;
|
||||||
|
|
||||||
|
$env = $this->env;
|
||||||
|
|
||||||
|
if($general->getNationID()===0){
|
||||||
|
$this->reservableConstraints=[
|
||||||
|
ConstraintHelper::NotBeNeutral(),
|
||||||
|
];
|
||||||
|
$this->runnableConstraints=[
|
||||||
|
ConstraintHelper::NotBeNeutral(),
|
||||||
|
];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setCity();
|
||||||
|
$this->setNation(['gold', 'rice', 'capset', 'capital']);
|
||||||
|
$this->setDestCity($this->nation['capital'], null);
|
||||||
|
|
||||||
|
[$reqGold, $reqRice] = $this->getCost();
|
||||||
|
|
||||||
|
$origCityLevel = CityConst::byID($this->nation['capital'])->level;
|
||||||
|
|
||||||
|
$this->runnableConstraints=[
|
||||||
|
ConstraintHelper::OccupiedCity(),
|
||||||
|
ConstraintHelper::BeChief(),
|
||||||
|
ConstraintHelper::SuppliedCity(),
|
||||||
|
ConstraintHelper::ReqDestCityValue('level', '>', 4, '더이상 감축할 수 없습니다.'),
|
||||||
|
ConstraintHelper::ReqDestCityValue('level', '>', $origCityLevel, '더이상 감축할 수 없습니다.')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCommandDetailTitle():string{
|
||||||
|
$name = $this->getName();
|
||||||
|
|
||||||
|
[$reqGold, $reqRice] = array_map('number_format', $this->getCost());
|
||||||
|
$amount = number_format($this->env['develcost'] * 5);
|
||||||
|
$reqTurn = $this->getPostReqTurn()+1;
|
||||||
|
|
||||||
|
return "{$name}/{$reqTurn}턴(금 {$reqGold}, 쌀 {$reqRice} 회수)";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCost():array{
|
||||||
|
$amount = $this->env['develcost'] * GameConst::$expandCityCostCoef + GameConst::$expandCityDefaultCost / 2;
|
||||||
|
|
||||||
|
return [$amount, $amount];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPreReqTurn():int{
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPostReqTurn():int{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addTermStack():bool{
|
||||||
|
$lastTurn = $this->getLastTurn();
|
||||||
|
$commandName = $this->getName();
|
||||||
|
if($lastTurn->getCommand() != $commandName && $lastTurn->getArg() !== $this->arg){
|
||||||
|
$this->setResultTurn(new LastTurn(
|
||||||
|
$commandName,
|
||||||
|
$this->arg,
|
||||||
|
1,
|
||||||
|
$this->nation['capset']
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($lastTurn->getSeq() < $this->nation['capset']){
|
||||||
|
//NOTE: 최근에 천도, 감축이 일어났으면 리셋됨
|
||||||
|
$this->setResultTurn(new LastTurn(
|
||||||
|
$commandName,
|
||||||
|
$this->arg,
|
||||||
|
1,
|
||||||
|
$this->nation['capset']
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($lastTurn->getTerm() < $this->getPreReqTurn()){
|
||||||
|
$this->setResultTurn(new LastTurn(
|
||||||
|
$commandName,
|
||||||
|
$this->arg,
|
||||||
|
$lastTurn->getTerm() + 1,
|
||||||
|
$this->nation['capset']
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBrief():string{
|
||||||
|
$commandName = $this->getName();
|
||||||
|
return "수도를 {$commandName}";
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
$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();
|
||||||
|
|
||||||
|
|
||||||
|
$general->increaseVar(
|
||||||
|
'experience',
|
||||||
|
$general->onCalcStat($general,
|
||||||
|
'experience', 5 * ($this->getPreReqTurn() + 1)
|
||||||
|
));
|
||||||
|
$general->increaseVar(
|
||||||
|
'dedication',
|
||||||
|
$general->onCalcStat($general,
|
||||||
|
'dedication', 5 * ($this->getPreReqTurn() + 1)
|
||||||
|
));
|
||||||
|
|
||||||
|
$josaUl = JosaUtil::pick($destCityName, '을');
|
||||||
|
$josaYi = JosaUtil::pick($generalName, '이');
|
||||||
|
$josaYiNation = JosaUtil::pick($nationName, '이');
|
||||||
|
|
||||||
|
$db->update('city', [
|
||||||
|
'level'=>$db->sqleval('level-1'),
|
||||||
|
'pop'=>$db->sqleval('greatest(pop - %i, %i)', GameConst::$expandCityPopIncreaseAmount, GameConst::$minAvailableRecruitPop),
|
||||||
|
'agri'=>$db->sqleval('greatest(agri - %i, 0)', GameConst::$expandCityDevelIncreaseAmount),
|
||||||
|
'comm'=>$db->sqleval('greatest(comm - %i, 0)', GameConst::$expandCityDevelIncreaseAmount),
|
||||||
|
'secu'=>$db->sqleval('greatest(secu - %i, 0)', GameConst::$expandCityDevelIncreaseAmount),
|
||||||
|
'def'=>$db->sqleval('greatest(def - %i, 0)', GameConst::$expandCityWallIncreaseAmount),
|
||||||
|
'wall'=>$db->sqleval('greatest(wall - %i, 0)', GameConst::$expandCityWallIncreaseAmount),
|
||||||
|
|
||||||
|
'pop_max'=>$db->sqleval('pop_max - %i', GameConst::$expandCityPopIncreaseAmount),
|
||||||
|
'agri_max'=>$db->sqleval('agri_max - %i', GameConst::$expandCityDevelIncreaseAmount),
|
||||||
|
'comm_max'=>$db->sqleval('comm_max - %i', GameConst::$expandCityDevelIncreaseAmount),
|
||||||
|
'secu_max'=>$db->sqleval('secu_max - %i', GameConst::$expandCityDevelIncreaseAmount),
|
||||||
|
'def_max'=>$db->sqleval('def_max - %i', GameConst::$expandCityWallIncreaseAmount),
|
||||||
|
'wall_max'=>$db->sqleval('wall_max - %i', GameConst::$expandCityWallIncreaseAmount),
|
||||||
|
], 'city=%i', $destCityID);
|
||||||
|
|
||||||
|
[$reqGold, $reqRice] = $this->getCost();
|
||||||
|
$db->update('nation', [
|
||||||
|
'capset' => $db->sqleval('capset + 1'),
|
||||||
|
'gold' => $db->sqleval('gold + %i', $reqGold),
|
||||||
|
'rice' => $db->sqleval('rice + %i', $reqRice),
|
||||||
|
], 'nation=%i', $nationID);
|
||||||
|
|
||||||
|
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>{$josaUl} 감축했습니다. <1>$date</");
|
||||||
|
$logger->pushGeneralHistoryLog("<G><b>{$destCityName}</b></>{$josaUl} <M>감축</>");
|
||||||
|
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>{$josaUl} <M>감축</>");
|
||||||
|
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>{$josaUl} <M>감축</>하였습니다.");
|
||||||
|
$logger->pushGlobalHistoryLog("<M><b>【감축】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>{$josaUl} <M>감축</>하였습니다.");
|
||||||
|
|
||||||
|
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
|
||||||
|
$general->applyDB($db);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,18 +40,12 @@ class che_의병모집 extends Command\NationCommand{
|
|||||||
$env = $this->env;
|
$env = $this->env;
|
||||||
$relYear = $env['year'] - $env['startyear'];
|
$relYear = $env['year'] - $env['startyear'];
|
||||||
|
|
||||||
if($relYear < 3){
|
|
||||||
$this->runnableConstraints = [
|
|
||||||
ConstraintHelper::AlwaysFail('현재 초반 제한중입니다.')
|
|
||||||
];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->runnableConstraints=[
|
$this->runnableConstraints=[
|
||||||
ConstraintHelper::BeChief(),
|
ConstraintHelper::BeChief(),
|
||||||
ConstraintHelper::NotBeNeutral(),
|
ConstraintHelper::NotBeNeutral(),
|
||||||
ConstraintHelper::OccupiedCity(),
|
ConstraintHelper::OccupiedCity(),
|
||||||
ConstraintHelper::AvailableStrategicCommand()
|
ConstraintHelper::AvailableStrategicCommand(),
|
||||||
|
ConstraintHelper::NotOpeningPart($relYear),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,207 @@
|
|||||||
|
<?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 = false;
|
||||||
|
|
||||||
|
protected function argTest():bool{
|
||||||
|
$this->arg = [];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function init(){
|
||||||
|
$general = $this->generalObj;
|
||||||
|
|
||||||
|
$env = $this->env;
|
||||||
|
|
||||||
|
if($general->getNationID()===0){
|
||||||
|
$this->reservableConstraints=[
|
||||||
|
ConstraintHelper::NotBeNeutral(),
|
||||||
|
];
|
||||||
|
$this->runnableConstraints=[
|
||||||
|
ConstraintHelper::NotBeNeutral(),
|
||||||
|
];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setCity();
|
||||||
|
$this->setNation(['gold', 'rice', 'capset', 'capital']);
|
||||||
|
$this->setDestCity($this->nation['capital'], null);
|
||||||
|
|
||||||
|
[$reqGold, $reqRice] = $this->getCost();
|
||||||
|
|
||||||
|
$this->runnableConstraints=[
|
||||||
|
ConstraintHelper::OccupiedCity(),
|
||||||
|
ConstraintHelper::BeChief(),
|
||||||
|
ConstraintHelper::SuppliedCity(),
|
||||||
|
ConstraintHelper::ReqDestCityValue('level', '>', 3, '수진, 진, 관문에서는 불가능합니다.'),
|
||||||
|
ConstraintHelper::ReqDestCityValue('level', '<', 7, '더이상 증축할 수 없습니다.'),
|
||||||
|
ConstraintHelper::ReqNationGold(GameConst::$basegold+$reqGold),
|
||||||
|
ConstraintHelper::ReqNationRice(GameConst::$baserice+$reqRice),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCommandDetailTitle():string{
|
||||||
|
$name = $this->getName();
|
||||||
|
|
||||||
|
[$reqGold, $reqRice] = array_map('number_format', $this->getCost());
|
||||||
|
$amount = number_format($this->env['develcost'] * 5);
|
||||||
|
$reqTurn = $this->getPostReqTurn()+1;
|
||||||
|
|
||||||
|
return "{$name}/{$reqTurn}턴(금 {$reqGold}, 쌀 {$reqRice})";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCost():array{
|
||||||
|
$amount = $this->env['develcost'] * GameConst::$expandCityCostCoef + GameConst::$expandCityDefaultCost;
|
||||||
|
|
||||||
|
return [$amount, $amount];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPreReqTurn():int{
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPostReqTurn():int{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addTermStack():bool{
|
||||||
|
$lastTurn = $this->getLastTurn();
|
||||||
|
$commandName = $this->getName();
|
||||||
|
if($lastTurn->getCommand() != $commandName && $lastTurn->getArg() !== $this->arg){
|
||||||
|
$this->setResultTurn(new LastTurn(
|
||||||
|
$commandName,
|
||||||
|
$this->arg,
|
||||||
|
1,
|
||||||
|
$this->nation['capset']
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($lastTurn->getSeq() < $this->nation['capset']){
|
||||||
|
//NOTE: 최근에 천도, 증축이 일어났으면 리셋됨
|
||||||
|
$this->setResultTurn(new LastTurn(
|
||||||
|
$commandName,
|
||||||
|
$this->arg,
|
||||||
|
1,
|
||||||
|
$this->nation['capset']
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($lastTurn->getTerm() < $this->getPreReqTurn()){
|
||||||
|
$this->setResultTurn(new LastTurn(
|
||||||
|
$commandName,
|
||||||
|
$this->arg,
|
||||||
|
$lastTurn->getTerm() + 1,
|
||||||
|
$this->nation['capset']
|
||||||
|
));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBrief():string{
|
||||||
|
$commandName = $this->getName();
|
||||||
|
return "수도를 {$commandName}";
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
$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();
|
||||||
|
|
||||||
|
|
||||||
|
$general->increaseVar(
|
||||||
|
'experience',
|
||||||
|
$general->onCalcStat($general,
|
||||||
|
'experience', 5 * ($this->getPreReqTurn() + 1)
|
||||||
|
));
|
||||||
|
$general->increaseVar(
|
||||||
|
'dedication',
|
||||||
|
$general->onCalcStat($general,
|
||||||
|
'dedication', 5 * ($this->getPreReqTurn() + 1)
|
||||||
|
));
|
||||||
|
|
||||||
|
$josaUl = JosaUtil::pick($destCityName, '을');
|
||||||
|
$josaYi = JosaUtil::pick($generalName, '이');
|
||||||
|
$josaYiNation = JosaUtil::pick($nationName, '이');
|
||||||
|
|
||||||
|
$db->update('city', [
|
||||||
|
'level'=>$db->sqleval('level+1'),
|
||||||
|
'pop2'=>$db->sqleval('pop_max + %i', GameConst::$expandCityPopIncreaseAmount),
|
||||||
|
'agri2'=>$db->sqleval('agri_max + %i', GameConst::$expandCityDevelIncreaseAmount),
|
||||||
|
'comm2'=>$db->sqleval('comm_max + %i', GameConst::$expandCityDevelIncreaseAmount),
|
||||||
|
'secu2'=>$db->sqleval('secu_max + %i', GameConst::$expandCityDevelIncreaseAmount),
|
||||||
|
'def2'=>$db->sqleval('def_max + %i', GameConst::$expandCityWallIncreaseAmount),
|
||||||
|
'wall2'=>$db->sqleval('wall_max + %i', GameConst::$expandCityWallIncreaseAmount),
|
||||||
|
], 'city=%i', $destCityID);
|
||||||
|
|
||||||
|
[$reqGold, $reqRice] = $this->getCost();
|
||||||
|
$db->update('nation', [
|
||||||
|
'capset' => $db->sqleval('capset + 1'),
|
||||||
|
'gold' => $db->sqleval('gold - %i', $reqGold),
|
||||||
|
'rice' => $db->sqleval('rice - %i', $reqRice),
|
||||||
|
], 'nation=%i', $nationID);
|
||||||
|
|
||||||
|
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>{$josaUl} 증축했습니다. <1>$date</");
|
||||||
|
$logger->pushGeneralHistoryLog("<G><b>{$destCityName}</b></>{$josaUl} <M>증축</>");
|
||||||
|
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>{$josaUl} <M>증축</>");
|
||||||
|
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>{$josaUl} <M>증축</>하였습니다.");
|
||||||
|
$logger->pushGlobalHistoryLog("<C><b>【증축】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>{$josaUl} <M>증축</>하였습니다.");
|
||||||
|
|
||||||
|
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
|
||||||
|
$general->applyDB($db);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -120,7 +120,13 @@ class che_천도 extends Command\NationCommand{
|
|||||||
public function addTermStack():bool{
|
public function addTermStack():bool{
|
||||||
$lastTurn = $this->getLastTurn();
|
$lastTurn = $this->getLastTurn();
|
||||||
$commandName = $this->getName();
|
$commandName = $this->getName();
|
||||||
if($lastTurn->getCommand() != $commandName){
|
|
||||||
|
$nationStor = \sammo\KVStorage::getStorage(DB::db(), 'nation_env');
|
||||||
|
$general = $this->getGeneral();
|
||||||
|
$nationID = $general->getNationID();
|
||||||
|
$nationStor->setValue("last천도Trial_{$nationID}", [$general->getVar('level'), $general->getTurnTime()]);
|
||||||
|
|
||||||
|
if($lastTurn->getCommand() != $commandName && $lastTurn->getArg() !== $this->arg){
|
||||||
$this->setResultTurn(new LastTurn(
|
$this->setResultTurn(new LastTurn(
|
||||||
$commandName,
|
$commandName,
|
||||||
$this->arg,
|
$this->arg,
|
||||||
@@ -215,7 +221,6 @@ class che_천도 extends Command\NationCommand{
|
|||||||
|
|
||||||
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
|
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
|
||||||
$general->applyDB($db);
|
$general->applyDB($db);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,6 +188,14 @@ class ConstraintHelper{
|
|||||||
return [__FUNCTION__, $minTrust];
|
return [__FUNCTION__, $minTrust];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function ReqCityValue($key, string $keyNick, string $comp, $reqVal, ?string $errMsg=null):array{
|
||||||
|
return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal, $errMsg]];
|
||||||
|
}
|
||||||
|
|
||||||
|
static function ReqDestCityValue($key, string $keyNick, string $comp, $reqVal, ?string $errMsg=null):array{
|
||||||
|
return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal, $errMsg]];
|
||||||
|
}
|
||||||
|
|
||||||
static function ReqCityTrader(int $npcType):array{
|
static function ReqCityTrader(int $npcType):array{
|
||||||
return [__FUNCTION__, $npcType];
|
return [__FUNCTION__, $npcType];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,139 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\Constraint;
|
||||||
|
|
||||||
|
use \sammo\JosaUtil;
|
||||||
|
use \sammo\Util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 범용으로 사용 가능한 도시 변수 검사도구
|
||||||
|
*/
|
||||||
|
class ReqCityValue extends Constraint{
|
||||||
|
const REQ_VALUES = Constraint::REQ_CITY|Constraint::REQ_ARRAY_ARG;
|
||||||
|
|
||||||
|
protected $key;
|
||||||
|
protected $maxKey;
|
||||||
|
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) == 5){
|
||||||
|
[$this->key, $this->keyNick, $comp, $this->reqVal, $this->errMsg] = $this->arg;
|
||||||
|
|
||||||
|
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("invalid comparator");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("require key, keyNick, comp, reqVal[, errMsg]");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->comp = $comp;
|
||||||
|
|
||||||
|
$this->maxKey = $this->key.'_max';
|
||||||
|
|
||||||
|
if(!key_exists($this->key, $this->city)){
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("require {$this->key} in city");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_numeric($this->reqVal)){
|
||||||
|
$this->isPercent = false;
|
||||||
|
}
|
||||||
|
else if(is_string($this->reqVal)){
|
||||||
|
$this->reqVal = Util::convPercentStrToFloat($this->reqVal);
|
||||||
|
if($this->reqVal === null){
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("require valid reqVal(percentStr|numeric) format");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!key_exists($this->maxKey, $this->city)){
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("require {$this->maxKey} in city");
|
||||||
|
}
|
||||||
|
$this->isPercent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->errMsg!==null && !is_string($this->errMsg)){
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("{$this->errMsg} must be string or null");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test():bool{
|
||||||
|
$this->checkInputValues();
|
||||||
|
$this->tested = true;
|
||||||
|
$keyNick = $this->keyNick;
|
||||||
|
|
||||||
|
if ($this->isPercent) {
|
||||||
|
$reqVal = $this->city[$this->maxKey] * $this->reqVal;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$reqVal = $this->reqVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
$compList = [
|
||||||
|
'<'=>function($target, $src){
|
||||||
|
return ($target < $src)?true:'너무 많습니다.';
|
||||||
|
},
|
||||||
|
'<='=>function($target, $src){
|
||||||
|
return ($target <= $src)?true:'너무 많습니다.';
|
||||||
|
},
|
||||||
|
'=='=>function($target, $src)use($keyNick){
|
||||||
|
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||||
|
},
|
||||||
|
'!='=>function($target, $src)use($keyNick){
|
||||||
|
return ($target != $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||||
|
},
|
||||||
|
'==='=>function($target, $src)use($keyNick){
|
||||||
|
return ($target === $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||||
|
},
|
||||||
|
'!=='=>function($target, $src)use($keyNick){
|
||||||
|
return ($target !== $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||||
|
},
|
||||||
|
'>='=>function($target, $src){
|
||||||
|
if($target >= $src){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if($src == 1){
|
||||||
|
return '없습니다';
|
||||||
|
}
|
||||||
|
return '부족합니다.';
|
||||||
|
},
|
||||||
|
'>'=>function($target, $src){
|
||||||
|
return $target > $src;
|
||||||
|
if($src == 0){
|
||||||
|
return '없습니다';
|
||||||
|
}
|
||||||
|
return '부족합니다.';
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
$comp = $compList[$this->comp];
|
||||||
|
$result = ($comp)($this->city[$this->key], $reqVal);
|
||||||
|
|
||||||
|
if($result === true){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->errMsg){
|
||||||
|
$this->reason = $this->errMsg;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$josaYi = JosaUtil::pick($keyNick, '이');
|
||||||
|
$this->reason = "{$keyNick}{$josaYi} {$result}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\Constraint;
|
||||||
|
|
||||||
|
use \sammo\JosaUtil;
|
||||||
|
use \sammo\Util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 범용으로 사용 가능한 도시 변수 검사도구
|
||||||
|
*/
|
||||||
|
class ReqDestCityValue extends Constraint{
|
||||||
|
const REQ_VALUES = Constraint::REQ_DEST_CITY|Constraint::REQ_ARRAY_ARG;
|
||||||
|
|
||||||
|
protected $key;
|
||||||
|
protected $maxKey;
|
||||||
|
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) == 5){
|
||||||
|
[$this->key, $this->keyNick, $comp, $this->reqVal, $this->errMsg] = $this->arg;
|
||||||
|
|
||||||
|
if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("invalid comparator");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("require key, keyNick, comp, reqVal[, errMsg]");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->comp = $comp;
|
||||||
|
|
||||||
|
$this->maxKey = $this->key.'_max';
|
||||||
|
|
||||||
|
if(!key_exists($this->key, $this->destCity)){
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("require {$this->key} in destCity");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_numeric($this->reqVal)){
|
||||||
|
$this->isPercent = false;
|
||||||
|
}
|
||||||
|
else if(is_string($this->reqVal)){
|
||||||
|
$this->reqVal = Util::convPercentStrToFloat($this->reqVal);
|
||||||
|
if($this->reqVal === null){
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("require valid reqVal(percentStr|numeric) format");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!key_exists($this->maxKey, $this->destCity)){
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("require {$this->maxKey} in destCity");
|
||||||
|
}
|
||||||
|
$this->isPercent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->errMsg!==null && !is_string($this->errMsg)){
|
||||||
|
if(!$throwExeception){return false; }
|
||||||
|
throw new \InvalidArgumentException("{$this->errMsg} must be string or null");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test():bool{
|
||||||
|
$this->checkInputValues();
|
||||||
|
$this->tested = true;
|
||||||
|
$keyNick = $this->keyNick;
|
||||||
|
|
||||||
|
if ($this->isPercent) {
|
||||||
|
$reqVal = $this->destCity[$this->maxKey] * $this->reqVal;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$reqVal = $this->reqVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
$compList = [
|
||||||
|
'<'=>function($target, $src){
|
||||||
|
return ($target < $src)?true:'너무 많습니다.';
|
||||||
|
},
|
||||||
|
'<='=>function($target, $src){
|
||||||
|
return ($target <= $src)?true:'너무 많습니다.';
|
||||||
|
},
|
||||||
|
'=='=>function($target, $src)use($keyNick){
|
||||||
|
return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||||
|
},
|
||||||
|
'!='=>function($target, $src)use($keyNick){
|
||||||
|
return ($target != $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||||
|
},
|
||||||
|
'==='=>function($target, $src)use($keyNick){
|
||||||
|
return ($target === $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||||
|
},
|
||||||
|
'!=='=>function($target, $src)use($keyNick){
|
||||||
|
return ($target !== $src)?true:"올바르지 않은 {$keyNick} 입니다.";
|
||||||
|
},
|
||||||
|
'>='=>function($target, $src){
|
||||||
|
if($target >= $src){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if($src == 1){
|
||||||
|
return '없습니다';
|
||||||
|
}
|
||||||
|
return '부족합니다.';
|
||||||
|
},
|
||||||
|
'>'=>function($target, $src){
|
||||||
|
return $target > $src;
|
||||||
|
if($src == 0){
|
||||||
|
return '없습니다';
|
||||||
|
}
|
||||||
|
return '부족합니다.';
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
$comp = $compList[$this->comp];
|
||||||
|
$result = ($comp)($this->destCity[$this->key], $reqVal);
|
||||||
|
|
||||||
|
if($result === true){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->errMsg){
|
||||||
|
$this->reason = $this->errMsg;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$josaYi = JosaUtil::pick($keyNick, '이');
|
||||||
|
$this->reason = "{$keyNick}{$josaYi} {$result}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1476,12 +1476,12 @@ class GeneralAI
|
|||||||
if($lastTurn->getCommand() === 'che_천도'){
|
if($lastTurn->getCommand() === 'che_천도'){
|
||||||
$cmd = buildNationCommandClass('che_천도', $general, $this->env, $lastTurn, $lastTurn->getArg());
|
$cmd = buildNationCommandClass('che_천도', $general, $this->env, $lastTurn, $lastTurn->getArg());
|
||||||
if($cmd->isRunnable()){
|
if($cmd->isRunnable()){
|
||||||
$nationStor->last천도Trial = [$general->getVar('level'), $general->getTurnTime()];
|
$nationStor->setValue("last천도Trial_{$this->nation['nation']}", [$general->getVar('level'), $general->getTurnTime()]);
|
||||||
return $cmd;
|
return $cmd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$lastTrial = $nationStor->last천도Trial;
|
$lastTrial = $nationStor->getValue("last천도Trial_{$this->nation['nation']}");
|
||||||
if($lastTrial){
|
if($lastTrial){
|
||||||
[$lastTrialLevel, $lastTrialTurnTime] = $lastTrial;
|
[$lastTrialLevel, $lastTrialTurnTime] = $lastTrial;
|
||||||
$timeDiffSeconds = TimeUtil::DateIntervalToSeconds(
|
$timeDiffSeconds = TimeUtil::DateIntervalToSeconds(
|
||||||
@@ -1597,7 +1597,7 @@ class GeneralAI
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$nationStor->last천도Trial = [$general->getVar('level'), $general->getTurnTime()];
|
$nationStor->setValue("last천도Trial_{$this->nation['nation']}", [$general->getVar('level'), $general->getTurnTime()]);
|
||||||
|
|
||||||
return $cmd;
|
return $cmd;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,7 +205,6 @@ CREATE TABLE `city` (
|
|||||||
`city` INT(6) NOT NULL AUTO_INCREMENT,
|
`city` INT(6) NOT NULL AUTO_INCREMENT,
|
||||||
`name` CHAR(64) NOT NULL,
|
`name` CHAR(64) NOT NULL,
|
||||||
`level` INT(1) NOT NULL,
|
`level` INT(1) NOT NULL,
|
||||||
`upgrading` INT(1) NOT NULL DEFAULT '0',
|
|
||||||
`nation` INT(6) NOT NULL DEFAULT '0',
|
`nation` INT(6) NOT NULL DEFAULT '0',
|
||||||
`supply` INT(1) NOT NULL DEFAULT '1',
|
`supply` INT(1) NOT NULL DEFAULT '1',
|
||||||
`front` INT(1) NOT NULL DEFAULT '0',
|
`front` INT(1) NOT NULL DEFAULT '0',
|
||||||
|
|||||||
Reference in New Issue
Block a user