105 lines
2.8 KiB
C#
105 lines
2.8 KiB
C#
|
|
using GUPS.AntiCheat.Protected;
|
||
|
|
using Newtonsoft.Json;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class gacharewardtabledata
|
||
|
|
{
|
||
|
|
protected ProtectedInt32 _n_GachaGrade;
|
||
|
|
public int n_GachaGrade
|
||
|
|
{
|
||
|
|
get { return _n_GachaGrade; }
|
||
|
|
set { _n_GachaGrade = value; _n_GachaGrade.Obfuscate(); }
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ProtectedInt32 _n_GachaRate;
|
||
|
|
public int n_GachaRate
|
||
|
|
{
|
||
|
|
get { return _n_GachaRate; }
|
||
|
|
set { _n_GachaRate = value; _n_GachaRate.Obfuscate(); }
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ProtectedInt32 _n_RewardMinCount;
|
||
|
|
public int n_RewardMinCount
|
||
|
|
{
|
||
|
|
get { return _n_RewardMinCount; }
|
||
|
|
set { _n_RewardMinCount = value; _n_RewardMinCount.Obfuscate(); }
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ProtectedInt32 _n_RewardMaxCount;
|
||
|
|
public int n_RewardMaxCount
|
||
|
|
{
|
||
|
|
get { return _n_RewardMaxCount; }
|
||
|
|
set { _n_RewardMaxCount = value; _n_RewardMaxCount.Obfuscate(); }
|
||
|
|
}
|
||
|
|
|
||
|
|
public eMoney e_GachaRewardType; // enum은 그대로 유지
|
||
|
|
|
||
|
|
protected ProtectedFloat _f_LuckyBonusRate;
|
||
|
|
public float f_LuckyBonusRate
|
||
|
|
{
|
||
|
|
get { return _f_LuckyBonusRate; }
|
||
|
|
set { _f_LuckyBonusRate = value; _f_LuckyBonusRate.Obfuscate(); }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class table_gachareward : table_base
|
||
|
|
{
|
||
|
|
public static table_gachareward Ins;
|
||
|
|
|
||
|
|
List<gacharewardtabledata> tableDatas;
|
||
|
|
|
||
|
|
protected override void Awake()
|
||
|
|
{
|
||
|
|
Ins = this;
|
||
|
|
base.Awake();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void Start()
|
||
|
|
{
|
||
|
|
tableDatas = JsonConvert.DeserializeObject<List<gacharewardtabledata>>(json_last);
|
||
|
|
base.Start();
|
||
|
|
}
|
||
|
|
|
||
|
|
public (eMoney, int, int) Get_Reward(int grade)
|
||
|
|
{
|
||
|
|
// grade에 맞는 모든 보상 후보 가져오기
|
||
|
|
var candidates = tableDatas.Where(d => d.n_GachaGrade == grade).ToList();
|
||
|
|
if (candidates.Count == 0)
|
||
|
|
{
|
||
|
|
Debug.LogError($"[table_gachareward] No reward found for grade {grade}");
|
||
|
|
return (default(eMoney), 0, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 가중치 합산
|
||
|
|
int totalRate = candidates.Sum(d => d.n_GachaRate);
|
||
|
|
|
||
|
|
// 랜덤 값 뽑기
|
||
|
|
int rand = Random.Range(0, totalRate);
|
||
|
|
int accum = 0;
|
||
|
|
gacharewardtabledata selected = null;
|
||
|
|
|
||
|
|
foreach (var c in candidates)
|
||
|
|
{
|
||
|
|
accum += c.n_GachaRate;
|
||
|
|
if (rand < accum)
|
||
|
|
{
|
||
|
|
selected = c;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (selected == null)
|
||
|
|
{
|
||
|
|
Debug.LogError($"[table_gachareward] Failed to select reward for grade {grade}");
|
||
|
|
return (default(eMoney), 0, 0);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 보상 개수 랜덤
|
||
|
|
int count = Random.Range(selected.n_RewardMinCount, selected.n_RewardMaxCount + 1);
|
||
|
|
int lucky = Mathf.Max(1, (int)(count * selected.f_LuckyBonusRate));
|
||
|
|
|
||
|
|
return (selected.e_GachaRewardType, count, lucky);
|
||
|
|
}
|
||
|
|
}
|