2025-10-16 21:08:40 +08:00

289 lines
7.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using Logic.Action;
using UnityEngine;
using Logic.Multilingual;
using RuntimeData;
//Data Asset用到绝对不能修改顺序
public enum TechType
{
None,
Climbing,Meditation,Mining,Philosophy,Smithery,
Organization,Strategy,Farming,Diplomacy,Construction,
Riding,FreeSpirit,Chivalry,Roads,Trade,
Hunting,Forestry,Archery,Mathematics,Spiritualism,
Fishing,Ramming,Sailing,Aquatism,Navigation,
EgyptFlandre,EgyptRemilia,EgyptMeiling,EgyptPatchouli,EgyptSakuya,
//Kaguya新增
KaguyaHunting,KaguyaArcher,KaguyaSpiritual,KaguyaForestry,KaguyaMath,KaguyaRoad,KaguyaTrade,KaguyaConstruction,
//Remilia新增
NoUseRemiliaConstruction,RemiliaFarming,NoUseRemiliaAuatism,RemiliaRamming,NoUseRemiliaChivalry,RemiliaFreeSpirit
}
//Data Asset用到绝对不能修改顺序
public enum TechAtom
{
None,
//None科技12个
CommonUnitUpgrade,
CommonUnitRecover,
CommonUnitExamine,
CommonUnitCapture,
CommonTrainWarrior,
BuildWonderPEACE,
BuildWonderKNOWLEDGE,
BuildWonderTRADE,
BuildWonderWEALTH,
BuildWonderPOWER,
BuildWonderPARK,
BuildWonderEYE,
//Climbing
UnitSkillMOUNTAINMOVE,
UnitSkillMOUNTAINDEFENSE,
//Climbing
BuildAcademy,
StartWonderPEACE,
BuildMine,
StartWonderKNOWLEDGE,
TechIndustry,
TrainUnitMinder,
TrainUnitSwordsman,
BuildForge,
GainFruit,
TrainUnitDefender,
TechAlly,
BuildFarm,
TechEmbassy,
TechDiplomacySight,
TrainUnitCloak,
BuildWindmill,
BurnForest,
TrainUnitRider,
BuildMilitary,
Disband,
BuildRoad,
BuildBridge,
StartWonderTRADE,
TrainUnitKnights,
Destroy,
BuildMarket,
StartWonderWEALTH,
GainAnimal,
BuildLumberHut,
ClearForest,
TrainUnitArcher,
UnitSKillFORESTDEFENSE,
BuildSawmill,
TrainUnitCatapult,
BuildPreserve,
GrowForest,
GainFish,
BuildPort,
UnitSkillWATERMOVE,
BuildNavalBase,
TrainUnitRammerShip,
TrainUnitShip,
UnitSkillOCEANMOVE,
UnitSkillWATERDEFENSE,
UnitSkillOCEANDEFENSE,
TrainUnitBomberShip,
UnitActionGather,
KaguyaFrenchNapoleanic,
TrainUnitKaguyaFrenchAnimalWarrior,
UnitSkillKaguyaFrenchWarriorSynergy,
KaguyaFrenchNapoleonicCode,
GrowForestOutside,
BuildKaguyaFrenchYard,
UnitSkillKaguyaFrenchCatapultSynergy,
KaguyaFrenchBambooMove,
//RemiliaFroces
BuildEgyptianIrrigation,
BuildRemiliaMilitary,
UnitSkillRemiliaForcesKill,
BuildEgyptianWaterIrrigation,
}
[Serializable]
[CreateAssetMenu(fileName = "TechDataAssets", menuName = "TH1 Game Data/Tech Data Asset")]
public class TechDataAssets : ScriptableObject
{
public List<TechInfo> TechList = new List<TechInfo>();
public List<TechAtomInfo> TechAtomList = new List<TechAtomInfo>();
[NonSerialized]
private bool _initialized;
private Dictionary<TechType, TechInfo> _techInfoDict = new Dictionary<TechType, TechInfo>();
[NonSerialized] private bool _atomInit;
private Dictionary<TechAtom, TechAtomInfo> _techAtomInfoDict = new Dictionary<TechAtom, TechAtomInfo>();
private void Init()
{
if (_initialized)
return;
foreach (var tech in TechList)
_techInfoDict.Add(tech.TechType,tech);
_initialized = true;
}
//-------------------------------------- TechInfo相关 --------------------------------
public TechInfo GetTechInfo(TechType techType)
{
Init();
return _techInfoDict.GetValueOrDefault(techType);
}
public bool GetTechInfo(TechType techType,out TechInfo info)
{
Init();
return _techInfoDict.TryGetValue(techType, out info);
}
public bool GetTechDesc(TechType techType, out string ret)
{
Init();
ret = "";
if (_techInfoDict.TryGetValue(techType, out var info))
{
ret = info.Description;
return true;
}
return false;
}
// 获取科技的所有后继科技 (非伟人科技)
public HashSet<TechType> GetNextTechs(TechType techType)
{
var nextTechs = new HashSet<TechType>(){techType};
while (GetNextTechs(techType, nextTechs)) { }
nextTechs.Remove(techType);
return nextTechs;
}
// 获取科技的后继科技
public bool GetNextTechs(TechType techType, HashSet<TechType> set)
{
bool isFound = false;
//遍历所有科技
foreach (var techInfo in TechList)
{
//如果已经在set 跳过
if (set.Contains(techInfo.TechType)) continue;
//如果他的父亲不在set里,跳过
if (!techInfo.FatherInSet(set)) continue;
//剩下的一定是父亲在set里或者父亲就是后继树根节点(techType)的节点加入set
set.Add(techInfo.TechType);
isFound = true;
}
return isFound;
}
//-------------------------------------- TechAtomInfo相关 --------------------------------
private void AtomInit()
{
if (_atomInit)
return;
foreach (var techAtomInfo in TechAtomList)
_techAtomInfoDict.Add(techAtomInfo.TechAtom,techAtomInfo);
_atomInit = true;
}
public bool GetTechAtomInfo(TechAtom techAtom, out TechAtomInfo info )
{
AtomInit();
return _techAtomInfoDict.TryGetValue(techAtom,out info);
}
}
[Serializable]
public class TechAtomInfo
{
public TechAtom TechAtom;
//是否是生产unit的时候AddSkill的技能
public bool IsAddSkill;
public List<UnitFullType> AddSkillCondition;
public SkillType AddSkillType;
public bool EnableAction;
public List<CommonActionId> TechActions;
}
[Serializable]
public class TechInfo
{
public TechType TechType; // 唯一ID
[MultilingualField]
public string TechName; // 显示名称
[MultilingualField]
public string Description; // 描述
public Sprite icon; // 图标
public int CostLevel; // 消耗等级(1,2,3)
public List<TechType> FatherTechList;
public List<CommonActionId> techActions; // 解锁action
public List<TechAtom> TechAtomList; // 解锁action
public bool FatherInSet(HashSet<TechType> set)
{
foreach (var tech in FatherTechList)
if (set.Contains(tech))
return true;
return false;
}
public bool IsFather(TechType techType)
{
foreach(var tech in FatherTechList)
if (tech == techType)
return true;
return false;
}
public int GetTechAtomCount()
{
int ret = techActions.Count;
foreach (var t in TechAtomList)
{
if (!Table.Instance.TechDataAssets.GetTechAtomInfo(t, out var info))
{
Debug.Log($"Wrong Get TechAtomInfo With {t}");
continue;
}
if (info.EnableAction)
ret += info.TechActions.Count;
}
return ret;
}
}