feat: 시나리오 event 포맷에서 target, priority 추가

This commit is contained in:
2022-02-05 07:43:27 +00:00
committed by Gitea
parent 5a675ad048
commit ce2f97e738
10 changed files with 73 additions and 46 deletions
+54 -40
View File
@@ -19,7 +19,7 @@ class Scenario{
private $title; private $title;
private $history; private $history;
/** @var \sammo\Scenario\Nation[] */ /** @var \sammo\Scenario\Nation[] */
private $nations; private $nations;
/** @var \sammo\Scenario\Nation[] */ /** @var \sammo\Scenario\Nation[] */
@@ -52,7 +52,7 @@ class Scenario{
} }
list( list(
$affinity, $name, $picturePath, $nationName, $locatedCity, $affinity, $name, $picturePath, $nationName, $locatedCity,
$leadership, $strength, $intel, $officerLevel, $birth, $death, $ego, $leadership, $strength, $intel, $officerLevel, $birth, $death, $ego,
$char, $text $char, $text
) = $rawGeneral; ) = $rawGeneral;
@@ -70,9 +70,9 @@ class Scenario{
$this->tmpGeneralQueue[$name] = $rawGeneral; $this->tmpGeneralQueue[$name] = $rawGeneral;
$obj = (new Scenario\GeneralBuilder( $obj = (new Scenario\GeneralBuilder(
$name, $name,
false, false,
$picturePath, $picturePath,
$nationID $nationID
)); ));
if(!$initFull){ if(!$initFull){
@@ -110,22 +110,22 @@ class Scenario{
$this->nations = []; $this->nations = [];
$this->nations[0] = $neutralNation; $this->nations[0] = $neutralNation;
$this->nationsInv = [$neutralNation->getName() => $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;
$nation = new Scenario\Nation( $nation = new Scenario\Nation(
$nationID, $nationID,
$name, $name,
$color, $color,
$gold, $gold,
$rice, $rice,
$infoText, $infoText,
$tech, $tech,
$type, $type,
$nationLevel, $nationLevel,
$cities $cities
); );
$this->nations[$nationID] = $nation; $this->nations[$nationID] = $nation;
@@ -134,7 +134,7 @@ class Scenario{
$this->diplomacy = Util::array_get($data['diplomacy'], []); $this->diplomacy = Util::array_get($data['diplomacy'], []);
$this->generals = array_map(function($rawGeneral){ $this->generals = array_map(function($rawGeneral){
return $this->generateGeneral($rawGeneral, false, 2); return $this->generateGeneral($rawGeneral, false, 2);
}, Util::array_get($data['general'], [])); }, Util::array_get($data['general'], []));
@@ -166,22 +166,22 @@ class Scenario{
$this->nations = []; $this->nations = [];
$this->nations[0] = $neutralNation; $this->nations[0] = $neutralNation;
$this->nationsInv = [$neutralNation->getName() => $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;
$nation = new Scenario\Nation( $nation = new Scenario\Nation(
$nationID, $nationID,
$name, $name,
$color, $color,
$gold, $gold,
$rice, $rice,
$infoText, $infoText,
$tech, $tech,
$type, $type,
$nationLevel, $nationLevel,
$cities $cities
); );
$this->nations[$nationID] = $nation; $this->nations[$nationID] = $nation;
@@ -190,7 +190,7 @@ class Scenario{
$this->diplomacy = Util::array_get($data['diplomacy'], []); $this->diplomacy = Util::array_get($data['diplomacy'], []);
$this->generals = array_map(function($rawGeneral){ $this->generals = array_map(function($rawGeneral){
return $this->generateGeneral($rawGeneral, true, 2); return $this->generateGeneral($rawGeneral, true, 2);
}, Util::array_get($data['general'], [])); }, Util::array_get($data['general'], []));
@@ -211,12 +211,22 @@ class Scenario{
$this->events = array_map(function($rawEvent){ $this->events = array_map(function($rawEvent){
//event는 여기서 풀지 않는다. 평가만 한다. //event는 여기서 풀지 않는다. 평가만 한다.
$cond = $rawEvent[0]; $target = $rawEvent[0];
$action = array_slice($rawEvent, 1); if(is_string($target)){
throw new \RuntimeException("{$target}이 문자열이 아님");
}
$priority = $rawEvent[1];
if(is_int($priority)){
throw new \RuntimeException("{$priority}가 정수가 아님");
}
$cond = $rawEvent[2];
$action = array_slice($rawEvent, 3);
new \sammo\Event\EventHandler($cond, $action); new \sammo\Event\EventHandler($cond, $action);
return [ return [
'target' => $target,
'priority' => $priority,
'cond' => $cond, 'cond' => $cond,
'action' => $action 'action' => $action
]; ];
@@ -310,7 +320,7 @@ class Scenario{
$this->initLite(); $this->initLite();
return $this->nations; return $this->nations;
} }
public function getMapTheme(){ public function getMapTheme(){
return $this->gameConf['mapName']; return $this->gameConf['mapName'];
} }
@@ -377,7 +387,7 @@ class Scenario{
private function buildGenerals($env){ private function buildGenerals($env){
$this->initFull(); $this->initFull();
try{ try{
$text = \file_get_contents(ServConfig::getSharedIconPath('../hook/list.json?1')); $text = \file_get_contents(ServConfig::getSharedIconPath('../hook/list.json?1'));
$storedIcons = Json::decode($text); $storedIcons = Json::decode($text);
@@ -398,7 +408,7 @@ class Scenario{
} }
$rawGeneral = $this->tmpGeneralQueue[$general->getGeneralRawName()]; $rawGeneral = $this->tmpGeneralQueue[$general->getGeneralRawName()];
$birth = $general->getBirthYear(); $birth = $general->getBirthYear();
if(!key_exists($birth, $remainGenerals)){ if(!key_exists($birth, $remainGenerals)){
$remainGenerals[$birth] = []; $remainGenerals[$birth] = [];
} }
@@ -432,13 +442,13 @@ class Scenario{
} }
$rawGeneral = $this->tmpGeneralQueue[$general->getGeneralRawName()]; $rawGeneral = $this->tmpGeneralQueue[$general->getGeneralRawName()];
$birth = $general->getBirthYear(); $birth = $general->getBirthYear();
if(!key_exists($birth, $remainGenerals)){ if(!key_exists($birth, $remainGenerals)){
$remainGenerals[$birth] = []; $remainGenerals[$birth] = [];
} }
$remainGenerals[$birth][] = array_merge(['RegNeutralNPC'], $rawGeneral); $remainGenerals[$birth][] = array_merge(['RegNeutralNPC'], $rawGeneral);
} }
return $remainGenerals; return $remainGenerals;
} }
@@ -508,7 +518,7 @@ class Scenario{
$nation->build($env); $nation->build($env);
} }
refreshNationStaticInfo(); refreshNationStaticInfo();
CityHelper::flushCache(); CityHelper::flushCache();
@@ -519,6 +529,8 @@ class Scenario{
$actions[] = ['DeleteEvent']; $actions[] = ['DeleteEvent'];
$this->events[] = [ $this->events[] = [
'target'=>'Month',
'priority'=>1000,
'cond'=>['Date', '>=', $targetYear, '1'], 'cond'=>['Date', '>=', $targetYear, '1'],
'action'=>$actions 'action'=>$actions
]; ];
@@ -540,6 +552,8 @@ class Scenario{
$events = array_map(function($rawEvent){ $events = array_map(function($rawEvent){
return [ return [
'target'=>$rawEvent['target'],
'priority'=>$rawEvent['priority'],
'condition'=>Json::encode($rawEvent['cond']), 'condition'=>Json::encode($rawEvent['cond']),
'action'=>Json::encode($rawEvent['action']) 'action'=>Json::encode($rawEvent['action'])
]; ];
@@ -549,7 +563,7 @@ class Scenario{
$db->insert('event', $events); $db->insert('event', $events);
} }
pushGlobalHistoryLog($this->history, $env['year'], $env['month']); pushGlobalHistoryLog($this->history, $env['year'], $env['month']);
@@ -568,7 +582,7 @@ class Scenario{
foreach(glob(self::SCENARIO_PATH.'/scenario_*.json') as $scenarioPath){ foreach(glob(self::SCENARIO_PATH.'/scenario_*.json') as $scenarioPath){
$scenarioName = pathinfo(basename($scenarioPath), PATHINFO_FILENAME); $scenarioName = pathinfo(basename($scenarioPath), PATHINFO_FILENAME);
$scenarioIdx = Util::array_last(explode('_', $scenarioName)); $scenarioIdx = Util::array_last(explode('_', $scenarioName));
if(!is_numeric($scenarioIdx)){ if(!is_numeric($scenarioIdx)){
continue; continue;
} }
+2
View File
@@ -8,11 +8,13 @@
}, },
"events":[ "events":[
[ [
"month", 1000,
["or", ["Date", "==", null, 12], ["Date", "==", null, 6]], ["or", ["Date", "==", null, 12], ["Date", "==", null, 6]],
["CreateManyNPC", 10, 10], ["CreateManyNPC", 10, 10],
["DeleteEvent"] ["DeleteEvent"]
], ],
[ [
"month", 1000,
["Date", "==", 181, 1], ["Date", "==", 181, 1],
["RaiseNPCNation"], ["RaiseNPCNation"],
["DeleteEvent"] ["DeleteEvent"]
+2
View File
@@ -11,11 +11,13 @@
}, },
"events":[ "events":[
[ [
"month", 1000,
["or", ["Date", "==", null, 12], ["Date", "==", null, 6]], ["or", ["Date", "==", null, 12], ["Date", "==", null, 6]],
["CreateManyNPC", 10, 10], ["CreateManyNPC", 10, 10],
["DeleteEvent"] ["DeleteEvent"]
], ],
[ [
"month", 1000,
["Date", "==", 181, 1], ["Date", "==", 181, 1],
["RaiseNPCNation"], ["RaiseNPCNation"],
["DeleteEvent"] ["DeleteEvent"]
+2 -2
View File
@@ -12,7 +12,7 @@
]], ]],
["황건적", "#FFD700", 10000, 10000, "황건적", 500, "태평도", 2, [ ["황건적", "#FFD700", 10000, 10000, "황건적", 500, "태평도", 2, [
"업","계교","진류","관도","정도","평원","복양","패","허창","초" "업","계교","진류","관도","정도","평원","복양","패","허창","초"
]] ]]
], ],
"diplomacy":[ "diplomacy":[
], ],
@@ -703,7 +703,7 @@
], ],
"history":[ "history":[
"<C>●</>184년 1월:<L><b>【역사모드1】</b></>황건적의 난", "<C>●</>184년 1월:<L><b>【역사모드1】</b></>황건적의 난",
"<C>●</>184년 1월:<Y><b>【황건적】</b></>전국 각지에서 황건적이 들고 일어서고 있습니다." "<C>●</>184년 1월:<Y><b>【황건적】</b></>전국 각지에서 황건적이 들고 일어서고 있습니다."
], ],
"initialEvents":[ "initialEvents":[
[ [
+2 -2
View File
@@ -20,7 +20,7 @@
"진류" "진류"
]], ]],
["유언", "#483D8B", 10000, 10000, "익주 주자사 유언", 1000, "유가", 3, [ ["유언", "#483D8B", 10000, 10000, "익주 주자사 유언", 1000, "유가", 3, [
"성도", "면죽", "자동", "강주" "성도", "면죽", "자동", "강주"
]], ]],
["원술", "#FFC0CB", 10000, 10000, "4세 5공 명문 혈통 원소의 사촌 원술", 1000, "병가", 2, [ ["원술", "#FFC0CB", 10000, 10000, "4세 5공 명문 혈통 원소의 사촌 원술", 1000, "병가", 2, [
"완" "완"
@@ -67,7 +67,7 @@
["공주", "#800080", 10000, 10000, "공주", 1000, "도가", 3, [ ["공주", "#800080", 10000, 10000, "공주", 1000, "도가", 3, [
"초" "초"
]] ]]
], ],
"diplomacy":[ "diplomacy":[
[1, 2, 1, 36], [1, 2, 1, 36],
+2 -2
View File
@@ -8,8 +8,8 @@
}, },
"nation":[ "nation":[
["조조", "#000080", 10000, 10000, "하북을 제패하고 대군을 이끌고 남하하는 조조", 1000, "병가", 6, [ ["조조", "#000080", 10000, 10000, "하북을 제패하고 대군을 이끌고 남하하는 조조", 1000, "병가", 6, [
"허창", "역경", "계교", "관도", "호관", "정도", "호로", "사곡", "함곡", "사수", "서주", "계", "허창", "역경", "계교", "관도", "호관", "정도", "호로", "사곡", "함곡", "사수", "서주", "계",
"북평", "진양", "남피", "평원", "하내", "업", "북해", "복양", "장안", "홍농", "낙양", "진류", "북평", "진양", "남피", "평원", "하내", "업", "북해", "복양", "장안", "홍농", "낙양", "진류",
"패", "초", "하비", "완", "여남", "수춘", "신야", "양양", "강릉", "장판" "패", "초", "하비", "완", "여남", "수춘", "신야", "양양", "강릉", "장판"
]], ]],
["손권", "#FF0000", 10000, 10000, "조조의 남하에 유비와 불가침으로 맞서는 손권", 1000, "덕가", 4, [ ["손권", "#FF0000", 10000, 10000, "조조의 남하에 유비와 불가침으로 맞서는 손권", 1000, "덕가", 4, [
+2
View File
@@ -15,11 +15,13 @@
}, },
"events":[ "events":[
[ [
"month", 1000,
["or", ["Date", "==", null, 12], ["Date", "==", null, 6]], ["or", ["Date", "==", null, 12], ["Date", "==", null, 6]],
["CreateManyNPC", 10, 10], ["CreateManyNPC", 10, 10],
["DeleteEvent"] ["DeleteEvent"]
], ],
[ [
"month", 1000,
["Date", "==", 181, 1], ["Date", "==", 181, 1],
["RaiseNPCNation"], ["RaiseNPCNation"],
["DeleteEvent"] ["DeleteEvent"]
+2
View File
@@ -99,11 +99,13 @@
], ],
"events":[ "events":[
[ [
"month", 1000,
["or", ["Date", "==", null, 12], ["Date", "==", null, 6]], ["or", ["Date", "==", null, 12], ["Date", "==", null, 6]],
["CreateManyNPC", 10, 10], ["CreateManyNPC", 10, 10],
["DeleteEvent"] ["DeleteEvent"]
], ],
[ [
"month", 1000,
["Date", "==", 181, 1], ["Date", "==", 181, 1],
["RaiseNPCNation"], ["RaiseNPCNation"],
["DeleteEvent"] ["DeleteEvent"]
+3
View File
@@ -59,11 +59,13 @@
}, },
"events":[ "events":[
[ [
"month", 1000,
["Date", "==", null, 12], ["Date", "==", null, 12],
["CreateManyNPC", 10, 10], ["CreateManyNPC", 10, 10],
["DeleteEvent"] ["DeleteEvent"]
], ],
[ [
"month", 1000,
["Date", "==", 182, 1], ["Date", "==", 182, 1],
["ChangeCity", "occupied", { ["ChangeCity", "occupied", {
"trade":100 "trade":100
@@ -71,6 +73,7 @@
["DeleteEvent"] ["DeleteEvent"]
], ],
[ [
"month", 1000,
["Date", "==", 182, 7], ["Date", "==", 182, 7],
["ChangeCity", "occupied", { ["ChangeCity", "occupied", {
"trade":100 "trade":100
+2
View File
@@ -11,11 +11,13 @@
], ],
"events": [ "events": [
[ [
"month", 1000,
["Date", "==", null, 12], ["Date", "==", null, 12],
["CreateManyNPC", 100, 0], ["CreateManyNPC", 100, 0],
["DeleteEvent"] ["DeleteEvent"]
], ],
[ [
"month", 1000,
["Date", "==", 181, 12], ["Date", "==", 181, 12],
["ChangeCity", "occupied", { ["ChangeCity", "occupied", {
"pop": "+60000", "pop": "+60000",