From fd7ae6d85d902c12cd2df40bacd51c8b2296df52 Mon Sep 17 00:00:00 2001 From: F16Gaming Date: Sun, 16 Dec 2012 15:05:48 +0100 Subject: [PATCH] Added new feature: EmoteManager --- CommandManager.lua | 14 ++++++++ EmoteManager.lua | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++ load.xml | 1 + locales/enUS.lua | 18 ++++++++++ 4 files changed, 127 insertions(+) create mode 100644 EmoteManager.lua 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 . +--]] + +-- 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 @@