From 78955a1540f1ffb811ac0bcb76229f77af227c06 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 2 Sep 2018 17:25:04 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B2=94=EC=9A=A9=EC=84=B1=EC=9D=84=20?= =?UTF-8?q?=EB=AA=A9=EC=A0=81=EC=9C=BC=EB=A1=9C=20LazyVarUpdater=EB=A5=BC?= =?UTF-8?q?=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/LazyVarUpdater.php | 79 ++++++++++++++++++++++++++++++++++++ hwe/sammo/WarUnit.php | 75 +--------------------------------- hwe/sammo/WarUnitCity.php | 5 +-- hwe/sammo/WarUnitGeneral.php | 5 +-- 4 files changed, 83 insertions(+), 81 deletions(-) create mode 100644 hwe/sammo/LazyVarUpdater.php diff --git a/hwe/sammo/LazyVarUpdater.php b/hwe/sammo/LazyVarUpdater.php new file mode 100644 index 00000000..a65243fd --- /dev/null +++ b/hwe/sammo/LazyVarUpdater.php @@ -0,0 +1,79 @@ +raw; + } + + function updateVar(string $key, $value){ + if($this->raw[$key] === $value){ + return; + } + if(!key_exists($key, $this->updatedVar)){ + $this->updatedVar[$key] = $this->raw[$key]; + } + $this->raw[$key] = $value; + } + + function updateVarWithLimit(string $key, $value, $min = null, $max = null){ + if($min !== null && $value < $min){ + $value = $min; + } + if($max !== null && $value > $max){ + $value = $max; + } + $this->updateVar($key, $value); + } + + function increaseVar(string $key, $value) + { + if($value === 0){ + return; + } + $targetValue = $this->raw[$key] + $value; + $this->updateVar($key, $targetValue); + } + + function increaseVarWithLimit(string $key, $value, $min = null, $max = null){ + $targetValue = $this->raw[$key] + $value; + if($min !== null && $targetValue < $min){ + $targetValue = $min; + } + if($max !== null && $targetValue > $max){ + $targetValue = $max; + } + $this->updateVar($key, $targetValue); + } + + function multiplyVar(string $key, $value) + { + if($value === 1){ + return; + } + $targetValue = $this->raw[$key] * $value; + $this->updateVar($key, $targetValue); + } + + function multiplyVarWithLimit(string $key, $value, $min = null, $max = null){ + $targetValue = $this->raw[$key] * $value; + if($min !== null && $targetValue < $min){ + $targetValue = $min; + } + if($max !== null && $targetValue > $max){ + $targetValue = $max; + } + $this->updateVar($key, $targetValue); + } + + function getUpdatedValues():array { + $updateVals = []; + foreach(array_keys($this->updatedVar) as $key){ + $updateVals[$key] = $this->raw[$key]; + } + return $updateVals; + } +} \ No newline at end of file diff --git a/hwe/sammo/WarUnit.php b/hwe/sammo/WarUnit.php index 5456cf31..972151f1 100644 --- a/hwe/sammo/WarUnit.php +++ b/hwe/sammo/WarUnit.php @@ -2,6 +2,8 @@ namespace sammo; class WarUnit{ + use LazyVarUpdater; + protected $raw; protected $rawNation; @@ -54,76 +56,10 @@ class WarUnit{ return $this->logActivatedSkill; } - function getRaw():array{ - return $this->raw; - } - function getRawNation():array{ return $this->rawNation; } - function getVar(string $key){ - return $this->raw[$key]; - } - - function updateVar(string $key, $value){ - if($this->raw[$key] === $value){ - return; - } - $this->raw[$key] = $value; - $this->updatedVar[$key] = true; - } - - function updateVarWithLimit(string $key, $value, $min = null, $max = null){ - if($min !== null && $value < $min){ - $value = $min; - } - if($max !== null && $value > $max){ - $value = $max; - } - $this->updateVar($key, $value); - } - - function increaseVar(string $key, $value) - { - if($value === 0){ - return; - } - $this->raw[$key] += $value; - $this->updatedVar[$key] = true; - } - - function increaseVarWithLimit(string $key, $value, $min = null, $max = null){ - $targetValue = $this->raw[$key] + $value; - if($min !== null && $targetValue < $min){ - $targetValue = $min; - } - if($max !== null && $targetValue > $max){ - $targetValue = $max; - } - $this->updateVar($key, $targetValue); - } - - function multiplyVar(string $key, $value) - { - if($value === 1){ - return; - } - $this->raw[$key] *= $value; - $this->updatedVar[$key] = true; - } - - function multiplyVarWithLimit(string $key, $value, $min = null, $max = null){ - $targetValue = $this->raw[$key] * $value; - if($min !== null && $targetValue < $min){ - $targetValue = $min; - } - if($max !== null && $targetValue > $max){ - $targetValue = $max; - } - $this->updateVar($key, $targetValue); - } - function getNationVar(string $key){ return $this->rawNation[$key]; } @@ -415,15 +351,8 @@ class WarUnit{ $this->getLogger()->pushBattleResultTemplate($this, $this->getOppose()); } - function applyDB($db):bool{ - throw new NotInheritedMethodException(); - } - - function criticalDamage():float{ //전특, 병종에 따라 필살 데미지가 달라질지도 모르므로 static 함수는 아닌 것으로 return Util::randRange(1.3, 2.0); } - - } \ No newline at end of file diff --git a/hwe/sammo/WarUnitCity.php b/hwe/sammo/WarUnitCity.php index 2f58a161..2c46b95b 100644 --- a/hwe/sammo/WarUnitCity.php +++ b/hwe/sammo/WarUnitCity.php @@ -137,10 +137,7 @@ class WarUnitCity extends WarUnit{ function applyDB($db):bool{ - $updateVals = []; - foreach(array_keys($this->updatedVar) as $key){ - $updateVals[$key] = $this->raw[$key]; - } + $updateVals = $this->getUpdatedValues(); if(!$updateVals){ return false; diff --git a/hwe/sammo/WarUnitGeneral.php b/hwe/sammo/WarUnitGeneral.php index a59c859d..9cef3ae6 100644 --- a/hwe/sammo/WarUnitGeneral.php +++ b/hwe/sammo/WarUnitGeneral.php @@ -971,10 +971,7 @@ class WarUnitGeneral extends WarUnit{ * @param \MeekroDB $db */ function applyDB($db):bool{ - $updateVals = []; - foreach(array_keys($this->updatedVar) as $key){ - $updateVals[$key] = $this->raw[$key]; - } + $updateVals = $this->getUpdatedValues(); if(!$updateVals){ return false;