Files
core/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php
T
Hide_D d17b2518df 전역 하드코드 이벤트를 동적 변경 영역으로 이동 (#230)
기존에 작성해두었던 EventHandler 시스템으로 하드코드 이벤트 이동
- 매달
  - 보급선 설정
  - 전쟁 단기 수입 설정
  - 부대장 부여
- 1월
  - 유산 포인트 계산
  - 도시 인구 변화
  - 수입
  - 관직 제한 해제
  - 재난
  - 상인
  - 새해 알림
  - 특기 부여
- 4월
  - 관직 제한 해제
  - 재난
- 7월
  - 유산 포인트 계산
  - 도시 인구 변화
  - 수입
  - 관직 제한 해제
  - 재난
  - 상인
- 10월
  - 관직 제한 해제
  - 재난
- 천통 시
  - 유산 포인트 계산

Reviewed-on: https://storage.hided.net/gitea/devsam/core/pulls/230
2023-03-12 17:14:49 +09:00

94 lines
2.6 KiB
PHP

<?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;
}
}
}
}