시나리오 json 파일에서 받아오는 규격 확장

국가를 'string'으로 표기 가능하도록 변경
전콘 번호를 'string'으로 표기 가능하도록 변경
This commit is contained in:
2018-05-28 23:08:59 +09:00
parent 30e2432fc3
commit d9f6f7956e
5 changed files with 45 additions and 21 deletions
+2 -2
View File
@@ -9,7 +9,7 @@ class RegNPC extends \sammo\Event\Action{
public function __construct( public function __construct(
int $affinity, int $affinity,
string $name, string $name,
int $pictureID, $picturePath,
int $nationID, int $nationID,
$locatedCity, $locatedCity,
int $leadership, int $leadership,
@@ -24,7 +24,7 @@ class RegNPC extends \sammo\Event\Action{
$this->npc = new \sammo\Scenario\NPC( $this->npc = new \sammo\Scenario\NPC(
$affinity, $affinity,
$name, $name,
$pictureID, $picturePath,
$nationID, $nationID,
$locatedCity, $locatedCity,
$leadership, $leadership,
+28 -8
View File
@@ -15,6 +15,8 @@ class Scenario{
private $history; private $history;
private $nations; private $nations;
private $nationsInv;
private $diplomacy; private $diplomacy;
private $generals; private $generals;
@@ -36,13 +38,17 @@ class Scenario{
$this->initOK = true; $this->initOK = true;
$data = $this->data; $data = $this->data;
$neutralNation = new Scenario\Nation(0, '재야', '#000000', 0, 0);
$this->nations = []; $this->nations = [];
$this->nations[0] = new Scenario\Nation(0, '재야', '#000000', 0, 0); $this->nations[0] = $neutralNation;
$this->nationsInv = [$neutralNation->getName() => $neutralNation];
foreach (Util::array_get($data['nation'],[]) as $idx=>$rawNation) { foreach (Util::array_get($data['nation'],[]) as $idx=>$rawNation) {
list($name, $color, $gold, $rice, $infoText, $tech, $type, $nationLevel, $cities) = $rawNation; list($name, $color, $gold, $rice, $infoText, $tech, $type, $nationLevel, $cities) = $rawNation;
$nationID = $idx+1; $nationID = $idx+1;
$this->nations[$nationID] = new Scenario\Nation(
$nation = new Scenario\Nation(
$nationID, $nationID,
$name, $name,
$color, $color,
@@ -54,6 +60,8 @@ class Scenario{
$nationLevel, $nationLevel,
$cities $cities
); );
$this->nations[$nationID] = $nation;
$this->nationsInv[$nation->getName()] = $nation;
} }
$this->diplomacy = Util::array_get($data['diplomacy'], []); $this->diplomacy = Util::array_get($data['diplomacy'], []);
@@ -65,12 +73,18 @@ class Scenario{
} }
list( list(
$affinity, $name, $pictureID, $nationID, $locatedCity, $affinity, $name, $picturePath, $nationName, $locatedCity,
$leadership, $power, $intel, $level, $birth, $death, $ego, $leadership, $power, $intel, $level, $birth, $death, $ego,
$char, $text $char, $text
) = $rawGeneral; ) = $rawGeneral;
if(!key_exists($nationID, $this->nations)){ if(key_exists($nationName, $this->nationsInv)){
$nationID = $this->nationsInv[$nationName]->getID();
}
else if(key_exists($nationName, $this->nations)){
$nationID = (int)$nationName;
}
else{
$nationID = 0; $nationID = 0;
} }
@@ -79,7 +93,7 @@ class Scenario{
return new Scenario\NPC( return new Scenario\NPC(
$affinity, $affinity,
$name, $name,
$pictureID, $picturePath,
$nationID, $nationID,
$locatedCity, $locatedCity,
$leadership, $leadership,
@@ -100,12 +114,18 @@ class Scenario{
} }
list( list(
$affinity, $name, $pictureID, $nationID, $locatedCity, $affinity, $name, $picturePath, $nationName, $locatedCity,
$leadership, $power, $intel, $level, $birth, $death, $ego, $leadership, $power, $intel, $level, $birth, $death, $ego,
$char, $text $char, $text
) = $rawGeneral; ) = $rawGeneral;
if(!key_exists($nationID, $this->nations)){ if(key_exists($nationName, $this->nationsInv)){
$nationID = $this->nationsInv[$nationName]->id;;
}
else if(key_exists($nationName, $this->nations)){
$nationID = (int)$nationName;
}
else{
$nationID = 0; $nationID = 0;
} }
@@ -114,7 +134,7 @@ class Scenario{
return new Scenario\NPC( return new Scenario\NPC(
$affinity, $affinity,
$name, $name,
$pictureID, $picturePath,
$nationID, $nationID,
$locatedCity, $locatedCity,
$leadership, $leadership,
+9 -9
View File
@@ -8,7 +8,7 @@ class NPC{
public $affinity; public $affinity;
public $name; public $name;
public $pictureID; public $picturePath;
public $nationID; public $nationID;
public $locatedCity; public $locatedCity;
public $leadership; public $leadership;
@@ -26,7 +26,7 @@ class NPC{
public function __construct( public function __construct(
int $affinity, int $affinity,
string $name, string $name,
int $pictureID, $picturePath,
int $nationID, int $nationID,
$locatedCity, //FIXME: 7.1로 올릴 때 ?string 으로 변경 $locatedCity, //FIXME: 7.1로 올릴 때 ?string 으로 변경
int $leadership, int $leadership,
@@ -41,7 +41,7 @@ class NPC{
){ ){
$this->affinity = $affinity; $this->affinity = $affinity;
$this->name = $name; $this->name = $name;
$this->pictureID = $pictureID; $this->picturePath = $picturePath;
$this->nationID = $nationID; $this->nationID = $nationID;
$this->locatedCity = $locatedCity; $this->locatedCity = $locatedCity;
$this->leadership = $leadership; $this->leadership = $leadership;
@@ -142,12 +142,12 @@ class NPC{
$name = 'ⓝ'.$this->name; $name = 'ⓝ'.$this->name;
$pictureID = $this->pictureID; $picturePath = $this->picturePath;
if($env['show_img_level'] == 3 && $pictureID > 0){ if($env['show_img_level'] < 3){
$picture = "{$pictureID}.jpg"; $picturePath = 'default.jpg';
} }
else{ else if(is_numeric($picturePath)){
$picture = 'default.jpg'; $picturePath = "{$picturePath}.jpg";
} }
$city = $this->locatedCity; $city = $this->locatedCity;
@@ -187,7 +187,7 @@ class NPC{
'npc_org'=>2, 'npc_org'=>2,
'affinity'=>$affinity, 'affinity'=>$affinity,
'name'=>$name, 'name'=>$name,
'picture'=>$picture, 'picture'=>$picturePath,
'nation'=>$nationID, 'nation'=>$nationID,
'city'=>$city, 'city'=>$city,
'leader'=>$this->leadership, 'leader'=>$this->leadership,
+4
View File
@@ -55,6 +55,10 @@ class Nation{
return $this->id; return $this->id;
} }
public function getName(){
return $this->name;
}
public function build($env=[]){ public function build($env=[]){
//NOTE: NPC의 숫자는 아직 확정된 것이 아니다. //NOTE: NPC의 숫자는 아직 확정된 것이 아니다.
$cities = array_map(function($cityName){ $cities = array_map(function($cityName){
+2 -2
View File
@@ -18,7 +18,7 @@ CREATE TABLE `general` (
`refresh` INT(6) NULL DEFAULT '0', `refresh` INT(6) NULL DEFAULT '0',
`logcnt` INT(6) NULL DEFAULT '1', `logcnt` INT(6) NULL DEFAULT '1',
`refcnt` INT(6) NULL DEFAULT '1', `refcnt` INT(6) NULL DEFAULT '1',
`picture` CHAR(32) NOT NULL, `picture` VARCHAR(40) NOT NULL,
`imgsvr` INT(1) NULL DEFAULT '0', `imgsvr` INT(1) NULL DEFAULT '0',
`name` CHAR(32) NOT NULL COLLATE 'utf8mb4_bin', `name` CHAR(32) NOT NULL COLLATE 'utf8mb4_bin',
`name2` CHAR(32) NULL DEFAULT NULL COLLATE 'utf8mb4_bin', `name2` CHAR(32) NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
@@ -370,7 +370,7 @@ create table if not exists hall (
nation char(12) default '', nation char(12) default '',
data int(5) default 0, data int(5) default 0,
color char(12) default '', color char(12) default '',
picture char(32) default '', picture varchar(40) default '',
PRIMARY KEY (no), PRIMARY KEY (no),
UNIQUE INDEX `type` (`type`, `rank`) UNIQUE INDEX `type` (`type`, `rank`)