훈련 턴 추가

This commit is contained in:
2018-10-15 02:05:39 +09:00
parent 01913983ea
commit 2ee06eab2d
7 changed files with 235 additions and 2 deletions
@@ -39,8 +39,7 @@ class che_기술연구 extends che_상업투자{
['OccupiedCity'],
['SuppliedCity'],
['ReqGeneralGold', $reqGold],
['ReqGeneralRice', $reqRice],
['ReqGeneralGold', $reqGold]
['ReqGeneralRice', $reqRice]
];
$this->reqGold = $reqGold;
+102
View File
@@ -0,0 +1,102 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\{
DB, Util, JosaUtil,
General,
ActionLogger,
GameConst,
getGeneralLeadership,getGeneralPower,getGeneralIntel,
getDomesticExpLevelBonus,
CriticalRatioDomestic, CriticalScore,
uniqueItemEx,
LastTurn
};
use \sammo\Command;
use \sammo\Constraint\Constraint;
use function sammo\CriticalScore;
use function sammo\uniqueItemEx;
use function sammo\getGeneralLeadership;
use sammo\GameUnitConst;
class che_훈련 extends Command\GeneralCommand{
static protected $actionName = '훈련';
protected function init(){
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['OccupiedCity'],
['ReqGeneralCrew'],
['ReqGeneralTrainMargin'],
];
}
protected function argTest():bool{
$this->arg = null;
return true;
}
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);
$score = Util::round($general->getLeadership() * 100 / $general->getVar('crew') * GameConst::$trainDelta);
$scoreText = number_format($score, 0);
$sideEffect = Util::valueFit(intval($general->getVar('atmos') * GameConst::$atmosSideEffectByTraining), 0);
$logger = $general->getLogger();
$logger->pushGeneralActionLog("훈련치가 <C>$scoreText</> 상승했습니다. <1>$date</>");
$exp = 100;
$ded = 70;
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
$general->increaseVarWithLimit('train', $score, 0, GameConst::$maxTrainByCommand);
$general->setVar('atmos', $sideEffect);
$general->addDex($general->getVar('crew')/100, $score, false);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
$general->increaseVar('leader2', 1);
$general->setResultTurn(new LastTurn(static::getName(), $this->arg));
$general->applyDB($db);
$this->checkStatChange();
uniqueItemEx($general->getVar('no'), $logger);
}
}
@@ -0,0 +1,33 @@
<?php
namespace sammo\Constraint;
use sammo\GameConst;
class ReqGeneralAtmosMargin extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('atmos', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require atmos in general");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
if($this->general['atmos'] < GameConst::$maxAtmosByCommand){
return true;
}
$this->reason = "병사들은 이미 정예병사들입니다.";
return false;
}
}
+32
View File
@@ -0,0 +1,32 @@
<?php
namespace sammo\Constraint;
class ReqGeneralCrew extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('crew', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require crew in general");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
if($this->general['crew'] > 0){
return true;
}
$this->reason = "병사들이 없습니다.";
return false;
}
}
@@ -0,0 +1,33 @@
<?php
namespace sammo\Constraint;
use sammo\GameConst;
class ReqGeneralTrainMargin extends Constraint{
const REQ_VALUES = Constraint::REQ_GENERAL;
public function checkInputValues(bool $throwExeception=true){
if(!parent::checkInputValues($throwExeception) && !$throwException){
return false;
}
if(!key_exists('train', $this->general)){
if(!$throwExeception){return false; }
throw new \InvalidArgumentException("require train in general");
}
return true;
}
public function test():bool{
$this->checkInputValues();
$this->tested = true;
if($this->general['train'] < GameConst::$maxTrainByCommand){
return true;
}
$this->reason = "병사들은 이미 정예병사들입니다.";
return false;
}
}
+2
View File
@@ -39,6 +39,8 @@ class GameConstBase
public static $atmosDelta = 30;
/** @var float 훈련시 사기 감소율*/
public static $atmosSideEffectByTraining = 1;
/** @var float 사기시 훈련 감소율*/
public static $trainSideEffectByAtmosTurn = 1;
/** @var float 계략 기본 성공률*/
public static $sabotageDefaultProb = 0.35;
/** @var int 계략시 확률 가중치(수치가 클수록 변화가 적음 : (지력차/$firing + $basefiring)*/
+32
View File
@@ -166,6 +166,10 @@ class General implements iAction{
return $this->levelObj;
}
function getCrewTypeObj():GameUnitDetail{
return GameUnitConst::byID($this->getVar('crewtype'));
}
//TODO: 장기적으로 General 클래스로 모두 옮겨와야함.
function getLeadership($withInjury = true, $withItem = true, $withStatAdjust = true, $useFloor = true):float{
return getGeneralLeadership($this->raw, $withInjury, $withItem, $withStatAdjust, $useFloor);
@@ -179,6 +183,34 @@ class General implements iAction{
return getGeneralIntel($this->raw, $withInjury, $withItem, $withStatAdjust, $useFloor);
}
function addDex(GameUnitDetail $crewType, float $exp, bool $affectTrainAtmos=false){
$armType = $crewType->armType;
if($armType == GameUnitConst::T_CASTLE){
$armType = GameUnitConst::T_SIEGE;
}
if($armType < 0){
return;
}
if($armType == GameUnitConst::T_WIZARD) {
$exp *= 0.9;
}
else if($armType == GameUnitConst::T_SIEGE) {
$exp *= 0.9;
}
if($affectTrainAtmos){
$exp *= ($this->getVar('train') + $this->getVar('atmos')) / 200;
}
$ntype = $armType*10;
$dexType = "dex{$ntype}";
$this->increaseVar($dexType, $exp);
}
/**
* @param \MeekroDB $db
*/