종전수락 버그 수정

This commit is contained in:
2020-12-13 22:05:07 +09:00
parent 8c7ec533bf
commit 84f54b4b8a
+198 -195
View File
@@ -1,195 +1,198 @@
<?php <?php
namespace sammo\Command\Nation; namespace sammo\Command\Nation;
use\sammo\{ use\sammo\{
DB, DB,
Util, Util,
JosaUtil, JosaUtil,
General, General,
DummyGeneral, DummyGeneral,
ActionLogger, ActionLogger,
GameConst, GameConst,
LastTurn, LastTurn,
GameUnitConst, GameUnitConst,
Command, Command,
MessageTarget, MessageTarget,
DiplomaticMessage, DiplomaticMessage,
Message, Message,
}; };
use function\sammo\{ use function\sammo\{
getDomesticExpLevelBonus, getDomesticExpLevelBonus,
CriticalRatioDomestic, CriticalRatioDomestic,
CriticalScoreEx, CriticalScoreEx,
getAllNationStaticInfo, getAllNationStaticInfo,
getNationStaticInfo, getNationStaticInfo,
GetImageURL GetImageURL
}; };
use \sammo\Constraint\Constraint; use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper; use \sammo\Constraint\ConstraintHelper;
class che_종전수락 extends Command\NationCommand class che_종전수락 extends Command\NationCommand
{ {
static protected $actionName = '종전 수락'; static protected $actionName = '종전 수락';
static public $reqArg = true; static public $reqArg = true;
protected function argTest(): bool protected function argTest(): bool
{ {
if ($this->arg === null) { if ($this->arg === null) {
return false; return false;
} }
if (!key_exists('destNationID', $this->arg)) { if (!key_exists('destNationID', $this->arg)) {
return false; return false;
} }
$destNationID = $this->arg['destNationID']; $destNationID = $this->arg['destNationID'];
if (!is_int($destNationID)) { if (!is_int($destNationID)) {
return false; return false;
} }
if ($destNationID < 1) { if ($destNationID < 1) {
return false; return false;
} }
if (!key_exists('destGeneralID', $this->arg)) { if (!key_exists('destGeneralID', $this->arg)) {
return false; return false;
} }
$destGeneralID = $this->arg['destGeneralID']; $destGeneralID = $this->arg['destGeneralID'];
if (!is_int($destGeneralID)) { if (!is_int($destGeneralID)) {
return false; return false;
} }
if ($destGeneralID <= 0) { if ($destGeneralID <= 0) {
return false; return false;
} }
if ($destGeneralID == $this->generalObj->getID()) { if ($destGeneralID == $this->generalObj->getID()) {
return false; return false;
} }
$this->arg = [ $this->arg = [
'destNationID' => $destNationID, 'destNationID' => $destNationID,
'destGeneralID' => $destGeneralID, 'destGeneralID' => $destGeneralID,
]; ];
return true; return true;
} }
protected function init() protected function init()
{ {
$general = $this->generalObj; $general = $this->generalObj;
$env = $this->env; $env = $this->env;
$relYear = $env['year'] - $env['startyear']; $relYear = $env['year'] - $env['startyear'];
$this->setCity(); $this->setCity();
$this->setNation(); $this->setNation();
$nationID = $this->nation['nation']; $nationID = $this->nation['nation'];
$this->permissionConstraints = [ $this->permissionConstraints = [
ConstraintHelper::AlwaysFail('예약 불가능 커맨드') ConstraintHelper::AlwaysFail('예약 불가능 커맨드')
]; ];
} }
protected function initWithArg() protected function initWithArg()
{ {
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], [], 1); $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], [], 1);
$this->setDestGeneral($destGeneral); $this->setDestGeneral($destGeneral);
$this->setDestNation($this->arg['destNationID']); $this->setDestNation($this->arg['destNationID']);
$this->fullConditionConstraints = [ $this->fullConditionConstraints = [
ConstraintHelper::BeChief(), ConstraintHelper::BeChief(),
ConstraintHelper::NotBeNeutral(), ConstraintHelper::NotBeNeutral(),
ConstraintHelper::ExistsDestNation(), ConstraintHelper::ExistsDestNation(),
ConstraintHelper::ExistsDestGeneral(), ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::ReqDestNationValue('nation', '소속', '==', $this->destGeneralObj->getNationID(), '제의 장수가 국가 소속이 아닙니다'), ConstraintHelper::ReqDestNationValue('nation', '소속', '==', $this->destGeneralObj->getNationID(), '제의 장수가 국가 소속이 아닙니다'),
ConstraintHelper::AllowDiplomacyBetweenStatus( ConstraintHelper::AllowDiplomacyBetweenStatus(
[0, 1], [0, 1],
'상대국과 선포, 전쟁중이지 않습니다.' '상대국과 선포, 전쟁중이지 않습니다.'
), ),
]; ];
} }
public function canDisplay():bool{ public function canDisplay():bool{
return false; return false;
} }
public function getCost(): array public function getCost(): array
{ {
return [0, 0]; return [0, 0];
} }
public function getPreReqTurn(): int public function getPreReqTurn(): int
{ {
return 0; return 0;
} }
public function getPostReqTurn(): int public function getPostReqTurn(): int
{ {
return 0; return 0;
} }
public function getBrief(): string public function getBrief(): string
{ {
$commandName = $this->getName(); $commandName = $this->getName();
$destNationName = getNationStaticInfo($this->arg['destNationID'])['name']; $destNationName = getNationStaticInfo($this->arg['destNationID'])['name'];
return "{$destNationName}국과 종전 합의"; return "{$destNationName}국과 종전 합의";
} }
public function run(): bool public function run(): bool
{ {
if (!$this->hasFullConditionMet()) { if (!$this->hasFullConditionMet()) {
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
} }
$db = DB::db(); $db = DB::db();
$env = $this->env; $env = $this->env;
$general = $this->generalObj; $general = $this->generalObj;
$generalName = $general->getName(); $generalName = $general->getName();
$nation = $this->nation; $nation = $this->nation;
$nationID = $nation['nation']; $nationID = $nation['nation'];
$nationName = $nation['name']; $nationName = $nation['name'];
$destNation = $this->destNation; $destNation = $this->destNation;
$destNationID = $destNation['nation']; $destNationID = $destNation['nation'];
$destNationName = $destNation['name']; $destNationName = $destNation['name'];
$logger = $general->getLogger(); $logger = $general->getLogger();
$destLogger = $this->destGeneralObj->getLogger(); $destLogger = $this->destGeneralObj->getLogger();
$db->update( $db->update(
'diplomacy', 'diplomacy',
[ [
'state' => 2, 'state' => 2,
'term' => 0 'term' => 0
], ],
'(me=%i AND you=%i) OR (you=%i AND me=%i)', '(me=%i AND you=%i) OR (you=%i AND me=%i)',
$nationID, $nationID,
$destNationID, $destNationID,
$nationID, $nationID,
$destNationID $destNationID
); );
$josaYiGeneral = JosaUtil::pick($generalName, '이'); \sammo\SetNationFront($nationID);
$josaYiNation = JosaUtil::pick($nationName, '이'); \sammo\SetNationFront($destNationID);
$josaWa = JosaUtil::pick($destNationName, ''); $josaYiGeneral = JosaUtil::pick($generalName, '');
$logger->pushGeneralActionLog("<D><b>{$destNationName}</b></>{$josaWa} 종전에 합의했습니다.", ActionLogger::PLAIN); $josaYiNation = JosaUtil::pick($nationName, '이');
$logger->pushGeneralHistoryLog("<D><b>{$destNationName}</b></>{$josaWa} 종전 수락");
$josaWa = JosaUtil::pick($destNationName, '와');
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYiGeneral} <D><b>{$destNationName}</b></>{$josaWa} <M>종전 합의</> 하였습니다."); $logger->pushGeneralActionLog("<D><b>{$destNationName}</b></>{$josaWa} 종전 합의습니다.", ActionLogger::PLAIN);
$logger->pushGlobalHistoryLog("<Y><b>【종전】</b></><D><b>{$nationName}</b></>{$josaYiNation} <D><b>{$destNationName}</b></>{$josaWa} <M>종전 합의</> 하였습니다."); $logger->pushGeneralHistoryLog("<D><b>{$destNationName}</b></>{$josaWa} 종전 수락");
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYiGeneral} <D><b>{$destNationName}</b></>{$josaWa} <M>종전 합의</> 하였습니다.");
$josaWa = JosaUtil::pick($nationName, '와'); $logger->pushGlobalHistoryLog("<Y><b>【종전】</b></><D><b>{$nationName}</b></>{$josaYiNation} <D><b>{$destNationName}</b></>{$josaWa} <M>종전 합의</> 하였습니다.");
$destLogger->pushGeneralActionLog("<D><b>{$nationName}</b></>{$josaWa} 종전에 성공했습니다.", ActionLogger::PLAIN);
$destLogger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>{$josaWa} 종전 성공");
$josaWa = JosaUtil::pick($nationName, '와');
$general->applyDB($db); $destLogger->pushGeneralActionLog("<D><b>{$nationName}</b></>{$josaWa} 종전에 성공했습니다.", ActionLogger::PLAIN);
$destLogger->flush(); $destLogger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>{$josaWa} 종전 성공");
return true; $general->applyDB($db);
} $destLogger->flush();
}
return true;
}
}