MonsterAttribute_1.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. MonsterAttribute = {}
  2. local orignalAttrNames = {"maxHP", "minDC", "maxDC", "hitRate", "missRate"}
  3. local attrNames = {"maxhp", "mindc", "maxdc", "hitrate", "missrate"}
  4. function MonsterAttribute.Initmonster(monster, monsterCfgId)
  5. -- local monsterCfg = ConfigDataManager.getTable("cfg_monster", "id", monsterCfgId)
  6. -- local cfgMonster = ConfigDataManager.getTable("cfg_monster","id",monsterCfgId)
  7. -- local group = ConfigDataManager.getTableValue("cfg_monster", "group", "id", monsterCfgId)
  8. local cfgMonster = ConfigDataManager.getById("cfg_monster", monsterCfgId)
  9. if cfgMonster.group == "" or cfgMonster.group == nil then
  10. error("cfg_monster没有对应的group:" .. monsterCfgId)
  11. return
  12. end
  13. local severOpenDays
  14. local serverType = getbaseinfo("servertype")
  15. if serverType == 1 then
  16. severOpenDays = getbaseinfo("serveropendays")
  17. elseif serverType == 2 then
  18. local crossOpenTime = getbaseinfo("crossopentime")
  19. local nowSec = getbaseinfo("nowsec")
  20. severOpenDays = TimeUtil.diffDays(crossOpenTime / 1000, nowSec) + 1
  21. end
  22. local currLine = MonsterAttribute.GetCurrentLine(cfgMonster.group, severOpenDays)
  23. if currLine == nil then
  24. error("怪物属性初始化时,cfg_monster_attribute_group没有对应的属性表,怪物配置id:" ..
  25. 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. -- local mapid = tonumber(getbaseinfo(monster, "unimapid"))
  48. -- local info = getmapinfobyid(mapid)
  49. -- local line = info.line
  50. if cfgMonster.reliverandpos == "1" then
  51. local mapid = tonumber(getbaseinfo(monster, "mapid"))
  52. local data = randommonsterbornpoint(mapid, 1)
  53. maptransfer(monster, data.x, data.y, mapid, 1, 128, 2, 2)
  54. end
  55. end
  56. function MonsterAttribute.GetCurrentLine(monsterCfgId, severOpenDays)
  57. local tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId, "day",
  58. severOpenDays)
  59. if tabs == nil or next(tabs) == nil then
  60. tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId, "day", 0)
  61. end
  62. if tabs == nil or next(tabs) == nil then
  63. tabs = MonsterAttribute.GetMaxOpenDayLine(monsterCfgId, severOpenDays)
  64. end
  65. if tabs == nil or next(tabs) == nil then
  66. return nil
  67. end
  68. return tabs[1]
  69. end
  70. function MonsterAttribute.GetMaxOpenDayLine(monsterCfgId, severOpenDays)
  71. local tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId)
  72. if tabs == nil or next(tabs) == nil then
  73. return nil
  74. end
  75. local maxDay = 0
  76. local currLine
  77. for _, line in ipairs(tabs) do
  78. local day = tonumber(line["day"])
  79. if day then
  80. if day <= severOpenDays and day > maxDay then
  81. maxDay = day
  82. currLine = line
  83. end
  84. end
  85. end
  86. if currLine == nil then
  87. return nil
  88. end
  89. return {currLine}
  90. end