Union = {} local this = {} ---@class UnionData ---@field createtime number 创建时间 ---@field memberinfos table 成员列表 ---@field leaderid number 盟主id ---@field unionid number 战盟id ---@field leaderontime number 盟主上位时间 ---@field unionname string 战盟名称 ---@field unionlevel number 战盟等级 ---@field totaldevote number 战盟总贡献 ---@field unionarmband number 战盟臂章ID ---@field ischangename number 是否改名 0 未改名 1 已改名 ---@field unionexp number 战盟经验 ---@field num number 当前人数 ---@field maxnum number 最大人数 ---@field enemyunionids table 敌对战盟 ---@field announcement string 战盟公告 ---@field unioncapital number 战盟资金 ---@field unioncachet number 战盟声望 ---@class UnionMemberInfos ---@field rid number 角色id ---@field name string 角色名字 ---@field level number 角色等级 ---@field career number 职业 ---@field position number 职位 ---@field devote number 贡献值 ---@field isonline number 是否在线 0 离线 1 在线 ---@field jointime number 加入时间 ---@field curweekactivetimes number 当前周活跃度 ---@field quitlinetime number 下线时间 function Union.sendLeaderOnlineStateMsg(actor) this.sendLeaderOnlineStateMsg(actor) end function this.sendLeaderOnlineStateMsg(actor) local union_id = tostring(getbaseinfo(actor, "unionid")) if string.tonumber(union_id) < 1 then return end local union_data = getunioninfo(actor) if table.isEmpty(union_data) then this.jprint(" ---- 发送盟主状态时 获取战盟数据失败!----") return end local rid = tostring(getbaseinfo(actor, "id")) local leader_id = tostring(union_data.leaderid) if tonumber(rid) ~= tonumber(leader_id) then return end local online_state = getbaseinfo(actor, "onlinestate") if online_state == "" or tonumber(online_state) == 0 then online_state = 0 else online_state = 1 end for _, member in pairs(union_data.memberinfos) do local member_actor = getactor(member.rid) sendluamsg(member_actor, LuaMessageIdToClient.RES_UNION_LEADER_ON_LINE_STATE, union_data) end this.jprint("------- 发送盟主在线状态 ------") end ------------------------------------ ↓战盟活动↓ ---------------------------------- Union.UnionActivity = {} ---@class Union.UnionActivity ---@field activityid number 活动id ---@field open string 是否开启 -- 获取战盟活动列表 function Union.UnionActivity.getUnionActivity(actor) local data = this.getUnionActivity(actor) sendluamsg(actor, LuaMessageIdToClient.RES_UNION_ACTIVITY_DATA, data) end function this.getUnionActivity(actor) local data = getallactivities(actor) if table.isEmpty(data) then this.jprint("获取活动列表失败") return end local union_active = {} for _, value in pairs(data) do local type = ConfigDataManager.getTableValue("cfg_activity_rule", "initType", "id", value.activityid) if tonumber(type) == UnionConst.UNION_ACTIVITY_INITTYPE then ---@type Union.UnionActivity local activity = { activityid = value.activityid, open = value.open } table.insert(union_active, activity) end end return union_active end ------------------------------------- ↑战盟活动↑ ----------------------------------- Union.DefaultUnion = {} --- 服务器启动后创建默认战盟 全局数据 this.GLOBAL_DEFAULT_UNION_CREATE_DATA_KEY = PlayerDefKey.UNION.GLOBAL_DEFAULT_UNION_CREATE_DATA_KEY this.DEFAULT_UNION_GLOBAL_ID = 1601 function Union.DefaultUnion.initDefaultUnion(is_gm) local serverType = getbaseinfo("servertype") if serverType == 2 then -- 跨服服务器不执行 return end local summary_list = getallunionsummary() local is_create = getsysvar(this.GLOBAL_DEFAULT_UNION_CREATE_DATA_KEY) this.debug("is_create", is_create, table.notEmpty(summary_list), is_create or table.notEmpty(summary_list)) if (is_create or table.notEmpty(summary_list)) and not is_gm then return end local value_str = ConfigDataManager.getTableValue("cfg_global", "value", "id", this.DEFAULT_UNION_GLOBAL_ID) if string.isNullOrEmpty(value_str) then return end local list = ConfigDataManager.getList("cfg_unionname") if table.isEmpty(list) then return end local create_info = string.split(value_str, "#") local union_count = tonumber(create_info[1]) local curr_count = 0 local usedIndexes = {} for idx, level in pairs(create_info) do if idx ~= 1 and curr_count < union_count then -- 随机一个战盟名称和战盟臂章 local log = math.random(1, 5) local randomIndex repeat randomIndex = math.random(1, #list) until not usedIndexes[randomIndex] --创建战盟 local config = list[randomIndex] local union_id = systemcreateunion(config.name, log, level) local union = getunioninfo(union_id) -- 标记已使用的索引 usedIndexes[randomIndex] = true this.debug("创建默认战盟:", union, union_id, log) end end setsysvar(this.GLOBAL_DEFAULT_UNION_CREATE_DATA_KEY, true) end function Union.combineglobalvar(varName) setsysvar(varName, true) end ---------------------------- 日志打印 ----------------------------- this.log_open = false function this.jprint(param) if not this.log_open then return end if param == nil then param = "error! 输出内容为空. nil" end jprint(param) end function this.loginfo(actor, param) if not this.log_open then return end if param == nil then param = "error! 日志输出内容为空. nil" end jprint(param) info(actor, param) end function this.debug(...) if not this.log_open then return end gameDebug.print(...) end --- 修改战盟名称 ---@param actor table 玩家对象 ---@param msgData table 战盟名称 function Union.changeUnionName(actor, msgData) local unionName = msgData["unionName"] ---@type UnionData local unionInfo = getunioninfo(actor) ---@type UnionMemberInfos local member = unionInfo.memberinfos[tonumber(actor:toString())] if member.position ~= 1 and member.position ~= 2 then noticeTip.noticeinfo(actor, StringIdConst.TEXT454) return end -- 如果首次更改战盟名称不消耗道具 if unionInfo.ischangename and unionInfo.ischangename == 1 then -- 如果背包中有战盟改名卡,则先消耗战盟改名卡 local cfgCost = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.CHANGE_NAME_CARD_COST) local split = string.split(cfgCost, "|") local tmps = string.split(split[1], "#") local costItemId = tmps[1] local costCount = tmps[2] if not Bag.checkItem(actor, costItemId, costCount) then local value = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.CHANGE_NAME_COST_WITHOUT_CARD) local split2 = string.split(value, "|") local tmp2 = string.split(split2[1], "#") costItemId = tmp2[1] costCount = tmp2[2] if not Bag.checkItem(actor, costItemId, costCount) then noticeTip.noticeinfo(actor, StringIdConst.TEXT346) return end end if not checkunionname(actor, unionName) then jprint("战盟名称不合法或重复 actor:" .. actor:toString() .. "unionName:" .. unionName) return end -- 从背包中移除指定数量的道具 removeitemfrombag(actor, costItemId, costCount,0,9999,'战盟改名') else if not checkunionname(actor, unionName) then jprint("战盟名称不合法或重复 actor:" .. actor:toString() .. "unionName:" .. unionName) return end end -- 修改战盟名称 changeunionname(actor, unionName) end this.gm_open = true function l_default_create_system_union(_, is_gm) if not this.gm_open then return end Union.DefaultUnion.initDefaultUnion(is_gm) end