원조 버그 수정

This commit is contained in:
2020-06-11 00:20:08 +09:00
parent 87e61c8920
commit 3673632089
2 changed files with 285 additions and 283 deletions
+4 -2
View File
@@ -73,9 +73,11 @@ jQuery(function($) {
} }
}, },
'integerArray': function($obj) { 'integerArray': function($obj) {
return $obj.map(function() { var result = [];
return parseInt($(this).val()); $obj.each(function() {
result.push(parseInt($(this).val()));
}); });
return result;
} }
} }
+281 -281
View File
@@ -1,282 +1,282 @@
<?php <?php
namespace sammo\Command\Nation; namespace sammo\Command\Nation;
use \sammo\{ use \sammo\{
DB, Util, JosaUtil, DB, Util, JosaUtil,
General, DummyGeneral, General, DummyGeneral,
ActionLogger, ActionLogger,
GameConst, GameConst,
LastTurn, LastTurn,
GameUnitConst, GameUnitConst,
Command, Command,
StringUtil StringUtil
}; };
use function \sammo\{ use function \sammo\{
getDomesticExpLevelBonus, getDomesticExpLevelBonus,
CriticalRatioDomestic, CriticalRatioDomestic,
CriticalScoreEx, CriticalScoreEx,
getAllNationStaticInfo, getAllNationStaticInfo,
getNationStaticInfo getNationStaticInfo
}; };
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('amountList', $this->arg)){ if(!key_exists('amountList', $this->arg)){
return false; return false;
} }
$amountList = $this->arg['amountList']; $amountList = $this->arg['amountList'];
if(!is_array($amountList)){ if(!is_array($amountList)){
return false; return false;
} }
if(count($amountList) != 2){ if(count($amountList) != 2){
return false; return false;
} }
[$goldAmount, $riceAmount] = $amountList; [$goldAmount, $riceAmount] = $amountList;
if(!is_int($goldAmount) || !is_int($riceAmount)){ if(!is_int($goldAmount) || !is_int($riceAmount)){
return false; return false;
} }
if($goldAmount < 0 || $riceAmount < 0){ if($goldAmount < 0 || $riceAmount < 0){
return false; return false;
} }
if($goldAmount == 0 && $riceAmount == 0){ if($goldAmount == 0 && $riceAmount == 0){
return false; return false;
} }
$this->arg = [ $this->arg = [
'destNationID'=>$destNationID, 'destNationID'=>$destNationID,
'amountList'=>[$goldAmount, $riceAmount] 'amountList'=>[$goldAmount, $riceAmount]
]; ];
return true; return true;
} }
protected function init(){ protected function init(){
$general = $this->generalObj; $general = $this->generalObj;
$this->setCity(); $this->setCity();
$this->setNation(['gold', 'rice', 'surlimit']); $this->setNation(['gold', 'rice', 'surlimit']);
$this->minConditionConstraints=[ $this->minConditionConstraints=[
ConstraintHelper::OccupiedCity(), ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(), ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(), ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqNationValue('surlimit', '외교제한', '==', 0, '외교제한중입니다.'), ConstraintHelper::ReqNationValue('surlimit', '외교제한', '==', 0, '외교제한중입니다.'),
]; ];
} }
protected function initWithArg() protected function initWithArg()
{ {
$destNationID = $this->arg['destNationID']; $destNationID = $this->arg['destNationID'];
$this->setDestNation($destNationID, ['gold', 'rice', 'surlimit']); $this->setDestNation($destNationID, ['gold', 'rice', 'surlimit']);
[$goldAmount, $riceAmount] = $this->arg['amountList']; [$goldAmount, $riceAmount] = $this->arg['amountList'];
$limit = $this->nation['level'] * GameConst::$coefAidAmount; $limit = $this->nation['level'] * GameConst::$coefAidAmount;
if($goldAmount > $limit || $riceAmount > $limit){ if($goldAmount > $limit || $riceAmount > $limit){
$this->fullConditionConstraints[ $this->fullConditionConstraints[
ConstraintHelper::AlwaysFail('작위 제한량 이상은 보낼 수 없습니다.') ConstraintHelper::AlwaysFail('작위 제한량 이상은 보낼 수 없습니다.')
]; ];
return; return;
} }
$this->fullConditionConstraints=[ $this->fullConditionConstraints=[
ConstraintHelper::ExistsDestNation(), ConstraintHelper::ExistsDestNation(),
ConstraintHelper::OccupiedCity(), ConstraintHelper::OccupiedCity(),
ConstraintHelper::BeChief(), ConstraintHelper::BeChief(),
ConstraintHelper::SuppliedCity(), ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqNationGold(GameConst::$basegold+(($goldAmount>0)?1:0)), ConstraintHelper::ReqNationGold(GameConst::$basegold+(($goldAmount>0)?1:0)),
ConstraintHelper::ReqNationRice(GameConst::$baserice+(($riceAmount>0)?1:0)), ConstraintHelper::ReqNationRice(GameConst::$baserice+(($riceAmount>0)?1:0)),
ConstraintHelper::ReqNationValue('surlimit', '외교제한', '==', 0, '외교제한중입니다.'), ConstraintHelper::ReqNationValue('surlimit', '외교제한', '==', 0, '외교제한중입니다.'),
ConstraintHelper::ReqDestNationValue('surlimit', '외교제한', '==', 0, '상대국이 외교제한중입니다.'), ConstraintHelper::ReqDestNationValue('surlimit', '외교제한', '==', 0, '상대국이 외교제한중입니다.'),
]; ];
} }
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 12; return 12;
} }
public function getBrief():string{ public function getBrief():string{
[$goldAmount, $riceAmount] = $this->arg['amountList']; [$goldAmount, $riceAmount] = $this->arg['amountList'];
$goldAmountText = number_format($goldAmount); $goldAmountText = number_format($goldAmount);
$riceAmountText = number_format($riceAmount); $riceAmountText = number_format($riceAmount);
$destNationName = $this->destNation['name']; $destNationName = $this->destNation['name'];
$commandName = $this->getName(); $commandName = $this->getName();
return "{$destNationName}】에게 국고 {$goldAmountText} 병량 {$riceAmountText} {$commandName}"; return "{$destNationName}】에게 국고 {$goldAmountText} 병량 {$riceAmountText} {$commandName}";
} }
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();
$general = $this->generalObj; $general = $this->generalObj;
$generalID = $general->getID(); $generalID = $general->getID();
$date = $general->getTurnTime($general::TURNTIME_HM); $date = $general->getTurnTime($general::TURNTIME_HM);
$nation = $this->nation; $nation = $this->nation;
$nationID = $nation['nation']; $nationID = $nation['nation'];
$nationName = $nation['name']; $nationName = $nation['name'];
$destNationID = $this->destNation['nation']; $destNationID = $this->destNation['nation'];
$destNationName = $this->destNation['name']; $destNationName = $this->destNation['name'];
[$goldAmount, $riceAmount] = $this->arg['amountList']; [$goldAmount, $riceAmount] = $this->arg['amountList'];
$goldAmount = Util::valueFit( $goldAmount = Util::valueFit(
$goldAmount, $goldAmount,
0, 0,
$nation['gold'] - GameConst::$basegold $nation['gold'] - GameConst::$basegold
); );
$riceAmount = Util::valueFit( $riceAmount = Util::valueFit(
$riceAmount, $riceAmount,
0, 0,
$nation['rice'] - GameConst::$baserice $nation['rice'] - GameConst::$baserice
); );
$goldAmountText = number_format($goldAmount); $goldAmountText = number_format($goldAmount);
$riceAmountText = number_format($riceAmount); $riceAmountText = number_format($riceAmount);
$logger = $general->getLogger(); $logger = $general->getLogger();
$year = $this->env['year']; $year = $this->env['year'];
$month = $this->env['month']; $month = $this->env['month'];
$josaRo = JosaUtil::pick($destNationName, '로'); $josaRo = JosaUtil::pick($destNationName, '로');
$broadcastMessage = "<D><b>{$destNationName}</b></>{$josaRo} 금<C>{$goldAmountText}</> 쌀<C>{$riceAmountText}</>을 지원했습니다."; $broadcastMessage = "<D><b>{$destNationName}</b></>{$josaRo} 금<C>{$goldAmountText}</> 쌀<C>{$riceAmountText}</>을 지원했습니다.";
$chiefList = $db->queryFirstColumn('SELECT no FROM general WHERE officer_level >= 5 AND no != %i AND nation = %i', $generalID, $nationID); $chiefList = $db->queryFirstColumn('SELECT no FROM general WHERE officer_level >= 5 AND no != %i AND nation = %i', $generalID, $nationID);
foreach($chiefList as $chiefID){ foreach($chiefList as $chiefID){
$chiefLogger = new ActionLogger($chiefID, $nationID, $year, $month); $chiefLogger = new ActionLogger($chiefID, $nationID, $year, $month);
$chiefLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN); $chiefLogger->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN);
$chiefLogger->flush(); $chiefLogger->flush();
} }
$logger->pushGeneralHistoryLog("<D><b>{$destNationName}</b></>{$josaRo} 금<C>{$goldAmountText}</> 쌀<C>{$riceAmountText}</>을 지원"); $logger->pushGeneralHistoryLog("<D><b>{$destNationName}</b></>{$josaRo} 금<C>{$goldAmountText}</> 쌀<C>{$riceAmountText}</>을 지원");
$logger->pushNationalHistoryLog("<D><b>{$destNationName}</b></>{$josaRo} 금<C>{$goldAmountText}</> 쌀<C>{$riceAmountText}</>을 지원"); $logger->pushNationalHistoryLog("<D><b>{$destNationName}</b></>{$josaRo} 금<C>{$goldAmountText}</> 쌀<C>{$riceAmountText}</>을 지원");
$logger->pushGlobalHistoryLog("<Y><b>【원조】</b></><D><b>{$nationName}</b></>에서 <D><b>{$destNationName}</b></>{$josaRo} 물자를 지원합니다"); $logger->pushGlobalHistoryLog("<Y><b>【원조】</b></><D><b>{$nationName}</b></>에서 <D><b>{$destNationName}</b></>{$josaRo} 물자를 지원합니다");
$logger->pushGeneralActionLog($broadcastMessage); $logger->pushGeneralActionLog($broadcastMessage);
$logger->pushGeneralActionLog("<D><b>{$destNationName}</b></>{$josaRo} 물자를 지원합니다. <1>$date</>", ActionLogger::PLAIN); $logger->pushGeneralActionLog("<D><b>{$destNationName}</b></>{$josaRo} 물자를 지원합니다. <1>$date</>", ActionLogger::PLAIN);
$destBroadcastMessage = $broadcastMessage = "<D><b>{$nationName}</b></>에서 금<C>{$goldAmountText}</> 쌀<C>{$riceAmountText}</>을 원조했습니다."; $destBroadcastMessage = $broadcastMessage = "<D><b>{$nationName}</b></>에서 금<C>{$goldAmountText}</> 쌀<C>{$riceAmountText}</>을 원조했습니다.";
$destChiefList = $db->queryFirstColumn('SELECT no FROM general WHERE officer_level >= 5 AND nation = %i', $destNationID); $destChiefList = $db->queryFirstColumn('SELECT no FROM general WHERE officer_level >= 5 AND nation = %i', $destNationID);
foreach($destChiefList as $destChiefID){ foreach($destChiefList as $destChiefID){
$destChiefLogger = new ActionLogger($destChiefID, $nationID, $year, $month); $destChiefLogger = new ActionLogger($destChiefID, $nationID, $year, $month);
$destChiefLogger->pushGeneralActionLog($destBroadcastMessage, ActionLogger::PLAIN); $destChiefLogger->pushGeneralActionLog($destBroadcastMessage, ActionLogger::PLAIN);
$destChiefLogger->flush(); $destChiefLogger->flush();
} }
$josaRoSrc = JosaUtil::pick($nationName, '로'); $josaRoSrc = JosaUtil::pick($nationName, '로');
$destNationLogger = new ActionLogger(0, $destChiefID, $year, $month); $destNationLogger = new ActionLogger(0, $destChiefID, $year, $month);
$destNationLogger->pushNationalHistoryLog("<D><b>{$nationName}</b></>{$josaRoSrc}부터 금<C>{$goldAmountText}</> 쌀<C>{$riceAmountText}</>을 지원 받음"); $destNationLogger->pushNationalHistoryLog("<D><b>{$nationName}</b></>{$josaRoSrc}부터 금<C>{$goldAmountText}</> 쌀<C>{$riceAmountText}</>을 지원 받음");
$db->update('nation', [ $db->update('nation', [
'gold'=>$db->sqleval('gold - %i', $goldAmount), 'gold'=>$db->sqleval('gold - %i', $goldAmount),
'rice'=>$db->sqleval('rice - %i', $riceAmount), 'rice'=>$db->sqleval('rice - %i', $riceAmount),
'surlimit'=>$db->sqleval('surlimit + %i', $this->getPostReqTurn()) 'surlimit'=>$db->sqleval('surlimit + %i', $this->getPostReqTurn())
], 'nation = %i', $nationID); ], 'nation = %i', $nationID);
$db->update('nation', [ $db->update('nation', [
'gold'=>$db->sqleval('gold + %i', $goldAmount), 'gold'=>$db->sqleval('gold + %i', $goldAmount),
'rice'=>$db->sqleval('rice + %i', $riceAmount), 'rice'=>$db->sqleval('rice + %i', $riceAmount),
], 'nation = %i', $destNationID); ], 'nation = %i', $destNationID);
$general->addExperience(5); $general->addExperience(5);
$general->addDedication(5); $general->addDedication(5);
$this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $this->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db); $general->applyDB($db);
return true; return true;
} }
public function getJSFiles(): array public function getJSFiles(): array
{ {
return [ return [
'js/defaultSelectNationByMap.js' 'js/defaultSelectNationByMap.js'
]; ];
} }
public function getForm(): string public function getForm(): string
{ {
$currentNationLevel = getNationStaticInfo($this->generalObj->getNationID())['level']; $currentNationLevel = getNationStaticInfo($this->generalObj->getNationID())['level'];
ob_start(); ob_start();
?> ?>
<?=\sammo\getMapHtml()?><br> <?=\sammo\getMapHtml()?><br>
타국에게 원조합니다.<br> 타국에게 원조합니다.<br>
작위별로 금액 제한이 있습니다.<br> 작위별로 금액 제한이 있습니다.<br>
<?php foreach(\sammo\getNationLevelList() as $level => [$levelText,,]): ?> <?php foreach(\sammo\getNationLevelList() as $level => [$levelText,,]): ?>
<?=StringUtil::padStringAlignRight($levelText, 10)?>: <?=number_format($level*GameConst::$coefAidAmount)?><br> <?=StringUtil::padStringAlignRight($levelText, 10)?>: <?=number_format($level*GameConst::$coefAidAmount)?><br>
<?php endforeach; ?> <?php endforeach; ?>
원조할 국가를 목록에서 선택하세요.<br> 원조할 국가를 목록에서 선택하세요.<br>
<select class='formInput' name="destNationID" id="destNationID" size='1' style='color:white;background-color:black;'> <select class='formInput' name="destNationID" id="destNationID" size='1' style='color:white;background-color:black;'>
<?php foreach(getAllNationStaticInfo() as $nation): ?> <?php foreach(getAllNationStaticInfo() as $nation): ?>
<option <option
value='<?=$nation['nation']?>' value='<?=$nation['nation']?>'
style='color:<?=$nation['color']?>;' style='color:<?=$nation['color']?>;'
>【<?=$nation['name']?> 】</option> >【<?=$nation['name']?> 】</option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
국고 <select class='formInput' name="amountList[]" class="amountList" size='1' style='color:white;background-color:black;'> 국고 <select class='formInput amountList' name="amountList[]" size='1' style='color:white;background-color:black;'>
<?php foreach(Util::range($currentNationLevel+1) as $nationLevel): ?> <?php foreach(Util::range($currentNationLevel+1) as $nationLevel): ?>
<option value='<?=$nationLevel*GameConst::$coefAidAmount?>'><?=$nationLevel*GameConst::$coefAidAmount?></option> <option value='<?=$nationLevel*GameConst::$coefAidAmount?>'><?=$nationLevel*GameConst::$coefAidAmount?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
병량 <select class='formInput' name="amountList[]" class="amountList" size='1' style='color:white;background-color:black;'> 병량 <select class='formInput amountList' name="amountList[]" size='1' style='color:white;background-color:black;'>
<?php foreach(Util::range($currentNationLevel+1) as $nationLevel): ?> <?php foreach(Util::range($currentNationLevel+1) as $nationLevel): ?>
<option value='<?=$nationLevel*GameConst::$coefAidAmount?>'><?=$nationLevel*GameConst::$coefAidAmount?></option> <option value='<?=$nationLevel*GameConst::$coefAidAmount?>'><?=$nationLevel*GameConst::$coefAidAmount?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
<input type=button id="commonSubmit" value="<?=$this->getName()?>"><br> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
<br> <br>
<?php <?php
return ob_get_clean(); return ob_get_clean();
} }
} }