커맨드 유효성을 2개에서 3개구성으로 변경
This commit is contained in:
@@ -1,17 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace sammo\Command\General;
|
||||
|
||||
use \sammo\{
|
||||
DB, Util, JosaUtil,
|
||||
General,
|
||||
use\sammo\{
|
||||
DB,
|
||||
Util,
|
||||
JosaUtil,
|
||||
General,
|
||||
ActionLogger,
|
||||
GameConst, GameUnitConst,
|
||||
GameConst,
|
||||
GameUnitConst,
|
||||
LastTurn,
|
||||
Command
|
||||
};
|
||||
|
||||
|
||||
use function \sammo\{
|
||||
use function\sammo\{
|
||||
searchDistance,
|
||||
printCitiesBasedOnDistance
|
||||
};
|
||||
@@ -22,44 +26,44 @@ use sammo\CityConst;
|
||||
|
||||
|
||||
|
||||
class che_화계 extends Command\GeneralCommand{
|
||||
class che_화계 extends Command\GeneralCommand
|
||||
{
|
||||
static protected $actionName = '화계';
|
||||
static public $reqArg = true;
|
||||
|
||||
static protected $statType = 'intel';
|
||||
static protected $injuryGeneral = true;
|
||||
|
||||
protected function argTest():bool{
|
||||
if($this->arg === null){
|
||||
protected function argTest(): bool
|
||||
{
|
||||
if ($this->arg === null) {
|
||||
return false;
|
||||
}
|
||||
if(!key_exists('destCityID', $this->arg)){
|
||||
if (!key_exists('destCityID', $this->arg)) {
|
||||
return false;
|
||||
}
|
||||
if(!key_exists($this->arg['destCityID'], CityConst::all())){
|
||||
if (!key_exists($this->arg['destCityID'], CityConst::all())) {
|
||||
return false;
|
||||
}
|
||||
$this->arg = [
|
||||
'destCityID'=>$this->arg['destCityID']
|
||||
'destCityID' => $this->arg['destCityID']
|
||||
];
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function calcSabotageAttackProb():float{
|
||||
protected function calcSabotageAttackProb(): float
|
||||
{
|
||||
$statType = static::$statType;
|
||||
$general = $this->generalObj;
|
||||
$nation = $this->nation;
|
||||
|
||||
if($statType === 'leadership'){
|
||||
if ($statType === 'leadership') {
|
||||
$genScore = $general->getLeadership();
|
||||
}
|
||||
else if($statType === 'strength'){
|
||||
} else if ($statType === 'strength') {
|
||||
$genScore = $general->getStrength();
|
||||
}
|
||||
else if($statType === 'intel'){
|
||||
} else if ($statType === 'intel') {
|
||||
$genScore = $general->getIntel();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
throw new \sammo\MustNotBeReachedException();
|
||||
}
|
||||
|
||||
@@ -68,29 +72,27 @@ class che_화계 extends Command\GeneralCommand{
|
||||
return $prob;
|
||||
}
|
||||
|
||||
protected function calcSabotageDefenceProb(array $destCityGeneralList):float{
|
||||
protected function calcSabotageDefenceProb(array $destCityGeneralList): float
|
||||
{
|
||||
$statType = static::$statType;
|
||||
$destCity = $this->destCity;
|
||||
$destNation = $this->destNation;
|
||||
$destNationID = $destNation['nation'];
|
||||
|
||||
$maxGenScore = 0;
|
||||
foreach($destCityGeneralList as $destGeneral){
|
||||
foreach ($destCityGeneralList as $destGeneral) {
|
||||
/** @var General $destGeneral */
|
||||
if($destGeneral->getNationID() != $destNationID){
|
||||
if ($destGeneral->getNationID() != $destNationID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if($statType === 'leadership'){
|
||||
if ($statType === 'leadership') {
|
||||
$genScore = $destGeneral->getLeadership();
|
||||
}
|
||||
else if($statType === 'strength'){
|
||||
} else if ($statType === 'strength') {
|
||||
$genScore = $destGeneral->getStrength();
|
||||
}
|
||||
else if($statType === 'intel'){
|
||||
} else if ($statType === 'intel') {
|
||||
$genScore = $destGeneral->getIntel();
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
throw new \sammo\MustNotBeReachedException();
|
||||
}
|
||||
$maxGenScore = max($maxGenScore, $genScore);
|
||||
@@ -103,17 +105,35 @@ class che_화계 extends Command\GeneralCommand{
|
||||
return $prob;
|
||||
}
|
||||
|
||||
protected function init(){
|
||||
protected function init()
|
||||
{
|
||||
|
||||
$general = $this->generalObj;
|
||||
|
||||
$this->setCity();
|
||||
$this->setDestCity($this->arg['destCityID'], null); //xxx: 이대로라면 메인 페이지 갱신시마다 DB query를 하게 된다.
|
||||
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->minConditionConstraints = [
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
ConstraintHelper::ReqGeneralGold($reqGold),
|
||||
ConstraintHelper::ReqGeneralRice($reqRice),
|
||||
];
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function initWithArg()
|
||||
{
|
||||
$this->setDestCity($this->arg['destCityID']);
|
||||
$this->setDestNation($this->destCity['nation']);
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$this->runnableConstraints=[
|
||||
|
||||
$this->fullConditionConstraints = [
|
||||
ConstraintHelper::NotBeNeutral(),
|
||||
ConstraintHelper::OccupiedCity(),
|
||||
ConstraintHelper::SuppliedCity(),
|
||||
@@ -128,58 +148,65 @@ class che_화계 extends Command\GeneralCommand{
|
||||
];
|
||||
}
|
||||
|
||||
public function getCommandDetailTitle():string{
|
||||
public function getCommandDetailTitle(): string
|
||||
{
|
||||
$name = $this->getName();
|
||||
$statTypeBase = [
|
||||
'leadership'=>'통솔경험',
|
||||
'strength'=>'무력경험',
|
||||
'intel'=>'지력경험',
|
||||
'leadership' => '통솔경험',
|
||||
'strength' => '무력경험',
|
||||
'intel' => '지력경험',
|
||||
];
|
||||
$statType = $statTypeBase[static::$statType];
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
|
||||
$title = "{$name}({$statType}";
|
||||
if($reqGold > 0){
|
||||
if ($reqGold > 0) {
|
||||
$title .= ", 자금{$reqGold}";
|
||||
}
|
||||
if($reqRice > 0){
|
||||
if ($reqRice > 0) {
|
||||
$title .= ", 군량{$reqRice}";
|
||||
}
|
||||
$title .= ')';
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function getCost():array{
|
||||
public function getCost(): array
|
||||
{
|
||||
$env = $this->env;
|
||||
$cost = $env['develcost'] * 5;
|
||||
return [$cost, $cost];
|
||||
}
|
||||
|
||||
public function getPreReqTurn():int{
|
||||
|
||||
public function getPreReqTurn(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPostReqTurn():int{
|
||||
public function getPostReqTurn(): int
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getBrief():string{
|
||||
public function getBrief(): string
|
||||
{
|
||||
$commandName = $this->getName();
|
||||
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
|
||||
return "【{$destCityName}】에 {$commandName}실행";
|
||||
}
|
||||
|
||||
public function getFailString():string{
|
||||
public function getFailString(): string
|
||||
{
|
||||
$commandName = $this->getName();
|
||||
$failReason = $this->testRunnable();
|
||||
if($failReason === null){
|
||||
$failReason = $this->testFullConditionMet();
|
||||
if ($failReason === null) {
|
||||
throw new \RuntimeException('실행 가능한 커맨드에 대해 실패 이유를 수집');
|
||||
}
|
||||
$destCityName = CityConst::byID($this->arg['destCityID'])->name;
|
||||
return "{$failReason} <G><b>{$destCityName}</b></>에 {$commandName} 실패.";
|
||||
}
|
||||
|
||||
protected function affectDestCity(int $injuryCount){
|
||||
protected function affectDestCity(int $injuryCount)
|
||||
{
|
||||
$general = $this->generalObj;
|
||||
$date = $general->getTurnTime($general::TURNTIME_HM);
|
||||
|
||||
@@ -198,9 +225,9 @@ class che_화계 extends Command\GeneralCommand{
|
||||
$destCity['comm'] -= $commAmount;
|
||||
|
||||
DB::db()->update('city', [
|
||||
'state'=>32,
|
||||
'agri'=>$destCity['agri'],
|
||||
'comm'=>$destCity['comm']
|
||||
'state' => 32,
|
||||
'agri' => $destCity['agri'],
|
||||
'comm' => $destCity['comm']
|
||||
], 'city=%i', $destCityID);
|
||||
|
||||
$agriAmountText = number_format($agriAmount);
|
||||
@@ -217,8 +244,9 @@ class che_화계 extends Command\GeneralCommand{
|
||||
);
|
||||
}
|
||||
|
||||
public function run():bool{
|
||||
if(!$this->isRunnable()){
|
||||
public function run(): bool
|
||||
{
|
||||
if (!$this->hasFullConditionMet()) {
|
||||
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
|
||||
}
|
||||
|
||||
@@ -239,13 +267,13 @@ class che_화계 extends Command\GeneralCommand{
|
||||
|
||||
$logger = $general->getLogger();
|
||||
|
||||
$dist = searchDistance($general->getCityID(), 5, false)[$destCityID]??99;
|
||||
$dist = searchDistance($general->getCityID(), 5, false)[$destCityID] ?? 99;
|
||||
|
||||
$destCityGeneralList = [];
|
||||
|
||||
|
||||
$cityGeneralID = $db->queryFirstColumn('SELECT no FROM general WHERE city = %i AND nation = %i', $destCityID, $destNationID);
|
||||
$destCityGeneralList = General::createGeneralObjListFromDB($cityGeneralID, ['name', 'city', 'nation', 'officer_level', 'leadership', 'horse', 'strength', 'weapon', 'intel', 'book', 'item', 'last_turn', 'injury', 'special', 'special2', 'injury', 'crew', 'atmos', 'train'], 2);
|
||||
foreach($destCityGeneralList as &$destCityGeneral){
|
||||
foreach ($destCityGeneralList as &$destCityGeneral) {
|
||||
$destCityGeneral->setRawCity($this->destCity);
|
||||
unset($destCityGeneral);
|
||||
}
|
||||
@@ -255,7 +283,7 @@ class che_화계 extends Command\GeneralCommand{
|
||||
$prob = GameConst::$sabotageDefaultProb + $this->calcSabotageAttackProb() - $this->calcSabotageDefenceProb($destCityGeneralList);
|
||||
$prob /= $dist;
|
||||
|
||||
if(!Util::randBool($prob)){
|
||||
if (!Util::randBool($prob)) {
|
||||
$josaYi = JosaUtil::pick($commandName, '이');
|
||||
$logger->pushGeneralActionLog("<G><b>{$destCityName}</b></>에 {$commandName}{$josaYi} 실패했습니다. <1>$date</>");
|
||||
|
||||
@@ -267,7 +295,7 @@ class che_화계 extends Command\GeneralCommand{
|
||||
$general->increaseVarWithLimit('rice', -$reqRice, 0);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar($statType.'_exp', 1);
|
||||
$general->increaseVar($statType . '_exp', 1);
|
||||
|
||||
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
@@ -275,17 +303,16 @@ class che_화계 extends Command\GeneralCommand{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(static::$injuryGeneral){
|
||||
if (static::$injuryGeneral) {
|
||||
$injuryCount = \sammo\SabotageInjury($destCityGeneralList, '계략');
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$injuryCount = 0;
|
||||
}
|
||||
|
||||
$this->affectDestCity($injuryCount);
|
||||
|
||||
$itemObj = $general->getItem();
|
||||
if($itemObj->isConsumableNow('GeneralCommand', '계략') && $itemObj->isConsumableNow('GeneralCommand', '계략')){
|
||||
if ($itemObj->isConsumableNow('GeneralCommand', '계략') && $itemObj->isConsumableNow('GeneralCommand', '계략')) {
|
||||
$itemName = $itemObj->getName();
|
||||
$itemRawName = $itemObj->getRawName();
|
||||
$josaUl = JosaUtil::pick($itemRawName, '을');
|
||||
@@ -295,13 +322,13 @@ class che_화계 extends Command\GeneralCommand{
|
||||
|
||||
$exp = Util::randRangeInt(201, 300);
|
||||
$ded = Util::randRangeInt(141, 210);
|
||||
|
||||
|
||||
[$reqGold, $reqRice] = $this->getCost();
|
||||
$general->increaseVarWithLimit('gold', -$reqGold, 0);
|
||||
$general->increaseVarWithLimit('rice', -$reqRice, 0);
|
||||
$general->addExperience($exp);
|
||||
$general->addDedication($ded);
|
||||
$general->increaseVar($statType.'_exp', 1);
|
||||
$general->increaseVar($statType . '_exp', 1);
|
||||
$general->increaseRankVar('firenum', 1);
|
||||
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
|
||||
$general->checkStatChange();
|
||||
@@ -325,18 +352,16 @@ class che_화계 extends Command\GeneralCommand{
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<?=\sammo\getMapHtml()?><br>
|
||||
선택된 도시에 <?=$commandName?><?=$josaUl?> 실행합니다.<br>
|
||||
목록을 선택하거나 도시를 클릭하세요.<br>
|
||||
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
|
||||
<?=\sammo\optionsForCities()?><br>
|
||||
</select> <input type=button id="commonSubmit" value="<?=$this->getName()?>"><br>
|
||||
<br>
|
||||
<br>
|
||||
<?=printCitiesBasedOnDistance($currentCityID, 2)?>
|
||||
<?= \sammo\getMapHtml() ?><br>
|
||||
선택된 도시에 <?= $commandName ?><?= $josaUl ?> 실행합니다.<br>
|
||||
목록을 선택하거나 도시를 클릭하세요.<br>
|
||||
<select class='formInput' name="destCityID" id="destCityID" size='1' style='color:white;background-color:black;'><br>
|
||||
<?= \sammo\optionsForCities() ?><br>
|
||||
</select> <input type=button id="commonSubmit" value="<?= $this->getName() ?>"><br>
|
||||
<br>
|
||||
<br>
|
||||
<?= printCitiesBasedOnDistance($currentCityID, 2) ?>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user