Scenario 세팅 과정에 문제 해결

SetNationFront 함수도 수정
This commit is contained in:
2018-03-31 16:06:24 +09:00
parent 71f5311b1d
commit 31d9bac59c
14 changed files with 65 additions and 76 deletions
+1 -1
View File
@@ -130,7 +130,7 @@ if($action == 'scrub_old_user'){
$cnt = 0; $cnt = 0;
} }
else{ else{
$db->delete('member', 'no IN (%li)', $targetUser); $db->delete('member', 'no IN %li', $targetUser);
$cnt = $db->affectedRows(); $cnt = $db->affectedRows();
} }
+2 -2
View File
@@ -2927,14 +2927,14 @@ function TrickInjury($connect, $city, $type=0) {
} }
function getRandTurn($term) { function getRandTurn($term) {
$randtime = $rand(0, 60 * $term - 1); $randtime = rand(0, 60 * $term - 1);
$turntime = date('Y-m-d H:i:s', strtotime('now') + $randtime); $turntime = date('Y-m-d H:i:s', strtotime('now') + $randtime);
return $turntime; return $turntime;
} }
function getRandTurn2($term) { function getRandTurn2($term) {
$randtime = $rand(0, 60 * $term - 1); $randtime = rand(0, 60 * $term - 1);
$turntime = date('Y-m-d H:i:s', strtotime('now') - $randtime); $turntime = date('Y-m-d H:i:s', strtotime('now') - $randtime);
return $turntime; return $turntime;
+27 -46
View File
@@ -1,5 +1,5 @@
<?php <?php
namespace sammo;
/** /**
* 게임 룰에 해당하는 함수 모음 * 게임 룰에 해당하는 함수 모음
@@ -200,60 +200,41 @@ function addGenDex($connect, $no, $type, $exp) {
//한국가의 전체 전방 설정 //한국가의 전체 전방 설정
function SetNationFront($connect, $nationNo) { function SetNationFront($nationNo) {
if(!$nationNo) { return; } if(!$nationNo) { return; }
// 도시소유 국가와 선포,교전중인 국가 // 도시소유 국가와 선포,교전중인 국가
$query = "select me,you from diplomacy where me={$nationNo} and (state=0 or (state=1 and term<=3))";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $adj = [];
$dipNum = MYDB_num_rows($result);
if($dipNum > 0) {
for($i=0; $i < $dipNum; $i++) {
$dip = MYDB_fetch_array($result);
$query = "select city,path from city where nation={$dip['you']}"; $db = DB::db();
$result2 = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $warNations = $db->queryFirstColumn('SELECT you from diplomacy where me = %i and (state=0 or (state=1 and term<=3))');
$cityNum = MYDB_num_rows($result2); if($warNations) {
for($k=0; $k < $cityNum; $k++) { foreach($warNations as $warNation){
$city = MYDB_fetch_array($result2); $enemyCities = $db->queryFirstColumn('SELECT city from city where nation=%i', $warNation);
$path = explode("|", $city['path']); foreach($enemyCities as $city){
$cnt = count($path); foreach(CityConst::byID($city)->path as $adjCity){
for($j=0; $j < $cnt; $j++) { $adj[$adjCity] = 1;
$adj[$path[$j]] = 1;
} }
} }
} }
} else { } else {
//평시이면 공백지 //평시이면 공백지
$query = "select city,path from city where nation=0"; //NOTE: if, else일 경우 NPC는 전쟁시에는 공백지로 출병하지 않는다는 뜻이 된다.
$result2 = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); foreach ($db->queryFirstColumn('SELECT city,path from city where nation=0') as $city) {
$cityNum = MYDB_num_rows($result2); foreach(CityConst::byID($city)->path as $adjCity){
for($k=0; $k < $cityNum; $k++) { $adj[$adjCity] = 1;
$city = MYDB_fetch_array($result2);
$path = explode("|", $city['path']);
$cnt = count($path);
for($j=0; $j < $cnt; $j++) {
$adj[$path[$j]] = 1;
} }
} }
} }
$str = "city=0"; $valid = 0;
$query = "select city from city where nation={$nationNo}"; $db->update('city', [
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); 'front'=>0
$cityNum = MYDB_num_rows($result); ], 'nation=%i', $nationNo);
for($i=0; $i < $cityNum; $i++) {
$city = MYDB_fetch_array($result); if($adj){
if(isset($city['city'])) { $db->update('city', [
if (isset($adj[$city['city']]) && ($adj[$city['city']] == 1)) { 'front'=>0
$str .= " or city={$city['city']}"; ], 'nation=%i and city in %li', $nationNo, array_keys($adj));
$valid = 1;
}
}
}
$query = "update city set front=0 where nation={$nationNo}";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
if($valid == 1) {
$query = "update city set front=1 where {$str}";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
} }
} }
@@ -664,7 +645,7 @@ group by A.nation
if($nation['level'] <= 0){ if($nation['level'] <= 0){
continue; continue;
} }
SetNationFront($connect, $nation['nation']); SetNationFront($nation['nation']);
} }
} }
+1 -1
View File
@@ -586,7 +586,7 @@ function processAI($connect, $no) {
//외교 평시에 선포 //외교 평시에 선포
if($dipState == 0 && $attackable == 0) { if($dipState == 0 && $attackable == 0) {
//전방 체크 먼저 //전방 체크 먼저
SetNationFront($connect, $nation['nation']); SetNationFront($nation['nation']);
$query = "select city from city where nation='{$general['nation']}' and front=1 limit 0,1"; $query = "select city from city where nation='{$general['nation']}' and front=1 limit 0,1";
$result = MYDB_query($query, $connect) or Error("processAI02 ".MYDB_error($connect),""); $result = MYDB_query($query, $connect) or Error("processAI02 ".MYDB_error($connect),"");
+5 -5
View File
@@ -1806,7 +1806,7 @@ function ConquerCity($connect, $game, $general, $city, $nation, $destnation) {
for($i=0; $i < $dipCount; $i++) { for($i=0; $i < $dipCount; $i++) {
$dip = MYDB_fetch_array($dipResult); $dip = MYDB_fetch_array($dipResult);
//전방설정 //전방설정
SetNationFront($connect, $dip['you']); SetNationFront($dip['you']);
} }
// 멸망이 아니면 // 멸망이 아니면
} else { } else {
@@ -1887,8 +1887,8 @@ function ConquerCity($connect, $game, $general, $city, $nation, $destnation) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
} }
//전방설정 //전방설정
SetNationFront($connect, $nation['nation']); SetNationFront($nation['nation']);
SetNationFront($connect, $destnation['nation']); SetNationFront($destnation['nation']);
} else { } else {
$query = "select name,nation from nation where nation='$conquerNation'"; $query = "select name,nation from nation where nation='$conquerNation'";
$conquerResult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); $conquerResult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
@@ -1910,8 +1910,8 @@ function ConquerCity($connect, $game, $general, $city, $nation, $destnation) {
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
} }
//전방설정 //전방설정
SetNationFront($connect, $destnation['nation']); SetNationFront($destnation['nation']);
SetNationFront($connect, $conquerNation); SetNationFront($conquerNation);
} }
pushGenLog($general, $log); pushGenLog($general, $log);
+3 -1
View File
@@ -23,7 +23,9 @@ class CityHelper{
$listByNation = []; $listByNation = [];
foreach (DB::db()->query('SELECT `city` as `id`, `name`, `level`, `nation` from city') as $city) { foreach (DB::db()->query('SELECT `city` as `id`, `name`, `level`, `nation` from city') as $city) {
$list[$city['id']] = $city; $id = $city['id'];
$name = $city['name'];
$list[$id] = $city;
$listInv[$city['name']] = $city; $listInv[$city['name']] = $city;
if(!key_exists($id, $listByNation)){ if(!key_exists($id, $listByNation)){
+1 -3
View File
@@ -152,13 +152,11 @@ class ChangeCity extends \sammo\Event\Action{
} }
public function run($env=null){ public function run($env=null){
$target = $this->target;
$cities = $this->getTargetCities($env); $cities = $this->getTargetCities($env);
DB::db()->update('city', DB::db()->update('city',
$this->queries $this->queries
, 'city IN (%li)', $cities); , 'city IN %li', $cities);
return [__CLASS__, DB::db()->affectedRows()]; return [__CLASS__, DB::db()->affectedRows()];
} }
+4 -4
View File
@@ -56,7 +56,7 @@ class RaiseInvader extends \sammo\Event\Action{
$db = DB::db(); $db = DB::db();
foreach($db->queryFirstColumn('SELECT capital, nation from nation WHERE capital in (%li)', $cities) as $row){ foreach($db->queryFirstColumn('SELECT capital, nation from nation WHERE capital in %li', $cities) as $row){
list($oldCapital, $nation) = $row; list($oldCapital, $nation) = $row;
$newCapital = $db->queryFirstRow('SELECT city from city where nation=%i and city !=%i \ $newCapital = $db->queryFirstRow('SELECT city from city where nation=%i and city !=%i \
order by rand() limit 1', $nation, $oldCapital); order by rand() limit 1', $nation, $oldCapital);
@@ -66,7 +66,7 @@ class RaiseInvader extends \sammo\Event\Action{
} }
$generals = []; $generals = [];
foreach($db->query('SELECT gen1, gen2, gen3 from city where city in (%li)', $cities) as $city){ foreach($db->query('SELECT gen1, gen2, gen3 from city where city in %li', $cities) as $city){
list($gen1, $gen2, $gen3) = $city; list($gen1, $gen2, $gen3) = $city;
if($gen1 != 0) $generals[]=$gen1; if($gen1 != 0) $generals[]=$gen1;
if($gen2 != 0) $generals[]=$gen2; if($gen2 != 0) $generals[]=$gen2;
@@ -75,14 +75,14 @@ class RaiseInvader extends \sammo\Event\Action{
$db->update('general', [ $db->update('general', [
'level'=>1 'level'=>1
], 'no in (%li)', $generals); ], 'no in %li', $generals);
$db->update('city', [ $db->update('city', [
'gen1'=>0, 'gen1'=>0,
'gen2'=>0, 'gen2'=>0,
'gen3'=>0, 'gen3'=>0,
'nation'=>0 'nation'=>0
], 'city in (%li)', $cities); ], 'city in %li', $cities);
} }
public function run($env=null){ public function run($env=null){
+5 -1
View File
@@ -2,10 +2,14 @@
namespace sammo\Event; namespace sammo\Event;
abstract class Condition{ abstract class Condition{
public abstract function __construct($args=null);
public abstract function eval($env=null); public abstract function eval($env=null);
public static function build($conditionChain){ public static function build($conditionChain){
if(is_bool($conditionChain)){
return new Condition\ConstBool($conditionChain);
}
if(!is_array($conditionChain)){ if(!is_array($conditionChain)){
return $conditionChain; return $conditionChain;
} }
+1 -1
View File
@@ -1,7 +1,7 @@
<?php <?php
namespace sammo\Event\Condition; namespace sammo\Event\Condition;
class ConstBool extends sammo\Event\Condition{ class ConstBool extends \sammo\Event\Condition{
private $fixedResult = true; private $fixedResult = true;
public function __construct(bool $value){ public function __construct(bool $value){
+1 -1
View File
@@ -9,7 +9,7 @@ class EventHandler{
public function __construct($rawCondition, $rawActions){ public function __construct($rawCondition, $rawActions){
$this->condition = Condition::build($rawCondition); $this->condition = Condition::build($rawCondition);
foreach($rawActions as $rawAction){ foreach($rawActions as $rawAction){
$this->condition = Action::build($rawAction); $this->actions[] = Action::build($rawAction);
} }
} }
+1 -1
View File
@@ -378,7 +378,7 @@ class Scenario{
refreshNationStaticInfo(); refreshNationStaticInfo();
foreach(getAllNationStaticInfo() as $nation){ foreach(getAllNationStaticInfo() as $nation){
SetNationFront($db->get(), $nation['nation']); SetNationFront($nation['nation']);
} }
} }
+4 -3
View File
@@ -96,7 +96,7 @@ class NPC{
$picture = 'default.jpg'; $picture = 'default.jpg';
} }
$city = $this->city; $city = $this->locatedCity;
if($city === null){ if($city === null){
if($nationID == 0){ if($nationID == 0){
$city = Util::choiceRandom(CityHelper::getAllCities())['id']; $city = Util::choiceRandom(CityHelper::getAllCities())['id'];
@@ -117,9 +117,10 @@ class NPC{
$specage = $age + 1; $specage = $age + 1;
$specage2 = $age + 1; $specage2 = $age + 1;
$npcID = $db->queryFirstField('SELECT max(npcid)+1 FROM general');
$db->insert('general',[ $db->insert('general',[
'npcid'=>$db->sqleval('max(npcid)+1'), 'npcid'=>$npcID,
'npc'=>2, 'npc'=>2,
'npc_org'=>2, 'npc_org'=>2,
'affinity'=>$this->affinity, 'affinity'=>$this->affinity,
@@ -127,7 +128,7 @@ class NPC{
'picture'=>$picture, 'picture'=>$picture,
'nation'=>$nationID, 'nation'=>$nationID,
'city'=>$city, 'city'=>$city,
'leader'=>$this->leader, 'leader'=>$this->leadership,
'power'=>$this->power, 'power'=>$this->power,
'intel'=>$this->intel, 'intel'=>$this->intel,
'experience'=>$experience, 'experience'=>$experience,
+9 -6
View File
@@ -59,7 +59,7 @@ class Nation{
}, $this->cities); }, $this->cities);
$capital = \sammo\CityHelper::getCityByName($this->capital)['id']; $capital = \sammo\CityHelper::getCityByName($this->capital)['id'];
$type = \sammo\NationCharCall($this->$type); $type = \sammo\NationCharCall($this->type);
$db = DB::db(); $db = DB::db();
$otherNations = $db->queryFirstColumn('SELECT nation FROM nation'); $otherNations = $db->queryFirstColumn('SELECT nation FROM nation');
@@ -81,29 +81,32 @@ class Nation{
'scoutmsg'=>$this->infoText, 'scoutmsg'=>$this->infoText,
'tech'=>$this->tech, 'tech'=>$this->tech,
'totaltech'=>0, 'totaltech'=>0,
'level'=>$this->level, 'level'=>$this->nationLevel,
'type'=>$type, 'type'=>$type,
]); ]);
$db->update('city', [ $db->update('city', [
'nation'=>$this->id 'nation'=>$this->id
], 'city IN (%li)', $cities); ], 'city IN %li', $cities);
$diplomacy = []; $diplomacy = [];
foreach($otherNations as $nation){ foreach($otherNations as $nation){
$diplomacy[] = [ $diplomacy[] = [
'me'=>$this->$id, 'me'=>$this->id,
'you'=>$nation, 'you'=>$nation,
'state'=>2 'state'=>2
]; ];
$diplomacy[] = [ $diplomacy[] = [
'me'=>$nation, 'me'=>$nation,
'you'=>$this->$id, 'you'=>$this->id,
'state'=>2 'state'=>2
]; ];
} }
$db->insert('diplomacy', $diplomacy); if(count($diplomacy) > 0){
$db->insert('diplomacy', $diplomacy);
}
} }
public function postBuild($env=[]){ public function postBuild($env=[]){