159 lines
4.8 KiB
C#
159 lines
4.8 KiB
C#
using CodeStage.AntiCheat.ObscuredTypes;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
|
|
public class DropItemInfo : MonoBehaviourSingletonTemplate<DropItemInfo>
|
|
{
|
|
Dictionary<int, List<DropItem>> dic_dropitem = new Dictionary<int, List<DropItem>>();
|
|
Dictionary<int, AsyncOperationHandle<GameObject>> dic_Handle = new Dictionary<int, AsyncOperationHandle<GameObject>>();
|
|
Dictionary<int, string> dic_addrPath = new Dictionary<int, string>
|
|
{
|
|
{ -1, "Assets/Res_Addr/Obj/DropItem_Item.prefab" },
|
|
{ 2, "Assets/Res_Addr/Obj/DropItem_Coin.prefab" },
|
|
};
|
|
List<DropItem> list_dropitems = new List<DropItem>();
|
|
Dictionary<int, ObscuredInt> Mob = new Dictionary<int, ObscuredInt>();
|
|
Dictionary<int, ObscuredInt> Elite = new Dictionary<int, ObscuredInt>();
|
|
Dictionary<int, ObscuredInt> Boss = new Dictionary<int, ObscuredInt>();
|
|
|
|
public StageDropData m_StageDropData = new StageDropData();
|
|
|
|
private void Start()
|
|
{
|
|
Make_DropItem(-1, 2);
|
|
Make_DropItem(2, 30);
|
|
}
|
|
|
|
public void AllOff()
|
|
{
|
|
m_StageDropData.Init();
|
|
Mob.Clear();
|
|
Elite.Clear();
|
|
Boss.Clear();
|
|
|
|
foreach (var item in dic_dropitem)
|
|
for (int i = 0; i < item.Value.Count; i++)
|
|
item.Value[i].gameObject.SetActive(false);
|
|
}
|
|
|
|
public void Add_MobKill(eSubRol subRol, int id)
|
|
{
|
|
var mob = Mob;
|
|
switch (subRol)
|
|
{
|
|
case eSubRol.Elite: mob = Elite; break;
|
|
case eSubRol.Boss: mob = Boss; break;
|
|
}
|
|
if (!mob.ContainsKey(id))
|
|
mob.Add(id, 0);
|
|
++mob[id];
|
|
mob[id].RandomizeCryptoKey();
|
|
}
|
|
public Dictionary<int, ObscuredInt> Get_Mob() { return Mob; }
|
|
public Dictionary<int, ObscuredInt> Get_Elite() { return Elite; }
|
|
public Dictionary<int, ObscuredInt> Get_Boss() { return Boss; }
|
|
|
|
|
|
void Make_DropItem(int key, int count)
|
|
{
|
|
AddrResourceMgr.Ins.LoadObject<GameObject>(dic_addrPath[key], handle =>
|
|
{
|
|
if (handle.IsDone && handle.Status == AsyncOperationStatus.Succeeded)
|
|
{
|
|
dic_Handle.Add(key, handle);
|
|
dic_dropitem.Add(key, new List<DropItem> { DSUtil.Get_Clone<DropItem>(dic_Handle[key].Result, transform) });
|
|
for (int i = 0; i < count - 1; i++)
|
|
Get_DropItem(key);
|
|
}
|
|
});
|
|
}
|
|
|
|
DropItem Get_DropItem(int key)
|
|
{
|
|
var dropitem = DSUtil.Get_Clone<DropItem>(dic_Handle[key].Result, transform);
|
|
dropitem.gameObject.SetActive(false);
|
|
dic_dropitem[key].Add(dropitem);
|
|
return dropitem;
|
|
}
|
|
|
|
public void Drop_DropItem(int itemid, int amount, Vector3 startpos)
|
|
{
|
|
int index = -1;
|
|
var item = table_itemlist.Ins.Get_Data(itemid);
|
|
switch (item.n_ItemID)
|
|
{
|
|
case 2: index = item.n_ItemID; break;
|
|
}
|
|
|
|
if (dic_dropitem.ContainsKey(index))
|
|
{
|
|
for (int i = 0; i < dic_dropitem[index].Count; i++)
|
|
{
|
|
var temp = dic_dropitem[index][i];
|
|
if (!temp.gameObject.activeInHierarchy)
|
|
{
|
|
temp.Set(itemid, amount, startpos);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var dropitem = Get_DropItem(index);
|
|
dropitem.Set(itemid, amount, startpos);
|
|
}
|
|
}
|
|
|
|
public List<DropItem> Get_DropItems()
|
|
{
|
|
list_dropitems.Clear();
|
|
foreach (var itemList in dic_dropitem.Values)
|
|
{
|
|
list_dropitems.AddRange(itemList.FindAll(item => item.gameObject.activeInHierarchy));
|
|
}
|
|
return list_dropitems;
|
|
}
|
|
|
|
public DropItem Get_NearestDropItem(Vector3 _pos)
|
|
{
|
|
var items = Get_DropItems();
|
|
if (items.Count == 0)
|
|
return null;
|
|
|
|
DropItem nearestItem = items[0];
|
|
float minDistance = Vector3.Distance(_pos, nearestItem.transform.position);
|
|
|
|
foreach (var item in items)
|
|
{
|
|
float distance = Vector3.Distance(_pos, item.transform.position);
|
|
if (distance < minDistance)
|
|
{
|
|
minDistance = distance;
|
|
nearestItem = item;
|
|
}
|
|
}
|
|
return nearestItem;
|
|
}
|
|
}
|
|
|
|
public class StageDropData
|
|
{
|
|
public ObscuredUInt GetExp;
|
|
Dictionary<int, ObscuredInt> Item = new Dictionary<int, ObscuredInt>();
|
|
|
|
public void Init()
|
|
{
|
|
GetExp = 0;
|
|
GetExp.RandomizeCryptoKey();
|
|
Item.Clear();
|
|
}
|
|
|
|
public void Add_Item(int itemid, int count)
|
|
{
|
|
if (!Item.ContainsKey(itemid)) Item.Add(itemid, 0);
|
|
Item[itemid] += count;
|
|
Item[itemid].RandomizeCryptoKey();
|
|
}
|
|
public Dictionary<int, ObscuredInt> Get_Item() { return Item; }
|
|
} |