시나리오 국가 설정 코드
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
namespace sammo\Scenario;
|
||||
use \sammo\DB;
|
||||
use \sammo\Util;
|
||||
namespace sammo;
|
||||
|
||||
class CityHelper{
|
||||
//Just Helper
|
||||
|
||||
+90
-11
@@ -9,7 +9,14 @@ class Scenario{
|
||||
|
||||
private $data;
|
||||
|
||||
private $year;
|
||||
private $title;
|
||||
|
||||
private $history;
|
||||
|
||||
private $nations;
|
||||
private $diplomacy;
|
||||
|
||||
private $generals;
|
||||
private $generalsEx;
|
||||
|
||||
@@ -22,18 +29,20 @@ class Scenario{
|
||||
$this->scenarioIdx = $scenarioIdx;
|
||||
$this->scenarioPath = $scenarioPath;
|
||||
|
||||
$this->data = Json::decode(file_get_contents($scenarioPath));
|
||||
$data = Json::decode(file_get_contents($scenarioPath));
|
||||
$this->data = $data;
|
||||
|
||||
$this->initialEvents = array_map(function($rawEvent){
|
||||
return new \sammo\Event\EventHandler($rawEvent[0], array_slice($rawEvent, 1));
|
||||
}, Util::array_get($this->data['initialEvents'], []));
|
||||
$this->year = Util::array_get($data['startYear']);
|
||||
$this->title = Util::array_get($data['title'] , '');
|
||||
|
||||
$this->history = Util::array_get($data['history'], []);
|
||||
|
||||
$this->nations = [];
|
||||
$this->nations[0] = new Scenario\Nation(0, '재야', '#ffffff', 0, 0);
|
||||
foreach (Util::array_get($this->data['nation'],[]) as $idx=>$nationRaw) {
|
||||
list($name, $color, $gold, $rice, $infoText, $tech, $type, $nationLevel, $cities) = $nationRaw;
|
||||
foreach (Util::array_get($data['nation'],[]) as $idx=>$rawNation) {
|
||||
list($name, $color, $gold, $rice, $infoText, $tech, $type, $nationLevel, $cities) = $rawNation;
|
||||
$nationID = $idx+1;
|
||||
|
||||
|
||||
$this->nations[$nationID] = new Scenario\Nation(
|
||||
$nationID,
|
||||
$name,
|
||||
@@ -47,6 +56,52 @@ class Scenario{
|
||||
$cities
|
||||
);
|
||||
}
|
||||
|
||||
$this->displomacy = Util::array_get($data['diplomacy'], []);
|
||||
|
||||
|
||||
$this->generals = array_map(function($rawGeneral){
|
||||
while(count($rawGeneral) < 14){
|
||||
$rawGeneral[] = null;
|
||||
}
|
||||
|
||||
list(
|
||||
$affinity, $name, $npcID, $nationID, $locatedCity,
|
||||
$leadership, $power, $intel, $birth, $death, $ego,
|
||||
$char, $text
|
||||
) = $rawGeneral;
|
||||
|
||||
if(!key_exists($nationID, $this->nations)){
|
||||
$nationID = 0;
|
||||
}
|
||||
|
||||
$general = new Scenario\NPC(
|
||||
$affinity,
|
||||
$name,
|
||||
$npcID,
|
||||
$nationID,
|
||||
$locatedCity,
|
||||
$leadership,
|
||||
$power,
|
||||
$intel,
|
||||
$birth,
|
||||
$death,
|
||||
$ego,
|
||||
$char,
|
||||
$text
|
||||
);
|
||||
|
||||
$this->nations[$nationID]->addNPC($general);
|
||||
}, Util::array_get($data['general'], []));
|
||||
|
||||
$this->initialEvents = array_map(function($rawEvent){
|
||||
return new \sammo\Event\EventHandler($rawEvent[0], array_slice($rawEvent, 1));
|
||||
}, Util::array_get($data['initialEvents'], []));
|
||||
|
||||
$this->events = array_map(function($rawEvent){
|
||||
return new \sammo\Event\EventHandler($rawEvent[0], array_slice($rawEvent, 1));
|
||||
}, Util::array_get($data['events'], []));
|
||||
|
||||
}
|
||||
|
||||
public function getScenarioIdx(){
|
||||
@@ -54,19 +109,19 @@ class Scenario{
|
||||
}
|
||||
|
||||
public function getYear(){
|
||||
return Util::array_get($this->data['startYear']);
|
||||
return $this->year;
|
||||
}
|
||||
|
||||
public function getTitle(){
|
||||
return Util::array_get($this->data['title']);
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function getNPC(){
|
||||
return Util::array_get($this->data['general']);
|
||||
return $this->generals;
|
||||
}
|
||||
|
||||
public function getNPCex(){
|
||||
return Util::array_get($this->data['general_ex']);
|
||||
return $this->generalsEx;
|
||||
}
|
||||
|
||||
public function getNation(){
|
||||
@@ -145,6 +200,30 @@ class Scenario{
|
||||
public function buildGame($env=[]){
|
||||
//NOTE: 초기화가 되어있다고 가정함.
|
||||
|
||||
|
||||
foreach($this->nations as $id=>$nation){
|
||||
if($id == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
$nation->build($env);
|
||||
}
|
||||
CityHelper::flushCache();
|
||||
foreach($this->generals as $general){
|
||||
$general->build($env);
|
||||
}
|
||||
|
||||
if($env['useExtentedGeneral']){
|
||||
foreach($this->generalsEx as $general){
|
||||
$general->build($env);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: 외교를 추가해야함
|
||||
foreach($this->initialEvents as $event){
|
||||
$event->tryRunEvent($env);
|
||||
}
|
||||
//TODO: event를 전역 handler에 등록해야함.
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,64 @@
|
||||
<?php
|
||||
namespace sammo\Scenario;
|
||||
use \sammo\Util;
|
||||
use \sammo\DB;
|
||||
use \sammo\CityHelper;
|
||||
|
||||
class NPC{
|
||||
|
||||
public $affinity;
|
||||
public $name;
|
||||
public $npcID;
|
||||
public $nationID;
|
||||
public $locatedCity;
|
||||
public $leadership;
|
||||
public $power;
|
||||
public $intel;
|
||||
public $birth;
|
||||
public $death;
|
||||
public $ego;
|
||||
public $charDomestic = 0;
|
||||
public $charWar = 0;
|
||||
public $text;
|
||||
|
||||
public function __construct(
|
||||
int $affinity,
|
||||
string $name,
|
||||
int $npcID,
|
||||
int $nationID,
|
||||
string $locatedCity,
|
||||
int $leadership,
|
||||
int $power,
|
||||
int $intel,
|
||||
int $birth = 150,
|
||||
int $death = 300,
|
||||
string $ego = null,
|
||||
string $char = null,
|
||||
string $text = null
|
||||
){
|
||||
$this->affinity = $affinity;
|
||||
$this->name = $name;
|
||||
$this->npcID = $npcID;
|
||||
$this->nationID = $nationID;
|
||||
$this->locatedCity = $locatedCity;
|
||||
$this->leadership = $leadership;
|
||||
$this->power = $power;
|
||||
$this->intel = $intel;
|
||||
$this->birth = $birth;
|
||||
$this->death = $death;
|
||||
$this->ego = $ego;
|
||||
$this->text = $text;
|
||||
|
||||
$char = \sammo\SpecCall($char);
|
||||
if($char < 40){
|
||||
$this->charDomestic = $char;
|
||||
}
|
||||
else{
|
||||
$this->charWar = $char;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function build($env=[]){
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
namespace sammo\Scenario;
|
||||
use \sammo\DB;
|
||||
use \sammo\Util;
|
||||
|
||||
class Nation{
|
||||
private $id;
|
||||
@@ -12,8 +14,11 @@ class Nation{
|
||||
private $type;
|
||||
private $nationLevel;
|
||||
|
||||
private $capital;
|
||||
|
||||
private $cities = [];
|
||||
private $generals = [];
|
||||
private $generalsEx = [];
|
||||
|
||||
public function __construct(
|
||||
int $id = null,
|
||||
@@ -27,14 +32,89 @@ class Nation{
|
||||
int $nationLevel = 0,
|
||||
array $cities = []
|
||||
){
|
||||
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->color = $color;
|
||||
$this->gold = $gold;
|
||||
$this->rice = $rice;
|
||||
$this->infoText = $infoText;
|
||||
$this->tech = $tech;
|
||||
$this->type = $type;
|
||||
$this->nationLevel = $nationLevel;
|
||||
$this->cities = $cities;
|
||||
|
||||
$this->capital = count($cities)>0?$cities[0]:null;
|
||||
}
|
||||
|
||||
public function setID(int $id){
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function build($env=[]){
|
||||
public function addNPC(NPC $npc, bool $isExtend=false){
|
||||
if($isExtend){
|
||||
$this->generalsEx[] = $npc;
|
||||
}
|
||||
else{
|
||||
$this->generals[] = $npc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function build($env=[]){
|
||||
$npc_cnt = count($this->generals);
|
||||
if($env['useExtentedGeneral']){
|
||||
$npc_cnt += count($this->generalsEx);
|
||||
}
|
||||
|
||||
$cities = array_map(function($cityName){
|
||||
return \sammo\CityHelper::getCityByName($cityName)['id'];
|
||||
}, $this->cities);
|
||||
$capital = \sammo\CityHelper::getCityByName($this->capital)['id'];
|
||||
|
||||
$type = \sammo\NationCharCall($this->$type);
|
||||
|
||||
$db = DB::db();
|
||||
$otherNations = $db->queryFirstColumn('SELECT nation FROM nation');
|
||||
|
||||
$db->insert('nation', [
|
||||
'nation'=>$this->id,
|
||||
'name'=>$this->name,
|
||||
'color'=>$this->color,
|
||||
'capital'=>$capital,
|
||||
'gennum'=>$npc_cnt,
|
||||
'gold'=>$this->gold,
|
||||
'rice'=>$this->rice,
|
||||
'bill'=>100,
|
||||
'rate'=>15,
|
||||
'scout'=>0,
|
||||
'war'=>0,
|
||||
'tricklimit'=>24,
|
||||
'surlimit'=>72,
|
||||
'scoutmsg'=>$this->infoText,
|
||||
'tech'=>$this->tech,
|
||||
'totaltech'=>$this->tech*$npc_cnt,
|
||||
'level'=>$this->level,
|
||||
'type'=>$type,
|
||||
]);
|
||||
|
||||
$db->update('city', [
|
||||
'nation'=>$this->id
|
||||
], 'city IN (%li)', $cities);
|
||||
|
||||
|
||||
$diplomacy = [];
|
||||
foreach($otherNations as $nation){
|
||||
$diplomacy[] = [
|
||||
'me'=>$this->$id,
|
||||
'you'=>$nation,
|
||||
'state'=>2
|
||||
];
|
||||
$diplomacy[] = [
|
||||
'me'=>$nation,
|
||||
'you'=>$this->$id,
|
||||
'state'=>2
|
||||
];
|
||||
}
|
||||
$db->insert('diplomacy', $diplomacy);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user