245 lines
6.8 KiB
C#
245 lines
6.8 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Runtime.CompilerServices;
|
||
using Logic.Multilingual;
|
||
using UnityEngine;
|
||
using RuntimeData;
|
||
using Unity.VisualScripting;
|
||
|
||
|
||
public enum WonderLibrary
|
||
{
|
||
EgyptianRemiliaPEACE,
|
||
EgyptianRemiliaKNOWLEDGE,
|
||
EgyptianRemiliaTRADE,
|
||
EgyptianRemiliaWEALTH,
|
||
EgyptianRemiliaPOWER,
|
||
EgyptianRemiliaPARK,
|
||
EgyptianRemiliaEYE,
|
||
RrenchKaguyaPEACE,
|
||
RrenchKaguyaKNOWLEDGE,
|
||
RrenchKaguyaTRADE,
|
||
RrenchKaguyaWEALTH,
|
||
RrenchKaguyaPOWER,
|
||
RrenchKaguyaPARK,
|
||
RrenchKaguyaEYE,
|
||
GermanyKanakoPEACE,
|
||
GermanyKanakoKNOWLEDGE,
|
||
GermanyKanakoTRADE,
|
||
GermanyKanakoWEALTH,
|
||
GermanyKanakoPOWER,
|
||
GermanyKanakoPARK,
|
||
GermanyKanakoEYE,
|
||
IndianSatoriPEACE,
|
||
IndianSatoriKNOWLEDGE,
|
||
IndianSatoriTRADE,
|
||
IndianSatoriWEALTH,
|
||
IndianSatoriPOWER,
|
||
IndianSatoriPARK,
|
||
IndianSatoriEYE,
|
||
NorwayReimuPEACE,
|
||
NorwayReimuKNOWLEDGE,
|
||
NorwayReimuTRADE,
|
||
NorwayReimuWEALTH,
|
||
NorwayReimuPOWER,
|
||
NorwayReimuPARK,
|
||
NorwayReimuEYE,
|
||
BritishByakurenPEACE,
|
||
BritishByakurenKNOWLEDGE,
|
||
BritishByakurenTRADE,
|
||
BritishByakurenWEALTH,
|
||
BritishByakurenPOWER,
|
||
BritishByakurenPARK,
|
||
BritishByakurenEYE,
|
||
PersianMikoPEACE,
|
||
PersianMikoKNOWLEDGE,
|
||
PersianMikoTRADE,
|
||
PersianMikoWEALTH,
|
||
PersianMikoPOWER,
|
||
PersianMikoPARK,
|
||
PersianMikoEYE,
|
||
ByzantineZanmuPEACE,
|
||
ByzantineZanmuKNOWLEDGE,
|
||
ByzantineZanmuTRADE,
|
||
ByzantineZanmuWEALTH,
|
||
ByzantineZanmuPOWER,
|
||
ByzantineZanmuPARK,
|
||
ByzantineZanmuEYE
|
||
}
|
||
|
||
|
||
[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;
|
||
|
||
public 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(WonderLibrary wonder, out WonderInfo wonderInfo)
|
||
{
|
||
wonderInfo = null;
|
||
foreach(var t in WonderInfoList)
|
||
if (t.Wonder == wonder)
|
||
{
|
||
wonderInfo = t;
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
public bool GetWonderInfoByType(WonderTypeEnum wonder,PlayerData player, out WonderInfo wonderInfo)
|
||
{
|
||
wonderInfo = null;
|
||
foreach(var t in WonderInfoList)
|
||
if (t.WonderType == wonder && t.CivId == player.PlayerCivId && t.ForceId == player.PlayerForceId)
|
||
{
|
||
wonderInfo = t;
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
|
||
|
||
public Sprite GetWonderSprite(WonderLibrary wonder,PlayerData playerData)
|
||
{
|
||
if (!GetWonderInfo(wonder, out var wonderInfo))
|
||
return null;
|
||
return wonderInfo.Sprite;
|
||
}
|
||
|
||
public Sprite GetResourceSprite(ResourceType resource, PlayerData playerData,GridData gridData = null)
|
||
{
|
||
if (resource == ResourceType.Temple)
|
||
{
|
||
Debug.Log("!");
|
||
}
|
||
if (!GetResourceInfo(resource, out var resourceInfo))
|
||
return null;
|
||
if (resourceInfo.VarientSprite)
|
||
{
|
||
foreach(var t in resourceInfo.SpriteList)
|
||
{
|
||
if ((t.IgnoreCivId || t.CivId == playerData.PlayerCivId)
|
||
&& (t.IgnoreForceId || t.ForceId == playerData.PlayerForceId))
|
||
{
|
||
if (!t.HasLevel || gridData == null) return t.Sprite;
|
||
//如果是拥有level的建筑,还要根据level返回
|
||
return t.LevelSprite[gridData.buildingLevel];
|
||
}
|
||
|
||
}
|
||
}
|
||
return resourceInfo.Sprite;
|
||
}
|
||
|
||
public string GetWonderName(WonderLibrary wonder,PlayerData playerData)
|
||
{
|
||
if (!GetWonderInfo(wonder, out var wonderInfo))
|
||
return "";
|
||
return wonderInfo.Name;
|
||
}
|
||
|
||
public string GetResourceName(ResourceType resource)
|
||
{
|
||
|
||
if (!_resourceInfoDict.TryGetValue(resource, out var resourceInfo))
|
||
{
|
||
Debug.Log("Error In GetResourceName , " + resource);
|
||
return "Error In GetResourceName";
|
||
}
|
||
|
||
|
||
return resourceInfo.ResourceName;
|
||
}
|
||
|
||
|
||
|
||
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;
|
||
|
||
[MultilingualField]
|
||
public string ResourceName;
|
||
public int Exp;
|
||
public List<CivForceToSprite> SpriteList;
|
||
}
|
||
|
||
[Serializable]
|
||
public class WonderInfo
|
||
{
|
||
public WonderLibrary Wonder;
|
||
public WonderTypeEnum WonderType;
|
||
public uint CivId;
|
||
public uint ForceId;
|
||
public Sprite Sprite;
|
||
[MultilingualField]
|
||
public string Name;
|
||
public int Exp;
|
||
|
||
} |