Files
core/hwe/sammo/Scenario/Nation.php
T
Hide_D 83d6a2169b 유산 포인트 시스템, 추가 기수 대비 (#187)
- 유산 포인트
  - 기수 뒤로도 누적되는 포인트
  - 생존, 최대 임관년 수, 최대 연속 내정 성공, 병종 상성 우위 횟수, 전투 횟수, 계략 성공 횟수, 천통 기여(규모 상승, 천통 수뇌, 천통 군주), 숙련도, 토너먼트, 베팅 당첨
  - 유산 관리 페이지 제공

- 태수국
  - 181년 1월에 자동 생성되는 u장수국
  - 시간이 지나면 사실상 자동 소멸
  - 유저국과는 4칸 거리, 서로는 2칸 거리
  - 이 시스템으로 인해 m장 거병 차단

- NPC 원조시 불가침
  - 1년 세수만큼 받은 경우 24개월 불가침 제안
  - 최소 6개월
  - 불가침을 받지 않고 추가 원조한 경우 계속해서 기간 상승
  - 단, 불가침 수락 전에 선포를 할 수 있음

Reviewed-on: https://storage.hided.net/gitea/devsam/core/pulls/187
Co-authored-by: hide_d <hided62@gmail.com>
Co-committed-by: hide_d <hided62@gmail.com>
2021-08-11 21:57:52 +09:00

198 lines
5.3 KiB
PHP

<?php
namespace sammo\Scenario;
use \sammo\DB;
use \sammo\GameConst;
use \sammo\Util;
use \sammo\KVStorage;
use \sammo\Json;
use function \sammo\getNationChiefLevel;
class Nation{
private $id;
private $name;
private $color;
private $gold;
private $rice;
private $infoText;
private $tech;
private $type;
private $nationLevel;
private $capital = null;
private $cities = [];
private $generals = [];
public function __construct(
int $id = null,
string $name = '국가',
string $color = '#000000',
int $gold = 0,
int $rice = 2000,
string $infoText = '국가 설명',
int $tech = 0,
?string $type = null,
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;
if(count($cities)){
$this->capital = $this->cities[0];
}
}
public function setID(int $id){
$this->id = $id;
}
public function getID(){
return $this->id;
}
public function getName(){
return $this->name;
}
public function build($env){
//NOTE: NPC의 숫자는 아직 확정된 것이 아니다.
$cities = array_map(function($cityName){
return \sammo\CityHelper::getCityByName($cityName)['id'];
}, $this->cities);
if($this->capital){
$capital = \sammo\CityHelper::getCityByName($this->capital)['id'];
}
else{
$capital = 0;
}
if($this->type === null){
$type = Util::choiceRandom(GameConst::$availableNationType);
}
else if(strpos($this->type, '_') === FALSE){
$type = 'che_'.$this->type;
}
else{
$type = $this->type;
}
$db = DB::db();
$nationStor = KVStorage::getStorage($db, $this->id, 'nation_env');
$otherNations = $db->queryFirstColumn('SELECT nation FROM nation');
$aux = [
'can_국기변경'=>1
];
if($this->nationLevel==7){
$aux['can_국호변경']=1;
}
$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,
'strategic_cmd_limit'=>24,
'surlimit'=>72,
'tech'=>$this->tech,
'level'=>$this->nationLevel,
'type'=>$type,
'aux'=>Json::encode($aux),
]);
if($cities){
$db->update('city', [
'nation'=>$this->id
], 'city IN %li', $cities);
}
$nationStor->scout_msg = $this->infoText;
$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 addGeneral(GeneralBuilder $general){
$this->generals[] = $general;
}
public function postBuild($env){
$npc_cnt = count($this->generals);
$db = DB::db();
$db->update('nation', [
'gennum'=>$npc_cnt,
], 'nation=%i', $this->id);
//군주가 없는지 확인
$hasRuler = $db->queryFirstField('SELECT count(*) FROM general WHERE nation=%i AND officer_level=12', $this->id);
if(!$hasRuler){
$newRuler = $db->queryFirstField('SELECT `no` FROM general WHERE nation=%i ORDER BY leadership+strength+intel DESC LIMIT 1', $this->id);
$db->update('general',['officer_level'=>12], 'no=%i', $newRuler);
}
$turnRows = [];
foreach(Util::range(12, getNationChiefLevel($this->nationLevel)-1, -1) as $chiefLevel){
foreach(Util::range(GameConst::$maxChiefTurn) as $turnIdx){
$turnRows[] = [
'nation_id'=>$this->id,
'officer_level'=>$chiefLevel,
'turn_idx'=>$turnIdx,
'action'=>'휴식',
'arg'=>'{}',
'brief'=>'휴식',
];
}
}
$db->insertIgnore('nation_turn', $turnRows);
}
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
];
}
}