Scenario build 1차 완료
- NPC 생성 로직 수정 - 생성 안된 장수는 event로 넘김 - 완료된 event 삭제하는 action 추가
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
//1회용 event임을 의미함
|
||||
class DeleteEvent extends \sammo\Event\Action{
|
||||
|
||||
public function __construct(){
|
||||
}
|
||||
|
||||
public function run($env){
|
||||
|
||||
$eventID = \sammo\Util::array_get($env['currentEventID']);
|
||||
if(!$eventID){
|
||||
throw new \RuntimeException('currentEventID가 지정되지 않았습니다.');
|
||||
//NOTE: 이걸 에러 내야할지 아닐지는 아직 판단 필요
|
||||
}
|
||||
$db = \sammo\DB::db();
|
||||
$db->delete('event', 'id = %i', $eventID);
|
||||
return [__CLASS__, $db->affectedRows()];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
//이전 RegNPC 함수를 EventAction으로 재구성
|
||||
class RegNPC extends \sammo\Event\Action{
|
||||
|
||||
private $npc;
|
||||
|
||||
public function __construct(
|
||||
int $affinity,
|
||||
string $name,
|
||||
int $pictureID,
|
||||
int $nationID,
|
||||
string $locatedCity,
|
||||
int $leadership,
|
||||
int $power,
|
||||
int $intel,
|
||||
int $birth = 160,
|
||||
int $death = 300,
|
||||
string $ego = null,
|
||||
string $char = null,
|
||||
string $text = null
|
||||
){
|
||||
$this->npc = new \sammo\Scenario\NPC(
|
||||
$affinity,
|
||||
$name,
|
||||
$pictureID,
|
||||
$nationID,
|
||||
$locatedCity,
|
||||
$leadership,
|
||||
$power,
|
||||
$intel,
|
||||
$birth,
|
||||
$death,
|
||||
$ego,
|
||||
$char,
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
public function run($env=null){
|
||||
$result = $this->npc->build($env);
|
||||
return [__CLASS__, $result];
|
||||
}
|
||||
|
||||
}
|
||||
+117
-13
@@ -20,6 +20,8 @@ class Scenario{
|
||||
private $generals;
|
||||
private $generalsEx;
|
||||
|
||||
private $tmpGeneralQueue = [];
|
||||
|
||||
private $initialEvents;
|
||||
private $events;
|
||||
|
||||
@@ -66,7 +68,7 @@ class Scenario{
|
||||
}
|
||||
|
||||
list(
|
||||
$affinity, $name, $npcID, $nationID, $locatedCity,
|
||||
$affinity, $name, $pictureID, $nationID, $locatedCity,
|
||||
$leadership, $power, $intel, $birth, $death, $ego,
|
||||
$char, $text
|
||||
) = $rawGeneral;
|
||||
@@ -75,10 +77,12 @@ class Scenario{
|
||||
$nationID = 0;
|
||||
}
|
||||
|
||||
$this->tmpGeneralQueue[$name] = $rawGeneral;
|
||||
|
||||
$general = new Scenario\NPC(
|
||||
$affinity,
|
||||
$name,
|
||||
$npcID,
|
||||
$pictureID,
|
||||
$nationID,
|
||||
$locatedCity,
|
||||
$leadership,
|
||||
@@ -94,12 +98,52 @@ class Scenario{
|
||||
$this->nations[$nationID]->addNPC($general);
|
||||
}, Util::array_get($data['general'], []));
|
||||
|
||||
$this->generalsEx = array_map(function($rawGeneral){
|
||||
while(count($rawGeneral) < 14){
|
||||
$rawGeneral[] = null;
|
||||
}
|
||||
|
||||
list(
|
||||
$affinity, $name, $pictureID, $nationID, $locatedCity,
|
||||
$leadership, $power, $intel, $birth, $death, $ego,
|
||||
$char, $text
|
||||
) = $rawGeneral;
|
||||
|
||||
if(!key_exists($nationID, $this->nations)){
|
||||
$nationID = 0;
|
||||
}
|
||||
|
||||
$this->tmpGeneralQueue[$name] = $rawGeneral;
|
||||
|
||||
$general = new Scenario\NPC(
|
||||
$affinity,
|
||||
$name,
|
||||
$pictureID,
|
||||
$nationID,
|
||||
$locatedCity,
|
||||
$leadership,
|
||||
$power,
|
||||
$intel,
|
||||
$birth,
|
||||
$death,
|
||||
$ego,
|
||||
$char,
|
||||
$text
|
||||
);
|
||||
|
||||
$this->nations[$nationID]->addNPC($general, true);
|
||||
}, Util::array_get($data['generalEx'], []));
|
||||
|
||||
$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));
|
||||
//event는 여기서 풀지 않는다.
|
||||
return [
|
||||
'cond' => $rawEvent[0],
|
||||
'action' => array_slice($rawEvent, 1)
|
||||
];
|
||||
}, Util::array_get($data['events'], []));
|
||||
|
||||
}
|
||||
@@ -125,6 +169,7 @@ class Scenario{
|
||||
}
|
||||
|
||||
public function getNation(){
|
||||
return $this->nations;
|
||||
|
||||
$nationsRaw = Util::array_get($this->data['nation']);
|
||||
if(!$nationsRaw){
|
||||
@@ -197,33 +242,92 @@ class Scenario{
|
||||
];
|
||||
}
|
||||
|
||||
private function buildGenerals($env){
|
||||
$remainGenerals = [];
|
||||
foreach($this->generals as $general){
|
||||
if($general->build($env)){
|
||||
continue;
|
||||
}
|
||||
|
||||
$rawGeneral = $this->tmpGeneralQueue[$general->$name];
|
||||
$birth = $general->birth;
|
||||
if(!key_exists($birth, $remainGenerals)){
|
||||
$remainGenerals[$birth] = [];
|
||||
}
|
||||
$remainGenerals[$birth][] = array_merge(['RegNPC'], $rawGeneral);
|
||||
}
|
||||
|
||||
if($env['useExtentedGeneral']){
|
||||
foreach($this->generalsEx as $general){
|
||||
if($general->build($env)){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$rawGeneral = $this->tmpGeneralQueue[$general->$name];
|
||||
$birth = $general->birth;
|
||||
if(!key_exists($birth, $remainGenerals)){
|
||||
$remainGenerals[$birth] = [];
|
||||
}
|
||||
$remainGenerals[$birth][] = array_merge(['RegNPC'], $rawGeneral);
|
||||
}
|
||||
return $remainGenerals;
|
||||
}
|
||||
|
||||
private function buildDiplomacy($env){
|
||||
$db = DB::db();
|
||||
foreach($this->diplomacy as $diplomacy){
|
||||
list($me, $you, $state, $remain) = $diplomacy;
|
||||
$db->update('diplomacy', [
|
||||
'state'=>$state,
|
||||
'remain'=>$remain
|
||||
], '(me = %i_me AND you = %i_you) OR (me = %i_you AND you = %i_me)', [
|
||||
'me'=>$me,
|
||||
'you'=>$you
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function buildGame($env=[]){
|
||||
//NOTE: 초기화가 되어있다고 가정함.
|
||||
|
||||
/*
|
||||
env로 사용된 것들,
|
||||
게임 변수 : year, month
|
||||
game 테이블 변수 : startyear, year, month, genius, turnterm, show_img_level, extend, fiction, npcmode
|
||||
install 변수 : npcmode, show_img_level, extend, scenario, fiction
|
||||
*/
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
foreach($this->nations as $id=>$nation){
|
||||
if($id == 0){
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$nation->build($env);
|
||||
}
|
||||
CityHelper::flushCache();
|
||||
foreach($this->generals as $general){
|
||||
$general->build($env);
|
||||
|
||||
$remainGenerals = $this->buildGenerals($env);
|
||||
|
||||
foreach($remainGenerals as $birth=>$actions){
|
||||
$targetYear = $birth + 14;//FIXME: 14가 어디서 튀어나왔나?
|
||||
|
||||
$actions[] = ['DeleteEvent'];
|
||||
$this->events[] = [
|
||||
'cond'=>['date', '==', $targetYear, '1'],
|
||||
'action'=>$actions
|
||||
];
|
||||
}
|
||||
|
||||
if($env['useExtentedGeneral']){
|
||||
foreach($this->generalsEx as $general){
|
||||
$general->build($env);
|
||||
}
|
||||
}
|
||||
$this->buildDiplomacy($env);
|
||||
|
||||
//TODO: 외교를 추가해야함
|
||||
foreach($this->initialEvents as $event){
|
||||
$event->tryRunEvent($env);
|
||||
}
|
||||
//TODO: event를 전역 handler에 등록해야함.
|
||||
|
||||
$db->insert('event', $this->events);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+101
-4
@@ -8,7 +8,7 @@ class NPC{
|
||||
|
||||
public $affinity;
|
||||
public $name;
|
||||
public $npcID;
|
||||
public $pictureID;
|
||||
public $nationID;
|
||||
public $locatedCity;
|
||||
public $leadership;
|
||||
@@ -24,13 +24,13 @@ class NPC{
|
||||
public function __construct(
|
||||
int $affinity,
|
||||
string $name,
|
||||
int $npcID,
|
||||
int $pictureID,
|
||||
int $nationID,
|
||||
string $locatedCity,
|
||||
int $leadership,
|
||||
int $power,
|
||||
int $intel,
|
||||
int $birth = 150,
|
||||
int $birth = 160,
|
||||
int $death = 300,
|
||||
string $ego = null,
|
||||
string $char = null,
|
||||
@@ -38,7 +38,7 @@ class NPC{
|
||||
){
|
||||
$this->affinity = $affinity;
|
||||
$this->name = $name;
|
||||
$this->npcID = $npcID;
|
||||
$this->pictureID = $pictureID;
|
||||
$this->nationID = $nationID;
|
||||
$this->locatedCity = $locatedCity;
|
||||
$this->leadership = $leadership;
|
||||
@@ -60,6 +60,103 @@ class NPC{
|
||||
|
||||
|
||||
public function build($env=[]){
|
||||
//scenario에 life==1인 경우 수명 제한이 없어지는 모양.
|
||||
$nationID = $this->nationID;
|
||||
if(!\sammo\getNationStaticInfo($nationID)){
|
||||
$nationID = 0;
|
||||
};
|
||||
|
||||
$year = $env['year'];
|
||||
$month = $env['month'];
|
||||
$age = $year - $this->birth;
|
||||
|
||||
if($this->death < $year){
|
||||
return true; //죽었으니 넘어간다.
|
||||
}
|
||||
if($age < 14){
|
||||
return false; //예약.
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
if($age == 14 && $month == 1){//FIXME: 14가 어디서 튀어나왔나?
|
||||
\sammo\pushHistory(["<C>●</>1월:<Y>$name</>(이)가 성인이 되어 <S>등장</>했습니다."]);
|
||||
}
|
||||
|
||||
if($this->ego == null){
|
||||
$this->ego = mt_rand(0, 9);//TODO: 나중에 성격을 따로 분리할 경우 클래스를 참조.
|
||||
}
|
||||
|
||||
$name = 'ⓝ'.$this->name;
|
||||
|
||||
if($env['show_img_level'] == 3 && $pictureID > 0){
|
||||
$picture = "{$pictureID}.jpg";
|
||||
}
|
||||
else{
|
||||
$picture = 'default.jpg';
|
||||
}
|
||||
|
||||
$city = $this->city;
|
||||
if($city === null){
|
||||
if($nationID == 0){
|
||||
$city = Util::choiceRandom(CityHelper::getAllCities())['id'];
|
||||
}
|
||||
else{
|
||||
$city = Util::choiceRandom(CityHelper::getAllNationCities($nationID))['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$experience = $age * 100;
|
||||
$dedication = $age * 100;
|
||||
$level = $nationID?1:0;
|
||||
|
||||
$turntime = \sammo\getRandTurn($env['turnterm']);
|
||||
|
||||
$killturn = ($this->death - $year) * 12 + mt_rand(0, 11);
|
||||
|
||||
$specage = $age + 1;
|
||||
$specage2 = $age + 1;
|
||||
|
||||
|
||||
$db->insert('general',[
|
||||
'npcid'=>$db->sqleval('max(npcid)+1'),
|
||||
'npc'=>2,
|
||||
'npc_org'=>2,
|
||||
'affinity'=>$this->affinity,
|
||||
'name'=>$name,
|
||||
'picture'=>$picture,
|
||||
'nation'=>$nationID,
|
||||
'city'=>$city,
|
||||
'leader'=>$this->leader,
|
||||
'power'=>$this->power,
|
||||
'intel'=>$this->intel,
|
||||
'experience'=>$experience,
|
||||
'dedication'=>$dedication,
|
||||
'level'=>$level,
|
||||
'gold'=>1000,
|
||||
'rice'=>1000,
|
||||
'crew'=>0,
|
||||
'crewtype'=>0,
|
||||
'train'=>0,
|
||||
'atmos'=>0,
|
||||
'weap'=>0,
|
||||
'book'=>0,
|
||||
'horse'=>0,
|
||||
'turntime'=>$turntime,
|
||||
'killturn'=>$killturn,
|
||||
'age'=>$age,
|
||||
'belong'=>1,
|
||||
'personal'=>$this->ego,
|
||||
'special'=>$this->charDomestic,
|
||||
'specage'=>$specage,
|
||||
'special2'=>$this->charWar,
|
||||
'specage2'=>$specage2,
|
||||
'npcmsg'=>$this->text,
|
||||
'makelimit'=>0,
|
||||
'bornyear'=>$this->birth,
|
||||
'deadyear'=>$this->death
|
||||
]);
|
||||
|
||||
return true; //생성되었다.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user