Browse Source

地块生成上限算法修改

pull/76/head
45 1 year ago
parent
commit
5827875a3d
  1. 59
      ColorlessWorld-2024-4-2/Assets/Scripts/MapManager.cs
  2. 8
      ColorlessWorld-2024-4-2/Assets/StreamingAssets/LevelMapToItem.csv
  3. 7
      ColorlessWorld-2024-4-2/Assets/StreamingAssets/MapItemCount.csv

59
ColorlessWorld-2024-4-2/Assets/Scripts/MapManager.cs

@ -5,6 +5,7 @@ using UnityEngine;
using UnityEngine.Rendering.VirtualTexturing; using UnityEngine.Rendering.VirtualTexturing;
using UnityEngine.UI; using UnityEngine.UI;
using static GameManager; using static GameManager;
using static UnityEngine.Rendering.DebugUI;
public class MapManager : Singleton<MapManager> public class MapManager : Singleton<MapManager>
{ {
@ -621,26 +622,34 @@ public class MapManager : Singleton<MapManager>
HashSet<MapUnity> allNode = getNodeTools.getAllCanUseNode(); HashSet<MapUnity> allNode = getNodeTools.getAllCanUseNode();
//获取物品上限 //获取物品上限
List<string> itemLimitList = PlayerStatsManager.Instance.itemLimitDic[int.Parse(currentLevelData.mapIndex)]; List<string> totalInfor = PlayerStatsManager.Instance.itemLimitDic[30001];
string limitInfor=null ; string limitInfor=null ;
switch (currentLevelData.fightEenemyPool) switch (currentLevelData.fightEenemyPool)
{ {
case Name.EnemyPool.Weak: case Name.EnemyPool.Weak:
limitInfor =itemLimitList[0]; limitInfor = totalInfor[levelData_SO.mapLevel];
break; break;
case Name.EnemyPool.Strong: case Name.EnemyPool.Strong:
limitInfor = itemLimitList[1]; limitInfor = totalInfor[levelData_SO.mapLevel + 3];
break; break;
case Name.EnemyPool.Elite: case Name.EnemyPool.Elite:
limitInfor = itemLimitList[2]; limitInfor = totalInfor[levelData_SO.mapLevel + 6];
break; break;
case Name.EnemyPool.Boss: case Name.EnemyPool.Boss:
limitInfor = itemLimitList[3]; limitInfor = totalInfor[levelData_SO.mapLevel + 9];
break; break;
} }
string[] limitValue = limitInfor.Split(';'); string[] limitValue = limitInfor.Split(';');
int lowerLimit = int.Parse(limitValue[(levelData_SO.mapLevel - 1) * 2]); Debug.Log("随机数量限制" + limitInfor);
int maxLimit = int.Parse(limitValue[(levelData_SO.mapLevel - 1) * 2 + 1]); //地形区间
int lowerLandformLimit = int.Parse(limitValue[0]);
int maxLandformLimit = int.Parse(limitValue[1]);
//地块区间
int lowerLandblockLimit = int.Parse(limitValue[2]);
int maxLandblockLimit = int.Parse(limitValue[3]);
//物品区间
int lowerObjectItemLimit = int.Parse(limitValue[4]);
int maxObjectItemLimit = int.Parse(limitValue[5]);
//切分物品数据 //切分物品数据
List <string[]> itemInforStringList = new List <string[]>(); List <string[]> itemInforStringList = new List <string[]>();
@ -652,22 +661,34 @@ public class MapManager : Singleton<MapManager>
//随机物品数量并限制上限 //随机物品数量并限制上限
int count = 0; int count = 0;
List <int> itemCountList = new List <int>(); List <int> itemCountList = new List <int>();
while (count <100) while (count <100)
{ {
count++; count++;
int totalCount = 0; int landformCount = 0;
int blockCount = 0;
int objectCount = 0;
itemCountList.Clear(); itemCountList.Clear();
for (int i = 0; i < itemInforStringList.Count; i++) for (int i = 0; i < itemInforStringList.Count; i++)
{ {
int itemCount = Random.Range(int.Parse(itemInforStringList[i][1]), int.Parse(itemInforStringList[i][2])); int itemCount = Random.Range(int.Parse(itemInforStringList[i][2]), int.Parse(itemInforStringList[i][3])+1);
Debug.Log("Ëæ»ú" + itemInforStringList[i][0] + itemCount); Debug.Log("随机" + itemInforStringList[i][1] + itemCount);
if(itemInforStringList[i][0] != "Vacancy") switch (int.Parse ( itemInforStringList[i][0]))
{ {
totalCount += itemCount; case 1:
landformCount+=itemCount;
break;
case 2:
blockCount+=itemCount;
break;
case 3:
objectCount+=itemCount;
break;
} }
itemCountList.Add(itemCount); itemCountList.Add(itemCount);
} }
if(totalCount >=lowerLimit &&totalCount <=maxLimit ) if(Scope0fJudgment(lowerLandformLimit , maxLandformLimit , landformCount )&& Scope0fJudgment(lowerLandblockLimit, maxLandblockLimit, blockCount) && Scope0fJudgment(lowerObjectItemLimit, maxObjectItemLimit,objectCount))
{ {
Debug.Log("成功"); Debug.Log("成功");
break; break;
@ -676,7 +697,7 @@ public class MapManager : Singleton<MapManager>
//根据随机出的数量表生成物品 //根据随机出的数量表生成物品
for (int i=0;i< itemInforStringList.Count;i++) for (int i=0;i< itemInforStringList.Count;i++)
{ {
GameObject item = Resources.Load<GameObject>(itemPrefabPath + itemInforStringList[i][0]); GameObject item = Resources.Load<GameObject>(itemPrefabPath + itemInforStringList[i][1]);
int itemCount = itemCountList[i]; int itemCount = itemCountList[i];
for(int j=0;j<itemCount;j++) for(int j=0;j<itemCount;j++)
{ {
@ -704,6 +725,16 @@ public class MapManager : Singleton<MapManager>
yield return null; yield return null;
} }
public bool Scope0fJudgment(int min,int max,int value )
{
Debug.Log("随机判断" + "min:" + min + "max:" + max);
if(value >=min &&value <=max )
{
return true;
}
return false;
}
[System .Serializable ] [System .Serializable ]
public class EnemyGenerateData public class EnemyGenerateData
{ {

8
ColorlessWorld-2024-4-2/Assets/StreamingAssets/LevelMapToItem.csv

@ -1,5 +1,5 @@
地图编号,物品数据,,, 地图编号,物品数据,,,
100001,tree;0;2,boom;0;2,Whirlpool;0;2,Vacancy;0;5 100001,3;tree;0;1,3;boom;0;1,1;Whirlpool;0;2,2;Vacancy;0;5
100002,tree;0;2,boom;1;2,Whirlpool;0;2,Vacancy;0;4 100002,3;tree;0;1,3;boom;0;1,1;Whirlpool;0;2,2;Vacancy;0;4
100003,tree;0;2,boom;0;2,Whirlpool;0;2,Vacancy;1;5 100003,3;tree;0;1,3;boom;0;1,1;Whirlpool;0;2,2;Vacancy;1;5
100004,tree;0;2,boom;0;2,Whirlpool;0;2,Vacancy;2;8 100004,3;tree;0;1,3;boom;0;1,1;Whirlpool;0;2,2;Vacancy;2;8

Can't render this file because it has a wrong number of fields in line 2.

7
ColorlessWorld-2024-4-2/Assets/StreamingAssets/MapItemCount.csv

@ -1,5 +1,2 @@
地图编号,弱怪,强怪,精英,boss 地图编号,弱怪,,,强怪,,,精英,,,boss,,
100001,0;1;0;1;1;2,0;2;1;2;2;3,1;2;2;2;3;3,1;2;2;3;3;4 30001,0;1;0;1;0;1,0;1;0;1;0;1,1;2;1;1;1;1,0;2;0;1;0;1,1;2;1;2;1;2,2;3;2;3;2;3,1;2;1;2;1;2,2;2;2;2;2;2,3;3;3;3;3;3,1;2;1;2;1;2,2;3;2;3;2;3,3;4;3;4;3;4
100002,0;2;0;1;1;1,0;1;1;2;2;3,1;2;2;2;3;3,1;2;2;3;3;4
100003,0;1;0;1;1;1,0;1;1;2;2;3,1;2;2;2;3;3,1;2;2;3;3;4
100004,0;1;0;1;1;1,0;1;1;2;2;3,1;2;2;2;3;3,1;2;2;3;3;4

Can't render this file because it has a wrong number of fields in line 2.
Loading…
Cancel
Save