65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
|
|
using GUPS.AntiCheat.Protected;
|
||
|
|
using Newtonsoft.Json;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
|
||
|
|
public class gacharateconfigtabledata
|
||
|
|
{
|
||
|
|
protected ProtectedInt32 _n_GachaGrade;
|
||
|
|
public int n_GachaGrade
|
||
|
|
{
|
||
|
|
get { return _n_GachaGrade; }
|
||
|
|
set { _n_GachaGrade = value; _n_GachaGrade.Obfuscate(); }
|
||
|
|
}
|
||
|
|
|
||
|
|
protected ProtectedInt32 _n_GachaGradeRate;
|
||
|
|
public int n_GachaGradeRate
|
||
|
|
{
|
||
|
|
get { return _n_GachaGradeRate; }
|
||
|
|
set { _n_GachaGradeRate = value; _n_GachaGrade.Obfuscate(); }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class table_gacharateconfig : table_base
|
||
|
|
{
|
||
|
|
public static table_gacharateconfig Ins;
|
||
|
|
|
||
|
|
List<gacharateconfigtabledata> tableDatas;
|
||
|
|
|
||
|
|
protected override void Awake()
|
||
|
|
{
|
||
|
|
Ins = this;
|
||
|
|
base.Awake();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void Start()
|
||
|
|
{
|
||
|
|
tableDatas = JsonConvert.DeserializeObject<List<gacharateconfigtabledata>>(json_last);
|
||
|
|
base.Start();
|
||
|
|
}
|
||
|
|
|
||
|
|
public gacharateconfigtabledata Get_RadomData()
|
||
|
|
{
|
||
|
|
if (tableDatas == null || tableDatas.Count == 0)
|
||
|
|
return null;
|
||
|
|
|
||
|
|
int totalRate = 0;
|
||
|
|
foreach (var data in tableDatas)
|
||
|
|
{
|
||
|
|
totalRate += data.n_GachaGradeRate;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 1 ~ totalRate 사이 난수 생성
|
||
|
|
int rand = UnityEngine.Random.Range(1, totalRate + 1);
|
||
|
|
|
||
|
|
int cumulative = 0;
|
||
|
|
foreach (var data in tableDatas)
|
||
|
|
{
|
||
|
|
cumulative += data.n_GachaGradeRate;
|
||
|
|
if (rand <= cumulative)
|
||
|
|
return data;
|
||
|
|
}
|
||
|
|
|
||
|
|
// fallback (논리상 여기 안 옴)
|
||
|
|
return tableDatas[tableDatas.Count - 1];
|
||
|
|
}
|
||
|
|
}
|