Files
core/hwe/sammo/Command/Nation/che_불가침수락.php
T
Hide_D b4d7acb827 유산 포인트 시스템, 추가 기수 대비 (#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

236 lines
6.8 KiB
PHP

<?php
namespace sammo\Command\Nation;
use \sammo\DB;
use \sammo\Util;
use \sammo\JosaUtil;
use \sammo\General;
use \sammo\DummyGeneral;
use \sammo\ActionLogger;
use \sammo\GameConst;
use \sammo\LastTurn;
use \sammo\GameUnitConst;
use \sammo\Command;
use \sammo\MessageTarget;
use \sammo\DiplomaticMessage;
use \sammo\Message;
use function \sammo\getDomesticExpLevelBonus;
use function \sammo\CriticalRatioDomestic;
use function \sammo\CriticalScoreEx;
use function \sammo\getAllNationStaticInfo;
use function \sammo\getNationStaticInfo;
use function \sammo\GetImageUR;
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Json;
use sammo\KVStorage;
class che_불가침수락 extends Command\NationCommand
{
static protected $actionName = '불가침 수락';
static public $reqArg = true;
protected function argTest(): bool
{
if ($this->arg === null) {
return false;
}
if (!key_exists('destNationID', $this->arg)) {
return false;
}
$destNationID = $this->arg['destNationID'];
if (!is_int($destNationID)) {
return false;
}
if ($destNationID < 1) {
return false;
}
if (!key_exists('destGeneralID', $this->arg)) {
return false;
}
$destGeneralID = $this->arg['destGeneralID'];
if (!is_int($destGeneralID)) {
return false;
}
if ($destGeneralID <= 0) {
return false;
}
if ($destGeneralID == $this->generalObj->getID()) {
return false;
}
if (!key_exists('year', $this->arg) || !key_exists('month', $this->arg)) {
return false;
}
$year = $this->arg['year'];
$month = $this->arg['month'];
if (!is_int($year) || !is_int($month)) {
return false;
}
if ($month < 1 || 12 < $month) {
return false;
}
if ($year < $this->env['startyear']) {
return false;
}
$this->arg = [
'destNationID' => $destNationID,
'destGeneralID' => $destGeneralID,
'year' => $year,
'month' => $month,
];
return true;
}
protected function init()
{
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$this->permissionConstraints = [
ConstraintHelper::AlwaysFail('예약 불가능 커맨드')
];
}
protected function initWithArg()
{
$env = $this->env;
$relYear = $env['year'] - $env['startyear'];
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], [], 1);
$this->setDestGeneral($destGeneral);
$this->setDestNation($this->arg['destNationID']);
//NOTE: 개월에서 기한으로 바뀜
$year = $this->arg['year'];
$month = $this->arg['month'];
$currentMonth = $env['year'] * 12 + $env['month'] - 1;
$reqMonth = $year * 12 + $month - 1;
$nationID = $this->nation['nation'];
if ($reqMonth <= $currentMonth) {
$this->fullConditionConstraints = [
ConstraintHelper::AlwaysFail('이미 기한이 지났습니다.')
];
return;
}
$this->fullConditionConstraints = [
ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::ReqDestNationValue('nation', '소속', '==', $this->destGeneralObj->getNationID(), '제의 장수가 국가 소속이 아닙니다'),
ConstraintHelper::DisallowDiplomacyBetweenStatus([
0 => '아국과 이미 교전중입니다.',
1 => '아국과 이미 선포중입니다.',
]),
];
}
public function canDisplay():bool{
return false;
}
public function getCost(): array
{
return [0, 0];
}
public function getPreReqTurn(): int
{
return 0;
}
public function getPostReqTurn(): int
{
return 0;
}
public function getBrief(): string
{
$commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
$year = $this->arg['year'];
$month = $this->arg['month'];
return "{$year}{$month}월까지 불가침 합의";
}
public function run(): bool
{
if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$env = $this->env;
$general = $this->generalObj;
$nation = $this->nation;
$nationID = $nation['nation'];
$nationName = $nation['name'];
$destNation = $this->destNation;
$destNationID = $destNation['nation'];
$destNationName = $destNation['name'];
$destNationStor = KVStorage::getStorage(DB::db(), $destNationID, 'nation_env');
$destRecvAssist = $destNationStor->getValue('recv_assist')??[];
$destRespAssist = $destNationStor->getValue('resp_assist')??[];
$destRespAssist["n{$nationID}"] = [$nationID, $destRecvAssist["n{$nationID}"][1]??0];
$destNationStor->setValue('resp_assist', $destRespAssist);
$year = $this->arg['year'];
$month = $this->arg['month'];
$logger = $general->getLogger();
$destLogger = $this->destGeneralObj->getLogger();
$currentMonth = $env['year'] * 12 + $env['month'] - 1;
$reqMonth = $year * 12 + $month - 1;
$db->update(
'diplomacy',
[
'state' => 7,
'term' => $reqMonth - $currentMonth
],
'(me=%i AND you=%i) OR (you=%i AND me=%i)',
$nationID,
$destNationID,
$nationID,
$destNationID
);
$josaWa = JosaUtil::pick($destNationName, '와');
$logger->pushGeneralActionLog("<D><b>{$destNationName}</b></>{$josaWa} <C>$year</>년 <C>{$month}</>월까지 불가침에 성공했습니다.", ActionLogger::PLAIN);
$logger->pushGeneralHistoryLog("<D><b>{$destNationName}</b></>{$josaWa} {$year}{$month}월까지 불가침 성공");
$josaWa = JosaUtil::pick($nationName, '와');
$destLogger->pushGeneralActionLog("<D><b>{$nationName}</b></>{$josaWa} <C>$year</>년 <C>{$month}</>월까지 불가침에 성공했습니다.", ActionLogger::PLAIN);
$destLogger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>{$josaWa} {$year}{$month}월까지 불가침 성공");
$general->applyDB($db);
$destLogger->flush();
return true;
}
}