123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- Mount = {}
- local this = {}
- MOUNT_LIMIT_TIME = 60 * 60
- TIME_LIMIT_MOUNT = "T$timeLimitMount"
- local HEI_WANG_MA_TYPE = 19
- -- 发送当前骑乘坐骑信息
- function Mount.sendCurrentRideMount(actor)
- local curRideMountId = getrolefield(actor,"role.rolemount.curridemountid")
- sendluamsg(actor, LuaMessageIdToClient.RES_CURRENT_RIDE_MOUNT, curRideMountId)
- end
- -- 坐骑穿戴装备
- function Mount.putOnItem(actor, msgData)
- local mountEquip = ConfigDataManager.getTableValue("cfg_mount","mountEquip","id",msgData[1])
- if mountEquip == "0" then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT359)
- end
- local putOnResult = mountputitem(actor, msgData[1],msgData[2],msgData[3])
- local result = {}
- result["result"] = putOnResult
- result["pos"] = msgData[3]
- result["itemcfgid"] = msgData[4]
- result["itemid"] = msgData[5]
- sendluamsg(actor, LuaMessageIdToClient.RES_MOUNT_PUT_ON_ITEM, result)
- Mount.mountDetail(actor,msgData)
- Mount.sendCurrentRideMount(actor)
- end
- -- 坐骑脱下装备
- function Mount.takeOffItem(actor, msgData)
- local takeOffResult = mountoffitem(actor, msgData[1],msgData[2])
- local result = {}
- result["result"] = takeOffResult
- result["pos"] = msgData[2]
- sendluamsg(actor, LuaMessageIdToClient.RES_MOUNT_TAKE_OFF_ITEM, result)
- Mount.mountDetail(actor,msgData)
- Mount.sendCurrentRideMount(actor)
- end
- -- 穿戴坐骑信息 需要穿戴坐骑背包索引
- function Mount.mountBagToStore(actor, msgData)
- local itemcfgid = msgData[2]
- local mountConfig = ConfigDataManager.getTable("cfg_mount","itemId",itemcfgid)
- if table.isEmpty(mountConfig) then
- error("坐骑配置信息中没有itemId为:" .. itemcfgid.."的配置项")
- return
- end
- local mountInfo = mountConfig[1]
- jprint("mountInfo",mountInfo)
- local limitedtype = mountInfo.limitedtype
- if limitedtype and limitedtype == "1" then
- -- 限时坐骑
- jprint("限时坐骑")
- local allTimeLimitMount = getplaydef(actor, TIME_LIMIT_MOUNT)
- local timeLimitMount = {}
- if table.isEmpty(allTimeLimitMount) then
- allTimeLimitMount = {}
- timeLimitMount = {
- time = getbaseinfo(actor,"nowsec"),
- itemCfgId = tonumber(mountInfo.icon),
- id = tonumber(mountInfo.id),
- endTime = getbaseinfo(actor,"nowsec") + tonumber(mountInfo.limitedtime) * MOUNT_LIMIT_TIME,
- }
- else
- local have = false
- for index, timeLimitMount in pairs(allTimeLimitMount) do
- if timeLimitMount.itemCfgId == tonumber(mountInfo.icon) then
- have = true
- end
- end
- if have then
- tipinfo(actor,"已经激活过该坐骑")
- return
- end
- timeLimitMount = {
- time = getbaseinfo(actor,"now"),
- itemCfgId = tonumber(mountInfo.icon),
- id = tonumber(mountInfo.id),
- endTime = getbaseinfo(actor,"nowsec") + tonumber(mountInfo.limitedtime) * MOUNT_LIMIT_TIME
- }
- end
- table.insert(allTimeLimitMount,timeLimitMount)
- setplaydef(actor, TIME_LIMIT_MOUNT,allTimeLimitMount)
- end
- local putOnResult = putonmount(actor, msgData[1])
- local result = {}
- result["result"] = putOnResult
- result["mountid"] = msgData
- sendluamsg(actor, LuaMessageIdToClient.RES_MOUNT_BAG_TO_STORE, result)
- Mount.sendCurrentRideMount(actor)
- Mount.setMountLogo(actor)
- end
- -- 设置坐骑标志
- function Mount.setMountLogo(actor)
- local mountLogo = getplaydef(actor,"T$mountlogo")
- if not mountLogo then
- local mountLogo = {}
- mountLogo["rank"] = 0
- end
- mountLogo["logo"] = 1
- setplaydef(actor,"T$mountlogo",mountLogo)
- Mount.sendMountLogo(actor)
- end
- -- 设置坐骑排行
- function Mount.setMountRank(actor,msgData)
- local mountLogo = getplaydef(actor,"T$mountlogo")
- mountLogo["rank"] = msgData
- setplaydef(actor,"T$mountlogo",mountLogo)
- Mount.sendMountLogo(actor)
- end
- -- 发送坐骑默认骑乘信息和排行信息
- function Mount.sendMountLogo(actor)
- local mountLogo = getplaydef(actor,"T$mountlogo")
- if not mountLogo then
- mountLogo = {}
- mountLogo["logo"] = 0
- mountLogo["rank"] = 0
- setplaydef(actor,"T$mountlogo",mountLogo)
- end
- sendluamsg(actor,LuaMessageIdToClient.RES_MOUNT_LOGO,mountLogo)
- end
- -- 发送其他人坐骑默认骑乘信息和排行信息
- function Mount.sendOtherMountRank(actor,otherRid)
- local otherActor = nil
- if actor:toString() == tostring(otherRid) then
- otherActor = actor
- elseif actor:toString() ~= tostring(otherRid) then
- otherActor = getactor(actor,otherRid)
- end
- local mountLogo = getplaydef(otherActor,"T$mountlogo")
- local rank = nil
- if not mountLogo then
- rank = 0
- mountLogo = {}
- mountLogo["logo"] = 0
- mountLogo["rank"] = 0
- setplaydef(otherActor,"T$mountlogo",mountLogo)
- elseif mountLogo then
- rank = mountLogo["rank"]
- end
- sendluamsg(actor,LuaMessageIdToClient.RES_OTHER_MOUNT_RANK,rank)
- end
- -- 检查坐骑详细信息
- function Mount.checkMountTime(actor)
- local allTimeLimitMount = getplaydef(actor, TIME_LIMIT_MOUNT)
- if table.isEmpty(allTimeLimitMount) then
- return
- end
- local time = getbaseinfo(actor,"nowsec")
- local newAllTimeLimitMount = {}
- for index, timeLimitMount in pairs(allTimeLimitMount) do
- if time > timeLimitMount.endTime then
- local msgData = {}
- msgData[1] = timeLimitMount.id
- msgData[2] = 1
- Mount.mountStoreToBag(actor, msgData)
- else
- table.insert(newAllTimeLimitMount,timeLimitMount)
- end
- end
- setplaydef(actor, TIME_LIMIT_MOUNT,newAllTimeLimitMount)
- end
- -- 脱下坐骑信息 需要脱下坐骑id
- function Mount.mountStoreToBag(actor, msgData)
- local takeOffResult = takeoffmount(actor, msgData[1],msgData[2])
- local result = {}
- result["result"] = takeOffResult
- result["mountid"] = msgData
- sendluamsg(actor, LuaMessageIdToClient.RES_MOUNT_STORE_TO_BAG, result)
- local mountLogo = getplaydef(actor,"T$mountlogo")
- if mountLogo then
- local rank = mountLogo["rank"]
- if rank and rank == msgData then
- mountLogo["rank"] = 0
- setplaydef(actor,"T$mountlogo",mountLogo)
- Mount.sendMountLogo(actor)
- end
- end
- local allMount = getallmount(actor)
- Mount.allMountInfo(actor)
- Mount.allAttInfo(actor, allMount)
- Mount.sendCurrentRideMount(actor)
- end
- -- 骑乘坐骑 需要骑乘坐骑id
- function Mount.ridingMount(actor, msgData)
- if not msgData or not msgData[1] then
- local curWearMountId = getrolefield(actor,"role.rolemount.curwearmountid")
- if curWearMountId == 0 then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT360)
- return
- end
- msgData = {0}
- -- error(msgData)
- end
- local rideResult = ridemount(actor, msgData[1])
- local result = {}
- result["mountid"] = rideResult
- sendluamsg(actor, LuaMessageIdToClient.RES_RIDING_MOUNT, result)
- -- 骑乘后属性发生改变
- local allMount = getallmount(actor)
- Mount.allAttInfo(actor, allMount)
- Mount.sendCurrentRideMount(actor)
- end
- -- 取消骑乘坐骑 可以什么都不传,也可以穿当前骑乘坐骑id
- function Mount.cancelRidingMount(actor, msgData)
- local cancelRideResult = cancelridemount(actor, msgData[1])
- local result = {}
- result["result"] = cancelRideResult
- result["mountid"] = msgData[1]
- sendluamsg(actor, LuaMessageIdToClient.RES_CANCEL_RIDING_MOUNT, result)
- -- 取消骑乘后属性发生改变
- local allMount = getallmount(actor)
- Mount.allAttInfo(actor, allMount)
- Mount.sendCurrentRideMount(actor)
- end
- -- 获取坐骑信息
- function Mount.allMountInfo(actor)
- local allMount = getallmount(actor)
- if table.isEmpty(allMount) then
- -- 没有坐骑,发送空的坐骑信息
- jprint(actor,"没有坐骑,发送空的坐骑信息")
- sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_INFO, allMount)
- Mount.allAttInfo(actor, allMount)
- return
- end
- local allTimeLimitMount = getplaydef(actor, TIME_LIMIT_MOUNT)
- jprint("allTimeLimitMount",allTimeLimitMount)
- if table.isEmpty(allTimeLimitMount) then
- -- 没有限时坐骑,直接发送坐骑信息即可
- jprint(actor,"没有限时坐骑,直接发送坐骑信息即可")
- sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_INFO, allMount)
- Mount.allAttInfo(actor, allMount)
- return
- end
- for index, timeLimitMount in pairs(allTimeLimitMount) do
- for index, mountInfo in pairs(allMount) do
- if timeLimitMount.id == tonumber(mountInfo.mountcfgid) then
- mountInfo.time = timeLimitMount.endTime
- jprint("设置成功",mountInfo)
- end
- end
- end
- jprint("全部坐骑信息",allMount)
- sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_INFO, allMount)
- Mount.allAttInfo(actor, allMount)
- end
- -- 获取坐骑信息
- function Mount.mountDetail(actor,msgData)
- local mount = mountdetailinfo(actor,msgData[1])
- local mountAtt = Mount.mountAttInfo(actor, mount,1)
- local result = {}
- result["item"] = mount["itematt"]
- result["att"] = mountAtt
- result["level"] = mount["level"]
- result["experience"] = mount["experience"]
- sendluamsg(actor,LuaMessageIdToClient.RES_MOUNT_DETAIL_INFO,result)
- end
- -- 设置坐骑显示与隐藏
- function Mount.mountShow(actor,msgData)
- local curRideMountId = getrolefield(actor,"role.rolemount.curridemountid")
- if curRideMountId == 0 then
- noticeTip.noticeinfo(actor, StringIdConst.TEXT361)
- return
- end
- mountisshow(actor,msgData)
- end
- -- 计算单个坐骑的属性
- function Mount.mountAttInfo(actor, mount,mountDetail)
- local mountAtt = {}
- local mountCfgId = mount["mountcfgid"]
- local wear = mount["wear"]
- if tonumber(wear) == 1 or mountDetail == 1 then
- local speed = ConfigDataManager.getTableValue("cfg_mount", "speed", "id", mountCfgId)
- Mount.mergemountatt(mountAtt, "318022", tonumber(speed))
- end
- local mountAttString = ConfigDataManager.getTableValue("cfg_mount", "attribute", "id", mountCfgId)
- local mountAttS = string.split(mountAttString, "|")
- for _, attInfo in pairs(mountAttS) do
- local attDetail = string.split(attInfo, "#")
- Mount.mergemountatt(mountAtt, attDetail[1], tonumber(attDetail[2]))
- end
- local mountEquip = ConfigDataManager.getTableValue("cfg_mount", "mountEquip", "id", mountCfgId)
- local itematt = mount["itematt"]
- if itematt and tonumber(mountEquip) == 1 then
- for index, itemInfo in pairs(itematt) do
- local itemDetailAtt = itemInfo["att"]
- for attCfgId, attValue in pairs(itemDetailAtt) do
- Mount.mergemountatt(mountAtt, attCfgId, tonumber(attValue))
- end
- end
- end
- local level = mount["level"]
- if level > 0 then
- local equipPriestConfigTable = ConfigDataManager.getTable("cfg_equip_priest", "type", HEI_WANG_MA_TYPE)
- if not table.isNullOrEmpty(equipPriestConfigTable) then
- for index, equipPriestConfig in pairs(equipPriestConfigTable) do
- info("equipPriestConfig",equipPriestConfig)
- local hawkAtt = equipPriestConfig["hawkatt"]
- if not string.isNullOrEmpty(hawkAtt) and tonumber(equipPriestConfig["hawklv"]) <= level then
- local hawkAttTable = string.split(hawkAtt, "|")
- for _, attInfo in pairs(hawkAttTable) do
- local attDetail = string.split(attInfo, "#")
- Mount.mergemountatt(mountAtt, attDetail[1], tonumber(attDetail[2]))
- end
- end
- end
- end
- end
- return mountAtt
- end
- -- 计算坐骑全部属性
- function Mount.allAttInfo(actor, allMount)
- local allMountAttInfo = {}
- if allMount then
- for index, mount in pairs(allMount) do
- local mountAtt = Mount.mountAttInfo(actor,mount,0)
- if mountAtt then
- Mount.totalMountAtt(allMountAttInfo, mountAtt)
- end
- end
- end
- sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_ATT_INFO, allMountAttInfo)
- end
- function Mount.totalMountAtt(allMountAttInfo, mountAtt)
- for attCfgId, attValue in pairs(mountAtt) do
- Mount.mergemountatt(allMountAttInfo, attCfgId, attValue)
- end
- end
- function Mount.mergemountatt(allAtt, attCfgId, attValue)
- local num = allAtt[attCfgId]
- if num == 0 or num == nil then
- allAtt[attCfgId] = tonumber(attValue)
- else
- allAtt[attCfgId] = num + tonumber(attValue)
- end
- end
|