Command 구조 일부 수정

This commit is contained in:
2018-09-30 03:04:20 +09:00
parent 98cfc8a748
commit 082c376dde
15 changed files with 156 additions and 22 deletions
@@ -0,0 +1,134 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\{
DB, Util, JosaUtil,
General,
ActionLogger,
getGeneralLeadership,getGeneralPower,getGeneralIntel,
getDomesticExpLevelBonus,
CriticalRatioDomestic, CriticalScore, TechLimit,
uniqueItemEx
};
use \sammo\Command;
use \sammo\Constraint\Constraint;
use function sammo\CriticalScore;
use function sammo\uniqueItemEx;
use function sammo\getGeneralLeadership;
class che_기술연구 extends che_상업투자{
static $statKey = 'intel';
static $actionKey = '기술';
static $actionName = '기술 연구';
protected function init(){
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$develCost = $this->env['develcost'];
$reqGold = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['OccupiedCity'],
['SuppliedCity'],
['ReqGeneralGold', $reqGold]
];
$this->reqGold = $reqGold;
}
protected function argTest():bool{
return true;
}
public function run():bool{
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$trust = Util::valueFit($this->city['trust'], 50);
$score = Util::valueFit($this->calcBaseScore(), 1);
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general->getRaw(), static::$statKey);
if($trust < 80){
$successRatio *= $trust / 80;
}
$successRatio = $general->onCalcDomestic(static::$cityKey, 'success', $successRatio);
$failRatio = $general->onCalcDomestic(static::$cityKey, 'fail', $failRatio);
$successRatio = Util::valueFit($successRatio, 0, 1);
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
$normalRatio = 1 - $failRatio - $successRatio;
$pick = Util::choiceRandomUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
'normal'=>$normalRatio
]);
$logger = $general->getLogger();
$date = substr($general->getVar('turntime'),11,5);
$score *= CriticalScoreEx($pick);
$score = Util::round($score);
$exp = $score * 0.7;
$ded = $score * 1.0;
$scoreText = number_format($score, 0);
$josaUl = JosaUtil::pick(static::$actionName, '을');
if($pick == 'fail'){
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
}
else if($pick == 'success'){
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
}
else{
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
}
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
if(TechLimit($this->env['startyear'], $this->env['year'], $this->nation['tech'])){
$score /= 4;
}
$genCount = Util::valueFit(
$db->queryFirstField('SELECT gennum FROM nation WHERE nation=%i', $general->getVar('nation')),
GameConst::$initialNationGenLimit
);
$nationUpdated = [
'tech' => $this->nation['tech'] + $score/$genCount
];
$db->update('nation', $nationUpdated, 'nation=%i', $general->getVar('nation'));
$general->increaseVarWithLimit('gold', -$this->reqGold, 0);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
$general->increaseVar(static::$statKey.'2', 1);
$general->updateVar('resturn', 'SUCCESS');
$general->applyDB($db);
$this->checkStatChange();
uniqueItemEx($general->getVar('no'), $logger);
}
}
@@ -0,0 +1,12 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\Util;
use \sammo\JosaUtil;
class che_농지개간 extends che_상업투자{
static $cityKey = 'agri';
static $statKey = 'intel';
static $actionKey = '농업';
static $actionName = '농지 개간';
}
@@ -0,0 +1,156 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\{
DB, Util, JosaUtil,
General,
ActionLogger,
getGeneralLeadership,getGeneralPower,getGeneralIntel,
getDomesticExpLevelBonus,
CriticalRatioDomestic, CriticalScore,
uniqueItemEx
};
use \sammo\Command;
use \sammo\Constraint\Constraint;
use function sammo\CriticalScore;
use function sammo\uniqueItemEx;
use function sammo\getGeneralLeadership;
class che_상업투자 extends GeneralCommand{
static $cityKey = 'comm';
static $statKey = 'intel';
static $actionKey = '상업';
static $actionName = '상업 투자';
protected function init(){
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$develCost = $this->env['develcost'];
$reqGold = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['OccupiedCity'],
['SuppliedCity'],
['ReqGeneralGold', $reqGold],
['RemainCityCapacity', [static::$cityKey, static::$actionName]]
];
$this->reqGold = $reqGold;
}
protected function argTest():bool{
return true;
}
protected function calcBaseScore():float{
$trust = Util::valueFit($this->city['trust'], 50);
$general = $this->generalObj;
if(static::$statKey == 'intel'){
$score = getGeneralIntel($general->getRaw(), true, true, true, false);
}
else if(static::$statKey == 'power'){
$score = getGeneralPower($general->getRaw(), true, true, true, false);
}
else if(static::$statKey == 'leader'){
$score = getGeneralLeadership($general->getRaw(), true, true, true, false);
}
else{
throw new \sammo\MustNotBeReachedException();
}
$score *= $trust / 100;
$score *= getDomesticExpLevelBonus($general['explevel']);
$score *= Util::randRange(0.8, 1.2);
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
return $score;
}
public function run():bool{
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$trust = Util::valueFit($this->city['trust'], 50);
$score = Util::valueFit($this->calcBaseScore(), 1);
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general->getRaw(), static::$statKey);
if($trust < 80){
$successRatio *= $trust / 80;
}
$successRatio = $general->onCalcDomestic(static::$cityKey, 'success', $successRatio);
$failRatio = $general->onCalcDomestic(static::$cityKey, 'fail', $failRatio);
$successRatio = Util::valueFit($successRatio, 0, 1);
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
$normalRatio = 1 - $failRatio - $successRatio;
$pick = Util::choiceRandomUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
'normal'=>$normalRatio
]);
$logger = $general->getLogger();
$date = substr($general->getVar('turntime'),11,5);
$score *= CriticalScoreEx($pick);
$score = Util::round($score);
$exp = $score * 0.7;
$ded = $score * 1.0;
$scoreText = number_format($score, 0);
$josaUl = JosaUtil::pick(static::$actionName, '을');
if($pick == 'fail'){
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
}
else if($pick == 'success'){
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
}
else{
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
}
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
//NOTE: 내정량 상승시 초과 가능?
$cityUpdated = [
static::$cityKey => Util::valueFit(
$this->city[static::$cityKey] + $score,
0,
$this->city[static::$cityKey.'2']
)
];
$db->update('city', $cityUpdated, 'city=%i', $general->getVar('city'));
$general->increaseVarWithLimit('gold', -$this->reqGold, 0);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
$general->increaseVar(static::$statKey.'2', 1);
$general->updateVar('resturn', 'SUCCESS');
$general->applyDB($db);
$this->checkStatChange();
uniqueItemEx($general->getVar('no'), $logger);
}
}
@@ -0,0 +1,12 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\Util;
use \sammo\JosaUtil;
class che_성벽보수 extends che_상업투자{
static $cityKey = 'wall';
static $statKey = 'power';
static $actionKey = '성벽';
static $actionName = '성벽 보수';
}
@@ -0,0 +1,12 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\Util;
use \sammo\JosaUtil;
class che_수비강화 extends che_상업투자{
static $cityKey = 'def';
static $statKey = 'power';
static $actionKey = '수비';
static $actionName = '수비 강화';
}
@@ -0,0 +1,147 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\{
DB, Util, JosaUtil,
General,
ActionLogger,
getGeneralLeadership,getGeneralPower,getGeneralIntel,
getDomesticExpLevelBonus,
CriticalRatioDomestic, CriticalScore,
uniqueItemEx
};
use \sammo\Command;
use \sammo\Constraint\Constraint;
use function sammo\CriticalScore;
use function sammo\uniqueItemEx;
use function sammo\getGeneralLeadership;
class che_상업투자 extends GeneralCommand{
static $cityKey = 'pop';
static $statKey = 'leader';
static $actionKey = '인구';
static $actionName = '정착 장려';
protected function init(){
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$develCost = $this->env['develcost'] * 2;
$reqRice = $general->onCalcDomestic(static::$actionKey, 'cost', $reqRice);
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['OccupiedCity'],
['SuppliedCity'],
['ReqGeneralGold', $reqRice],
['RemainCityCapacity', [static::$cityKey, static::$actionName]]
];
$this->reqRice = $reqRice;
}
protected function argTest():bool{
return true;
}
protected function calcBaseScore():float{
$general = $this->generalObj;
if(static::$statKey == 'leader'){
$score = getGeneralLeadership($general->getRaw(), true, true, true, false);
}
else{
throw new \sammo\MustNotBeReachedException();
}
$score *= getDomesticExpLevelBonus($general['explevel']);
$score *= Util::randRange(0.8, 1.2);
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
return $score;
}
public function run():bool{
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$score = Util::valueFit($this->calcBaseScore(), 1);
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general->getRaw(), static::$statKey);
$successRatio = $general->onCalcDomestic(static::$cityKey, 'success', $successRatio);
$failRatio = $general->onCalcDomestic(static::$cityKey, 'fail', $failRatio);
$successRatio = Util::valueFit($successRatio, 0, 1);
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
$normalRatio = 1 - $failRatio - $successRatio;
$pick = Util::choiceRandomUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
'normal'=>$normalRatio
]);
$logger = $general->getLogger();
$date = substr($general->getVar('turntime'),11,5);
$score *= CriticalScoreEx($pick);
$score = Util::round($score);
$exp = $score * 0.7;
$ded = $score * 1.0;
$score *= 10;
$scoreText = number_format($score, 0);
$josaUl = JosaUtil::pick(static::$actionName, '을');
if($pick == 'fail'){
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 주민이 <C>$scoreText</>명 증가했습니다. <1>$date</>");
}
else if($pick == 'success'){
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 주민이 <C>$scoreText</>명 증가했습니다. <1>$date</>");
}
else{
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 주민이 <C>$scoreText</>명 증가했습니다. <1>$date</>");
}
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
//NOTE: 내정량 상승시 초과 가능?
$cityUpdated = [
static::$cityKey => Util::valueFit(
$this->city[static::$cityKey] + $score,
0,
$this->city[static::$cityKey.'2']
)
];
$db->update('city', $cityUpdated, 'city=%i', $general->getVar('city'));
$general->increaseVarWithLimit('rice', -$this->reqRice, 0);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
$general->increaseVar(static::$statKey.'2', 1);
$general->updateVar('resturn', 'SUCCESS');
$general->applyDB($db);
$this->checkStatChange();
uniqueItemEx($general->getVar('no'), $logger);
}
}
@@ -0,0 +1,145 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\{
DB, Util, JosaUtil,
General,
ActionLogger,
getGeneralLeadership,getGeneralPower,getGeneralIntel,
getDomesticExpLevelBonus,
CriticalRatioDomestic, CriticalScore,
uniqueItemEx
};
use \sammo\Command;
use \sammo\Constraint\Constraint;
use function sammo\CriticalScore;
use function sammo\uniqueItemEx;
use function sammo\getGeneralLeadership;
class che_주민선정 extends GeneralCommand{
static $cityKey = 'trust';
static $statKey = 'leader';
static $actionKey = '민심';
static $actionName = '주민 선정';
protected function init(){
$general = $this->generalObj;
$this->setCity();
$this->setNation();
$develCost = $this->env['develcost'] * 2;
$reqRice = $general->onCalcDomestic(static::$actionKey, 'cost', $reqGold);
$this->runnableConstraints=[
['NoNeutral'],
['NoWanderingNation'],
['OccupiedCity'],
['SuppliedCity'],
['ReqGeneralRice', $reqRice],
['RemainCityTrust', static::$actionName]
];
$this->reqRice = $reqRice;
}
protected function argTest():bool{
return true;
}
protected function calcBaseScore():float{
$general = $this->generalObj;
if(static::$statKey == 'leader'){
$score = getGeneralLeadership($general->getRaw(), true, true, true, false);
}
else{
throw new \sammo\MustNotBeReachedException();
}
$score *= getDomesticExpLevelBonus($general['explevel']);
$score *= Util::randRange(0.8, 1.2);
$score = $general->onCalcDomestic(static::$actionKey, 'score', $score);
$score = Util::valutFit($score, 1);
return $score;
}
public function run():bool{
if(!$this->isRunnable()){
throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도');
}
$db = DB::db();
$general = $this->generalObj;
$score = Util::valueFit($this->calcBaseScore(), 1);
['success'=>$successRatio, 'fail'=>$failRatio] = CriticalRatioDomestic($general->getRaw(), static::$statKey);
$successRatio = $general->onCalcDomestic(static::$cityKey, 'success', $successRatio);
$failRatio = $general->onCalcDomestic(static::$cityKey, 'fail', $failRatio);
$successRatio = Util::valueFit($successRatio, 0, 1);
$failRatio = Util::valueFit($failRatio, 0, 1 - $successRatio);
$normalRatio = 1 - $failRatio - $successRatio;
$pick = Util::choiceRandomUsingWeight([
'fail'=>$failRatio,
'success'=>$successRatio,
'normal'=>$normalRatio
]);
$logger = $general->getLogger();
$date = substr($general->getVar('turntime'),11,5);
$score *= CriticalScoreEx($pick);
$exp = $score * 0.7;
$ded = $score * 1.0;
$score /= 10;
$scoreText = number_format($score, 1);
$josaUl = JosaUtil::pick(static::$actionName, '을');
if($pick == 'fail'){
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <span class='ev_failed'>실패</span>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
}
else if($pick == 'success'){
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} <S>성공</>하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
}
else{
$logger->pushGeneralActionLog(static::$actionName."{$josaUl} 하여 <C>$scoreText</> 상승했습니다. <1>$date</>");
}
$exp = $general->onPreGeneralStatUpdate($general, 'experience', $exp);
$ded = $general->onPreGeneralStatUpdate($general, 'dedication', $ded);
//NOTE: 내정량 상승시 초과 가능?
$cityUpdated = [
static::$cityKey => Util::valueFit(
$this->city[static::$cityKey] + $score,
0,
100
)
];
$db->update('city', $cityUpdated, 'city=%i', $general->getVar('city'));
$general->increaseVarWithLimit('rice', -$this->reqRice, 0);
$general->increaseVar('experience', $exp);
$general->increaseVar('dedication', $ded);
$general->increaseVar(static::$statKey.'2', 1);
$general->updateVar('resturn', 'SUCCESS');
$general->applyDB($db);
$this->checkStatChange();
uniqueItemEx($general->getVar('no'), $logger);
}
}
@@ -0,0 +1,12 @@
<?php
namespace sammo\GeneralCommand;
use \sammo\Util;
use \sammo\JosaUtil;
class che_치안강화 extends che_상업투자{
static $cityKey = 'secu';
static $statKey = 'power';
static $actionKey = '치안';
static $actionName = '치안 강화';
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace sammo\Command\General;
use \sammo\Command;
use \sammo\Util;
use \sammo\JosaUtil;
class 휴식 extends GeneralCommand{
protected function init(){
//아무것도 하지 않음
}
protected function argTest():bool{
return true;
}
public function getCost():array{
return [0, 0];
}
public function run():bool{
$general = $this->generalObj;
$logger = $general->getLogger();
$date = substr($general->getVar('turntime'),11,5);
$logger->pushGeneralActionLog("아무것도 실행하지 않았습니다. <1>$date</>");
$general->increaseVar('killturn', -1);
$general->applyDB(DB::db());
return true;
}
}