diff --git a/CommandManager.lua b/CommandManager.lua index bdafde2..9837b27 100644 --- a/CommandManager.lua +++ b/CommandManager.lua @@ -64,6 +64,7 @@ C.CommandManager = { local L = C.LocaleManager local CM = C.CommandManager local PM = C.PlayerManager +local EM = C.EmoteManager local QM = C.QueueManager local RM = C.RollManager local LM = C.LootManager @@ -1195,6 +1196,19 @@ CM:Register({"follow", "f"}, PM.Access.Groups.User.Level, function(args, sender, return "CM_FOLLOW_STARTED", {name} end, "CM_FOLLOW_HELP") +CM:Register({"emote", "em", "e"}, PM.Access.Groups.User.Level, function(args, sender, isChat, bnetInfo) + if #args < 1 then + return false, "CM_EMOTE_USAGE" + end + + return EM:DoEmote(args[1]) +end, "CM_EMOTE_HELP") + +-- Alias for !emote sit +CM:Register({"sit"}, PM.Access.Groups.User.Level, function(args, sender, isChat, bnetInfo) + return EM:DoEmote(EM.Emotes.Sit) +end, "CM_SIT_HELP") + for i,v in ipairs(CM.Slash) do _G["SLASH_" .. C.Name:upper() .. i] = "/" .. v end diff --git a/EmoteManager.lua b/EmoteManager.lua new file mode 100644 index 0000000..0594700 --- /dev/null +++ b/EmoteManager.lua @@ -0,0 +1,94 @@ +--[[ + * 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" + }, + 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 + +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 diff --git a/load.xml b/load.xml index 9726f0a..d465a72 100644 --- a/load.xml +++ b/load.xml @@ -29,6 +29,7 @@ <Script file="GroupTools.lua" /> <Script file="AuthManager.lua" /> <Script file="PlayerManager.lua" /> + <Script file="EmoteManager.lua" /> <Script file="QueueManager.lua" /> <Script file="RollManager.lua" /> <Script file="LootManager.lua" /> diff --git a/locales/enUS.lua b/locales/enUS.lua index c1579f8..256f59a 100644 --- a/locales/enUS.lua +++ b/locales/enUS.lua @@ -317,6 +317,11 @@ local L = { CM_FOLLOW_STARTED = "Started following %s!", CM_FOLLOW_SELF = "I cannot follow myself.", + CM_EMOTE_HELP = "Performs an emote", + CM_EMOTE_USAGE = "Usage: emote <emote> (E.g: 'emote sit')", + + CM_SIT_HELP = "Alias for 'emote sit'", + ------------ -- Events -- ------------ @@ -472,6 +477,19 @@ local L = { PM_LIST_SETBLACK = "Now using list as blacklist.", ------------------ + -- EmoteManager -- + ------------------ + + EM_ERR_UNKNOWN = "Unknown emote: %s", + EM_ERR_CANNOT = "Unable to perform emote %q: %s", + + EM_SUCCESS = "Successfully executed the %s emote!", + + EM_VALIDATOR_ERR_MOVEMENT = "Cannot perform that emote while moving", + EM_VALIDATOR_ERR_FLYING = "Cannot perform that emote while flying", + EM_VALIDATOR_ERR_COMBAT = "Cannot perform that emote while in combat", + + ------------------ -- DeathManager -- ------------------