CityHelper 추가

This commit is contained in:
2018-03-28 19:14:11 +09:00
parent 78a1ca3651
commit 907ba0b26e
2 changed files with 75 additions and 0 deletions
+1
View File
@@ -240,6 +240,7 @@ function SpecCall($call) {
case '의술': $type = 73; break;
case '격노': $type = 74; break;
case '척사': $type = 75; break;
default: $type = 0; break;
}
return $type;
}
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace sammo\Scenario;
use \sammo\DB;
class CityHelper{
//Just Helper
private static $list = null;
private static $listInv = null;
private static $listByNation = null;
private function __construct(){
}
public static function flushCache(){
self::$list = null;
self::$listInv = null;
self::$listByNation = null;
}
public static function generateCache(){
$list = [];
$listInv = [];
$listByNation = [];
foreach (DB::db()->query('SELECT `city` as `id`, `name`, `level`, `nation` from city') as $city) {
$list[$city['id']] = $city;
$listInv[$city['name']] = $city;
if(!key_exists($id, $listByNation)){
$listByNation[$id] = [];
}
$listByNation[$id][] = $city;
}
self::$list = $list;
self::$listInv = $listInv;
self::$listByNation = $listByNation;
}
public static function getAllCities(){
if(self::$list === null){
self::generateCache();
}
return self::$list;
}
public static function getAllNationCities(int $nationID){
if(self::$listByNation === null){
self::generateCache();
}
return self::$listByNation[$nationID];
}
public static function getCity(int $cityID){
if(self::$list === null){
self::generateCache();
}
return self::$list[$cityID];
}
public static function getCityByName(string $cityName){
if(self::$listInv === null){
self::generateCache();
}
return self::$listInv[$cityName];
}
}