유산 포인트 시스템 기본 구현(1/2)
This commit is contained in:
@@ -50,6 +50,20 @@ class General implements iAction{
|
|||||||
'occupied'=>1,
|
'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_MS = -1;
|
||||||
const TURNTIME_FULL = 0;
|
const TURNTIME_FULL = 0;
|
||||||
const TURNTIME_HMS = 1;
|
const TURNTIME_HMS = 1;
|
||||||
@@ -1141,4 +1155,123 @@ class General implements iAction{
|
|||||||
}
|
}
|
||||||
return $result;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user