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;
$general = new Scenario\NPC(
return new Scenario\NPC(
$affinity,
$name,
$pictureID,
@@ -94,8 +94,6 @@ class Scenario{
$char,
$text
);
$this->nations[$nationID]->addNPC($general);
}, Util::array_get($data['general'], []));
$this->generalsEx = array_map(function($rawGeneral){
@@ -115,7 +113,7 @@ class Scenario{
$this->tmpGeneralQueue[$name] = $rawGeneral;
$general = new Scenario\NPC(
return new Scenario\NPC(
$affinity,
$name,
$pictureID,
@@ -131,7 +129,6 @@ class Scenario{
$text
);
$this->nations[$nationID]->addNPC($general, true);
}, Util::array_get($data['generalEx'], []));
$this->initialEvents = array_map(function($rawEvent){
@@ -232,14 +229,40 @@ class Scenario{
public function getScenarioBrief(){
$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 [
'year'=>$this->getYear(),
'title'=>$this->getTitle(),
'npc_cnt'=>count($this->getNPC()),
'npcEx_cnt'=>count($this->getNPCex()),
'nation'=>array_map(function($nation){
return $nation->getBrief();
'nation'=>array_map(function($nation) use ($nationGeneralCnt, $nationGeneralExCnt){
$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())
];
}
@@ -339,6 +362,11 @@ class Scenario{
}, $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 $cities = [];
private $generals = [];
private $generalsEx = [];
public function __construct(
int $id = null,
@@ -50,22 +48,12 @@ class Nation{
$this->id = $id;
}
public function addNPC(NPC $npc, bool $isExtend=false){
if($isExtend){
$this->generalsEx[] = $npc;
}
else{
$this->generals[] = $npc;
}
public function getID(){
return $this->id;
}
public function build($env=[]){
$npc_cnt = count($this->generals);
if($env['useExtentedGeneral']){
$npc_cnt += count($this->generalsEx);
}
//NOTE: NPC의 숫자는 아직 확정된 것이 아니다.
$cities = array_map(function($cityName){
return \sammo\CityHelper::getCityByName($cityName)['id'];
}, $this->cities);
@@ -81,7 +69,7 @@ class Nation{
'name'=>$this->name,
'color'=>$this->color,
'capital'=>$capital,
'gennum'=>$npc_cnt,
'gennum'=>0,
'gold'=>$this->gold,
'rice'=>$this->rice,
'bill'=>100,
@@ -92,7 +80,7 @@ class Nation{
'surlimit'=>72,
'scoutmsg'=>$this->infoText,
'tech'=>$this->tech,
'totaltech'=>$this->tech*$npc_cnt,
'totaltech'=>0,
'level'=>$this->level,
'type'=>$type,
]);
@@ -118,6 +106,18 @@ class Nation{
$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(){
return [
'id'=>$this->id,
@@ -129,9 +129,7 @@ class Nation{
'tech'=>$this->tech,
'type'=>$this->type,
'nationLevel'=>$this->nationLevel,
'cities'=>$this->cities,
'generals'=>count($this->generals),
'generalsEx'=>count($this->generalsEx)
'cities'=>$this->cities
];
}
}