feat: RaiserInvader 초기 구현
This commit is contained in:
@@ -3,7 +3,7 @@ namespace sammo\Event;
|
||||
|
||||
abstract class Action{
|
||||
//public abstract function __construct(...$args);
|
||||
public abstract function run($env);
|
||||
public abstract function run(array $env);
|
||||
|
||||
public static function build($actionArgs):Action{
|
||||
if(!is_array($actionArgs)){
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use function sammo\getNationStaticInfo;
|
||||
use sammo\DB;
|
||||
use sammo\Util;
|
||||
|
||||
class AutoDeleteInvader extends \sammo\Event\Action{
|
||||
private $nationID;
|
||||
public function __construct(int $nationID){
|
||||
$this->nationID = $nationID;
|
||||
}
|
||||
|
||||
public function run(array $env){
|
||||
if(getNationStaticInfo($this->nationID)===null){
|
||||
return [__CLASS__, "Not Exists"];
|
||||
}
|
||||
$db = DB::db();
|
||||
$onWar = $db->queryFirstField('SELECT count(*) FROM diplomacy WHERE me = %i AND state IN %li', $this->nationID, [0, 1]);
|
||||
if($onWar){
|
||||
return [__CLASS__, "On War"];
|
||||
}
|
||||
|
||||
$rulerID = $db->queryFirstField('SELECT no FROM general WHERE nation = %i AND officer_level = 12', $this->nationID);
|
||||
$db->update('general_turn', [
|
||||
'action'=>'che_방랑',
|
||||
'arg'=>'[]',
|
||||
'brief'=>"이민족 방랑"
|
||||
], 'general_id = %i', $rulerID);
|
||||
$db->update('general', [
|
||||
'killturn'=>5
|
||||
], 'nation = %i', $this->nationID);
|
||||
|
||||
$eventID = Util::array_get($env['currentEventID']);
|
||||
$db->delete('event', 'id = %i', $eventID);
|
||||
|
||||
return [__CLASS__, 'Deleted'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -161,7 +161,7 @@ class ChangeCity extends \sammo\Event\Action{
|
||||
throw new \InvalidArgumentException('올바르지 않은 cond 입니다.');
|
||||
}
|
||||
|
||||
public function run($env=null){
|
||||
public function run(array $env){
|
||||
$cities = $this->getTargetCities($env);
|
||||
|
||||
DB::db()->update('city',
|
||||
|
||||
@@ -7,7 +7,7 @@ class CreateAdminNPC extends \sammo\Event\Action{
|
||||
|
||||
}
|
||||
|
||||
public function run($env=null){
|
||||
public function run(array $env){
|
||||
return [__CLASS__, 'NYI'];
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class CreateManyNPC extends \sammo\Event\Action{
|
||||
}
|
||||
|
||||
|
||||
public function run($env=null){
|
||||
public function run(array $env){
|
||||
if($this->npcCount <= 0){
|
||||
return [__CLASS__, []];
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ class DeleteEvent extends \sammo\Event\Action{
|
||||
public function __construct(){
|
||||
}
|
||||
|
||||
public function run($env=null){
|
||||
public function run(array $env){
|
||||
|
||||
$eventID = \sammo\Util::array_get($env['currentEventID']);
|
||||
if(!$eventID){
|
||||
|
||||
@@ -1,116 +1,226 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use sammo\CityConst;
|
||||
use sammo\DB;
|
||||
use sammo\Json;
|
||||
use sammo\KVStorage;
|
||||
use sammo\Scenario\GeneralBuilder;
|
||||
use sammo\Scenario\Nation;
|
||||
use sammo\UniqueConst;
|
||||
use sammo\Util;
|
||||
|
||||
/**
|
||||
* 이민족 침입을 모사
|
||||
*
|
||||
* 양수 : 정해진 값. [절대값]
|
||||
* 음수 : 합산(장수 등), 혹은 평균(기술 등)을 나누어 적용한 값 [상대값]
|
||||
* 음수 : 합산(장수 등), 혹은 평균(기술 등)을 곱해 적용한 값 [상대값]
|
||||
*
|
||||
* event_1.php, 센 이민족 : npcEachCount = -0.5, specAvg = 195, specDist = 5, tech = 15000, dex = 450000
|
||||
* event_2.php, 약한 이민족 : npcEachCount = -0.5, specAvg = 150, specDist = 20, tech = -1, dex = 0
|
||||
* event_3.php, 엄청 약한 이민족 : npcEachCount = 100, specAvg = 50, specDist = 5, tech = 0, dex = 0
|
||||
* event_1.php, 센 이민족 : npcEachCount = -0.5, specAvg = 195, tech = 15000, dex = 450000
|
||||
* event_2.php, 약한 이민족 : npcEachCount = -0.5, specAvg = 150, tech = -1, dex = 0
|
||||
* event_3.php, 엄청 약한 이민족 : npcEachCount = 100, specAvg = 50, tech = 0, dex = 0
|
||||
*/
|
||||
class RaiseInvader extends \sammo\Event\Action{
|
||||
class RaiseInvader extends \sammo\Event\Action
|
||||
{
|
||||
private $npcEachCount;
|
||||
private $specAvg;
|
||||
private $specDist;
|
||||
private $tech;
|
||||
private $dex;
|
||||
|
||||
const INVADER_LIST = [
|
||||
'강'=>63,
|
||||
'저'=>64,
|
||||
'흉노'=>65,
|
||||
'남만'=>66,
|
||||
'산월'=>67,
|
||||
'오환'=>68,
|
||||
'왜'=>69
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
$npcEachCount = -0.5,
|
||||
int $specAvg = 150,
|
||||
int $specDist = 20,
|
||||
int $specAvg = 50,
|
||||
int $tech = -1,
|
||||
int $dex = 0
|
||||
){
|
||||
$dex = -0.01
|
||||
) {
|
||||
$this->npcEachCount = $npcEachCount;
|
||||
$this->specAvg = $specAvg;
|
||||
$this->specDist = $specDist;
|
||||
$this->tech = $tech;
|
||||
$this->dex = $dex;
|
||||
|
||||
if($specDist < 0){
|
||||
throw new \InvalidArgumentException('specDist는 음수를 지원하지 않습니다.');
|
||||
}
|
||||
}
|
||||
|
||||
private function moveCapital(){
|
||||
$cities = array_map(function ($value) {
|
||||
return $value;
|
||||
}, static::INVADER_LIST);
|
||||
private function moveCapital()
|
||||
{
|
||||
$cities = [];
|
||||
foreach (CityConst::all() as $cityObj) {
|
||||
if ($cityObj->level != 4) {
|
||||
continue;
|
||||
}
|
||||
$cities[] = $cityObj->id;
|
||||
}
|
||||
|
||||
if (count($cities) == 0) {
|
||||
return [__CLASS__, 0];
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
|
||||
foreach($db->queryFirstColumn('SELECT capital, nation from nation WHERE capital in %li', $cities) as $row){
|
||||
foreach ($db->queryFirstColumn('SELECT capital, nation from nation WHERE capital in %li', $cities) as $row) {
|
||||
list($oldCapital, $nation) = $row;
|
||||
$newCapital = $db->queryFirstRow('SELECT city from city where nation=%i and city !=%i \
|
||||
order by rand() limit 1', $nation, $oldCapital);
|
||||
$db->update('nation', ['capital'=>$newCapital], 'nation=%i', $nation);
|
||||
$db->update('nation', ['capital' => $newCapital], 'nation=%i', $nation);
|
||||
|
||||
$db->update('general', ['city'=>$newCapital], 'nation=%i and city=%i', $nation, $oldCapital);
|
||||
$db->update('general', ['city' => $newCapital], 'nation=%i and city=%i', $nation, $oldCapital);
|
||||
}
|
||||
|
||||
|
||||
$db->update('general', [
|
||||
'officer_level'=>1,
|
||||
'officer_city'=>0
|
||||
'officer_level' => 1,
|
||||
'officer_city' => 0
|
||||
], 'officer_city in %li', $cities);
|
||||
|
||||
$db->update('city', [
|
||||
'nation'=>0
|
||||
'nation' => 0,
|
||||
'front'=>0,
|
||||
'supply'=>1,
|
||||
], 'city in %li', $cities);
|
||||
}
|
||||
|
||||
public function run($env=null){
|
||||
public function run(array $env)
|
||||
{
|
||||
$db = DB::db();
|
||||
$npcEachCount = $this->npcEachCount;
|
||||
|
||||
if($npcEachCount < 0){
|
||||
$npcEachCount =
|
||||
$db->queryFirstField('SELECT count(no) from general where npc < 9') / count(self::INVADER_LIST);
|
||||
$npcEachCount /= -1 * $this->npcEachCount;
|
||||
/** @var \sammo\CityInitDetail[] */
|
||||
$cities = [];
|
||||
foreach (CityConst::all() as $cityObj) {
|
||||
if ($cityObj->level != 4) {
|
||||
continue;
|
||||
}
|
||||
$cities[] = $cityObj;
|
||||
}
|
||||
|
||||
if ($npcEachCount < 0) {
|
||||
$npcEachCount =
|
||||
$db->queryFirstField('SELECT count(no) from general where npc < 5') / count($cities);
|
||||
$npcEachCount *= -1 * $this->npcEachCount;
|
||||
}
|
||||
$npcEachCount = max(10, Util::toInt($npcEachCount));
|
||||
|
||||
$specAvg = $this->specAvg;
|
||||
if($specAvg < 0){
|
||||
$specAvg = $db->queryFirstField('SELECT avg(sum(`leadership` + `strength` + `intel`)) from general where npc < 9');
|
||||
$specAvg /= -1 * $this->specAvg;
|
||||
if ($specAvg < 0) {
|
||||
$specAvg = $db->queryFirstField('SELECT avg(sum(`leadership` + `strength` + `intel`)) from general where npc < 5');
|
||||
$specAvg *= -1 * $this->specAvg;
|
||||
}
|
||||
$specAvg = Util::toInt($specAvg);
|
||||
|
||||
$tech = $this->tech;
|
||||
if($tech < 0){
|
||||
if ($tech < 0) {
|
||||
$tech = $db->queryFirstField("SELECT avg(tech) from nation where `level`>0");
|
||||
$tech /= -1 * $this->tech;
|
||||
$tech *= -1 * $this->tech;
|
||||
}
|
||||
|
||||
$dex = $this->dex;
|
||||
if($dex < 0){
|
||||
if ($dex < 0) {
|
||||
$dex = $db->queryFirstField("SELECT avg(dex1 + dex2 + dex3 + dex4 + dex5)/5 from nation where `level`>0");
|
||||
$dex /= -1 * $this->dex;
|
||||
$dex *= -1 * $this->dex;
|
||||
}
|
||||
$dex = Util::toInt($dex);
|
||||
|
||||
$this->moveCapital();
|
||||
//TODO:국가를 만들고
|
||||
//TODO:장수를 세팅하고
|
||||
//TODO:외교를 설정한다.
|
||||
$serverID = UniqueConst::$serverID;
|
||||
$existNations = $db->queryFirstColumn("SELECT nation FROM `nation`");
|
||||
$lastNationID = max(
|
||||
max($existNations),
|
||||
$db->queryFirstField("SELECT max(`nation`) FROM `ng_old_nations` WHERE server_id = %s", $serverID),
|
||||
);
|
||||
|
||||
//TODO: 시나리오 구현 후 마무리.
|
||||
//TODO: 임관 모드가 '랜임모드'인 경우 오랑캐와 충돌하므로 해제해야함.
|
||||
|
||||
return [__CLASS__, 'NYI'];
|
||||
$db->update('general', [
|
||||
'gold' => 999999,
|
||||
'rice' => 999999,
|
||||
], true);
|
||||
|
||||
$year = $env['year'];
|
||||
|
||||
$invaderNationIDList = [];
|
||||
|
||||
foreach ($cities as $cityObj) {
|
||||
if ($cityObj->level != 4) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lastNationID += 1;
|
||||
$invaderNationID = $lastNationID;
|
||||
$invaderNationIDList[] = $invaderNationID;
|
||||
|
||||
$invaderName = $cityObj->name;
|
||||
$nationName = "ⓞ{$invaderName}족";
|
||||
$cityID = $cityObj->id;
|
||||
$nationObj = new Nation($invaderNationID, $nationName, '#800080', 9999999, 9999999, "중원의 부패를 물리쳐라! 이민족 침범!", $tech, "che_병가", 1, [$cityID]);
|
||||
$nationObj->addGeneral((new GeneralBuilder("{$invaderName}대왕", false, null, $lastNationID))
|
||||
->setEgo('che_패권')
|
||||
->setSpecial('che_인덕', 'che_척사')
|
||||
->setLifeSpan($year - 20, $year + 20)
|
||||
->setNPCType(9)
|
||||
->setStat(Util::toInt($specAvg * 1.8), Util::toInt($specAvg * 1.8), Util::toInt($specAvg * 1.2))
|
||||
->setAffinity(999)
|
||||
->setGoldRice(99999, 99999)
|
||||
);
|
||||
|
||||
foreach (Util::range(1, $npcEachCount) as $invaderGenIdx) {
|
||||
$gen = (new GeneralBuilder("{$invaderName}장수{$invaderGenIdx}", false, null, $invaderNationID))
|
||||
->setEgo('che_패권')
|
||||
->setSpecial('che_인덕', 'che_척사')
|
||||
->setLifeSpan($year - 20, $year + 20)
|
||||
->setNPCType(9)
|
||||
->setAffinity(999)
|
||||
->setGoldRice(99999, 99999);
|
||||
|
||||
$leadership = Util::randRangeInt(Util::toInt($specAvg * 1.2), Util::toInt($specAvg * 1.4));
|
||||
$mainStat = Util::randRangeInt(Util::toInt($specAvg * 1.2), Util::toInt($specAvg * 1.4));
|
||||
$subStat = $specAvg * 3 - $leadership - $mainStat;
|
||||
|
||||
if (Util::randBool()) {
|
||||
//무장
|
||||
$dexTable = [$dex * 2, $dex, $dex];
|
||||
shuffle($dexTable);
|
||||
$gen->setStat($leadership, $mainStat, $subStat)
|
||||
->setDex($dexTable[0], $dexTable[1], $dexTable[2], $dex, 0);
|
||||
} else {
|
||||
//지장
|
||||
$gen->setStat($leadership, $subStat, $mainStat)
|
||||
->setDex($dex, $dex, $dex, $dex * 2, 0);
|
||||
}
|
||||
$nationObj->addGeneral($gen);
|
||||
}
|
||||
|
||||
$nationObj->build($env);
|
||||
$nationObj->postBuild($env);
|
||||
$db->insert('event', [
|
||||
'condition'=>Json::encode(true),
|
||||
'action'=>Json::encode(["AutoDeleteInvader", $invaderNationID]),
|
||||
]);
|
||||
}
|
||||
|
||||
$db->update('nation', [
|
||||
'scout' => 1
|
||||
], 'nation IN %li', $invaderNationIDList);
|
||||
$db->update('diplomacy', [
|
||||
'state' => 1,
|
||||
'term' => 24,
|
||||
], '(me IN %li AND you IN %li) OR (me IN %li AND you IN %li)', $existNations, $invaderNationIDList, $invaderNationIDList, $existNations);
|
||||
|
||||
$cityMaxPop = $specAvg*$npcEachCount*100;
|
||||
$db->update('city', [
|
||||
'pop_max'=>$cityMaxPop,
|
||||
'def_max'=>10000,
|
||||
'wall_max'=>1000,
|
||||
], 'nation IN %li', $invaderNationIDList);
|
||||
|
||||
$db->update('city', [
|
||||
'pop'=>$db->sqleval('pop_max'),
|
||||
'secu'=>$db->sqleval('secu_max'),
|
||||
'def'=>$db->sqleval('def_max'),
|
||||
'wall'=>$db->sqleval('wall_max'),
|
||||
], true);
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$gameStor->isunited = 1;
|
||||
|
||||
return [__CLASS__, count($invaderNationIDList)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class RegNPC extends \sammo\Event\Action{
|
||||
->setLifeSpan($birth, $death);
|
||||
}
|
||||
|
||||
public function run($env){
|
||||
public function run(array $env){
|
||||
$result = $this->npc->fillRemainSpecAsZero($env)->build($env);
|
||||
return [__CLASS__, $result];
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class RegNeutralNPC extends \sammo\Event\Action{
|
||||
->setNPCType(6);
|
||||
}
|
||||
|
||||
public function run($env=null){
|
||||
public function run(array $env){
|
||||
$result = $this->npc->fillRemainSpecAsZero($env)->build($env);
|
||||
return [__CLASS__, $result];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user