버그 수정. getStatValue 성능 향상

This commit is contained in:
2019-10-09 15:57:18 +09:00
parent 107263d061
commit 987450d880
3 changed files with 76 additions and 35 deletions
+4 -4
View File
@@ -49,11 +49,11 @@ class che_징병 extends Command\GeneralCommand{
if(!key_exists('crewType', $this->arg)){ if(!key_exists('crewType', $this->arg)){
return false; return false;
} }
if(!key_exists('amountCrew', $this->arg)){ if(!key_exists('amount', $this->arg)){
return false; return false;
} }
$crewType = $this->arg['crewType']; $crewType = $this->arg['crewType'];
$amount = $this->arg['amountCrew']; $amount = $this->arg['amount'];
if(!is_int($crewType)){ if(!is_int($crewType)){
return false; return false;
@@ -71,7 +71,7 @@ class che_징병 extends Command\GeneralCommand{
} }
$this->arg = [ $this->arg = [
'crewType'=>$crewType, 'crewType'=>$crewType,
'amountCrew'=>$amount 'amount'=>$amount
]; ];
return true; return true;
} }
@@ -91,7 +91,7 @@ class che_징병 extends Command\GeneralCommand{
if($reqCrewType->id == $currCrewType->id){ if($reqCrewType->id == $currCrewType->id){
$maxCrew -= $general->getVar('crew'); $maxCrew -= $general->getVar('crew');
} }
$reqCrew = Util::valueFit($this->arg['amountCrew'], 100, $maxCrew); $reqCrew = Util::valueFit($this->arg['amount'], 100, $maxCrew);
$this->reqCrew = $reqCrew; $this->reqCrew = $reqCrew;
$this->reqCrewType = $reqCrewType; $this->reqCrewType = $reqCrewType;
$this->currCrewType = $currCrewType; $this->currCrewType = $currCrewType;
+66 -23
View File
@@ -40,6 +40,25 @@ class General implements iAction{
const TURNTIME_HMS = 1; const TURNTIME_HMS = 1;
const TURNTIME_HM = 2; const TURNTIME_HM = 2;
protected $calcCache = [];
protected static $prohibitedDirectUpdateVars = [
//Reason: iAction
'leadership'=>1,
'power'=>1,
'intel'=>1,
'nation'=>2,
'level'=>1,
//NOTE: levelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남.
'special'=>1,
'special2'=>1,
'personal'=>1,
'horse'=>1,
'weapon'=>1,
'book'=>1,
'item'=>1
];
/** /**
* @param array $raw DB row값. * @param array $raw DB row값.
@@ -236,14 +255,23 @@ class General implements iAction{
* *
* @param string $statName 스탯값, leadership, strength, intel 가능 * @param string $statName 스탯값, leadership, strength, intel 가능
* @param bool $withInjury 부상값 사용 여부 * @param bool $withInjury 부상값 사용 여부
* @param bool $withItem 아이템 적용 여부 * @param bool $withIActionObj 아이템, 특성, 성격 등 보정치 적용 여부
* @param bool $withStatAdjust 추가 능력치 보정 사용 여부 * @param bool $withStatAdjust 능력치 보정 사용 여부
* @param bool $useFloor 내림 사용 여부, false시 float 값을 반환할 수도 있음 * @param bool $useFloor 내림 사용 여부, false시 float 값을 반환할 수도 있음
* *
* @return int|float 계산된 능력치 * @return int|float 계산된 능력치
*/ */
protected function getStatValue(string $statName, $withInjury = true, $withItem = true, $withStatAdjust = true, $useFloor = true):float{ protected function getStatValue(string $statName, $withInjury = true, $withIActionObj = true, $withStatAdjust = true, $useFloor = true):float{
$cKey = "{$statName}_{$withInjury}_{$withIActionObj}_{$withStatAdjust}";
if(key_exists($cKey, $this->calcCache)){
$statValue = $this->calcCache[$cKey];
if($useFloor){
return Util::toInt($statValue);
}
return $statValue;
}
$statValue = $this->getVar($statName); $statValue = $this->getVar($statName);
if($withInjury){ if($withInjury){
@@ -252,26 +280,26 @@ class General implements iAction{
if($withStatAdjust){ if($withStatAdjust){
if($statName === 'strength'){ if($statName === 'strength'){
$statValue += Util::round($this->getStatValue('intel', $withInjury, $withItem, false, false) / 4); $statValue += Util::round($this->getStatValue('intel', $withInjury, $withIActionObj, false, false) / 4);
} }
else if($statName === 'intel'){ else if($statName === 'intel'){
$statValue += Util::round($this->getStatValue('strength', $withInjury, $withItem, false, false) / 4); $statValue += Util::round($this->getStatValue('strength', $withInjury, $withIActionObj, false, false) / 4);
} }
} }
foreach([ if($withIActionObj){
$this->nationType, foreach([
$this->levelObj, $this->nationType,
$this->specialDomesticObj, $this->levelObj,
$this->specialWarObj, $this->specialDomesticObj,
$this->personalityObj $this->specialWarObj,
] as $actionObj){ $this->personalityObj
if($actionObj !== null){ ] as $actionObj){
$statValue = $actionObj->onCalcStat($this, $statName, $statValue); if($actionObj !== null){
$statValue = $actionObj->onCalcStat($this, $statName, $statValue);
}
} }
}
if($withItem){
foreach($this->itemObjs as $actionObj){ foreach($this->itemObjs as $actionObj){
if($actionObj !== null){ if($actionObj !== null){
$statValue = $actionObj->onCalcStat($this, $statName, $statValue); $statValue = $actionObj->onCalcStat($this, $statName, $statValue);
@@ -279,22 +307,25 @@ class General implements iAction{
} }
} }
$this->calcCache[$cKey] = $statValue;
if($useFloor){ if($useFloor){
return Util::toInt($statValue); return Util::toInt($statValue);
} }
return $statValue; return $statValue;
} }
function getLeadership($withInjury = true, $withItem = true, $withStatAdjust = true, $useFloor = true):float{ function getLeadership($withInjury = true, $withIActionObj = true, $withStatAdjust = true, $useFloor = true):float{
return $this->getStatValue('leadership', $withInjury, $withItem, $withStatAdjust, $useFloor); return $this->getStatValue('leadership', $withInjury, $withIActionObj, $withStatAdjust, $useFloor);
} }
function getStrength($withInjury = true, $withItem = true, $withStatAdjust = true, $useFloor = true):float{ function getStrength($withInjury = true, $withIActionObj = true, $withStatAdjust = true, $useFloor = true):float{
return $this->getStatValue('strength', $withInjury, $withItem, $withStatAdjust, $useFloor); return $this->getStatValue('strength', $withInjury, $withIActionObj, $withStatAdjust, $useFloor);
} }
function getIntel($withInjury = true, $withItem = true, $withStatAdjust = true, $useFloor = true):float{ function getIntel($withInjury = true, $withIActionObj = true, $withStatAdjust = true, $useFloor = true):float{
return $this->getStatValue('intel', $withInjury, $withItem, $withStatAdjust, $useFloor); return $this->getStatValue('intel', $withInjury, $withIActionObj, $withStatAdjust, $useFloor);
} }
function addDex(GameUnitDetail $crewType, float $exp, bool $affectTrainAtmos=false){ function addDex(GameUnitDetail $crewType, float $exp, bool $affectTrainAtmos=false){
@@ -325,6 +356,18 @@ class General implements iAction{
$this->increaseVar($dexType, $exp); $this->increaseVar($dexType, $exp);
} }
function updateVar(string $key, $value){
if(!key_exists($key, $this->updatedVar)){
$this->updatedVar[$key] = $this->raw[$key];
$this->calcCache = [];
}
if($this->raw[$key] === $value){
return;
}
$this->raw[$key] = $value;
$this->calcCache = [];
}
/** /**
* @param \MeekroDB $db * @param \MeekroDB $db
*/ */
+6 -8
View File
@@ -388,18 +388,16 @@ class GeneralAI{
$gold -= $obj훈련->getCost()[0] * 2; $gold -= $obj훈련->getCost()[0] * 2;
$gold -= $obj사기진작->getCost()[0] * 2; $gold -= $obj사기진작->getCost()[0] * 2;
$cost = getCost($type) * getTechCost($tech); $cost = $general->getCrewTypeObj()->costWithTech($tech);
$cost = $general->onCalcDomestic('징병', 'cost', $cost); $cost = $general->onCalcDomestic('징병', 'cost', $cost);
$crew = intdiv($gold, $cost); $crew = intdiv($gold, $cost);
if($leadership*100 < $crew) { $crew = $leadership; }
$crew *= 100; $crew *= 100;
$arg = [ return ['che_징병', [
'crewType'=>$type, 'crewType'=>$type,
'amountCrew'=>$crew 'amount'=>$crew
]; ]];
return ['che_징병', $arg];
} }
public function getPayTurnCandidates(string $resName):array{ public function getPayTurnCandidates(string $resName):array{
@@ -1350,10 +1348,10 @@ class GeneralAI{
//총 통솔의 절반을 징병하는 것을 기준으로 함 //총 통솔의 절반을 징병하는 것을 기준으로 함
$general = $this->getGeneralObj(); $general = $this->getGeneralObj();
$tech = $this->nation['tech']; $tech = $this->nation['tech'];
$crewType = GameUnitConst::byID($general->getVar('crewtype')); $crewType = $general->getCrewTypeObj();
$baseArmCost = $crewType->costWithTech( $baseArmCost = $crewType->costWithTech(
$tech, $tech,
$general->getLeadership(false) / 2 $general->getLeadership(false) * 50
);//기본 병종 );//기본 병종
$baseArmCost = $general->onCalcDomestic('징병', 'cost', $baseArmCost); $baseArmCost = $general->onCalcDomestic('징병', 'cost', $baseArmCost);
$baseArmRice = $general->getLeadership(false) / 2 * $crewType->rice * getTechCost($tech); $baseArmRice = $general->getLeadership(false) / 2 * $crewType->rice * getTechCost($tech);