generalSource 폐기
This commit is contained in:
@@ -36,8 +36,6 @@ abstract class BaseCommand{
|
||||
|
||||
protected $runnableConstraints = null;
|
||||
protected $reservableConstraints = null;
|
||||
|
||||
protected $generalSource = null;
|
||||
|
||||
protected $logger;
|
||||
|
||||
@@ -54,17 +52,6 @@ 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;
|
||||
|
||||
@@ -92,16 +92,18 @@ class che_강행 extends Command\GeneralCommand{
|
||||
$general->setVar('city', $destCityID);
|
||||
|
||||
if($general->getVar('level') == 12 && $this->nation['level'] == 0){
|
||||
$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);
|
||||
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;
|
||||
|
||||
$generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID());
|
||||
if($generalList){
|
||||
$db->update('general', [
|
||||
'city'=>$destCityID
|
||||
], 'no IN %li', $generalList);
|
||||
}
|
||||
foreach($generalList as $targetGeneralID){
|
||||
$targetGeneral = General::createGeneralObjFromDB($targetGeneralID, [], 1);
|
||||
$targetLogger = new ActionLogger($targetGeneralID, $general->getNationID(), $env['year'], $env['month']);
|
||||
$targetLogger->pushGeneralActionLog("방랑군 세력이 <G><b>{$destCityName}</b></>{$josaRo} 강행했습니다.", ActionLogger::PLAIN);
|
||||
$targetLogger->flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ class che_기술연구 extends che_상업투자{
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
uniqueItemEx($general->getVar('no'), $logger);
|
||||
uniqueItemEx($general->getID(), $logger);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ class che_단련 extends Command\GeneralCommand{
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
uniqueItemEx($general->getVar('no'), $logger);
|
||||
uniqueItemEx($general->getID(), $logger);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ class che_사기진작 extends Command\GeneralCommand{
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
uniqueItemEx($general->getVar('no'), $logger);
|
||||
uniqueItemEx($general->getID(), $logger);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ class che_상업투자 extends Command\GeneralCommand{
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
uniqueItemEx($general->getVar('no'), $logger);
|
||||
uniqueItemEx($general->getID(), $logger);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -92,16 +92,17 @@ class che_이동 extends Command\GeneralCommand{
|
||||
$general->setVar('city', $destCityID);
|
||||
|
||||
if($general->getVar('level') == 12 && $this->nation['level'] == 0){
|
||||
$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);
|
||||
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;
|
||||
$generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID());
|
||||
if($generalList){
|
||||
$db->update('general', [
|
||||
'city'=>$destCityID
|
||||
], 'no IN %li', $generalList);
|
||||
}
|
||||
foreach($generalList as $targetGeneralID){
|
||||
$targetGeneral = General::createGeneralObjFromDB($targetGeneralID, [], 1);
|
||||
$targetLogger = new ActionLogger($targetGeneralID, $general->getNationID(), $env['year'], $env['month']);
|
||||
$targetLogger->pushGeneralActionLog("방랑군 세력이 <G><b>{$destCityName}</b></>{$josaRo} 이동했습니다.", ActionLogger::PLAIN);
|
||||
$targetLogger->flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ class che_정착장려 extends Command\GeneralCommand{
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
uniqueItemEx($general->getVar('no'), $logger);
|
||||
uniqueItemEx($general->getID(), $logger);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ class che_주민선정 extends Command\GeneralCommand{
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
uniqueItemEx($general->getVar('no'), $logger);
|
||||
uniqueItemEx($general->getID(), $logger);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -81,16 +81,17 @@ class che_집합 extends Command\GeneralCommand{
|
||||
|
||||
$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;
|
||||
$generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND troop=%i AND no!=%i', $general->getNationID(), $troopID, $general->getID());
|
||||
if($generalList){
|
||||
$db->update('general', [
|
||||
'city'=>$cityID
|
||||
], 'no IN %li', $generalList);
|
||||
}
|
||||
foreach($generalList as $targetGeneralID){
|
||||
$targetGeneral = General::createGeneralObjFromDB($targetGeneralID, [], 1);
|
||||
$targetLogger = new ActionLogger($targetGeneralID, $general->getNationID(), $env['year'], $env['month']);
|
||||
$targetLogger->pushGeneralActionLog("{$troopName}의 부대원들은 <G><b>{$cityName}</b></>{$josaRo} 집합되었습니다.", ActionLogger::PLAIN);
|
||||
$targetLogger->flush();
|
||||
}
|
||||
|
||||
$exp = 70;
|
||||
@@ -106,7 +107,7 @@ class che_집합 extends Command\GeneralCommand{
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
uniqueItemEx($general->getVar('no'), $logger);
|
||||
uniqueItemEx($general->getID(), $logger);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ class che_훈련 extends Command\GeneralCommand{
|
||||
$general->checkStatChange();
|
||||
$general->applyDB($db);
|
||||
|
||||
uniqueItemEx($general->getVar('no'), $logger);
|
||||
uniqueItemEx($general->getID(), $logger);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -504,9 +504,9 @@ class General implements iAction{
|
||||
return $caller;
|
||||
}
|
||||
|
||||
static public function createGeneralObjFromDB(int $generalID, ?array $column=null, bool $fullConstruct=true):self{
|
||||
static public function createGeneralObjFromDB(int $generalID, ?array $column=null, int $constructMode=2):self{
|
||||
$db = DB::db();
|
||||
if($fullConstruct){
|
||||
if($constructMode > 0){
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
[$year, $month] = $gameStor->getValuesAsArray(['year', 'month']);
|
||||
}
|
||||
@@ -533,7 +533,7 @@ class General implements iAction{
|
||||
if($column === null){
|
||||
$column = $fullColumn;
|
||||
}
|
||||
else if($fullConstruct){
|
||||
else if($constructMode > 1){
|
||||
$column = array_unique(array_merge($defaultEventColumn, $column));
|
||||
}
|
||||
else{
|
||||
@@ -545,7 +545,7 @@ class General implements iAction{
|
||||
throw new \InvalidArgumentException("generalID에 해당하는 장수가 없음: {$generalID}");
|
||||
}
|
||||
|
||||
$general = new static($rawGeneral, null, $year, $month, $fullConstruct);
|
||||
$general = new static($rawGeneral, null, $year, $month, $constructMode > 1);
|
||||
|
||||
return $general;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class che_도시치료 extends BaseGeneralTrigger{
|
||||
$patients = $db->queryAllLists(
|
||||
'SELECT no,name,nation FROM general WHERE city=%i AND injury > 10 AND no != %i',
|
||||
$general->getVar('city'),
|
||||
$general->getVar('no')
|
||||
$general->getID()
|
||||
);
|
||||
|
||||
if(!$patients){
|
||||
|
||||
@@ -8,12 +8,10 @@ class TurnExecutionHelper
|
||||
* @var General $generalObj;
|
||||
*/
|
||||
protected $generalObj;
|
||||
protected $generalSource = null;
|
||||
|
||||
public function __construct(General $general, ?array $generalSource = null)
|
||||
public function __construct(General $general)
|
||||
{
|
||||
$this->generalObj = $general;
|
||||
$this->generalSource = $generalSource;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
@@ -77,7 +75,6 @@ class TurnExecutionHelper
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
$commandObj = buildNationCommandClass($commandClassName, $general, $gameStor->getAll(true), $commandLast, $commandArg);
|
||||
$commandObj->setGeneralSource($this->generalSource);
|
||||
|
||||
$failReason = $commandObj->testReservable();
|
||||
if($failReason){
|
||||
@@ -103,7 +100,6 @@ class TurnExecutionHelper
|
||||
$commandClass = getGeneralCommandClass($commandClassName);
|
||||
/** @var \sammo\Command\GeneralCommand $commandObj */
|
||||
$commandObj = new $commandClass($general, $gameStor->getAll(true), $commandArg, $commandLast);
|
||||
$commandObj->setGeneralSource($this->generalSource);
|
||||
|
||||
$failReason = $commandObj->testReservable();
|
||||
if($failReason){
|
||||
@@ -188,61 +184,47 @@ class TurnExecutionHelper
|
||||
|
||||
static public function executeGeneralCommandUntil(string $date, \DateTimeInterface $limitActionTime, int $year, int $month){
|
||||
$db = DB::db();
|
||||
$rawGeneralsTodo = $db->queryFirstRow(
|
||||
'SELECT no,name,name2,picture,imgsvr,nation,nations,city,troop,injury,affinity,
|
||||
leader,leader2,power,power2,intel,intel2,weap,book,horse,item,
|
||||
experience,dedication,level,gold,rice,crew,crewtype,train,atmos,
|
||||
turntime,makenation,makelimit,killturn,block,dedlevel,explevel,
|
||||
age,belong,personal,special,special2,term,mode,
|
||||
npc,npc_org,npcid,deadyear,npcmsg,
|
||||
dex0,dex10,dex20,dex30,dex40,
|
||||
warnum,killnum,deathnum,killcrew,deathcrew,recwar,last_turn
|
||||
$generalsTodo = $db->queryFirstRow(
|
||||
'SELECT no,name,turntime,killturn,block,npc,deadyear,
|
||||
general_turn.`action` AS `action`, general_turn.arg AS arg
|
||||
FROM general LEFT JOIN general_turn ON general.`no` = general_turn.general_id AND turn_idx = 0
|
||||
WHERE turntime < %s ORDER BY turntime ASC, `no` ASC',
|
||||
$date
|
||||
);
|
||||
|
||||
$generalsTodo = [];
|
||||
$generalSource = [];
|
||||
foreach($rawGeneralsTodo as $rawGeneral){
|
||||
$currentTurn = null;
|
||||
|
||||
foreach($generalsTodo as $rawGeneral){
|
||||
$generalCommand = $rawGeneral['action'];
|
||||
$generalArg = Json::decode($rawGeneral['arg'])??[];
|
||||
unset($rawGeneral['action']);
|
||||
unset($rawGeneral['arg']);
|
||||
$general = new General($rawGeneral, $year, $month);
|
||||
|
||||
$generalsTodo[] = [$general, $generalCommand, $generalArg];
|
||||
$generalSource[$general->getID()] = $general;
|
||||
}
|
||||
|
||||
$currentTurn = null;
|
||||
|
||||
foreach($generalsTodo as [$general, $generalCommand, $generalArg]){
|
||||
|
||||
$currActionTime = new \DateTimeImmutable();
|
||||
if($currActionTime > $limitActionTime){
|
||||
return [true, $currentTurn];
|
||||
}
|
||||
|
||||
$turnObj = new static($general, $generalSource);
|
||||
$general = General::createGeneralObjFromDB($rawGeneral['no']);
|
||||
$turnObj = new static($general);
|
||||
|
||||
$hasNationTurn = false;
|
||||
if($generalWork['nation'] != 0 && $generalWork['level'] >= 5){
|
||||
if($general->getVar('nation') != 0 && $general->getVar('level') >= 5){
|
||||
$nationStor = KVStorage::getStorage($db, 'nation_env');
|
||||
$lastNationTurnKey = "turn_last_{$generalWork['nation']}_{$generalWork['level']}";
|
||||
$lastNationTurnKey = "turn_last_{$general->getVar('nation')}_{$general->getVar('level')}";
|
||||
$lastNationTurn = $nationStor->getDBValue($lastNationTurnKey)??[];
|
||||
//수뇌 몇 없는데 매번 left join 하는건 낭비인것 같다.
|
||||
$rawNationTurn = Json::decode($db->queryFirstRow(
|
||||
'SELECT action, arg FROM nation_turn WHERE nation_id = %i AND level = %i AND turn_idx =0',
|
||||
$generalWork['nation'],
|
||||
$generalWork['level']
|
||||
$general->getVar('nation'),
|
||||
$general->getVar('level')
|
||||
))??[];
|
||||
$hasNationTurn = true;
|
||||
$nationCommand = $rawNationTurn['action'];
|
||||
$nationArg = Json::decode($rawNationTurn['arg']);
|
||||
}
|
||||
|
||||
if($generalWork['npc'] >= 2){
|
||||
if($general->getVar('npc') >= 2){
|
||||
$ai = new GeneralAI($turnObj->getGeneral());
|
||||
if($hasNationTurn){
|
||||
[$nationCommand, $nationArg] = $ai->chooseNationTurn($nationCommand, $nationArg);
|
||||
@@ -264,12 +246,15 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC',
|
||||
}
|
||||
$turnObj->processCommand($generalCommand, $generalArg);
|
||||
}
|
||||
pullNationCommand($generalWork['nation'], $generalWork['level']);
|
||||
pullGeneralCommand($generalWork['no']);
|
||||
pullNationCommand($general->getVar('nation'), $general->getVar('level'));
|
||||
pullGeneralCommand($general->getID());
|
||||
|
||||
$currentTurn = $general->getVar('turntime');
|
||||
|
||||
$turnObj->updateTurnTime();
|
||||
$turnObj->applyDB();
|
||||
|
||||
$currentTurn = $generalWork['turntime'];
|
||||
|
||||
}
|
||||
|
||||
return [false, $currentTurn];
|
||||
|
||||
Reference in New Issue
Block a user