상업투자 구현 중
This commit is contained in:
@@ -2,21 +2,137 @@
|
|||||||
namespace sammo\Command;
|
namespace sammo\Command;
|
||||||
|
|
||||||
use \sammo\{
|
use \sammo\{
|
||||||
Util, JosaUtil,
|
Util, JosaUtil, DB,
|
||||||
General,
|
General,
|
||||||
|
ActionLogger
|
||||||
};
|
};
|
||||||
|
|
||||||
use \sammo\Constraint\{
|
use \sammo\Constraint\Constraint;
|
||||||
Constraint, NoNeutral, NoOpeningPart, NoWanderingNation, OccupiedCity,
|
|
||||||
RemainCityCapacity, ReqGeneralGold, SuppliedCity
|
|
||||||
};
|
|
||||||
abstract class BaseCommand{
|
abstract class BaseCommand{
|
||||||
|
/**
|
||||||
|
* @var General|null $generalObj
|
||||||
|
* @var array|null $destGeneral
|
||||||
|
*/
|
||||||
protected $id = 0;
|
protected $id = 0;
|
||||||
protected $name = 'CommandName';
|
protected $name = 'CommandName';
|
||||||
|
|
||||||
abstract public function __construct(General $general, ...$args);
|
protected $generalObj = null;
|
||||||
|
protected $city = null;
|
||||||
|
protected $nation = null;
|
||||||
|
protected $arg = null;
|
||||||
|
protected $env = null;
|
||||||
|
|
||||||
|
protected $destGeneral = null;
|
||||||
|
protected $destCity = null;
|
||||||
|
protected $destNation = null;
|
||||||
|
|
||||||
|
protected $available = null;
|
||||||
|
protected $reason = null;
|
||||||
|
|
||||||
|
protected $constraints = null;
|
||||||
|
|
||||||
|
protected $logger;
|
||||||
|
|
||||||
|
public function __construct(General $generalObj, array $env, $arg){
|
||||||
|
$this->generalObj = $generalObj;
|
||||||
|
$this->logger = $generalObj->getLogger();
|
||||||
|
$this->env = $env;
|
||||||
|
$this->arg = $arg;
|
||||||
|
$this->init();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setCity(array $args=null){
|
||||||
|
$db = DB::db();
|
||||||
|
if($args == null){
|
||||||
|
$this->city = $this->generalObj->getRawCity();
|
||||||
|
if($this->city){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->city = $db->queryFirstRow('SELECT * FROM city WHERE city=%i', $this->generalObj->getVar('city'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->city = $db->queryFirstRow('SELECT %lb FROM city WHERE city=%i', $args, $this->generalObj->getVar('city'));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setNation(?array $args = null){
|
||||||
|
if($args == null){
|
||||||
|
$this->nation = $this->generalObj->getStaticNation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
$this->nation = $db->queryFirstRow('SELECT %lb FROM nation WHERE nation=%i', $args, $this->generalObj->getVar('nation'));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setDestGeneralFromObj(General $destGeneral){
|
||||||
|
$this->destGeneral = $destGeneral->getRaw();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setDestGeneral(int $generalNo, array $args){
|
||||||
|
$db = DB::db();
|
||||||
|
$this->destGeneral = $db->queryFirstRow('SELECT %lb FROM general WHERE no=%i', $args, $generalNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setDestCity(int $cityNo, ?array $args){
|
||||||
|
$db = DB::db();
|
||||||
|
if($args == null){
|
||||||
|
$this->destCity = $db->queryFirstRow('SELECT * FROM city WHERE city=%i', $cityNo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->destCity = $db->queryFirstRow('SELECT %lb FROM city WHERE city=%i', $args, $cityNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setDestNation(int $nationNo, ?array $args = null){
|
||||||
|
if($args == null){
|
||||||
|
$this->destNation = getNationStaticInfo($nationNo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = DB::db();
|
||||||
|
$this->destNation = $db->queryFirstRow('SELECT %lb FROM nation WHERE nation=%i', $args, $nationNo);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected function init();
|
||||||
|
|
||||||
public function getName():string {
|
public function getName():string {
|
||||||
return static::$name;
|
return static::$name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLogger():ActionLogger{
|
||||||
|
return $this->logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test():?string{
|
||||||
|
if($this->constraints === null){
|
||||||
|
throw new \InvalidArgumentException('인자가 제대로 설정되지 않았습니다');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->reason = Constraint::testAll($this->constraints, [
|
||||||
|
'general'=>$this->generalObj->getRaw(),
|
||||||
|
'city'=>$this->city,
|
||||||
|
'nation'=>$this->city,
|
||||||
|
'arg'=>$this->arg,
|
||||||
|
|
||||||
|
'destGeneral'=>$this->destGeneral,
|
||||||
|
'destCity'=>$this->destCity,
|
||||||
|
'destNation'=>$this->destNation,
|
||||||
|
]);
|
||||||
|
$this->available = $this->reason === null;
|
||||||
|
return $this->reason;
|
||||||
|
|
||||||
|
}
|
||||||
|
public function isAvailable():bool {
|
||||||
|
if($this->available === null){
|
||||||
|
$this->test();
|
||||||
|
}
|
||||||
|
return $this->available;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public function getCost():array;
|
||||||
|
|
||||||
|
abstract public function run():bool;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace sammo\Command;
|
namespace sammo\Command;
|
||||||
|
|
||||||
use \sammo\Util;
|
use \sammo\{
|
||||||
use \sammo\JosaUtil;
|
Util, JosaUtil,
|
||||||
|
General,
|
||||||
|
ActionLogger
|
||||||
|
};
|
||||||
|
|
||||||
|
use \sammo\Constraint\Constraint;
|
||||||
|
|
||||||
|
|
||||||
class che_상업투자 extends BaseCommand{
|
class che_상업투자 extends BaseCommand{
|
||||||
|
static $cityKey = 'comm';
|
||||||
|
static $actionName = '상업 투자';
|
||||||
|
|
||||||
|
protected function init(){
|
||||||
|
|
||||||
|
$general = $this->generalObj;
|
||||||
|
|
||||||
|
$this->setCity();
|
||||||
|
$this->setNation();
|
||||||
|
$develCost = $this->env['develcost'];
|
||||||
|
|
||||||
|
$nationTypeObj = $general->getNationTypeObj();
|
||||||
|
$generalLevelObj = $general->getGeneralLevelObj();
|
||||||
|
|
||||||
|
$this->constraints=[
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,12 @@ namespace sammo;
|
|||||||
class General{
|
class General{
|
||||||
use LazyVarUpdater;
|
use LazyVarUpdater;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var iActionTrigger $nationType
|
||||||
|
* @var iActionTrigger $levelObj
|
||||||
|
* @var iActionTrigger $specialDomesticObj
|
||||||
|
*/
|
||||||
|
|
||||||
protected $raw = [];
|
protected $raw = [];
|
||||||
protected $rawCity = null;
|
protected $rawCity = null;
|
||||||
|
|
||||||
@@ -14,6 +20,7 @@ class General{
|
|||||||
protected $logActivatedSkill = [];
|
protected $logActivatedSkill = [];
|
||||||
protected $isFinished = false;
|
protected $isFinished = false;
|
||||||
|
|
||||||
|
|
||||||
protected $nationType;
|
protected $nationType;
|
||||||
protected $levelObj;
|
protected $levelObj;
|
||||||
protected $specialDomesticObj;
|
protected $specialDomesticObj;
|
||||||
@@ -79,6 +86,10 @@ class General{
|
|||||||
return $this->raw['name'];
|
return $this->raw['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRawCity():?array{
|
||||||
|
return $this->rawCity;
|
||||||
|
}
|
||||||
|
|
||||||
function getCityID():int{
|
function getCityID():int{
|
||||||
return $this->raw['city'];
|
return $this->raw['city'];
|
||||||
}
|
}
|
||||||
@@ -103,6 +114,10 @@ class General{
|
|||||||
return $this->levelObj;
|
return $this->levelObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onCalcDomestic(string $turnType, string $varType, float $value){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: 장기적으로 General 클래스로 모두 옮겨와야함.
|
//TODO: 장기적으로 General 클래스로 모두 옮겨와야함.
|
||||||
function getLeadership($withInjury = true, $withItem = true, $withStatAdjust = true, $useFloor = true):float{
|
function getLeadership($withInjury = true, $withItem = true, $withStatAdjust = true, $useFloor = true):float{
|
||||||
return getGeneralLeadership($this->raw, $withInjury, $withItem, $withStatAdjust, $useFloor);
|
return getGeneralLeadership($this->raw, $withInjury, $withItem, $withStatAdjust, $useFloor);
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ trait LazyVarUpdater{
|
|||||||
return $this->raw;
|
return $this->raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getVar(string $key){
|
||||||
|
return $this->raw[$key];
|
||||||
|
}
|
||||||
|
|
||||||
function updateVar(string $key, $value){
|
function updateVar(string $key, $value){
|
||||||
if($this->raw[$key] === $value){
|
if($this->raw[$key] === $value){
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user