miduo_client/Assets/ManagedResources/~Lua/Modules/Guild/MyGuildManager.lua

591 lines
19 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

MyGuildManager = {}
local this = MyGuildManager
function this.Initialize()
this.MyGuildInfo = nil
this.MyMemInfo = nil
this.MyGuildMemList = {}
this.MyGuildApplyList = {}
this.MyGuildLogList = {}
this._MemWalkData = {}
this.MyFeteInfo={}
end
-- 登录初始化数据
function MyGuildManager.InitBaseData(func)
if PlayerManager.familyId == 0 then
if func then func() end
return
end
NetManager.RequestMyGuildInfo(func)
end
-- 初始化所有数据
function MyGuildManager.InitAllData(func)
if PlayerManager.familyId == 0 then
if func then func() end
return
end
-- 有公会刷新一遍数据
local step = 0
local function _StepFunc()
step = step + 1
if step == 3 then
if func then func() end
end
end
NetManager.RequestMyGuildInfo(_StepFunc)
this.RequestMyGuildMembers(_StepFunc)
GuildFightManager.InitData(_StepFunc)
end
-- 设置我的公会信息
function MyGuildManager.SetMyGuildInfo(msg)
-- 公会信息
this.MyGuildInfo = msg.familyBaseInfo
if this.MyGuildInfo.id then
PlayerManager.familyId = this.MyGuildInfo.id
end
-- 发送数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.DataUpdate)
end
-- 设置我的公会信息
function MyGuildManager.SetMyMemInfo(msg)
-- 成员数据
this.MyMemInfo = msg.familyUserInfo
-- 发送数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.DataUpdate)
end
--设置我的祭祀信息
function MyGuildManager.SetMyFeteInfo(msg)
this.MyFeteInfo.takeFeteReward=msg.familyUserInfo.takeFeteReward --祭祀领取进度
this.MyFeteInfo.lastFeteGuildId=msg.familyUserInfo.lastFeteGuildId --上次祭祀公会id
this.MyFeteInfo.lastFeteType=msg.familyUserInfo.lastFeteType --上次祭祀类型 //每日清除 5点推送
end
--设置祭祀 进度信息
function MyGuildManager.SetMyFeteInfo_ByScore(msg)
this.MyFeteInfo.score=msg.score
end
--设置祭祀5点刷新 数据重置
function MyGuildManager.SetMyFeteInfo_FiveRefresh(msg)
this.MyFeteInfo.takeFeteReward=msg.takeFeteReward
this.MyFeteInfo.lastFeteType=msg.lastFeteType
end
---============================ 行走相关======================================
-- 请求行走
function MyGuildManager.RequestWalk(pathlist, func)
NetManager.GuildWalkRequest(pathlist, func)
end
-- 设置公会中玩家得行走数据
function MyGuildManager.SetWalkData(msg)
this._MemWalkData = {}
Log("==============公会行走数据初始化")
for i, data in ipairs(msg.familyWalkIndicaiton) do
Log("uid = "..data.uid..", name = "..data.name..", 当前位置 = "..data.curPos)
this._MemWalkData[data.uid] = data
end
Log("==============公会行走数据初始化")
end
-- 更新行走数据
function MyGuildManager.UpdateWalkData(msg)
if not this._MemWalkData then
this._MemWalkData = {}
end
this._MemWalkData[msg.uid] = msg
Log("++++++++++++++公会行走数据更新")
Log("uid = "..msg.uid..", name = "..msg.name..", 当前位置 = "..msg.curPos)
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.WalkUpdate, msg)
end
-- 获取所有行走数据
function MyGuildManager.GetMemWalkData()
return this._MemWalkData
end
-- 获取某个成员得行走数据
function MyGuildManager.GetMemWalkDataById(uid)
return this._MemWalkData[uid]
end
---============================ 行走相关end======================================
-- 获取日志信息
function MyGuildManager.RequestMyGuildLog(func)
NetManager.RequestMyGuildLog(function(msg)
this.MyGuildLogList = msg.familyLogInfo
if func then func() end
-- 发送日志数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.LogDataUpdate)
end)
end
-- 获取成员信息
function MyGuildManager.RequestMyGuildMembers(func)
NetManager.RequestMyGuildMembers(function(msg)
this.MyGuildMemList = msg.familyUserInfo
table.sort(this.MyGuildMemList, function(a, b)
if a.seconds == b.seconds then
return a.position < b.position
end
return a.seconds < b.seconds
end)
if func then func() end
-- 发送成员数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.MemberDataUpdate)
end)
end
-- 获取申请信息
function MyGuildManager.RequestMyGuildApplyList(func)
NetManager.RequestMyGuildApply(function(msg)
this.MyGuildApplyList = msg.familyApply
if func then func() end
-- 发送申请数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.ApplyDataUpdate)
-- 刷新服务器红点
ResetServerRedPointStatus(RedPointType.Guild_Apply)
end)
end
-- 申请修改图腾
function MyGuildManager.RequestChangeLogo(logoId, func)
NetManager.RequestChangeLogo(logoId, function(msg)
this.MyGuildInfo.icon = logoId
if func then func() end
-- 发送申请数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.DataUpdate)
end)
end
-- 获取我的公会信息
function MyGuildManager.GetMyGuildInfo()
return this.MyGuildInfo
end
-- 获取我的公会的成员数据
function MyGuildManager.GetMyGuildMemList()
return this.MyGuildMemList
end
-- 获取我的公会的会长信息
function MyGuildManager.GetMyGuildMasterInfo()
for _, v in ipairs(this.MyGuildMemList) do
if v.position == GUILD_GRANT.MASTER then
return v
end
end
end
-- 获取公会成员数据
function MyGuildManager.GetMemInfo(memId)
if not memId then return end
for _, v in ipairs(this.MyGuildMemList) do
if v.roleUid == memId then
return v
end
end
end
-- 重置公会成员战斗力
function MyGuildManager.ResetMemForce(memId, force)
if not memId then return end
for _, v in ipairs(this.MyGuildMemList) do
if v.roleUid == memId then
v.soulForce = force
break
end
end
-- 发送数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.DataUpdate)
end
-- 获取我再公会中的数据
function MyGuildManager.GetMyMemInfo()
return this.MyMemInfo
end
-- 获取公会日志数据
function MyGuildManager.GetMyGuildLog()
return this.MyGuildLogList
end
-- 获取公会申请数据
function MyGuildManager.GetMyGuildApplyList()
return this.MyGuildApplyList
end
-- 获取我在公会中的职位
function MyGuildManager.GetMyPositionInGuild()
if PlayerManager.familyId == 0 then return end
if not this.MyMemInfo then return end
return this.MyMemInfo.position
end
-- 获取公会管理数量
function MyGuildManager.GetAdminMemNum()
local num = 0
for _, v in ipairs(this.MyGuildMemList) do
if v.position == GUILD_GRANT.ADMIN then
num = num + 1
end
end
return num
end
---============== 操作=================
-- 请求操作申请数据
function MyGuildManager.OperateApply(opType, applyId, func)
-- 公会战期间无法执行此操作
--if opType == GUILD_APPLY_OPTYPE.ONE_AGREE or opType == GUILD_APPLY_OPTYPE.ALL_AGREE then
-- if GuildFightManager.IsInGuildFight() then
-- PopupTipPanel.ShowTip("公会战期间无法执行此操作")
-- return
-- end
--end
if opType == GUILD_APPLY_OPTYPE.ALL_AGREE or opType == GUILD_APPLY_OPTYPE.ALL_REFUSE then
if #this.MyGuildApplyList == 0 then
PopupTipPanel.ShowTip("没有入会申请")
return
end
end
NetManager.RequestOperateMyGuildApply(opType, applyId, function()
if opType == GUILD_APPLY_OPTYPE.ALL_AGREE or opType == GUILD_APPLY_OPTYPE.ALL_REFUSE then
this.MyGuildApplyList = {}
elseif opType == GUILD_APPLY_OPTYPE.ONE_AGREE or opType == GUILD_APPLY_OPTYPE.ONE_REFUSE then
local removeIndex = nil
for i, v in ipairs(this.MyGuildApplyList) do
if v.roleUid == applyId then
removeIndex = i
break
end
end
-- 删除相应位置的数据
if removeIndex then
table.remove(this.MyGuildApplyList, removeIndex)
end
end
-- 发送申请数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.ApplyDataUpdate)
-- 成功回调
if func then func() end
end)
end
-- 请求修改公会宣言
function MyGuildManager.RequestChangeGuildAnnounce(announce, func)
local pos = this.GetMyPositionInGuild()
if pos == GUILD_GRANT.MEMBER then
PopupTipPanel.ShowTip("您无权修改公会宣言")
return
end
if not announce or announce == "" then
PopupTipPanel.ShowTip("公会宣言不可为空")
return
end
NetManager.RequestChangeGuildBase(1, announce, function(msg)
if msg.result == 0 then
PopupTipPanel.ShowTip(msg.err)
return
end
this.MyGuildInfo.annouce = announce
if func then func() end
-- 发送数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.DataUpdate)
end)
end
-- 请求修改公会名称
function MyGuildManager.RequestChangeGuildName(name, func)
local pos = this.GetMyPositionInGuild()
if pos == GUILD_GRANT.MEMBER then
PopupTipPanel.ShowTip("您无权修改公会名称")
return
end
-- 判断物品数量
local cost = ConfigManager.GetConfigData(ConfigName.GuildSetting, 1).RenameCost
local haveNum = BagManager.GetItemCountById(cost[1][1])
if haveNum < cost[1][2] then
PopupTipPanel.ShowTip("所需物品不足")
return
end
if not name or name == "" then
PopupTipPanel.ShowTip("公会名称不可为空")
return
end
local config = ConfigManager.GetConfigData(ConfigName.GuildSetting, 1)
local minLen, maxLen = config.NameSize[1], config.NameSize[2]
local len = StringWidth(name)
if len < minLen or len > maxLen then
PopupTipPanel.ShowTip("公会名称长度不符合规范2-6个字")
return
end
NetManager.RequestChangeGuildBase(0, name, function(msg)
if msg.result == 0 then
PopupTipPanel.ShowTip(msg.err)
return
end
this.MyGuildInfo.name = name
if func then func() end
-- 发送数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.DataUpdate)
end)
end
-- 请求修改公会申请类型
function MyGuildManager.RequestChangeJoinType(joinType, limitLevel, func)
local pos = this.GetMyPositionInGuild()
if pos == GUILD_GRANT.MEMBER then return end
NetManager.RequestChangeJoinType(joinType, limitLevel, function()
this.MyGuildInfo.joinType = joinType
if func then func() end
-- 发送数据更新事件
--Game.GlobalEvent:DispatchEvent(GameEvent.Guild.DataUpdate)
end)
end
-- 请求退出公会
function MyGuildManager.RequestQuitGuild(func)
-- 公会战期间无法执行此操作
if GuildFightManager.IsInGuildFight() then
PopupTipPanel.ShowTip("公会战期间无法执行此操作")
return
end
local pos = this.GetMyPositionInGuild()
if pos == GUILD_GRANT.MASTER then
PopupTipPanel.ShowTip("会长不能退出公会")
return
end
NetManager.RequestQuitGuild(function()
PlayerManager.familyId = 0
this.MyGuildInfo = nil
this.MyMemInfo = nil
this.MyFeteInfo={}
this.MyGuildMemList = {}
this.MyGuildApplyList = {}
this.MyGuildLogList = {}
if func then func() end
-- 退出公会成功事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.OnQuitGuild)
-- 退出公会成功
PopupTipPanel.ShowTip("退出公会成功")
-- 刷新服务器红点
ResetServerRedPointStatus(RedPointType.Guild_Apply)
ResetServerRedPointStatus(RedPointType.Guild_Shop)
ResetServerRedPointStatus(RedPointType.Shop_Guild_Check)
end)
end
-- 请求任命官职
function MyGuildManager.AppointmentPos(tId, tPos, func)
-- 公会战期间无法执行此操作
if GuildFightManager.IsInGuildFight() then
PopupTipPanel.ShowTip("公会战期间无法执行此操作")
return
end
if tId == PlayerManager.uid then
PopupTipPanel.ShowTip("无法对自己执行此操作")
return
end
-- 判断我是否有权限
local pos = MyGuildManager.GetMyPositionInGuild()
if pos == GUILD_GRANT.MEMBER then
PopupTipPanel.ShowTip("您没有变更成员职位的权限")
return
end
--
if tPos == GUILD_GRANT.MASTER and pos ~= GUILD_GRANT.MASTER then
PopupTipPanel.ShowTip("您没有转让会长的权限")
return
end
-- 如果委任官员判断官员数量是否已达上限
if tPos == GUILD_GRANT.ADMIN then
local adminNum = this.GetAdminMemNum()
local guildData = this.GetMyGuildInfo()
local maxNum = ConfigManager.GetConfigData(ConfigName.GuildLevelConfig, guildData.levle).OfficalNum
if adminNum >= maxNum then
PopupTipPanel.ShowTip("已达官员最大数量")
return
end
end
-- 判断目标成员职位是否符合条件
local tData = this.GetMemInfo(tId)
if tPos == tData.position then
PopupTipPanel.ShowTip("此成员已经是公会"..GUILD_GRANT_STR[tPos])
return
end
-- 管理之间无法操作
if pos == GUILD_GRANT.ADMIN and tData.position == GUILD_GRANT.ADMIN then
PopupTipPanel.ShowTip("您无法对官员执行此操作")
return
end
NetManager.RequestMyGuildAppointment(tId, tPos, function()
-- 成员数据变动
this.RequestMyGuildMembers()
if func then func() end
end)
end
-- 请求踢人
function MyGuildManager.RequestKickOut(tId, func)
-- 公会战期间无法执行此操作
if GuildFightManager.IsInGuildFight() then
PopupTipPanel.ShowTip("公会战期间无法执行此操作")
return
end
if tId == PlayerManager.uid then
PopupTipPanel.ShowTip("无法对自己执行此操作")
return
end
-- 判断我是否有权限
local pos = MyGuildManager.GetMyPositionInGuild()
if pos == GUILD_GRANT.MEMBER then
PopupTipPanel.ShowTip("您没有此权限")
return
end
-- 判断目标职位是否符合条件
local tData = this.GetMemInfo(tId)
-- 管理之间无法操作
if tData.position == GUILD_GRANT.MASTER then
PopupTipPanel.ShowTip("您无法对会长执行此操作")
return
elseif pos == GUILD_GRANT.ADMIN and tData.position == GUILD_GRANT.ADMIN then
PopupTipPanel.ShowTip("您无法对官员执行此操作")
return
end
NetManager.RequestKickOutFormMyGuild(tId, function()
-- 成员数据变动
this.RequestMyGuildMembers()
if func then func() end
end)
end
-- 请求退出公会
function MyGuildManager.RequestDismissGuild(dType, func)
-- 公会战期间无法执行解散公会的操作
if dType == 1 then
if GuildFightManager.IsInGuildFight() then
PopupTipPanel.ShowTip("公会战期间无法执行此操作")
return
end
end
local pos = this.GetMyPositionInGuild()
if pos ~= GUILD_GRANT.MASTER then
PopupTipPanel.ShowTip("您没有此权限")
return
end
NetManager.RequestDismissGuild(dType, function()
if func then func() end
-- 解散公会成功
local destroyTime = ConfigManager.GetConfigData(ConfigName.GuildSetting, 1).DestroyTime
local timeStr = ""
if destroyTime < 60 then
timeStr = destroyTime .. ""
elseif destroyTime >= 60 and destroyTime < 3600 then
timeStr = math.floor(destroyTime/60).."分钟"
else
timeStr = math.floor(destroyTime/3600).."小时"
end
PopupTipPanel.ShowTip(dType == 1 and string.format("公会将在%s后解散", timeStr) or "取消解散成功")
-- 发送数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.DismissStatusChanged)
end)
end
-- 判断商店栏位是否解锁
local _SortUnLockLevel = nil
function MyGuildManager.GetGuildShopSortIsUnLock(sort)
if not _SortUnLockLevel then
_SortUnLockLevel = {}
local guildLevelConfig = ConfigManager.GetConfig(ConfigName.GuildLevelConfig)
for level, data in ConfigPairs(guildLevelConfig) do
for sort = 1, data.ShopSort do
if not _SortUnLockLevel[sort] then
_SortUnLockLevel[sort] = level
end
end
end
end
local unLockLevel = _SortUnLockLevel[sort]
-- 没有解锁等级 999级解锁
if not unLockLevel then return false, 999 end
-- 判断是否解锁
local isUnLock = this.GetMyGuildInfo().levle >= unLockLevel
return isUnLock, unLockLevel
end
---=========== 服务器推送方法================
-- 被提出公会
function MyGuildManager.BeKickOut(msg)
-- uid 为0表示公会解散
if msg.uid == PlayerManager.uid or msg.uid == 0 then
PlayerManager.familyId = 0
this.MyGuildInfo = nil
this.MyMemInfo = nil
this.MyFeteInfo={}
this.MyGuildMemList = {}
this.MyGuildApplyList = {}
this.MyGuildLogList = {}
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.BeKickOut)
-- 添加tip显示
GuildManager.AddGuildTip(GUILD_TIP_TYPE.KICKOUT, msg.uid)
-- 刷新服务器红点
ResetServerRedPointStatus(RedPointType.Guild_Apply)
ResetServerRedPointStatus(RedPointType.Guild_Shop)
ResetServerRedPointStatus(RedPointType.Shop_Guild_Check)
else
local rIndex = nil
for index, mem in ipairs(this.MyGuildMemList) do
if mem.roleUid == msg.uid then
rIndex = index
break
end
end
if rIndex then
local rMem = table.remove(this.MyGuildMemList, rIndex)
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.KickOut, rMem.roleUid)
end
end
end
-- 我的职位更新
function MyGuildManager.UpdateGuildPosition(msg)
local pos = msg.position
local uid = msg.uid
if uid == PlayerManager.uid then
local oldPos = this.MyMemInfo.position
this.MyMemInfo.position = pos
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.PositionUpdate)
-- 加入tip显示
GuildManager.AddGuildTip(GUILD_TIP_TYPE.POS, pos, oldPos)
-- 降职重置红点儿
if pos == GUILD_GRANT.MEMBER then
-- 刷新服务器红点
ResetServerRedPointStatus(RedPointType.Guild_Apply)
end
end
-- 更新成员列表里的职位
for _, v in ipairs(this.MyGuildMemList) do
if v.roleUid == uid then
v.position = pos
break
end
end
-- 发送数据更新事件
Game.GlobalEvent:DispatchEvent(GameEvent.Guild.MemberDataUpdate)
end
return this