140 lines
4.1 KiB
C#
140 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using RuntimeData;
|
|
|
|
|
|
[Serializable]
|
|
[CreateAssetMenu(fileName = "GridAndResourceDataAssets", menuName = "TH1 Game Data/GridAndResource Data Asset")]
|
|
public class GridAndResourceDataAssets : ScriptableObject
|
|
{
|
|
public List<TerrainInfo> TerrainInfoList;
|
|
public List<ResourceInfo> ResourceInfoList;
|
|
public List<WonderInfo> WonderInfoList;
|
|
public MountainInfo MountainInfo;
|
|
public VegetationInfo VegetationInfo;
|
|
|
|
private Dictionary<ResourceType,ResourceInfo> _resourceInfoDict = new Dictionary<ResourceType, ResourceInfo>();
|
|
|
|
[NonSerialized]
|
|
private bool _initialized = false;
|
|
|
|
private void Init()
|
|
{
|
|
if (_initialized)
|
|
return;
|
|
foreach(var t in ResourceInfoList)
|
|
_resourceInfoDict[t.Resource] = t;
|
|
|
|
_initialized = true;
|
|
}
|
|
public bool GetResourceInfo(ResourceType resource, out ResourceInfo resourceInfo)
|
|
{
|
|
Init();
|
|
return _resourceInfoDict.TryGetValue(resource, out resourceInfo);
|
|
}
|
|
|
|
public bool GetWonderInfo(WonderTypeEnum wonder, out WonderInfo wonderInfo)
|
|
{
|
|
wonderInfo = null;
|
|
foreach(var t in WonderInfoList)
|
|
if (t.WonderType == wonder)
|
|
{
|
|
wonderInfo = t;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public Sprite GetWonderSprite(WonderTypeEnum wonder,PlayerData playerData)
|
|
{
|
|
if (!GetWonderInfo(wonder, out var wonderInfo))
|
|
return null;
|
|
foreach (var t in wonderInfo.SpriteList)
|
|
if ((t.IgnoreCivId || t.CivId == playerData.PlayerCivId)
|
|
&& (t.IgnoreForceId || t.ForceId == playerData.PlayerForceId))
|
|
return t.Sprite;
|
|
return null;
|
|
}
|
|
|
|
public string GetWonderName(WonderTypeEnum wonder,PlayerData playerData)
|
|
{
|
|
if (!GetWonderInfo(wonder, out var wonderInfo))
|
|
return "";
|
|
foreach (var t in wonderInfo.SpriteList)
|
|
if ((t.IgnoreCivId || t.CivId == playerData.PlayerCivId)
|
|
&& (t.IgnoreForceId || t.ForceId == playerData.PlayerForceId))
|
|
return t.Name;
|
|
return "";
|
|
}
|
|
|
|
public CivForceToSprite GetWonderSpriteAndName(WonderTypeEnum wonder,PlayerData playerData)
|
|
{
|
|
if (!GetWonderInfo(wonder, out var wonderInfo))
|
|
return null;
|
|
foreach (var t in wonderInfo.SpriteList)
|
|
if ((t.IgnoreCivId || t.CivId == playerData.PlayerCivId)
|
|
&& (t.IgnoreForceId || t.ForceId == playerData.PlayerForceId))
|
|
return t;
|
|
return null;
|
|
}
|
|
|
|
|
|
public ResourceType GetMillLikeRelative(ResourceType resource)
|
|
{
|
|
if (resource == ResourceType.Sawmill)
|
|
return ResourceType.LumberHut;
|
|
if (resource == ResourceType.Windmill)
|
|
return ResourceType.Farm;
|
|
if (resource == ResourceType.Forge)
|
|
return ResourceType.Mine;
|
|
if (resource == ResourceType.Mine)
|
|
return ResourceType.Forge;
|
|
if (resource == ResourceType.Farm)
|
|
return ResourceType.Windmill;
|
|
if (resource == ResourceType.LumberHut)
|
|
return ResourceType.Sawmill;
|
|
return ResourceType.None;
|
|
}
|
|
}
|
|
|
|
|
|
[Serializable]
|
|
public class TerrainInfo
|
|
{
|
|
public TerrainType TerrainType;
|
|
public Sprite Sprite;
|
|
public bool VarientSprite;
|
|
public List<CivForceToSprite> SpriteList;
|
|
}
|
|
|
|
[Serializable]
|
|
public class MountainInfo
|
|
{
|
|
public List<CivForceToSprite> SpriteList;
|
|
}
|
|
|
|
[Serializable]
|
|
public class VegetationInfo
|
|
{
|
|
public List<CivForceToSprite> SpriteList;
|
|
}
|
|
|
|
[Serializable]
|
|
public class ResourceInfo
|
|
{
|
|
public ResourceType Resource;
|
|
public Sprite Sprite;
|
|
public bool VarientSprite;
|
|
public int Exp;
|
|
public List<CivForceToSprite> SpriteList;
|
|
}
|
|
|
|
[Serializable]
|
|
public class WonderInfo
|
|
{
|
|
public WonderTypeEnum WonderType;
|
|
public List<CivForceToSprite> SpriteList;
|
|
public int Exp;
|
|
|
|
} |