MonsterAttribute.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. MonsterAttribute = {}
  2. local orignalAttrNames = {
  3. "maxHP", "minDC", "maxDC", "hitRate", "missRate"
  4. }
  5. local attrNames = {
  6. "maxhp", "mindc", "maxdc", "hitrate", "missrate"
  7. }
  8. function MonsterAttribute.Initmonster(monster, monsterCfgId)
  9. local group = ConfigDataManager.getTableValue("cfg_monster", "group", "id", monsterCfgId)
  10. if group == "" or group == nil then
  11. error("cfg_monster没有对应的group:" .. monsterCfgId)
  12. return
  13. end
  14. local severOpenDays = getbaseinfo("serveropendays")
  15. local currLine = MonsterAttribute.GetCurrentLine(group, severOpenDays)
  16. if currLine == nil then
  17. error("怪物属性初始化时,cfg_monster_attribute_group没有对应的属性表,怪物配置id:" .. monsterCfgId .. ",开服天数:" .. severOpenDays)
  18. return
  19. end
  20. local attrParams = {}
  21. for i, attrName in ipairs(attrNames) do
  22. local value = tonumber(currLine[attrName])
  23. table.insert(attrParams, orignalAttrNames[i])
  24. table.insert(attrParams, value)
  25. --updateattrgroup(monster, "monAttrByOpenday", orignalAttrNames[i], value)
  26. end
  27. --一次性写入,只调用一次命令
  28. if not table.isNullOrEmpty(attrParams) then
  29. updateattrgroup(monster, "monAttrByOpenday", table.unpack(attrParams))
  30. end
  31. --其他属性
  32. local att = currLine["att"]
  33. if not string.isNullOrEmpty(att) then
  34. local attMap = string.toIntIntMap(att, "#", "|")
  35. updateattrgroup(monster, "monAttrByOpenday", attMap)
  36. end
  37. local maxHP = getattrinfo(monster, "maxHP")
  38. sethp(monster, maxHP)
  39. end
  40. function MonsterAttribute.GetCurrentLine(monsterCfgId, severOpenDays)
  41. local tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId, "day",
  42. severOpenDays)
  43. if tabs == nil or next(tabs) == nil then
  44. tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId, "day", 0)
  45. end
  46. if tabs == nil or next(tabs) == nil then
  47. tabs = MonsterAttribute.GetMaxOpenDayLine(monsterCfgId, severOpenDays)
  48. end
  49. if tabs == nil or next(tabs) == nil then
  50. return nil
  51. end
  52. return tabs[1]
  53. end
  54. function MonsterAttribute.GetMaxOpenDayLine(monsterCfgId, severOpenDays)
  55. local tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId)
  56. if tabs == nil or next(tabs) == nil then
  57. return nil
  58. end
  59. local maxDay = 0
  60. local currLine
  61. for _, line in ipairs(tabs) do
  62. local day = tonumber(line["day"])
  63. if day then
  64. if day <= severOpenDays and day > maxDay then
  65. maxDay = day
  66. currLine = line
  67. end
  68. end
  69. end
  70. if currLine == nil then
  71. return nil
  72. end
  73. return { currLine }
  74. end