local M = class("GroupData") function M:ctor() self.id = 0 self.name = "" -- 盟主ID self.owner = 0 --盟主昵称 self.o_nick = "" --盟主头像 self.o_portrait = "" --自己在圈子的职位 self.lev = 3 self.top_time = 0 --已获取成员数 self.member_num = 0 -- 总成员数 self.total_member_num = 0 --圈子房间数 self.room_num = 0 -- 1普通圈子2大联盟 self.type = 1 -- 1是房主支付2AA支付 self.pay_type = 1 --成员列表 self.members = {} self.memberMap = {} --房间列表 self.rooms = {} --默认房间列表 self.default_rooms = {} --玩法列表 self.playList = {} --加圈子申请数 self.joins = 0 --自动解散 self.dissolve_opt = 1 --占座踢出 self.kick_opt = 1 --玩家申请 self.apply = 0 --盟主钻石 self.diamo = 0 --隐藏功能 self.hide_action = 0 --是否开启全民推广 self.promote = false end -- 添加成员 function M:addMember(member) local _tem = self.memberMap[member.uid] if _tem then for k, v in pairs(member) do _tem[k] = v end else self.memberMap[member.uid] = member self.members[#self.members + 1] = member self.member_num = #self.members end end -- 删除成员 function M:delMember(id) local _tem = self.memberMap[id] if _tem then self.memberMap[id] = nil for i=1,#self.members do local member = self.members[i] if member.uid == id then table.remove(self.members,i) break end end self.member_num = #self.members end end function M:clearMember() self.members = {} self.memberMap = {} self.member_num = 0 end function M:getMember(id) return self.memberMap[id] end -- 添加房间 function M:addRoom(room) local pid = room.pid local play = self:getPlay(pid) print("jefe addRoom") if not play then return end for i=1,#self.rooms do local tem = self.rooms[i] if room.id == tem.id then self.rooms[i] = room for j = 1, #play.rooms do if room.id == play.rooms[j].id then play.rooms[j] = room return end end return end end self.rooms[#self.rooms+1] = room -- 把房间加入对应的玩法下的列表 play.rooms[#play.rooms + 1] = room end -- 删除房间 function M:delRoom(id) local pid = 0 for i=1,#self.rooms do local room = self.rooms[i] if room.id == id then pid = room.pid table.remove(self.rooms,i) break end end if pid == 0 then return end local play = self:getPlay(pid) if not play then return end for i = 1, #play.rooms do local room = play.rooms[i] if room.id == id then table.remove(play.rooms, i) break end end end -- 添加玩法 function M:addPlay(play) --printlog("添加玩法addPlay===>>>") --pt(play) local maxRound=0 if play.maxRound then maxRound=play.maxRound else local hpdata = json.decode(play.hpData) maxRound=hpdata.maxRound end local pnum = play.maxPlayers local room = {maxPlayers = pnum, status = -1, default = true, pid = play.id,times=maxRound} play.rooms = {} local index = self:getPlayIndex(play.id) if index ~= -1 then self.playList[index] = play self.default_rooms[index] = room return end self.playList[#self.playList + 1] = play -- 房间列表中,给每个玩法添加一个对应的空房间 self.default_rooms[#self.default_rooms + 1] = room --self.playList=self:SortPlay(self.playList) --pt(self.playList) --self.default_rooms=self:SortDefaultPlay(self.default_rooms) end function M:SortPlay(list) local singlePlayList={} local otherPlayList={} for i=1,#list do local hpdata=json.decode(list[i].hpData) if hpdata.maxRound and hpdata.maxRound==1 then table.insert(singlePlayList,list[i]) else table.insert(otherPlayList,list[i]) end end for i=1,#otherPlayList do table.insert(singlePlayList,otherPlayList[i]) end return singlePlayList end function M:SortDefaultPlay(list) local singlePlayList={} local otherPlayList={} for i=1,#list do if list[i].times and list[i].times==1 then table.insert(singlePlayList,list[i]) else table.insert(otherPlayList,list[i]) end end for i=1,#otherPlayList do table.insert(singlePlayList,otherPlayList[i]) end return singlePlayList end -- 删除玩法 function M:delPlay(pid) local index = self:getPlayIndex(pid) if index ~= -1 then table.remove(self.playList,index) table.remove(self.default_rooms, index) return true end return false end -- 禁止玩法 function M:banPlay(pid, ban) local play = self:getPlay(pid) --printlog("禁止玩法===>>>") --pt(play) play.ban = ban end -- 标记玩法 function M:markPlay(pid, ban) local play = self:getPlay(pid) --printlog("标记玩法===>>>") play.mark = ban --pt(play) end function M:getPlay(pid) local index = self:getPlayIndex(pid) if index ~= -1 then return self.playList[index] end return nil end function M:getPlayName(pid) local index = self:getPlayIndex(pid) if index ~= -1 then return self.playList[index].name end return "已删除" end function M:getPlayIndex(pid) for i=1,#self.playList do local tem = self.playList[i] if tem.id == pid then return i end end return -1 end function M:clearPlay() self.playList = {} self.rooms = {} self.default_rooms={} for i = 1, #self.playList do self.playList[i].rooms = {} end end function M:clear() self.playList = {} self.members = {} self.memberMap = {} self.rooms = {} self.default_rooms = {} end return M