Commit 49c72235 authored by 18김상언's avatar 18김상언

드랍 아이템 데이터 파싱하는 LoadDropTable 다시한번 수정함

parent 7e47c8c8
......@@ -6,7 +6,7 @@ using System.Text;
public class EnemyManager : Singleton<EnemyManager>
{
// static variable
// static variable
// about action
public enum State
{
......@@ -21,27 +21,15 @@ public class EnemyManager : Singleton<EnemyManager>
LegendaryAdd }
public delegate void Action();
// about drop item
public struct DropItemInfo
{
public readonly int id;
public readonly float prob;
public DropItemInfo(int inputID, float inputProb)
{
id = inputID;
prob = inputProb;
}
}
// data
// data
// dictionary
public readonly Dictionary<int, DropItemInfo> dropTableByID;
public readonly Dictionary<int, Dictionary<ItemType, int>> dropTableByID;
public readonly Dictionary<int, Dictionary<State, Action>> actionDictByID;
// method
// method
// constructor
protected EnemyManager()
{
......@@ -49,7 +37,6 @@ public class EnemyManager : Singleton<EnemyManager>
string actionTableDataPath = "";
LoadDropTable(dropTableDataPath);
LoadActionTable(actionTableDataPath);
}
// Load Dictionary
......@@ -59,6 +46,7 @@ public class EnemyManager : Singleton<EnemyManager>
string[] cellValue = null;
string tableLine = null;
strReader.ReadLine();
Dictionary<ItemType, int> dropItemInfo = new Dictionary<ItemType, int>();
while ((tableLine = strReader.ReadLine()) != null)
{
......@@ -66,67 +54,46 @@ public class EnemyManager : Singleton<EnemyManager>
cellValue = tableLine.Split(',');
int monsterID = -1;
int itemID = -1;
float prob = -1.0f;
int.TryParse(cellValue[0], out monsterID);
int.TryParse(cellValue[2], out itemID);
float.TryParse(cellValue[3], out prob);
DropItemInfo dropItemInfo = new DropItemInfo(itemID, prob);
dropTableByID.Add(monsterID, dropItemInfo);
}
}
private void EnemyItemList(string dataPath)
{
StreamReader strReader = new StreamReader(dataPath, Encoding.UTF8);
string[] cellValue = null;
string tableLine = null;
strReader.ReadLine();
while ((tableLine = strReader.ReadLine()) != null) return;
{
cellValue = tableLine.Split(',');
// 여기에 dic 쓰고
int enemyID = -1;
float[] parseData = new float[Enum.GetValues(typeof(ItemType)).Length];
int[] weight = {-1};
int sum = 0;
int[] cumulatedWeight = { -1 };
int.TryParse(cellValue[0], out enemyID);
for (int i = 0; i < parseData.Length; i++)
for(int i=1;i<17;i++)
{
float.TryParse(cellValue[i + 1], out parseData[i]);
// dic.add 여기에 쓰고
int.TryParse(cellValue[i+1], out weight[i]);
}
//지금 쓰인 경우가 EnemyManager 자체에서 아이템 선택하는 경우
float nRnd = UnityEngine.Random.Range(0, 1);
ItemType dropItem = ItemType.None;
float prob = parseData[(int)ItemType.None];
for(int i=0;i<parseData.Length;i++)
{
if (parseData[i] > nRnd)
for(int i=0;i<16;i++)
{
dropItem = (ItemType)i;
prob = parseData[i];
break;
}
nRnd -= parseData[i];
sum += weight[i];
cumulatedWeight[i] = sum;
}
/* 이 경우가 데이터만 파싱할때인데
* 그럴려면 dropTableByID가 Dictionary<int, Dictionary<ItemList, float>> 형태가 돼야함
Dictionary<ItemList, float> dic = new Dictionary<ItemList, float>();
for (int i = 0; i < parseData.Length; i++) {
dic.Add((ItemList)i, parseData[i]);
for(int i=0;i<16;i++)
{
dropItemInfo.Add((ItemType)i, cumulatedWeight[i]);
}
dropTableByID.Add(enemyID, dic);
*/
dropTableByID.Add(enemyID, dropItemInfo);
}
}
private void LoadActionTable(string dataPath)
// Load ALL CSV Data
private void LoadEnemyData(string dataPath)
{
StreamReader strReader = new StreamReader(dataPath, Encoding.UTF8);
string[] cellValue = null;
string tableLine = null;
strReader.ReadLine();
while ((tableLine = strReader.ReadLine()) != null)
{
cellValue = tableLine.Split(',');
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment