-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSafeShift.lua
More file actions
145 lines (133 loc) · 4.7 KB
/
Copy pathSafeShift.lua
File metadata and controls
145 lines (133 loc) · 4.7 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
local fileLocalCD
local canUnshift = true
local spellNameMap =
{
direbear = "Dire Bear Form",
bear = "Bear Form",
aquatic = "Aquatic Form",
cat = "Cat Form",
travel = "Travel Form",
moonkin = "Moonkin Form",
}
local forms = {}
forms.map = {}
function forms:Update()
-- forms = {}
forms.map = {}
local numForms = GetNumShapeshiftForms()
for i=1, numForms do
local _, name = GetShapeshiftFormInfo(i);
for form,spellName in pairs(spellNameMap) do
if string.lower(name)==string.lower(spellName) then
forms.map[form] = i
break
end
end
end
end
local SafeShift = CreateFrame("Frame")
SafeShift:RegisterEvent("ADDON_LOADED")
SafeShift:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")
function SafeShift:OnEvent()
if event == "ADDON_LOADED" and arg1 == "SafeShift-TWoW" then
-- Our saved variables, if they exist, have been loaded at this point.
if SafeShiftOptions == nil then
-- This is the first time this addon is loaded; set SVs to default values
SafeShiftOptions = {
unshiftCooldown = 0.5, -- in seconds
}
end
forms:Update()
fileLocalCD = SafeShiftOptions.unshiftCooldown
elseif event == "UPDATE_SHAPESHIFT_FORMS" then
forms:Update()
end
end
SafeShift:SetScript("OnEvent", SafeShift.OnEvent)
local function GetShapeshiftForm()
for _,index in pairs(forms.map) do
local _, _, active = GetShapeshiftFormInfo(index)
if active then
return index
end
end
return 0 -- 0 = humanoid
end
function SafeShift:Shift(form, spellName)
local formIndex = forms.map[form]
local currentForm = GetShapeshiftForm()
--DEFAULT_CHAT_FRAME:AddMessage("Spell: " .. tostring(spellName) .. " | FormIndex: " .. tostring(formIndex) .. " | CurrentForm: " .. tostring(currentForm) .. " | CanUnshift: " .. tostring(canUnshift))
if formIndex == currentForm then
if canUnshift == true then
--DEFAULT_CHAT_FRAME:AddMessage("Powershifting")
CastSpellByName(spellName)
SafeShift:SetScript("OnUpdate", nil)
end
else
if canUnshift == true then
--DEFAULT_CHAT_FRAME:AddMessage("Switching Form")
CastSpellByName(spellName)
SafeShift:SetScript("OnUpdate", SafeShift.OnUpdate)
canUnshift = false
end
end
end
local total = 0
function SafeShift:OnUpdate()
total = total + arg1
if total >= fileLocalCD then
total = 0
canUnshift = true
SafeShift:SetScript("OnUpdate", nil)
end
end
local printColors =
{
DARK = "|cffFF7D0A",
MEDIUM = "|cffFF9D4B",
LIGHT = "|cffFFB475",
}
--FONT_COLOR_CODE_CLOSE = "|r",
local printStrings =
{
TITLE = string.format("%s[SafeShift]%s %sSafety measure against accidentally unshifting immediately after shapeshifting.",
printColors.DARK, FONT_COLOR_CODE_CLOSE, printColors.LIGHT),
USAGE = string.format("%sUsage:%s", printColors.MEDIUM, FONT_COLOR_CODE_CLOSE),
SHIFT = string.format("%s/safeshift%s [%scat%s | %sbear%s | %sdirebear%s | %stravel%s | %smoonkin%s | %saquatic%s] - safely shift into <form> without unshifting for the set period.",
printColors.DARK, FONT_COLOR_CODE_CLOSE, printColors.MEDIUM, FONT_COLOR_CODE_CLOSE, printColors.MEDIUM, FONT_COLOR_CODE_CLOSE,
printColors.MEDIUM, FONT_COLOR_CODE_CLOSE, printColors.MEDIUM, FONT_COLOR_CODE_CLOSE, printColors.MEDIUM, FONT_COLOR_CODE_CLOSE, printColors.MEDIUM, FONT_COLOR_CODE_CLOSE),
COOLDOWN = string.format("%s/safeshift%s [%scd%s | %scooldown%s] <%svalue in seconds%s> - sets the safe period during which you may not unshift.",
printColors.DARK, FONT_COLOR_CODE_CLOSE, printColors.MEDIUM, FONT_COLOR_CODE_CLOSE, printColors.MEDIUM, FONT_COLOR_CODE_CLOSE, printColors.MEDIUM, FONT_COLOR_CODE_CLOSE),
CURRENT_CD = string.format("%sCurrent cooldown:%s %s%s", printColors.LIGHT, FONT_COLOR_CODE_CLOSE, printColors.MEDIUM, "%s"),
}
SLASH_SAFESHIFT1 = "/safeshift"
function SlashCmdList.SAFESHIFT(msg)
msg = string.lower(msg)
if msg == "" or msg == "help" then
DEFAULT_CHAT_FRAME:AddMessage(printStrings.TITLE)
DEFAULT_CHAT_FRAME:AddMessage(printStrings.USAGE)
DEFAULT_CHAT_FRAME:AddMessage(printStrings.SHIFT)
DEFAULT_CHAT_FRAME:AddMessage(printStrings.COOLDOWN)
DEFAULT_CHAT_FRAME:AddMessage(string.format(printStrings.CURRENT_CD, fileLocalCD))
else
local args = {};
for word in string.gfind(msg, "[^%s]+") do
table.insert(args, word);
end
if args[1] == "cooldown" or args[1] == "cd" then
local cd = tonumber(args[2])
if cd then
DEFAULT_CHAT_FRAME:AddMessage(string.format("[SafeShift] Setting unshift cooldown to %s second(s).", cd))
SafeShiftOptions.unshiftCooldown = cd
fileLocalCD = cd
end
elseif spellNameMap[args[1]] ~= nil then
local form = args[1]
if form then
SafeShift:Shift(form, spellNameMap[args[1]])
end
else
DEFAULT_CHAT_FRAME:AddMessage("[SafeShift] Unknown command. Enter /SafeShift help for a list of commands.")
end
end
end