496 lines
15 KiB
C#
496 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Logic.Action;
|
|
using UnityEngine;
|
|
using RuntimeData;
|
|
using Logic.Multilingual;
|
|
using TMPro;
|
|
|
|
public enum CivEnum
|
|
{
|
|
Common = 0,
|
|
Egyptian = 1,
|
|
French = 2,
|
|
Germany = 3,
|
|
Indian = 4,
|
|
Norway = 5,
|
|
Britain = 6,
|
|
Persian = 7,
|
|
Byzantine = 8,
|
|
// --- 新增阵营 ---
|
|
Sumerian = 9, // 苏美尔
|
|
Mayan = 10, // 玛雅
|
|
Malian = 11, // 马里
|
|
Greek = 12, // 希腊
|
|
Khmer = 13, // 高棉
|
|
Aztec = 14, // 阿兹特克
|
|
Incan = 15, // 印加
|
|
Mongolian = 16, // 蒙古
|
|
Arabian = 17, // 阿拉伯
|
|
Max = 18
|
|
}
|
|
|
|
public enum ForceEnum
|
|
{
|
|
Common = 0,
|
|
Remilia = 1,
|
|
Kaguya = 2,
|
|
Kanako = 3,
|
|
Satori = 4,
|
|
Reimu = 5,
|
|
Byakuren = 6,
|
|
Miko = 7,
|
|
Zanmu = 8,
|
|
Yuyuko = 9,
|
|
Hecatia = 10,
|
|
Megumu = 11,
|
|
Cirno = 12,
|
|
Yorihime = 13,
|
|
Tenshi = 14,
|
|
Ubame = 15,
|
|
Seija = 16,
|
|
Marisa = 17,
|
|
Max = 0
|
|
}
|
|
|
|
[Serializable]
|
|
public struct Empire
|
|
{
|
|
public CivEnum Civ;
|
|
public ForceEnum Force;
|
|
|
|
public Empire(CivEnum civ, ForceEnum force)
|
|
{
|
|
Civ = civ;
|
|
Force = force;
|
|
}
|
|
|
|
public static bool operator ==(Empire a, Empire b)
|
|
{
|
|
return a.Civ == b.Civ && a.Force == b.Force;
|
|
}
|
|
public static bool operator !=(Empire a, Empire b)
|
|
{
|
|
return !(a == b);
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return obj is Empire other && this == other;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(Civ, Force);
|
|
}
|
|
}
|
|
|
|
public enum LandformType
|
|
{
|
|
Terrain,
|
|
Mountain,
|
|
Tree,
|
|
Road,
|
|
Resource,
|
|
Max
|
|
}
|
|
|
|
[Serializable]
|
|
[CreateAssetMenu(fileName = "PlayerDataAssets", menuName = "TH1 Game Data/Player Data Asset")]
|
|
public class PlayerDataAssets : ScriptableObject
|
|
{
|
|
public List<PlayerInfo> PlayerDataList = new List<PlayerInfo>();
|
|
public List<LandformPack> CivLandformList = new List<LandformPack>();
|
|
public Color CommonColor;
|
|
public Sprite CommonPlayerAvatar;
|
|
[MultilingualField]
|
|
public string CommonForceTitleText;
|
|
private Dictionary<UnitType,UnitTypeInfo> _unitTypeDict = new Dictionary<UnitType, UnitTypeInfo>();
|
|
private Dictionary<GiantType,UnitTypeInfo> _giantTypeDict = new Dictionary<GiantType, UnitTypeInfo>();
|
|
|
|
[NonSerialized]
|
|
private bool _initialized = false;
|
|
|
|
public bool GetPlayerInfo(PlayerData player,out PlayerInfo info)
|
|
{
|
|
info = null;
|
|
if (player == null)
|
|
return false;
|
|
foreach (var t in PlayerDataList)
|
|
{
|
|
if (t.CivId == player.PlayerCivId && t.ForceId == player.PlayerForceId)
|
|
{
|
|
info = t;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
public bool GetPlayerInfoByCivId(uint cid,uint forceid,out PlayerInfo info)
|
|
{
|
|
info = null;
|
|
foreach (var t in PlayerDataList)
|
|
{
|
|
if (t.CivId == cid && t.ForceId == forceid)
|
|
{
|
|
info = t;
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool GetPlayerInfo(CivEnum civ,ForceEnum force,out PlayerInfo info)
|
|
{
|
|
uint cid = Table.Instance.TransCivEnumToCivId(civ);
|
|
uint forceid = Table.Instance.TransForceEnumToForceId(force);
|
|
return GetPlayerInfoByCivId(cid,forceid,out info);
|
|
}
|
|
|
|
public bool GetPlayerInfo(Empire empire, out PlayerInfo info)
|
|
{
|
|
return GetPlayerInfo(empire.Civ, empire.Force, out info);
|
|
}
|
|
|
|
|
|
//判断一个action是否在一个玩家的techPool里面
|
|
public bool CheckActionInTechPool(CommonActionId actionId,PlayerData player)
|
|
{
|
|
if (!GetPlayerInfo(player, out var info)) return false;
|
|
foreach (var t in info.TechPool)
|
|
{
|
|
if(!Table.Instance.TechDataAssets.GetTechInfo(t,out var techInfo))continue;
|
|
var actionList = techInfo.GetActionList();
|
|
foreach(var a in actionList)
|
|
if (a == actionId)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// --------------------------------------------- 处理初始资源参数的模块 -------------------------------------
|
|
|
|
public bool GetCivLandformPack(CivEnum civ, out LandformPack info)
|
|
{
|
|
foreach(var t in CivLandformList)
|
|
if (t.civ == civ)
|
|
{
|
|
info = t;
|
|
return true;
|
|
}
|
|
|
|
info = null;
|
|
return false;
|
|
}
|
|
//terrain重载
|
|
public float GetLandformRate(TerrainType terrain, CivEnum civ)
|
|
{
|
|
var ret = 1f;
|
|
//if (tree != Vegetation.Trees) return 0;
|
|
return ret;
|
|
}
|
|
|
|
//tree重载(树占平地的比例)
|
|
public float GetLandformRate(Vegetation tree, CivEnum civ = CivEnum.Common)
|
|
{
|
|
if (tree != Vegetation.Trees) return 0f;
|
|
if (!GetCivLandformPack(civ,out var civInfo)) return 0f;
|
|
if (!GetCivLandformPack(CivEnum.Common,out var commonInfo)) return 0f;
|
|
if (!commonInfo.GetLandformRate(tree, InnerOuterCity.All,out var commonRate)) return 0f;
|
|
if (!civInfo.GetLandformRate(tree, InnerOuterCity.All,out var civRate)) return commonRate;
|
|
return commonRate * civRate;
|
|
}
|
|
|
|
//mountain重载 (山占所有陆地的比例)
|
|
public float GetLandformRate(TerrainFeature mountain, CivEnum civ = CivEnum.Common)
|
|
{
|
|
if (mountain != TerrainFeature.Mountain) return 0f;
|
|
if (!GetCivLandformPack(civ,out var civInfo)) return 0f;
|
|
if (!GetCivLandformPack(CivEnum.Common,out var commonInfo)) return 0f;
|
|
if (!commonInfo.GetLandformRate(mountain, InnerOuterCity.All,out var commonRate)) return 0f;
|
|
if (!civInfo.GetLandformRate(mountain, InnerOuterCity.All,out var civRate)) return commonRate;
|
|
return commonRate * civRate;
|
|
}
|
|
|
|
//animal/fruit/crop/metal重载(animal占森林的比例)
|
|
public float GetLandformRate(ResourceType resource, CivEnum civ = CivEnum.Common,InnerOuterCity innerOuterCity = InnerOuterCity.All)
|
|
{
|
|
if (!(resource is ResourceType.Animal or ResourceType.Metal or ResourceType.Crop or ResourceType.Farm or ResourceType.Fruit or ResourceType.Treasure or ResourceType.Starfish or ResourceType.Fish)) return 0f;
|
|
if (!GetCivLandformPack(civ,out var civInfo)) return 0f;
|
|
if (!GetCivLandformPack(CivEnum.Common,out var commonInfo)) return 0f;
|
|
if (!commonInfo.GetLandformRate(resource, innerOuterCity,out var commonRate)) return 0f;
|
|
//注意civInfo要传入 InnerOuterCity.All 因为不分内外城
|
|
if (!civInfo.GetLandformRate(resource, InnerOuterCity.All,out var civRate)) return commonRate;
|
|
return commonRate * civRate;
|
|
}
|
|
|
|
public bool GetLandformCount(TerrainType terrain, CivEnum civ,out int count)
|
|
{
|
|
count = 0;
|
|
if (terrain != TerrainType.Land) return false;
|
|
if (!GetCivLandformPack(civ, out var civInfo)) return false;
|
|
if (!civInfo.GetLandformCount(terrain, InnerOuterCity.InnerCity, out count)) return false;
|
|
return true;
|
|
}
|
|
|
|
//tree的城市保底数量
|
|
public bool GetLandformCount(Vegetation tree, CivEnum civ,out int count)
|
|
{
|
|
count = 0;
|
|
if (tree != Vegetation.Trees) return false;
|
|
if (!GetCivLandformPack(civ, out var civInfo)) return false;
|
|
if (!civInfo.GetLandformCount(tree, InnerOuterCity.InnerCity, out count)) return false;
|
|
return true;
|
|
}
|
|
|
|
//mountain的城市保底数量
|
|
public bool GetLandformCount(TerrainFeature mountain, CivEnum civ,out int count)
|
|
{
|
|
count = 0;
|
|
if (mountain != TerrainFeature.Mountain) return false;
|
|
if (!GetCivLandformPack(civ,out var civInfo)) return false;
|
|
if (!civInfo.GetLandformCount(mountain, InnerOuterCity.InnerCity,out count)) return false;
|
|
return true;
|
|
}
|
|
|
|
public bool GetLandformCount(ResourceType resource, CivEnum civ,InnerOuterCity innerOuterCity,out int count)
|
|
{
|
|
count = 0;
|
|
if (!(resource is ResourceType.Animal or ResourceType.Metal or ResourceType.Crop or ResourceType.Farm or ResourceType.Fruit or ResourceType.Fish)) return false;
|
|
if (!GetCivLandformPack(civ,out var civInfo)) return false;
|
|
if (!civInfo.GetLandformCount(resource, innerOuterCity,out count)) return false;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class PlayerInfo
|
|
{
|
|
public uint ForceId;
|
|
public uint CivId;
|
|
[MultilingualField]
|
|
public string CivName;
|
|
[MultilingualField]
|
|
public string ForceName;
|
|
[MultilingualField]
|
|
public string LeaderName;
|
|
public Sprite LeaderIllustration;
|
|
public Sprite LeaderAvatar;
|
|
public Sprite WinPic;
|
|
public Sprite LosePic;
|
|
public Sprite LoadingPic;
|
|
//public Sprite PopulationSprite;
|
|
public List<TechType> TechPool = new List<TechType>();
|
|
public List<TechType> TechStart = new List<TechType>();
|
|
public Color Color;
|
|
public Sprite FlagIcon;
|
|
public int Diff;
|
|
public List<TechAtom> TechAtomList;
|
|
[MultilingualField] public string EmpireDesc;
|
|
[MultilingualField] public string LeaderDesc;
|
|
[MultilingualField(false,true,false)]
|
|
public List<string> StartChatBubble;
|
|
[MultilingualField(false,true,false)]
|
|
public List<string> MeetChatBubble;
|
|
[MultilingualField(false,true,false)]
|
|
public List<string> LoseChatBubble;
|
|
[MultilingualField(false,true,false)]
|
|
public List<string> WinChatBubble;
|
|
|
|
|
|
public string MusicName;
|
|
|
|
|
|
|
|
PlayerInfo()
|
|
{
|
|
foreach (TechType t in System.Enum.GetValues(typeof(TechType)))
|
|
TechPool.Add(t);
|
|
TechStart.Add(TechType.None);
|
|
}
|
|
|
|
public string GetRandomMeetChat()
|
|
{
|
|
if (MeetChatBubble.Count > 0)
|
|
return MeetChatBubble[UnityEngine.Random.Range(0, MeetChatBubble.Count)];
|
|
else return "0";
|
|
|
|
}
|
|
|
|
public string GetSpeaker()
|
|
{
|
|
switch (ForceId)
|
|
{
|
|
case 0:
|
|
return nameof(GiantType.EgyptianRemilia);
|
|
case 1:
|
|
return nameof(GiantType.FrenchKaguya);
|
|
case 2:
|
|
return nameof(GiantType.GermanyKanako);
|
|
case 3:
|
|
return nameof(GiantType.IndianSatori);
|
|
case 4:
|
|
return "NorwayReimu";
|
|
case 5:
|
|
return "BritishByakuren";
|
|
case 6:
|
|
return "PersianMiko";
|
|
case 7:
|
|
return "ByzantineZanmu";
|
|
}
|
|
return nameof(GiantType.None);
|
|
}
|
|
|
|
public string GetRandomStartChat()
|
|
{
|
|
if (StartChatBubble.Count > 0)
|
|
return StartChatBubble[UnityEngine.Random.Range(0, StartChatBubble.Count)];
|
|
else return "0";
|
|
|
|
}
|
|
public string GetRandomLoseChat()
|
|
{
|
|
if (LoseChatBubble.Count > 0)
|
|
return LoseChatBubble[UnityEngine.Random.Range(0, LoseChatBubble.Count)];
|
|
else return "0";
|
|
|
|
}
|
|
|
|
public string GetRandomWinChat()
|
|
{
|
|
if (WinChatBubble.Count > 0)
|
|
return WinChatBubble[UnityEngine.Random.Range(0, WinChatBubble.Count)];
|
|
else return "0";
|
|
|
|
}
|
|
}
|
|
|
|
|
|
[Serializable]
|
|
public class LandformPack
|
|
{
|
|
public CivEnum civ;
|
|
public List<LandformParamItem> LandformParamList;
|
|
|
|
//tree重载(树占平地的比例)
|
|
public bool GetLandformRate(Vegetation tree,InnerOuterCity innerOuterCity ,out float rate)
|
|
{
|
|
foreach(var t in LandformParamList)
|
|
if (t.LandformType == LandformType.Tree && innerOuterCity == t.InnerOuterCity && !t.IsCountControl)
|
|
{
|
|
rate = t.Rate;
|
|
return true;
|
|
}
|
|
rate = 0f;
|
|
return false;
|
|
}
|
|
|
|
//mountain重载 (山占所有陆地的比例)
|
|
public bool GetLandformRate(TerrainFeature mountain, InnerOuterCity innerOuterCity,out float rate)
|
|
{
|
|
foreach(var t in LandformParamList)
|
|
if (t.LandformType == LandformType.Mountain && innerOuterCity == t.InnerOuterCity && !t.IsCountControl)
|
|
{
|
|
rate = t.Rate;
|
|
return true;
|
|
}
|
|
|
|
rate = 0f;
|
|
return false;
|
|
}
|
|
|
|
//animal/fruit/crop/metal重载(animal占森林的比例)
|
|
public bool GetLandformRate(ResourceType resource, InnerOuterCity innerOuterCity,out float rate)
|
|
{
|
|
foreach(var t in LandformParamList)
|
|
if (t.LandformType == LandformType.Resource && t.ResourceType == resource &&
|
|
innerOuterCity == t.InnerOuterCity && !t.IsCountControl)
|
|
{
|
|
rate = t.Rate;
|
|
return true;
|
|
}
|
|
rate = 0f;
|
|
return false;
|
|
}
|
|
|
|
|
|
public bool GetLandformCount(TerrainType terrain, InnerOuterCity innerOuterCity,out int count)
|
|
{
|
|
foreach(var t in LandformParamList)
|
|
if (t.LandformType == LandformType.Terrain && t.TerrainType == TerrainType.Land && innerOuterCity == t.InnerOuterCity && t.IsCountControl)
|
|
{
|
|
count = t.Count;
|
|
return true;
|
|
}
|
|
|
|
count = 0;
|
|
return false;
|
|
}
|
|
public bool GetLandformCount(ResourceType resource, InnerOuterCity innerOuterCity,out int count)
|
|
{
|
|
foreach(var t in LandformParamList)
|
|
if (t.LandformType == LandformType.Resource && t.ResourceType == resource && innerOuterCity == t.InnerOuterCity && t.IsCountControl)
|
|
{
|
|
count = t.Count;
|
|
return true;
|
|
}
|
|
|
|
count = 0;
|
|
return false;
|
|
}
|
|
//tree重载(树占平地的比例)
|
|
public bool GetLandformCount(Vegetation tree,InnerOuterCity innerOuterCity ,out int count)
|
|
{
|
|
foreach(var t in LandformParamList)
|
|
if (t.LandformType == LandformType.Tree && innerOuterCity == t.InnerOuterCity && t.IsCountControl)
|
|
{
|
|
count = t.Count;
|
|
return true;
|
|
}
|
|
count = 0;
|
|
return false;
|
|
}
|
|
public bool GetLandformCount(TerrainFeature mountain, InnerOuterCity innerOuterCity,out int count)
|
|
{
|
|
foreach(var t in LandformParamList)
|
|
if (t.LandformType == LandformType.Mountain && innerOuterCity == t.InnerOuterCity && t.IsCountControl)
|
|
{
|
|
count = t.Count;
|
|
return true;
|
|
}
|
|
|
|
count = 0;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public enum InnerOuterCity
|
|
{
|
|
All,//无视内外圈
|
|
InnerCity,//1圈领土
|
|
OuterCity,//2圈领土
|
|
Edge,//3圈及以外领土
|
|
Max
|
|
}
|
|
|
|
//单个的地貌数据参数,例如“少山的”“多山的”“多海的”之类的
|
|
[Serializable]
|
|
public class LandformParamItem
|
|
{
|
|
|
|
public LandformType LandformType;
|
|
public string ParamPackDesc;//这个parampack的描述信息
|
|
public TerrainType TerrainType;
|
|
public ResourceType ResourceType;
|
|
public float Rate;
|
|
public InnerOuterCity InnerOuterCity;
|
|
public bool IsCountControl;
|
|
public int Count;
|
|
|
|
} |