집합, 귀환 추가
This commit is contained in:
@@ -551,138 +551,6 @@ function process_16(&$general) {
|
||||
pushGenLog($general, $log);
|
||||
}
|
||||
|
||||
function process_26(&$general) {
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$connect=$db->get();
|
||||
|
||||
$log = [];
|
||||
$alllog = [];
|
||||
$history = [];
|
||||
$date = substr($general['turntime'],11,5);
|
||||
|
||||
$troop = getTroop($general['troop']);
|
||||
|
||||
$admin = $gameStor->getValues(['year', 'month']);
|
||||
|
||||
$query = "select nation,name,supply from city where city='{$general['city']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$city = MYDB_fetch_array($result);
|
||||
|
||||
$query = "select no,name,nation,city from general where troop='{$general['troop']}' and no!='{$general['no']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$gencount = MYDB_num_rows($result);
|
||||
|
||||
if($general['nation'] != $city['nation']) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:아국이 아닙니다. 집합 실패. <1>$date</>";
|
||||
} elseif($city['supply'] == 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:고립된 도시입니다. 집합 실패. <1>$date</>";
|
||||
} elseif($general['no'] != $troop['no']) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:부대장이 아닙니다. 집합 실패. <1>$date</>";
|
||||
} elseif($gencount == 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:집합 가능한 부대원이 없습니다. 집합 실패. <1>$date</>";
|
||||
} else {
|
||||
$log[] = "<C>●</>{$admin['month']}월:<G><b>{$city['name']}</b></>에서 집합을 실시했습니다. <1>$date</>";
|
||||
$exp = 70;
|
||||
$ded = 100;
|
||||
|
||||
// 성격 보정
|
||||
$exp = CharExperience($exp, $general['personal']);
|
||||
$ded = CharDedication($ded, $general['personal']);
|
||||
|
||||
//부대원에게 로그 전달
|
||||
$josaRo = JosaUtil::pick($city['name'], '로');
|
||||
$genlog = ["<C>●</><S>{$troop['name']}</>의 부대원들은 <G><b>{$city['name']}</b></>{$josaRo} 집합되었습니다."];
|
||||
|
||||
for($i=0; $i < $gencount; $i++) {
|
||||
$troopgen = MYDB_fetch_array($result);
|
||||
if($general['city'] != $troopgen['city']) {
|
||||
pushGenLog($troopgen, $genlog);
|
||||
}
|
||||
}
|
||||
|
||||
// 같은 부대원 모두 집합
|
||||
$query = "update general set city='{$general['city']}' where troop='{$general['troop']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
// 경험치 명성 공헌 상승
|
||||
$general['leader2']++;
|
||||
$query = "update general set resturn='SUCCESS',leader2='{$general['leader2']}',dedication=dedication+'$ded',experience=experience+'$exp' where no='{$general['no']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
$log = checkAbility($general, $log);
|
||||
$log = uniqueItem($general, $log);
|
||||
}
|
||||
|
||||
pushGeneralPublicRecord($alllog, $admin['year'], $admin['month']);
|
||||
pushGenLog($general, $log);
|
||||
}
|
||||
|
||||
function process_28(&$general) {
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$connect=$db->get();
|
||||
|
||||
$log = [];
|
||||
$alllog = [];
|
||||
$history = [];
|
||||
$youlog = [];
|
||||
|
||||
$date = substr($general['turntime'],11,5);
|
||||
|
||||
$admin = $gameStor->getValues(['year', 'month']);
|
||||
|
||||
$nation = getNationStaticInfo($general['nation']);
|
||||
|
||||
if($nation['level'] == 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:방랑군입니다. 귀환 실패. <1>$date</>";
|
||||
} elseif($general['level'] == 0) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:재야입니다. 귀환 실패. <1>$date</>";
|
||||
} elseif(($general['level'] == 1 || $general['level'] >= 5) && $general['city'] == $nation['capital']) {
|
||||
$log[] = "<C>●</>{$admin['month']}월:이미 수도입니다. 귀환 실패. <1>$date</>";
|
||||
} else {
|
||||
if($general['level'] == 2) {
|
||||
$query = "select city,name from city where gen3='{$general['no']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$city = MYDB_fetch_array($result);
|
||||
} elseif($general['level'] == 3) {
|
||||
$query = "select city,name from city where gen2='{$general['no']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$city = MYDB_fetch_array($result);
|
||||
} elseif($general['level'] == 4) {
|
||||
$query = "select city,name from city where gen1='{$general['no']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$city = MYDB_fetch_array($result);
|
||||
} else {
|
||||
$query = "select city,name from city where city='{$nation['capital']}'";
|
||||
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
$city = MYDB_fetch_array($result);
|
||||
}
|
||||
|
||||
$josaRo = JosaUtil::pick($city['name'], '로');
|
||||
$log[] = "<C>●</>{$admin['month']}월:<G>{$city['name']}</>{$josaRo} 귀환했습니다. <1>$date</>";
|
||||
$exp = 70;
|
||||
$ded = 100;
|
||||
|
||||
// 성격 보정
|
||||
$exp = CharExperience($exp, $general['personal']);
|
||||
$ded = CharDedication($ded, $general['personal']);
|
||||
|
||||
// 귀환
|
||||
$query = "update general set city='{$city['city']}' where no='{$general['no']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
// 경험치 상승 // 명성,공헌 상승
|
||||
$general['leader2']++;
|
||||
$query = "update general set resturn='SUCCESS',leader2='{$general['leader2']}',experience=experience+'$exp',dedication=dedication+'$ded' where no='{$general['no']}'";
|
||||
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
|
||||
|
||||
$log = checkAbility($general, $log);
|
||||
}
|
||||
|
||||
pushGenLog($general, $log);
|
||||
//pushGenLog($you, $youlog);
|
||||
}
|
||||
|
||||
function process_31(&$general) {
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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){
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user