虚弱0 度精华0阅读权限30在线时间70 小时
|
- local function getInvasionSchedules(index, scheduleManager)
- local schedules = {}
- for i = 1, #scheduleManager do
- local row = scheduleManager[i]
- if tonumber(row[1]) == index then
- table.insert(schedules, {
- Year = row[2],
- Month = row[3],
- Day = row[4],
- DoW = row[5],
- Hour = row[6],
- Minute = row[7],
- Second = row[8],
- })
- end
- end
- return schedules
- end
- local function sendAdminsInvasionNotice(monster, map)
- local indexes = GetMonsterIndexes(monster, map)
- for i = 1, #indexes do
- local index = indexes[i]
- local data = GetMonsterData(index)
- SendAdminsNotice(
- 1,
- {"%s Invaded %s (%d, %d)", "%s Invadiu %s (%d, %d)", "%s invadió %s (%d, %d)"},
- {data.name, data.map.name, data.map.x, data.map.y}
- )
- end
- end
- local function loadInvasions()
- local monsterSetBase = ReadSectionFile("../Data/Monster/MonsterSetBase.txt")
- local invasionSetBase = monsterSetBase[3]
- local invasionManager = ReadSectionFile("../Data/Event/InvasionManager.dat")
- local scheduleManager = invasionManager[0]
- local durationManager = invasionManager[1]
- local monsterManager = invasionManager[3]
- for i = 1, #invasionSetBase do
- local monster = tonumber(invasionSetBase[i][1])
- local map = tonumber(invasionSetBase[i][2])
- local quantity = tonumber(invasionSetBase[i][9])
- local index = getInvasionIndex(monster, monsterManager)
- local duration = getInvasionDuration(index, durationManager)
- local schedules = getInvasionSchedules(index, scheduleManager)
- table.insert(Invasions, {
- Monster = monster,
- Map = map,
- Quantity = quantity,
- LiveCount = quantity,
- Duration = duration,
- Schedules = schedules,
- CurrentSchedule = nil,
- })
- end
- end
- function ReadScript()
- loadInvasions()
- LogColor(2, string.format(
- "[LUA][InvasionNotice] %d invasions loaded successfully",
- #Invasions
- ))
- end
- function MonsterDie(index, killerIndex)
- if GetObjectType(index) ~= OBJECT_MONSTER then
- return
- end
- local monster = GetObjectClass(index)
- local map = GetObjectMap(index)
- local invasion = findInvasion(monster, map)
- if not invasion then
- return
- end
- local liveCount = GetMonsterLiveCount(monster, map)
- if (liveCount < invasion.LiveCount) then
- invasion.LiveCount = liveCount
- end
- invasion.LiveCount = invasion.LiveCount - 1
- local monsterName = GetMonsterName(monster)
- local killerName = GetObjectName(killerIndex)
- SendPlayersNotice(
- 0,
- {"%s defeated %s [%d/%d]", "%s derrotou %s [%d/%d]", "%s derrotó %s [%d/%d]"},
- {killerName, monsterName, invasion.Quantity - invasion.LiveCount, invasion.Quantity}
- )
- if invasion.LiveCount == 0 then
- invasion.CurrentSchedule = nil
- invasion.LiveCount = invasion.Quantity
- SendPlayersNotice(
- 0,
- {"%s is defeated!", "%s foi derrotado(a)!", "%s fue derrotado(a)!"},
- {monsterName}
- )
- end
- end
- function TimerThread()
- local gameServerCode = GetGameServerCode()
- if (gameServerCode == 40) then
- return
- end
- for i = 1, #Invasions do
- local invasion = Invasions[i]
- local liveCount = GetMonsterLiveCount(invasion.Monster, invasion.Map)
- local currentSchedule = GetTimeUpSchedule(invasion.Schedules, 0)
- if not invasion.CurrentSchedule and liveCount > 0 and currentSchedule then
- invasion.CurrentSchedule = currentSchedule
- local monsterName = GetMonsterName(invasion.Monster)
- local mapName = GetMapName(invasion.Map)
- SendPlayersNotice(
- 0,
- {"The %s Invasion has begun in %s!", "A Invasão de %s começou em %s!", "La invasión de %s comenzó en %s!"},
- {monsterName, mapName}
- )
- sendAdminsInvasionNotice(invasion.Monster, invasion.Map)
- elseif invasion.CurrentSchedule then
- local currentSchedule = GetTimeUpSchedule(invasion.Schedules, invasion.Duration)
- if not currentSchedule then
- invasion.CurrentSchedule = nil
- invasion.LiveCount = invasion.Quantity
- local monsterName = GetMonsterName(invasion.Monster)
- SendPlayersNotice(
- 0,
- {"%s has gone!", "%s foi embora!", "%s se fue!"},
- {monsterName}
- )
- end
- end
- end
- end
- BridgeFunctionAttach("OnReadScript", "ReadScript")
- BridgeFunctionAttach("OnMonsterDie", "MonsterDie")
- BridgeFunctionAttach("OnTimerThread", "TimerThread")
- function GetAdmins()
- local admins = {}
- for index = GetMinUserIndex(), GetMaxUserIndex() do
- local isAdmin = CommandCheckGameMasterLevel(index, 2) == 1
- if isAdmin then
- table.insert(admins, index)
- end
- end
- return admins
- end
- function GetPlayers()
- local players = {}
- for index = GetMinUserIndex(), GetMaxUserIndex() do
- table.insert(players, index)
- end
- return players
- end
- function SendAdminsNotice(value, message, args)
- local admins = GetAdmins()
- for i = 1, #admins do
- local index = admins[i]
- if (type(message) ~= "string") then
- message = message[GetUserLanguage(index) + 1]
- end
- NoticeSend(index, value, string.format(message, table.unpack(args)))
- end
- end
- function SendPlayersNotice(value, message, args)
- local players = GetPlayers()
- for i = 1, #players do
- local index = players[i]
- if (type(message) ~= "string") then
- message = message[GetUserLanguage(index) + 1]
- end
- NoticeSend(index, value, string.format(message, table.unpack(args)))
- end
- end
- function ReadSectionFile(filename)
- local config = {}
- local currentSection = nil
- for line in io.lines(filename) do
- line = line:match("^%s*(.-)%s*$")
- if line ~= "" and not line:match("^//") then
- if line:match("^%d+$") then
- currentSection = tonumber(line)
- if currentSection and not config[currentSection] then
- config[currentSection] = {}
- end
- elseif line == "end" then
- currentSection = nil
- elseif currentSection then
- local row = {}
- for column in line:gmatch("%S+") do
- table.insert(row, column)
- end
- table.insert(config[currentSection], row)
- end
- end
- end
- return config
- end
- function CheckScheduleTimeUp(schedule, duration)
- local date = os.date("*t")
- local currentTime = os.time({
- year = date.year,
- month = date.month,
- day = date.day,
- hour = date.hour,
- min = date.min,
- sec = 0,
- })
- local scheduleTime = os.time({
- year = (schedule.Year ~= "*" and tonumber(schedule.Year)) or date.year,
- month = (schedule.Month ~= "*" and tonumber(schedule.Month)) or date.month,
- day = (schedule.Day ~= "*" and tonumber(schedule.Day)) or date.day,
- hour = (schedule.Hour ~= "*" and tonumber(schedule.Hour)) or date.hour,
- min = (schedule.Minute ~= "*" and tonumber(schedule.Minute)) or date.min,
- sec = 0,
- })
- local isTimeUp = scheduleTime <= currentTime and (scheduleTime + duration) >= currentTime
- return isTimeUp
- end
- function GetTimeUpSchedule(schedules, duration)
- for i = 1, #schedules do
- local schedule = schedules[i]
- if (CheckScheduleTimeUp(schedule, duration)) then
- return schedule
- end
- end
- return nil
- end
- function GetMonsterData(index)
- local map = GetObjectMap(index)
- return {
- index = index,
- name = GetObjectName(index),
- map = {
- name = GetMapName(map),
- x = GetObjectMapX(index),
- y = GetObjectMapY(index),
- }
- }
- end
- function GetMonsterIndexes(monster, map)
- local indexes = {}
- for index = GetMinMonsterIndex(), GetMaxMonsterIndex() do
- local currentMonster = GetObjectClass(index)
- local currentMap = GetObjectMap(index)
- if monster == currentMonster and (not map or currentMap == map) then
- table.insert(indexes, index)
- end
- end
- return indexes
- end
- function GetMonsterLiveCount(monster, map)
- local liveCount = 0
- local indexes = GetMonsterIndexes(monster, map)
- for i = 1, #indexes do
- local index = indexes[i]
- local isDead = GetObjectLive(index) <= 0
- if not isDead then
- liveCount = liveCount + 1
- end
- end
- return liveCount
- end
复制代码
|
|