집합, 귀환 추가

This commit is contained in:
2018-10-17 02:38:51 +09:00
parent 337424cb96
commit 220e98b2cc
9 changed files with 338 additions and 135 deletions
+1 -1
View File
@@ -92,7 +92,7 @@ class che_강행 extends Command\GeneralCommand{
$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());
$generalList = $db->query('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);
+101
View File
@@ -0,0 +1,101 @@
<?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();
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['NotCapital', 1],
];
}
protected function argTest():bool{
$this->arg = null;
return true;
}
public function getCost():array{
return [0, 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;
$generalID = $general->getID();
$date = substr($general->getVar('turntime'),11,5);
switch($general->getVar('level')){
case 2: [$cityID, $cityName] = $db->queryFirstList('SELECT city, name FROM city WHERE gen3=%i', $generalID); break;
case 3: [$cityID, $cityName] = $db->queryFirstList('SELECT city, name FROM city WHERE gen2=%i', $generalID); break;
case 4: [$cityID, $cityName] = $db->queryFirstList('SELECT city, name FROM city WHERE gen1=%i', $generalID); break;
default: [$cityID, $cityName] = $db->queryFirstList('SELECT city, name FROM city WHERE city=%i', $this->nation['capital']); break;
}
$josaRo = JosaUtil::pick($cityName, '로');
$logger = $general->getLogger();
$logger->pushGeneralActionLog("<G><b>{$cityName}</b></>{$josaRo} 귀환했습니다. <1>$date</>");
$exp = 70;
$ded = 100;
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
$general->setVar('city', $cityID);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
$general->increaseVar('leader2', 1);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
$general->applyDB($db);
}
}
+1 -1
View File
@@ -92,7 +92,7 @@ class che_이동 extends Command\GeneralCommand{
$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());
$generalList = $db->query('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);
+113
View File
@@ -0,0 +1,113 @@
<?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=[
['NoNeutral'],
['OccupiedCity'],
['SuppliedCity'],
['MustBeTroopLeader'],
['ReqTroopMembers'],
];
}
protected function argTest():bool{
$this->arg = null;
return true;
}
public function getCost():array{
return [0, 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);
$cityID = $this->city['city'];
$cityName = $this->city['name'];
$josaRo = JosaUtil::pick($cityName, '로');
$troopID = $general->getVar('troop');
$troopName = $db->queryFirstField('SELECT name FROM troop WHERE troop = %i', $troopID);
$logger = $general->getLogger();
$logger->pushGeneralActionLog("<G><b>{$cityName}</b></>에서 집합을 실시했습니다. <1>$date</>");
$generalList = $db->query('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND troop=%i AND no!=%i', $general->getNationID(), $troopID, $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("{$troopName}의 부대원들은 <G><b>{$cityName}</b></>{$josaRo} 집합되었습니다.", ActionLogger::PLAIN);
$targetGeneral = null;
}
$exp = 70;
$ded = 100;
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
$general->increaseVar('leader2', 1);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
$general->applyDB($db);
uniqueItemEx($general->getVar('no'), $logger);
}
}
@@ -0,0 +1,38 @@
<?php
namespace sammo\Constraint;
use sammo\DB;
//TODO: DB 사용하지 않도록 변경
class MustBeTroopLeader extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('troop', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require troop in general");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
//XXX: 부대장인지 알 수가 없음
$db = DB::db();
$troopLeader = $db->queryFirstField('SELECT no FROM troop WHERE troop = %i', $this->general['troop']);
if($troopLeader == $this->general['no']){
return true;
}
$this->reason = "부대장이 아닙니다.";
return false;
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace sammo\Constraint;
class NotCapital extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_NATION|Constraint::REQ_INT_ARG;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('city', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require city in general");
}
if(!key_exists('level', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require level in general");
}
if(!key_exists('capital', $this->nation)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require capital in nation");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
if($this->nation['capital'] != $this->general['city']){
return true;
}
if($this->arg && 2 <= $this->general['level'] && $this->general['level'] <= 4){
return true;
}
$this->reason = "이미 수도입니다.";
return false;
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
namespace sammo\Constraint;
class NoWanderingNation extends Constraint{
class OccupiedCity extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_CITY;
public function checkInputValues(bool $throwExeception=true){
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace sammo\Constraint;
use sammo\DB;
class ReqTroopMembers extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('troop', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require troop in general");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
$db = DB::db();
//NOTE:이 경우에 DB를 사용하지 않을 수 있는가?
$troopMember = $db->queryFirstField('SELECT no FROM troop WHERE troop = %i AND no != %i LIMIT 1', $this->general['troop'], $this->general['no']);
if($troopMember !== null){
return true;
}
$this->reason = "집합 가능한 부대원이 없습니다.";
return false;
}
}