Mount_1.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. LineManager.takeoffequip(actor)
  216. local allMount = getallmount(actor)
  217. if table.isEmpty(allMount) then
  218. -- 没有坐骑,发送空的坐骑信息
  219. jprint(actor,"没有坐骑,发送空的坐骑信息")
  220. sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_INFO, allMount)
  221. Mount.allAttInfo(actor, allMount)
  222. return
  223. end
  224. local allTimeLimitMount = getplaydef(actor, TIME_LIMIT_MOUNT)
  225. -- jprint("allTimeLimitMount",allTimeLimitMount)
  226. if table.isEmpty(allTimeLimitMount) then
  227. -- 没有限时坐骑,直接发送坐骑信息即可
  228. jprint(actor,"没有限时坐骑,直接发送坐骑信息即可")
  229. sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_INFO, allMount)
  230. Mount.allAttInfo(actor, allMount)
  231. return
  232. end
  233. for index, timeLimitMount in pairs(allTimeLimitMount) do
  234. for index, mountInfo in pairs(allMount) do
  235. if timeLimitMount.id == tonumber(mountInfo.mountcfgid) then
  236. mountInfo.time = timeLimitMount.endTime
  237. -- jprint("设置成功",mountInfo)
  238. end
  239. end
  240. end
  241. -- jprint("全部坐骑信息",allMount)
  242. sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_INFO, allMount)
  243. Mount.allAttInfo(actor, allMount)
  244. end
  245. -- 获取坐骑信息
  246. function Mount.mountDetail(actor,msgData)
  247. local mount = mountdetailinfo(actor,msgData[1])
  248. local mountAtt = Mount.mountAttInfo(actor, mount,1)
  249. local result = {}
  250. result["item"] = mount["itematt"]
  251. result["att"] = mountAtt
  252. result["level"] = mount["level"]
  253. result["experience"] = mount["experience"]
  254. sendluamsg(actor,LuaMessageIdToClient.RES_MOUNT_DETAIL_INFO,result)
  255. end
  256. -- 设置坐骑显示与隐藏
  257. function Mount.mountShow(actor,msgData)
  258. local curRideMountId = getrolefield(actor,"role.rolemount.curridemountid")
  259. if curRideMountId == 0 then
  260. -- noticeTip.noticeinfo(actor, StringIdConst.TEXT361)
  261. return
  262. end
  263. mountisshow(actor,msgData)
  264. end
  265. -- 计算单个坐骑的属性
  266. function Mount.mountAttInfo(actor, mount,mountDetail)
  267. local mountAtt = {}
  268. local mountCfgId = mount["mountcfgid"]
  269. local wear = mount["wear"]
  270. if tonumber(wear) == 1 or mountDetail == 1 then
  271. local speed = ConfigDataManager.getTableValue("cfg_mount", "speed", "id", mountCfgId)
  272. Mount.mergemountatt(mountAtt, "318022", tonumber(speed))
  273. end
  274. local mountAttString = ConfigDataManager.getTableValue("cfg_mount", "attribute", "id", mountCfgId)
  275. local mountAttS = string.split(mountAttString, "|")
  276. for _, attInfo in pairs(mountAttS) do
  277. local attDetail = string.split(attInfo, "#")
  278. Mount.mergemountatt(mountAtt, attDetail[1], tonumber(attDetail[2]))
  279. end
  280. local mountEquip = ConfigDataManager.getTableValue("cfg_mount", "mountEquip", "id", mountCfgId)
  281. local itematt = mount["itematt"]
  282. if itematt and tonumber(mountEquip) == 1 then
  283. for index, itemInfo in pairs(itematt) do
  284. local itemDetailAtt = itemInfo["att"]
  285. for attCfgId, attValue in pairs(itemDetailAtt) do
  286. Mount.mergemountatt(mountAtt, attCfgId, tonumber(attValue))
  287. end
  288. end
  289. end
  290. local level = mount["level"] or 0
  291. if level > 0 then
  292. local equipPriestConfigTable = ConfigDataManager.getTable("cfg_equip_priest", "type", HEI_WANG_MA_TYPE)
  293. if not table.isNullOrEmpty(equipPriestConfigTable) then
  294. for index, equipPriestConfig in pairs(equipPriestConfigTable) do
  295. -- info("equipPriestConfig",equipPriestConfig)
  296. local hawkAtt = equipPriestConfig["hawkatt"]
  297. if not string.isNullOrEmpty(hawkAtt) and tonumber(equipPriestConfig["hawklv"]) <= level then
  298. local hawkAttTable = string.split(hawkAtt, "|")
  299. for _, attInfo in pairs(hawkAttTable) do
  300. local attDetail = string.split(attInfo, "#")
  301. Mount.mergemountatt(mountAtt, attDetail[1], tonumber(attDetail[2]))
  302. end
  303. end
  304. end
  305. end
  306. end
  307. return mountAtt
  308. end
  309. -- 计算坐骑全部属性
  310. function Mount.allAttInfo(actor, allMount)
  311. local allMountAttInfo = {}
  312. if allMount then
  313. for index, mount in pairs(allMount) do
  314. local mountAtt = Mount.mountAttInfo(actor,mount,0)
  315. if mountAtt then
  316. Mount.totalMountAtt(allMountAttInfo, mountAtt)
  317. end
  318. end
  319. end
  320. sendluamsg(actor, LuaMessageIdToClient.RES_ALL_MOUNT_ATT_INFO, allMountAttInfo)
  321. end
  322. function Mount.totalMountAtt(allMountAttInfo, mountAtt)
  323. for attCfgId, attValue in pairs(mountAtt) do
  324. Mount.mergemountatt(allMountAttInfo, attCfgId, attValue)
  325. end
  326. end
  327. function Mount.mergemountatt(allAtt, attCfgId, attValue)
  328. local num = allAtt[attCfgId]
  329. if num == 0 or num == nil then
  330. allAtt[attCfgId] = tonumber(attValue)
  331. else
  332. allAtt[attCfgId] = num + tonumber(attValue)
  333. end
  334. end