파일 위치를 twe에서 hwe로 옮김.
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
namespace sammo\Scenario;
|
||||
use \sammo\Util;
|
||||
use \sammo\DB;
|
||||
use \sammo\CityHelper;
|
||||
|
||||
class NPC{
|
||||
|
||||
public $affinity;
|
||||
public $name;
|
||||
public $pictureID;
|
||||
public $nationID;
|
||||
public $locatedCity;
|
||||
public $leadership;
|
||||
public $power;
|
||||
public $intel;
|
||||
public $level;
|
||||
public $birth;
|
||||
public $death;
|
||||
public $ego;
|
||||
public $charDomestic = 0;
|
||||
public $charWar = 0;
|
||||
public $text;
|
||||
|
||||
//[ 1, "헌제",1002, 1, null, 17, 13, 61, 0, 170, 250, "안전", null, "산 넘어 산이로구나..."],
|
||||
public function __construct(
|
||||
int $affinity,
|
||||
string $name,
|
||||
int $pictureID,
|
||||
int $nationID,
|
||||
$locatedCity, //FIXME: 7.1로 올릴 때 ?string 으로 변경
|
||||
int $leadership,
|
||||
int $power,
|
||||
int $intel,
|
||||
int $level = 0,
|
||||
int $birth = 160,
|
||||
int $death = 300,
|
||||
$ego = null,
|
||||
$char = null,
|
||||
$text = null
|
||||
){
|
||||
$this->affinity = $affinity;
|
||||
$this->name = $name;
|
||||
$this->pictureID = $pictureID;
|
||||
$this->nationID = $nationID;
|
||||
$this->locatedCity = $locatedCity;
|
||||
$this->leadership = $leadership;
|
||||
$this->power = $power;
|
||||
$this->intel = $intel;
|
||||
$this->level = $level;
|
||||
$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=[]){
|
||||
//scenario에 life==1인 경우 수명 제한이 없어지는 모양.
|
||||
$nationID = $this->nationID;
|
||||
if(!\sammo\getNationStaticInfo($nationID)){
|
||||
$nationID = 0;
|
||||
};
|
||||
|
||||
$year = $env['year'];
|
||||
$month = $env['month'];
|
||||
$age = $year - $this->birth;
|
||||
$name = $this->name;
|
||||
|
||||
if($this->death < $year){
|
||||
return true; //죽었으니 넘어간다.
|
||||
}
|
||||
if($age < \sammo\GameConst::$adultAge){
|
||||
return false; //예약.
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
if($age == \sammo\GameConst::$adultAge && $month == 1){//FIXME: 14가 어디서 튀어나왔나?
|
||||
\sammo\pushHistory(["<C>●</>1월:<Y>$name</>(이)가 성인이 되어 <S>등장</>했습니다."]);
|
||||
}
|
||||
|
||||
if($this->ego == null){
|
||||
$ego = mt_rand(0, 9);//TODO: 나중에 성격을 따로 분리할 경우 클래스를 참조.
|
||||
}
|
||||
else{
|
||||
$ego = \sammo\CharCall($this->ego);
|
||||
}
|
||||
|
||||
$name = 'ⓝ'.$this->name;
|
||||
|
||||
if($env['show_img_level'] == 3 && $pictureID > 0){
|
||||
$picture = "{$pictureID}.jpg";
|
||||
}
|
||||
else{
|
||||
$picture = 'default.jpg';
|
||||
}
|
||||
|
||||
$city = $this->locatedCity;
|
||||
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:$this->level;
|
||||
|
||||
$turntime = \sammo\getRandTurn($env['turnterm']);
|
||||
|
||||
$killturn = ($this->death - $year) * 12 + mt_rand(0, 11);
|
||||
|
||||
$specage = $age + 1;
|
||||
$specage2 = $age + 1;
|
||||
|
||||
$npcID = $db->queryFirstField('SELECT max(npcid)+1 FROM general');
|
||||
|
||||
$db->insert('general',[
|
||||
'npcid'=>$npcID,
|
||||
'npc'=>2,
|
||||
'npc_org'=>2,
|
||||
'affinity'=>$this->affinity,
|
||||
'name'=>$name,
|
||||
'picture'=>$picture,
|
||||
'nation'=>$nationID,
|
||||
'city'=>$city,
|
||||
'leader'=>$this->leadership,
|
||||
'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'=>$ego,
|
||||
'special'=>$this->charDomestic,
|
||||
'specage'=>$specage,
|
||||
'special2'=>$this->charWar,
|
||||
'specage2'=>$specage2,
|
||||
'npcmsg'=>$this->text,
|
||||
'makelimit'=>0,
|
||||
'bornyear'=>$this->birth,
|
||||
'deadyear'=>$this->death
|
||||
]);
|
||||
|
||||
return true; //생성되었다.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
namespace sammo\Scenario;
|
||||
use \sammo\DB;
|
||||
use \sammo\Util;
|
||||
|
||||
class Nation{
|
||||
private $id;
|
||||
private $name;
|
||||
private $color;
|
||||
private $gold;
|
||||
private $rice;
|
||||
private $infoText;
|
||||
private $tech;
|
||||
private $type;
|
||||
private $nationLevel;
|
||||
|
||||
private $capital;
|
||||
|
||||
private $cities = [];
|
||||
|
||||
public function __construct(
|
||||
int $id = null,
|
||||
string $name = '국가',
|
||||
string $color = '#ffffff',
|
||||
int $gold = 0,
|
||||
int $rice = 2000,
|
||||
string $infoText = '국가 설명',
|
||||
int $tech = 0,
|
||||
string $type = '유가',
|
||||
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 getID(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function build($env=[]){
|
||||
//NOTE: NPC의 숫자는 아직 확정된 것이 아니다.
|
||||
$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'=>0,
|
||||
'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'=>0,
|
||||
'level'=>$this->nationLevel,
|
||||
'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
|
||||
];
|
||||
}
|
||||
if(count($diplomacy) > 0){
|
||||
$db->insert('diplomacy', $diplomacy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function postBuild($env=[]){
|
||||
$npc_cnt = count($this->generals);
|
||||
if($env['extended_general']){
|
||||
$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,
|
||||
'name'=>$this->name,
|
||||
'color'=>$this->color,
|
||||
'gold'=>$this->gold,
|
||||
'rice'=>$this->rice,
|
||||
'infoText'=>$this->infoText,
|
||||
'tech'=>$this->tech,
|
||||
'type'=>$this->type,
|
||||
'nationLevel'=>$this->nationLevel,
|
||||
'cities'=>$this->cities
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user