범용성을 목적으로 LazyVarUpdater를 분리
This commit is contained in:
@@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
namespace sammo;
|
||||||
|
|
||||||
|
trait LazyVarUpdater{
|
||||||
|
protected $raw = [];
|
||||||
|
protected $updatedVar = [];
|
||||||
|
|
||||||
|
function getRaw():array{
|
||||||
|
return $this->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-73
@@ -2,6 +2,8 @@
|
|||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
class WarUnit{
|
class WarUnit{
|
||||||
|
use LazyVarUpdater;
|
||||||
|
|
||||||
protected $raw;
|
protected $raw;
|
||||||
protected $rawNation;
|
protected $rawNation;
|
||||||
|
|
||||||
@@ -54,76 +56,10 @@ class WarUnit{
|
|||||||
return $this->logActivatedSkill;
|
return $this->logActivatedSkill;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRaw():array{
|
|
||||||
return $this->raw;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRawNation():array{
|
function getRawNation():array{
|
||||||
return $this->rawNation;
|
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){
|
function getNationVar(string $key){
|
||||||
return $this->rawNation[$key];
|
return $this->rawNation[$key];
|
||||||
}
|
}
|
||||||
@@ -415,15 +351,8 @@ class WarUnit{
|
|||||||
$this->getLogger()->pushBattleResultTemplate($this, $this->getOppose());
|
$this->getLogger()->pushBattleResultTemplate($this, $this->getOppose());
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyDB($db):bool{
|
|
||||||
throw new NotInheritedMethodException();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function criticalDamage():float{
|
function criticalDamage():float{
|
||||||
//전특, 병종에 따라 필살 데미지가 달라질지도 모르므로 static 함수는 아닌 것으로
|
//전특, 병종에 따라 필살 데미지가 달라질지도 모르므로 static 함수는 아닌 것으로
|
||||||
return Util::randRange(1.3, 2.0);
|
return Util::randRange(1.3, 2.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -137,10 +137,7 @@ class WarUnitCity extends WarUnit{
|
|||||||
|
|
||||||
|
|
||||||
function applyDB($db):bool{
|
function applyDB($db):bool{
|
||||||
$updateVals = [];
|
$updateVals = $this->getUpdatedValues();
|
||||||
foreach(array_keys($this->updatedVar) as $key){
|
|
||||||
$updateVals[$key] = $this->raw[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$updateVals){
|
if(!$updateVals){
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -971,10 +971,7 @@ class WarUnitGeneral extends WarUnit{
|
|||||||
* @param \MeekroDB $db
|
* @param \MeekroDB $db
|
||||||
*/
|
*/
|
||||||
function applyDB($db):bool{
|
function applyDB($db):bool{
|
||||||
$updateVals = [];
|
$updateVals = $this->getUpdatedValues();
|
||||||
foreach(array_keys($this->updatedVar) as $key){
|
|
||||||
$updateVals[$key] = $this->raw[$key];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!$updateVals){
|
if(!$updateVals){
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user