SummonAndChat = {} -- 处理特殊道具 function SummonAndChat.handleSpecialItems(actor, itemConfigId, count) -- info("MS===============" .. string.format("itemConfigId:%d, count:%d", itemConfigId, count)) local itemConfig = ConfigDataManager.getById("cfg_item", itemConfigId) -- info("MS=============== itemConfig : ", itemConfig) if table.isNullOrEmpty(itemConfig) then return end local useParam = itemConfig.useparam if string.isNullOrEmpty(useParam) then return end local params = string.split(useParam, "#") local actionType = params[1] -- info("MS=============== 使用道具类型" .. string.format("actionType:%s", actionType)) if actionType == "team_summon" then SummonAndChat.teamSummon(actor, itemConfigId, count) elseif actionType == "union_summon" then SummonAndChat.unionSummon(actor, itemConfigId, count) end end -- 队伍召唤功能 function SummonAndChat.teamSummon(actor, itemConfigId, count) --找到队伍id local teamId = tonumber(getbaseinfo(actor, "teamid")) if teamId == nil or teamId == 0 then tipinfo(actor, "您不在队伍中") return false end local teamInfo = getteaminfo(actor, teamId) if table.isNullOrEmpty(teamInfo) then tipinfo(actor, "队伍信息获取失败") return false end -- 检查是否为队长 local allTeamMemberInfo = teamInfo["allteammemberinfo"] --local isLeader = false --for _, memberInfo in pairs(allTeamMemberInfo) do --if tonumber(memberInfo["rid"]) == tonumber(getbaseinfo(actor, "rid")) and tonumber(memberInfo["leader"]) == 1 then --isLeader = true --break --end --end -- if not isLeader then -- tipinfo(actor, "只有队长才能使用队伍召唤卡") -- return false -- end -- 获取队长位置信息 local mapId = tonumber(getbaseinfo(actor, "mapid")) local line = tonumber(getbaseinfo(actor, "line")) local x = tonumber(getbaseinfo(actor, "x")) local y = tonumber(getbaseinfo(actor, "y")) local mapName = getmapname(actor, mapId) local requesterName = getrolefield(actor, "role.basic.name") local requesterRid = tonumber(getbaseinfo(actor, "rid")) -- 向所有队员发送传送请求 local summonCount = 0 for _, memberInfo in pairs(allTeamMemberInfo) do local memberRid = tonumber(memberInfo["rid"]) if memberRid ~= requesterRid then -- 不给自己发送 local memberActor = getactor(actor, memberRid) if memberActor then -- 发送传送请求消息 SummonAndChat.sendTransferRequest(memberActor, requesterRid, requesterName, "team", mapId, mapName, line, x, y) summonCount = summonCount + 1 end end end if summonCount > 0 then tipinfo(actor, string.format("已向%d名队员发送传送请求", summonCount)) return true else tipinfo(actor, "没有可召唤的队员") return false end end -- 战盟召唤功能 function SummonAndChat.unionSummon(actor, itemConfigId, count) -- 检查是否为盟主 local unionId = tonumber(getbaseinfo(actor, "unionid")) if unionId == nil or unionId == 0 then tipinfo(actor, "您不在战盟中") return false end local unionInfo = getunioninfo(actor, unionId) if table.isNullOrEmpty(unionInfo) then tipinfo(actor, "战盟信息获取失败") return false end -- 获取盟主位置信息 local mapId = tonumber(getbaseinfo(actor, "mapid")) local line = tonumber(getbaseinfo(actor, "line")) local x = tonumber(getbaseinfo(actor, "x")) local y = tonumber(getbaseinfo(actor, "y")) local mapName = getbaseinfo(actor, 'maptitle') local requesterName = getrolefield(actor, "role.basic.name") local requesterRid = getbaseinfo(actor, "rid") -- 向所有战盟成员发送传送请求 local allUnionMemberInfo = unionInfo["memberinfos"] -- info("MS=============== allUnionMemberInfo 数量 : ", #allUnionMemberInfo) local summonCount = 0 for _, memberInfo in pairs(allUnionMemberInfo) do local memberRid = tonumber(memberInfo.rid) if memberRid ~= requesterRid then -- 不给自己发送 local memberActor = getactor(actor, memberRid) if memberActor and tonumber(getbaseinfo(memberActor, "onlinestate")) == 1 then -- 发送传送请求消息 info(string.format("MS=============== 发送传送请求消息给 %d requesterName: %s", memberRid, requesterName)) SummonAndChat.sendTransferRequest(memberActor, requesterRid, requesterName, "union", mapId, mapName, line, x, y) summonCount = summonCount + 1 info(string.format("MS=============== 发送传送请求消息完成, 当前数量 : %d", summonCount)) end end end info(string.format("MS=============== 发送传送请求消息数量 : %d", summonCount)) if summonCount > 0 then tipinfo(actor, string.format("已向 【 %d 名 】 战盟成员发送传送请求", summonCount)) return true else tipinfo(actor, "没有可召唤的战盟成员") return false end end -- 发送传送请求消息 function SummonAndChat.sendTransferRequest(targetActor, requesterRid, requesterName, requestType, mapId, mapName, line, x, y) local requestData = { requesterRid = requesterRid, requesterName = requesterName, requestType = requestType, -- "team" 或 "union" mapId = mapId, mapName = mapName, line = line, x = x, y = y, timestamp = getbaseinfo("nowsec") } -- 发送传送请求消息到客户端 sendluamsg(targetActor, LuaMessageIdToClient.RES_SUMMON_TRANSFER_SUCCESS, requestData) -- info("MS=============== 发送传送请求消息到客户端") -- 存储请求信息,用于后续处理 local requestKey = "@transfer_request_" .. requesterRid setplaydef(targetActor, requestKey, requestData) end -- 处理传送请求响应 function SummonAndChat.handleTransferResponse(actor, msgData) -- info("MS=============== handleTransferResponse: ", msgData) local requestKey = "@transfer_request_" .. msgData.requesterRid local accepted = msgData.accepted local requesterRid = msgData.requesterRid local itemsNeedIndex = msgData.itemsNeedIndex local requestData = getplaydef(actor, requestKey) -- info("MS=============== 获取请求信息,用于后续处理 requestData: ", requestData) if table.isNullOrEmpty(requestData) then tipinfo(actor, "传送请求已过期") return false end -- 清除请求数据 setplaydef(actor, requestKey, nil) if accepted then -- 检查请求是否过期(30秒内有效) local currentTime = getbaseinfo("nowsec") if currentTime - requestData.timestamp > 30 then tipinfo(actor, "传送请求已过期") return false end -- 检查地图是否可以传送 local canTransfer, reason = SummonAndChat.checkMapTransferCondition(actor, requestData.mapId, requestData.line, requestData.x, requestData.y) -- info("MS=============== canTransfer: ", canTransfer) -- info("MS=============== reason: ", reason) if canTransfer then canTransfer, reason = SummonAndChat.checkMapTransferItemsNeed(actor, requestData.mapId, itemsNeedIndex) end -- info("MS=============== canTransfer2: ", canTransfer) -- info("MS=============== reason2: ", reason) if canTransfer then -- 执行传送 maptransfer(actor, requestData.x, requestData.y, requestData.mapId, requestData.line, 3) -- tipinfo(actor, "已传送到" .. requestData.requesterName .. "身边") -- info("MS=============== 已传送到" .. requestData.requesterName .. "身边") -- 通知请求者 local requesterActor = getactor(requestData.requesterRid) if requesterActor then local targetName = getrolefield(actor, "role.basic.name") tipinfo(requesterActor, "【 " .. targetName .. " 】接受了传送请求") end return true else tipinfo(actor, "无法传送:" .. reason) return false end else -- 通知请求者 local requesterActor = getactor(requestData.requesterRid) if requesterActor then local targetName = getrolefield(actor, "role.basic.name") tipinfo(requesterActor, targetName .. "拒绝了传送请求") end tipinfo(actor, "已拒绝传送请求") return false end end -- 检查地图是否可以传送 function SummonAndChat.checkMapTransferCondition(actor, mapId, line, x, y) -- 检查地图是否存在 if not getmapname(actor, mapId) then return false, "目标地图不存在" end -- 检查线路是否存在 if line <= 0 then return false, "目标线路无效" end -- 检查坐标是否有效 if x < 0 or y < 0 then return false, "目标坐标无效" end -- 检查等级是否满足 local mapLevel = ConfigDataManager.getTableValue("cfg_map_info", "intolv", "id", mapId) if tonumber(mapLevel) > tonumber(getbaseinfo(actor, "level")) then return false, "你的等级不足" .. mapLevel .. "级" end -- 检查是否在同一地图 -- local currentMapId = tonumber(getbaseinfo(actor, "mapid")) -- if currentMapId ~= mapId then -- return false, "只能在同一地图内传送" -- end local checkResult, tip = LineManager.CheckCanEnterLineMap(actor, mapId, line) if checkResult ~= nil and checkResult == false then return checkResult, tip end return true, "" end -- 检查地图是否可以传送 function SummonAndChat.checkMapTransferItemsNeed(actor, mapId, itemsNeedIndex) -- 检查地图是否存在 if not getmapname(actor, mapId) then return false, "目标地图不存在" end local checkResult, tip = LineManager.CheckEnterLineMapItemsNeed(actor, mapId, itemsNeedIndex) if checkResult ~= nil and checkResult == false then return checkResult, tip end return true, "" end