build 전까진 실제 장수를 알 수 없는 점 보완

This commit is contained in:
2018-03-29 01:23:58 +09:00
parent 7f01e90573
commit fd0f5edfe3
2 changed files with 53 additions and 27 deletions
+35 -7
View File
@@ -79,7 +79,7 @@ class Scenario{
$this->tmpGeneralQueue[$name] = $rawGeneral; $this->tmpGeneralQueue[$name] = $rawGeneral;
$general = new Scenario\NPC( return new Scenario\NPC(
$affinity, $affinity,
$name, $name,
$pictureID, $pictureID,
@@ -94,8 +94,6 @@ class Scenario{
$char, $char,
$text $text
); );
$this->nations[$nationID]->addNPC($general);
}, Util::array_get($data['general'], [])); }, Util::array_get($data['general'], []));
$this->generalsEx = array_map(function($rawGeneral){ $this->generalsEx = array_map(function($rawGeneral){
@@ -115,7 +113,7 @@ class Scenario{
$this->tmpGeneralQueue[$name] = $rawGeneral; $this->tmpGeneralQueue[$name] = $rawGeneral;
$general = new Scenario\NPC( return new Scenario\NPC(
$affinity, $affinity,
$name, $name,
$pictureID, $pictureID,
@@ -131,7 +129,6 @@ class Scenario{
$text $text
); );
$this->nations[$nationID]->addNPC($general, true);
}, Util::array_get($data['generalEx'], [])); }, Util::array_get($data['generalEx'], []));
$this->initialEvents = array_map(function($rawEvent){ $this->initialEvents = array_map(function($rawEvent){
@@ -232,14 +229,40 @@ class Scenario{
public function getScenarioBrief(){ public function getScenarioBrief(){
$nations = []; $nations = [];
$nationGeneralCnt = [];
$nationGeneralExCnt = [];
foreach($this->generals as $general){
$nationID = $general->nationID;
if(!key_exists($nationID, $nationGeneralCnt)){
$nationGeneralCnt[$nationID] = 1;
}
else{
$nationGeneralCnt[$nationID] += 1;
}
}
foreach($this->generalsEx as $general){
$nationID = $general->nationID;
if(!key_exists($nationID, $nationGeneralExCnt)){
$nationGeneralExCnt[$nationID] = 1;
}
else{
$nationGeneralExCnt[$nationID] += 1;
}
}
return [ return [
'year'=>$this->getYear(), 'year'=>$this->getYear(),
'title'=>$this->getTitle(), 'title'=>$this->getTitle(),
'npc_cnt'=>count($this->getNPC()), 'npc_cnt'=>count($this->getNPC()),
'npcEx_cnt'=>count($this->getNPCex()), 'npcEx_cnt'=>count($this->getNPCex()),
'nation'=>array_map(function($nation){ 'nation'=>array_map(function($nation) use ($nationGeneralCnt, $nationGeneralExCnt){
return $nation->getBrief(); $brief = $nation->getBrief();
$brief['generals'] = Util::array_get($nationGeneralCnt[$nation->getID()], 0);
$brief['generalsEx'] = Util::array_get($nationGeneralExCnt[$nation->getID()], 0);
return $brief;
},$this->getNation()) },$this->getNation())
]; ];
} }
@@ -339,6 +362,11 @@ class Scenario{
}, $this->events); }, $this->events);
$db->insert('event', $this->events); $db->insert('event', $this->events);
refreshNationStaticInfo();
foreach(getAllNationStaticInfo() as $nation){
SetNationFront($connect, $nation['nation']);
}
} }
/** /**
+18 -20
View File
@@ -17,8 +17,6 @@ class Nation{
private $capital; private $capital;
private $cities = []; private $cities = [];
private $generals = [];
private $generalsEx = [];
public function __construct( public function __construct(
int $id = null, int $id = null,
@@ -50,22 +48,12 @@ class Nation{
$this->id = $id; $this->id = $id;
} }
public function addNPC(NPC $npc, bool $isExtend=false){ public function getID(){
if($isExtend){ return $this->id;
$this->generalsEx[] = $npc;
}
else{
$this->generals[] = $npc;
}
} }
public function build($env=[]){ public function build($env=[]){
$npc_cnt = count($this->generals); //NOTE: NPC의 숫자는 아직 확정된 것이 아니다.
if($env['useExtentedGeneral']){
$npc_cnt += count($this->generalsEx);
}
$cities = array_map(function($cityName){ $cities = array_map(function($cityName){
return \sammo\CityHelper::getCityByName($cityName)['id']; return \sammo\CityHelper::getCityByName($cityName)['id'];
}, $this->cities); }, $this->cities);
@@ -81,7 +69,7 @@ class Nation{
'name'=>$this->name, 'name'=>$this->name,
'color'=>$this->color, 'color'=>$this->color,
'capital'=>$capital, 'capital'=>$capital,
'gennum'=>$npc_cnt, 'gennum'=>0,
'gold'=>$this->gold, 'gold'=>$this->gold,
'rice'=>$this->rice, 'rice'=>$this->rice,
'bill'=>100, 'bill'=>100,
@@ -92,7 +80,7 @@ class Nation{
'surlimit'=>72, 'surlimit'=>72,
'scoutmsg'=>$this->infoText, 'scoutmsg'=>$this->infoText,
'tech'=>$this->tech, 'tech'=>$this->tech,
'totaltech'=>$this->tech*$npc_cnt, 'totaltech'=>0,
'level'=>$this->level, 'level'=>$this->level,
'type'=>$type, 'type'=>$type,
]); ]);
@@ -118,6 +106,18 @@ class Nation{
$db->insert('diplomacy', $diplomacy); $db->insert('diplomacy', $diplomacy);
} }
public function postBuild($env=[]){
$npc_cnt = count($this->generals);
if($env['useExtentedGeneral']){
$npc_cnt += count($this->generalsEx);
}
$db->update('nation', [
'gennum'=>$npc_cnt,
'totaltech'=>$this->tech*$npc_cnt
], 'nation=%i', $this->id);
}
public function getBrief(){ public function getBrief(){
return [ return [
'id'=>$this->id, 'id'=>$this->id,
@@ -129,9 +129,7 @@ class Nation{
'tech'=>$this->tech, 'tech'=>$this->tech,
'type'=>$this->type, 'type'=>$this->type,
'nationLevel'=>$this->nationLevel, 'nationLevel'=>$this->nationLevel,
'cities'=>$this->cities, 'cities'=>$this->cities
'generals'=>count($this->generals),
'generalsEx'=>count($this->generalsEx)
]; ];
} }
} }