From a1875e85a5f4de245652fe03162244a0876bb47a Mon Sep 17 00:00:00 2001 From: hide_d Date: Sat, 7 Aug 2021 04:16:06 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9C=A0=EC=82=B0=20=ED=8F=AC=EC=9D=B8?= =?UTF-8?q?=ED=8A=B8=20=EC=8B=9C=EC=8A=A4=ED=85=9C=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84(1/2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/General.php | 133 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index af7a2193..6943322f 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -50,6 +50,20 @@ class General implements iAction{ 'occupied'=>1, ]; + const INHERITANCE_KEY = [ + 'previous'=>[true, 1, '기존 포인트'], + 'lived_month'=>[true, 1, '생존'], + 'max_belong'=>[true, 10, '최대 임관년 수'], + 'max_domestic_critical'=>[true, 1, '최대 연속 내정 성공'], + 'snipe_combat'=>[true, 10, '병종 저격 횟수'], + 'combat'=>[['rank', 'warnum'], 5, '전투 횟수'], + 'sabotage'=>[['rank', 'firenum'], 20, '계략 성공 횟수'], + 'unifier'=>[true, 1, '천통 수뇌'], + 'dex'=>[false, 0.001, '숙련도'], + 'tournament'=>[true, 1, '토너먼트'], + 'betting'=>[false, 10, '베팅 당첨'], + ]; + const TURNTIME_FULL_MS = -1; const TURNTIME_FULL = 0; const TURNTIME_HMS = 1; @@ -1141,4 +1155,123 @@ class General implements iAction{ } return $result; } + + /** + * @return int|float + */ + public function getInheritancePoint(string $key, &$aux=null){ + $inheritType = static::INHERITANCE_KEY[$key]??null; + if($inheritType === null){ + throw new \OutOfRangeException("{$key}는 유산 타입이 아님"); + } + + [$storeType, $multiplier, ] = $inheritType; + + if($storeType === true){ + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$this->getID()}"); + [$value, $aux] = $inheritStor->getValue($key); + return $value; + } + + if(is_array($storeType)){ + [$storSubType, $storSubKey] = $storeType; + if($storSubType === 'rank'){ + return $this->getRankVar($storSubKey) * $multiplier; + } + if($storSubType === 'raw'){ + return $this->getVar($storSubKey) * $multiplier; + } + if($storSubType === 'aux'){ + return ($this->getAuxVar($storSubKey)??0) * $multiplier; + } + throw new \InvalidArgumentException("{$storSubType}은 참조 할 수 없는 유산 세부키임"); + } + + if($storeType !== false){ + throw new \InvalidArgumentException("{$storeType}은 올바르지 않은 유산 키임"); + } + + $extractFn = function(){ return [0, null];}; + switch($key){ + case 'dex': + $extractFn = function() use ($multiplier){ + $totalDex = 0; + foreach(array_keys(GameUnitConst::allType()) as $armType){ + $totalDex += $this->getVar("dex{$armType}"); + } + return [$totalDex * $multiplier, null]; + }; + break; + case 'betting': + $extractFn = function() use ($multiplier){ + $betWin = $this->getRankVar('betwin'); + $betWinRate = $this->getRankVar('betwingold')/max(1, $this->getRankVar('betgold')); + + return [$betWin * $multiplier * pow($betWinRate, 2), null]; + }; + break; + default: + throw new \InvalidArgumentException("{$key}는 유산 추출기를 보유하고 있지 않음"); + } + + [$value, $aux] = ($extractFn)(); + return $value; + } + + public function setInheritancePoint(string $key, $value, $aux=null){ + if(!is_int($value) && !is_float($value)){ + throw new \InvalidArgumentException("{$value}는 숫자가 아님"); + } + $inheritType = static::INHERITANCE_KEY[$key]??null; + if($inheritType === null){ + throw new \OutOfRangeException("{$key}는 유산 타입이 아님"); + } + + [$storeType, $multiplier, ] = $inheritType; + if($storeType !== true){ + throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님"); + } + if($multiplier != 1){ + throw new \InvalidArgumentException("{$key}는 1:1 유산 포인트가 아님"); + } + + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$this->getID()}"); + $inheritStor->setValue($key, [$value, $aux]); + } + + public function increaseInheritancePoint(string $key, $value, $aux=null){ + if(!is_int($value) && !is_float($value)){ + throw new \InvalidArgumentException("{$value}는 숫자가 아님"); + } + + $inheritType = static::INHERITANCE_KEY[$key]??null; + if($inheritType === null){ + throw new \OutOfRangeException("{$key}는 유산 타입이 아님"); + } + + [$storeType, $multiplier, ] = $inheritType; + if($storeType !== true){ + throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님"); + } + + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$this->getID()}"); + [$oldValue, $oldAux] = $inheritStor->getValue($key)??[0, null]; + + if($oldAux !== $aux){ + $oldValue = 0; + } + + $newValue = $oldValue + $value * $multiplier; + $inheritStor->setValue($key, [$newValue, $aux]); + } + + public function calcTotalInheritancePoint(): int{ + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$this->getID()}"); + $inheritStor->cacheAll(); + $total = 0; + foreach(array_keys(static::INHERITANCE_KEY) as $key){ + $total += $this->getInheritancePoint($key); + } + return Util::toInt($total); + } } \ No newline at end of file