MonsterAttribute.lua 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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
  15. local serverType = getbaseinfo("servertype")
  16. if serverType == 1 then
  17. severOpenDays = getbaseinfo("serveropendays")
  18. elseif serverType == 2 then
  19. local crossOpenTime = getbaseinfo("crossopentime")
  20. local nowSec = getbaseinfo("nowsec")
  21. severOpenDays = TimeUtil.diffDays(crossOpenTime / 1000, nowSec) + 1
  22. end
  23. local currLine = MonsterAttribute.GetCurrentLine(group, severOpenDays)
  24. if currLine == nil then
  25. error("怪物属性初始化时,cfg_monster_attribute_group没有对应的属性表,怪物配置id:" .. monsterCfgId .. ",开服天数:" .. severOpenDays)
  26. return
  27. end
  28. local attrParams = {}
  29. for i, attrName in ipairs(attrNames) do
  30. local value = tonumber(currLine[attrName])
  31. table.insert(attrParams, orignalAttrNames[i])
  32. table.insert(attrParams, value)
  33. --updateattrgroup(monster, "monAttrByOpenday", orignalAttrNames[i], value)
  34. end
  35. --一次性写入,只调用一次命令
  36. if not table.isNullOrEmpty(attrParams) then
  37. updateattrgroup(monster, "monAttrByOpenday", table.unpack(attrParams))
  38. end
  39. --其他属性
  40. local att = currLine["att"]
  41. if not string.isNullOrEmpty(att) then
  42. local attMap = string.toIntIntMap(att, "#", "|")
  43. updateattrgroup(monster, "monAttrByOpenday", attMap)
  44. end
  45. local maxHP = getattrinfo(monster, "maxHP")
  46. sethp(monster, maxHP)
  47. end
  48. function MonsterAttribute.GetCurrentLine(monsterCfgId, severOpenDays)
  49. local tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId, "day",
  50. severOpenDays)
  51. if tabs == nil or next(tabs) == nil then
  52. tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId, "day", 0)
  53. end
  54. if tabs == nil or next(tabs) == nil then
  55. tabs = MonsterAttribute.GetMaxOpenDayLine(monsterCfgId, severOpenDays)
  56. end
  57. if tabs == nil or next(tabs) == nil then
  58. return nil
  59. end
  60. return tabs[1]
  61. end
  62. function MonsterAttribute.GetMaxOpenDayLine(monsterCfgId, severOpenDays)
  63. local tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId)
  64. if tabs == nil or next(tabs) == nil then
  65. return nil
  66. end
  67. local maxDay = 0
  68. local currLine
  69. for _, line in ipairs(tabs) do
  70. local day = tonumber(line["day"])
  71. if day then
  72. if day <= severOpenDays and day > maxDay then
  73. maxDay = day
  74. currLine = line
  75. end
  76. end
  77. end
  78. if currLine == nil then
  79. return nil
  80. end
  81. return { currLine }
  82. end