-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDestinations.lua
More file actions
108 lines (88 loc) · 3.52 KB
/
Destinations.lua
File metadata and controls
108 lines (88 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
------------------------------------------
-- Destinations Module
------------------------------------------
local MageService = MAGESERVICE
------------------------------------------
-- Create the Destinations module
------------------------------------------
local Destinations = {}
------------------------------------------
-- Destination Data
------------------------------------------
-- This table will store the destination keywords
-- The keys are the destination names, and the values are lists of keywords
-- that can be used to identify them in messages
local destinationMap = {
Stormwind = {"sw", "stormw", "stormwind", "storm wind", "strom", "stormwin", "stomwind", "swind", "stormwnd", "swcity", "stormcity", "human city", "sw city"},
Ironforge = {"if", "ironforge", "ironf", "iron forge", "iforge", "iron f", "dwarfcity", "dwarf city", "irnforge", "forge", "ironfoge", "irnforg"},
Darnassus = {"darn", "darnassus", "darnas", "darnasus", "darnassis", "darnass", "nelfs", "nightelf city", "nelf city", "elf city", "darnassus city", "darn city", "tree city"},
}
------------------------------------------
-- Destination Functions
------------------------------------------
-- Function to find a destination in a message
function Destinations.FindInMessage(message)
if not message or type(message) ~= "string" then
return nil
end
-- Convert message to lowercase for case-insensitive matching
local lowerMessage = string.lower(message)
-- Check each destination
for destination, keywords in pairs(destinationMap) do
for _, keyword in ipairs(keywords) do
if string.find(lowerMessage, keyword, 1, true) then
return destination
end
end
end
return nil
end
------------------------------------------
-- Player Destination Tracking
------------------------------------------
-- This table will store player destinations
-- The keys will be player names (normalized), and the values will be destination names
local playerDestinations = {}
-- Function to add player destination
function Destinations.AddPlayerDestination(playerName, destination)
if not playerName or not destination then
return false
end
-- Normalize playerName to handle different formats
playerName = string.lower(playerName)
-- Check if destination is valid (exists in destinationMap)
if not destinationMap[destination] then
return false
end
-- Store the destination for this player
playerDestinations[playerName] = destination
return true
end
-- Function to get player destination
function Destinations.GetPlayerDestination(playerName)
if not playerName then
return nil
end
-- Normalize playerName to handle different formats
playerName = string.lower(playerName)
-- Return the player's destination (or nil if not set)
return playerDestinations[playerName]
end
-- Function to remove player destination
function Destinations.RemovePlayerDestination(playerName)
if not playerName then
return false
end
-- Normalize playerName to handle different formats
playerName = string.lower(playerName)
-- Check if the player has a destination
if playerDestinations[playerName] then
playerDestinations[playerName] = nil
return true
end
return false
end
------------------------------------------
-- Register the module in the addon namespace
------------------------------------------
MageService.Destinations = Destinations