전역 하드코드 이벤트를 동적 변경 영역으로 이동 (#230)
기존에 작성해두었던 EventHandler 시스템으로 하드코드 이벤트 이동 - 매달 - 보급선 설정 - 전쟁 단기 수입 설정 - 부대장 부여 - 1월 - 유산 포인트 계산 - 도시 인구 변화 - 수입 - 관직 제한 해제 - 재난 - 상인 - 새해 알림 - 특기 부여 - 4월 - 관직 제한 해제 - 재난 - 7월 - 유산 포인트 계산 - 도시 인구 변화 - 수입 - 관직 제한 해제 - 재난 - 상인 - 10월 - 관직 제한 해제 - 재난 - 천통 시 - 유산 포인트 계산 Reviewed-on: https://storage.hided.net/gitea/devsam/core/pulls/230
This commit was merged in pull request #230.
This commit is contained in:
@@ -3,6 +3,10 @@ namespace sammo\Event;
|
||||
|
||||
abstract class Action{
|
||||
//public abstract function __construct(...$args);
|
||||
/*
|
||||
TODO: event trigger를 인자로 보낼 수 있으면 좋을 것
|
||||
예시로, 도시 점령 시, 점령한 도시의 정보를 인자로 보낼 수 있으면 좋을 것
|
||||
/*/
|
||||
public abstract function run(array $env);
|
||||
|
||||
public static function build($actionArgs):Action{
|
||||
@@ -16,6 +20,7 @@ abstract class Action{
|
||||
}
|
||||
|
||||
$args = array_slice($actionArgs, 1);
|
||||
/** @var \ReflectionClass<Action> */
|
||||
$ref = new \ReflectionClass($className);
|
||||
return $ref->newInstanceArgs($args);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use sammo\ActionLogger;
|
||||
use sammo\DB;
|
||||
use sammo\GameConst;
|
||||
use sammo\JosaUtil;
|
||||
use sammo\Json;
|
||||
use sammo\LiteHashDRBG;
|
||||
use sammo\RandUtil;
|
||||
use sammo\SpecialityHelper;
|
||||
use sammo\UniqueConst;
|
||||
use sammo\Util;
|
||||
|
||||
use function sammo\buildGeneralSpecialDomesticClass;
|
||||
use function sammo\buildGeneralSpecialWarClass;
|
||||
|
||||
class AssignGeneralSpeciality extends \sammo\Event\Action
|
||||
{
|
||||
public function run(array $env)
|
||||
{
|
||||
$startYear = $env['startyear'];
|
||||
$year = $env['year'];
|
||||
$month = $env['month'];
|
||||
|
||||
if ($year < $startYear + 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
$rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||
UniqueConst::$hiddenSeed,
|
||||
'assignGeneralSpeciality',
|
||||
$year,
|
||||
$month,
|
||||
)));
|
||||
|
||||
foreach ($db->query('SELECT no,name,nation,leadership,strength,intel,aux from general where specage<=age and special=%s', GameConst::$defaultSpecialDomestic) as $general) {
|
||||
$generalID = $general['no'];
|
||||
$special = SpecialityHelper::pickSpecialDomestic(
|
||||
$rng,
|
||||
$general,
|
||||
(Json::decode($general['aux'])['prev_types_special']) ?? []
|
||||
);
|
||||
$specialClass = buildGeneralSpecialDomesticClass($special);
|
||||
$specialText = $specialClass->getName();
|
||||
$db->update('general', [
|
||||
'special' => $special
|
||||
], 'no=%i', $generalID);
|
||||
|
||||
$logger = new ActionLogger($generalID, $general['nation'], $year, $month);
|
||||
|
||||
$josaUl = JosaUtil::pick($specialText, '을');
|
||||
$logger->pushGeneralActionLog("특기 【<b><L>{$specialText}</></b>】{$josaUl} 익혔습니다!", ActionLogger::PLAIN);
|
||||
$logger->pushGeneralHistoryLog("특기 【<b><C>{$specialText}</></b>】{$josaUl} 습득");
|
||||
}
|
||||
|
||||
foreach ($db->query('SELECT no,name,nation,leadership,strength,intel,npc,dex1,dex2,dex3,dex4,dex5,aux from general where specage2<=age and special2=%s', GameConst::$defaultSpecialWar) as $general) {
|
||||
$generalID = $general['no'];
|
||||
$generalAux = Json::decode($general['aux']);
|
||||
|
||||
$updateVars = [];
|
||||
if (key_exists('inheritSpecificSpecialWar', $generalAux)) {
|
||||
$special2 = $generalAux['inheritSpecificSpecialWar'];
|
||||
unset($generalAux['inheritSpecificSpecialWar']);
|
||||
$updateVars['aux'] = Json::encode($generalAux);
|
||||
} else {
|
||||
$special2 = SpecialityHelper::pickSpecialWar(
|
||||
$rng,
|
||||
$general,
|
||||
($generalAux['prev_types_special2']) ?? []
|
||||
);
|
||||
}
|
||||
|
||||
$specialClass = buildGeneralSpecialWarClass($special2);
|
||||
$specialText = $specialClass->getName();
|
||||
|
||||
$updateVars['special2'] = $special2;
|
||||
$db->update('general', $updateVars, 'no=%i', $general['no']);
|
||||
|
||||
$logger = new ActionLogger($generalID, $general['nation'], $year, $month);
|
||||
|
||||
$josaUl = JosaUtil::pick($specialText, '을');
|
||||
$logger->pushGeneralActionLog("특기 【<b><L>{$specialText}</></b>】{$josaUl} 익혔습니다!", ActionLogger::PLAIN);
|
||||
$logger->pushGeneralHistoryLog("특기 【<b><C>{$specialText}</></b>】{$josaUl} 습득");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use Ds\Map;
|
||||
use sammo\DB;
|
||||
use sammo\Enums\InheritanceKey;
|
||||
use sammo\Enums\RankColumn;
|
||||
use sammo\General;
|
||||
use sammo\InheritancePointManager;
|
||||
|
||||
class MergeInheritPointRank extends \sammo\Event\Action
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function run(array $env)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
$generals = General::createGeneralObjListFromDB(null, null, 2);
|
||||
|
||||
$points = new Map();
|
||||
$points->allocate(count($generals));
|
||||
foreach($generals as $general){
|
||||
$generalID = $general->getID();
|
||||
$points[$generalID] = 0;
|
||||
}
|
||||
|
||||
foreach(InheritanceKey::cases() as $key){
|
||||
if($key === InheritanceKey::previous){
|
||||
continue;
|
||||
}
|
||||
$subPoints = InheritancePointManager::getInstance()->getInheritancePointFromAll($generals, $key);
|
||||
foreach($generals as $general){
|
||||
$generalID = $general->getID();
|
||||
$points[$generalID] += $subPoints[$generalID] ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
$pointsPairs = [];
|
||||
foreach($points as $generalID => $point){
|
||||
$pointsPairs[] = [
|
||||
'nation_id' => $generals[$generalID]->getNationID(),
|
||||
'general_id' => $generalID,
|
||||
'type' => RankColumn::inherit_point_earned_by_merge->value,
|
||||
'value' => $point,
|
||||
];
|
||||
}
|
||||
//XXX: multiple batch update가 제공되지 않으므로..
|
||||
$db->delete('rank_data', '`type` = %s', RankColumn::inherit_point_earned_by_merge->value);
|
||||
$db->insert('rank_data', $pointsPairs);
|
||||
|
||||
$db->query(
|
||||
'UPDATE `rank_data` D SET `value` = (SELECT SUM(`value`) FROM `rank_data` S WHERE S.general_id = D.general_id AND S.`type` IN %ls) WHERE D.`type` = %s',
|
||||
[RankColumn::inherit_point_earned_by_action->value, RankColumn::inherit_point_earned_by_merge->value],
|
||||
RankColumn::inherit_point_earned->value
|
||||
);
|
||||
|
||||
$db->query(
|
||||
'UPDATE `rank_data` D SET `value` = (SELECT `value` FROM `rank_data` S WHERE S.general_id = D.general_id AND S.`type` = %s) WHERE D.`type` = %s',
|
||||
RankColumn::inherit_point_spent_dynamic->value,
|
||||
RankColumn::inherit_point_spent->value
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use sammo\ActionLogger;
|
||||
use sammo\DB;
|
||||
|
||||
class NewYear extends \sammo\Event\Action
|
||||
{
|
||||
public function run(array $env)
|
||||
{
|
||||
$year = $env['year'];
|
||||
$month = $env['month'];
|
||||
|
||||
$logger = new ActionLogger(0, 0, $year, $month, false);
|
||||
$logger->pushGlobalActionLog("<C>{$year}</>년이 되었습니다.");
|
||||
$logger->pushGeneralHistoryLog("<S>모두들 즐거운 게임 하고 계신가요? ^^ <Y>매너 있는 플레이</> 부탁드리고, 게임보단 <L>건강이 먼저</>란점, 잊지 마세요!</>", $logger::NOTICE_YEAR_MONTH);
|
||||
$logger->flush(); //TODO: globalAction류는 전역에서 관리하는것이 좋을 듯.
|
||||
|
||||
$db = DB::db();
|
||||
|
||||
//나이와 호봉 증가
|
||||
$db->update('general', [
|
||||
'age' => $db->sqleval('age+1'),
|
||||
], true);
|
||||
|
||||
$db->update('general', [
|
||||
'belong' => $db->sqleval('belong+1')
|
||||
], 'nation != 0');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use RuntimeException;
|
||||
use sammo\ActionLogger;
|
||||
use sammo\DB;
|
||||
use sammo\Enums\ResourceType;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
use sammo\KVStorage;
|
||||
use sammo\StringUtil;
|
||||
use sammo\Util;
|
||||
|
||||
use function sammo\getBill;
|
||||
use function sammo\getGoldIncome;
|
||||
use function sammo\getOutcome;
|
||||
use function sammo\getRiceIncome;
|
||||
use function sammo\getWallIncome;
|
||||
use function sammo\pushAdminLog;
|
||||
use function sammo\tab2;
|
||||
|
||||
class ProcessIncome extends \sammo\Event\Action
|
||||
{
|
||||
public function __construct(public string $resource)
|
||||
{
|
||||
if (ResourceType::tryFrom($resource) === null) {
|
||||
throw new RuntimeException('잘못된 자원 타입');
|
||||
}
|
||||
}
|
||||
|
||||
private function processGoldIncome(array $env)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
[$year, $month] = [$env['year'], $env['month']];
|
||||
$adminLog = [];
|
||||
|
||||
|
||||
$nationList = $db->query('SELECT name,nation,capital,gold,level,rate_tmp,bill,type from nation');
|
||||
$cityListByNation = Util::arrayGroupBy($db->query('SELECT * FROM city'), 'nation');
|
||||
$generalRawListByNation = Util::arrayGroupBy($db->query('SELECT no,name,nation,gold,officer_level,dedication,city FROM general WHERE npc != 5'), 'nation');
|
||||
|
||||
//국가별 처리
|
||||
foreach ($nationList as $nation) {
|
||||
$nationID = $nation['nation'];
|
||||
|
||||
$generalRawList = $generalRawListByNation[$nationID];
|
||||
$income = getGoldIncome($nationID, $nation['level'], $nation['rate_tmp'], $nation['capital'], $nation['type'], $cityListByNation[$nationID] ?? []);
|
||||
$originoutcome = getOutcome(100, $generalRawList);
|
||||
$outcome = Util::round($nation['bill'] / 100 * $originoutcome);
|
||||
|
||||
// 실제 지급량 계산
|
||||
$nation['gold'] += $income;
|
||||
// 기본량도 안될경우
|
||||
if ($nation['gold'] < GameConst::$basegold) {
|
||||
$realoutcome = 0;
|
||||
// 실지급률
|
||||
$ratio = 0;
|
||||
//기본량은 넘지만 요구량이 안될경우
|
||||
} elseif ($nation['gold'] - GameConst::$basegold < $outcome) {
|
||||
$realoutcome = $nation['gold'] - GameConst::$basegold;
|
||||
$nation['gold'] = GameConst::$basegold;
|
||||
// 실지급률
|
||||
$ratio = $realoutcome / $originoutcome;
|
||||
} else {
|
||||
$realoutcome = $outcome;
|
||||
$nation['gold'] -= $realoutcome;
|
||||
// 실지급률
|
||||
$ratio = $realoutcome / $originoutcome;
|
||||
}
|
||||
$nation['gold'] = Util::valueFit($nation['gold'], GameConst::$basegold);
|
||||
$adminLog[] = StringUtil::padStringAlignRight((string)$nation['name'], 12, " ")
|
||||
. " // 세금 : " . StringUtil::padStringAlignRight((string)$income, 6, " ")
|
||||
. " // 세출 : " . StringUtil::padStringAlignRight((string)$originoutcome, 6, " ")
|
||||
. " // 실제 : " . tab2((string)$realoutcome, 6, " ")
|
||||
. " // 지급률 : " . tab2((string)round($ratio * 100, 2), 5, " ")
|
||||
. " % // 결과금 : " . tab2((string)$nation['gold'], 6, " ");
|
||||
|
||||
$incomeText = number_format($income);
|
||||
$incomeLog = "이번 수입은 금 <C>$incomeText</>입니다.";
|
||||
$nationStor = KVStorage::getStorage($db, $nationID, 'nation_env');
|
||||
$nationStor->prev_income_gold = $income;
|
||||
|
||||
$db->update('nation', [
|
||||
'gold' => $nation['gold']
|
||||
], 'nation=%i', $nationID);
|
||||
|
||||
// 각 장수들에게 지급
|
||||
foreach ($generalRawList as $rawGeneral) {
|
||||
$generalObj = new General($rawGeneral, null, null, null, $year, $month, false);
|
||||
$gold = Util::round(getBill($generalObj->getVar('dedication')) * $ratio);
|
||||
$generalObj->increaseVar('gold', $gold);
|
||||
|
||||
$logger = $generalObj->getLogger();
|
||||
if ($generalObj->getVar('officer_level') > 4) {
|
||||
$logger->pushGeneralActionLog($incomeLog, $logger::PLAIN);
|
||||
}
|
||||
|
||||
$goldText = number_format($gold);
|
||||
$logger->pushGeneralActionLog("봉급으로 금 <C>$goldText</>을 받았습니다.", $logger::PLAIN);
|
||||
$generalObj->applyDB($db);
|
||||
}
|
||||
}
|
||||
|
||||
$logger = new ActionLogger(0, 0, $year, $month);
|
||||
$logger->pushGlobalHistoryLog('<W><b>【지급】</b></>봄이 되어 봉록에 따라 자금이 지급됩니다.');
|
||||
$logger->flush();
|
||||
|
||||
pushAdminLog($adminLog);
|
||||
}
|
||||
|
||||
private function processRiceIncome(array $env)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
[$year, $month] = [$env['year'], $env['month']];
|
||||
$adminLog = [];
|
||||
|
||||
$nationList = $db->query('SELECT name,level,nation,capital,rice,rate_tmp,bill,type from nation');
|
||||
$cityListByNation = Util::arrayGroupBy($db->query('SELECT * FROM city'), 'nation');
|
||||
$generalRawListByNation = Util::arrayGroupBy($db->query('SELECT no,name,nation,rice,officer_level,dedication,city FROM general WHERE npc != 5'), 'nation');
|
||||
|
||||
//국가별 처리
|
||||
foreach ($nationList as $nation) {
|
||||
$nationID = $nation['nation'];
|
||||
|
||||
$generalRawList = $generalRawListByNation[$nationID];
|
||||
$income = getRiceIncome($nation['nation'], $nation['level'], $nation['rate_tmp'], $nation['capital'], $nation['type'], $cityListByNation[$nationID] ?? []);
|
||||
$income += getWallIncome($nation['nation'], $nation['level'], $nation['rate_tmp'], $nation['capital'], $nation['type'], $cityListByNation[$nationID] ?? []);
|
||||
$originoutcome = getOutcome(100, $generalRawList);
|
||||
$outcome = Util::round($nation['bill'] / 100 * $originoutcome);
|
||||
|
||||
// 실제 지급량 계산
|
||||
$nation['rice'] += $income;
|
||||
// 기본량도 안될경우
|
||||
if ($nation['rice'] < GameConst::$baserice) {
|
||||
$realoutcome = 0;
|
||||
// 실지급률
|
||||
$ratio = 0;
|
||||
//기본량은 넘지만 요구량이 안될경우
|
||||
} elseif ($nation['rice'] - GameConst::$baserice < $outcome) {
|
||||
$realoutcome = $nation['rice'] - GameConst::$baserice;
|
||||
$nation['rice'] = GameConst::$baserice;
|
||||
// 실지급률
|
||||
$ratio = $realoutcome / $originoutcome;
|
||||
} else {
|
||||
$realoutcome = $outcome;
|
||||
$nation['rice'] -= $realoutcome;
|
||||
// 실지급률
|
||||
$ratio = $realoutcome / $originoutcome;
|
||||
}
|
||||
$nation['rice'] = Util::valueFit($nation['rice'], GameConst::$baserice);
|
||||
$adminLog[] = StringUtil::padStringAlignRight($nation['name'], 12, " ")
|
||||
. " // 세곡 : " . StringUtil::padStringAlignRight((string)$income, 6, " ")
|
||||
. " // 세출 : " . StringUtil::padStringAlignRight((string)$originoutcome, 6, " ")
|
||||
. " // 실제 : " . tab2((string)$realoutcome, 6, " ")
|
||||
. " // 지급률 : " . tab2((string)round($ratio * 100, 2), 5, " ")
|
||||
. " % // 결과곡 : " . tab2((string)$nation['rice'], 6, " ");
|
||||
|
||||
$incomeText = number_format($income);
|
||||
$incomeLog = "이번 수입은 쌀 <C>$incomeText</>입니다.";
|
||||
$nationStor = KVStorage::getStorage($db, $nationID, 'nation_env');
|
||||
$nationStor->prev_income_rice = $income;
|
||||
|
||||
$db->update('nation', [
|
||||
'rice' => $nation['rice']
|
||||
], 'nation=%i', $nationID);
|
||||
|
||||
// 각 장수들에게 지급
|
||||
foreach ($generalRawList as $rawGeneral) {
|
||||
$generalObj = new General($rawGeneral, null, null, null, $year, $month, false);
|
||||
$rice = Util::round(getBill($generalObj->getVar('dedication')) * $ratio);
|
||||
$generalObj->increaseVar('rice', $rice);
|
||||
|
||||
$logger = $generalObj->getLogger();
|
||||
if ($generalObj->getVar('officer_level') > 4) {
|
||||
$logger->pushGeneralActionLog($incomeLog, $logger::PLAIN);
|
||||
}
|
||||
$riceText = number_format($rice);
|
||||
$logger->pushGeneralActionLog("봉급으로 쌀 <C>$riceText</>을 받았습니다.", $logger::PLAIN);
|
||||
$generalObj->applyDB($db);
|
||||
}
|
||||
}
|
||||
|
||||
$logger = new ActionLogger(0, 0, $year, $month);
|
||||
$logger->pushGlobalHistoryLog('<W><b>【지급】</b></>가을이 되어 봉록에 따라 군량이 지급됩니다.');
|
||||
$logger->flush();
|
||||
|
||||
pushAdminLog($adminLog);
|
||||
}
|
||||
|
||||
public function run(array $env)
|
||||
{
|
||||
if ($this->resource === ResourceType::gold->value) {
|
||||
$this->processGoldIncome($env);
|
||||
} else {
|
||||
$this->processRiceIncome($env);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use RuntimeException;
|
||||
use sammo\DB;
|
||||
use sammo\Enums\ResourceType;
|
||||
use sammo\GameConst;
|
||||
use sammo\KVStorage;
|
||||
|
||||
use function sammo\buildNationTypeClass;
|
||||
use function sammo\popIncrease;
|
||||
use function sammo\pushGlobalHistoryLog;
|
||||
|
||||
class ProcessSemiAnnual extends \sammo\Event\Action
|
||||
{
|
||||
public function __construct(public string $resource)
|
||||
{
|
||||
if(ResourceType::tryFrom($resource) === null){
|
||||
throw new RuntimeException('잘못된 자원 타입');
|
||||
}
|
||||
}
|
||||
|
||||
public function popIncrease()
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
$nationList = $db->queryAllLists('SELECT nation,rate_tmp,type FROM nation');
|
||||
|
||||
// 인구 및 민심
|
||||
|
||||
$db->update('city', [
|
||||
'trust' => 50,
|
||||
'agri' => $db->sqleval('agri * 0.99'),
|
||||
'comm' => $db->sqleval('comm * 0.99'),
|
||||
'secu' => $db->sqleval('secu * 0.99'),
|
||||
'def' => $db->sqleval('def * 0.99'),
|
||||
'wall' => $db->sqleval('wall * 0.99'),
|
||||
], 'nation=0');
|
||||
|
||||
foreach ($nationList as [$nationID, $taxRate, $nationType]) {
|
||||
$nationTypeObj = buildNationTypeClass($nationType);
|
||||
|
||||
|
||||
$popRatio = (30 - $taxRate) / 200; // 20일때 5% 5일때 12.5% 50일때 -10%
|
||||
$popRatio = $nationTypeObj->onCalcNationalIncome('pop', $popRatio);
|
||||
|
||||
$updateVar = [];
|
||||
if ($popRatio >= 0) {
|
||||
$updateVar['pop'] = $db->sqleval('least(pop_max, %i + pop * (1 + %d * (1 + secu / secu_max / 10)))', GameConst::$basePopIncreaseAmount, $popRatio);
|
||||
} else {
|
||||
$updateVar['pop'] = $db->sqleval('least(pop_max, %i + pop * (1 + %d * (1 - secu / secu_max / 10)))', GameConst::$basePopIncreaseAmount, $popRatio);
|
||||
}
|
||||
|
||||
$genericRatio = (20 - $taxRate) / 200; // 20일때 0% 0일때 10% 100일때 -40%
|
||||
foreach (['agri', 'comm', 'secu', 'def', 'wall'] as $key) {
|
||||
$updateVar[$key] = $db->sqleval('least(%b, %b * (1 + %d))', $key . '_max', $key, $genericRatio);
|
||||
}
|
||||
|
||||
$trustDiff = 20 - $taxRate;
|
||||
$updateVar['trust'] = $db->sqleval('greatest(0, least(100, trust + %i))', $trustDiff);
|
||||
|
||||
$db->update('city', $updateVar, 'nation = %i AND supply = 1', $nationID);
|
||||
}
|
||||
}
|
||||
|
||||
public function run(array $env)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
|
||||
$resource = $this->resource;
|
||||
|
||||
// 내정 1% 감소
|
||||
$db->update('city', [
|
||||
'dead' => 0,
|
||||
'agri' => $db->sqleval('agri * 0.99'),
|
||||
'comm' => $db->sqleval('comm * 0.99'),
|
||||
'secu' => $db->sqleval('secu * 0.99'),
|
||||
'def' => $db->sqleval('def * 0.99'),
|
||||
'wall' => $db->sqleval('wall * 0.99'),
|
||||
], true);
|
||||
|
||||
//인구 증가
|
||||
popIncrease();
|
||||
|
||||
// > 10000 유지비 3%, > 1000 유지비 1%
|
||||
// 유지비 1%
|
||||
$db->update('general', [
|
||||
$resource => $db->sqleval('IF(%b > 10000, %b * 0.97, %b * 0.99)', $resource, $resource, $resource)
|
||||
], '%b > 1000', $resource);
|
||||
|
||||
// > 100000 유지비 5%, > 100000 유지비 3%, > 1000 유지비 1%
|
||||
$db->update('nation', [
|
||||
$resource => $db->sqleval('IF(%b > 100000, %b * 0.95, IF(%b > 10000, %b * 0.97, %b * 0.99))', $resource, $resource, $resource, $resource, $resource)
|
||||
], '%b > 1000', $resource);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use sammo\DB;
|
||||
use sammo\Util;
|
||||
|
||||
use function sammo\getAllNationStaticInfo;
|
||||
use function sammo\getWarGoldIncome;
|
||||
|
||||
class ProcessWarIncome extends \sammo\Event\Action
|
||||
{
|
||||
public function run(array $env)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
$cityListByNation = Util::arrayGroupBy($db->query('SELECT * FROM city'), 'nation');
|
||||
|
||||
foreach(getAllNationStaticInfo() as $nation){
|
||||
if($nation['level'] <= 0){
|
||||
continue;
|
||||
}
|
||||
$nationID = $nation['nation'];
|
||||
$income = getWarGoldIncome($nation['type'], $cityListByNation[$nationID]??[]);
|
||||
$db->update('nation', [
|
||||
'gold'=>$db->sqleval('gold + %i', $income)
|
||||
], 'nation=%i', $nationID);
|
||||
}
|
||||
|
||||
// 10%수입, 20%부상병
|
||||
$db->update('city', [
|
||||
'pop'=>$db->sqleval('pop + dead * %d', 0.2),
|
||||
'dead'=>0
|
||||
], true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use sammo\DB;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
use sammo\KVStorage;
|
||||
use sammo\LiteHashDRBG;
|
||||
use sammo\RandUtil;
|
||||
use sammo\UniqueConst;
|
||||
use sammo\Util;
|
||||
|
||||
use function sammo\_setGeneralCommand;
|
||||
use function sammo\buildGeneralCommandClass;
|
||||
|
||||
class ProvideNPCTroopLeader extends \sammo\Event\Action
|
||||
{
|
||||
const MaxNPCTroopLeaderCnt = [
|
||||
1 => 0,
|
||||
2 => 1,
|
||||
3 => 3,
|
||||
4 => 4,
|
||||
5 => 6,
|
||||
6 => 7,
|
||||
7 => 9
|
||||
];
|
||||
|
||||
public function run(array $env)
|
||||
{
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
$NPCTroopLeaderCntByNation = [];
|
||||
foreach ($db->queryAllLists('SELECT nation,count(no) FROM general WHERE npc = 5 GROUP BY nation') as [$nationID, $NPCTroopLeaderCnt]) {
|
||||
$NPCTroopLeaderCntByNation[$nationID] = $NPCTroopLeaderCnt;
|
||||
};
|
||||
|
||||
$year = $env['year'];
|
||||
$month = $env['month'];
|
||||
|
||||
foreach ($db->query('SELECT nation,name,level,tech,aux FROM nation') as $nation) {
|
||||
$nationID = $nation['nation'];
|
||||
$maxNPCTroopLeaderCnt = self::MaxNPCTroopLeaderCnt[$nation['level']];
|
||||
$NPCTroopLeaderCnt = $NPCTroopLeaderCntByNation[$nationID] ?? 0;
|
||||
|
||||
if ($NPCTroopLeaderCnt >= $maxNPCTroopLeaderCnt) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$lastNPCTroopLeaderID = $gameStor->lastNPCTroopLeaderID ?? 0;
|
||||
|
||||
$troopLeaderRng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||
UniqueConst::$hiddenSeed,
|
||||
'troopLeader',
|
||||
$year,
|
||||
$month,
|
||||
$nationID
|
||||
)));
|
||||
|
||||
while ($NPCTroopLeaderCnt < $maxNPCTroopLeaderCnt) {
|
||||
$lastNPCTroopLeaderID += 1;
|
||||
$npcObj = new \sammo\Scenario\GeneralBuilder(
|
||||
$troopLeaderRng,
|
||||
sprintf('부대장%4d', $lastNPCTroopLeaderID),
|
||||
false,
|
||||
null,
|
||||
$nation['nation']
|
||||
);
|
||||
$npcObj->setAffinity(999)->setStat(10, 10, 10)
|
||||
->setSpecialSingle('척사')->setEgo('che_은둔')
|
||||
->setKillturn(70)->setGoldRice(0, 0)
|
||||
->setNPCType(5)->fillRemainSpecAsZero($env);
|
||||
$npcObj->build($env);
|
||||
$npcID = $npcObj->getGeneralID();
|
||||
|
||||
$db->insert('troop', [
|
||||
'troop_leader' => $npcID,
|
||||
'name' => $npcObj->getGeneralName(),
|
||||
'nation' => $nation['nation'],
|
||||
]);
|
||||
$db->update('general', [
|
||||
'troop' => $npcID
|
||||
], 'no=%i', $npcID);
|
||||
|
||||
$cmd = buildGeneralCommandClass('che_집합', General::createGeneralObjFromDB($npcID), $env);
|
||||
_setGeneralCommand($cmd, iterator_to_array(Util::range(GameConst::$maxTurn)));
|
||||
$NPCTroopLeaderCnt += 1;
|
||||
$gameStor->lastNPCTroopLeaderID = $lastNPCTroopLeaderID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use sammo\ActionLogger;
|
||||
use sammo\DB;
|
||||
use sammo\General;
|
||||
use sammo\KVStorage;
|
||||
use sammo\LiteHashDRBG;
|
||||
use sammo\RandUtil;
|
||||
use sammo\UniqueConst;
|
||||
use sammo\Util;
|
||||
|
||||
use function sammo\SabotageInjury;
|
||||
|
||||
class RaiseDisaster extends \sammo\Event\Action
|
||||
{
|
||||
public function run(array $env)
|
||||
{
|
||||
$db = DB::db();
|
||||
$startYear = $env['startyear'];
|
||||
$year = $env['year'];
|
||||
$month = $env['month'];
|
||||
|
||||
$rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||
UniqueConst::$hiddenSeed,
|
||||
'disater',
|
||||
$year,
|
||||
$month,
|
||||
)));
|
||||
|
||||
//재난표시 초기화
|
||||
$db->update('city', [
|
||||
'state' => 0,
|
||||
], 'state <= 10');
|
||||
|
||||
// 초반 3년은 스킵
|
||||
if ($startYear + 3 > $year) return;
|
||||
|
||||
$boomingRate = [
|
||||
1 => 0,
|
||||
4 => 0.25,
|
||||
7 => 0.25,
|
||||
10 => 0
|
||||
];
|
||||
|
||||
$isGood = $rng->nextBool($boomingRate[$month]);
|
||||
|
||||
|
||||
$targetCityList = [];
|
||||
|
||||
foreach ($db->query('SELECT city,name,secu,secu_max FROM city') as $city) {
|
||||
//호황 발생 도시 선택 ( 기본 2% )
|
||||
//재해 발생 도시 선택 ( 기본 6% )
|
||||
if ($isGood) {
|
||||
$raiseProp = 0.02 + ($city['secu'] / $city['secu_max']) * 0.05; // 2 ~ 7%
|
||||
} else {
|
||||
$raiseProp = 0.06 - ($city['secu'] / $city['secu_max']) * 0.05; // 1 ~ 6%
|
||||
}
|
||||
|
||||
if ($rng->nextBool($raiseProp)) {
|
||||
$targetCityList[] = $city;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$targetCityList) {
|
||||
return;
|
||||
}
|
||||
|
||||
$targetCityNames = "<G><b>" . join(' ', Util::squeezeFromArray($targetCityList, 'name')) . "</b></>";
|
||||
$disasterTextList = [
|
||||
1 => [
|
||||
['<M><b>【재난】</b></>', 4, '역병이 발생하여 도시가 황폐해지고 있습니다.'],
|
||||
['<M><b>【재난】</b></>', 5, '지진으로 피해가 속출하고 있습니다.'],
|
||||
['<M><b>【재난】</b></>', 3, '추위가 풀리지 않아 얼어죽는 백성들이 늘어나고 있습니다.'],
|
||||
['<M><b>【재난】</b></>', 9, '황건적이 출현해 도시를 습격하고 있습니다.'],
|
||||
],
|
||||
4 => [
|
||||
['<M><b>【재난】</b></>', 7, '홍수로 인해 피해가 급증하고 있습니다.'],
|
||||
['<M><b>【재난】</b></>', 5, '지진으로 피해가 속출하고 있습니다.'],
|
||||
['<M><b>【재난】</b></>', 6, '태풍으로 인해 피해가 속출하고 있습니다.'],
|
||||
],
|
||||
7 => [
|
||||
['<M><b>【재난】</b></>', 8, '메뚜기 떼가 발생하여 도시가 황폐해지고 있습니다.'],
|
||||
['<M><b>【재난】</b></>', 5, '지진으로 피해가 속출하고 있습니다.'],
|
||||
['<M><b>【재난】</b></>', 8, '흉년이 들어 굶어죽는 백성들이 늘어나고 있습니다.'],
|
||||
],
|
||||
10 => [
|
||||
['<M><b>【재난】</b></>', 3, '혹한으로 도시가 황폐해지고 있습니다.'],
|
||||
['<M><b>【재난】</b></>', 5, '지진으로 피해가 속출하고 있습니다.'],
|
||||
['<M><b>【재난】</b></>', 3, '눈이 많이 쌓여 도시가 황폐해지고 있습니다.'],
|
||||
['<M><b>【재난】</b></>', 9, '황건적이 출현해 도시를 습격하고 있습니다.'],
|
||||
]
|
||||
];
|
||||
|
||||
$boomingTextList = [
|
||||
1 => null,
|
||||
4 => [
|
||||
['<C><b>【호황】</b></>', 2, '호황으로 도시가 번창하고 있습니다.'],
|
||||
],
|
||||
7 => [
|
||||
['<C><b>【풍작】</b></>', 1, '풍작으로 도시가 번창하고 있습니다.'],
|
||||
],
|
||||
10 => null
|
||||
];
|
||||
|
||||
[$logTitle, $stateCode, $logBody] = $rng->choice(($isGood ? $boomingTextList : $disasterTextList)[$month]);
|
||||
|
||||
$logger = new ActionLogger(0, 0, $year, $month, false);
|
||||
|
||||
$logger->pushGlobalHistoryLog("{$logTitle}{$targetCityNames}에 {$logBody}");
|
||||
$logger->flush();
|
||||
|
||||
if (!$isGood) {
|
||||
$generalListByCity = Util::arrayGroupBy($db->query('SELECT no, name, nation, city, officer_level, injury, leadership, strength, intel, horse, weapon, book, item, crew, crewtype, atmos, train, special, special2 FROM general WHERE city IN %li', Util::squeezeFromArray($targetCityList, 'city')), 'city');
|
||||
//NOTE: 쿼리 1번이지만 복잡하기 vs 쿼리 여러번이지만 조금 더 깔끔하기
|
||||
foreach ($targetCityList as $city) {
|
||||
$affectRatio = Util::valueFit($city['secu'] / $city['secu_max'] / 0.8, 0, 1);
|
||||
$affectRatio = 0.8 + $affectRatio * 0.15;
|
||||
|
||||
$db->update('city', [
|
||||
'state' => $stateCode,
|
||||
'pop' => $db->sqleval('pop * %d', $affectRatio),
|
||||
'trust' => $db->sqleval('trust * %d', $affectRatio),
|
||||
'agri' => $db->sqleval('agri * %d', $affectRatio),
|
||||
'comm' => $db->sqleval('comm * %d', $affectRatio),
|
||||
'secu' => $db->sqleval('secu * %d', $affectRatio),
|
||||
'def' => $db->sqleval('def * %d', $affectRatio),
|
||||
'wall' => $db->sqleval('wall * %d', $affectRatio),
|
||||
], 'city = %i', $city['city']);
|
||||
|
||||
$generalList = array_map(
|
||||
function ($rawGeneral) use ($city, $year, $month) {
|
||||
return new General($rawGeneral, null, $city, null, $year, $month, false);
|
||||
},
|
||||
$generalListByCity[$city['city']] ?? []
|
||||
);
|
||||
|
||||
SabotageInjury($rng, $generalList, '재난');
|
||||
}
|
||||
} else {
|
||||
foreach ($targetCityList as $city) {
|
||||
$affectRatio = Util::valueFit($city['secu'] / $city['secu_max'] / 0.8, 0, 1);
|
||||
$affectRatio = 1.01 + $affectRatio * 0.04;
|
||||
|
||||
$db->update('city', [
|
||||
'state' => $stateCode,
|
||||
'pop' => $db->sqleval('least(pop * %d, pop_max)', $affectRatio),
|
||||
'trust' => $db->sqleval('least(trust * %d, 100)', $affectRatio),
|
||||
'agri' => $db->sqleval('least(agri * %d, agri_max)', $affectRatio),
|
||||
'comm' => $db->sqleval('least(comm * %d, comm_max)', $affectRatio),
|
||||
'secu' => $db->sqleval('least(secu * %d, secu_max)', $affectRatio),
|
||||
'def' => $db->sqleval('least(def * %d, def_max)', $affectRatio),
|
||||
'wall' => $db->sqleval('least(wall * %d, wall_max)', $affectRatio),
|
||||
], 'city = %i', $city['city']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use sammo\DB;
|
||||
use sammo\LiteHashDRBG;
|
||||
use sammo\RandUtil;
|
||||
use sammo\UniqueConst;
|
||||
use sammo\Util;
|
||||
|
||||
class RandomizeCityTradeRate extends \sammo\Event\Action
|
||||
{
|
||||
public function run(array $env)
|
||||
{
|
||||
$year = $env['year'];
|
||||
$month = $env['month'];
|
||||
|
||||
$rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||
UniqueConst::$hiddenSeed,
|
||||
'randomizeCityTradeRate',
|
||||
$year,
|
||||
$month,
|
||||
)));
|
||||
|
||||
$db = DB::db();
|
||||
foreach ($db->query('SELECT city,level FROM city') as $city) {
|
||||
//시세
|
||||
$prob = [
|
||||
1 => 0,
|
||||
2 => 0,
|
||||
3 => 0,
|
||||
4 => 0.2,
|
||||
5 => 0.4,
|
||||
6 => 0.6,
|
||||
7 => 0.8,
|
||||
8 => 1
|
||||
][$city['level']];
|
||||
if ($prob > 0 && $rng->nextBool($prob)) {
|
||||
$trade = $rng->nextRangeInt(95, 105);
|
||||
} else {
|
||||
$trade = null;
|
||||
}
|
||||
$db->update('city', [
|
||||
'trade' => $trade
|
||||
], 'city=%i', $city['city']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use sammo\DB;
|
||||
|
||||
class ResetOfficerLock extends \sammo\Event\Action
|
||||
{
|
||||
public function run(array $env)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
//천도 제한 해제, 관직 변경 제한 해제
|
||||
$db->update('nation', [
|
||||
'chief_set' => 0,
|
||||
], true);
|
||||
//관직 변경 제한 해제
|
||||
$db->update('city', [
|
||||
'officer_set' => 0,
|
||||
], true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Event\Action;
|
||||
|
||||
use sammo\ActionLogger;
|
||||
use sammo\CityConst;
|
||||
use sammo\DB;
|
||||
use sammo\JosaUtil;
|
||||
use sammo\Util;
|
||||
|
||||
class UpdateCitySupply extends \sammo\Event\Action
|
||||
{
|
||||
public function run(array $env)
|
||||
{
|
||||
$db = DB::db();
|
||||
|
||||
$cities = [];
|
||||
foreach ($db->query('SELECT city, nation FROM city WHERE nation != 0') as $city) {
|
||||
$newCity = new \stdClass();
|
||||
$newCity->id = Util::toInt($city['city']);
|
||||
$newCity->nation = Util::toInt($city['nation']);
|
||||
$newCity->supply = false;
|
||||
|
||||
$cities[$newCity->id] = $newCity;
|
||||
}
|
||||
|
||||
$queue = new \SplQueue();
|
||||
foreach ($db->queryAllLists('SELECT capital, nation FROM nation WHERE `level` > 0') as list($capitalID, $nationID)) {
|
||||
if (!key_exists($capitalID, $cities)) {
|
||||
continue;
|
||||
}
|
||||
$city = $cities[$capitalID];
|
||||
if ($nationID != $city->nation) {
|
||||
continue;
|
||||
}
|
||||
$city->supply = true;
|
||||
$queue->enqueue($city);
|
||||
}
|
||||
|
||||
while (!$queue->isEmpty()) {
|
||||
$cityLink = $queue->dequeue();
|
||||
$city = CityConst::byID($cityLink->id);
|
||||
|
||||
foreach (array_keys($city->path) as $connCityID) {
|
||||
if (!key_exists($connCityID, $cities)) {
|
||||
continue;
|
||||
}
|
||||
$connCity = $cities[$connCityID];
|
||||
if ($connCity->nation != $cityLink->nation) {
|
||||
continue;
|
||||
}
|
||||
if ($connCity->supply) {
|
||||
continue;
|
||||
}
|
||||
$connCity->supply = true;
|
||||
$queue->enqueue($connCity);
|
||||
}
|
||||
}
|
||||
|
||||
$db->update('city', [
|
||||
'supply' => 1
|
||||
], 'nation=0');
|
||||
|
||||
$db->update('city', [
|
||||
'supply' => 0
|
||||
], 'nation!=0');
|
||||
|
||||
$supply = [];
|
||||
|
||||
foreach ($cities as $city) {
|
||||
if ($city->supply) {
|
||||
$supply[] = $city->id;
|
||||
}
|
||||
}
|
||||
|
||||
if ($supply) {
|
||||
$db->update('city', [
|
||||
'supply' => 1
|
||||
], 'city IN %li', $supply);
|
||||
}
|
||||
|
||||
//미보급도시 10% 감소
|
||||
$db->update('city', [
|
||||
'pop' => $db->sqleval('pop * 0.9'),
|
||||
'trust' => $db->sqleval('trust * 0.9'),
|
||||
'agri' => $db->sqleval('agri * 0.9'),
|
||||
'comm' => $db->sqleval('comm * 0.9'),
|
||||
'secu' => $db->sqleval('secu * 0.9'),
|
||||
'def' => $db->sqleval('def * 0.9'),
|
||||
'wall' => $db->sqleval('wall * 0.9'),
|
||||
], 'supply = 0');
|
||||
//미보급도시 장수 병 훈 사 5%감소
|
||||
//NOTE: update inner join도 가능하지만, meekrodb 기준으로 깔끔하게.
|
||||
$unsuppliedCities = $db->query('SELECT city, nation, trust, name FROM city WHERE supply = 0');
|
||||
foreach (Util::arrayGroupBy($unsuppliedCities, 'nation') as $nationID => $cityList) {
|
||||
$cityIDList = Util::squeezeFromArray($cityList, 'city');
|
||||
$db->update('general', [
|
||||
'crew' => $db->sqleval('crew*0.95'),
|
||||
'atmos' => $db->sqleval('atmos*0.95'),
|
||||
'train' => $db->sqleval('train*0.95'),
|
||||
], 'city IN %li AND nation = %i', $cityIDList, $nationID);
|
||||
}
|
||||
|
||||
//민심30이하 공백지 처리
|
||||
$lostCities = [];
|
||||
foreach ($unsuppliedCities as $unsuppliedCity) {
|
||||
if ($unsuppliedCity['trust'] >= 30) {
|
||||
continue;
|
||||
}
|
||||
$lostCities[$unsuppliedCity['city']] = $unsuppliedCity;
|
||||
}
|
||||
|
||||
$logger = new ActionLogger(0, 0, $env['year'], $env['month']);
|
||||
|
||||
if ($lostCities) {
|
||||
foreach ($lostCities as $lostCity) {
|
||||
$josaYi = JosaUtil::pick($lostCity['name'], '이');
|
||||
$logger->pushGlobalHistoryLog("<R><b>【고립】</b></><G><b>{$lostCity['name']}</b></>{$josaYi} 보급이 끊겨 <R>미지배</> 도시가 되었습니다.");
|
||||
}
|
||||
$db->update('general', [
|
||||
'officer_level' => 1,
|
||||
'officer_city' => 0
|
||||
], 'officer_city IN %li', array_keys($lostCities));
|
||||
$db->update('city', [
|
||||
'nation' => 0,
|
||||
'officer_set' => 0,
|
||||
'conflict' => '{}',
|
||||
'term' => 0,
|
||||
'front' => 0
|
||||
], 'city IN %li', array_keys($lostCities));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user