466 lines
15 KiB
C#
466 lines
15 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Runtime.CompilerServices;
|
||
using Logic.CrashSight;
|
||
using Logic.Multilingual;
|
||
using ParadoxNotion;
|
||
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 GetVegetationInfo(out VegetationInfo vegetationInfo)
|
||
{
|
||
vegetationInfo = VegetationInfo;
|
||
return true;
|
||
}
|
||
|
||
public bool GetMountainInfo(out MountainInfo mountainInfo)
|
||
{
|
||
mountainInfo = MountainInfo;
|
||
return true;
|
||
}
|
||
|
||
public bool GetTerrainInfo(TerrainType terrainType, out TerrainInfo terrainInfo)
|
||
{
|
||
terrainInfo = null;
|
||
foreach (var info in TerrainInfoList)
|
||
if (info.TerrainType == terrainType)
|
||
{
|
||
terrainInfo = info;
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
//获得一个varientResource的name和desc
|
||
public void GetResourceVarientInfo(ResourceType resource, PlayerData playerData,GridData gridData,out string name,out string desc)
|
||
{
|
||
name = "";
|
||
desc = "";
|
||
if (!GetResourceInfo(resource, out var resourceInfo)) return;
|
||
uint cid = playerData?.PlayerCivId ?? 0;
|
||
uint forceid = playerData?.PlayerForceId ?? 0;
|
||
//如果是remilia 特别类,过一遍remilia的滤网,优先级更高
|
||
if (gridData.HasSpType(GridSpType.RemiliaGrid))
|
||
{
|
||
if(resource == ResourceType.Animal || resource == ResourceType.Fruit )
|
||
foreach(var t in resourceInfo.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.RemiliaGrid)
|
||
{
|
||
name = t.Name;
|
||
desc = t.Desc;
|
||
return;
|
||
}
|
||
}
|
||
|
||
//如果是kaguya 特别类,过一遍kaguya的滤网
|
||
if (gridData.HasSpType(GridSpType.KaguyaGrid))
|
||
{
|
||
if(resource == ResourceType.Animal || resource == ResourceType.Fruit )
|
||
foreach(var t in resourceInfo.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.KaguyaGrid)
|
||
{
|
||
name = t.Name;
|
||
desc = t.Desc;
|
||
return;
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
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 GetMountainSprite(GridData grid)
|
||
{
|
||
if (grid.Feature != TerrainFeature.Mountain) return null;
|
||
if (!GetMountainInfo(out var info)) return null;
|
||
//如果是remilia 特别类,先过一遍remilia的滤网,优先级高于kaguya
|
||
if (grid.HasSpType(GridSpType.RemiliaGrid))
|
||
foreach (var t in info.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.RemiliaGrid)
|
||
return t.Sprite;
|
||
//如果是kaguya 特别类,先过一遍kaguya的滤网
|
||
if (grid.HasSpType(GridSpType.KaguyaGrid))
|
||
foreach (var t in info.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.KaguyaGrid)
|
||
return t.Sprite;
|
||
foreach (var t in info.SpriteList)
|
||
if (grid.CivId == t.CivId)
|
||
return t.Sprite;
|
||
return null;
|
||
}
|
||
|
||
public Sprite GetTerrainSprite(GridData grid)
|
||
{
|
||
if (!GetTerrainInfo(grid.Terrain,out var info)) return null;
|
||
if (!info.VarientSprite)
|
||
return info.Sprite;
|
||
|
||
//如果是remilia 特别类,先过一遍remilia的滤网,优先级高于kaguya
|
||
if (grid.HasSpType(GridSpType.RemiliaGrid))
|
||
foreach (var t in info.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.RemiliaGrid)
|
||
return t.Sprite;
|
||
//如果是kaguya 特别类,先过一遍kaguya的滤网
|
||
if (grid.HasSpType(GridSpType.KaguyaGrid))
|
||
foreach (var t in info.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.KaguyaGrid)
|
||
return t.Sprite;
|
||
|
||
|
||
|
||
foreach (var t in info.SpriteList)
|
||
if (grid.CivId == t.CivId)
|
||
return t.Sprite;
|
||
return info.Sprite;
|
||
}
|
||
|
||
public Sprite GetGroundSprite(CivEnum civEnum, GridSpType gridSpType)
|
||
{
|
||
foreach (var t in TerrainInfoList)
|
||
{
|
||
if (t.TerrainType == TerrainType.Land)
|
||
{
|
||
foreach(var p in t.SpriteList)
|
||
if (Table.Instance.TransCivIdToCivEnum(p.CivId) == civEnum && p.GridSpType == gridSpType)
|
||
{
|
||
return p.Sprite;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
public Sprite GetVegetationSprite(GridData grid)
|
||
{
|
||
if (grid.Vegetation != Vegetation.Trees) return null;
|
||
if (!GetVegetationInfo(out var info)) return null;
|
||
//如果是remilia 特别类,先过一遍remilia的滤网,优先级高于kaguya
|
||
if (grid.HasSpType(GridSpType.RemiliaGrid))
|
||
foreach (var t in info.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.RemiliaGrid)
|
||
return t.Sprite;
|
||
|
||
//如果是kaguya 特别类,先过一遍kaguya的滤网
|
||
if (grid.HasSpType(GridSpType.KaguyaGrid))
|
||
foreach (var t in info.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.KaguyaGrid)
|
||
return t.Sprite;
|
||
foreach (var t in info.SpriteList)
|
||
if (grid.CivId == t.CivId)
|
||
return t.Sprite;
|
||
return null;
|
||
}
|
||
|
||
public Sprite GetResourceSprite(ResourceType resource, PlayerData playerData,GridData gridData,bool mirror = false)
|
||
{
|
||
if (!GetResourceInfo(resource, out var resourceInfo))
|
||
return null;
|
||
uint cid = playerData?.PlayerCivId ?? 0;
|
||
uint forceid = playerData?.PlayerForceId ?? 0;
|
||
//如果是remilia 特别类,先过一遍remilia的滤网,优先级高于kaguya
|
||
if (gridData.HasSpType(GridSpType.RemiliaGrid))
|
||
{
|
||
if(resource == ResourceType.Animal)
|
||
foreach(var t in resourceInfo.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.RemiliaGrid)
|
||
return t.Sprite;
|
||
if(resource == ResourceType.Fruit)
|
||
foreach(var t in resourceInfo.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.RemiliaGrid)
|
||
return t.Sprite;
|
||
}
|
||
|
||
//如果是kaguya 特别类,过一遍kaguya的滤网
|
||
if (gridData.HasSpType(GridSpType.KaguyaGrid))
|
||
{
|
||
if(resource == ResourceType.Animal)
|
||
foreach(var t in resourceInfo.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.KaguyaGrid)
|
||
return t.Sprite;
|
||
if(resource == ResourceType.Fruit)
|
||
foreach(var t in resourceInfo.SpriteList)
|
||
if (t.IsGridSpType && t.GridSpType == GridSpType.KaguyaGrid)
|
||
return t.Sprite;
|
||
}
|
||
|
||
//如果是通用sprite且有mirror
|
||
if (!resourceInfo.VarientSprite && mirror)
|
||
{
|
||
if (resourceInfo.HasMirror) return resourceInfo.MirrorSprite;
|
||
return resourceInfo.Sprite;
|
||
}
|
||
//如果是根据等级或者种族变化的
|
||
if (resourceInfo.CivIdForceIdNotFromPlayer)
|
||
cid = gridData?.CivId ?? 0;
|
||
if (resourceInfo.VarientSprite)
|
||
{
|
||
foreach(var t in resourceInfo.SpriteList)
|
||
{
|
||
if ((t.IgnoreCivId || t.CivId == cid)
|
||
&& (t.IgnoreForceId || t.ForceId == forceid))
|
||
{
|
||
if (!t.HasLevel || gridData == null) return t.Sprite;
|
||
//如果是拥有level的建筑,还要根据level返回
|
||
if (t.LevelSprite.Count == 0)
|
||
{
|
||
LogSystem.LogError($"LevelSprite Count is 0 {gridData.Resource} : {gridData.buildingLevel}");
|
||
return null;
|
||
}
|
||
if (gridData.buildingLevel < 0)
|
||
{
|
||
LogSystem.LogError($"building Level < 0 {gridData.Resource} : {gridData.buildingLevel}");
|
||
return null;
|
||
}
|
||
if (gridData.buildingLevel >= t.LevelSprite.Count)
|
||
{
|
||
LogSystem.LogError($"gridData BuildingLevel Overflow {gridData.Resource} : {gridData.buildingLevel}");
|
||
return t.LevelSprite[0];
|
||
}
|
||
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;
|
||
[MultilingualField]
|
||
public string ResourceName;
|
||
[MultilingualField]
|
||
public string ResourceDesc;
|
||
public List<CivForceToSprite> SpriteList;
|
||
}
|
||
|
||
[Serializable]
|
||
public class MountainInfo
|
||
{
|
||
[MultilingualField]
|
||
public string ResourceName;
|
||
[MultilingualField]
|
||
public string ResourceDesc;
|
||
public List<CivForceToSprite> SpriteList;
|
||
}
|
||
|
||
[Serializable]
|
||
public class VegetationInfo
|
||
{
|
||
[MultilingualField]
|
||
public string ResourceName;
|
||
[MultilingualField]
|
||
public string ResourceDesc;
|
||
public List<CivForceToSprite> SpriteList;
|
||
}
|
||
|
||
[Serializable]
|
||
public class ResourceInfo
|
||
{
|
||
public ResourceType Resource;
|
||
public Sprite Sprite;
|
||
[MultilingualField]
|
||
public string ResourceName;
|
||
[MultilingualField]
|
||
public string ResourceDesc;
|
||
public int Exp;
|
||
|
||
//如果是神像,确定是什么棋子类型
|
||
public ChessType ChessType;
|
||
//动物、植物、土地这些 不从player读取civid和forceid的情况
|
||
public bool CivIdForceIdNotFromPlayer;
|
||
//每个城市只能有一个
|
||
public bool HasLevel;
|
||
public int MaxLevel;
|
||
public int CityExpPerLevel;
|
||
public bool HasMirror;
|
||
public Sprite MirrorSprite;
|
||
public bool VarientSprite;
|
||
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;
|
||
|
||
} |