UGCProjects/GZJ/Script/Manager/GameDataManager.lua
2025-01-08 22:46:12 +08:00

505 lines
16 KiB
Lua
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.

--[[------------------------------------------游戏数据管理中心------------------------------------------------------]]--
GameDataManager = GameDataManager or {}
GameDataManager.HasInitialized = false
--[[------------------------------------------动态数据------------------------------------------------------]]--
--游戏准备阶段配置表
GameDataManager.GameReadyStageConfigTable = {}
--技能配置表
GameDataManager.SkillConfigTable = {}
--武器初始化表
GameDataManager.WeaponConstructTable = {}
--物品初始化表
GameDataManager.ItemConfigTable = {}
--物品模型表
GameDataManager.ItemMeshConfigTable = {}
--怪物信息表(已分类)
GameDataManager.MonsterBaseConfigTable = {}
--结算数据仅用于Client
GameDataManager.GameResultData = {}
-- 表示视觉效果的全局ID
GameDataManager.EffectInstanceId = 0
--[[------------------------------------------常用指针------------------------------------------------------]]--
--当前PlayerState 仅用于Client
GameDataManager.OwnerPlayerState = nil
--当前PlayerController 仅用于Client
GameDataManager.OwnerPlayerController = nil
GameDataManager.CommonAttackWaveList = {}
function GameDataManager:Init()
if GameDataManager.HasInitialized then
return
end
self:LoadGameReadyStageConfigTable()
self:LoadSkillConfigTable()
self:LoadWeaponConstructTable()
self:LoadItemConfigTable()
self:LoadMonsterBaseConfigTable()
GameDataManager.InitCommonAttackWaveList()
GameDataManager.HasInitialized = true
end
function GameDataManager:UnInit()
GameDataManager.MonsterBaseConfigTable = nil
GameDataManager.ItemConfigTable = nil
GameDataManager.ItemMeshConfigTable = nil
GameDataManager.GameReadyStageConfigTable = nil
GameDataManager.SkillConfigTable = nil
GameDataManager.WeaponConstructTable = nil
GameDataManager.GameResultData = nil
GameDataManager.OwnerPlayerState = nil
GameDataManager.OwnerPlayerController = nil
end
function GameDataManager.GetEffectInstanceId()
GameDataManager.EffectInstanceId = GameDataManager.EffectInstanceId + 1
return GameDataManager.EffectInstanceId
end
function GameDataManager:LoadGameReadyStageConfigTable()
GameDataManager.GameReadyStageConfigTable = CSVLoader.LoadTable("CSV/GameReadyStageConfigTable", nil)
table.sort(GameDataManager.GameReadyStageConfigTable, function(a, b) return a.Stage < b.Stage end)
for i, v in pairs(GameDataManager.GameReadyStageConfigTable) do
UE.Log("[CSV][GameReadyStageConfig] 游戏准备阶段配置: Index = %d, Stage = %d, WaitTime = %.2f", i, v.Stage, v.WaitTime)
end
end
function GameDataManager:LoadSkillConfigTable()
local SkillConfig = require("Script.SimpleSkill.SkillConfig")
GameDataManager.SkillConfigTable = SkillConfig
for i, v in pairs(GameDataManager.SkillConfigTable) do
UE.Log("[CSV][SkillConfig] 技能参数配置: SkillName = %s, Desc = %s", i, v.Description)
end
end
function GameDataManager:LoadWeaponConstructTable()
GameDataManager.WeaponConstructTable = CSVLoader.LoadTable("CSV/WeaponAppearanceTable", nil)
for i, v in pairs(GameDataManager.WeaponConstructTable) do
UE.Log("[CSV][WeaponConstruct] 武器初始化配置: WeaponID = %s, WeaponName = %s", i, v.WeaponName)
end
end
function GameDataManager:LoadItemConfigTable()
local ItemDataConfigTable = CSVLoader.LoadTable("CSV/ItemDataConfigTable", "ItemID")
GameDataManager.ItemMeshConfigTable = Tables.ItemMeshConfig
GameDataManager.ItemConfigTable = ItemDataConfigTable
for i, v in pairs(GameDataManager.ItemConfigTable) do
UE.Log("[CSV][ItemConfig] 道具配置: ItemID = %s, ItemType = %s", i, v.ItemType)
end
end
function GameDataManager:LoadMonsterBaseConfigTable()
local InfoTable = {}
for MonsterID, MonsterConfig in pairs(Tables.MonsterBaseConfig) do
if InfoTable[MonsterConfig.Type] == nil then
InfoTable[MonsterConfig.Type] = {}
end
table.insert(InfoTable[MonsterConfig.Type], MonsterConfig)
end
GameDataManager.MonsterBaseConfigTable = InfoTable
end
function GameDataManager.GetItemMeshPathByItemType(InItemType, WeaponClassType)
local MeshPath = GameDataManager.ItemMeshConfigTable[InItemType]
if MeshPath == nil then
return nil
end
if WeaponClassType == nil then
return KismetSystemLibrary.MakeSoftObjectPath(MeshPath)
end
return KismetSystemLibrary.MakeSoftObjectPath(MeshPath[WeaponClassType])
end
function GameDataManager.GetItemInfoByItemID(InItemID)
--首先获取各种类型
--操作一下Id
if DropItemConfigTable.Items[InItemID] ~= nil then
return DropItemConfigTable.Items[InItemID]
end
InItemID = InItemID // 100 * 100
if DropItemConfigTable.Items[InItemID] ~= nil then
return DropItemConfigTable.Items[InItemID]
end
local ItemType = GetItemTypeByItemId(InItemID)
if DropItemConfigTable.Items[ItemType] ~= nil then
return DropItemConfigTable.Items[ItemType + 1]
end
-- 这个就是具体的大类
local val = InItemID // 1000 * 1000
if ItemType == EItemType.SkillBook then
val = 21000
end
if DropItemConfigTable.Items[val] ~= nil then
return DropItemConfigTable.Items[val]
end
print("[GameDataManager.GetItemInfoByItemID] 查看是否其他方式进行找到对应数据的,通过现有的方法无法找到")
return nil
end
function GameDataManager.GetItemIconByItemID(InItemID)
return GameDataManager.GetItemInfoByItemID(InItemID).Icon
end
function GameDataManager.GetItemDescByItemID(InItemID)
InItemID = InItemID - InItemID % 1000
return GameDataManager.ItemConfigTable[InItemID].Desc
end
function GameDataManager.GetItemNameByItemID(InItemID)
end
function GameDataManager.GetItemTypeByItemID(InItemID)
InItemID = InItemID - InItemID % 1000
return GameDataManager.ItemConfigTable[InItemID].ItemType
end
function GameDataManager.GetGameReadyStageConfig()
if table.isEmpty(GameDataManager.GameReadyStageConfigTable) then
GameDataManager:LoadGameReadyStageConfigTable()
end
return GameDataManager.GameReadyStageConfigTable
end
function GameDataManager.GetGameReadyStageInfoByStage(InStage)
if table.isEmpty(GameDataManager.GameReadyStageConfigTable) then
GameDataManager:LoadGameReadyStageConfigTable()
end
for _, v in pairs(GameDataManager.GameReadyStageConfigTable) do
if v.Stage == InStage then
return v
end
end
return nil
end
function GameDataManager.GetWeaponMeshInfo(ID)
local WeaponConstructData = GameDataManager.GetWeaponConstructDataByID(ID)
if WeaponConstructData then
return WeaponConstructData.MeshConfig
end
return nil
end
function GameDataManager.GetWeaponIcon(ID)
local WeaponConstructData = GameDataManager.GetWeaponConstructDataByID(ID)
if WeaponConstructData then
return WeaponConstructData.Icon
end
return nil
end
function GameDataManager.GetWeaponType(ID)
local WeaponConstructData = GameDataManager.GetWeaponConstructDataByID(ID)
if WeaponConstructData then
return WeaponConstructData.WeaponType
end
return nil
end
function GameDataManager.GetSkillData(SkillName)
if table.isEmpty(GameDataManager.SkillConfigTable) then
GameDataManager:LoadSkillConfigTable()
end
for i, v in pairs(GameDataManager.SkillConfigTable) do
if tonumber(i) == tonumber(SkillName) then
UE.Log("[GameDataManager][GetSkillData] find skillname: InSkillName = %s", tostring(SkillName))
return v
end
end
UE.Log("[GameDataManager][GetSkillData] can't find skill: InSkillName = %s", tostring(SkillName))
return nil
end
function GameDataManager.GetSkillTypeByName(SkillName)
if table.isEmpty(GameDataManager.SkillConfigTable) then
GameDataManager:LoadSkillConfigTable()
end
for i, v in pairs(GameDataManager.SkillConfigTable) do
if tonumber(i) == tonumber(SkillName) then
UE.Log("[GameDataManager][GetSkillTypeByName] skillname = %d, Find SkillType=%d", SkillName, v.SkillType)
return v.SkillType
end
end
UE.Log("[GameDataManager][GetSkillTypeByName] skillname = %d, cant Find SkillType", SkillName)
return nil
end
function GameDataManager.GetSkillNamesByAccessType(InAccessType)
if InAccessType > ESkillAccessType.Acquired or InAccessType < ESkillAccessType.BuiltIn then
return {}
end
if table.isEmpty(GameDataManager.SkillConfigTable) then
GameDataManager:LoadSkillConfigTable()
end
local SkillNames = {}
for SkillName, SkillConfig in pairs(GameDataManager.SkillConfigTable) do
if SkillConfig.SkillAccess == InAccessType then
table.insert(SkillNames, SkillName)
end
end
return SkillNames
end
function GameDataManager.GetSkillDescByName(SkillName)
local SkillInfo = GlobalConfigs.SkillInfo[SkillName]
if SkillInfo then
return SkillInfo.Desc
end
return ""
end
function GameDataManager.GetTalentSkillShortDescByName(SkillName)
local SkillInfo = GlobalConfigs.SkillInfo[SkillName]
if SkillInfo then
local ShortDesc = SkillInfo.ShortDesc
return ShortDesc or ""
end
return ""
end
function GameDataManager.GetSkillNameStrByName(SkillName)
local SkillInfo = GlobalConfigs.SkillInfo[SkillName]
if SkillInfo then
return SkillInfo.Name
end
return ""
end
function GameDataManager.GetSkillIconPathByName(SkillName)
local SkillInfo = GlobalConfigs.SkillInfo[SkillName]
local IconIndex = -1
if SkillInfo then
IconIndex = SkillInfo.IconIndex
end
if IconIndex <= 0 then
return ""
end
return UGCGameSystem.GetUGCResourcesFullPath(string.format('Asset/IconTexture/Role_Icon/Textures/Icon_UGC_role_%02d.Icon_UGC_role_%02d', IconIndex, IconIndex))
end
function GameDataManager.GetWeaponConstructDataByID(ID)
if table.isEmpty(GameDataManager.WeaponConstructTable) then
GameDataManager:LoadWeaponConstructTable()
end
local WeaponConstructData = GameDataManager.WeaponConstructTable[ID]
if WeaponConstructData then
return WeaponConstructData
end
UE.Log("[GameDataManager][GetWeaponConstructDataByID] ID = %s, Failed", tostring(ID))
return nil
end
function GameDataManager.GetMonsterTypeByID(InID)
local MonsterInfo = Tables.MonsterBaseConfig[InID]
if MonsterInfo then
return MonsterInfo.Type
end
return EMonsterType.Default
end
function GameDataManager.GetRandCommonMonsterClass()
return GameDataManager.GetRandMonsterClassByType(EMonsterType.Common)
end
function GameDataManager.InitCommonAttackWaveList()
local TempCommonAttackWave = TableHelper.DeepCopy(Tables.CommonAttackWave)
table.sort(TempCommonAttackWave, function (CommonAttackWave1, CommonAttackWave2) return CommonAttackWave1.Order < CommonAttackWave2.Order end)
local TempAttackWave = 1
for k, v in pairs(TempCommonAttackWave) do
for i = 1 ,TempCommonAttackWave[k].AttackWaveNumber do
GameDataManager.CommonAttackWaveList[TempAttackWave] = TempCommonAttackWave[k].CommonID
print("InitCommonAttackWaveList_TempAttackWave " .. TempAttackWave .." CommonID " .. TempCommonAttackWave[k].CommonID)
TempAttackWave = TempAttackWave + 1
end
end
end
function GameDataManager.GetAttackWaveCommonMonsterClass()
local MonsterClass = nil
if GameDataManager.CommonAttackWaveList[UGCGameSystem.GameState.CurAttackWave] then
local MonsterPath = Tables.MonsterBaseConfig[GameDataManager.CommonAttackWaveList[UGCGameSystem.GameState.CurAttackWave]].Path
MonsterClass = UE.LoadClass(MonsterPath)
UE.Log("GetAttackWaveCommonMonsterClass_Succeed")
else
MonsterClass = GameDataManager.GetRandCommonMonsterClass()
UE.Log("[Error] GameDataManager.GetAttackWaveCommonMonsterClass CommonAttackWaveList: %d is nil", UGCGameSystem.GameState.CurAttackWave)
end
return MonsterClass
end
function GameDataManager.GetRandBossMonsterClass()
if GameDataManager.BossIndex == nil then
GameDataManager.BossIndex = 0
end
GameDataManager.BossIndex = GameDataManager.BossIndex + 1
local CurBossID = UGCGameSystem.GameState.BossList[GameDataManager.BossIndex]
return GameDataManager.GetMonsterClassByID(CurBossID)
end
function GameDataManager.GetRandHangupMonsterClass()
return GameDataManager.GetRandMonsterClassByType(EMonsterType.HangupRoom)
end
function GameDataManager.GetRandBreachMonsterClass()
return GameDataManager.GetRandMonsterClassByType(EMonsterType.Breach)
end
function GameDataManager.GetRandMonsterClassByType(InMonsterType)
if table.isEmpty(GameDataManager.MonsterBaseConfigTable) then
GameDataManager:LoadMonsterBaseConfigTable()
end
local MonsterConfig = GameDataManager.MonsterBaseConfigTable[InMonsterType]
if MonsterConfig then
local Index = math.random(1, #MonsterConfig)
return UE.LoadClass(MonsterConfig[Index].Path)
end
return nil
end
function GameDataManager.GetMonsterConfigsByType(InMonsterType)
if table.isEmpty(GameDataManager.MonsterBaseConfigTable) then
GameDataManager:LoadMonsterBaseConfigTable()
end
return GameDataManager.MonsterBaseConfigTable[InMonsterType]
end
function GameDataManager.GetMonsterClassByID(InID)
local MonsterConfig = Tables.MonsterBaseConfig[InID]
if MonsterConfig then
return UE.LoadClass(MonsterConfig.Path)
end
return nil
end
function GameDataManager.GetRandDullMonsterClass()
local DullMonsters = Tables.MonsterPawn.DullMonsters
if DullMonsters then
local Index = math.random(1, #DullMonsters)
return UE.LoadClass(DullMonsters[Index])
end
return nil
--return UE.LoadClass(Tables.MonsterPawn.AttackMonsters.Normal[1])
end
function GameDataManager.GetChallengeInfoIndex(InMonsterType)
return Tables.ChallengeMonsterTypeInfo[InMonsterType]
end
function GameDataManager.GetChallengeMonsterLifeSpan(InMonsterType)
local ChallengeInfoIndex = Tables.ChallengeMonsterTypeInfo[InMonsterType]
if ChallengeInfoIndex then
local ChallengeInfo = Tables.ChallengeInfo[ChallengeInfoIndex]
return ChallengeInfo.LifeTime
end
return -1
end
function GameDataManager:SetLocalPlayerController(InController)
GameDataManager.OwnerPlayerController = InController
end
function GameDataManager:SetLocalPlayerState(InPlayerState)
GameDataManager.OwnerPlayerState = InPlayerState
end
function GameDataManager.GetLocalPlayerState()
if GameDataManager.OwnerPlayerState == nil or UE.IsValid(GameDataManager.OwnerPlayerState) == false then
local LocalPC = GameDataManager.GetLocalPlayerController()
if LocalPC then
local PlayerState = LocalPC.PlayerState
if PlayerState ~= nil and UE.IsValid(PlayerState) then
GameDataManager:SetLocalPlayerState(PlayerState)
end
end
end
return GameDataManager.OwnerPlayerState
end
function GameDataManager.GetLocalPlayerKey()
local LocalPC = GameDataManager.GetLocalPlayerController()
if LocalPC then
return LocalPC.PlayerKey
end
return -1
end
function GameDataManager.GetLocalPlayerController()
if GameDataManager.OwnerPlayerController == nil or UE.IsValid(GameDataManager.OwnerPlayerController) == false then
local GameState = UGCGameSystem.GameState
if GameState ~= nil and UE.IsValid(GameState) then
local PC = STExtraGameplayStatics.GetFirstPlayerController(GameState)
if PC ~= nil and UE.IsValid(PC) then
GameDataManager:SetLocalPlayerController(PC)
end
end
end
return GameDataManager.OwnerPlayerController
end
function GameDataManager.GetLocalPlayerPawn()
if GameDataManager.GetLocalPlayerController() == nil then
return nil
end
return GameDataManager.OwnerPlayerController:GetPlayerCharacterSafety()
end
-------------------------------- Skill ----------------------------------
function GameDataManager.GetSkillNameById(InId)
return InId // 100 % 100
end
function GameDataManager.GetSkillLevelById(InID)
return InID // 10 % 10
end
function GameDataManager.GetSkillIdByNameAndLevel(InSkillName, InLevel)
return 20000 + InSkillName * 100 + InLevel * 10
end
return GameDataManager