using CodeStage.AntiCheat.ObscuredTypes; using Newtonsoft.Json; using System.Collections.Generic; using UnityEngine; public class RewardRandomBagTableData : TableDataBase { public int n_ItemGrade; //e_ItemType ObscuredInt _DropIndex; public int n_DropIndex { get { return _DropIndex; } set { _DropIndex = value; _DropIndex.RandomizeCryptoKey(); } } ObscuredInt _ItemId; public int n_ItemId { get { return _ItemId; } set { _ItemId = value; _ItemId.RandomizeCryptoKey(); } } ObscuredInt _DropRate; public int n_DropRate { get { return _DropRate; } set { _DropRate = value; _DropRate.RandomizeCryptoKey(); } } ObscuredInt _DropCountMin; public int n_DropCountMin { get { return _DropCountMin; } set { _DropCountMin = value; _DropCountMin.RandomizeCryptoKey(); } } ObscuredInt _DropCountMax; public int n_DropCountMax { get { return _DropCountMax; } set { _DropCountMax = value; _DropCountMax.RandomizeCryptoKey(); } } public int Get_Count() { return Random.Range(n_DropCountMin, n_DropCountMax + 1); } } public class table_RewardRandomBag : table_base { public static table_RewardRandomBag Ins; List tableDatas; Dictionary> dic_Datas = new Dictionary>(); protected override void Awake() { Ins = this; base.Awake(); } protected override void Start() { tableDatas = JsonConvert.DeserializeObject>(json_last); for (int i = 0; i < tableDatas.Count; i++) { var temp = tableDatas[i]; if (!dic_Datas.ContainsKey(temp.n_DropIndex)) dic_Datas.Add(temp.n_DropIndex, new List()); dic_Datas[temp.n_DropIndex].Add(temp); } base.Start(); } public List Get_DataList() { return tableDatas; } public List Get_Datas(int index) { return dic_Datas[index]; } public ItemSimpleData Get_Reward(int index) { if (dic_Datas.ContainsKey(index)) { var lst = dic_Datas[index]; if (lst == null || lst.Count == 0) { Popup.Ins.Set($"랜덤백 ID({index})에 설정된 아이템이 없습니다."); return new ItemSimpleData(); } // 전체 확률 합계 구하기 int totalWeight = 0; for (int i = 0; i < lst.Count; i++) totalWeight += lst[i].n_DropRate; if (totalWeight <= 0) { Popup.Ins.Set($"랜덤백 ID({index})에 설정된 가중치가 없습니다."); return new ItemSimpleData(); } // 랜덤값 추출 (1 ~ totalWeight) int rand = Random.Range(1, totalWeight + 1); // 가중치에 따라 선택 int cumulative = 0; for (int i = 0; i < lst.Count; i++) { cumulative += lst[i].n_DropRate; if (rand <= cumulative) { if (table_ItemList.Ins.Get_Data_orNull(lst[i].n_ItemId) == null) Popup.Ins.Set($"랜덤백에 설정된 아이템 ID({lst[i].n_ItemId})는 아이템 테이블에 없는 아이템입니다."); return new ItemSimpleData { itemid = lst[i].n_ItemId, amount = lst[i].Get_Count() }; } } } Popup.Ins.Set($"랜덤백 ID({index})는 테이블에 없습니다."); return new ItemSimpleData(); } }