diff --git a/i_entrance/j_set_userlist.php b/i_entrance/j_set_userlist.php index 787ef165..14ff2e41 100644 --- a/i_entrance/j_set_userlist.php +++ b/i_entrance/j_set_userlist.php @@ -130,7 +130,7 @@ if($action == 'scrub_old_user'){ $cnt = 0; } else{ - $db->delete('member', 'no IN (%li)', $targetUser); + $db->delete('member', 'no IN %li', $targetUser); $cnt = $db->affectedRows(); } diff --git a/twe/func.php b/twe/func.php index 4d1f5a8b..e79f6bc9 100644 --- a/twe/func.php +++ b/twe/func.php @@ -2927,14 +2927,14 @@ function TrickInjury($connect, $city, $type=0) { } 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); return $turntime; } 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); return $turntime; diff --git a/twe/func_gamerule.php b/twe/func_gamerule.php index 264cf714..a16fa828 100644 --- a/twe/func_gamerule.php +++ b/twe/func_gamerule.php @@ -1,5 +1,5 @@ 0) { - for($i=0; $i < $dipNum; $i++) { - $dip = MYDB_fetch_array($result); + + $adj = []; - $query = "select city,path from city where nation={$dip['you']}"; - $result2 = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $cityNum = MYDB_num_rows($result2); - for($k=0; $k < $cityNum; $k++) { - $city = MYDB_fetch_array($result2); - $path = explode("|", $city['path']); - $cnt = count($path); - for($j=0; $j < $cnt; $j++) { - $adj[$path[$j]] = 1; + $db = DB::db(); + $warNations = $db->queryFirstColumn('SELECT you from diplomacy where me = %i and (state=0 or (state=1 and term<=3))'); + if($warNations) { + foreach($warNations as $warNation){ + $enemyCities = $db->queryFirstColumn('SELECT city from city where nation=%i', $warNation); + foreach($enemyCities as $city){ + foreach(CityConst::byID($city)->path as $adjCity){ + $adj[$adjCity] = 1; } } } } else { - //평시이면 공백지 - $query = "select city,path from city where nation=0"; - $result2 = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $cityNum = MYDB_num_rows($result2); - for($k=0; $k < $cityNum; $k++) { - $city = MYDB_fetch_array($result2); - $path = explode("|", $city['path']); - $cnt = count($path); - for($j=0; $j < $cnt; $j++) { - $adj[$path[$j]] = 1; + //평시이면 공백지 + //NOTE: if, else일 경우 NPC는 전쟁시에는 공백지로 출병하지 않는다는 뜻이 된다. + foreach ($db->queryFirstColumn('SELECT city,path from city where nation=0') as $city) { + foreach(CityConst::byID($city)->path as $adjCity){ + $adj[$adjCity] = 1; } } } - $str = "city=0"; $valid = 0; - $query = "select city from city where nation={$nationNo}"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $cityNum = MYDB_num_rows($result); - for($i=0; $i < $cityNum; $i++) { - $city = MYDB_fetch_array($result); - if(isset($city['city'])) { - if (isset($adj[$city['city']]) && ($adj[$city['city']] == 1)) { - $str .= " or city={$city['city']}"; - $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),""); + + $db->update('city', [ + 'front'=>0 + ], 'nation=%i', $nationNo); + + if($adj){ + $db->update('city', [ + 'front'=>0 + ], 'nation=%i and city in %li', $nationNo, array_keys($adj)); } } @@ -664,7 +645,7 @@ group by A.nation if($nation['level'] <= 0){ continue; } - SetNationFront($connect, $nation['nation']); + SetNationFront($nation['nation']); } } diff --git a/twe/func_npc.php b/twe/func_npc.php index e858c704..2174550d 100644 --- a/twe/func_npc.php +++ b/twe/func_npc.php @@ -586,7 +586,7 @@ function processAI($connect, $no) { //외교 평시에 선포 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"; $result = MYDB_query($query, $connect) or Error("processAI02 ".MYDB_error($connect),""); diff --git a/twe/process_war.php b/twe/process_war.php index 653494df..40b9dfef 100644 --- a/twe/process_war.php +++ b/twe/process_war.php @@ -1806,7 +1806,7 @@ function ConquerCity($connect, $game, $general, $city, $nation, $destnation) { for($i=0; $i < $dipCount; $i++) { $dip = MYDB_fetch_array($dipResult); //전방설정 - SetNationFront($connect, $dip['you']); + SetNationFront($dip['you']); } // 멸망이 아니면 } else { @@ -1887,8 +1887,8 @@ function ConquerCity($connect, $game, $general, $city, $nation, $destnation) { MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); } //전방설정 - SetNationFront($connect, $nation['nation']); - SetNationFront($connect, $destnation['nation']); + SetNationFront($nation['nation']); + SetNationFront($destnation['nation']); } else { $query = "select name,nation from nation where nation='$conquerNation'"; $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),""); } //전방설정 - SetNationFront($connect, $destnation['nation']); - SetNationFront($connect, $conquerNation); + SetNationFront($destnation['nation']); + SetNationFront($conquerNation); } pushGenLog($general, $log); diff --git a/twe/sammo/CityHelper.php b/twe/sammo/CityHelper.php index 991e7fba..14f5df72 100644 --- a/twe/sammo/CityHelper.php +++ b/twe/sammo/CityHelper.php @@ -23,7 +23,9 @@ class CityHelper{ $listByNation = []; 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; if(!key_exists($id, $listByNation)){ diff --git a/twe/sammo/Event/Action/ChangeCity.php b/twe/sammo/Event/Action/ChangeCity.php index 1ff2f5dd..849f5c57 100644 --- a/twe/sammo/Event/Action/ChangeCity.php +++ b/twe/sammo/Event/Action/ChangeCity.php @@ -152,13 +152,11 @@ class ChangeCity extends \sammo\Event\Action{ } public function run($env=null){ - - $target = $this->target; $cities = $this->getTargetCities($env); DB::db()->update('city', $this->queries - , 'city IN (%li)', $cities); + , 'city IN %li', $cities); return [__CLASS__, DB::db()->affectedRows()]; } diff --git a/twe/sammo/Event/Action/RaiseInvader.php b/twe/sammo/Event/Action/RaiseInvader.php index 62154903..c76ced4a 100644 --- a/twe/sammo/Event/Action/RaiseInvader.php +++ b/twe/sammo/Event/Action/RaiseInvader.php @@ -56,7 +56,7 @@ class RaiseInvader extends \sammo\Event\Action{ $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; $newCapital = $db->queryFirstRow('SELECT city from city where nation=%i and city !=%i \ order by rand() limit 1', $nation, $oldCapital); @@ -66,7 +66,7 @@ class RaiseInvader extends \sammo\Event\Action{ } $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; if($gen1 != 0) $generals[]=$gen1; if($gen2 != 0) $generals[]=$gen2; @@ -75,14 +75,14 @@ class RaiseInvader extends \sammo\Event\Action{ $db->update('general', [ 'level'=>1 - ], 'no in (%li)', $generals); + ], 'no in %li', $generals); $db->update('city', [ 'gen1'=>0, 'gen2'=>0, 'gen3'=>0, 'nation'=>0 - ], 'city in (%li)', $cities); + ], 'city in %li', $cities); } public function run($env=null){ diff --git a/twe/sammo/Event/Condition.php b/twe/sammo/Event/Condition.php index 0e7bedd9..05838684 100644 --- a/twe/sammo/Event/Condition.php +++ b/twe/sammo/Event/Condition.php @@ -2,10 +2,14 @@ namespace sammo\Event; abstract class Condition{ - public abstract function __construct($args=null); public abstract function eval($env=null); public static function build($conditionChain){ + + if(is_bool($conditionChain)){ + return new Condition\ConstBool($conditionChain); + } + if(!is_array($conditionChain)){ return $conditionChain; } diff --git a/twe/sammo/Event/Condition/ConstBool.php b/twe/sammo/Event/Condition/ConstBool.php index 89f64930..70d997ae 100644 --- a/twe/sammo/Event/Condition/ConstBool.php +++ b/twe/sammo/Event/Condition/ConstBool.php @@ -1,7 +1,7 @@ condition = Condition::build($rawCondition); foreach($rawActions as $rawAction){ - $this->condition = Action::build($rawAction); + $this->actions[] = Action::build($rawAction); } } diff --git a/twe/sammo/Scenario.php b/twe/sammo/Scenario.php index 1e61039e..56cb3f77 100644 --- a/twe/sammo/Scenario.php +++ b/twe/sammo/Scenario.php @@ -378,7 +378,7 @@ class Scenario{ refreshNationStaticInfo(); foreach(getAllNationStaticInfo() as $nation){ - SetNationFront($db->get(), $nation['nation']); + SetNationFront($nation['nation']); } } diff --git a/twe/sammo/Scenario/NPC.php b/twe/sammo/Scenario/NPC.php index f40de269..1b8f3b8f 100644 --- a/twe/sammo/Scenario/NPC.php +++ b/twe/sammo/Scenario/NPC.php @@ -96,7 +96,7 @@ class NPC{ $picture = 'default.jpg'; } - $city = $this->city; + $city = $this->locatedCity; if($city === null){ if($nationID == 0){ $city = Util::choiceRandom(CityHelper::getAllCities())['id']; @@ -117,9 +117,10 @@ class NPC{ $specage = $age + 1; $specage2 = $age + 1; + $npcID = $db->queryFirstField('SELECT max(npcid)+1 FROM general'); $db->insert('general',[ - 'npcid'=>$db->sqleval('max(npcid)+1'), + 'npcid'=>$npcID, 'npc'=>2, 'npc_org'=>2, 'affinity'=>$this->affinity, @@ -127,7 +128,7 @@ class NPC{ 'picture'=>$picture, 'nation'=>$nationID, 'city'=>$city, - 'leader'=>$this->leader, + 'leader'=>$this->leadership, 'power'=>$this->power, 'intel'=>$this->intel, 'experience'=>$experience, diff --git a/twe/sammo/Scenario/Nation.php b/twe/sammo/Scenario/Nation.php index 7cc8c0cf..38ee5a62 100644 --- a/twe/sammo/Scenario/Nation.php +++ b/twe/sammo/Scenario/Nation.php @@ -59,7 +59,7 @@ class Nation{ }, $this->cities); $capital = \sammo\CityHelper::getCityByName($this->capital)['id']; - $type = \sammo\NationCharCall($this->$type); + $type = \sammo\NationCharCall($this->type); $db = DB::db(); $otherNations = $db->queryFirstColumn('SELECT nation FROM nation'); @@ -81,29 +81,32 @@ class Nation{ 'scoutmsg'=>$this->infoText, 'tech'=>$this->tech, 'totaltech'=>0, - 'level'=>$this->level, + 'level'=>$this->nationLevel, 'type'=>$type, ]); $db->update('city', [ 'nation'=>$this->id - ], 'city IN (%li)', $cities); + ], 'city IN %li', $cities); $diplomacy = []; foreach($otherNations as $nation){ $diplomacy[] = [ - 'me'=>$this->$id, + 'me'=>$this->id, 'you'=>$nation, 'state'=>2 ]; $diplomacy[] = [ 'me'=>$nation, - 'you'=>$this->$id, + 'you'=>$this->id, 'state'=>2 ]; } - $db->insert('diplomacy', $diplomacy); + if(count($diplomacy) > 0){ + $db->insert('diplomacy', $diplomacy); + } + } public function postBuild($env=[]){