ConstraintHelper 추가

This commit is contained in:
2018-11-15 03:33:44 +09:00
parent 2cb7513355
commit c3699a8595
44 changed files with 588 additions and 168 deletions
+1
View File
@@ -8,6 +8,7 @@ use \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
abstract class BaseCommand{
/**
+2 -1
View File
@@ -11,6 +11,7 @@ use \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_NPC능동 extends Command\GeneralCommand{
@@ -43,7 +44,7 @@ class che_NPC능동 extends Command\GeneralCommand{
$general = $this->generalObj;
$this->runnableConstraints=[
['MustBeNPC']
ConstraintHelper::MustBeNPC()
];
}
+5 -4
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
@@ -47,10 +48,10 @@ class che_강행 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotSameDestCity'],
['NearCity', 3],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
ConstraintHelper::NotSameDestCity(),
ConstraintHelper::NearCity(3),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
+4 -3
View File
@@ -12,6 +12,7 @@ use \sammo\{
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
use function sammo\getNationTypeClass;
use function sammo\refreshNationStaticInfo;
@@ -44,9 +45,9 @@ class che_거병 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
['BeNeutral'],
['BeOpeningPart', $relYear],
['AllowJoinAction'],
ConstraintHelper::BeNeutral(),
ConstraintHelper::BeOpeningPart($relYear),
ConstraintHelper::AllowJoinAction(),
];
}
+8 -7
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
use function sammo\getNationTypeClass;
use function sammo\refreshNationStaticInfo;
@@ -78,13 +79,13 @@ class che_건국 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
['ReqNationValue', 'gennum', '수하 장수', '>=', 2],
['BeOpeningPart', $relYear],
['WanderingNation'],
['CheckNationNameDuplicate', $nationName],
['BeLord'],
['AllowJoinAction'],
['ConstructableCity']
ConstraintHelper::ReqNationValue('gennum', '수하 장수', '>=', 2),
ConstraintHelper::BeOpeningPart($relYear),
ConstraintHelper::WanderingNation(),
ConstraintHelper::CheckNationNameDuplicate($nationName),
ConstraintHelper::BeLord(),
ConstraintHelper::AllowJoinAction(),
ConstraintHelper::ConstructableCity(),
];
}
+1
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use \sammo\TextDecoration\SightseeingMessage;
@@ -21,6 +21,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\MustNotBeReachedException;
class che_군량매매 extends Command\GeneralCommand{
@@ -59,16 +60,16 @@ class che_군량매매 extends Command\GeneralCommand{
$this->setNation();
$this->runnableConstraints=[
['ReqCityTrader', $general->getVar('npc')],
['OccupiedCity', true],
['SuppliedCity'],
ConstraintHelper::ReqCityTrader($general->getVar('npc')),
ConstraintHelper::OccupiedCity(true),
ConstraintHelper::SuppliedCity(),
];
if($this->arg['buyRice']){
$this->runnableConstraints[] = ['ReqGeneralGold', 1];
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralGold(1);
}
else{
$this->runnableConstraints[] = ['ReqGeneralRice', 1];
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralRice(1);
}
}
+4 -3
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
@@ -38,9 +39,9 @@ class che_귀환 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['NotWanderingNation'],
['NotCapital', 1],
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::NotCapital(true),
];
}
@@ -18,6 +18,7 @@ use function sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_기술연구 extends che_상업투자{
@@ -40,12 +41,12 @@ class che_기술연구 extends che_상업투자{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['NotWanderingNation'],
['OccupiedCity'],
['SuppliedCity'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice]
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice)
];
$this->reqGold = $reqGold;
+7 -6
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
@@ -37,12 +38,12 @@ class che_단련 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['ReqGeneralCrew'],
['ReqGeneralValue', 'train', '훈련', GameConst::$defaultTrainHigh],
['ReqGeneralValue', 'atmos', '사기', GameConst::$defaultAtmosHigh],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::ReqGeneralCrew(),
ConstraintHelper::ReqGeneralValue('train', '훈련', '<', GameConst::$defaultTrainHigh),
ConstraintHelper::ReqGeneralValue('atmos', '사기', '<', GameConst::$defaultAtmosHigh),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
+11 -9
View File
@@ -20,6 +20,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_등용 extends Command\GeneralCommand{
@@ -57,17 +58,18 @@ class che_등용 extends Command\GeneralCommand{
$this->setDestGeneral($destGeneral);
[$reqGold, $reqRice] = $this->getCost();
$relYear = $this->env['year'] - $this->env['startyear'];
$this->runnableConstraints=[
['ReqEnvValue', 'join_mode', '==', 'onlyRandom', '랜덤 임관만 가능합니다'],
['NotBeNeutral'],
['NotOpeningPart'],
['OccupiedCity'],
['SuppliedCity'],
['ExistsDestGeneral'],
['DifferentNationDestGeneral'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
ConstraintHelper::ReqEnvValue('join_mode', '==', 'onlyRandom', '랜덤 임관만 가능합니다'),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::DifferentNationDestGeneral(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
if($this->destGeneralObj->getVar('level') == 12){
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
use sammo\MustNotBeReachedException;
@@ -61,10 +62,10 @@ class che_랜덤임관 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
['BeNeutral'],
['ExistsDestNation'],
['AllowJoinAction'],
['ExistsAllowJoinNation', $relYear, [$this->arg['destNationIDList']]],
ConstraintHelper::BeNeutral(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::AllowJoinAction(),
ConstraintHelper::ExistsAllowJoinNation($relYear, $this->arg['destNationIDList']),
];
}
+119
View File
@@ -0,0 +1,119 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\{
DB, Util, JosaUtil,
General, DummyGeneral,
ActionLogger,
GameConst,
LastTurn,
GameUnitConst,
Command
};
use function \sammo\{
getDomesticExpLevelBonus,
CriticalRatioDomestic,
CriticalScoreEx,
tryUniqueItemLottery
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_모반 extends Command\GeneralCommand{
static protected $actionName = '모반';
protected function argTest():bool{
$this->arg = null;
return true;
}
protected function init(){
$general = $this->generalObj;
$this->setNation();
$destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], 1);
$this->setDestGeneral($destGeneral);
$this->runnableConstraints=[
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::BeChief(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::NotLord(),
ConstraintHelper::AllowRebellion(),
];
}
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();
$general = $this->generalObj;
$date = substr($general->getVar('turntime'),11,5);
$destGeneral = $this->destGeneralObj;
$generalName = $general->getName();
$destGeneralName = $destGeneral->getName();
$nationName = $this->nation['name'];
$logger = $general->getLogger();
$destLogger = $destGeneral->getLogger();
$destGeneral->setVar('level', 12);
$general->setVar('level', 1);
$general->multiplyVar('experience', 0.7);
$db->update('city', [
'gen1'=>0
], 'gen1=%i', $destGeneral->getID());
$db->update('city', [
'gen2'=>0
], 'gen2=%i', $destGeneral->getID());
$db->update('city', [
'gen3'=>0
], 'gen3=%i', $destGeneral->getID());
$destGeneral->increaseVarWithLimit($resKey, $amount);
$general->increaseVarWithLimit($resKey, -$amount, 0);
$josaYi = JosaUtil::pick($generalName, '이');
$logger->pushGlobalHistoryLog("<Y><b>【선양】</b></><Y>{$generalName}</>{$josaYi} <D><b>{$nationName}</b></>의 군주 자리를 <Y>{$destGeneralName}</>에게 선양했습니다.");
$logger->pushNationalHistoryLog("<Y>{$generalName}</>{$josaYi} <Y>{$destGeneralName}</>에게 선양");
$logger->pushGeneralActionLog("<Y>{$destGeneralName}</>에게 군주의 자리를 물려줍니다. <1>$date</>");
$destLogger->pushGeneralActionLog("<Y>{$generalName}</>에게서 군주의 자리를 물려받습니다.");
$logger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>의 군주자리를 <Y>{$destGeneralName}</>에게 선양");
$destLogger->pushGeneralHistoryLog("<D><b>{$nationName}</b></>의 군주자리를 물려 받음");
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->checkStatChange();
$general->applyDB($db);
$destGeneral->applyDB($db);
return true;
}
}
@@ -19,6 +19,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_물자조달 extends Command\GeneralCommand{
@@ -37,10 +38,10 @@ class che_물자조달 extends Command\GeneralCommand{
$this->setNation();
$this->runnableConstraints=[
['NotBeNeutral'],
['NotWanderingNation'],
['OccupiedCity'],
['SuppliedCity']
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity()
];
}
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_사기진작 extends Command\GeneralCommand{
@@ -36,13 +37,13 @@ class che_사기진작 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['NotWanderingNation'],
['OccupiedCity'],
['ReqGeneralCrew'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
['ReqGeneralAtmosMargin', GameConst::$maxAtmosByCommand],
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralCrew(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
ConstraintHelper::ReqGeneralAtmosMargin(GameConst::$maxAtmosByCommand),
];
}
@@ -19,6 +19,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_상업투자 extends Command\GeneralCommand{
@@ -43,13 +44,13 @@ class che_상업투자 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['NotWanderingNation'],
['OccupiedCity'],
['SuppliedCity'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
['RemainCityCapacity', [static::$cityKey, static::$actionName]]
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
ConstraintHelper::RemainCityCapacity(static::$cityKey, static::$actionName)
];
$this->reqGold = $reqGold;
+5 -4
View File
@@ -19,6 +19,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_선양 extends Command\GeneralCommand{
@@ -55,10 +56,10 @@ class che_선양 extends Command\GeneralCommand{
$this->setDestGeneral($destGeneral);
$this->runnableConstraints=[
['BeLord'],
['ExistsDestGeneral'],
['FriendlyDestGeneral'],
['DisallowDiplomacyStatus', [4], '현재 통합 진행중입니다.']
ConstraintHelper::BeLord(),
ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::FriendlyDestGeneral(),
ConstraintHelper::DisallowDiplomacyStatus([4], '현재 통합 진행중입니다.')
];
}
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_소집해제 extends Command\GeneralCommand{
static protected $actionName = '소집해제';
@@ -33,7 +34,7 @@ class che_소집해제 extends Command\GeneralCommand{
$this->setNation();
$this->runnableConstraints=[
['ReqGeneralCrew'],
ConstraintHelper::ReqGeneralCrew(),
];
}
+1
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
+5 -4
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
@@ -47,10 +48,10 @@ class che_이동 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotSameDestCity'],
['NearCity', 1],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
ConstraintHelper::NotSameDestCity(),
ConstraintHelper::NearCity(1),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
@@ -19,6 +19,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_인재탐색 extends Command\GeneralCommand{
@@ -39,17 +40,17 @@ class che_인재탐색 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['NotWanderingNation'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
$relYear = $env['year'] - $env['startyear'];
if($relYear < 3 && $this->nation['gennum'] >= GameConst::$initialNationGenLimit){
$nationName = $this->nation['name'];
$josaUn = JosaUtil::pick($nationName, '은');
$this->runnableConstraints[] = ['AlwaysFail', "현재 <D>{$nationName}</>{$josaUn} 탐색이 제한되고 있습니다."];
$this->runnableConstraints[] = ConstraintHelper::AlwaysFail("현재 <D>{$nationName}</>{$josaUn} 탐색이 제한되고 있습니다.");
}
}
+6 -5
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
@@ -84,11 +85,11 @@ class che_임관 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
['ReqEnvValue', 'join_mode', '==', 'onlyRandom', '랜덤 임관만 가능합니다'],
['BeNeutral'],
['ExistsDestNation'],
['AllowJoinDestNation', $relYear],
['AllowJoinAction']
ConstraintHelper::ReqEnvValue('join_mode', '==', 'onlyRandom', '랜덤 임관만 가능합니다'),
ConstraintHelper::BeNeutral(),
ConstraintHelper::ExistsDestNation(),
ConstraintHelper::AllowJoinDestNation($relYear),
ConstraintHelper::AllowJoinAction()
];
}
@@ -21,6 +21,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_장비매매 extends Command\GeneralCommand{
static protected $actionName = '장비매매';
@@ -65,20 +66,20 @@ class che_장비매매 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['ReqCityTrader', $general->getVar('npc')],
['ReqCityCapacity', 'secu', '치안 수치', $itemCode * 1000],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
ConstraintHelper::ReqCityTrader($general->getVar('npc')),
ConstraintHelper::ReqCityCapacity('secu', '치안 수치', $itemCode * 1000),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
if($itemCode == 0){
$this->runnableConstraints[] = ['ReqGeneralValue', $itemType, $itemTypeName, 1];
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralValue($itemType, $itemTypeName, '>=', 1);
}
else if($itemCode == $general->getVar($itemType)){
$this->runnableConstraints[] = ['AlwaysFail', '이미 가지고 있습니다.'];
$this->runnableConstraints[] = ConstraintHelper::AlwaysFail('이미 가지고 있습니다.');
}
else if($itemType != 'item' && $general->getVar($itemType) > 6){
$this->runnableConstraints[] = ['AlwaysFail', '이미 진귀한 것을 가지고 있습니다.'];
$this->runnableConstraints[] = ConstraintHelper::AlwaysFail('이미 진귀한 것을 가지고 있습니다.');
}
}
@@ -17,6 +17,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_전투태세 extends Command\GeneralCommand{
@@ -37,14 +38,14 @@ class che_전투태세 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['NotWanderingNation'],
['OccupiedCity'],
['ReqGeneralCrew'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
['ReqGeneralTrainMargin', GameConst::$maxTrainByCommand - 10],
['ReqGeneralAtmosMargin', GameConst::$maxAtmosByCommand - 10],
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralCrew(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
ConstraintHelper::ReqGeneralTrainMargin(GameConst::$maxTrainByCommand - 10),
ConstraintHelper::ReqGeneralAtmosMargin(GameConst::$maxAtmosByCommand - 10),
];
}
@@ -19,6 +19,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use function sammo\getGeneralLeadership;
@@ -43,13 +44,13 @@ class che_정착장려 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['NotWanderingNation'],
['OccupiedCity'],
['SuppliedCity'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
['RemainCityCapacity', [static::$cityKey, static::$actionName]]
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
ConstraintHelper::RemainCityCapacity(static::$cityKey, static::$actionName)
];
$this->reqRice = $reqRice;
@@ -19,6 +19,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_주민선정 extends Command\GeneralCommand{
@@ -42,13 +43,13 @@ class che_주민선정 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['NotWanderingNation'],
['OccupiedCity'],
['SuppliedCity'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
['RemainCityTrust', static::$actionName]
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
ConstraintHelper::RemainCityTrust(static::$actionName)
];
$this->reqRice = $reqRice;
+8 -7
View File
@@ -19,6 +19,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_증여 extends Command\GeneralCommand{
@@ -73,17 +74,17 @@ class che_증여 extends Command\GeneralCommand{
$this->setDestGeneral($destGeneral);
$this->runnableConstraints=[
['NotBeNeutral'],
['OccupiedCity'],
['SuppliedCity'],
['ExistsDestGeneral'],
['FriendlyDestGeneral']
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::ExistsDestGeneral(),
ConstraintHelper::FriendlyDestGeneral()
];
if($this->arg['isGold']){
$this->runnableConstraints[] = ['ReqGeneralGold', 1];
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralGold(1);
}
else{
$this->runnableConstraints[] = ['ReqGeneralRice', 1];
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralRice(1);
}
}
+6 -5
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
@@ -39,11 +40,11 @@ class che_집합 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['OccupiedCity'],
['SuppliedCity'],
['MustBeTroopLeader'],
['ReqTroopMembers'],
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
ConstraintHelper::MustBeTroopLeader(),
ConstraintHelper::ReqTroopMembers(),
];
}
+9 -8
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
@@ -92,14 +93,14 @@ class che_징병 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotBeNeutral'],
['OccupiedCity'],
['ReqCityCapacity', 'pop', '주민', 30000 + $reqCrew],
['ReqCityTrust', 20],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
['ReqGeneralCrewMargin', $reqCrewType->id],
['AvailableRecruitCrewType', $reqCrewType->id]
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqCityCapacity('pop', '주민', 30000 + $reqCrew),
ConstraintHelper::ReqCityTrust(20),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
ConstraintHelper::ReqGeneralCrewMargin($reqCrewType->id),
ConstraintHelper::AvailableRecruitCrewType($reqCrewType->id)
];
}
+4 -3
View File
@@ -17,6 +17,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
@@ -49,9 +50,9 @@ class che_첩보 extends Command\GeneralCommand{
[$reqGold, $reqRice] = $this->getCost();
$this->runnableConstraints=[
['NotOccupiedDestCity'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
ConstraintHelper::NotOccupiedDestCity(),
ConstraintHelper::ReqGeneralGold($reqGold),
ConstraintHelper::ReqGeneralRice($reqRice),
];
}
+10 -8
View File
@@ -17,6 +17,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
@@ -47,16 +48,17 @@ class che_출병 extends Command\GeneralCommand{
$this->setDestNation(['nation' ,'level','name','capital','gennum','tech','type','gold','rice']);
[$reqGold, $reqRice] = $this->getCost();
$relYear = $this->env['year'] - $this->env['startyear'];
$this->runnableConstraints=[
['NotOpeningPart'],
['NearCity', 1],
['NotBeNeutral'],
['OccupiedCity'],
['ReqGeneralCrew'],
['ReqGeneralRice', $reqRice],
['AllowWar'],
['BattleGroundCity', 1],
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::NearCity(1),
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralCrew(),
ConstraintHelper::ReqGeneralRice($reqRice),
ConstraintHelper::AllowWar(),
ConstraintHelper::BattleGroundCity(true),
];
}
+4 -3
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
@@ -38,9 +39,9 @@ class che_하야 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
['NotBeNeutral'],
['NotOpeningPart', $relYear],
['NotLord'],
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotOpeningPart($relYear),
ConstraintHelper::NotLord(),
];
}
+3 -2
View File
@@ -12,6 +12,7 @@ use \sammo\{
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
use sammo\CityConst;
use function sammo\getNationTypeClass;
use function sammo\refreshNationStaticInfo;
@@ -46,8 +47,8 @@ class che_해산 extends Command\GeneralCommand{
$relYear = $env['year'] - $env['startyear'];
$this->runnableConstraints=[
['BeLord'],
['WanderingNation'],
ConstraintHelper::BeLord(),
ConstraintHelper::WanderingNation(),
];
}
+6 -5
View File
@@ -19,6 +19,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
class che_헌납 extends Command\GeneralCommand{
@@ -55,15 +56,15 @@ class che_헌납 extends Command\GeneralCommand{
$this->setNation();
$this->runnableConstraints=[
['NotBeNeutral'],
['OccupiedCity'],
['SuppliedCity'],
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::SuppliedCity(),
];
if($this->arg['isGold']){
$this->runnableConstraints[] = ['ReqGeneralGold', 1];
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralGold(1);
}
else{
$this->runnableConstraints[] = ['ReqGeneralRice', 1];
$this->runnableConstraints[] = ConstraintHelper::ReqGeneralRice(1);
}
}
+6 -5
View File
@@ -16,6 +16,7 @@ use function \sammo\{
};
use \sammo\Constraint\Constraint;
use \sammo\Constraint\ConstraintHelper;
@@ -35,11 +36,11 @@ class che_훈련 extends Command\GeneralCommand{
$this->setNation();
$this->runnableConstraints=[
['NotBeNeutral'],
['NotWanderingNation'],
['OccupiedCity'],
['ReqGeneralCrew'],
['ReqGeneralTrainMargin', GameConst::$maxTrainByCommand],
ConstraintHelper::NotBeNeutral(),
ConstraintHelper::NotWanderingNation(),
ConstraintHelper::OccupiedCity(),
ConstraintHelper::ReqGeneralCrew(),
ConstraintHelper::ReqGeneralTrainMargin(GameConst::$maxTrainByCommand),
];
}
+61
View File
@@ -0,0 +1,61 @@
<?php
namespace sammo\Constraint;
use \sammo\JosaUtil;
use \sammo\Util;
use \sammo\DB;
use \sammo\MustNotBeReachedException;
class AllowRebellion extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('killturn', $this->env)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require killturn in env");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
$general = $this->general;
$nationID = $general['nation'];
if($nationID == 0){
throw new MustNotBeReachedException('재야임');
}
$db = DB::db();
$lord = $db->queryFirstRow('SELECT no, killturn, npc FROM general WHERE nation = %i AND level = 12', $nationID);
if(!$lord){
throw new MustNotBeReachedException('군주가 없음');
}
if($lord['no'] == $general['no']){
$this->reason = '이미 군주입니다.';
return false;
}
if($lord['killturn'] >= $this->env['killturn']){
$this->reason = '군주가 활동중입니다.';
return false;
}
if(in_array($lord['npc'], [2,3,6,9])){
$this->reason = '군주가 NPC입니다.';
return false;
}
return true;
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ namespace sammo\Constraint;
use \sammo\DB;
class BattleGroundCity extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_DEST_CITY|Contraint::REQ_INT_ARG;
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_DEST_CITY|Constraint::REQ_BOOLEAN_ARG;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
+7 -1
View File
@@ -16,7 +16,8 @@ abstract class Constraint{
const REQ_STRING_ARG = self::REQ_ARG | 0x1000;
const REQ_INT_ARG = self::REQ_ARG | 0x2000;
const REQ_NUMERIC_ARG = self::REQ_ARG | 0x4000;
const REQ_ARRAY_ARG = self::REQ_ARG | 0x8000;
const REQ_BOOLEAN_ARG = self::REQ_ARG | 0x8000;
const REQ_ARRAY_ARG = self::REQ_ARG | 0x10000;
const REQ_VALUES = 0;
@@ -144,6 +145,11 @@ abstract class Constraint{
throw new \InvalidArgumentException('require string arg');
}
if(($valueType&static::REQ_BOOLEAN_ARG) && !is_bool($this->arg)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException('require bool arg');
}
if(($valueType&static::REQ_INT_ARG) && !is_int($this->arg)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException('require int arg');
+186
View File
@@ -0,0 +1,186 @@
<?php
namespace sammo\Constraint;
class ConstraintHelper{
static function AllowJoinAction():array{
return [__FUNCTION__];
}
static function AllowJoinDestNation(int $relYear):array{
return [__FUNCTION__, $relYear];
}
static function AllowRebellion():array{
return [__FUNCTION__];
}
static function AllowWar():array{
return [__FUNCTION__];
}
static function AlwaysFail(string $failMessage):array{
return [__FUNCTION__, $failMessage];
}
static function AvailableRecruitCrewType(int $crewTypeID):array{
return [__FUNCTION__, $crewTypeID];
}
static function BattleGroundCity(bool $ignoreSameNation=false):array{
return [__FUNCTION__, $ignoreSameNation];
}
static function BeChief():array{
return [__FUNCTION__];
}
static function BeLord():array{
return [__FUNCTION__];
}
static function BeNeutral():array{
return [__FUNCTION__];
}
static function BeOpeningPart(int $relYear):array{
return [__FUNCTION__, $relYear];
}
static function CheckNationNameDuplicate(string $nationName):array{
return [__FUNCTION__, $nationName];
}
static function ConstructableCity():array{
return [__FUNCTION__];
}
static function DifferentNationDestGeneral():array{
return [__FUNCTION__];
}
static function DisallowDiplomacyStatus(array $disallowStatus, string $failMessage):array{
return [__FUNCTION__, $disallowStatus, $failMessage];
}
static function ExistsAllowJoinNation(int $relYear, array $excludeNationList):array{
return [__FUNCTION__, $relYear, $excludeNationList];
}
static function ExistsDestGeneral():array{
return [__FUNCTION__];
}
static function ExistsDestNation():array{
return [__FUNCTION__];
}
static function FriendlyDestGeneral():array{
return [__FUNCTION__];
}
static function NearCity(int $distance):array{
return [__FUNCTION__, $distance];
}
static function MustBeNPC():array{
return [__FUNCTION__];
}
static function MustBeTroopLeader():array{
return [__FUNCTION__];
}
static function NotBeNeutral():array{
return [__FUNCTION__];
}
static function NotCapital(bool $ignoreOfficer=false):array{
return [__FUNCTION__, $ignoreOfficer];
}
static function NotOccupiedCity():array{
return [__FUNCTION__];
}
static function NotOpeningPart(int $relYear):array{
return [__FUNCTION__, $relYear];
}
static function NotSameDestCity():array{
return [__FUNCTION__];
}
static function NotLord():array{
return [__FUNCTION__];
}
static function NotWanderingNation():array{
return [__FUNCTION__];
}
static function OccupiedCity(bool $allowNeutral=true):array{
return [__FUNCTION__, $allowNeutral];
}
static function RemainCityCapacity($key, string $actionName):array{
return [__FUNCTION__, $key, $actionName];
}
static function ReqCityCapacity($key, string $keyNick, $reqVal):array{
return [__FUNCTION__, $key, $keyNick, $reqVal];
}
static function ReqCityTrust(float $minTrust):array{
return [__FUNCTION__, $minTrust];
}
static function ReqCityTrader(int $npcType):array{
return [__FUNCTION__, $npcType];
}
static function ReqEnvValue($key, string $keyNick, string $comp, $reqVal, string $failMessage):array{
return [__FUNCTION__, $key, $keyNick, $comp, $reqVal, $failMessage];
}
static function ReqGeneralAtmosMargin(int $maxAtmos):array{
return [__FUNCTION__, $maxAtmos];
}
static function ReqGeneralCrew():array{
return [__FUNCTION__];
}
static function ReqGeneralCrewMargin(int $crewTypeID):array{
return [__FUNCTION__, $crewTypeID];
}
static function ReqGeneralGold(int $reqGold):array{
return [__FUNCTION__, $reqGold];
}
static function ReqGeneralRice(int $reqRice):array{
return [__FUNCTION__, $reqRice];
}
static function ReqGeneralTrainMargin(int $maxTrain):array{
return [__FUNCTION__, $maxTrain];
}
static function ReqGeneralValue($key, string $keyNick, string $comp, $reqVal):array{
return [__FUNCTION__, $key, $keyNick, $comp, $reqVal];
}
static function ReqTroopMembers():array{
return [__FUNCTION__];
}
static function SuppliedCity():array{
return [__FUNCTION__];
}
static function WanderingNation():array{
return [__FUNCTION__];
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
namespace sammo\Constraint;
class ExistsDestGeneral extends Constraint{
class ExistsDestNation extends Constraint{
const REQ_VALUES = Constraint::REQ_DEST_NATION;
public function checkInputValues(bool $throwExeception=true){
+1 -1
View File
@@ -3,7 +3,7 @@
namespace sammo\Constraint;
class NotCapital extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_NATION|Constraint::REQ_INT_ARG;
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_NATION|Constraint::REQ_BOOLEAN_ARG;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
+3 -3
View File
@@ -3,7 +3,7 @@
namespace sammo\Constraint;
class OccupiedCity extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_CITY;
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_CITY|Constraint::REQ_BOOLEAN_ARG;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
@@ -27,8 +27,8 @@ class OccupiedCity extends Constraint{
$this->checkInputValues();
$this->tested = true;
//특수 예외로 ARG가 지정된 경우에는 재야여도 'OccupiedCity'로 허용함
if($this->arg && $this->general['nation'] == 0){
//재야여도 허용하는 경우
if($this->arg[0] && $this->general['nation'] == 0){
return true;
}
@@ -13,6 +13,11 @@ class ReqGeneralCrewMargin extends Constraint{
return false;
}
if(GameUnitConst::byID($this->arg) === null){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("{$this->arg} is invalid crewtype");
}
foreach(['leader','power','intel','crew','crewtype','nation','level'] as $key){
if(!key_exists($key, $this->general)){
if(!$throwExeception){return false; }
@@ -33,6 +38,13 @@ class ReqGeneralCrewMargin extends Constraint{
//XXX: 왜 General -> obj -> General 변환을 하고 있나?
$generalObj = new General($this->general, null, null, null, false);
$reqCrewType = GameUnitConst::byID($this->arg);
if($reqCrewType->id != $generalObj->getCrewTypeObj()->id){
return true;
}
$leadership = $generalObj->getLeadership();
$crew = $this->general['crew'];
+1 -1
View File
@@ -8,7 +8,7 @@ use \sammo\Util;
/**
* 범용으로 사용 가능한 장수 변수 검사도구
*/
class RegGeneralValue extends Constraint{
class ReqGeneralValue extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_ARRAY_ARG;
protected $key;