diff --git a/.phan/config.php b/.phan/config.php index 68f08443..8e20fd17 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -15,7 +15,7 @@ return [ // Note that the **only** effect of choosing `'5.6'` is to infer // that functions removed in php 7.0 exist. // (See `backward_compatibility_checks` for additional options) - "target_php_version" => '8.0', + "target_php_version" => '7.3', 'backward_compatibility_checks ' => false, 'minimum_severity'=>\Phan\Issue::SEVERITY_NORMAL, diff --git a/hwe/b_betting.php b/hwe/b_betting.php index d02e4ca0..cafa7f45 100644 --- a/hwe/b_betting.php +++ b/hwe/b_betting.php @@ -36,7 +36,7 @@ if ($con >= 2) { } switch ($admin['tnmt_type']) { -default: throw new \RuntimeException('Invalid tnmt_type');break; +default: throw new \RuntimeException('Invalid tnmt_type'); case 0: $tnmt_type = "전력전"; $tp = "total"; $tp2 = "종합"; $tp3 = "total"; break; case 1: $tnmt_type = "통솔전"; $tp = "leadership"; $tp2 = "통솔"; $tp3 = "leadership"; break; case 2: $tnmt_type = "일기토"; $tp = "strength"; $tp2 = "무력"; $tp3 = "strength"; break; diff --git a/hwe/b_myPage.php b/hwe/b_myPage.php index d02b07fa..6790093c 100644 --- a/hwe/b_myPage.php +++ b/hwe/b_myPage.php @@ -88,9 +88,9 @@ $me->applyDB($db); if($gameStor->turntime <= $gameStor->opentime){ //서버 가오픈시 할 수 있는 행동 - if($me['npc'] == 0){ + if($me->getVar('npc') == 0){ $showDieImmediatelyBtn = true; - if(addTurn($me['lastrefresh'], $gameStor->turnterm, 2) <= TimeUtil::DatetimeNow()){ + if(addTurn($me->getVar('lastrefresh'), $gameStor->turnterm, 2) <= TimeUtil::now()){ $availableDieImmediately = true; } } diff --git a/hwe/c_die_immediately.php b/hwe/c_die_immediately.php index f656a8c6..feb4f986 100644 --- a/hwe/c_die_immediately.php +++ b/hwe/c_die_immediately.php @@ -25,7 +25,7 @@ $gameStor->cacheValues(['turnterm', 'opentime', 'turntime', 'year', 'month']); if($gameStor->turntime <= $gameStor->opentime){ //서버 가오픈시 할 수 있는 행동 - if(addTurn($general['lastrefresh'], $gameStor->turnterm, 2) <= TimeUtil::DatetimeNow()){ + if(addTurn($general['lastrefresh'], $gameStor->turnterm, 2) <= TimeUtil::now()){ $availableDieImmediately = true; } } diff --git a/hwe/func.php b/hwe/func.php index 154157dd..a88eb99e 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -331,7 +331,7 @@ function checkSecretMaxPermission($penalty){ return $secretMax; } -function checkSecretPermission($me, $checkSecretLimit=true){ +function checkSecretPermission(array $me, $checkSecretLimit=true){ if(!key_exists('penalty', $me) || !key_exists('permission', $me)){ trigger_error ('canAccessSecret() 함수에 필요한 인자가 부족'); } @@ -1656,7 +1656,7 @@ function nextRuler(General $general) { if(!$candidate){ - DeleteConflict($general['nation']); + DeleteConflict($general->getNationID()); deleteNation($general); return; } diff --git a/hwe/func_process.php b/hwe/func_process.php index 1ce90896..fd4ab027 100644 --- a/hwe/func_process.php +++ b/hwe/func_process.php @@ -4,7 +4,7 @@ namespace sammo; /** * 내정 커맨드 사용시 성공 확률 계산 * - * @param array $general 장수 정보 + * @param General $general 장수 정보 * @param string $type 내정 커맨드 타입, 'leadership' = 통솔 기반, 'strength' = 무력 기반, 'intel' = 지력 기반 * * @return array 계산된 실패, 성공 확률 ('success' => 성공 확률, 'fail' => 실패 확률) diff --git a/hwe/func_tournament.php b/hwe/func_tournament.php index 695f694e..ecd01a06 100644 --- a/hwe/func_tournament.php +++ b/hwe/func_tournament.php @@ -28,6 +28,7 @@ function processTournament() { case 5: $unit = 30; break; case 6: $unit = 15; break; case 7: $unit = 5; break; + default: throw new MustNotBeReachedException(); } //업데이트 횟수 @@ -617,6 +618,7 @@ function finalFight($tnmt_type, $tnmt, $phase, $type) { case 8: $offset = 30; $turn = 3; $next = 8; break; case 4: $offset = 40; $turn = 1; $next = 9; break; case 2: $offset = 50; $turn = 0; $next = 0; break; + default: throw new MustNotBeReachedException(); } $grp = $phase + $offset; @@ -662,6 +664,7 @@ function setGift($tnmt_type, $tnmt, $phase) { case 1: $tp = "통솔전"; $tp2 = "tl"; break; case 2: $tp = "일기토"; $tp2 = "ts"; break; case 3: $tp = "설전"; $tp2 = "ti"; break; + default: throw new MustNotBeReachedException(); } //16강자 명성 돈 @@ -1120,6 +1123,7 @@ function fight($tnmt_type, $tnmt, $phs, $group, $g1, $g2, $type) { $gen1resKey = 'd'; $gen2resKey = 'd'; break; + default: new MustNotBeReachedException(); } $db->update('rank_data', [ diff --git a/hwe/j_diplomacy_destroy_letter.php b/hwe/j_diplomacy_destroy_letter.php index 39bb5071..ca417cd7 100644 --- a/hwe/j_diplomacy_destroy_letter.php +++ b/hwe/j_diplomacy_destroy_letter.php @@ -86,7 +86,7 @@ if(in_array($stateOpt, ['try_destroy_src', 'try_destroy_dest'])){ 'aux'=>Json::encode($aux) ], 'no=%i', $letterNo); while(true){ - $deleteLetter = $db->queryFirstRow('SELECT prev_no, aux FROM ng_diplomacy WHERE no = %i AND state = \'replaced\'', $currentLetterNo); + $deleteLetter = $db->queryFirstRow('SELECT prev_no, aux FROM ng_diplomacy WHERE no = %i AND state = \'replaced\'', $letterNo); if(!$deleteLetter){ break; } diff --git a/hwe/sammo/ActionNationType/che_덕가.php b/hwe/sammo/ActionNationType/che_덕가.php index ddd668f4..7b0c486f 100644 --- a/hwe/sammo/ActionNationType/che_덕가.php +++ b/hwe/sammo/ActionNationType/che_덕가.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_덕가 extends \sammo\BaseNation{ @@ -30,10 +31,10 @@ class che_덕가 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'rice'){ - return $amount * 0.9; + return Util::toInt($amount * 0.9); } if($type == 'pop'){ - return $amount * 1.2; + return Util::toInt($amount * 1.2); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_도가.php b/hwe/sammo/ActionNationType/che_도가.php index 80221f39..30eeeb4e 100644 --- a/hwe/sammo/ActionNationType/che_도가.php +++ b/hwe/sammo/ActionNationType/che_도가.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_도가 extends \sammo\BaseNation{ @@ -25,7 +26,7 @@ class che_도가 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'pop'){ - return $amount * 1.2; + return Util::toInt($amount * 1.2); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_도적.php b/hwe/sammo/ActionNationType/che_도적.php index 447da481..981f1f74 100644 --- a/hwe/sammo/ActionNationType/che_도적.php +++ b/hwe/sammo/ActionNationType/che_도적.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_도적 extends \sammo\BaseNation{ @@ -29,7 +30,7 @@ class che_도적 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'gold'){ - return $amount * 0.9; + return Util::toInt($amount * 0.9); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_명가.php b/hwe/sammo/ActionNationType/che_명가.php index 5063beaa..68bae153 100644 --- a/hwe/sammo/ActionNationType/che_명가.php +++ b/hwe/sammo/ActionNationType/che_명가.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_명가 extends \sammo\BaseNation{ @@ -26,10 +27,10 @@ class che_명가 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'rice'){ - return $amount * 0.9; + return Util::toInt($amount * 0.9); } if($type == 'pop'){ - return $amount * 1.2; + return Util::toInt($amount * 1.2); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_법가.php b/hwe/sammo/ActionNationType/che_법가.php index e18cf9fb..81d414d3 100644 --- a/hwe/sammo/ActionNationType/che_법가.php +++ b/hwe/sammo/ActionNationType/che_법가.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_법가 extends \sammo\BaseNation{ @@ -26,10 +27,10 @@ class che_법가 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'gold'){ - return $amount * 1.1; + return Util::toInt($amount * 1.1); } if($type == 'pop'){ - return $amount * 0.8; + return Util::toInt($amount * 0.8); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_병가.php b/hwe/sammo/ActionNationType/che_병가.php index 7a378809..8eff57ec 100644 --- a/hwe/sammo/ActionNationType/che_병가.php +++ b/hwe/sammo/ActionNationType/che_병가.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_병가 extends \sammo\BaseNation{ @@ -30,7 +31,7 @@ class che_병가 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'pop'){ - return $amount * 0.8; + return Util::toInt($amount * 0.8); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_불가.php b/hwe/sammo/ActionNationType/che_불가.php index 425f6496..6fc210ae 100644 --- a/hwe/sammo/ActionNationType/che_불가.php +++ b/hwe/sammo/ActionNationType/che_불가.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_불가 extends \sammo\BaseNation{ @@ -25,7 +26,7 @@ class che_불가 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'gold'){ - return $amount * 0.9; + return Util::toInt($amount * 0.9); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_오두미도.php b/hwe/sammo/ActionNationType/che_오두미도.php index af564566..8b1dd72a 100644 --- a/hwe/sammo/ActionNationType/che_오두미도.php +++ b/hwe/sammo/ActionNationType/che_오두미도.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_오두미도 extends \sammo\BaseNation{ @@ -30,10 +31,10 @@ class che_오두미도 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'rice'){ - return $amount * 1.1; + return Util::toInt($amount * 1.1); } if($type == 'pop'){ - return $amount * 1.2; + return Util::toInt($amount * 1.2); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_유가.php b/hwe/sammo/ActionNationType/che_유가.php index 1e024848..b427ce51 100644 --- a/hwe/sammo/ActionNationType/che_유가.php +++ b/hwe/sammo/ActionNationType/che_유가.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_유가 extends \sammo\BaseNation{ @@ -25,7 +26,7 @@ class che_유가 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'rice'){ - return $amount * 0.9; + return Util::toInt($amount * 0.9); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_음양가.php b/hwe/sammo/ActionNationType/che_음양가.php index db874f9d..45c3e3f4 100644 --- a/hwe/sammo/ActionNationType/che_음양가.php +++ b/hwe/sammo/ActionNationType/che_음양가.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_음양가 extends \sammo\BaseNation{ @@ -26,7 +27,7 @@ class che_음양가 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'pop'){ - return $amount * 1.2; + return Util::toInt($amount * 1.2); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_종횡가.php b/hwe/sammo/ActionNationType/che_종횡가.php index 361f5006..81030bc3 100644 --- a/hwe/sammo/ActionNationType/che_종횡가.php +++ b/hwe/sammo/ActionNationType/che_종횡가.php @@ -27,7 +27,7 @@ class che_종횡가 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'gold'){ - return $amount * 0.9; + return Util::toInt($amount * 0.9); } return $amount; diff --git a/hwe/sammo/ActionNationType/che_태평도.php b/hwe/sammo/ActionNationType/che_태평도.php index 3f3b68cb..96f4d4bf 100644 --- a/hwe/sammo/ActionNationType/che_태평도.php +++ b/hwe/sammo/ActionNationType/che_태평도.php @@ -2,6 +2,7 @@ namespace sammo\ActionNationType; use \sammo\iAction; use \sammo\General; +use \sammo\Util; class che_태평도 extends \sammo\BaseNation{ @@ -30,7 +31,7 @@ class che_태평도 extends \sammo\BaseNation{ public function onCalcNationalIncome(string $type, int $amount):int{ if($type == 'pop'){ - return $amount * 1.2; + return Util::toInt($amount * 1.2); } return $amount; diff --git a/hwe/sammo/Command/BaseCommand.php b/hwe/sammo/Command/BaseCommand.php index c8b0778f..fcca1f4a 100644 --- a/hwe/sammo/Command/BaseCommand.php +++ b/hwe/sammo/Command/BaseCommand.php @@ -14,10 +14,6 @@ use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; abstract class BaseCommand{ - /** - * @var General|null $generalObj - * @var General|null $destGeneralObj - */ static protected $actionName = 'CommandName'; static public $reqArg = false; @@ -253,7 +249,7 @@ abstract class BaseCommand{ return static::$actionName; } - public function getLogger():ActionLogger{ + public function getLogger():?ActionLogger{ return $this->logger; } @@ -403,7 +399,6 @@ abstract class BaseCommand{ } public function getForm():string{ throw new \sammo\MustNotBeReachedException(); - return ''; } public function getLastTurn():LastTurn{ diff --git a/hwe/sammo/Command/General/che_상업투자.php b/hwe/sammo/Command/General/che_상업투자.php index 7d785607..8c2e9d70 100644 --- a/hwe/sammo/Command/General/che_상업투자.php +++ b/hwe/sammo/Command/General/che_상업투자.php @@ -29,6 +29,8 @@ class che_상업투자 extends Command\GeneralCommand{ static protected $actionName = '상업 투자'; static protected $debuffFront = 0.5; + protected $reqGold; + protected function argTest():bool{ $this->arg = null; return true; diff --git a/hwe/sammo/Command/General/che_정착장려.php b/hwe/sammo/Command/General/che_정착장려.php index cfec8340..f35f9977 100644 --- a/hwe/sammo/Command/General/che_정착장려.php +++ b/hwe/sammo/Command/General/che_정착장려.php @@ -28,6 +28,8 @@ class che_정착장려 extends Command\GeneralCommand{ static protected $actionKey = '인구'; static protected $actionName = '정착 장려'; + protected $reqRice; + protected function argTest():bool{ $this->arg = null; return true; diff --git a/hwe/sammo/Command/General/che_주민선정.php b/hwe/sammo/Command/General/che_주민선정.php index b7b00741..7373a82d 100644 --- a/hwe/sammo/Command/General/che_주민선정.php +++ b/hwe/sammo/Command/General/che_주민선정.php @@ -28,6 +28,8 @@ class che_주민선정 extends Command\GeneralCommand{ static protected $actionKey = '민심'; static protected $actionName = '주민 선정'; + protected $reqRice; + protected function argTest():bool{ $this->arg = null; return true; diff --git a/hwe/sammo/Command/General/che_징병.php b/hwe/sammo/Command/General/che_징병.php index a45b485b..31913a39 100644 --- a/hwe/sammo/Command/General/che_징병.php +++ b/hwe/sammo/Command/General/che_징병.php @@ -24,9 +24,6 @@ use \sammo\Constraint\ConstraintHelper; class che_징병 extends Command\GeneralCommand{ - /** - * @var \sammo\GameUnitDetail $reqCrewType - */ static protected $actionName = '징병'; static protected $costOffset = 1; static public $reqArg = true; diff --git a/hwe/sammo/Command/Nation/che_물자원조.php b/hwe/sammo/Command/Nation/che_물자원조.php index b59f6b6f..07408f8d 100644 --- a/hwe/sammo/Command/Nation/che_물자원조.php +++ b/hwe/sammo/Command/Nation/che_물자원조.php @@ -98,8 +98,8 @@ class che_물자원조 extends Command\NationCommand{ ConstraintHelper::OccupiedCity(), ConstraintHelper::BeChief(), ConstraintHelper::SuppliedCity(), - ConstraintHelper::ReqNationGold(GameConst::$basegold+($goldAmount>0)?1:0), - ConstraintHelper::ReqNationRice(GameConst::$baserice+($riceAmount>0)?1:0), + ConstraintHelper::ReqNationGold(GameConst::$basegold+(($goldAmount>0)?1:0)), + ConstraintHelper::ReqNationRice(GameConst::$baserice+(($riceAmount>0)?1:0)), ConstraintHelper::ReqNationValue('surlimit', '외교제한', '==', 0, '외교제한중입니다.'), ConstraintHelper::ReqDestNationValue('surlimit', '외교제한', '==', 0, '상대국이 외교제한중입니다.'), ]; diff --git a/hwe/sammo/Constraint/AllowStrategicCommand.php b/hwe/sammo/Constraint/AllowStrategicCommand.php index b8beeebb..c618b371 100644 --- a/hwe/sammo/Constraint/AllowStrategicCommand.php +++ b/hwe/sammo/Constraint/AllowStrategicCommand.php @@ -2,7 +2,7 @@ namespace sammo\Constraint; -class AllowWar extends Constraint{ +class AllowStrategicCommand extends Constraint{ const REQ_VALUES = Constraint::REQ_NATION; public function checkInputValues(bool $throwExeception=true):bool{ diff --git a/hwe/sammo/Constraint/ExistsAllowJoinNation.php b/hwe/sammo/Constraint/ExistsAllowJoinNation.php index ebfdfc3a..32168209 100644 --- a/hwe/sammo/Constraint/ExistsAllowJoinNation.php +++ b/hwe/sammo/Constraint/ExistsAllowJoinNation.php @@ -5,7 +5,7 @@ use \sammo\DB; use \sammo\GameConst; use \sammo\Json; -class AllowJoinDestNation extends Constraint{ +class ExistsAllowJoinNation extends Constraint{ const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_ARRAY_ARG; protected $relYear; diff --git a/hwe/sammo/Constraint/ReqCityValue.php b/hwe/sammo/Constraint/ReqCityValue.php index 80d8be49..25f2f8a6 100644 --- a/hwe/sammo/Constraint/ReqCityValue.php +++ b/hwe/sammo/Constraint/ReqCityValue.php @@ -111,7 +111,9 @@ class ReqCityValue extends Constraint{ return '부족합니다.'; }, '>'=>function($target, $src){ - return $target > $src; + if($target > $src){ + return true; + } if($src == 0){ return '없습니다'; } diff --git a/hwe/sammo/Constraint/ReqDestCityValue.php b/hwe/sammo/Constraint/ReqDestCityValue.php index d5b9fc10..76fddb2f 100644 --- a/hwe/sammo/Constraint/ReqDestCityValue.php +++ b/hwe/sammo/Constraint/ReqDestCityValue.php @@ -111,7 +111,9 @@ class ReqDestCityValue extends Constraint{ return '부족합니다.'; }, '>'=>function($target, $src){ - return $target > $src; + if($target > $src){ + return true; + } if($src == 0){ return '없습니다'; } diff --git a/hwe/sammo/Constraint/ReqDestNationValue.php b/hwe/sammo/Constraint/ReqDestNationValue.php index 5de227d8..8369157d 100644 --- a/hwe/sammo/Constraint/ReqDestNationValue.php +++ b/hwe/sammo/Constraint/ReqDestNationValue.php @@ -111,7 +111,9 @@ class ReqDestNationValue extends Constraint{ return '부족합니다.'; }, '>'=>function($target, $src){ - return $target > $src; + if($target > $src){ + return true; + } if($src == 0){ return '없습니다'; } diff --git a/hwe/sammo/Constraint/ReqGeneralValue.php b/hwe/sammo/Constraint/ReqGeneralValue.php index 8ed7453e..079531d2 100644 --- a/hwe/sammo/Constraint/ReqGeneralValue.php +++ b/hwe/sammo/Constraint/ReqGeneralValue.php @@ -89,7 +89,9 @@ class ReqGeneralValue extends Constraint{ return '부족합니다.'; }, '>'=>function($target, $src){ - return $target > $src; + if($target > $src){ + return true; + } if($src == 0){ return '없습니다'; } diff --git a/hwe/sammo/Constraint/ReqNationAuxValue.php b/hwe/sammo/Constraint/ReqNationAuxValue.php index 73b18ac7..5a896278 100644 --- a/hwe/sammo/Constraint/ReqNationAuxValue.php +++ b/hwe/sammo/Constraint/ReqNationAuxValue.php @@ -135,7 +135,9 @@ class ReqNationAuxValue extends Constraint{ return '부족합니다.'; }, '>'=>function($target, $src){ - return $target > $src; + if($target > $src){ + return true; + } if($src == 0){ return '없습니다'; } diff --git a/hwe/sammo/Constraint/ReqNationValue.php b/hwe/sammo/Constraint/ReqNationValue.php index 5d701f81..dedb35f4 100644 --- a/hwe/sammo/Constraint/ReqNationValue.php +++ b/hwe/sammo/Constraint/ReqNationValue.php @@ -111,7 +111,9 @@ class ReqNationValue extends Constraint{ return '부족합니다.'; }, '>'=>function($target, $src){ - return $target > $src; + if($target > $src){ + return true; + } if($src == 0){ return '없습니다'; } diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 2043a56c..8141187f 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -8,15 +8,6 @@ use sammo\WarUnitTrigger as WarUnitTrigger; class General implements iAction{ use LazyVarUpdater; - /** - * @var iAction $nationType - * @var iAction $officerLevelObj - * @var iAction $specialDomesticObj - * @var iAction $specialWarObj - * @var iAction $personalityObj - * @var iAction[] $itemObjs - */ - protected $raw = []; protected $rawCity = null; @@ -32,11 +23,17 @@ class General implements iAction{ protected $logActivatedSkill = []; protected $isFinished = false; + /** @var iAction */ protected $nationType = null; + /** @var iAction */ protected $officerLevelObj = null; + /** @var iAction */ protected $specialDomesticObj = null; + /** @var iAction */ protected $specialWarObj = null; + /** @var iAction */ protected $personalityObj = null; + /** @var iAction[] */ protected $itemObjs = []; protected $lastTurn = null; @@ -79,8 +76,8 @@ class General implements iAction{ /** * @param array $raw DB row값. * @param null|array $city DB city 테이블의 row값 - * @param int $year 게임 연도 - * @param int $month 게임 월 + * @param int|null $year 게임 연도 + * @param int|null $month 게임 월 * @param bool $fullConstruct iAction, 및 ActionLogger 초기화 여부, false인 경우 no, name, city, nation, officer_level 정도로 초기화 가능 */ public function __construct(array $raw, ?array $rawRank, ?array $city, ?array $nation, ?int $year, ?int $month, bool $fullConstruct=true){ @@ -270,7 +267,11 @@ class General implements iAction{ } function getCrewTypeObj():GameUnitDetail{ - return GameUnitConst::byID($this->getVar('crewtype')); + $crewType = GameUnitConst::byID($this->getVar('crewtype')); + if($crewType === null){ + throw new \InvalidArgumentException('Invalid CrewType:'.$this->getVar('crewtype')); + } + return $crewType; } function calcRecentWarTurn(int $turnTerm):int{ @@ -292,7 +293,7 @@ class General implements iAction{ return 0; } - $result = intdiv($secDiff, 60 * $turnTerm); + $result = intdiv(Util::toInt($secDiff), 60 * $turnTerm); $this->calcCache[$cacheKey] = $result; return $result; } diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index 4c6bfc8e..45a83d8b 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -8,9 +8,7 @@ use sammo\Scenario\NPC; class GeneralAI { - /** - * @var General $general - */ + /** @var General */ protected $general; /** @var array */ protected $city; @@ -92,8 +90,12 @@ class GeneralAI if ($general->getRawCity() === null) { $city = $db->queryFirstRow('SELECT * FROM city WHERE city = %i', $general->getCityID()); $general->setRawCity($city); + $this->city = $city; } - $this->city = $general->getRawCity(); + else{ + $this->city = $general->getRawCity(); + } + $this->nation = $db->queryFirstRow( 'SELECT nation,name,color,capital,capset,gennum,gold,rice,bill,rate,rate_tmp,scout,war,strategic_cmd_limit,surlimit,tech,power,level,l12set,l11set,l10set,l9set,l8set,l7set,l6set,l5set,type,aux FROM nation WHERE nation = %i', $general->getNationID() @@ -496,7 +498,7 @@ class GeneralAI return null; } - $turnList = General::getReservedTurnByGeneralList(array_keys($generalCadidates), 0, $this->env); + $turnList = General::getReservedTurnByGeneralList($generalCadidates, 0, $this->env); $generalCadidates = array_filter($generalCadidates, function(General $general)use($turnList){ $generalID = $general->getID(); if($turnList[$generalID] instanceof Command\General\che_징병){ @@ -2898,8 +2900,6 @@ class GeneralAI 'amount' => GameConst::$maxResourceActionAmount ]); } - - return null; } protected function do중립(): GeneralCommand @@ -3205,6 +3205,9 @@ class GeneralAI return $reservedCommand; } $result = $this->do집합(); + if(!$result){ + throw new MustNotBeReachedException(); + } $result->reason='do집합'; return $result; } diff --git a/hwe/sammo/LazyVarUpdater.php b/hwe/sammo/LazyVarUpdater.php index 8a7a7768..22bd55cb 100644 --- a/hwe/sammo/LazyVarUpdater.php +++ b/hwe/sammo/LazyVarUpdater.php @@ -4,6 +4,7 @@ namespace sammo; trait LazyVarUpdater{ protected $raw = []; protected $updatedVar = []; + protected $auxVar = null; protected $auxUpdated = false; function getRaw(bool $extractAux=false):array{ diff --git a/hwe/sammo/MessageTarget.php b/hwe/sammo/MessageTarget.php index 38878bff..c8ec7ba5 100644 --- a/hwe/sammo/MessageTarget.php +++ b/hwe/sammo/MessageTarget.php @@ -38,7 +38,7 @@ class MessageTarget extends Target { public static function buildFromArray($arr) { if(!$arr){ - return null; + throw new \InvalidArgumentException(); } if(!Util::array_get($arr['nation_id'])){ $arr['nation'] = '재야'; @@ -71,7 +71,7 @@ class MessageTarget extends Target { ) = $db->queryFirstList('SELECT `name`, nation, imgsvr, picture FROM general WHERE `no`=%i', $generalID); if($generalName === null){ - return null; + throw new \RuntimeException('장수가 없음:'.$generalID); } $icon = GetImageURL($imgsvr, $picture); diff --git a/hwe/sammo/TextDecoration/DyingMessage.php b/hwe/sammo/TextDecoration/DyingMessage.php index 4578ed45..da073a55 100644 --- a/hwe/sammo/TextDecoration/DyingMessage.php +++ b/hwe/sammo/TextDecoration/DyingMessage.php @@ -6,6 +6,7 @@ use \sammo\Util; use \sammo\JosaUtil; class DyingMessage{ + private $general; private $name; private $realName; private $npc; diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index 015699d9..7135e18f 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -4,9 +4,7 @@ namespace sammo; use \Symfony\Component\Lock; class TurnExecutionHelper { - /** - * @var General $generalObj; - */ + /** @var General*/ protected $generalObj; public function __construct(General $general) @@ -267,17 +265,16 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', } $autorunMode = false; - $tryAutorun = false; + $ai = null; if($general->getVar('npc') >= 2 || ($autorun_user['limit_minutes']??false)){ - $tryAutorun = true; $ai = new GeneralAI($turnObj->getGeneral()); } if(!$turnObj->processBlocked()){ $turnObj->preprocessCommand(); if($hasNationTurn){ - if($tryAutorun){ + if($ai){ $nationCommandObj = $ai->chooseNationTurn($nationCommandObj); LogText("NationTurn", "General, {$general->getName()}, {$general->getID()}, {$general->getStaticNation()['name']}, {$nationCommandObj->getBrief()}, {$nationCommandObj->reason}, "); } @@ -287,7 +284,7 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', $nationStor->setValue($lastNationTurnKey, $resultNationTurn->toJson()); } - if($tryAutorun){ + if($ai){ $newGeneralCommandObj = $ai->chooseGeneralTurn($generalCommandObj); // npc AI 처리 if($generalCommandObj !== $newGeneralCommandObj){ $autorunMode = true; @@ -347,7 +344,7 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', $prevTurn = cutTurn($gameStor->turntime, $gameStor->turnterm); $nextTurn = addTurn($prevTurn, $gameStor->turnterm); - $maxActionTime = ini_get('max_execution_time'); + $maxActionTime = Util::toInt(ini_get('max_execution_time')); if($maxActionTime == 0){ $maxActionTime = 60; } diff --git a/hwe/sammo/WarUnit.php b/hwe/sammo/WarUnit.php index b49fcb41..31818347 100644 --- a/hwe/sammo/WarUnit.php +++ b/hwe/sammo/WarUnit.php @@ -143,7 +143,11 @@ class WarUnit{ } function getLogger():ActionLogger{ - return $this->getGeneral()->getLogger(); + $logger = $this->getGeneral()->getLogger(); + if($logger === null){ + throw new \RuntimeException(); + } + return $logger; } function getKilled():int{ diff --git a/hwe/sammo/WarUnitCity.php b/hwe/sammo/WarUnitCity.php index 1a051513..c721f9ef 100644 --- a/hwe/sammo/WarUnitCity.php +++ b/hwe/sammo/WarUnitCity.php @@ -149,7 +149,7 @@ class WarUnitCity extends WarUnit{ } - function applyDB($db):bool{ + function applyDB(\MeekroDB $db):bool{ $updateVals = $this->getUpdatedValues(); $this->getLogger()->rollback(); //수비 도시의 로그는 기록하지 않음 diff --git a/hwe/sammo/WarUnitGeneral.php b/hwe/sammo/WarUnitGeneral.php index 0e394a17..42f5ea3c 100644 --- a/hwe/sammo/WarUnitGeneral.php +++ b/hwe/sammo/WarUnitGeneral.php @@ -2,6 +2,8 @@ namespace sammo; class WarUnitGeneral extends WarUnit{ + protected $raw; + function __construct(General $general, array $rawNation, bool $isAttacker){ $this->general = $general; $this->raw = $general->getRaw(); @@ -301,10 +303,7 @@ class WarUnitGeneral extends WarUnit{ $this->checkStatChange(); } - /** - * @param \MeekroDB $db - */ - function applyDB($db):bool{ + function applyDB(\MeekroDB $db):bool{ $affected = $this->getGeneral()->applyDB($db); $this->getLogger()->flush(); return $affected; diff --git a/src/sammo/KVStorage.php b/src/sammo/KVStorage.php index 8f7eabbd..56597638 100644 --- a/src/sammo/KVStorage.php +++ b/src/sammo/KVStorage.php @@ -1,6 +1,8 @@ setValue($key, $value); + $this->setValue($key, $value); } public function __unset($key){ @@ -63,7 +65,9 @@ class KVStorage{ } public function invalidateCacheValue($key):self{ - $key = mb_strtolower($key); + if(is_string($key)){ + $key = mb_strtolower($key); + } if($this->cacheData === null){ return $this; } @@ -192,8 +196,15 @@ class KVStorage{ return $result; } + /** + * @param string|int $key + * @param bool $onlyCache + * @return mixed|null + */ public function getValue($key, bool $onlyCache=false){ - $key = mb_strtolower($key); + if(is_string($key)){ + $key = mb_strtolower($key); + } if($this->cacheData !== null && ($onlyCache || key_exists($key, $this->cacheData))){ return $this->cacheData[$key] ?? null; } @@ -205,8 +216,17 @@ class KVStorage{ return $value; } + /** + * + * @param string|int $key + * @param mixed $value + * @return KVStorage + * @throws MeekroDBException + */ public function setValue($key, $value):self{ - $key = mb_strtolower($key); + if(is_string($key)){ + $key = mb_strtolower($key); + } if($value === null){ return $this->deleteValue($key); } @@ -217,8 +237,17 @@ class KVStorage{ return $this->setDBValue($key, $value); } + /** + * + * @param string|int $key + * @param mixed $value + * @return KVStorage + * @throws MeekroDBException + */ public function deleteValue($key):self{ - $key = mb_strtolower($key); + if(is_string($key)){ + $key = mb_strtolower($key); + } if(isset($this->cacheData[$key])){ unset($this->cacheData[$key]); } diff --git a/src/sammo/Session.php b/src/sammo/Session.php index ef29cba1..c0689e49 100644 --- a/src/sammo/Session.php +++ b/src/sammo/Session.php @@ -52,9 +52,9 @@ class Session public function restart(): Session { //NOTE: logout 프로세스는 아예 세션을 날려버리기도 하므로, 항상 안전하게 session_restart가 가능함을 보장하지 않음. - ini_set('session.use_only_cookies', false); - ini_set('session.use_cookies', false); - ini_set('session.use_trans_sid', false); + ini_set('session.use_only_cookies', 'false'); + ini_set('session.use_cookies', 'false'); + ini_set('session.use_trans_sid', 'false'); ini_set('session.cache_limiter', "none"); session_id($this->sessionID); session_start(); // second session_start diff --git a/src/sammo/TimeUtil.php b/src/sammo/TimeUtil.php index 0f62231a..46881e14 100644 --- a/src/sammo/TimeUtil.php +++ b/src/sammo/TimeUtil.php @@ -76,13 +76,13 @@ class TimeUtil return date('H:i:s', strtotime('00:00:00') + $second); } - public static function today() + public static function today():string { $obj = new \DateTime(); return $obj->format('Y-m-d'); } - public static function now(bool $withFraction=false) + public static function now(bool $withFraction=false):string { $obj = new \DateTime(); if(!$withFraction){ @@ -91,7 +91,7 @@ class TimeUtil return $obj->format('Y-m-d H:i:s.u'); } - public static function nowAddDays($day, bool $withFraction=false) + public static function nowAddDays($day, bool $withFraction=false):string { $obj = new \DateTime(); $obj->add(static::secondsToDateInterval($day * 3600 * 24)); @@ -101,7 +101,7 @@ class TimeUtil return $obj->format('Y-m-d H:i:s.u'); } - public static function nowAddHours($hour, bool $withFraction=false) + public static function nowAddHours($hour, bool $withFraction=false):string { $obj = new \DateTime(); $obj->add(static::secondsToDateInterval($hour * 3600)); @@ -111,7 +111,7 @@ class TimeUtil return $obj->format('Y-m-d H:i:s.u'); } - public static function nowAddMinutes($minute, bool $withFraction=false) + public static function nowAddMinutes($minute, bool $withFraction=false):string { $obj = new \DateTime(); $obj->add(static::secondsToDateInterval($minute * 60)); @@ -121,7 +121,7 @@ class TimeUtil return $obj->format('Y-m-d H:i:s.u'); } - public static function nowAddSeconds($second, bool $withFraction=false) + public static function nowAddSeconds($second, bool $withFraction=false):string { $obj = new \DateTime(); $obj->add(static::secondsToDateInterval($second)); diff --git a/src/sammo/Util.php b/src/sammo/Util.php index 83e8d64c..19705e75 100644 --- a/src/sammo/Util.php +++ b/src/sammo/Util.php @@ -567,7 +567,7 @@ class Util extends \utilphp\util * * @param array $array 배열. 1차원 배열 또는 2차원 배열 * @param int|string|null $key 2차원 배열에서 참조할 키. - * @return int|float 합계 + * @return array */ public static function arrayGroupBy(array $array, $key, bool $preserveRowKey=false) { $result = array();