-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmoteManager.lua
111 lines (90 loc) · 2.64 KB
/
EmoteManager.lua
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
109
110
111
--[[
* Copyright (c) 2011-2012 by Adam Hellberg.
*
* This file is part of Command.
*
* Command is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Command is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Command. If not, see <http://www.gnu.org/licenses/>.
--]]
-- Upvalues
local pairs = pairs
-- API Upvalues
local DoEmote = DoEmote
local IsFlying = IsFlying
local GetUnitSpeed = GetUnitSpeed
local UnitAffectingCombat = UnitAffectingCombat
local C = Command
local L = C.LocaleManager
C.EmoteManager = {
Emotes = {
Sit = "sit",
Stand = "stand",
Wave = "wave",
Sleep = "sleep",
Lie = "lie",
Kiss = "kiss",
Slap = "slap"
},
EmoteValidators = {}
}
local EM = C.EmoteManager
local emoteMapping
EM.EmoteValidators[EM.Emotes.Sit] = function()
if GetUnitSpeed("player") > 0 then
return false, "EM_VALIDATOR_ERR_MOVEMENT"
elseif IsFlying() then
return false, "EM_VALIDATOR_ERR_FLYING"
elseif UnitAffectingCombat("player") then
return false, "EM_VALIDATOR_ERR_COMBAT"
end
return true
end
EM.EmoteValidators[EM.Emotes.Stand] = EM.EmoteValidators[EM.Emotes.Sit]
EM.EmoteValidators[EM.Emotes.Sleep] = EM.EmoteValidators[EM.Emotes.Sit]
EM.EmoteValidators[EM.Emotes.Lie] = EM.EmoteValidators[EM.Emotes.Sit]
EM.EmoteValidators[EM.Emotes.Wave] = function()
return not UnitAffectingCombat("player")
end
EM.EmoteValidators[EM.Emotes.Kiss] = EM.EmoteValidators[EM.Emotes.Wave]
EM.EmoteValidators[EM.Emotes.Slap] = EM.EmoteValidators[EM.Emotes.Wave]
function EM:Init()
end
function EM:HasEmote(emote)
emote = emote:lower()
if not emoteMapping then -- Build emote mapping for faster checking
emoteMapping = {}
for k,v in pairs(self.Emotes) do
emoteMapping[v] = k
end
end
return self.Emotes[emoteMapping[emote]] == emote
end
function EM:CanEmote(emote)
return self.EmoteValidators[emote]()
end
-- Simple wrapper func
function EM:RawDoEmote(emote)
DoEmote(emote)
end
function EM:DoEmote(emote)
emote = emote:lower()
if not self:HasEmote(emote) then
return false, "EM_ERR_UNKNOWN", {emote}
end
local can, err = self:CanEmote(emote)
if not can then
return false, "EM_ERR_CANNOT", {L(err)}
end
self:RawDoEmote(emote)
return "EM_SUCCESS", {emote}
end