Scenario 세팅 과정에 문제 해결
SetNationFront 함수도 수정
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+27
-46
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace sammo;
|
||||
|
||||
/**
|
||||
* 게임 룰에 해당하는 함수 모음
|
||||
@@ -200,60 +200,41 @@ function addGenDex($connect, $no, $type, $exp) {
|
||||
|
||||
|
||||
//한국가의 전체 전방 설정
|
||||
function SetNationFront($connect, $nationNo) {
|
||||
function SetNationFront($nationNo) {
|
||||
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),"");
|
||||
$dipNum = MYDB_num_rows($result);
|
||||
if($dipNum > 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']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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),"");
|
||||
|
||||
+5
-5
@@ -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);
|
||||
|
||||
@@ -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)){
|
||||
|
||||
@@ -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()];
|
||||
}
|
||||
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace sammo\Event\Condition;
|
||||
|
||||
class ConstBool extends sammo\Event\Condition{
|
||||
class ConstBool extends \sammo\Event\Condition{
|
||||
private $fixedResult = true;
|
||||
|
||||
public function __construct(bool $value){
|
||||
|
||||
@@ -9,7 +9,7 @@ class EventHandler{
|
||||
public function __construct($rawCondition, $rawActions){
|
||||
$this->condition = Condition::build($rawCondition);
|
||||
foreach($rawActions as $rawAction){
|
||||
$this->condition = Action::build($rawAction);
|
||||
$this->actions[] = Action::build($rawAction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -378,7 +378,7 @@ class Scenario{
|
||||
|
||||
refreshNationStaticInfo();
|
||||
foreach(getAllNationStaticInfo() as $nation){
|
||||
SetNationFront($db->get(), $nation['nation']);
|
||||
SetNationFront($nation['nation']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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=[]){
|
||||
|
||||
Reference in New Issue
Block a user