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
+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;