Files
Main/Assets/GameAssets/Resources/Lua/Logic/MapLogicEx/XianFu/XianFuHouseMapLogic.lua
2025-01-25 04:38:09 +08:00

319 lines
12 KiB
Lua

------------------------------------------------
--作者: 何健
--日期: 2021-06-16
--文件: XianFuHouseMapLogic.lua
--模块: XianFuHouseMapLogic
------------------------------------------------
local XianFuHouseMapLogic = {
--父逻辑系统
Parent = nil,
Msg = nil, --服务器返回消息
BlockTable = {},
HouseLv = 1,
TupInfo = {}, --聚宝盆数据缓存
MapLength = 10,
MapWidth = 10,
}
function XianFuHouseMapLogic:OnEnterScene(parent)
self.Parent = parent
--设置开关
GameCenter.MapLogicSwitch.CanRide = true
GameCenter.MapLogicSwitch.CanFly = true
GameCenter.MapLogicSwitch.CanRollDoge = true
GameCenter.MapLogicSwitch.CanMandate = true
GameCenter.MapLogicSwitch.CanOpenTeam = true
GameCenter.MapLogicSwitch.ShowNewFunction = true
GameCenter.MapLogicSwitch.UseAutoStrikeBack = true
GameCenter.MapLogicSwitch.CanTeleport = true
GameCenter.MapLogicSwitch.IsCopyMap = true
GameCenter.MapLogicSwitch.IsPlaneCopyMap = false
GameCenter.MapLogicSwitch.HoldFighting = false
GameCenter.MapLogicSwitch.EventOpen = UnityUtils.GetObjct2Int(UILuaEventDefine.UIHouseCopyFormForm_OPEN)
GameCenter.MapLogicSwitch.EventClose = UnityUtils.GetObjct2Int(UILuaEventDefine.UIHouseCopyFormForm_CLOSE)
GameCenter.MapLogicSwitch.OtherName = DataConfig.DataMessageString.Get("Boss")
GameCenter.MapLogicSwitch.OtherSprName = "tongyong"
GameCenter.MapLogicSwitch.ShowServerID = true
--关掉菜单
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_CLOSE_MAINMENU)
GameCenter.PushFixEvent(UILuaEventDefine.UIHouseCopyFormForm_OPEN)
end
--更新
function XianFuHouseMapLogic:Update(dt)
if self.UpdateFormDataCount and self.UpdateFormDataCount > 0 then
self.UpdateFormDataCount = self.UpdateFormDataCount - 1
if self.UpdateFormDataCount == 0 then
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_HOME_ALLJIAJU_UPDATE)
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_HOMETUPINFO, self.TupInfo)
GameCenter.HomeTaskSystem:CheckRedPoint()
end
end
end
function XianFuHouseMapLogic:OnLeaveScene()
self.Msg = nil
GameCenter.PushFixEvent(UILuaEventDefine.UIHouseCopyFormForm_CLOSE)
end
--处理协议
function XianFuHouseMapLogic:OnMsgHandle(msg)
if msg.MsgID == GameCenter.Network.GetMsgID("MSG_Home.ResHomeInfo") then
if not msg.mapInfo then
return
end
self.HelperInfo = msg.helper
if msg.owner then
self.OwnerInfo = msg.owner.owner
self.HouseLv = msg.owner.level
if self.JiaJuDic then
self.JiaJuDic:Clear()
else
self.JiaJuDic = Dictionary:New()
end
if msg.owner.cells then
for i = 1, #msg.owner.cells do
self:UpdateJiaJuData(nil, msg.owner.cells[i])
end
end
if msg.owner.store then
for i = 1, #msg.owner.store do
self:UpdateJiaJuData(msg.owner.store[i])
end
end
if msg.owner.tupLevel ~= nil then
self.TupInfo.tupLevel = msg.owner.tupLevel
end
if msg.owner.tupExp ~= nil then
self.TupInfo.tupExp = msg.owner.tupExp
end
if msg.owner.tupReward ~= nil then
self.TupInfo.tupReward = msg.owner.tupReward
end
if msg.owner.tupRewardExp ~= nil then
self.TupInfo.tupRewardExp = msg.owner.tupRewardExp
end
end
self:SetHouseMapLength()
self.IsUnFriendEnter = msg.authUnFriendEnter
self.IsUnFriendOpt = msg.authUnFriendOpt
self:RefreshMap()
self.UpdateFormDataCount = 5
elseif msg.MsgID == GameCenter.Network.GetMsgID("MSG_Home.ResHomeTupInfo") then
if msg.tupLevel ~= nil then
self.TupInfo.tupLevel = msg.tupLevel
end
if msg.tupExp ~= nil then
self.TupInfo.tupExp = msg.tupExp
end
if msg.tupReward ~= nil then
self.TupInfo.tupReward = msg.tupReward
end
if msg.tupRewardExp ~= nil then
self.TupInfo.tupRewardExp = msg.tupRewardExp
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_HOMETUPINFO, self.TupInfo)
GameCenter.HomeTaskSystem:CheckRedPoint()
elseif msg.MsgID == GameCenter.Network.GetMsgID("MSG_Home.ResHomeLevelUp") then
self.HouseLv = msg.homeLevel
self:SetHouseMapLength()
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_HOME_LV_UPDATE)
Utils.ShowPromptByEnum("C_HOUSE_LVUPMSG")
self:RefreshMap()
--家具库存更新
elseif msg.MsgID == GameCenter.Network.GetMsgID("MSG_Home.ResHomeFurnitureUpdate") then
self:UpdateJiaJuData(msg.store)
elseif msg.MsgID == GameCenter.Network.GetMsgID("MSG_Home.ResHomeDecorate") then
--拆除
if msg.type == 0 then
if self.JiaJuDic then
self:UpdateJiaJuData(msg.store)
if msg.furniture then
if self.JiaJuDic:ContainsKey(msg.furniture.modelId) then
self.JiaJuDic[msg.furniture.modelId].CellDic:Remove(msg.furniture.id)
end
local _ch = GameCenter.LuaCharacterSystem:FindCharacter(msg.furniture.id)
if _ch then
self:CancelPathGridData(_ch)
_ch.IsDeleted = true
end
end
end
else
if self.JiaJuDic then
self:UpdateJiaJuData(msg.store, msg.furniture)
local _ch = GameCenter.LuaCharacterSystem:FindCharacter(msg.furniture.id)
if _ch then
_ch.IsNew = false
self:SetPathGridData(_ch.FillCellList, true)
end
end
end
if msg.furniture then
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_HOME_JIAJU_UPDATE, msg.furniture.id)
end
end
end
function XianFuHouseMapLogic:UpdateJiaJuData(store, cells)
if store then
if self.JiaJuDic:ContainsKey(store.modelId) then
self.JiaJuDic[store.modelId].BagCount = store.count
else
local _tmp = {}
_tmp.CellDic = Dictionary:New()
_tmp.BagCount = store.count
self.JiaJuDic:Add(store.modelId, _tmp)
end
end
if cells then
if self.JiaJuDic:ContainsKey(cells.modelId) then
if self.JiaJuDic[cells.modelId].CellDic:ContainsKey(cells.id) then
self.JiaJuDic[cells.modelId].CellDic[cells.id] = cells
else
self.JiaJuDic[cells.modelId].CellDic:Add(cells.id, cells)
end
else
local _tmp = {}
_tmp.CellDic = Dictionary:New()
_tmp.CellDic:Add(cells.id, cells)
_tmp.BagCount = 0
self.JiaJuDic:Add(cells.modelId, _tmp)
end
end
end
function XianFuHouseMapLogic:GetMainUIState()
return {
[MainFormSubPanel.PlayerHead] = true, --主角头像
[MainFormSubPanel.TargetHead] = true, --目标头像
[MainFormSubPanel.TopMenu] = true, --顶部菜单
[MainFormSubPanel.MiniMap] = false, --小地图
[MainFormSubPanel.FlySwordGrave] = true, --境界
[MainFormSubPanel.TaskAndTeam] = false, --任务和组队
[MainFormSubPanel.Joystick] = true, --摇杆
[MainFormSubPanel.Exp] = true, --经验
[MainFormSubPanel.MiniChat] = true, --小聊天框
[MainFormSubPanel.Skill] = true, --技能
[MainFormSubPanel.SelectPkMode] = true, --选择PK模式
[MainFormSubPanel.FunctionFly] = true, --新功能开启飞行界面
[MainFormSubPanel.FastPrompt] = false, --快速提醒界面
[MainFormSubPanel.FastBts] = true, --快速操作按钮界面
[MainFormSubPanel.Ping] = true, --ping
[MainFormSubPanel.SkillWarning] = false, --技能释放警示
[MainFormSubPanel.CustomBtn] = true, --自定义按钮
[MainFormSubPanel.SitDown] = false, --打坐
[MainFormSubPanel.RemotePlayerHead] = true, --远程玩家头像
[MainFormSubPanel.ChangeSkill] = true, --变身技能
}
end
function XianFuHouseMapLogic:RefreshMap()
if self.JiaJuDic then
self.JiaJuDic:Foreach(function(k, v)
v.CellDic:Foreach(function(k2, v2)
local _cfg = DataConfig.DataSocialHouseFurniture[k]
if _cfg.Type == 1 or _cfg.Type == 2 then
GameCenter.LuaCharacterSystem:RefreshWall(k, k2, _cfg, self.HouseLv)
else
GameCenter.LuaCharacterSystem:RefreshJiaJu(k, v2, _cfg, false, self.HouseLv)
end
end)
end)
end
self:SetPathGridData(nil, true)
end
function XianFuHouseMapLogic:GetMainLeftUIState()
return {
[MainLeftSubPanel.Task] = false, --任务分页
[MainLeftSubPanel.Team] = false, --队伍分页
[MainLeftSubPanel.Other] = false, --其他分页
}
end
function XianFuHouseMapLogic:FindBlockList()
local _list = List:New()
if self.JiaJuDic then
self.JiaJuDic:Foreach(function(k, v)
v.CellDic:Foreach(function(k2, v2)
local _cfg = DataConfig.DataSocialHouseFurniture[k]
if _cfg.Type == 1 or _cfg.Type == 2 then
else
local _ch = GameCenter.LuaCharacterSystem:FindCharacter(v2.id)
if _ch then
for i = 1, #_ch.FillCellList do
if not _list:Contains(_ch.FillCellList[i]) then
_list:Add(_ch.FillCellList[i])
end
end
end
end
end)
end)
end
return _list
end
function XianFuHouseMapLogic:SetPathGridData(blockList, isFreshBlock)
if not blockList then
blockList = self:FindBlockList()
end
if self.BlockTable[1] == nil then
for i = 1, self.MapLength * self.MapWidth do
if blockList and blockList:Contains(i) then
self.BlockTable[i] = true
else
self.BlockTable[i] = false
end
end
else
if blockList then
for i = 1, #blockList do
self.BlockTable[blockList[i]] = true
end
end
end
if isFreshBlock then
GameCenter.MapLogicSwitch:SetPathGridData(self.BlockTable, self.MapLength, self.MapWidth)
end
end
function XianFuHouseMapLogic:CancelPathGridData(ch)
local blockList = ch.FillCellList
if self.BlockTable[1] == nil then
for i = 1, self.MapLength * self.MapWidth do
self.BlockTable[i] = false
end
else
if blockList then
for i = 1, #blockList do
self.BlockTable[blockList[i]] = false
end
end
end
GameCenter.MapLogicSwitch:SetPathGridData(self.BlockTable, self.MapLength, self.MapWidth)
end
function XianFuHouseMapLogic:SaveSetInfo(authUnFriendEnter, authUnFriendOpt, helper)
self.IsUnFriendEnter = authUnFriendEnter
self.IsUnFriendOpt = authUnFriendOpt
if helper then
if not self.HelperInfo then
self.HelperInfo = {}
end
self.HelperInfo.id = helper
end
end
function XianFuHouseMapLogic:SetHouseMapLength()
local _ar = DataConfig.DataSocialHouse[self.HouseLv]
if _ar then
self.MapLength = _ar.SquareLength
self.MapWidth = _ar.SquareWidth
end
end
return XianFuHouseMapLogic