버그 수정

This commit is contained in:
2019-04-21 21:15:53 +09:00
parent da5fc417c5
commit 0c64b506c2
12 changed files with 67 additions and 42 deletions
+7 -7
View File
@@ -145,14 +145,14 @@ abstract class BaseCommand{
$db = DB::db(); $db = DB::db();
$destNation = $db->queryFirstRow('SELECT %l FROM nation WHERE nation=%i', Util::formatListOfBackticks($args), $nationID); $nation = $db->queryFirstRow('SELECT %l FROM nation WHERE nation=%i', Util::formatListOfBackticks($args), $nationID);
if($destNation === null){ if($nation === null){
$destNation = []; $nation = [];
foreach($args as $arg){ foreach($args as $arg){
$destNation[$arg] = $defaultValues[$arg]; $nation[$arg] = $defaultValues[$arg];
} }
} }
$this->destNation = $destNation; $this->nation = $nation;
} }
protected function setDestGeneral(General $destGeneralObj){ protected function setDestGeneral(General $destGeneralObj){
@@ -246,7 +246,7 @@ abstract class BaseCommand{
'general'=>$this->generalObj->getRaw(), 'general'=>$this->generalObj->getRaw(),
'city'=>$this->city, 'city'=>$this->city,
'nation'=>$this->nation, 'nation'=>$this->nation,
'arg'=>$this->arg, 'cmd_arg'=>$this->arg,
'destGeneral'=>$this->destGeneralObj->getRaw(), 'destGeneral'=>$this->destGeneralObj->getRaw(),
'destCity'=>$this->destCity, 'destCity'=>$this->destCity,
@@ -282,7 +282,7 @@ abstract class BaseCommand{
'general'=>$this->generalObj->getRaw(), 'general'=>$this->generalObj->getRaw(),
'city'=>$this->city, 'city'=>$this->city,
'nation'=>$this->nation, 'nation'=>$this->nation,
'arg'=>$this->arg, 'cmd_arg'=>$this->arg,
'destGeneral'=>$this->destGeneralObj?$this->destGeneralObj->getRaw():null, 'destGeneral'=>$this->destGeneralObj?$this->destGeneralObj->getRaw():null,
'destCity'=>$this->destCity, 'destCity'=>$this->destCity,
@@ -191,6 +191,8 @@ class che_인재탐색 extends Command\GeneralCommand{
$isOurNation = $this->nation['scout'] == 0; $isOurNation = $this->nation['scout'] == 0;
$age = $env['year'] - 20;
$newNPC = new \sammo\Scenario\NPC( $newNPC = new \sammo\Scenario\NPC(
Util::randRangeInt(1, 150), Util::randRangeInt(1, 150),
\sammo\getRandGenName(), \sammo\getRandGenName(),
@@ -201,7 +203,7 @@ class che_인재탐색 extends Command\GeneralCommand{
$power, $power,
$intel, $intel,
$isOurNation?1:0, $isOurNation?1:0,
$env['year'] - 20, $age,
$env['year'] + Util::randRangeInt(10, 50), $env['year'] + Util::randRangeInt(10, 50),
null, null,
null null
+3 -2
View File
@@ -57,14 +57,15 @@ class che_징병 extends Command\GeneralCommand{
if(!is_int($crewType)){ if(!is_int($crewType)){
return false; return false;
} }
if(!is_int($amount)){ if(!is_numeric($amount)){
return false; return false;
} }
$amount = (int)$amount;
if(GameUnitConst::byID($crewType) === null){ if(GameUnitConst::byID($crewType) === null){
return false; return false;
} }
if($amount < 100){ if($amount < 0){
return false; return false;
} }
$this->arg = [ $this->arg = [
@@ -157,14 +157,14 @@ class che_불가침제의 extends Command\NationCommand{
$now = new \DateTime($date); $now = new \DateTime($date);
$validUntil = new \DateTime($date); $validUntil = new \DateTime($date);
$validMinutes = max(30, $turnterm*3); $validMinutes = max(30, $env['turnterm']*3);
$validUntil->add(new \DateInterval("PT{$validMinutes}M")); $validUntil->add(new \DateInterval("PT{$validMinutes}M"));
$msg = new DiplomaticMessage( $msg = new DiplomaticMessage(
Message::MSGTYPE_DIPLOMACY, Message::MSGTYPE_DIPLOMACY,
$src, $src,
$dest, $dest,
"{$srcNation['name']}{$year}{$month}까지 불가침 제의 서신", "{$nationName}{$year}{$month}까지 불가침 제의 서신",
$now, $now,
$validUntil, $validUntil,
[ [
@@ -177,7 +177,7 @@ class che_불가침제의 extends Command\NationCommand{
$general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db); $general->applyDB($db);
$destGeneral->applyDB($db); $destLogger->flush();
return true; return true;
} }
@@ -134,7 +134,7 @@ class che_선전포고 extends Command\NationCommand{
], '(me=%i AND you=%i) OR (me=%i AND you=%i)', $nationID, $destNationID, $destNationID, $nationID); ], '(me=%i AND you=%i) OR (me=%i AND you=%i)', $nationID, $destNationID, $destNationID, $nationID);
//국메로 저장 //국메로 저장
$text = "【외교】{$env['year']}{$env['month']}월:{$nationNation}에서 {$destNationName}에 선전포고"; $text = "【외교】{$env['year']}{$env['month']}월:{$nationName}에서 {$destNationName}에 선전포고";
$src = new MessageTarget( $src = new MessageTarget(
$general->getID(), $general->getID(),
@@ -164,7 +164,7 @@ class che_선전포고 extends Command\NationCommand{
$general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db); $general->applyDB($db);
$destGeneral->applyDB($db); $destLogger->flush();
return true; return true;
} }
+9
View File
@@ -16,6 +16,15 @@ class 휴식 extends Command\NationCommand{
protected function init(){ protected function init(){
//아무것도 하지 않음 //아무것도 하지 않음
} }
public function getPreReqTurn():int{
return 0;
}
public function getPostReqTurn():int{
return 0;
}
public function getCost():array{ public function getCost():array{
return [0, 0]; return [0, 0];
} }
+1
View File
@@ -1,6 +1,7 @@
<?php <?php
namespace sammo\Constraint; namespace sammo\Constraint;
use \sammo\GameConst;
class BeOpeningPart extends Constraint{ class BeOpeningPart extends Constraint{
const REQ_VALUES = Constraint::REQ_INT_ARG; const REQ_VALUES = Constraint::REQ_INT_ARG;
+26 -17
View File
@@ -26,6 +26,8 @@ abstract class Constraint{
protected $nation = null; protected $nation = null;
protected $arg = null; protected $arg = null;
protected $cmd_arg = null;
protected $destGeneral = null; protected $destGeneral = null;
protected $destCity = null; protected $destCity = null;
protected $destNation = null; protected $destNation = null;
@@ -40,38 +42,43 @@ abstract class Constraint{
return static::REQ_VALUES; return static::REQ_VALUES;
} }
public function general(array $general){ public function setGeneral(array $general){
$this->general = $general; $this->general = $general;
$this->tested = false; $this->tested = false;
$this->reason = null; $this->reason = null;
} }
public function city(array $city){ public function setCity(array $city){
$this->city = $city; $this->city = $city;
$this->tested = false; $this->tested = false;
$this->reason = null; $this->reason = null;
} }
public function nation(array $nation){ public function setNation(array $nation){
$this->nation = $nation; $this->nation = $nation;
$this->tested = false; $this->tested = false;
$this->reason = null; $this->reason = null;
} }
public function arg($arg){ public function setArg($arg){
$this->arg = $arg; $this->arg = $arg;
$this->tested = false; $this->tested = false;
$this->reason = null; $this->reason = null;
} }
public function setCmdArg($cmd_arg){
$this->cmd_arg = $cmd_arg;
$this->tested = false;
$this->reason = null;
}
public function destGeneral(array $general){ public function setDestGeneral(array $general){
$this->destGeneral = $general; $this->destGeneral = $general;
$this->tested = false; $this->tested = false;
$this->reason = null; $this->reason = null;
} }
public function destCity(array $city){ public function setDestCity(array $city){
$this->destCity = $city; $this->destCity = $city;
$this->tested = false; $this->tested = false;
$this->reason = null; $this->reason = null;
} }
public function destNation(array $nation){ public function setDestNation(array $nation){
$this->destNation = $nation; $this->destNation = $nation;
$this->tested = false; $this->tested = false;
$this->reason = null; $this->reason = null;
@@ -84,14 +91,14 @@ abstract class Constraint{
continue; continue;
} }
switch($key){ switch($key){
case 'general': $self->general($value); break; case 'general': $self->setGeneral($value); break;
case 'city': $self->city($value); break; case 'city': $self->setCity($value); break;
case 'nation': $self->nation($value); break; case 'nation': $self->setNation($value); break;
case 'arg': $self->arg($value); break; case 'cmd_arg': $self->setCmdArg($value); break;
case 'destGeneral': $self->destGeneral($value); break; case 'destGeneral': $self->setDestGeneral($value); break;
case 'destCity': $self->destCity($value); break; case 'destCity': $self->setDestCity($value); break;
case 'destNation': $self->destNation($value); break; case 'destNation': $self->setDestNation($value); break;
} }
} }
@@ -169,7 +176,7 @@ abstract class Constraint{
} }
public function reason():?string{ public function reason():?string{
if(!$this->tested === false){ if($this->tested === false){
throw new \RuntimeException(get_class($this).'::test가 실행되지 않음'); throw new \RuntimeException(get_class($this).'::test가 실행되지 않음');
} }
return $this->reason; return $this->reason;
@@ -186,11 +193,13 @@ abstract class Constraint{
/** @var \sammo\Constraint\Constraint $contraint */ /** @var \sammo\Constraint\Constraint $contraint */
$constraint = call_user_func($method,$input); $constraint = call_user_func($method,$input);
assert($constraint !== null);
assert($constraint instanceof Constraint); assert($constraint instanceof Constraint);
assert(count($constraintArgs) < 3);
if(count($constraintArgs) > 1){ if(count($constraintArgs) == 2){
$arg = $constraintArgs[1]; $arg = $constraintArgs[1];
$constraint->arg($arg); $constraint->setArg($arg);
} }
+7 -7
View File
@@ -69,11 +69,11 @@ class ConstraintHelper{
} }
static function DisallowDiplomacyStatus(int $nationID, array $disallowList):array{ static function DisallowDiplomacyStatus(int $nationID, array $disallowList):array{
return [__FUNCTION__, $nationID, $disallowList]; return [__FUNCTION__, [$nationID, $disallowList]];
} }
static function ExistsAllowJoinNation(int $relYear, array $excludeNationList):array{ static function ExistsAllowJoinNation(int $relYear, array $excludeNationList):array{
return [__FUNCTION__, $relYear, $excludeNationList]; return [__FUNCTION__, [$relYear, $excludeNationList]];
} }
static function ExistsDestGeneral():array{ static function ExistsDestGeneral():array{
@@ -145,7 +145,7 @@ class ConstraintHelper{
} }
static function RemainCityCapacity($key, string $actionName):array{ static function RemainCityCapacity($key, string $actionName):array{
return [__FUNCTION__, $key, $actionName]; return [__FUNCTION__, [$key, $actionName]];
} }
static function RemainCityTrust(string $actionName):array{ static function RemainCityTrust(string $actionName):array{
@@ -153,7 +153,7 @@ class ConstraintHelper{
} }
static function ReqCityCapacity($key, string $keyNick, $reqVal):array{ static function ReqCityCapacity($key, string $keyNick, $reqVal):array{
return [__FUNCTION__, $key, $keyNick, $reqVal]; return [__FUNCTION__, [$key, $keyNick, $reqVal]];
} }
static function ReqCityTrust(float $minTrust):array{ static function ReqCityTrust(float $minTrust):array{
@@ -165,7 +165,7 @@ class ConstraintHelper{
} }
static function ReqEnvValue($key, string $keyNick, string $comp, $reqVal, string $failMessage):array{ static function ReqEnvValue($key, string $keyNick, string $comp, $reqVal, string $failMessage):array{
return [__FUNCTION__, $key, $keyNick, $comp, $reqVal, $failMessage]; return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal, $failMessage]];
} }
static function ReqGeneralAtmosMargin(int $maxAtmos):array{ static function ReqGeneralAtmosMargin(int $maxAtmos):array{
@@ -193,7 +193,7 @@ class ConstraintHelper{
} }
static function ReqGeneralValue($key, string $keyNick, string $comp, $reqVal):array{ static function ReqGeneralValue($key, string $keyNick, string $comp, $reqVal):array{
return [__FUNCTION__, $key, $keyNick, $comp, $reqVal]; return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal]];
} }
static function ReqNationGold(int $reqGold):array{ static function ReqNationGold(int $reqGold):array{
@@ -205,7 +205,7 @@ class ConstraintHelper{
} }
static function ReqNationValue($key, string $keyNick, string $comp, $reqVal):array{ static function ReqNationValue($key, string $keyNick, string $comp, $reqVal):array{
return [__FUNCTION__, $key, $keyNick, $comp, $reqVal]; return [__FUNCTION__, [$key, $keyNick, $comp, $reqVal]];
} }
static function ReqTroopMembers():array{ static function ReqTroopMembers():array{
+1
View File
@@ -1,6 +1,7 @@
<?php <?php
namespace sammo\Constraint; namespace sammo\Constraint;
use \sammo\GameConst;
class NotOpeningPart extends Constraint{ class NotOpeningPart extends Constraint{
const REQ_VALUES = Constraint::REQ_INT_ARG; const REQ_VALUES = Constraint::REQ_INT_ARG;
+4 -2
View File
@@ -278,7 +278,7 @@ class GeneralAI{
return [Util::choiceRandomUsingWeight($commandList), null]; return [Util::choiceRandomUsingWeight($commandList), null];
} }
public function chooseRecruitCrewType():array{ public function chooseRecruitCrewType():?array{
$general = $this->getGeneralObj(); $general = $this->getGeneralObj();
$city = $this->city; $city = $this->city;
$nation = $this->nation; $nation = $this->nation;
@@ -374,7 +374,9 @@ class GeneralAI{
$cost = $general->onCalcDomestic('징병', 'cost', $cost); $cost = $general->onCalcDomestic('징병', 'cost', $cost);
$crew = intdiv($gold, $cost); $crew = intdiv($gold, $cost);
if($leadership < $crew) { $crew = $leadership; } if($leadership*100 < $crew) { $crew = $leadership; }
$crew *= 100;
$arg = [ $arg = [
'crewType'=>$type, 'crewType'=>$type,
'amountCrew'=>$crew 'amountCrew'=>$crew
@@ -104,7 +104,7 @@ class SightseeingMessage{
} }
public function pickAction():array{ public function pickAction():array{
[$type, $texts] = Util::choiceRandomUsingWeightPair(static::$messages); [$type, $texts] = Util::choiceRandomUsingWeightPair(static::$messages??[]);
$text = Util::choiceRandom($texts); $text = Util::choiceRandom($texts);
return [$type, $text]; return [$type, $text];