버그 수정, 허보 구현

This commit is contained in:
2020-03-21 20:17:39 +09:00
parent afbbbaa855
commit d918234bb8
5 changed files with 297 additions and 5 deletions
@@ -43,6 +43,8 @@ class che_백성동원 extends Command\NationCommand{
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->setDestCity($this->arg['destCityID'], null);
$this->setDestNation($this->destCity['nation']);
$this->runnableConstraints=[
ConstraintHelper::OccupiedCity(),
@@ -50,7 +52,7 @@ class che_백성동원 extends Command\NationCommand{
ConstraintHelper::AllowDiplomacyStatus($this->generalObj->getNationID(), [
0
], '전쟁중이 아닙니다.'),
ConstraintHelper::SuppliedDestCity(),
ConstraintHelper::OccupiedDestCity(),
ConstraintHelper::AvailableStrategicCommand()
];
}
+16 -4
View File
@@ -31,7 +31,17 @@ class che_수몰 extends Command\NationCommand{
static public $reqArg = true;
protected function argTest():bool{
$this->arg = [];
if(!key_exists('destCityID', $this->arg)){
return false;
}
if(CityConst::byID($this->arg['destCityID']) === null){
return false;
}
$destCityID = $this->arg['destCityID'];
$this->arg = [
'destCityID'=>$destCityID,
];
return true;
}
@@ -43,6 +53,8 @@ class che_수몰 extends Command\NationCommand{
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->setDestCity($this->arg['destCityID'], null);
$this->setDestNation($this->destCity['nation']);
$this->runnableConstraints=[
ConstraintHelper::OccupiedCity(),
@@ -51,7 +63,6 @@ class che_수몰 extends Command\NationCommand{
ConstraintHelper::NotOccupiedDestCity(),
ConstraintHelper::BattleGroundCity(),
ConstraintHelper::AvailableStrategicCommand(),
ConstraintHelper::OccupiedDestCity()
];
}
@@ -151,8 +162,9 @@ class che_수몰 extends Command\NationCommand{
$josaYiNation = JosaUtil::pick($nationName, '이');
$logger->pushGeneralHistoryLog('<M>수몰</>을 발동');
$logger->pushNationalHistoryLog("<L><b>【전략】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>에 <M>수몰</>을 발동하였습니다.");
$logger->pushGeneralHistoryLog("<G><b>{$destCityName}</b></>에 <M>수몰</>을 발동");
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>수몰</>을 발동");
$logger->pushGlobalHistoryLog("<L><b>【전략】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>에 <M>수몰</>을 발동하였습니다.");
$db->update('nation', ['strategic_cmd_limit' => $this->getPostReqTurn()], 'nation=%i', $nationID);
+216
View File
@@ -0,0 +1,216 @@
<?php
namespace sammo\Command\Nation;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command,
MessageTarget,
Message,
CityConst
};
use function \sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
GetImageURL,
getNationStaticInfo
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\Event\Action;
class che_허보 extends Command\NationCommand{
static protected $actionName = '허보';
static public $reqArg = true;
protected function argTest():bool{
if(!key_exists('destCityID', $this->arg)){
return false;
}
if(CityConst::byID($this->arg['destCityID']) === null){
return false;
}
$destCityID = $this->arg['destCityID'];
$this->arg = [
'destCityID'=>$destCityID,
];
return true;
}
protected function init(){
$general = $this->generalObj;
$env = $this->env;
$this->setCity();
$this->setNation(['strategic_cmd_limit']);
$this->setDestCity($this->arg['destCityID'], null);
$this->setDestNation($this->destCity['nation']);
$this->runnableConstraints=[
ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(),
ConstraintHelper::NotNeutralDestCity(),
ConstraintHelper::NotOccupiedDestCity(),
ConstraintHelper::DisallowDiplomacyBetweenStatus(
[0, 1],
'선포, 전쟁중인 상대국에게만 가능합니다.'
),
ConstraintHelper::AvailableStrategicCommand(),
];
}
public function getCost():array{
return [0, 0];
}
public function getPreReqTurn():int{
return 2;
}
public function getPostReqTurn():int{
$genCount = Util::valueFit($this->nation['gennum'], GameConst::$initialNationGenLimit);
$nextTerm = Util::round(sqrt($genCount*4)*10);
$nextTerm = $this->generalObj->onCalcStrategic($this->getName(), 'delay', $nextTerm);
return $nextTerm;
}
public function getBrief():string{
$commandName = $this->getName();
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
$josaUl = JosaUtil::pick($destCityName, '을');
return "{$destCityName}{$josaUl} {$commandName}";
}
public function run():bool{
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$generalID = $general->getID();
$generalName = $general->getName();
$date = $general->getTurnTime($general::TURNTIME_HM);
$year = $this->env['year'];
$month = $this->env['month'];
$destCity = $this->destCity;
$destCityID = $destCity['city'];
$destCityName = $destCity['name'];
$destNationID = $destCity['nation'];
$destNationName = getNationStaticInfo($destNationID)['name'];
$nationID = $general->getNationID();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$logger->pushGeneralActionLog("허보 발동! <1>$date</>");
$general->increaseVar(
'experience',
$general->onCalcStat($general,
'experience', 5 * ($this->getPreReqTurn() + 1)
));
$general->increaseVar(
'dedication',
$general->onCalcStat($general,
'dedication', 5 * ($this->getPreReqTurn() + 1)
));
$josaYi = JosaUtil::pick($generalName, '이');
$broadcastMessage = "<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>허보</>를 발동하였습니다.";
$targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID);
foreach($targetGeneralList as $targetGeneralID){
$targetLogger = new ActionLogger($targetGeneralID, $nationID, $year, $month);
$targetLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$targetLogger->flush();
}
$destBroadcastMessage = "상대의 <M>허보</>에 당했다! <1>$date</>";
$destNationCityList = $db->queryFirstColumn('SELECT city FROM city WHERE nation = %i AND supply = 1', $destNationID);
$targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND city=%i', $destNationID, $destCityID);
$destNationLogged = false;
foreach(General::createGeneralObjListFromDB($targetGeneralList) as $targetGeneralID => $targetGeneral){
$targetLogger = $targetGeneral->getLogger();
$targetLogger->pushGeneralActionLog($destBroadcastMessage, ActionLogger::PLAIN);
if(!$destNationLogged){
$targetLogger->pushNationalHistoryLog(
"<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국의 <G><b>{$destCityName}</b></>에 <M>허보</>를 발동", ActionLogger::PLAIN
);
$destNationLogged = true;
}
$moveCityID = Util::choiceRandom($destNationCityList);
if($moveCityID == $destCityID){
//현재도시면 다시 랜덤 추첨
$moveCityID = Util::choiceRandom($destNationCityList);
}
$targetGeneral->setVar('city', $moveCityID);
$targetGeneral->applyDB($db);
}
if(!$targetGeneralList){
//아무도 없었다!
$destNationLordID = $db->queryFirstField('SELECT no FROM general WHERE nation=%i AND level=12', $destNationID);
$targetLogger = new ActionLogger($destNationLordID, $destNationID, $year, $month);
$targetLogger->pushNationalHistoryLog(
"<D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} 아국의 <G><b>{$destCityName}</b></>에 <M>허보</>를 발동", ActionLogger::PLAIN
);
$targetLogger->flush();
}
$db->update('city', [
'def' => $db->sqleval('def * 0.2'),
'wall' => $db->sqleval('wall * 0.2'),
], 'city=%i', $destCityID);
$josaYiNation = JosaUtil::pick($nationName, '이');
$logger->pushGeneralHistoryLog("<G><b>{$destCityName}</b></>에 <M>허보</>를 발동");
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <G><b>{$destCityName}</b></>에 <M>허보</>를 발동");
$logger->pushGlobalHistoryLog("<L><b>【전략】</b></><D><b>{$nationName}</b></>{$josaYiNation} <G><b>{$destCityName}</b></>에 <M>허보</>를 발동하였습니다.");
$db->update('nation', ['strategic_cmd_limit' => $this->getPostReqTurn()], 'nation=%i', $nationID);
$general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0));
$general->applyDB($db);
return true;
}
public function getForm(): string
{
ob_start();
?>
<?=\sammo\getMapHtml()?><br>
선택된 도시에 허보를 발동합니다.<br>
전쟁중인 상대국 도시만 가능합니다.<br>
목록을 선택하거나 도시를 클릭하세요.<br>
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'>
<?=\sammo\optionsForCities()?><br>
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<br>
<?php
return ob_get_clean();
}
}
@@ -0,0 +1,58 @@
<?php
namespace sammo\Constraint;
use \sammo\JosaUtil;
use \sammo\DB;
class AllowDiplomacyBetweenStatus extends Constraint{
const REQ_VALUES = Constraint::REQ_ARRAY_ARG|Constraint::REQ_NATION|Constraint::REQ_DEST_NATION;
protected $nationID;
protected $destNationID;
protected $allowDipCodeList = [];
protected $errMsg = '';
public function checkInputValues(bool $throwExeception=true):bool{
if(!parent::checkInputValues($throwExeception) && !$throwExeception){
return false;
}
if(count($this->arg) != 2){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require allowDipCodeList, errMsg pair");
}
$this->nationID = $this->nation['nation'];
$this->destNationID = $this->destNation['nation'];
[$this->allowDipCodeList, $this->errMsg] = $this->arg;
foreach($this->allowDipCodeList as $dipCode){
if(!is_int($dipCode)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("dipCode $dipCode must be int");
}
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
$db = DB::db();
$state = $db->queryFirstField(
'SELECT state FROM diplomacy WHERE me = %i AND you = %i AND `state` IN %li LIMIT 1',
$this->nationID,
$this->destNationID,
array_keys($this->allowDipCodeList)
);
if($state !== null){
return true;
}
$this->reason = $this->errMsg;
return false;
}
}
@@ -11,6 +11,10 @@ class ConstraintHelper{
static function AllowDiplomacyStatus(int $nationID, array $disallowList, string $errMsg):array{
return [__FUNCTION__, [$nationID, $disallowList, $errMsg]];
}
static function AllowDiplomacyBetweenStatus(array $allowDipCodeList, string $errMsg):array{
return [__FUNCTION__, $allowDipCodeList, $errMsg];
}
static function AllowJoinAction():array{
return [__FUNCTION__];