Files
core/twe/func_map.php
T
Hide_D 75fb281264 func_map.php를 통해 현재 지도 값을 받아오는 코드 추가
j_map.php를 통해 지도를 json 형태로 열람하는 코드 추가

연감의 저장코드를 http를 통해 지도를 받아오는 방식에서 func_map.php를 이용하는 방식으로 변경

map.js에서 반환값이 올바른지 확인하는 코드 추가

b_CurrentCity.php의 도시 정보 값을 get으로도 받을 수 있도록 변경

map.js에서 재야 상태일때 올바르게 처리하도록 변경
2018-02-02 09:36:14 +09:00

130 lines
3.4 KiB
PHP

<?php
class MapRequest{
public $year;
public $month;
public $aux;
public $neutralView;
public $showMe;
function __construct($obj){
$this->year = $obj['year'];
$this->month = $obj['month'];
$this->aux = $obj['aux'];
$this->neutralView = $obj['neutralView'];
$this->showMe = $obj['showMe'];
}
}
/**
* @param int $year
* @param int $month
* @return mixed
*/
function getHistoryMap($year, $month){
if(!$year || !$month){
return ['result'=>false, 'reason'=>'연 월이 지정되지 않음'];
}
$map = getDB()->queryFirstField('select map from history where year=%i and month=%i',
$year,
$month);
if(!$map){
return ['result'=>false, 'reason'=>'연감이 저장되지 않음'];
}
return json_decode($map, true);//까짓거 json_decode, json_encode 두번하지 뭐.
}
/**
* @param MapRequest|array $req
* @return mixed
*/
function getWorldMap($req){
if(is_array($req)){
$req = new MapRequest($req);
}
if($req->year && $req->month){
return getHistoryMap($req->year, $req->month);
}
$generalID = getGeneralID();
$db = getDB();
$game = $db->queryFirstRow('select `startyear`, `year`, `month` from `game` where `no` = 1');
$startYear = intval($game['startyear']);
$year = intval($game['year']);
$month = intval($game['month']);
if($generalID && ($req->showMe || $req->neutralView)){
$city = $db->queryFirstRow(
'select `city`, `nation` from `general` where `user_id`=%i',
$generalID);
$myCity = intval($city['city']);
$myNation = intval($city['nation']);
if(!$req->showMe){
$myCity = null;
}
if(!$req->neutralView){
$myNation = null;
}
}
else{
$myCity = null;
$myNation = null;
}
if($myNation){
$spyList = $db->queryFirstField('select `spy` from `nation` where `nation`=%i',
$myNation);
$spyList = array_map('intval', explode("|", $spyList));
}
else{
$spyList = [];
}
$nationList = [];
foreach($db->query('select `nation`, `name`, `color`, `capital` from `nation`') as $row){
$nationList[] = [
intval($row['nation']),
$row['name'],
$row['color'],
intval($row['capital'])
];
}
if($myNation){
//굳이 타국 도시에 있는 아국 장수 리스트를 뽑을 이유가 없음. 일단 다 뽑자.
$shownByGeneralList =
array_map('intval',
$db->queryFirstColumn('select distinct `city` from `general` where `nation` = %i',
$myNation));
}
else{
$shownByGeneralList = [];
}
$cityList = [];
foreach($db->query('select `city`, `level`, `state`, `nation`, `region`, `supply` from `city`') as $r){
$cityList[] =
array_map('intval', [$r['city'], $r['level'], $r['state'], $r['nation'], $r['region'], $r['supply']]);
}
return [
'startYear' => $startYear,
'year' => $year,
'month' => $month,
'cityList' => $cityList,
'nationList' => $nationList,
'spyList' => $spyList,
'shownByGeneralList' => $shownByGeneralList,
'myCity' => $myCity,
'myNation' => $myNation,
'result' => true
];
}