Mount.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. Mount = {}
  2. local this = {}
  3. MOUNT_LIMIT_TIME = 60 * 60
  4. TIME_LIMIT_MOUNT = "T$timeLimitMount"
  5. local HEI_WANG_MA_TYPE = 19
  6. -- 发送当前骑乘坐骑信息
  7. function Mount.sendCurrentRideMount(actor)
  8. local curRideMountId = getrolefield(actor,"role.rolemount.curridemountid")
  9. sendluamsg(actor, LuaMessageIdToClient.RES_CURRENT_RIDE_MOUNT, curRideMountId)
  10. end
  11. -- 坐骑穿戴装备
  12. function Mount.putOnItem(actor, msgData)
  13. local mountEquip = ConfigDataManager.getTableValue("cfg_mount","mountEquip","id",msgData[1])
  14. if mountEquip == "0" then
  15. noticeTip.noticeinfo(actor, StringIdConst.TEXT359)
  16. end
  17. local putOnResult = mountputitem(actor, msgData[1],msgData[2],msgData[3])
  18. local result = {}
  19. result["result"] = putOnResult
  20. result["pos"] = msgData[3]
  21. result["itemcfgid"] = msgData[4]
  22. result["itemid"] = msgData[5]
  23. sendluamsg(actor, LuaMessageIdToClient.RES_MOUNT_PUT_ON_ITEM, result)
  24. Mount.mountDetail(actor,msgData)
  25. Mount.sendCurrentRideMount(actor)
  26. end
  27. -- 坐骑脱下装备
  28. function Mount.takeOffItem(actor, msgData)
  29. local takeOffResult = mountoffitem(actor, msgData[1],msgData[2])
  30. local result = {}
  31. result["result"] = takeOffResult
  32. result["pos"] = msgData[2]
  33. sendluamsg(actor, LuaMessageIdToClient.RES_MOUNT_TAKE_OFF_ITEM, result)
  34. Mount.mountDetail(actor,msgData)
  35. Mount.sendCurrentRideMount(actor)
  36. end
  37. -- 穿戴坐骑信息 需要穿戴坐骑背包索引
  38. function Mount.mountBagToStore(actor, msgData)
  39. local itemcfgid = msgData[2]
  40. local mountConfig = ConfigDataManager.getTable("cfg_mount","itemId",itemcfgid)
  41. if table.isEmpty(mountConfig) then
  42. error("坐骑配置信息中没有itemId为:" .. itemcfgid.."的配置项")
  43. return
  44. end
  45. local mountInfo = mountConfig[1]
  46. jprint("mountInfo",mountInfo)
  47. local limitedtype = mountInfo.limitedtype
  48. if limitedtype and limitedtype == "1" then
  49. -- 限时坐骑
  50. jprint("限时坐骑")
  51. local allTimeLimitMount = getplaydef(actor, TIME_LIMIT_MOUNT)
  52. local timeLimitMount = {}
  53. if table.isEmpty(allTimeLimitMount) then
  54. allTimeLimitMount = {}
  55. timeLimitMount = {
  56. time = getbaseinfo(actor,"nowsec"),
  57. itemCfgId = tonumber(mountInfo.icon),
  58. id = tonumber(mountInfo.id),
  59. endTime = getbaseinfo(actor,"nowsec") + tonumber(mountInfo.limitedtime) * MOUNT_LIMIT_TIME,
  60. }
  61. else
  62. local have = false
  63. for index, timeLimitMount in pairs(allTimeLimitMount) do
  64. if timeLimitMount.itemCfgId == tonumber(mountInfo.icon) then
  65. have = true
  66. end
  67. end
  68. if have then
  69. tipinfo(actor,"已经激活过该坐骑")
  70. return
  71. end
  72. timeLimitMount = {
  73. time = getbaseinfo(actor,"now"),
  74. itemCfgId = tonumber(mountInfo.icon),
  75. id = tonumber(mountInfo.id),
  76. endTime = getbaseinfo(actor,"nowsec") + tonumber(mountInfo.limitedtime) * MOUNT_LIMIT_TIME
  77. }
  78. end
  79. table.insert(allTimeLimitMount,timeLimitMount)
  80. setplaydef(actor, TIME_LIMIT_MOUNT,allTimeLimitMount)
  81. end
  82. local putOnResult = putonmount(actor, msgData[1])
  83. local result = {}
  84. result["result"] = putOnResult
  85. result["mountid"] = msgData
  86. sendluamsg(actor, LuaMessageIdToClient.RES_MOUNT_BAG_TO_STORE, result)
  87. Mount.sendCurrentRideMount(actor)
  88. Mount.setMountLogo(actor)
  89. end
  90. -- 设置坐骑标志
  91. function Mount.setMountLogo(actor)
  92. local mountLogo = getplaydef(actor,"T$mountlogo")
  93. if not mountLogo then
  94. local mountLogo = {}
  95. mountLogo["rank"] = 0
  96. end
  97. mountLogo["logo"] = 1
  98. setplaydef(actor,"T$mountlogo",mountLogo)
  99. Mount.sendMountLogo(actor)
  100. end
  101. -- 设置坐骑排行
  102. function Mount.setMountRank(actor,msgData)
  103. local mountLogo = getplaydef(actor,"T$mountlogo")
  104. mountLogo["rank"] = msgData
  105. setplaydef(actor,"T$mountlogo",mountLogo)
  106. Mount.sendMountLogo(actor)
  107. end
  108. -- 发送坐骑默认骑乘信息和排行信息
  109. function Mount.sendMountLogo(actor)
  110. local mountLogo = getplaydef(actor,"T$mountlogo")
  111. if not mountLogo then
  112. mountLogo = {}
  113. mountLogo["logo"] = 0
  114. mountLogo["rank"] = 0
  115. setplaydef(actor,"T$mountlogo",mountLogo)
  116. end
  117. sendluamsg(actor,LuaMessageIdToClient.RES_MOUNT_LOGO,mountLogo)
  118. end
  119. -- 发送其他人坐骑默认骑乘信息和排行信息
  120. function Mount.sendOtherMountRank(actor,otherRid)
  121. local otherActor = nil
  122. if actor:toString() == tostring(otherRid) then
  123. otherActor = actor
  124. elseif actor:toString() ~= tostring(otherRid) then
  125. otherActor = getactor(actor,otherRid)
  126. end
  127. local mountLogo = getplaydef(otherActor,"T$mountlogo")
  128. local rank = nil
  129. if not mountLogo then
  130. rank = 0
  131. mountLogo = {}
  132. mountLogo["logo"] = 0
  133. mountLogo["rank"] = 0
  134. setplaydef(otherActor,"T$mountlogo",mountLogo)
  135. elseif mountLogo then
  136. rank = mountLogo["rank"]
  137. end
  138. sendluamsg(actor,LuaMessageIdToClient.RES_OTHER_MOUNT_RANK,rank)
  139. end
  140. -- 检查坐骑详细信息
  141. function Mount.checkMountTime(actor)
  142. local allTimeLimitMount = getplaydef(actor, TIME_LIMIT_MOUNT)
  143. if table.isEmpty(allTimeLimitMount) then
  144. return
  145. end
  146. local time = getbaseinfo(actor,"nowsec")
  147. local newAllTimeLimitMount = {}
  148. for index, timeLimitMount in pairs(allTimeLimitMount) do
  149. if time > timeLimitMount.endTime then
  150. local msgData = {}
  151. msgData[1] = timeLimitMount.id
  152. msgData[2] = 1
  153. Mount.mountStoreToBag(actor, msgData)
  154. else
  155. table.insert(newAllTimeLimitMount,timeLimitMount)
  156. end
  157. end
  158. setplaydef(actor, TIME_LIMIT_MOUNT,newAllTimeLimitMount)
  159. end
  160. -- 脱下坐骑信息 需要脱下坐骑id
  161. function Mount.mountStoreToBag(actor, msgData)
  162. local takeOffResult = takeoffmount(actor, msgData[1],msgData[2])
  163. local result = {}
  164. result["result"] = takeOffResult
  165. result["mountid"] = msgData
  166. sendluamsg(actor, LuaMessageIdToClient.RES_MOUNT_STORE_TO_BAG, result)
  167. local mountLogo = getplaydef(actor,"T$mountlogo")
  168. if mountLogo then
  169. local rank = mountLogo["rank"]
  170. if rank and rank == msgData then
  171. mountLogo["rank"] = 0
  172. setplaydef(actor,"T$mountlogo",mountLogo)
  173. Mount.sendMountLogo(actor)
  174. end
  175. end
  176. local allMount = getallmount(actor)
  177. Mount.allMountInfo(actor)
  178. Mount.allAttInfo(actor, allMount)
  179. Mount.sendCurrentRideMount(actor)
  180. end
  181. -- 骑乘坐骑 需要骑乘坐骑id
  182. function Mount.ridingMount(actor, msgData)
  183. if not msgData or not msgData[1] then
  184. local curWearMountId = getrolefield(actor,"role.rolemount.curwearmountid")
  185. if curWearMountId == 0 then
  186. noticeTip.noticeinfo(actor, StringIdConst.TEXT360)
  187. return
  188. end
  189. msgData = {0}
  190. -- error(msgData)
  191. end
  192. local rideResult = ridemount(actor, msgData[1])
  193. local result = {}
  194. result["mountid"] = rideResult
  195. sendluamsg(actor, LuaMessageIdToClient.RES_RIDING_MOUNT, result)
  196. -- 骑乘后属性发生改变
  197. local allMount = getallmount(actor)
  198. Mount.allAttInfo(actor, allMount)
  199. Mount.sendCurrentRideMount(actor)
  200. end
  201. -- 取消骑乘坐骑 可以什么都不传,也可以穿当前骑乘坐骑id
  202. function Mount.cancelRidingMount(actor, msgData)
  203. local cancelRideResult = cancelridemount(actor, msgData[1])
  204. local result = {}
  205. result["result"] = cancelRideResult
  206. result["mountid"] = msgData[1]
  207. sendluamsg(actor, LuaMessageIdToClient.RES_CANCEL_RIDING_MOUNT, result)
  208. -- 取消骑乘后属性发生改变
  209. local allMount = getallmount(actor)
  210. Mount.allAttInfo(actor, allMount)
  211. Mount.sendCurrentRideMount(actor)
  212. end
  213. -- 获取坐骑信息
  214. function Mount.allMountInfo(actor)
  215. local allMount = getallmount(actor)
  216. if table.isEmpty(allMount) then
  217. -- 没有坐骑,发送空的坐骑信息
  218. jprint(actor,"没有坐骑,发送空的坐骑信息")
  219. sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_INFO, allMount)
  220. Mount.allAttInfo(actor, allMount)
  221. return
  222. end
  223. local allTimeLimitMount = getplaydef(actor, TIME_LIMIT_MOUNT)
  224. jprint("allTimeLimitMount",allTimeLimitMount)
  225. if table.isEmpty(allTimeLimitMount) then
  226. -- 没有限时坐骑,直接发送坐骑信息即可
  227. jprint(actor,"没有限时坐骑,直接发送坐骑信息即可")
  228. sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_INFO, allMount)
  229. Mount.allAttInfo(actor, allMount)
  230. return
  231. end
  232. for index, timeLimitMount in pairs(allTimeLimitMount) do
  233. for index, mountInfo in pairs(allMount) do
  234. if timeLimitMount.id == tonumber(mountInfo.mountcfgid) then
  235. mountInfo.time = timeLimitMount.endTime
  236. jprint("设置成功",mountInfo)
  237. end
  238. end
  239. end
  240. jprint("全部坐骑信息",allMount)
  241. sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_INFO, allMount)
  242. Mount.allAttInfo(actor, allMount)
  243. end
  244. -- 获取坐骑信息
  245. function Mount.mountDetail(actor,msgData)
  246. local mount = mountdetailinfo(actor,msgData[1])
  247. local mountAtt = Mount.mountAttInfo(actor, mount,1)
  248. local result = {}
  249. result["item"] = mount["itematt"]
  250. result["att"] = mountAtt
  251. result["level"] = mount["level"]
  252. result["experience"] = mount["experience"]
  253. sendluamsg(actor,LuaMessageIdToClient.RES_MOUNT_DETAIL_INFO,result)
  254. end
  255. -- 设置坐骑显示与隐藏
  256. function Mount.mountShow(actor,msgData)
  257. local curRideMountId = getrolefield(actor,"role.rolemount.curridemountid")
  258. if curRideMountId == 0 then
  259. noticeTip.noticeinfo(actor, StringIdConst.TEXT361)
  260. return
  261. end
  262. mountisshow(actor,msgData)
  263. end
  264. -- 计算单个坐骑的属性
  265. function Mount.mountAttInfo(actor, mount,mountDetail)
  266. local mountAtt = {}
  267. local mountCfgId = mount["mountcfgid"]
  268. local wear = mount["wear"]
  269. if tonumber(wear) == 1 or mountDetail == 1 then
  270. local speed = ConfigDataManager.getTableValue("cfg_mount", "speed", "id", mountCfgId)
  271. Mount.mergemountatt(mountAtt, "318022", tonumber(speed))
  272. end
  273. local mountAttString = ConfigDataManager.getTableValue("cfg_mount", "attribute", "id", mountCfgId)
  274. local mountAttS = string.split(mountAttString, "|")
  275. for _, attInfo in pairs(mountAttS) do
  276. local attDetail = string.split(attInfo, "#")
  277. Mount.mergemountatt(mountAtt, attDetail[1], tonumber(attDetail[2]))
  278. end
  279. local mountEquip = ConfigDataManager.getTableValue("cfg_mount", "mountEquip", "id", mountCfgId)
  280. local itematt = mount["itematt"]
  281. if itematt and tonumber(mountEquip) == 1 then
  282. for index, itemInfo in pairs(itematt) do
  283. local itemDetailAtt = itemInfo["att"]
  284. for attCfgId, attValue in pairs(itemDetailAtt) do
  285. Mount.mergemountatt(mountAtt, attCfgId, tonumber(attValue))
  286. end
  287. end
  288. end
  289. local level = mount["level"]
  290. if level > 0 then
  291. local equipPriestConfigTable = ConfigDataManager.getTable("cfg_equip_priest", "type", HEI_WANG_MA_TYPE)
  292. if not table.isNullOrEmpty(equipPriestConfigTable) then
  293. for index, equipPriestConfig in pairs(equipPriestConfigTable) do
  294. info("equipPriestConfig",equipPriestConfig)
  295. local hawkAtt = equipPriestConfig["hawkatt"]
  296. if not string.isNullOrEmpty(hawkAtt) and tonumber(equipPriestConfig["hawklv"]) <= level then
  297. local hawkAttTable = string.split(hawkAtt, "|")
  298. for _, attInfo in pairs(hawkAttTable) do
  299. local attDetail = string.split(attInfo, "#")
  300. Mount.mergemountatt(mountAtt, attDetail[1], tonumber(attDetail[2]))
  301. end
  302. end
  303. end
  304. end
  305. end
  306. return mountAtt
  307. end
  308. -- 计算坐骑全部属性
  309. function Mount.allAttInfo(actor, allMount)
  310. local allMountAttInfo = {}
  311. if allMount then
  312. for index, mount in pairs(allMount) do
  313. local mountAtt = Mount.mountAttInfo(actor,mount,0)
  314. if mountAtt then
  315. Mount.totalMountAtt(allMountAttInfo, mountAtt)
  316. end
  317. end
  318. end
  319. sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_ATT_INFO, allMountAttInfo)
  320. end
  321. function Mount.totalMountAtt(allMountAttInfo, mountAtt)
  322. for attCfgId, attValue in pairs(mountAtt) do
  323. Mount.mergemountatt(allMountAttInfo, attCfgId, attValue)
  324. end
  325. end
  326. function Mount.mergemountatt(allAtt, attCfgId, attValue)
  327. local num = allAtt[attCfgId]
  328. if num == 0 or num == nil then
  329. allAtt[attCfgId] = tonumber(attValue)
  330. else
  331. allAtt[attCfgId] = num + tonumber(attValue)
  332. end
  333. end