RoleAttr_1.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. RoleAttr = {}
  2. local this = {}
  3. ---@class RoleAttrProgrammeData
  4. ---@field current number 当前方案
  5. ---@field freeSwitchAttrPointData table<number,FreeSwitchAttrPointData>
  6. ---@class FreeSwitchAttrPointData
  7. ---@field id number
  8. ---@field attr table
  9. ---@field name string
  10. this.ROLE_ATTR_CHANGE_LINE_KEY = "T$_ROLE_ATTR_CHANGE_LINE_KEY"
  11. RoleAttrKey = {
  12. UNION_ARMBAND_LEVEL = "roleunionarmbandlevelattrkey", -- 战盟臂章等级属性
  13. UNION_ARMBAND_STRONG = "roleunionarmbandstrongattrkey", -- 战盟臂章强化属性
  14. PRIVILEGE_MONTH_DROP_RATE = "privilegemonthdroprateattrpointkey", -- 月卡特权增加爆率
  15. EXP_BOOST_ITEM_USE = "roleexpboostitemuseattrpointkey", -- 经验药水使用增加杀怪经验提升
  16. VIP_GIFT_PACK = "rolevipgiftpackprivilegekey", -- VIP特权增加属性
  17. ANGEL_MAJOR_EQUIPMENT = "roleangelmajorattrkey_%s", -- 大天使装备属性
  18. ANGEL_MAJOR_TALENT = "roleangelmajorattrkey", -- 大天使天赋属性
  19. ANGEL_GRAIL = "roleangelgrailattrkey_%s", -- 大天使圣杯属性
  20. PRIVILEGE_EXP_BOOST = "roleexpboostprivilegekey", -- 经验提升特权
  21. ANGEL_GRAIL_SUIT = "roleangelgrailsuitattrkey", -- 大天使圣杯套装属性
  22. TWOWEAPONSATTRS = "twoweaponsattrs", -- 双手武器属性
  23. }
  24. function RoleAttr.levelup(actor, level, oldlevel)
  25. this.addAttrPointByCareer(actor, level, oldlevel)
  26. end
  27. -- 添加属性,并把属性保存起来,下次添加属性自动叠加
  28. function RoleAttr.addAndSaveRoleAttr(actor, key, attr_map)
  29. this.addAndSaveRoleAttr(actor, key, attr_map)
  30. end
  31. -- 减少属性,并把属性保存起来,下次添加属性自动相减
  32. function RoleAttr.reduceAndSaveRoleAttr(actor, key, attr_map)
  33. this.reduceAndSaveRoleAttr(actor, key, attr_map)
  34. end
  35. -- 清空指定Key的属性和保存的数据
  36. function RoleAttr.clearRoleAttrAndDB(actor, key)
  37. this.clearRoleAttrAndDB(actor, key)
  38. end
  39. function RoleAttr.createrole(actor)
  40. -- this.createRoleAddAttrPointByCareer(actor)
  41. end
  42. function RoleAttr.setPrivilegeAttrPointProgramme(actor, data)
  43. this.setPrivilegeAttrPointProgramme(actor, data)
  44. end
  45. function RoleAttr.getPrivilegeAttrPointProgramme(actor)
  46. local data = this.getPrivilegeData(actor)
  47. -- this.jprint("--- 获取属性点方案数据 ---")
  48. -- this.jprint(data)
  49. sendluamsg(actor, LuaMessageIdToClient.RES_GET_ROLE_ATTR_POINT_PROGRAMME, data)
  50. end
  51. function RoleAttr.changePrivilegeAttrPointProgramme(actor, key)
  52. this.changePrivilegeAttrPointProgramme(actor, key)
  53. end
  54. -----------------------------------
  55. function this.createRoleAddAttrPointByCareer(actor)
  56. --local level = getbaseinfo(actor, "level")
  57. --this.addAttrPointByCareer(actor, level, 0)
  58. end
  59. function this.setPrivilegeAttrPointProgramme(actor, param)
  60. local data = this.getPrivilegeData(actor)
  61. if table.isEmpty(data) then
  62. data = {}
  63. data.current = 1
  64. end
  65. -- this.jprint("--- param ---")
  66. this.jprint(param)
  67. if table.isEmpty(data.freeSwitchAttrPointData) then
  68. data.freeSwitchAttrPointData = {}
  69. end
  70. data.freeSwitchAttrPointData[param.id] = param
  71. this.setPrivilegeData(actor, data)
  72. RoleAttr.getPrivilegeAttrPointProgramme(actor)
  73. end
  74. ---@return RoleAttrProgrammeData
  75. function this.getPrivilegeData(actor)
  76. return getplaydef(actor, this.ROLE_ATTR_CHANGE_LINE_KEY)
  77. end
  78. function this.setPrivilegeData(actor, data)
  79. setplaydef(actor, this.ROLE_ATTR_CHANGE_LINE_KEY, data)
  80. end
  81. function this.changePrivilegeAttrPointProgramme(actor, key)
  82. local is_has = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.SWITCHING_POINT_SCHEME)
  83. if not is_has then
  84. -- this.jprint("玩家没有权限")
  85. return
  86. end
  87. local data = this.getPrivilegeData(actor)
  88. if table.isEmpty(data) then
  89. sendluamsg(actor, LuaMessageIdToClient.RES_CHANGE_ROLE_ATTR_POINT_PROGRAMME, key)
  90. return
  91. end
  92. -- this.jprint("key")
  93. -- this.jprint(key)
  94. -- this.jprint("--- data ---")
  95. -- this.jprint(data)
  96. if data.current == key then
  97. -- this.jprint("当前方案和要切换的方案一样,无需切换")
  98. return
  99. end
  100. data.current = key
  101. this.setPrivilegeData(actor, data)
  102. resetattrpoint(actor, 1, 0)
  103. local programme_data = data.freeSwitchAttrPointData[key]
  104. if table.isEmpty(programme_data) then
  105. sendluamsg(actor, LuaMessageIdToClient.RES_CHANGE_ROLE_ATTR_POINT_PROGRAMME, key)
  106. return
  107. end
  108. -- this.jprint("-- programme_data --")
  109. -- this.jprint(programme_data)
  110. if not table.isEmpty(programme_data.attr) then
  111. attr_map = {}
  112. for _, v in pairs(programme_data.attr) do
  113. attr_map[v.type] = v.num
  114. end
  115. -- this.jprint("-- attr_map --")
  116. -- this.jprint(attr_map)
  117. deployattrpoint(actor, attr_map, 1)
  118. end
  119. sendluamsg(actor, LuaMessageIdToClient.RES_CHANGE_ROLE_ATTR_POINT_PROGRAMME, key)
  120. end
  121. function this.addAttrPointByCareer(actor, level, oldlevel)
  122. this.jprint(oldlevel)
  123. this.jprint(level)
  124. local career = getbaseinfo(actor, "getbasecareer")
  125. career = tonumber(career)
  126. -- this.jprint("职业:" .. career)
  127. local key = "";
  128. if career == 1 then
  129. key = "swordsmanAttribute"
  130. end
  131. if career == 2 then
  132. key = "magicianAttribute"
  133. end
  134. if career == 3 then
  135. key = "archerAttributes"
  136. end
  137. if career == 4 then
  138. key = "magicSwordsmanAttribute"
  139. end
  140. if career == 5 then
  141. key = "saintMentorAttribute"
  142. end
  143. if career == 6 then
  144. key = "summonerAttribute"
  145. end
  146. if key == "" then
  147. -- this.jprint("职业错误")
  148. return
  149. end
  150. local attr_map = this.getAttrMap(actor)
  151. for i = oldlevel + 1, level do
  152. this.calculAttr(actor, i, key, attr_map)
  153. end
  154. if next(attr_map) == nil then
  155. return
  156. end
  157. -- this.jprint("添加属性点")
  158. -- this.jprint(attr_map)
  159. this.setAttrMap(actor, attr_map)
  160. addrolekmlattributes(actor, "luaaddattrpointbycareer", attr_map)
  161. end
  162. function this.getAttrMap(actor)
  163. local data = getplaydef(actor, "T$_luaaddattrpointbycareer")
  164. if data == nil then
  165. data = {}
  166. end
  167. return data
  168. end
  169. function this.setAttrMap(actor, attr_map)
  170. setplaydef(actor, "T$_luaaddattrpointbycareer", attr_map)
  171. end
  172. function this.calculAttr(actor, level, key, attr_map)
  173. local attr_map_str = ConfigDataManager.getTableValue("cfg_level", key, "id", level)
  174. if attr_map_str == nil or attr_map_str == "" then
  175. return
  176. end
  177. local map = string.toIntIntMap(attr_map_str, "#", "|")
  178. -- this.jprint("map")
  179. for attr_id, value in pairs(map) do
  180. -- this.jprint(attr_id)
  181. -- this.jprint(value)
  182. local attr_value = attr_map[attr_id]
  183. -- this.jprint("attr_value")
  184. -- this.jprint(attr_value)
  185. if attr_value ~= nil and tonumber(attr_value) > 0 then
  186. attr_value = attr_value + value
  187. else
  188. attr_value = value
  189. end
  190. attr_map[attr_id] = attr_value
  191. end
  192. end
  193. function this.addAndSaveRoleAttr(actor, key, attr_map)
  194. if table.isEmpty(attr_map) then
  195. return
  196. end
  197. local db_key = "T$_" .. key
  198. local data = getplaydef(actor, db_key)
  199. if table.isEmpty(data) then
  200. data = attr_map
  201. else
  202. for attr_id, value in pairs(attr_map) do
  203. if data[attr_id] == nil then
  204. data[attr_id] = value
  205. else
  206. data[attr_id] = data[attr_id] + value
  207. end
  208. end
  209. end
  210. setplaydef(actor, db_key, data)
  211. addrolekmlattributes(actor, key, data)
  212. -- this.jprint("---- 添加属性 ----")
  213. -- this.jprint("key")
  214. -- this.jprint(key)
  215. -- this.jprint("data")
  216. -- this.jprint(data)
  217. end
  218. function this.reduceAndSaveRoleAttr(actor, key, attr_map)
  219. if table.isEmpty(attr_map) then
  220. return
  221. end
  222. local db_key = "T$_" .. key
  223. local data = getplaydef(actor, db_key)
  224. if table.isEmpty(data) then
  225. data = {}
  226. end
  227. for attr_id, value in pairs(attr_map) do
  228. if data[attr_id] ~= nil then
  229. data[attr_id] = math.max(0, data[attr_id] - value)
  230. end
  231. end
  232. setplaydef(actor, db_key, data)
  233. addrolekmlattributes(actor, key, data)
  234. end
  235. function this.clearRoleAttrAndDB(actor, key)
  236. local db_key = "T$_" .. key
  237. setplaydef(actor, db_key, {})
  238. addrolekmlattributes(actor, key, {})
  239. end
  240. ---------------------------- 日志打印 -----------------------------
  241. this.log_open = false
  242. function this.jprint(param)
  243. if not this.log_open then
  244. return
  245. end
  246. if param == nil then
  247. param = "error! 输出内容为空. nil"
  248. end
  249. jprint(param)
  250. end
  251. function this.loginfo(actor, param)
  252. if not this.log_open then
  253. return
  254. end
  255. if param == nil then
  256. param = "error! 日志输出内容为空. nil"
  257. end
  258. jprint(param)
  259. info(actor, param)
  260. end
  261. -- 设置角色属性加成方式
  262. function RoleAttr.setRoleAttAddWay(actor, msgData)
  263. local addAttWay = setroleattaddway(actor, msgData[1])
  264. sendluamsg(actor, LuaMessageIdToClient.RES_ROLE_ATT_ADD_WAY, addAttWay)
  265. end
  266. -- 设置角色属性加成方式
  267. function RoleAttr.getRoleAttAddWay(actor)
  268. local addAttWay = getrolefield(actor, "role.RoleAttribute.attrAddWay")
  269. sendluamsg(actor, LuaMessageIdToClient.RES_ROLE_ATT_ADD_WAY, addAttWay)
  270. end
  271. function RoleAttr.transferCareer(actor, careerName)
  272. local wash = ConfigDataManager.getTableValue("cfg_career", "wash", "name", careerName)
  273. if tonumber(wash) == 1 then
  274. resetattrpoint(actor, 1)
  275. end
  276. local rec = getplaydef(actor, PlayerDefKey.player.CAREER_REC)
  277. local msgData = {}
  278. if not string.isNullOrEmpty(rec) then
  279. msgData[1] = rec
  280. setplaydef(actor, PlayerDefKey.player.CAREER_REC, nil)
  281. else
  282. local careerRec = ConfigDataManager.getTableValue("cfg_career", "careerRec", "name", careerName)
  283. local careerRecTable = string.split(careerRec, "|")
  284. if #careerRecTable ~= 1 then
  285. msgData[1] = -1
  286. end
  287. end
  288. if not table.isNullOrEmpty(msgData) then
  289. RoleAttr.setRoleAttAddWay(actor, msgData)
  290. end
  291. end
  292. -- @description 脚本计算角色最终属性
  293. -- @param 玩家对象
  294. -- @return
  295. function RoleAttr.CalcPlayFinalAttr(actor)
  296. --攻速加成=(1+attackSpeed*攻击速度转换系数)*(AniSpeedBonus)-1
  297. local aniSpeed = getattrinfo(actor, "attackSpeed")
  298. local aniSpeedBonus = getattrinfo(actor, "AniSpeedBonus")
  299. local coefficient = tonumber(ConfigDataManager.getTableValue("cfg_global", "value", "id", 7001))
  300. if coefficient == nil then
  301. coefficient = 0.0067
  302. else
  303. coefficient = coefficient / 10000
  304. end
  305. local atkSpeed = (1 + aniSpeed * coefficient) * aniSpeedBonus - 1
  306. --jprint(name,"属性计算","aniSpeed",aniSpeed)
  307. --jprint(name,"属性计算","coefficient",coefficient)
  308. --jprint(name,"属性计算","aniSpeedBonus",aniSpeedBonus)
  309. --jprint(name,"属性计算","aniSpeed",aniSpeed)
  310. --jprint(name,"属性计算","attackSpeedBonus",atkSpeed)
  311. local id = attrname2id("attackSpeedBonus")
  312. local remarks = tonumber(ConfigDataManager.getTableValue("cfg_att_info", "remarks", "id", id))
  313. if remarks == 2 then
  314. atkSpeed = atkSpeed * 10000
  315. if atkSpeed < 0 then
  316. atkSpeed = 0
  317. end
  318. end
  319. local ret = {}
  320. local innerData = { id = id, value = atkSpeed }
  321. table.insert(ret, innerData)
  322. -- 自动恢复魔法
  323. local mpRecovery = getattrinfo(actor, "MPFullRecoverRate")
  324. if mpRecovery and mpRecovery ~= "" and mpRecovery > 0 then
  325. local roleInfo = getsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO)
  326. if not table.isEmpty(roleInfo) then
  327. local exist = false
  328. for _, v in pairs(roleInfo) do
  329. if actor:toString() == v["actor"]:toString() then
  330. exist = true
  331. end
  332. end
  333. if not exist then
  334. table.insert(roleInfo, {
  335. actor = actor,
  336. recovery = mpRecovery
  337. })
  338. setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, roleInfo)
  339. end
  340. else
  341. local temp = {}
  342. table.insert(temp, {
  343. actor = actor,
  344. recovery = mpRecovery
  345. })
  346. setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, temp)
  347. GlobalTimer.setontimerex(TimerIds.AUTO_RECOVERY_MAGIC, TimeUnit.SECOND * 3)
  348. end
  349. end
  350. return ret
  351. end
  352. --- 自动恢复魔法
  353. function RoleAttr.autoRecoveryMagic()
  354. local roleInfo = getsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO)
  355. if not table.isEmpty(roleInfo) then
  356. for key, actorInfo in pairs(roleInfo) do
  357. local actor = actorInfo["actor"]
  358. local mpFullRecoverRate = actorInfo["recovery"]
  359. if mpFullRecoverRate > 0 then
  360. local mp = getbaseinfo(actor, "mp")
  361. local maxMp = getbaseinfo(actor, "maxmp")
  362. local incrementMp = maxMp * mpFullRecoverRate
  363. if mp + incrementMp > maxMp then
  364. setmp(actor, maxMp)
  365. table.remove(roleInfo, key)
  366. else
  367. setmp(actor, mp + incrementMp)
  368. end
  369. else
  370. table.remove(roleInfo, key)
  371. end
  372. end
  373. setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, roleInfo)
  374. if table.isEmpty(roleInfo) then
  375. GlobalTimer.setofftimer(TimerIds.AUTO_RECOVERY_MAGIC)
  376. end
  377. end
  378. end
  379. --- 切换地图后将actor对象mapId修改
  380. ---@param actor table 玩家对象
  381. ---@param mapCfgId number 地图配置id
  382. function RoleAttr.enterMap(actor, mapCfgId)
  383. local roleInfo = getsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO)
  384. if not table.isEmpty(roleInfo) then
  385. for k, v in pairs(roleInfo) do
  386. local player = v["actor"]
  387. local recovery = v["recovery"]
  388. if player:toString() == actor:toString() then
  389. local getActor = getactor(actor, player:toString(), gamemap.getMapKey(mapCfgId, 1))
  390. table.remove(roleInfo, k)
  391. table.insert(roleInfo, {
  392. actor = getActor,
  393. recovery = recovery
  394. })
  395. break
  396. end
  397. end
  398. setsysvar(SystemVarConst.AUTO_RECOVERY_MAGIC_ROLE_INFO, roleInfo)
  399. end
  400. end