| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- MonsterAttribute = {}
- local orignalAttrNames = {"maxHP", "minDC", "maxDC", "hitRate", "missRate"}
- local attrNames = {"maxhp", "mindc", "maxdc", "hitrate", "missrate"}
- function MonsterAttribute.Initmonster(monster, monsterCfgId)
- -- local monsterCfg = ConfigDataManager.getTable("cfg_monster", "id", monsterCfgId)
- -- local cfgMonster = ConfigDataManager.getTable("cfg_monster","id",monsterCfgId)
- -- local group = ConfigDataManager.getTableValue("cfg_monster", "group", "id", monsterCfgId)
- local cfgMonster = ConfigDataManager.getById("cfg_monster", monsterCfgId)
- if cfgMonster.group == "" or cfgMonster.group == nil then
- error("cfg_monster没有对应的group:" .. monsterCfgId)
- return
- end
- local severOpenDays
- local serverType = getbaseinfo("servertype")
- if serverType == 1 then
- severOpenDays = getbaseinfo("serveropendays")
- elseif serverType == 2 then
- local crossOpenTime = getbaseinfo("crossopentime")
- local nowSec = getbaseinfo("nowsec")
- severOpenDays = TimeUtil.diffDays(crossOpenTime / 1000, nowSec) + 1
- end
- local currLine = MonsterAttribute.GetCurrentLine(cfgMonster.group, severOpenDays)
- if currLine == nil then
- error("怪物属性初始化时,cfg_monster_attribute_group没有对应的属性表,怪物配置id:" ..
- monsterCfgId .. ",开服天数:" .. severOpenDays)
- return
- end
- local attrParams = {}
- for i, attrName in ipairs(attrNames) do
- local value = tonumber(currLine[attrName])
- table.insert(attrParams, orignalAttrNames[i])
- table.insert(attrParams, value)
- -- updateattrgroup(monster, "monAttrByOpenday", orignalAttrNames[i], value)
- end
- -- 一次性写入,只调用一次命令
- if not table.isNullOrEmpty(attrParams) then
- updateattrgroup(monster, "monAttrByOpenday", table.unpack(attrParams))
- end
- -- 其他属性
- local att = currLine["att"]
- if not string.isNullOrEmpty(att) then
- local attMap = string.toIntIntMap(att, "#", "|")
- updateattrgroup(monster, "monAttrByOpenday", attMap)
- end
- local maxHP = getattrinfo(monster, "maxHP")
- sethp(monster, maxHP)
- -- local mapid = tonumber(getbaseinfo(monster, "unimapid"))
- -- local info = getmapinfobyid(mapid)
- -- local line = info.line
- if cfgMonster.reliverandpos == "1" then
- local mapid = tonumber(getbaseinfo(monster, "mapid"))
- local data = randommonsterbornpoint(mapid, 1)
- maptransfer(monster, data.x, data.y, mapid, 1, 128, 2, 2)
- end
- end
- function MonsterAttribute.GetCurrentLine(monsterCfgId, severOpenDays)
- local tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId, "day",
- severOpenDays)
- if tabs == nil or next(tabs) == nil then
- tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId, "day", 0)
- end
- if tabs == nil or next(tabs) == nil then
- tabs = MonsterAttribute.GetMaxOpenDayLine(monsterCfgId, severOpenDays)
- end
- if tabs == nil or next(tabs) == nil then
- return nil
- end
- return tabs[1]
- end
- function MonsterAttribute.GetMaxOpenDayLine(monsterCfgId, severOpenDays)
- local tabs = ConfigDataManager.getTable("cfg_monster_attribute_group", "monsterid", monsterCfgId)
- if tabs == nil or next(tabs) == nil then
- return nil
- end
- local maxDay = 0
- local currLine
- for _, line in ipairs(tabs) do
- local day = tonumber(line["day"])
- if day then
- if day <= severOpenDays and day > maxDay then
- maxDay = day
- currLine = line
- end
- end
- end
- if currLine == nil then
- return nil
- end
- return {currLine}
- end
|