징병 모병 추가, iAction 구조 일부 변경

This commit is contained in:
2018-10-20 23:31:32 +09:00
parent 18ae2f121a
commit 05fcb5397e
50 changed files with 560 additions and 183 deletions
@@ -0,0 +1,61 @@
<?php
namespace sammo\Constraint;
use \sammo\GameUnitConst;
use \sammo\DB;
class AvailableRecruitCrewType extends Constraint{
const REQ_VALUES = Constraint::REQ_NATION|Constraint::REQ_INT_ARG;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('nation', $this->nation)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require nation in nation");
}
if(!key_exists('tech', $this->nation)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require tecg in nation");
}
if(GameUnitConst::byID($this->arg) === null){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("invalid crewtype");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
[$startyear, $year] = $gameStor->getValuesAsArray(['startyear', 'year']);
$nationID = $this->nation['nation'];
$tech = $this->nation['tech'];
$ownCities = [];
$ownRegions = [];
foreach($db->queryFirstColumn('SELECT city FROM city WHERE nation = %i', $nationID) as $ownCity){
$ownCities[$ownCity] = 1;
$ownRegions[CityConst::byId($ownCity)->region] = 1;
}
$crewType = GameUnitConst::byID($this->arg);
if($crewType->isValid($ownCities, $ownRegions, $year = $startyear, $tech)){
return true;
}
$this->reason = "현재 선택할 수 없는 병종입니다.";
return false;
}
}
+70
View File
@@ -0,0 +1,70 @@
<?php
namespace sammo\Constraint;
use \sammo\JosaUtil;
use \sammo\Util;
class ReqCityCapacity extends Constraint{
const REQ_VALUES = Constraint::REQ_CITY|Constraint::REQ_ARRAY_ARG;
protected $key;
protected $maxKey;
protected $keyNick;
protected $reqVal;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
[$this->key, $this->keyNick, $this->reqVal] = $this->arg;
$this->maxKey = $this->key.'2';
if(!key_exists($this->key, $this->city)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require {$this->key} in city");
}
if(is_numeric($this->reqVal)){
$this->isPercent = false;
}
else if(is_str($this->reqVal)){
$this->reqVal = Util::convPercentStrToFloat($this->reqVal);
if($this->reqVal === null){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require valid reqVal(percentStr|numeric) format");
}
if(!key_exists($this->maxKey, $this->city)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require {$this->maxKey} in city");
}
$this->isPercent = true;
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
if($this->isPercent){
if($this->city[$this->key] >= $this->city[$this->maxKey] * $this->reqVal){
return true;
}
}
else{
if($this->city[$this->key] >= $this->reqVal){
return true;
}
}
$josaYi = JosaUtil::pick($keyNick, '이');
$this->reason = "{$keyNick}{$josaUn} 모자랍니다.";
return false;
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace sammo\Constraint;
use \sammo\JosaUtil;
class RemainCityTrust extends Constraint{
const REQ_VALUES = Constraint::REQ_CITY|Constraint::REQ_NUMERIC_ARG;
protected $key;
protected $maxKey;
protected $keyNick;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
$this->keyNick = '민심';
$this->key = 'trust';
$this->reqVal = $this->arg;
if(!key_exists($this->key, $this->city)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require {$this->key} in city");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
if($this->city[$this->key] >= $this->reqVal){
return true;
}
$this->reason = "민심이 낮아 주민들이 도망갑니다.";
return false;
}
}
@@ -0,0 +1,46 @@
<?php
namespace sammo\Constraint;
use sammo\GameConst;
use sammo\GameUnitConst;
use sammo\General;
class ReqGeneralCrewMargin extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL|Constraint::REQ_INT_ARG;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
foreach(['leader','power','intel','crew','crewtype','nation','level'] as $key){
if(!key_exists($key, $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require {$key} in general");
}
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
if($crewType != $this->general['crewtype']){
return true;
}
//XXX: 왜 General -> obj -> General 변환을 하고 있나?
$generalObj = new General($this->general, null, null, null, false);
$leadership = $generalObj->getLeadership();
$crew = $this->general['crew'];
if($leadership * 100 > $crew){
return true;
}
$this->reason = "이미 많은 병력을 보유하고 있습니다.";
return false;
}
}