불가침 제의 구현
This commit is contained in:
@@ -259,96 +259,6 @@ function process_53(&$general) {
|
|||||||
pushGenLog($general, ["<C>●</>{$month}월:<D><b>{$destNation['name']}</b></>{$josaRo} 통합 제의 서신을 보냈습니다.<1>$date</>"]);
|
pushGenLog($general, ["<C>●</>{$month}월:<D><b>{$destNation['name']}</b></>{$josaRo} 통합 제의 서신을 보냈습니다.<1>$date</>"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function process_61(&$general) {
|
|
||||||
$db = DB::db();
|
|
||||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
|
||||||
$date = substr($general['turntime'],11,5);
|
|
||||||
list($year, $month, $turnterm) = $gameStor->getValuesAsArray(['year','month','turnterm']);
|
|
||||||
|
|
||||||
if($general['level'] < 5 || $general['nation']==0) {
|
|
||||||
pushGenLog($general, ["<C>●</>{$month}월:수뇌부가 아닙니다. 제의 실패. <1>$date</>"]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$supply = $db->queryFirstField('SELECT supply FROM city WHERE city=%i AND nation=%i', $general['city'], $general['nation']);
|
|
||||||
$myTurn = $db->queryFirstField('SELECT %b FROM nation WHERE nation=%i', "l{$general['level']}turn0", $general['nation']);
|
|
||||||
|
|
||||||
$command = DecodeCommand($myTurn);
|
|
||||||
$which = $command[1];
|
|
||||||
$when = Util::valueFit($command[2], 1, 20);
|
|
||||||
|
|
||||||
$srcNation = getNationStaticInfo($general['nation']);
|
|
||||||
$destNation = getNationStaticInfo($which);
|
|
||||||
|
|
||||||
if($destNation['nation'] == 0) {
|
|
||||||
pushGenLog($general, ["<C>●</>{$month}월:멸망한 국가입니다. 제의 실패. <1>$date</>"]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($supply === null) {
|
|
||||||
pushGenLog($general, ["<C>●</>{$month}월:아국이 아닙니다. 제의 실패. <1>$date</>"]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($supply === 0) {
|
|
||||||
pushGenLog($general, ["<C>●</>{$month}월:고립된 도시입니다. 제의 실패. <1>$date</>"]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 상대에게 발송
|
|
||||||
$src = new MessageTarget(
|
|
||||||
$general['no'],
|
|
||||||
$general['name'],
|
|
||||||
$srcNation['nation'],
|
|
||||||
$srcNation['name'],
|
|
||||||
$srcNation['color'],
|
|
||||||
GetImageURL($general['imgsvr'], $general['picture'])
|
|
||||||
);
|
|
||||||
|
|
||||||
$dest = new MessageTarget(
|
|
||||||
0,
|
|
||||||
'',
|
|
||||||
$destNation['nation'],
|
|
||||||
$destNation['name'],
|
|
||||||
$destNation['color']
|
|
||||||
);
|
|
||||||
|
|
||||||
$now = new \DateTime($date);
|
|
||||||
$validUntil = new \DateTime($date);
|
|
||||||
$validMinutes = max(30, $turnterm*3);
|
|
||||||
$validUntil->add(new \DateInterval("PT{$validMinutes}M"));
|
|
||||||
|
|
||||||
//FIXME: 현재 command가 숫자로만 이루어져 있어서 문자열을 처리할 수 없다.
|
|
||||||
//XXX: 으악.
|
|
||||||
//TODO: 커맨드 처리 방식을 json으로 변경
|
|
||||||
$option = $db->queryFirstField('SELECT reserved FROM diplomacy WHERE me=%i AND you=%i', $src->nationID, $dest->nationID);
|
|
||||||
|
|
||||||
$msg = new DiplomaticMessage(
|
|
||||||
Message::MSGTYPE_DIPLOMACY,
|
|
||||||
$src,
|
|
||||||
$dest,
|
|
||||||
"{$srcNation['name']}의 {$when}년 불가침 제의 서신",
|
|
||||||
$now,
|
|
||||||
$validUntil,
|
|
||||||
[
|
|
||||||
'action'=>DiplomaticMessage::TYPE_NO_AGGRESSION,
|
|
||||||
'year'=>$when,
|
|
||||||
'option'=>$option
|
|
||||||
]
|
|
||||||
);
|
|
||||||
$msg->send();
|
|
||||||
|
|
||||||
//NOTE: 현재 내무부 외교란의 비고는 diplomacy가 기준이니까 유지할 필요는 있다.
|
|
||||||
//FIXME: 외교란도 message란의 diplomacy를 참조하든가 하도록.
|
|
||||||
$db->update('diplomacy', [
|
|
||||||
'showing'=>$validUntil->format('Y-m-d H:i:s')
|
|
||||||
], 'me=%i AND you=%i', $src->nationID, $dest->nationID);
|
|
||||||
// 3턴후
|
|
||||||
|
|
||||||
pushGenLog($general, ["<C>●</>{$month}월:<D><b>{$destNation['name']}</b></>으로 불가침 제의 서신을 보냈습니다.<1>$date</>"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function process_63(&$general) {
|
function process_63(&$general) {
|
||||||
$db = DB::db();
|
$db = DB::db();
|
||||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||||
|
|||||||
@@ -0,0 +1,196 @@
|
|||||||
|
<?php
|
||||||
|
namespace sammo\Command\Nation;
|
||||||
|
|
||||||
|
use \sammo\{
|
||||||
|
DB, Util, JosaUtil,
|
||||||
|
General, DummyGeneral,
|
||||||
|
ActionLogger,
|
||||||
|
GameConst,
|
||||||
|
LastTurn,
|
||||||
|
GameUnitConst,
|
||||||
|
Command
|
||||||
|
};
|
||||||
|
|
||||||
|
use function \sammo\{
|
||||||
|
getDomesticExpLevelBonus,
|
||||||
|
CriticalRatioDomestic,
|
||||||
|
CriticalScoreEx
|
||||||
|
};
|
||||||
|
|
||||||
|
use \sammo\Constraint\Constraint;
|
||||||
|
use \sammo\Constraint\ConstraintHelper;
|
||||||
|
|
||||||
|
class che_불가침제의 extends Command\NationCommand{
|
||||||
|
static protected $actionName = '불가침제의';
|
||||||
|
|
||||||
|
protected function argTest():bool{
|
||||||
|
//NOTE: 멸망 직전에 턴을 넣을 수 있으므로, 존재하지 않는 국가여도 argTest에서 바로 탈락시키지 않음
|
||||||
|
if(!key_exists('destNationID', $this->arg)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$destNationID = $this->arg['destNationID'];
|
||||||
|
if(!is_int($destNationID)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($destNationID < 1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$optionText = $this->arg['optionText']??'';
|
||||||
|
if(!is_string($optionText)){
|
||||||
|
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,
|
||||||
|
'optionText'=>$optionText,
|
||||||
|
'year'=>$year,
|
||||||
|
'month'=>$month,
|
||||||
|
];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function init(){
|
||||||
|
$general = $this->generalObj;
|
||||||
|
|
||||||
|
$env = $this->env;
|
||||||
|
$relYear = $env['year'] - $env['startyear'];
|
||||||
|
|
||||||
|
$this->setCity();
|
||||||
|
$this->setNation();
|
||||||
|
|
||||||
|
$this->setDestNation($this->arg['destNationID'], null);
|
||||||
|
|
||||||
|
//NOTE: 개월에서 기한으로 바뀜
|
||||||
|
$year = $this->arg['year'];
|
||||||
|
$month = $this->arg['month'];
|
||||||
|
|
||||||
|
$currentMonth = $env['year'] * 12 + $env['month'] - 1;
|
||||||
|
$reqMonth = $year *12 + $month - 1;
|
||||||
|
|
||||||
|
if ($reqMonth < $currentMonth + 12) {
|
||||||
|
$this->runnableConstraints = [
|
||||||
|
ConstraintHelper::AlwaysFail('기한은 1년 이상이어야 합니다.')
|
||||||
|
];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->runnableConstraints=[
|
||||||
|
ConstraintHelper::BeChief(),
|
||||||
|
ConstraintHelper::NotBeNeutral(),
|
||||||
|
ConstraintHelper::OccupiedCity(),
|
||||||
|
ConstraintHelper::SuppliedCity(),
|
||||||
|
ConstraintHelper::ExistsDestNation(),
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCost():array{
|
||||||
|
return [0, 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPreReqTurn():int{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPostReqTurn():int{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function run():bool{
|
||||||
|
if(!$this->isRunnable()){
|
||||||
|
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
$env = $this->env;
|
||||||
|
|
||||||
|
$general = $this->generalObj;
|
||||||
|
$generalName = $general->getName();
|
||||||
|
$date = substr($general->getVar('turntime'),11,5);
|
||||||
|
|
||||||
|
$nation = $this->nation;
|
||||||
|
$nationID = $nation['nation'];
|
||||||
|
$nationName = $nation['name'];
|
||||||
|
|
||||||
|
$destNation = $this->destNation;
|
||||||
|
$destNationID = $destNation['nation'];
|
||||||
|
$destNationName = $destNation['name'];
|
||||||
|
|
||||||
|
$year = $this->arg['year'];
|
||||||
|
$month = $this->arg['month'];
|
||||||
|
|
||||||
|
$logger = $general->getLogger();
|
||||||
|
$destLogger = new ActionLogger(0, $destNationID, $env['year'], $env['month']);
|
||||||
|
|
||||||
|
$logger->pushGeneralActionLog("<D><b>{$destNationName}</b></>으로 불가침 제의 서신을 보냈습니다.<1>$date</>");
|
||||||
|
|
||||||
|
// 상대에게 발송
|
||||||
|
$src = new MessageTarget(
|
||||||
|
$general->getID(),
|
||||||
|
$general->getName(),
|
||||||
|
$nationID,
|
||||||
|
$nationName,
|
||||||
|
$nation['color'],
|
||||||
|
GetImageURL($general->getVar('imgsvr'), $general->getVar('picture'))
|
||||||
|
);
|
||||||
|
$dest = new MessageTarget(
|
||||||
|
0,
|
||||||
|
'',
|
||||||
|
$destNationID,
|
||||||
|
$destNationName,
|
||||||
|
$destNation['color']
|
||||||
|
);
|
||||||
|
|
||||||
|
$now = new \DateTime($date);
|
||||||
|
$validUntil = new \DateTime($date);
|
||||||
|
$validMinutes = max(30, $turnterm*3);
|
||||||
|
$validUntil->add(new \DateInterval("PT{$validMinutes}M"));
|
||||||
|
|
||||||
|
$msg = new DiplomaticMessage(
|
||||||
|
Message::MSGTYPE_DIPLOMACY,
|
||||||
|
$src,
|
||||||
|
$dest,
|
||||||
|
"{$srcNation['name']}의 {$year}년 {$month}까지 불가침 제의 서신",
|
||||||
|
$now,
|
||||||
|
$validUntil,
|
||||||
|
[
|
||||||
|
'action'=>DiplomaticMessage::TYPE_NO_AGGRESSION,
|
||||||
|
'year'=>$year,
|
||||||
|
'month'=>$month,
|
||||||
|
'option'=>$this->arg['optionText'],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$msg->send();
|
||||||
|
|
||||||
|
//FIXME: 현재 내무부, 외교란이 구형 코드임. diplomacy_ticket을 이용하여 재구현
|
||||||
|
$db->update('diplomacy', [
|
||||||
|
'showing'=>$validUntil->format('Y-m-d H:i:s'),
|
||||||
|
'reserved'=>$this->arg['optionText'],
|
||||||
|
], 'me=%i AND you=%i', $nationID, $destNationID);
|
||||||
|
|
||||||
|
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||||
|
$general->applyDB($db);
|
||||||
|
$destGeneral->applyDB($db);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user