From ff87555eba0e24078f7aa88d591a3e7aafc4c165 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 21 Oct 2018 15:20:27 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=84=EA=B4=80=20=EC=B6=94=EA=B0=80.=20?= =?UTF-8?q?=EC=9C=A0=EB=8B=88=ED=81=AC=20=EB=B3=B5=EA=B6=8C=20=EC=B6=94?= =?UTF-8?q?=EC=B2=A8=EC=9D=84=20General=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func.php | 24 +-- hwe/func_process_personnel.old.php | 59 ++++++ hwe/func_process_personnel.php | 59 ------ hwe/sammo/Command/General/che_강행.php | 2 +- hwe/sammo/Command/General/che_견문.php | 2 +- hwe/sammo/Command/General/che_군량매매.php | 2 +- hwe/sammo/Command/General/che_귀환.php | 6 +- hwe/sammo/Command/General/che_기술연구.php | 9 +- hwe/sammo/Command/General/che_단련.php | 7 +- hwe/sammo/Command/General/che_등용.php | 13 +- hwe/sammo/Command/General/che_물자조달.php | 6 +- hwe/sammo/Command/General/che_사기진작.php | 9 +- hwe/sammo/Command/General/che_상업투자.php | 9 +- hwe/sammo/Command/General/che_소집해제.php | 2 +- hwe/sammo/Command/General/che_요양.php | 2 +- hwe/sammo/Command/General/che_이동.php | 2 +- hwe/sammo/Command/General/che_임관.php | 170 ++++++++++++++++++ hwe/sammo/Command/General/che_장비매매.php | 2 +- hwe/sammo/Command/General/che_전투태세.php | 9 +- hwe/sammo/Command/General/che_정착장려.php | 9 +- hwe/sammo/Command/General/che_주민선정.php | 9 +- hwe/sammo/Command/General/che_증여.php | 11 +- hwe/sammo/Command/General/che_집합.php | 7 +- hwe/sammo/Command/General/che_징병.php | 7 +- hwe/sammo/Command/General/che_첩보.php | 2 +- hwe/sammo/Command/General/che_출병.php | 7 +- hwe/sammo/Command/General/che_헌납.php | 4 +- hwe/sammo/Command/General/che_훈련.php | 9 +- hwe/sammo/Constraint/AllowJoinAction.php | 35 ++++ hwe/sammo/Constraint/AllowJoinDestNation.php | 61 +++++++ hwe/sammo/Constraint/AllowWar.php | 2 +- hwe/sammo/Constraint/BeNeutral.php | 32 ++++ hwe/sammo/Constraint/ExistsDestNation.php | 27 +++ .../{NoNeutral.php => NotBeNeutral.php} | 8 +- .../{NoOpeningPart.php => NotOpeningPart.php} | 2 +- ...eringNation.php => NotWanderingNation.php} | 2 +- hwe/sammo/GameConstBase.php | 2 + hwe/sammo/General.php | 2 +- 38 files changed, 467 insertions(+), 165 deletions(-) create mode 100644 hwe/sammo/Command/General/che_임관.php create mode 100644 hwe/sammo/Constraint/AllowJoinAction.php create mode 100644 hwe/sammo/Constraint/AllowJoinDestNation.php create mode 100644 hwe/sammo/Constraint/BeNeutral.php create mode 100644 hwe/sammo/Constraint/ExistsDestNation.php rename hwe/sammo/Constraint/{NoNeutral.php => NotBeNeutral.php} (72%) rename hwe/sammo/Constraint/{NoOpeningPart.php => NotOpeningPart.php} (94%) rename hwe/sammo/Constraint/{NoWanderingNation.php => NotWanderingNation.php} (94%) diff --git a/hwe/func.php b/hwe/func.php index eb6b56bb..65c58613 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -1695,25 +1695,19 @@ function CheckHall($no) { } } -function uniqueItemEx(int $generalID, ActionLogger $logger, string $acquireType='아이템'):bool { - //TODO: 이름 바꾸기 +function tryUniqueItemLottery(General $general, string $acquireType='아이템'):bool{ $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); - $general = $db->queryFirstRow('SELECT no,name,nation,npc,weap,book,horse,item FROM general WHERE no=%i', $generalID); - if(!$general){ + if($general->getVar('npc') >= 2){ return false; } - if($general['npc'] >= 2) { - return false; - } - if($general['horse'] > 6 || $general['weap'] > 6 || $general['book'] > 6 || $general['item'] > 6){ + if($general->getVar('npc') > 6 || $general->getVar('weap') > 6 || $general->getVar('book') > 6 || $general->getVar('item') > 6){ return false; } $scenario = $gameStor->scenario; - $genCount = $db->queryFirstField('SELECT count(*) FROM general WHERE npc<2'); if ($scenario < 100) { @@ -1768,16 +1762,16 @@ function uniqueItemEx(int $generalID, ActionLogger $logger, string $acquireType= [$itemType, $itemCode] = Util::choiceRandom($availableUnique); - $nationName = getNationStaticInfo($general['nation'])['name']; - $generalName = $general['name']; + $nationName = $general->getStaticNation()['name']; + $generalName = $general->getNation(); $josaYi = JosaUtil::pick($generalName, '이'); $itemName = ($itemTypes[$itemType])($itemCode); $josaUl = JosaUtil::pick($itemName, '을'); - - $db->update('general', [ - $itemType=>$itemCode - ], 'no=%i', $generalID); + + $general->setVar($itemType, $itemCode); + + $logger = $general->getLogger(); $logger->pushGeneralActionLog("{$itemName}{$josaUl} 습득했습니다!"); $logger->pushGlobalActionLog("{$generalName}{$josaYi} {$itemName}{$josaUl} 습득했습니다!"); diff --git a/hwe/func_process_personnel.old.php b/hwe/func_process_personnel.old.php index eb111376..f2753864 100644 --- a/hwe/func_process_personnel.old.php +++ b/hwe/func_process_personnel.old.php @@ -1,6 +1,65 @@ get(); + + $log = []; + $alllog = []; + $history = []; + $date = substr($general['turntime'],11,5); + + $admin = $gameStor->getValues(['startyear','year','month','develcost']); + + $query = "select nation,supply from city where city='{$general['city']}'"; + $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $city = MYDB_fetch_array($result); + + $command = DecodeCommand($general['turn0']); + $who = $command[1]; + + $query = "select * from general where no='$who'"; + $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + $you = MYDB_fetch_array($result); + + $cost = Util::round($admin['develcost'] + ($you['experience'] + $you['dedication'])/1000) * 10; + + if(!$you) { + $log[] = "●{$admin['month']}월:없는 장수입니다. 등용 실패. <1>$date"; + } elseif($admin['year'] < $admin['startyear']+3) { + $log[] = "●{$admin['month']}월:초반 제한중입니다. 등용 실패. <1>$date"; + } elseif($city['nation'] != $general['nation']) { + $log[] = "●{$admin['month']}월:아국이 아닙니다. 등용 실패. <1>$date"; + } elseif($city['supply'] == 0) { + $log[] = "●{$admin['month']}월:고립된 도시입니다. 등용 실패. <1>$date"; + } elseif($general['gold'] < $cost) { + $log[] = "●{$admin['month']}월:자금이 모자랍니다. 등용 실패. <1>$date"; + } else { + $log[] = "●{$admin['month']}월:{$you['name']}에게 등용 권유 서신을 보냈습니다. <1>$date"; + $exp = 100; + $ded = 200; + + // 성격 보정 + $exp = CharExperience($exp, $general['personal']); + $ded = CharDedication($ded, $general['personal']); + + $msg = ScoutMessage::buildScoutMessage($general['no'], $who, $reason); + if($msg){ + $msg->send(true); + } + + + $general['intel2']++; + $query = "update general set resturn='SUCCESS',gold=gold-'$cost',intel2='{$general['intel2']}',dedication=dedication+'$ded',experience=experience+'$exp' where no='{$general['no']}'"; + MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); + + $log = checkAbility($general, $log); + } + pushGenLog($general, $log); +} + function process_25(&$general) { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/func_process_personnel.php b/hwe/func_process_personnel.php index f2753864..eb111376 100644 --- a/hwe/func_process_personnel.php +++ b/hwe/func_process_personnel.php @@ -1,65 +1,6 @@ get(); - - $log = []; - $alllog = []; - $history = []; - $date = substr($general['turntime'],11,5); - - $admin = $gameStor->getValues(['startyear','year','month','develcost']); - - $query = "select nation,supply from city where city='{$general['city']}'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $city = MYDB_fetch_array($result); - - $command = DecodeCommand($general['turn0']); - $who = $command[1]; - - $query = "select * from general where no='$who'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $you = MYDB_fetch_array($result); - - $cost = Util::round($admin['develcost'] + ($you['experience'] + $you['dedication'])/1000) * 10; - - if(!$you) { - $log[] = "●{$admin['month']}월:없는 장수입니다. 등용 실패. <1>$date"; - } elseif($admin['year'] < $admin['startyear']+3) { - $log[] = "●{$admin['month']}월:초반 제한중입니다. 등용 실패. <1>$date"; - } elseif($city['nation'] != $general['nation']) { - $log[] = "●{$admin['month']}월:아국이 아닙니다. 등용 실패. <1>$date"; - } elseif($city['supply'] == 0) { - $log[] = "●{$admin['month']}월:고립된 도시입니다. 등용 실패. <1>$date"; - } elseif($general['gold'] < $cost) { - $log[] = "●{$admin['month']}월:자금이 모자랍니다. 등용 실패. <1>$date"; - } else { - $log[] = "●{$admin['month']}월:{$you['name']}에게 등용 권유 서신을 보냈습니다. <1>$date"; - $exp = 100; - $ded = 200; - - // 성격 보정 - $exp = CharExperience($exp, $general['personal']); - $ded = CharDedication($ded, $general['personal']); - - $msg = ScoutMessage::buildScoutMessage($general['no'], $who, $reason); - if($msg){ - $msg->send(true); - } - - - $general['intel2']++; - $query = "update general set resturn='SUCCESS',gold=gold-'$cost',intel2='{$general['intel2']}',dedication=dedication+'$ded',experience=experience+'$exp' where no='{$general['no']}'"; - MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - - $log = checkAbility($general, $log); - } - pushGenLog($general, $log); -} - function process_25(&$general) { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/Command/General/che_강행.php b/hwe/sammo/Command/General/che_강행.php index 47f281ef..c9f4ff9f 100644 --- a/hwe/sammo/Command/General/che_강행.php +++ b/hwe/sammo/Command/General/che_강행.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; diff --git a/hwe/sammo/Command/General/che_견문.php b/hwe/sammo/Command/General/che_견문.php index 0ebe35b4..58983730 100644 --- a/hwe/sammo/Command/General/che_견문.php +++ b/hwe/sammo/Command/General/che_견문.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; diff --git a/hwe/sammo/Command/General/che_군량매매.php b/hwe/sammo/Command/General/che_군량매매.php index 6f76ff7c..b3c0a15b 100644 --- a/hwe/sammo/Command/General/che_군량매매.php +++ b/hwe/sammo/Command/General/che_군량매매.php @@ -14,7 +14,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx, + tryUniqueItemLottery, getItemCost, getItemCost2, getItemInfo, getHorseName, getWeapName, getBookName, getItemName diff --git a/hwe/sammo/Command/General/che_귀환.php b/hwe/sammo/Command/General/che_귀환.php index 7a398173..ad8daa36 100644 --- a/hwe/sammo/Command/General/che_귀환.php +++ b/hwe/sammo/Command/General/che_귀환.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -38,8 +38,8 @@ class che_귀환 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], - ['NoWanderingNation'], + ['NotBeNeutral'], + ['NotWanderingNation'], ['NotCapital', 1], ]; } diff --git a/hwe/sammo/Command/General/che_기술연구.php b/hwe/sammo/Command/General/che_기술연구.php index 2d623c20..55120960 100644 --- a/hwe/sammo/Command/General/che_기술연구.php +++ b/hwe/sammo/Command/General/che_기술연구.php @@ -14,7 +14,7 @@ use function sammo\{ getDomesticExpLevelBonus, CriticalRatioDomestic, CriticalScoreEx, - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -40,8 +40,8 @@ class che_기술연구 extends che_상업투자{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], - ['NoWanderingNation'], + ['NotBeNeutral'], + ['NotWanderingNation'], ['OccupiedCity'], ['SuppliedCity'], ['ReqGeneralGold', $reqGold], @@ -129,10 +129,9 @@ class che_기술연구 extends che_상업투자{ $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); + tryUniqueItemLottery($general); $general->applyDB($db); - uniqueItemEx($general->getID(), $logger); - return true; } diff --git a/hwe/sammo/Command/General/che_단련.php b/hwe/sammo/Command/General/che_단련.php index 479b8ad5..487ba8e5 100644 --- a/hwe/sammo/Command/General/che_단련.php +++ b/hwe/sammo/Command/General/che_단련.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -37,7 +37,7 @@ class che_단련 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], + ['NotBeNeutral'], ['ReqGeneralCrew'], ['ReqGeneralValue', 'train', '훈련', GameConst::$defaultTrainHigh], ['ReqGeneralValue', 'atmos', '사기', GameConst::$defaultAtmosHigh], @@ -112,9 +112,8 @@ class che_단련 extends Command\GeneralCommand{ $general->increaseVar($incStat, 1); $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); + tryUniqueItemLottery($general); $general->applyDB($db); - - uniqueItemEx($general->getID(), $logger); return true; } diff --git a/hwe/sammo/Command/General/che_등용.php b/hwe/sammo/Command/General/che_등용.php index 0cbe0bd0..5d9caee7 100644 --- a/hwe/sammo/Command/General/che_등용.php +++ b/hwe/sammo/Command/General/che_등용.php @@ -16,7 +16,7 @@ use function \sammo\{ getDomesticExpLevelBonus, CriticalRatioDomestic, CriticalScoreEx, - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -53,19 +53,14 @@ class che_등용 extends Command\GeneralCommand{ $this->setCity(); $this->setNation(); - try{ - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['nation'], 0); - } - catch(NoDBResultException $e){ - $destGeneral = new DummyGeneral(false); - } + $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['nation'], 0); $this->setDestGeneral($destGeneral); [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], - ['NoOpeningPart'], + ['NotBeNeutral'], + ['NotOpeningPart'], ['OccupiedCity'], ['SuppliedCity'], ['ExistsDestGeneral'], diff --git a/hwe/sammo/Command/General/che_물자조달.php b/hwe/sammo/Command/General/che_물자조달.php index 4ef473d8..3b0587e2 100644 --- a/hwe/sammo/Command/General/che_물자조달.php +++ b/hwe/sammo/Command/General/che_물자조달.php @@ -15,7 +15,7 @@ use function \sammo\{ getDomesticExpLevelBonus, CriticalRatioDomestic, CriticalScoreEx, - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -37,8 +37,8 @@ class che_물자조달 extends Command\GeneralCommand{ $this->setNation(); $this->runnableConstraints=[ - ['NoNeutral'], - ['NoWanderingNation'], + ['NotBeNeutral'], + ['NotWanderingNation'], ['OccupiedCity'], ['SuppliedCity'] ]; diff --git a/hwe/sammo/Command/General/che_사기진작.php b/hwe/sammo/Command/General/che_사기진작.php index b00b091f..fd79fc4c 100644 --- a/hwe/sammo/Command/General/che_사기진작.php +++ b/hwe/sammo/Command/General/che_사기진작.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -36,8 +36,8 @@ class che_사기진작 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], - ['NoWanderingNation'], + ['NotBeNeutral'], + ['NotWanderingNation'], ['OccupiedCity'], ['ReqGeneralCrew'], ['ReqGeneralGold', $reqGold], @@ -94,10 +94,9 @@ class che_사기진작 extends Command\GeneralCommand{ $general->increaseVar('leader2', 1); $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); + tryUniqueItemLottery($general); $general->applyDB($db); - uniqueItemEx($general->getID(), $logger); - return true; } diff --git a/hwe/sammo/Command/General/che_상업투자.php b/hwe/sammo/Command/General/che_상업투자.php index 286b7e4f..38b96890 100644 --- a/hwe/sammo/Command/General/che_상업투자.php +++ b/hwe/sammo/Command/General/che_상업투자.php @@ -15,7 +15,7 @@ use function \sammo\{ getDomesticExpLevelBonus, CriticalRatioDomestic, CriticalScoreEx, - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -43,8 +43,8 @@ class che_상업투자 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], - ['NoWanderingNation'], + ['NotBeNeutral'], + ['NotWanderingNation'], ['OccupiedCity'], ['SuppliedCity'], ['ReqGeneralGold', $reqGold], @@ -172,9 +172,8 @@ class che_상업투자 extends Command\GeneralCommand{ $general->increaseVar(static::$statKey.'2', 1); $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); + tryUniqueItemLottery($general); $general->applyDB($db); - - uniqueItemEx($general->getID(), $logger); return true; } diff --git a/hwe/sammo/Command/General/che_소집해제.php b/hwe/sammo/Command/General/che_소집해제.php index 04c53a32..8f52735b 100644 --- a/hwe/sammo/Command/General/che_소집해제.php +++ b/hwe/sammo/Command/General/che_소집해제.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; diff --git a/hwe/sammo/Command/General/che_요양.php b/hwe/sammo/Command/General/che_요양.php index 401d6e2e..aad99faf 100644 --- a/hwe/sammo/Command/General/che_요양.php +++ b/hwe/sammo/Command/General/che_요양.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; diff --git a/hwe/sammo/Command/General/che_이동.php b/hwe/sammo/Command/General/che_이동.php index 8e6bf4ad..42722226 100644 --- a/hwe/sammo/Command/General/che_이동.php +++ b/hwe/sammo/Command/General/che_이동.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; diff --git a/hwe/sammo/Command/General/che_임관.php b/hwe/sammo/Command/General/che_임관.php new file mode 100644 index 00000000..fda4d72f --- /dev/null +++ b/hwe/sammo/Command/General/che_임관.php @@ -0,0 +1,170 @@ +arg['destNationID']??null; + $destGeneralID = $this->arg['destGeneralID']??null; + + if($destGeneralID === null && $destNationID === null){ + return false; + } + + if($destGeneralID !== null && $destNationID !== null){ + return false; + } + + if ($destNationID !== null) { + if(!is_int($destNationID)){ + return false; + } + if($destNationID < 1){ + return false; + } + + $this->arg = [ + 'destNationID' => $destNationID + ]; + } + else{ + if(!is_int($destGeneralID)){ + return false; + } + if($destGeneralID < 1){ + return false; + } + + $this->arg = [ + 'destGeneralID' => $destGeneralID + ]; + } + + return true; + } + + protected function init(){ + + $general = $this->generalObj; + + $this->setCity(); + $this->setNation(); + + $destGeneralID = $this->arg['destGeneralID']??null; + $destNationID = $this->arg['destNationID']??null; + if($destGeneralID !== null){ + $this->setDestGeneral($destGeneralID); + $this->setDestNation($this->destGeneralObj->getVar('nation')); + } + else{ + $this->setDestNation($destNationID, ['gennum', 'scout']); + } + + $relYear = $env['year'] = $env['startyear']; + + $this->runnableConstraints=[ + ['BeNeutral'], + ['ExistsDestNation'], + ['AllowJoinDestNation', $relYear], + ['AllowJoinAction'] + ]; + } + + public function getCost():array{ + return [0, 0]; + } + + public function getPreReqTurn():int{ + return 0; + } + + public function getPostReqTurn():int{ + return 0; + } + + public function run():bool{ + if(!$this->isRunnable()){ + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + $env = $this->env; + + $general = $this->generalObj; + $date = substr($general->getVar('turntime'),11,5); + $generalName = $general->getName(); + $josaYi = JosaUtil::pick($generalName, '이'); + + $destNation = $this->destNation; + $gennum = $destNation['gennum']; + $destNationID = $destNation['nation']; + $destNationName = $destNation['name']; + + $logger = $general->getLogger(); + + $logger->pushGeneralActionLog("{$destNationName}에 임관했습니다. <1>$date"); + $logger->pushGeneralHistoryLog("{$destNationName}에 임관"); + $logger->pushGlobalActionLog("{$generalName}{$josaYi} {$destNationName}임관했습니다."); + + if($gennum < GameConst::$initialNationGenLimit) { + $exp = 700; + } + else { + $exp = 100; + } + + $exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp); + $general->setVar('nation', $destNationID); + $general->setVar('level', 1); + $general->setVar('belong', 1); + + if($this->destGeneralObj !== null){ + $general->setVar('city', $this->destGeneralObj->getCityID()); + } + else{ + $targetCityID = $db->queryFirstField('SELECT city FROM nation WHERE nation = %i AND level=12', $destNationID); + $general->setVar('city', $targetCityID); + } + + $db->update('nation', [ + 'gennum'=>$db->sqleval('gennum + 1') + ], 'nation=%i', $destNationID); + + $relYear = $env['year'] = $env['startyear']; + if($general->getVar('npc') == 1 || $relYear >= 3){ + $joinedNations = Join::decode($general->getVar('nations')); + $joinedNations[] = $destNationID; + $general->setVar('nations', Join::encode($joinedNations)); + } + + $general->increaseVar('experience', $exp); + $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); + $general->checkStatChange(); + tryUniqueItemLottery($general); + $general->applyDB($db); + + return true; + } + + +} \ No newline at end of file diff --git a/hwe/sammo/Command/General/che_장비매매.php b/hwe/sammo/Command/General/che_장비매매.php index 38bc56ac..df5b3fb5 100644 --- a/hwe/sammo/Command/General/che_장비매매.php +++ b/hwe/sammo/Command/General/che_장비매매.php @@ -14,7 +14,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx, + tryUniqueItemLottery, getItemCost, getItemCost2, getItemInfo, getHorseName, getWeapName, getBookName, getItemName diff --git a/hwe/sammo/Command/General/che_전투태세.php b/hwe/sammo/Command/General/che_전투태세.php index de83fc0e..c6dc627c 100644 --- a/hwe/sammo/Command/General/che_전투태세.php +++ b/hwe/sammo/Command/General/che_전투태세.php @@ -13,7 +13,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx, getTechCost + tryUniqueItemLottery, getTechCost }; use \sammo\Constraint\Constraint; @@ -37,8 +37,8 @@ class che_전투태세 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], - ['NoWanderingNation'], + ['NotBeNeutral'], + ['NotWanderingNation'], ['OccupiedCity'], ['ReqGeneralCrew'], ['ReqGeneralGold', $reqGold], @@ -125,10 +125,9 @@ class che_전투태세 extends Command\GeneralCommand{ $general->increaseVar('leader2', 3); $general->setResultTurn($turnResult); $general->checkStatChange(); + tryUniqueItemLottery($general); $general->applyDB($db); - uniqueItemEx($general->getID(), $logger); - return true; } diff --git a/hwe/sammo/Command/General/che_정착장려.php b/hwe/sammo/Command/General/che_정착장려.php index f2b6e11b..bdccded6 100644 --- a/hwe/sammo/Command/General/che_정착장려.php +++ b/hwe/sammo/Command/General/che_정착장려.php @@ -15,7 +15,7 @@ use function \sammo\{ getDomesticExpLevelBonus, CriticalRatioDomestic, CriticalScoreEx, - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -43,8 +43,8 @@ class che_정착장려 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], - ['NoWanderingNation'], + ['NotBeNeutral'], + ['NotWanderingNation'], ['OccupiedCity'], ['SuppliedCity'], ['ReqGeneralGold', $reqGold], @@ -159,9 +159,8 @@ class che_정착장려 extends Command\GeneralCommand{ $general->increaseVar(static::$statKey.'2', 1); $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); + tryUniqueItemLottery($general); $general->applyDB($db); - - uniqueItemEx($general->getID(), $logger); return true; } diff --git a/hwe/sammo/Command/General/che_주민선정.php b/hwe/sammo/Command/General/che_주민선정.php index 84d3a1a0..032d5e90 100644 --- a/hwe/sammo/Command/General/che_주민선정.php +++ b/hwe/sammo/Command/General/che_주민선정.php @@ -15,7 +15,7 @@ use function \sammo\{ getDomesticExpLevelBonus, CriticalRatioDomestic, CriticalScoreEx, - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -42,8 +42,8 @@ class che_주민선정 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], - ['NoWanderingNation'], + ['NotBeNeutral'], + ['NotWanderingNation'], ['OccupiedCity'], ['SuppliedCity'], ['ReqGeneralGold', $reqGold], @@ -156,9 +156,8 @@ class che_주민선정 extends Command\GeneralCommand{ $general->increaseVar(static::$statKey.'2', 1); $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); + tryUniqueItemLottery($general); $general->applyDB($db); - - uniqueItemEx($general->getID(), $logger); return true; } diff --git a/hwe/sammo/Command/General/che_증여.php b/hwe/sammo/Command/General/che_증여.php index e88168ba..361cf51a 100644 --- a/hwe/sammo/Command/General/che_증여.php +++ b/hwe/sammo/Command/General/che_증여.php @@ -15,7 +15,7 @@ use function \sammo\{ getDomesticExpLevelBonus, CriticalRatioDomestic, CriticalScoreEx, - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -69,16 +69,11 @@ class che_증여 extends Command\GeneralCommand{ $this->setCity(); $this->setNation(); - try{ - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], 1); - } - catch(NoDBResultException $e){ - $destGeneral = new DummyGeneral(false); - } + $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], 1); $this->setDestGeneral($destGeneral); $this->runnableConstraints=[ - ['NoNeutral'], + ['NotBeNeutral'], ['OccupiedCity'], ['SuppliedCity'], ['ExistsDestGeneral'], diff --git a/hwe/sammo/Command/General/che_집합.php b/hwe/sammo/Command/General/che_집합.php index 07a346ea..50d58afb 100644 --- a/hwe/sammo/Command/General/che_집합.php +++ b/hwe/sammo/Command/General/che_집합.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -39,7 +39,7 @@ class che_집합 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], + ['NotBeNeutral'], ['OccupiedCity'], ['SuppliedCity'], ['MustBeTroopLeader'], @@ -105,10 +105,9 @@ class che_집합 extends Command\GeneralCommand{ $general->increaseVar('leader2', 1); $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); + tryUniqueItemLottery($general); $general->applyDB($db); - uniqueItemEx($general->getID(), $logger); - return true; } diff --git a/hwe/sammo/Command/General/che_징병.php b/hwe/sammo/Command/General/che_징병.php index 432e65d5..e8e47548 100644 --- a/hwe/sammo/Command/General/che_징병.php +++ b/hwe/sammo/Command/General/che_징병.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -92,7 +92,7 @@ class che_징병 extends Command\GeneralCommand{ [$reqGold, $reqRice] = $this->getCost(); $this->runnableConstraints=[ - ['NoNeutral'], + ['NotBeNeutral'], ['OccupiedCity'], ['ReqCityCapacity', 'pop', '주민', 30000 + $reqCrew], ['ReqCityTrust', 20], @@ -186,10 +186,9 @@ class che_징병 extends Command\GeneralCommand{ $general->increaseVar('leader2', 1); $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); + tryUniqueItemLottery($general); $general->applyDB($db); - uniqueItemEx($general->getID(), $logger); - return true; } diff --git a/hwe/sammo/Command/General/che_첩보.php b/hwe/sammo/Command/General/che_첩보.php index 1433ae2a..9a2fa584 100644 --- a/hwe/sammo/Command/General/che_첩보.php +++ b/hwe/sammo/Command/General/che_첩보.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx, + tryUniqueItemLottery, searchDistance }; diff --git a/hwe/sammo/Command/General/che_출병.php b/hwe/sammo/Command/General/che_출병.php index 7a5d53ec..a4b72125 100644 --- a/hwe/sammo/Command/General/che_출병.php +++ b/hwe/sammo/Command/General/che_출병.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx, + tryUniqueItemLottery, processWar }; @@ -51,7 +51,7 @@ class che_출병 extends Command\GeneralCommand{ $this->runnableConstraints=[ ['NotOpeningPart'], ['NearCity', 1], - ['NoNeutral'], + ['NotBeNeutral'], ['OccupiedCity'], ['ReqGeneralCrew'], ['ReqGeneralRice', $reqRice], @@ -125,7 +125,8 @@ class che_출병 extends Command\GeneralCommand{ //TODO: 장기적으로 통합해야함 processWar($general->getRaw(), $this->destCity); - uniqueItemEx($general->getID(), $logger); + tryUniqueItemLottery($general); + $general->applyDB($db); return true; } diff --git a/hwe/sammo/Command/General/che_헌납.php b/hwe/sammo/Command/General/che_헌납.php index 6bd3ce88..5d8bee9e 100644 --- a/hwe/sammo/Command/General/che_헌납.php +++ b/hwe/sammo/Command/General/che_헌납.php @@ -15,7 +15,7 @@ use function \sammo\{ getDomesticExpLevelBonus, CriticalRatioDomestic, CriticalScoreEx, - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -55,7 +55,7 @@ class che_헌납 extends Command\GeneralCommand{ $this->setNation(); $this->runnableConstraints=[ - ['NoNeutral'], + ['NotBeNeutral'], ['OccupiedCity'], ['SuppliedCity'], ]; diff --git a/hwe/sammo/Command/General/che_훈련.php b/hwe/sammo/Command/General/che_훈련.php index 5245ab6f..b3cd8171 100644 --- a/hwe/sammo/Command/General/che_훈련.php +++ b/hwe/sammo/Command/General/che_훈련.php @@ -12,7 +12,7 @@ use \sammo\{ use function \sammo\{ - uniqueItemEx + tryUniqueItemLottery }; use \sammo\Constraint\Constraint; @@ -35,8 +35,8 @@ class che_훈련 extends Command\GeneralCommand{ $this->setNation(); $this->runnableConstraints=[ - ['NoNeutral'], - ['NoWanderingNation'], + ['NotBeNeutral'], + ['NotWanderingNation'], ['OccupiedCity'], ['ReqGeneralCrew'], ['ReqGeneralTrainMargin', GameConst::$maxTrainByCommand], @@ -91,10 +91,9 @@ class che_훈련 extends Command\GeneralCommand{ $general->increaseVar('leader2', 1); $general->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); + tryUniqueItemLottery($general); $general->applyDB($db); - uniqueItemEx($general->getID(), $logger); - return true; } diff --git a/hwe/sammo/Constraint/AllowJoinAction.php b/hwe/sammo/Constraint/AllowJoinAction.php new file mode 100644 index 00000000..abc72033 --- /dev/null +++ b/hwe/sammo/Constraint/AllowJoinAction.php @@ -0,0 +1,35 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require makelimit in general"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->general['makelimit'] == 0){ + return true; + } + + $joinActionLimit = GameConst::$joinActionLimit; + + $this->reason = "재야가 된지 {$joinActionLimit}턴이 지나야 합니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/AllowJoinDestNation.php b/hwe/sammo/Constraint/AllowJoinDestNation.php new file mode 100644 index 00000000..7dbb51ba --- /dev/null +++ b/hwe/sammo/Constraint/AllowJoinDestNation.php @@ -0,0 +1,61 @@ +nation)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require scout in nation"); + } + + if(!key_exists('gennum', $this->nation)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require gennum in nation"); + } + + if(!key_exists('nations', $this->general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require nations in nation"); + } + + $this->relYear = $this->arg; + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + $db = DB::db(); + + if($relYear < GameConst::$openingPartYear && $this->destNation['gennum'] >= GameConst::$initialNationGenLimit){ + $this->reason = "임관이 제한되고 있습니다."; + return false; + } + + if($this->destNation['scout'] == 0){ + $this->reason = "임관이 금지되어 있습니다."; + return false; + } + + $joinedNations = Json::decode($this->general['nations']); + if(in_array($this->destNation['nation'], $joinedNations)){ + $this->reason = "이미 임관했었던 국가입니다."; + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/AllowWar.php b/hwe/sammo/Constraint/AllowWar.php index ee2b1ff6..122b0e00 100644 --- a/hwe/sammo/Constraint/AllowWar.php +++ b/hwe/sammo/Constraint/AllowWar.php @@ -2,7 +2,7 @@ namespace sammo\Constraint; -class NotCapital extends Constraint{ +class AllowWar extends Constraint{ const REQ_VALUES = Constraint::REQ_NATION; public function checkInputValues(bool $throwExeception=true){ diff --git a/hwe/sammo/Constraint/BeNeutral.php b/hwe/sammo/Constraint/BeNeutral.php new file mode 100644 index 00000000..73b7682f --- /dev/null +++ b/hwe/sammo/Constraint/BeNeutral.php @@ -0,0 +1,32 @@ +general)){ + if(!$throwExeception){return false; } + throw new \InvalidArgumentException("require nation in general"); + } + + return true; + } + + public function test():bool{ + $this->checkInputValues(); + $this->tested = true; + + if($this->general['nation'] == 0){ + return true; + } + + $this->reason = "재야가 아닙니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/ExistsDestNation.php b/hwe/sammo/Constraint/ExistsDestNation.php new file mode 100644 index 00000000..de57e6e5 --- /dev/null +++ b/hwe/sammo/Constraint/ExistsDestNation.php @@ -0,0 +1,27 @@ +checkInputValues(); + $this->tested = true; + + if($this->destNation['nation']){ + return true; + } + + $this->reason = "없는 국가입니다."; + return false; + } +} \ No newline at end of file diff --git a/hwe/sammo/Constraint/NoNeutral.php b/hwe/sammo/Constraint/NotBeNeutral.php similarity index 72% rename from hwe/sammo/Constraint/NoNeutral.php rename to hwe/sammo/Constraint/NotBeNeutral.php index 7d86c0d3..8ecd8a1f 100644 --- a/hwe/sammo/Constraint/NoNeutral.php +++ b/hwe/sammo/Constraint/NotBeNeutral.php @@ -2,7 +2,7 @@ namespace sammo\Constraint; -class NoOpeningPart extends Constraint{ +class NotBeNeutral extends Constraint{ const REQ_VALUES = Constraint::REQ_GENERAL; public function checkInputValues(bool $throwExeception=true){ @@ -10,9 +10,9 @@ class NoOpeningPart extends Constraint{ return false; } - if(!key_exists('level', $this->general)){ + if(!key_exists('nation', $this->general)){ if(!$throwExeception){return false; } - throw new \InvalidArgumentException("require level in general"); + throw new \InvalidArgumentException("require nation in general"); } return true; @@ -22,7 +22,7 @@ class NoOpeningPart extends Constraint{ $this->checkInputValues(); $this->tested = true; - if($this->general['level'] != 0){ + if($this->general['nation'] != 0){ return true; } diff --git a/hwe/sammo/Constraint/NoOpeningPart.php b/hwe/sammo/Constraint/NotOpeningPart.php similarity index 94% rename from hwe/sammo/Constraint/NoOpeningPart.php rename to hwe/sammo/Constraint/NotOpeningPart.php index db7da18a..d1aad147 100644 --- a/hwe/sammo/Constraint/NoOpeningPart.php +++ b/hwe/sammo/Constraint/NotOpeningPart.php @@ -2,7 +2,7 @@ namespace sammo\Constraint; -class NoOpeningPart extends Constraint{ +class NotOpeningPart extends Constraint{ const REQ_VALUES = Constraint::REQ_INT_ARG; protected $relYear; diff --git a/hwe/sammo/Constraint/NoWanderingNation.php b/hwe/sammo/Constraint/NotWanderingNation.php similarity index 94% rename from hwe/sammo/Constraint/NoWanderingNation.php rename to hwe/sammo/Constraint/NotWanderingNation.php index 6291b7b3..52deff06 100644 --- a/hwe/sammo/Constraint/NoWanderingNation.php +++ b/hwe/sammo/Constraint/NotWanderingNation.php @@ -2,7 +2,7 @@ namespace sammo\Constraint; -class NoWanderingNation extends Constraint{ +class NotWanderingNation extends Constraint{ const REQ_VALUES = Constraint::REQ_NATION; public function checkInputValues(bool $throwExeception=true){ diff --git a/hwe/sammo/GameConstBase.php b/hwe/sammo/GameConstBase.php index 30073f3a..8927588a 100644 --- a/hwe/sammo/GameConstBase.php +++ b/hwe/sammo/GameConstBase.php @@ -96,6 +96,8 @@ class GameConstBase /** @var int 초반 제한 기간 */ public static $openingPartYear = 3; + /** @var int 거병,임관 제한 기간 */ + public static $joinActionLimit = 12; /** @var array 선택 가능한 국가 성향 */ public static $availableNationType = [ diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 75fcebdc..d1e41af4 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -558,7 +558,7 @@ class General implements iAction{ $rawGeneral = $db->queryFirstRow('SELECT $lb FROM general WHERE no = %i', $generalID); if(!$rawGeneral){ - throw new NoDBResultException("generalID에 해당하는 장수가 없음: {$generalID}"); + return new DummyGeneral($constructMode > 0); } $general = new static($rawGeneral, null, $year, $month, $constructMode > 1);