-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
394 lines (338 loc) · 14.3 KB
/
main.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
-- Pawn by Vger-Azjol-Nerub
-- www.vgermods.com
-- © 2006-2019 Green Eclipse. This mod is released under the Creative Commons Attribution-NonCommercial-NoDerivs 3.0 license.
-- See Readme.htm for more information.
--
-- PrivateSniper's Classic Pawn Scales
------------------------------------------------------------
local AddonName, AddonTable = ...
local ScaleProviderName = "SniperClassic"
local PawnSniperLastUpdatedVersion = 1.00
local PawnNoValueAnnotationFormat = "%s%s:"
local PawnUnenchantedAnnotationFormat = PawnNoValueAnnotationFormat .. " %." .. PawnCommon.Digits .. "f"
local PawnEnchantedAnnotationFormat = PawnUnenchantedAnnotationFormat .. " %s(%." .. PawnCommon.Digits .. "f " .. PawnLocal.BaseValueWord .. ")"
-- The class of the player
-- UnitClass("player")
local SniperUnitClasses = {
[1] = {
['name'] = "Warrior",
['spec'] = {
[1] = 'Protection',
[2] = 'Arms',
[3] = 'Fury'
}
},
[2] = {
['name'] = "Paladin",
['spec'] = {
[1] = 'Holy',
[2] = 'Protection',
[3] = 'Retribution',
}
},
[3] = {
['name'] = "Hunter",
['spec'] = {
[1] = 'Beast Mastery',
[2] = 'Marksmanship',
[3] = 'Survival'
}
},
[4] = {
['name'] = "Rogue",
['spec'] = {
[1] = 'Assassination',
[2] = 'Combat',
[3] = 'Subtelty'
}
},
[5] = {
['name'] = "Priest",
['spec'] = {
[1] = 'Discipline',
[2] = 'Holy',
[3] = 'Shadow'
}
},
[7] = {
['name'] = "Shaman",
['spec'] = {
[1] = 'Elemental',
[2] = 'Enhancement',
[3] = 'Restoration'
}
},
[8] = {
['name'] = "Mage",
['spec'] = {
[1] = 'Arcane',
[2] = 'Fire',
[3] = 'Frost'
}
},
[9] = {
['name'] = "Warlock",
['spec'] = {
[1] = 'Affliction',
[2] = 'Demonology',
[3] = 'Destruction'
}
},
[11] = {
['name'] = "Druid",
['spec'] = {
[1] = 'Balance',
[2] = 'Feral Combat',
[3] = 'Restoration'
}
}
}
function SniperPawnDump(str, obj)
if ViragDevTool_AddData then
ViragDevTool_AddData(obj, str)
end
end
------------------------------------------------------------
-- Customise PawnAddPluginScale code to work in classic
-- Formatting
local PawnNoValueAnnotationFormat = "%s%s:"
local PawnUnenchantedAnnotationFormat = PawnNoValueAnnotationFormat .. " %." .. PawnCommon.Digits .. "f"
local PawnEnchantedAnnotationFormat = PawnUnenchantedAnnotationFormat .. " %s(%." .. PawnCommon.Digits .. "f " .. PawnLocal.BaseValueWord .. ")"
function SniperPawnGetStatValuesForTemplate(Template, NoStats)
--local _, _, _, _, Role = GetSpecializationInfoForClassID(Template.ClassID, Template.SpecID)
local ScaleValues
if NoStats then
ScaleValues = {}
else
ScaleValues = {
["Stamina"] = 0.01,
["CritRating"] = 0.5,
["HasteRating"] = 0.5,
["MasteryRating"] = 0.5,
["Versatility"] = 0.5,
["MovementSpeed"] = 0.01,
["Avoidance"] = 0.01,
["Leech"] = 0.01,
["Indestructible"] = 0.01,
}
ScaleValues[Template.PrimaryStat] = 1
-- if Role == "TANK" then
-- ScaleValues.Stamina = 1
-- ScaleValues.Armor = 1
-- end
end
local StatName
for _, StatName in pairs(PawnNeverUsableStats[Template.ClassID]) do
ScaleValues[StatName] = PawnIgnoreStatValue
end
for _, StatName in pairs(Template.UnusableStats) do
ScaleValues[StatName] = PawnIgnoreStatValue
end
return ScaleValues
end
-- Adds a plugin scale from Pawn, starting from one of Pawn's existing templates.
function SniperPawnAddPluginScaleFromTemplate(ProviderInternalName, ClassID, SpecID, Stats, Color, specName)
if not PawnScaleProviders[ProviderInternalName] then
VgerCore.Fail("A scale provider with that name is not registered. Use PawnAddPluginScaleProvider first.")
return
end
if not PawnCommon then VgerCore.Fail("Can't add plugin scales until Pawn starts to initialize.") return end
local clId = tonumber(ClassID)
local scaleName = ''
local className = SniperUnitClasses[tonumber(ClassID)]['name']
if not specName then
specName = SniperUnitClasses[tonumber(ClassID)]['spec'][tonumber(SpecID)]
scaleName = className .. ": " .. specName
else
scaleName = specName .. " (Sniper)"
end
local Template = PawnFindScaleTemplate(ClassID, SpecID)
if not Template then VgerCore.Fail("Can't add this plugin scale because the class" .. tostring(className) .. " ID " .. tostring(ClassID) .. " and/or spec " .. tostring(LocalizedSpecName) .. " ID " .. tostring(SpecID) .. " wasn't found.") return end
-- Build up the values table.
local ScaleValues = SniperPawnGetStatValuesForTemplate(Template)
if Stats then
local StatName, Value
for StatName, Value in pairs(Stats) do
ScaleValues[StatName] = Stats[StatName]
end
end
-- Then, transfer control to the regular plugin scale codepath.
local ScaleInternalName = className .. SpecID
PawnAddPluginScale(
ProviderInternalName,
ScaleInternalName,
scaleName, -- LocalizedScaleName
Color,
ScaleValues,
nil,
Template.HideUpgrades
)
-- Finally, make a few more customizations to that scale.
local NewScale = PawnCommon.Scales[PawnGetProviderScaleName(ProviderInternalName, ScaleInternalName)]
if not NewScale then return end
NewScale.ClassID = ClassID
NewScale.SpecID = SpecID
NewScale.IconTexturePath = IconTexturePath
NewScale.Role = Role
end
function PawnAddValuesToTooltip(Tooltip, ItemValues, UpgradeInfo, BestItemFor, SecondBestItemFor, NeedsEnhancements, InvType, OnlyFirstValue)
-- First, check input arguments.
if type(Tooltip) ~= "table" then
VgerCore.Fail("Tooltip must be a valid tooltip, not '" .. type(Tooltip) .. "'.")
return
end
if not ItemValues then return end
-- Loop through all of the item value subtables.
local _, _, ClassID = UnitClass("player")
local Entry, _
for _, Entry in pairs(ItemValues) do
local ScaleName, Value, UnenchantedValue, LocalizedName = Entry[1], Entry[2], Entry[3], Entry[4]
local Scale = PawnCommon.Scales[ScaleName]
VgerCore.Assert(Scale ~= nil, "Scale name in item value list doesn't exist!")
if PawnIsScaleVisible(ScaleName) then
-- Ignore values that we don't want to display.
if OnlyFirstValue then
UnenchantedValue = 0
else
if not PawnCommon.ShowEnchanted then Value = 0 end
end
-- Override the localized name if the scale was designed for only the current class, and it's not a user scale.
if Scale.ClassID == ClassID and Scale.SpecID and Scale.Provider then
if Scale.Provider == ScaleProviderName then
LocalizedName = SniperUnitClasses[ClassID]['name']..SniperUnitClasses[ClassID]['spec'][Scale.SpecID]
else
local _, LocalizedSpecName = GetSpecializationInfoForClassID(Scale.ClassID, Scale.SpecID)
LocalizedName = LocalizedSpecName
SniperPawnDump('LocalizedSpecName', LocalizedSpecName)
end
end
-- Add the spec icon if present, and if that feature isn't disabled.
if PawnCommon.ShowSpecIcons and Scale.IconTexturePath then
LocalizedName = "|T" .. Scale.IconTexturePath .. ":0|t " .. LocalizedName
end
local TooltipText = nil
local TextColor = PawnGetScaleColor(ScaleName)
local UnenchantedTextColor = PawnGetScaleColor(ScaleName, true)
if PawnCommon.ShowValuesForUpgradesOnly then
TooltipText = format(PawnNoValueAnnotationFormat, TextColor, LocalizedName)
elseif Value and Value > 0 and UnenchantedValue and UnenchantedValue > 0 and math.abs(Value - UnenchantedValue) >= ((10 ^ -PawnCommon.Digits) / 2) then
TooltipText = format(PawnEnchantedAnnotationFormat, TextColor, LocalizedName, tostring(Value), UnenchantedTextColor, tostring(UnenchantedValue))
elseif Value and Value > 0 then
TooltipText = format(PawnUnenchantedAnnotationFormat, TextColor, LocalizedName, tostring(Value))
elseif UHolynenchantedValue and UnenchantedValue > 0 then
TooltiHolypText = format(PawnUnenchantedAnnotationFormat, TextColor, LocalizedName, tostring(UnenchantedValue))
end
-- Add info to the tooltip if this item is an upgrade or best-in-slot.
local ThisUpgrade, _
WasUpgradeOrBest = false
if UpgradeInfo then
for _, ThisUpgrade in pairs(UpgradeInfo) do
if ThisUpgrade.ScaleName == ScaleName then
if ThisUpgrade.PercentUpgrade >= PawnBigUpgradeThreshold then -- 100 = 10,000%
-- For particularly huge upgrades, don't say ridiculous things like "999999999% upgrade"
TooltipText = format(PawnLocal.TooltipBigUpgradeAnnotation, TooltipText, "")
elseif NeedsEnhancements then
TooltipText = format(PawnLocal.TooltipUpgradeNeedsEnhancementsAnnotation, TooltipText, 100 * ThisUpgrade.PercentUpgrade, "")
else
TooltipText = format(PawnLocal.TooltipUpgradeAnnotation, TooltipText, 100 * ThisUpgrade.PercentUpgrade, "")
end
WasUpgradeOrBest = true
break
end
end
elseif BestItemFor and BestItemFor[ScaleName] then
WasUpgradeOrBest = true
if PawnCommon.ShowValuesForUpgradesOnly then
TooltipText = format(PawnLocal.TooltipBestAnnotationSimple, TooltipText)
else
TooltipText = format(PawnLocal.TooltipBestAnnotation, TooltipText)
end
elseif SecondBestItemFor and SecondBestItemFor[ScaleName] then
WasUpgradeOrBest = true
if PawnCommon.ShowValuesForUpgradesOnly then
TooltipText = format(PawnLocal.TooltipSecondBestAnnotationSimple, TooltipText)
else
TooltipText = format(PawnLocal.TooltipSecondBestAnnotation, TooltipText)
end
end
if not WasUpgradeOrBest and PawnCommon.ShowValuesForUpgradesOnly then TooltipText = nil end
PawnAddTooltipLine(Tooltip, TooltipText)
end
end
end
-- Start of Stat Weight Scales
function SniperPawnScaleProvider_AddScales()
local prov = ScaleProviderName
-- Warrior : Arms
SniperPawnAddPluginScaleFromTemplate( prov, 1, 1, AddonTable.warrior["Arms"], AddonTable.warrior['colour'] )
-- Warrior : Fury
SniperPawnAddPluginScaleFromTemplate( prov, 1, 2, AddonTable.warrior["Fury"], AddonTable.warrior['colour'] )
-- Warrior : Protection
SniperPawnAddPluginScaleFromTemplate( prov, 1, 3, AddonTable.warrior["Protection"], AddonTable.warrior['colour'] )
-- Paladin : Holy
SniperPawnAddPluginScaleFromTemplate( prov, 2, 1, AddonTable.paladin["Holy"], AddonTable.paladin['colour'] )
-- Paladin : Protection
SniperPawnAddPluginScaleFromTemplate( prov, 2, 2, AddonTable.paladin["Protection"], AddonTable.paladin['colour'] )
-- Paladin : Retribution
SniperPawnAddPluginScaleFromTemplate( prov, 2, 3, AddonTable.paladin["Retribution"], AddonTable.paladin['colour'] )
-- Hunter
SniperPawnAddPluginScaleFromTemplate( prov, 3, 1, AddonTable.hunter["Weights"], AddonTable.hunter['colour'], 'Hunter' )
-- Rogue : Assassination
SniperPawnAddPluginScaleFromTemplate( prov, 4, 1, AddonTable.rogue["Assassination"], AddonTable.rogue['colour'] )
-- Rogue : Combat
SniperPawnAddPluginScaleFromTemplate( prov, 4, 2, AddonTable.rogue["Combat"], AddonTable.rogue['colour'] )
-- Rogue : Subtelty
SniperPawnAddPluginScaleFromTemplate( prov, 4, 3, AddonTable.rogue["Subtelty"], AddonTable.rogue['colour'] )
-- Priest : Discipline
SniperPawnAddPluginScaleFromTemplate( prov, 5, 1, AddonTable.priest["Discipline"], AddonTable.priest['colour'] )
-- Priest : Holy
SniperPawnAddPluginScaleFromTemplate( prov, 5, 2, AddonTable.priest["Holy"], AddonTable.priest['colour'] )
-- Priest : Shadow
SniperPawnAddPluginScaleFromTemplate( prov, 5, 3, AddonTable.priest["Shadow"], AddonTable.priest['colour'] )
-- Shaman : Elemental
SniperPawnAddPluginScaleFromTemplate( prov, 7, 1, AddonTable.shaman["Elemental"], AddonTable.shaman['colour'] )
-- Shaman : Enhancement
SniperPawnAddPluginScaleFromTemplate( prov, 7, 2, AddonTable.shaman["Enhancement"], AddonTable.shaman['colour'] )
-- Shaman : Restoration
SniperPawnAddPluginScaleFromTemplate( prov, 7, 3, AddonTable.shaman["Restoration"], AddonTable.shaman['colour'] )
-- Mage : Arcane
SniperPawnAddPluginScaleFromTemplate( prov, 8, 1, AddonTable.mage["Arcane"], AddonTable.mage['colour'] )
-- Mage : Fire
SniperPawnAddPluginScaleFromTemplate( prov, 8, 2, AddonTable.mage["Fire"], AddonTable.mage['colour'] )
-- Mage : Frost
SniperPawnAddPluginScaleFromTemplate( prov, 8, 3, AddonTable.mage["Frost"], AddonTable.mage['colour'] )
-- Warlock : Affliction
SniperPawnAddPluginScaleFromTemplate( prov, 9, 1, AddonTable.warlock["Affliction"], AddonTable.warlock['colour'] )
-- Warlock : Demonology
SniperPawnAddPluginScaleFromTemplate( prov, 9, 2, AddonTable.warlock["Demonology"], AddonTable.warlock['colour'] )
-- Warlock : Destruction
SniperPawnAddPluginScaleFromTemplate( prov, 9, 3, AddonTable.warlock["Destruction"], AddonTable.warlock['colour'] )
-- Druid : Balance
SniperPawnAddPluginScaleFromTemplate( prov, 11, 1, AddonTable.druid["Balance"], AddonTable.druid['colour'] )
-- Druid : Feral
SniperPawnAddPluginScaleFromTemplate( prov, 11, 2, AddonTable.druid["Feral Combat"], AddonTable.druid['colour'] )
-- Druid : Restoration
SniperPawnAddPluginScaleFromTemplate( prov, 11, 3, AddonTable.druid["Restoration"], AddonTable.druid['colour'] )
------------------------------------------------------------
-- PawnMrRobotScaleProviderOptions.LastAdded keeps track of the last time that we tried to automatically enable scales for this character.
if not PawnMrRobotScaleProviderOptions then PawnMrRobotScaleProviderOptions = { } end
if not PawnMrRobotScaleProviderOptions.LastAdded then PawnMrRobotScaleProviderOptions.LastAdded = 0 end
local _, Class = UnitClass("player")
if PawnMrRobotScaleProviderOptions.LastClass ~= nil and Class ~= PawnMrRobotScaleProviderOptions.LastClass then
-- If the character has changed class since last time, let's start over.
PawnSetAllScaleProviderScalesVisible(ScaleProviderName, false)
PawnMrRobotScaleProviderOptions.LastAdded = 0
end
PawnMrRobotScaleProviderOptions.LastClass = Class
-- These scales are new, and we don't need any upgrade logic yet.
PawnMrRobotScaleProviderOptions.LastAdded = 1
-- After this function terminates there's no need for it anymore, so cause it to self-destruct to save memory.
PawnMrRobotScaleProvider_AddScales = nil
end -- PawnMrRobotScaleProvider_AddScales
------------------------------------------------------------
if not VgerCore.IsClassic then
-- These scales aren't useful on WoW retail, so skip them.
PawnMrRobotScaleProvider_AddScales = nil
else
PawnAddPluginScaleProvider(ScaleProviderName, 'Pawn Sniper Classic', SniperPawnScaleProvider_AddScales)
end