Mercurial > wow > degaine
comparison Degaine.lua @ 0:97422a3e11c9
Initial commit, woot !
author | contrebasse |
---|---|
date | Wed, 08 Dec 2010 21:29:27 +0100 |
parents | |
children | 66640a8f1cbd |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:97422a3e11c9 |
---|---|
1 local AddonName = ... | |
2 -- Dégaine auto des armes | |
3 | |
4 -- BUGS connus : | |
5 -- le camouflage du voleur ne rentre pas l'arme | |
6 -- si on se lève en sautant ça ne sort pas l'arme (impossible de savoir si on était assis avant) | |
7 | |
8 -- DEBUG | |
9 local debug = false; | |
10 | |
11 -- Fonctions globales en local | |
12 -- GLOBALS: ToggleAutoDegaine, isDegaineAuto, BINDING_HEADER_DEGAINE | |
13 local GossipFrame = GossipFrame; | |
14 local DEFAULT_CHAT_FRAME = DEFAULT_CHAT_FRAME; | |
15 local InCombatLockdown = InCombatLockdown; | |
16 local ToggleSheath = ToggleSheath; | |
17 | |
18 local pairs = pairs; | |
19 local type = type; | |
20 | |
21 -- Pour les raccourcis | |
22 -- Cf Bindings.xml pour les raccourcis eux-mêmes | |
23 BINDING_HEADER_DEGAINE = "Dégainer automatiquement"; | |
24 | |
25 -- Variables locales | |
26 local DegaineFrame = CreateFrame("Frame"); | |
27 local playername = UnitName("player"); | |
28 local done = true; | |
29 local t_restant = -1; | |
30 | |
31 -- Configuration des events à regarder | |
32 local events = { -- events sans arguments à voir | |
33 GOSSIP_SHOW = true, | |
34 MERCHANT_SHOW = function() return GossipFrame:IsShown(); end, | |
35 BANKFRAME_OPENED = true; --function() return GossipFrame:IsShown(); end, | |
36 AUCTION_HOUSE_SHOW = true, | |
37 }; | |
38 local events1player = { -- events dont le 1er argument doit être le joueur | |
39 UNIT_SPELLCAST_FAILED = true; | |
40 UNIT_SPELLCAST_INTERRUPTED = true; | |
41 UNIT_SPELLCAST_SUCCEEDED = true; | |
42 }; | |
43 local events2playername = { -- events dont le 2e argument doit être le joueur | |
44 CHAT_MSG_SAY = true; | |
45 CHAT_MSG_YELL = true; | |
46 CHAT_MSG_TEXT_EMOTE = true; | |
47 }; | |
48 | |
49 -- Fonctions d'activation/désactivation des events | |
50 local registerEvents = function() | |
51 --if debug then | |
52 -- DEBUG | |
53 -- DegaineFrame:RegisterAllEvents(); | |
54 --else | |
55 for k,v in pairs(events) do DegaineFrame:RegisterEvent(k); end | |
56 for k,v in pairs(events1player) do DegaineFrame:RegisterEvent(k); end | |
57 for k,v in pairs(events2playername) do DegaineFrame:RegisterEvent(k); end | |
58 --end | |
59 end -- function | |
60 local unregisterEvents = function() | |
61 if not debug then | |
62 for k,v in pairs(events) do DegaineFrame:UnregisterEvent(k); end | |
63 for k,v in pairs(events1player) do DegaineFrame:UnregisterEvent(k); end | |
64 for k,v in pairs(events2playername) do DegaineFrame:UnregisterEvent(k); end | |
65 end | |
66 end -- function | |
67 | |
68 -- Fonction de timer | |
69 -- On attend un petit délai avant de dégainer, pour voir l'animation et éviter que ça bug | |
70 local OnUpdate = function(self,t_ecoule) | |
71 if not done then | |
72 t_restant = t_restant - t_ecoule; | |
73 if t_restant<=0 then | |
74 done = true; | |
75 ToggleSheath(); | |
76 end | |
77 end | |
78 end | |
79 | |
80 -- Fonctions d'activation/désactivation | |
81 local activer = function() | |
82 if (not isDegaineAuto) or InCombatLockdown() then return end | |
83 | |
84 DegaineFrame:SetScript("OnUpdate", OnUpdate); | |
85 registerEvents(); | |
86 end | |
87 local desactiver = function() | |
88 -- Désactivation | |
89 unregisterEvents(); | |
90 DegaineFrame:SetScript("OnUpdate", nil); | |
91 done = true; | |
92 end | |
93 | |
94 -- Fonctions | |
95 local printState = function() | |
96 DEFAULT_CHAT_FRAME:AddMessage(isDegaineAuto and "Dégainage automatique |cFF00FF00activé|r" or "Dégainage automatique |cFFFF0000désactivé|r"); | |
97 end | |
98 local OnEvent = function(self,event, arg1, arg2, ...) | |
99 if debug then | |
100 DEFAULT_CHAT_FRAME:AddMessage(event); | |
101 if arg1 then DEFAULT_CHAT_FRAME:AddMessage("arg1 = "..arg1); end | |
102 if arg2 then DEFAULT_CHAT_FRAME:AddMessage("arg2 = "..arg2); end | |
103 end | |
104 | |
105 if ((events[event] and (type(events[event])~="function" or events[event]())) | |
106 or (events1player[event] and arg1=="player") | |
107 or (events2playername[event] and arg2==playername)) then | |
108 t_restant = 2; | |
109 done = false; | |
110 elseif event == "PLAYER_REGEN_ENABLED" then | |
111 desactiver(); | |
112 elseif event == "PLAYER_REGEN_DISABLED" then | |
113 activer(); | |
114 elseif event == "ADDON_LOADED" and arg1==AddonName then | |
115 if isDegaineAuto==nil then | |
116 isDegaineAuto = true; | |
117 end | |
118 if isDegaineAuto then | |
119 activer(); | |
120 else | |
121 desactiver(); | |
122 end | |
123 printState(); | |
124 end | |
125 end | |
126 | |
127 -- Pour mettre le dégainage auto on/off TODO | |
128 ToggleAutoDegaine = function() | |
129 if isDegaineAuto then | |
130 isDegaineAuto = false; | |
131 desactiver(); | |
132 else | |
133 isDegaineAuto = true; | |
134 activer(); | |
135 end | |
136 printState(); | |
137 end | |
138 | |
139 -- Enregistrement des events et activation | |
140 DegaineFrame:RegisterEvent("PLAYER_REGEN_ENABLED"); | |
141 DegaineFrame:RegisterEvent("PLAYER_REGEN_DISABLED"); | |
142 DegaineFrame:RegisterEvent("ADDON_LOADED"); | |
143 DegaineFrame:SetScript("OnEvent",OnEvent); | |
144 -- ça ne marche pas... question posée sur http://forums.wowace.com/showthread.php?p=310547#post310547 | |
145 hooksecurefunc("SitStandOrDescendStart",function() if isDegaineAuto and not InCombatLockdown() then t_restant = 2; done = false; end; end); | |
146 activer(); |