diff --git a/hwe/sammo/Command/Nation/che_부대탈퇴지시.php b/hwe/sammo/Command/Nation/che_부대탈퇴지시.php new file mode 100644 index 00000000..882df358 --- /dev/null +++ b/hwe/sammo/Command/Nation/che_부대탈퇴지시.php @@ -0,0 +1,161 @@ +arg === null) { + return false; + } + if (!key_exists('destGeneralID', $this->arg)) { + return false; + } + $destGeneralID = $this->arg['destGeneralID']; + if (!is_int($destGeneralID)) { + return false; + } + if ($destGeneralID <= 0) { + return false; + } + $this->arg = [ + 'destGeneralID' => $destGeneralID + ]; + return true; + } + + protected function init() + { + $this->setCity(); + $this->setNation(); + + $this->minConditionConstraints = [ + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::BeChief(), + ]; + } + + public function getBrief(): string + { + $commandName = $this->getName(); + $destGeneralName = $this->destGeneralObj->getName(); + return "【{$destGeneralName}】{$commandName}"; + } + + protected function initWithArg() + { + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); + $this->setDestGeneral($destGeneral); + + if($this->arg['destGeneralID'] == $this->getGeneral()->getID()){ + $this->fullConditionConstraints=[ + ConstraintHelper::AlwaysFail('본인입니다') + ]; + return; + } + + $this->fullConditionConstraints = [ + ConstraintHelper::NotBeNeutral(), + ConstraintHelper::BeChief(), + ConstraintHelper::ExistsDestGeneral(), + ConstraintHelper::FriendlyDestGeneral() + ]; + } + + public function getCost(): array + { + return [0, 0]; + } + + public function getPreReqTurn(): int + { + return 0; + } + + public function getPostReqTurn(): int + { + return 0; + } + + public function run(\Sammo\RandUtil $rng): bool + { + if (!$this->hasFullConditionMet()) { + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + + $general = $this->generalObj; + $generalName = $general->getName(); + + $destGeneral = $this->destGeneralObj; + $destGeneralName = $destGeneral->getName(); + $logger = $this->getLogger(); + + $troopID = $destGeneral->getVar('troop'); + if($troopID == 0){ + $josaUn = JosaUtil::pick($destGeneralName, '은'); + $logger->pushGeneralActionLog("{$destGeneralName}{$josaUn} 부대원이 아닙니다."); + $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); + return true; + } + + if($troopID == $destGeneral->getID()){ + $josaUn = JosaUtil::pick($destGeneralName, '은'); + $logger->pushGeneralActionLog("{$destGeneralName}{$josaUn} 부대장입니다."); + $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); + return true; + } + + $destGeneral->setVar('troop', 0); + + $logger->pushGeneralActionLog("{$destGeneralName}에게 부대 탈퇴를 지시했습니다."); + $destGeneral->getLogger()->pushGeneralActionLog("{$generalName}에게 부대 탈퇴를 지시 받았습니다."); + + $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); + StaticEventHandler::handleEvent($this->generalObj, $this->destGeneralObj, $this::class, $this->env, $this->arg); + $general->applyDB($db); + $destGeneral->applyDB($db); + + return true; + } + + public function exportJSVars(): array + { + $db = DB::db(); + $nationID = $this->getNationID(); + $troops = Util::convertArrayToDict($db->query('SELECT * FROM troop WHERE nation=%i', $nationID), 'troop_leader'); + $destRawGenerals = $db->queryAllLists('SELECT no,name,officer_level,npc,gold,rice,leadership,strength,intel,city,crew,train,atmos,troop FROM general WHERE nation = %i ORDER BY npc,binary(name)', $nationID); + return [ + 'procRes' => [ + 'troops' => $troops, + 'generals' => $destRawGenerals, + 'generalsKey' => ['no', 'name', 'officerLevel', 'npc', 'gold', 'rice', 'leadership', 'strength', 'intel', 'cityID', 'crew', 'train', 'atmos', 'troopID'], + 'cities' => \sammo\JSOptionsForCities(), + 'minAmount' => 100, + 'maxAmount' => GameConst::$maxResourceActionAmount, + 'amountGuide' => GameConst::$resourceActionAmountGuide, + ] + ]; + } +} diff --git a/hwe/sammo/GameConstBase.php b/hwe/sammo/GameConstBase.php index ba9f74a2..bfd7687e 100644 --- a/hwe/sammo/GameConstBase.php +++ b/hwe/sammo/GameConstBase.php @@ -375,6 +375,7 @@ class GameConstBase 'che_발령', 'che_포상', 'che_몰수', + 'che_부대탈퇴지시', ], '외교' => [ 'che_물자원조',