이동 구현. BaseCommand에 GeneralSource 연결.
This commit is contained in:
@@ -37,7 +37,7 @@ abstract class BaseCommand{
|
||||
protected $runnableConstraints = null;
|
||||
protected $reservableConstraints = null;
|
||||
|
||||
|
||||
protected $generalSource = null;
|
||||
|
||||
protected $logger;
|
||||
|
||||
@@ -54,6 +54,17 @@ abstract class BaseCommand{
|
||||
|
||||
}
|
||||
|
||||
public function setGeneralSource(?array $generalSource){
|
||||
$this->generalSource = $generalSource;
|
||||
}
|
||||
|
||||
protected function getGeneralObjFromGeneralSource(int $generalNo):?General{
|
||||
if($this->generalSource === null){
|
||||
return null;
|
||||
}
|
||||
return $this->generalSource[$generalNo]??null;
|
||||
}
|
||||
|
||||
protected function resetTestCache():void{
|
||||
$this->runnable = null;
|
||||
$this->reservable = null;
|
||||
@@ -105,7 +116,12 @@ abstract class BaseCommand{
|
||||
protected function setDestCity(int $cityNo, ?array $args){
|
||||
$this->resetTestCache();
|
||||
$db = DB::db();
|
||||
if($args == null){
|
||||
if($args === []){
|
||||
$cityObj = \sammo\CityConst::byID($cityNo);
|
||||
$this->destCity = ['city'=>$cityNo, 'name'=>$cityObj->name];
|
||||
return;
|
||||
}
|
||||
if($args === null){
|
||||
$this->destCity = $db->queryFirstRow('SELECT * FROM city WHERE city=%i', $cityNo);
|
||||
return;
|
||||
}
|
||||
@@ -114,7 +130,7 @@ abstract class BaseCommand{
|
||||
|
||||
protected function setDestNation(int $nationNo, ?array $args = null){
|
||||
$this->resetTestCache();
|
||||
if($args == null){
|
||||
if($args === null || $args === []){
|
||||
$this->destNation = getNationStaticInfo($nationNo);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace sammo\GeneralCommand;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst, GameUnitConst,
|
||||
LastTurn,
|
||||
Command
|
||||
};
|
||||
|
||||
|
||||
use function \sammo\{
|
||||
uniqueItemEx
|
||||
};
|
||||
|
||||
use \sammo\Constraint\Constraint;
|
||||
use sammo\CityConst;
|
||||
|
||||
|
||||
|
||||
class che_이동 extends Command\GeneralCommand{
|
||||
static protected $actionName = '이동';
|
||||
|
||||
protected function init(){
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setNation();
|
||||
$this->setDestCity($this->arg['destCityID'], []);
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->runnableConstraints=[
|
||||
['NotSameCity'],
|
||||
['NearCity', 1],
|
||||
['ReqGeneralGold', $reqGold],
|
||||
['ReqGeneralRice', $reqRice],
|
||||
];
|
||||
}
|
||||
|
||||
protected function argTest():bool{
|
||||
if(!key_exists('destCityID', $this->arg)){
|
||||
return false;
|
||||
}
|
||||
if(!key_exists($this->arg['destCityID'], CityConst::all())){
|
||||
return false;
|
||||
}
|
||||
$this->arg = [
|
||||
'destCityID'=>$this->arg['destCityID']
|
||||
];
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
$env = $this->env;
|
||||
return [$env['develcost'], 0];
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->isRunnable()){
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
$env = $this->env;
|
||||
|
||||
$general = $this->generalObj;
|
||||
$date = substr($general->getVar('turntime'),11,5);
|
||||
|
||||
$destCityName = $this->destCity['name'];
|
||||
$destCityID = $this->destCity['city'];
|
||||
$josaRo = JosaUtil::pick($destCityName, '로');
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>{$josaRo} 이동했습니다. <1>$date</>");
|
||||
|
||||
$exp = 50;
|
||||
|
||||
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
|
||||
$general->setVar('city', $destCityID);
|
||||
|
||||
if($general->getVar('level') == 12 && $this->nation['level'] == 0){
|
||||
$generalList = $db->queryFirstColumn('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID());
|
||||
foreach($generalList as $targetRawGeneral){
|
||||
$targetGeneralID = $targetRawGeneral['no'];
|
||||
$targetGeneral = $this->getGeneralObjFromGeneralSource($targetGeneralID);
|
||||
if($targetGeneral === null){
|
||||
$targetGeneral = new General($targetRawGeneral, null, $env['year'], $env['month'], false);
|
||||
}
|
||||
$targetGeneral->setVar('city', $destCityID);
|
||||
$targetGeneral->getLogger()->pushGeneralActionLog("방랑군 세력이 <G><b>{$destCityName}</b></>{$josaRo} 이동했습니다.", ActionLogger::PLAIN);
|
||||
$targetGeneral = null;
|
||||
}
|
||||
}
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
$general->increaseVarWithLimit('gold', -$reqGold, 0);
|
||||
$general->increaseVar('experience', $exp);
|
||||
$general->increaseVar('leader2', 1);
|
||||
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user