Player.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by zhoutao.
  4. --- DateTime: 2024/10/28 14:17
  5. ---
  6. Player = {}
  7. --- 改变角色名称
  8. --- @param actor table 玩家对象
  9. --- @param msgData table 角色名称
  10. function Player.changeRoleName(actor, msgData)
  11. local roleName = msgData["roleName"]
  12. local isFirstChangeName = getplaydef(actor, PlayerDefKey.player.FIRST_CHANGE_NAME)
  13. if not string.isNullOrEmpty(isFirstChangeName) then
  14. local value = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.CHANGE_NAME_CARD_COST)
  15. local split = string.split(value, "|")
  16. local tmps = string.split(split[2], "#")
  17. local costItemId = tmps[1]
  18. local costCount = tmps[2]
  19. if not Bag.checkItem(actor, costItemId, costCount) then
  20. noticeTip.noticeinfo(actor, StringIdConst.TEXT346)
  21. return
  22. end
  23. if not checkrolename(actor, roleName) then
  24. jprint("角色名不合法 actor:" .. actor:toString() .. " roleName:" .. roleName)
  25. return
  26. end
  27. -- 从背包中移除指定数量的道具
  28. removeitemfrombag(actor, costItemId, costCount, 0, 9999, '角色改名')
  29. changerolename(actor, roleName)
  30. return
  31. else
  32. if not checkrolename(actor, roleName) then
  33. jprint("角色名不合法 actor:" .. actor:toString() .. " roleName:" .. roleName)
  34. return
  35. end
  36. changerolename(actor, roleName)
  37. setplaydef(actor, PlayerDefKey.player.FIRST_CHANGE_NAME, 1)
  38. end
  39. end
  40. --- 获取角色是否为首次改名
  41. --- @param actor table 玩家对象
  42. function Player.getRoleChangeNameInfo(actor)
  43. local isFirstChangeName = getplaydef(actor, PlayerDefKey.player.FIRST_CHANGE_NAME)
  44. sendluamsg(actor, LuaMessageIdToClient.RES_ROLE_IS_FIRST_CHANGE_NAME, isFirstChangeName and 1 or 0)
  45. end
  46. function Player.UpdateFightValue(actor)
  47. --默认战斗力=10*攻击+8*防御+0.25*生命+1400*1%卓越一击倍率+1160*1%幸运一击倍率+4670*1%双倍一击倍率+3400*1%攻速+3400*1%伤害加成
  48. local maxDC = getattrinfo(actor, "maxDC")
  49. local armor = getattrinfo(actor, "armor")
  50. local maxHP = getattrinfo(actor, "maxHP")
  51. local excellentDamageChance = math.max( getattrinfo(actor, "excellentDamageChance") ,1 )
  52. local criticalDamageChance = math.max( getattrinfo(actor, "criticalDamageChance"),1 )
  53. local doubleDamageChance =math.max( getattrinfo(actor, "doubleDamageChance"),1 )
  54. local attackSpeed = math.max( getattrinfo(actor, "attackSpeed"),1 )
  55. local damageRate = math.max( getattrinfo(actor, "damageRate"),1 )
  56. local result = 10 * maxDC + 8 * armor + 0.25 * maxHP + 1400 * excellentDamageChance * 0.01 +
  57. 1160 * criticalDamageChance * 0.01 +
  58. 4670 * doubleDamageChance * 0.01 +
  59. 3400 * attackSpeed * 0.01 + 3400 * damageRate * 0.01
  60. savefightvalue(actor, result)
  61. end