arg === null) { return false; } if (!key_exists('isPull', $this->arg)) { return false; } if (!key_exists('amount', $this->arg)) { return false; } if (!key_exists('destGeneralID', $this->arg)) { return false; } $isPull = $this->arg['isPull']; $amount = $this->arg['amount']; $destGeneralID = $this->arg['destGeneralID']; if (!is_numeric($amount)) { return false; } if ($amount <= 0) { return false; } if (!is_bool($isPull)) { return false; } if (!is_int($destGeneralID)) { return false; } if ($destGeneralID <= 0) { return false; } $amount = Util::clamp($amount, 1, 5); $this->arg = [ 'isPull' => $isPull, 'amount' => $amount, 'destGeneralID' => $destGeneralID ]; return true; } protected function init() { $general = $this->generalObj; $this->setCity(); $this->setNation(); $this->minConditionConstraints = [ ConstraintHelper::NotBeNeutral(), ConstraintHelper::OccupiedCity(), ConstraintHelper::BeChief(), ConstraintHelper::SuppliedCity(), ]; } 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::OccupiedCity(), ConstraintHelper::BeChief(), ConstraintHelper::SuppliedCity(), 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 getBrief(): string { $isPull = $this->arg['isPull']; $amount = $this->arg['amount']; $actSpecificName = $isPull ? '당기기' : '미루기'; $destGeneral = $this->destGeneralObj; return "【{$destGeneral->getName()}】 {$amount}턴 {$actSpecificName}"; } public function run(\Sammo\RandUtil $rng): bool { if (!$this->hasFullConditionMet()) { throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); } $db = DB::db(); $general = $this->generalObj; $date = $general->getTurnTime($general::TURNTIME_HM); $isPull = $this->arg['isPull']; $amount = $this->arg['amount']; $destGeneral = $this->destGeneralObj; if($isPull){ pullGeneralCommand($destGeneral->getID(), $amount); } else{ pushGeneralCommand($destGeneral->getID(), $amount); } $logger = $general->getLogger(); $actDestText = $isPull ? '당겼습니다.' : '미루었습니다.'; $actText = $isPull ? '당기도록' : '미루도록'; $destGeneral->getLogger()->pushGeneralActionLog("{$general->getName()}의 지시로 {$amount}턴을 {$actDestText}", ActionLogger::PLAIN); $logger->pushGeneralActionLog("{$destGeneral->getName()}에게 {$amount}턴을 {$actText} 지시했습니다. <1>$date"); $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 = Util::convertArrayToDict($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), 0); if($destRawGenerals){ foreach ($db->queryAllLists( 'SELECT general_id, brief FROM general_turn WHERE general_id IN %li AND turn_idx = 0', array_keys($destRawGenerals) ) as [$generalID, $brief]) { if (!key_exists($generalID, $destRawGenerals)) { continue; } $destRawGenerals[$generalID][] = $brief; } } return [ 'procRes' => [ 'troops' => $troops, 'generals' => array_values($destRawGenerals), 'generalsKey' => ['no', 'name', 'officerLevel', 'npc', 'gold', 'rice', 'leadership', 'strength', 'intel', 'cityID', 'crew', 'train', 'atmos', 'troopID', 'turn0Brief'], 'cities' => \sammo\JSOptionsForCities(), 'amountGuide' => [1, 2, 3, 4, 5], 'minAmount' => 1, 'maxAmount' => 5, ] ]; } }