You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
362 lines
11 KiB
362 lines
11 KiB
using LitJson; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using UnityEngine; |
|
|
|
|
|
[System.Serializable] |
|
public class Tile |
|
{ |
|
public int x; |
|
public int y; |
|
public MapTile.Type type; |
|
public string obstacle = string.Empty; |
|
public int angle; |
|
|
|
static public Tile Create(Vector2 idx, MapTile.Type type, string obstacle, int angle) |
|
{ |
|
Tile data = new Tile(); |
|
|
|
data.x = (int)idx.x; |
|
data.y = (int)idx.y; |
|
data.type = type; |
|
data.obstacle = obstacle; |
|
data.angle = angle; |
|
|
|
return data; |
|
} |
|
|
|
static public string JsonCreate(List<Tile> tiles) |
|
{ |
|
return JsonMapper.ToJson(tiles); |
|
} |
|
static public List<Tile> JsonLoad(string json) |
|
{ |
|
return JsonMapper.ToObject<List<Tile>>(json); |
|
} |
|
} |
|
[System.Serializable] |
|
public class TileData |
|
{ |
|
public List<bool> typeApply; |
|
public List<bool> typeDoors; |
|
public List<Tile> tileDatas; |
|
} |
|
|
|
[System.Serializable] |
|
public class FloorData |
|
{ |
|
public float rateMax = 0.3f; |
|
[Space(10)] |
|
public GameObject blkNameEmpty; |
|
[Space(10)] |
|
public int cntDefault; |
|
public int cntMonster; |
|
public List<GameObject> blkNameDefault = new List<GameObject>(); |
|
public List<string> mobAppear = new List<string>(); |
|
public AppearList MonsterAppearGet() |
|
{ |
|
return DataManager.Instance.dataMonsterAppear.AppearListGet(mobAppear[Random.Range(0, mobAppear.Count)]); |
|
} |
|
/// <summary> |
|
/// 생성 되어야 할 블럭의 타입 리스트를 넘깁니다. |
|
/// 빈블럭 (cntDefault - cntMonster - 1)개, 몬스터블럭 (cntMonster)개, 보스블럭 1개 |
|
/// </summary> |
|
/// <returns></returns> |
|
public List<MapBlock.Type> DefaultTypeGet() |
|
{ |
|
List<MapBlock.Type> types = new List<MapBlock.Type>(); |
|
|
|
types.AddRange(Enumerable.Repeat<MapBlock.Type>(MapBlock.Type.None, cntDefault - cntMonster).ToList<MapBlock.Type>()); |
|
types.AddRange(Enumerable.Repeat<MapBlock.Type>(MapBlock.Type.Monster, cntMonster).ToList<MapBlock.Type>()); |
|
types = Util.ListShuffle<MapBlock.Type>.Shuffle(types); |
|
|
|
//types.Add(MapBlock.Type.Boss); |
|
|
|
return types; |
|
} |
|
|
|
//public int cntWave; |
|
[Space(10)] |
|
public int cntWaveMin; |
|
public int cntWaveMax; |
|
public int WaveCountGet() |
|
{ |
|
return Random.Range(cntWaveMin, cntWaveMax); |
|
} |
|
public List<GameObject> blkNameWave = new List<GameObject>(); |
|
public List<string> waveAppear = new List<string>(); |
|
public void WaveAppearGet(List<AppearList> waveAppsers) |
|
{ |
|
waveAppsers.Clear(); |
|
for (int i = 0; i < waveAppear.Count; i++) |
|
waveAppsers.Add(DataManager.Instance.dataMonsterAppear.AppearListGet(waveAppear[i])); |
|
} |
|
|
|
[Space(10)] |
|
public int cntBoss; |
|
public List<GameObject> blkNameBoss = new List<GameObject>(); |
|
public string bossAppear; |
|
public AppearList BossAppearGet() |
|
{ |
|
return DataManager.Instance.dataMonsterAppear.AppearListGet(bossAppear); |
|
} |
|
public List<string> bossInferior = new List<string>(); |
|
public AppearList BossInferiorGet() |
|
{ |
|
return DataManager.Instance.dataMonsterAppear.AppearListGet(bossInferior[Random.Range(0, bossInferior.Count)]); |
|
} |
|
|
|
//public int cntBossMini; |
|
[Space(10)] |
|
public int cntMiniMin; |
|
public int cntMiniMax; |
|
public int MiniCountGet() |
|
{ |
|
return Random.Range(cntMiniMin, cntMiniMax); |
|
} |
|
public List<GameObject> blkNameBossMini = new List<GameObject>(); |
|
public string miniAppear; |
|
public AppearList MiniAppearGet() |
|
{ |
|
return DataManager.Instance.dataMonsterAppear.AppearListGet(miniAppear); |
|
} |
|
public List<string> miniInferior = new List<string>(); |
|
public AppearList MiniInferiorGet() |
|
{ |
|
return DataManager.Instance.dataMonsterAppear.AppearListGet(miniInferior[Random.Range(0, miniInferior.Count)]); |
|
} |
|
|
|
[Space(10)] |
|
public int cntShopMin; |
|
public int cntShopMax; |
|
public int ShopCountGet() |
|
{ |
|
return Random.Range(cntShopMin, cntShopMax); |
|
} |
|
public List<GameObject> blkNameShop = new List<GameObject>(); |
|
public int productCnt = 3; |
|
public int productTierMin = 0; |
|
public int productTierMax = 999; |
|
|
|
[Space(10)] |
|
public int cntHidden; |
|
public List<GameObject> blkNameHidden = new List<GameObject>(); |
|
|
|
public FloorData() |
|
{ |
|
} |
|
public FloorData(string[] spl) |
|
{ |
|
int i = 1; |
|
|
|
cntDefault = int.Parse(spl[i++]); |
|
cntMonster = int.Parse(spl[i++]); |
|
string[] value = spl[i++].Split('|'); |
|
for (int j = 0; j < value.Length; j++) |
|
mobAppear.Add(value[j]); |
|
|
|
cntWaveMin = int.Parse(spl[i++]); |
|
cntWaveMax = int.Parse(spl[i++]); |
|
value = spl[i++].Split('|'); |
|
for (int j = 0; j < value.Length; j++) |
|
waveAppear.Add(value[j]); |
|
|
|
cntBoss = int.Parse(spl[i++]); |
|
bossAppear = spl[i++]; |
|
value = spl[i++].Split('|'); |
|
for (int j = 0; j < value.Length; j++) |
|
bossInferior.Add(value[j]); |
|
|
|
cntMiniMin = int.Parse(spl[i++]); |
|
cntMiniMax = int.Parse(spl[i++]); |
|
miniAppear = spl[i++]; |
|
value = spl[i++].Split('|'); |
|
for (int j = 0; j < value.Length; j++) |
|
miniInferior.Add(value[j]); |
|
|
|
cntShopMin = int.Parse(spl[i++]); |
|
cntShopMax = int.Parse(spl[i++]); |
|
value = spl[i++].Split(':'); |
|
string[] value2 = value[0].Split('~'); |
|
productCnt = int.Parse(value[1]); |
|
productTierMin = int.Parse(value2[0]); |
|
productTierMax = int.Parse(value2[1]); |
|
|
|
cntHidden = int.Parse(spl[i++]); |
|
} |
|
|
|
/// <summary> |
|
/// 생성 되어야 할 특수블럭의 타입 리스트를 넘깁니다. |
|
/// </summary> |
|
/// <param name="SHUFFLE"></param> |
|
/// <returns></returns> |
|
public List<MapBlock.Type> SpecialTypeGet() |
|
{ |
|
List<MapBlock.Type> types = new List<MapBlock.Type>(); |
|
types.AddRange(Enumerable.Repeat<MapBlock.Type>(MapBlock.Type.Hidden, cntHidden).ToList<MapBlock.Type>()); |
|
types.AddRange(Enumerable.Repeat<MapBlock.Type>(MapBlock.Type.Mini, MiniCountGet()).ToList<MapBlock.Type>()); |
|
types.AddRange(Enumerable.Repeat<MapBlock.Type>(MapBlock.Type.Shop, ShopCountGet()).ToList<MapBlock.Type>()); |
|
types.AddRange(Enumerable.Repeat<MapBlock.Type>(MapBlock.Type.Wave, WaveCountGet()).ToList<MapBlock.Type>()); |
|
|
|
types = Util.ListShuffle<MapBlock.Type>.Shuffle(types); |
|
|
|
return types; |
|
} |
|
/// <summary> |
|
/// 생성 되는 블럭의 프리팹을 넘깁니다. |
|
/// blkName{?} 리스트에 이름 목록 중 1개의 프리팹, 없을 경우는 어쩔? |
|
/// </summary> |
|
/// <param name="type"></param> |
|
/// <returns></returns> |
|
public GameObject PrefabGet(MapBlock.Type type) |
|
{ |
|
return blkNameEmpty; |
|
|
|
List<GameObject> names = null; |
|
|
|
switch (type) |
|
{ |
|
case MapBlock.Type.Empty: |
|
return blkNameEmpty; |
|
case MapBlock.Type.None: |
|
case MapBlock.Type.Monster: |
|
names = blkNameDefault; |
|
break; |
|
case MapBlock.Type.Boss: |
|
names = blkNameBoss; |
|
break; |
|
case MapBlock.Type.Hidden: |
|
names = blkNameHidden; |
|
break; |
|
case MapBlock.Type.Mini: |
|
names = blkNameBossMini; |
|
break; |
|
case MapBlock.Type.Shop: |
|
names = blkNameShop; |
|
break; |
|
case MapBlock.Type.Wave: |
|
names = blkNameWave; |
|
break; |
|
} |
|
|
|
return names[Random.Range(0, names.Count)]; |
|
} |
|
|
|
public void LoadAll(string thema) |
|
{ |
|
blkNameDefault.Clear(); |
|
blkNameBoss.Clear(); |
|
blkNameBossMini.Clear(); |
|
blkNameHidden.Clear(); |
|
blkNameShop.Clear(); |
|
blkNameWave.Clear(); |
|
|
|
GameObject[] all = Resources.LoadAll<GameObject>($"Prefab/Map/{thema}"); |
|
for (int i = 0; i < all.Length; i++) |
|
{ |
|
string[] spl = all[i].name.Split(' '); |
|
try |
|
{ |
|
MapBlock.Type type = Util.EnumUtil<MapBlock.Type>.Parse(spl[1]); |
|
|
|
switch (type) |
|
{ |
|
case MapBlock.Type.Empty: |
|
blkNameEmpty = all[i]; |
|
break; |
|
case MapBlock.Type.Monster: |
|
blkNameDefault.Add(all[i]); |
|
break; |
|
case MapBlock.Type.Boss: |
|
blkNameBoss.Add(all[i]); |
|
break; |
|
case MapBlock.Type.Mini: |
|
blkNameBossMini.Add(all[i]); |
|
break; |
|
case MapBlock.Type.Hidden: |
|
blkNameHidden.Add(all[i]); |
|
break; |
|
case MapBlock.Type.Shop: |
|
blkNameShop.Add(all[i]); |
|
break; |
|
case MapBlock.Type.Wave: |
|
blkNameWave.Add(all[i]); |
|
break; |
|
} |
|
} |
|
catch |
|
{ |
|
Debug.LogError($"Dungeon Undefined Type -> {all[i].name}"); |
|
} |
|
} |
|
} |
|
} |
|
|
|
[System.Serializable] |
|
public class DataDungeon : IData |
|
{ |
|
public string dungeon; |
|
public List<FloorData> floors = new List<FloorData>(); |
|
public List<TileData> tiles = new List<TileData>(); |
|
|
|
public override void TableLoad() |
|
{ |
|
floors.Clear(); |
|
Debug.LogWarning($"{path} Floor"); |
|
string[] strLine = FileLoadWithLineSplit($"{path} Floor"); |
|
string[] spl; |
|
for (int i = 1; i < strLine.Length; i++) |
|
{ |
|
if (1 < strLine[i].Length) |
|
{ |
|
spl = strLine[i].Split(','); |
|
floors.Add(new FloorData(spl)); |
|
} |
|
} |
|
|
|
tiles.Clear(); |
|
strLine = FileLoadWithLineSplit($"{path} Tile"); |
|
for (int i = 0; i < strLine.Length; i++) |
|
{ |
|
if (1 < strLine[i].Length) |
|
{ |
|
TileData data = JsonMapper.ToObject<TileData>(strLine[i]); |
|
tiles.Add(data); |
|
} |
|
} |
|
} |
|
public override void LoadedCheck() |
|
{ |
|
; |
|
} |
|
|
|
public DataDungeon Load(string dungeon) |
|
{ |
|
this.dungeon = dungeon; |
|
path = $"Prefab/Map/{dungeon}/{dungeon}"; |
|
TableLoad(); |
|
|
|
return this; |
|
} |
|
|
|
public List<TileData> TileGet(MapBlock.Type type, List<MapDoor> doors) |
|
{ |
|
List<TileData> datas = tiles.FindAll((a) => |
|
{ |
|
if (!a.typeApply[(int)type]) |
|
return false; |
|
|
|
for (int i = 0; i < a.typeDoors.Count; i++) |
|
{ |
|
if (!a.typeDoors[i] && doors[i] != null) |
|
return false; |
|
} |
|
|
|
return true; |
|
}); |
|
|
|
return datas; |
|
} |
|
}
|
|
|