-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMapSpot.lua
More file actions
233 lines (202 loc) · 6.34 KB
/
Copy pathMapSpot.lua
File metadata and controls
233 lines (202 loc) · 6.34 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
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
-- A MapSpot represents one node of a MapSpot type guide.
local ZGV = ZygorGuidesViewer ; if not ZGV then return end
local table,string,tonumber,ipairs,pairs,setmetatable = table,string,tonumber,ipairs,pairs,setmetatable
local MapSpot = {}
ZGV.MapSpotProto = MapSpot
ZGV.MapSpotProto_mt = { __index=MapSpot }
local L = ZGV.L
function MapSpot:New(spottype,level)
return setmetatable({['type']=spottype or "at",['level']=level, ['objects']={}},ZGV.MapSpotProto_mt);
end
function MapSpot:AreRequirementsMet()
--[[
local raceclass=true
if self.requirement then
raceclass=false
for i,v in pairs(self.requirement) do if ZGV:RaceClassMatch(v) then raceclass=true break end end
end
if not raceclass then return false end
if self.condition_visible and not self.condition_visible() then return false end
return true
--]]
-- wrong
end
function MapSpot:GetTitle()
if self.title then return self.title end
if self.vendor then return self.vendor end
return "?"
end
function MapSpot:IsInRange()
return not self.waypoint.hideminimap
--[[
local guide=self.parentGuide
if self.num<#guide.steps then
return guide.steps[self.num+1]
else
guide=ZGV:GetGuideByTitle(self.parentGuide.next)
if guide then
return guide.steps[1]
else
return nil
end
end
--]]
end
function MapSpot:IsVisible()
if self.parentSet then
return self.parentSet.visible and not self.hidden
else
return false
end
end
-- Called for a marker, presumably containing a reference to a MapSpot.
local function MapSpot_waypoint_OnUpdate(waypoint)
if waypoint.spot then waypoint.spot:OnUpdate() end
end
local function MapSpot_waypoint_OnEnter(waypoint,...)
if waypoint.spot then waypoint.spot:OnEnter(...) end
end
local function MapSpot_waypoint_OnEvent(waypoint)
if waypoint.spot then waypoint.spot:OnEvent() end
end
function MapSpot:Show()
if not self.waypoint then
self.waypoint = ZGV.Pointer:SetWaypoint(nil,self.map,self.x,self.y,{title=self:GetTitle(),type="poi",icon=ZGV.DIR .. "\\Skin\\minimaparrow-gold-dot",edgeicon=ZGV.DIR .. "\\Skin\\minimaparrow-gold-edge",overworld=false,onminimap="zonedistance"})
if not self.waypoint then return end
self.waypoint.spot = self
self.waypoint.OnUpdate = MapSpot_waypoint_OnUpdate
self.waypoint.OnEnter = MapSpot_waypoint_OnEnter
self.waypoint.OnEvent = MapSpot_waypoint_OnEvent
end
self:UpdateVisibility()
return self.waypoint
end
function MapSpot:GetObjectsOfType(objtype,onlyvis)
if self.objects then
local ret={}
for o,obj in ipairs(self.objects) do
if obj.item and (obj[objtype] or obj.item[objtype] or (objtype=="drop" and not obj.item.ore and not obj.item.skin and not obj.item.herb and not obj.item.vendor and not obj.vendor)) then
if not onlyvis or not obj.hidden then
tinsert(ret,obj)
end
end
end
if #ret>0 then return ret else return nil end
end
end
local function MapSpot_ObjectToString(obj)
if obj.type=="item" and not obj.hidden then
local id = obj.item.id
local data = id and ZGV:GetItemData(id) or ""
local perc = ""
if obj.perc then perc=(" (%d%%)"):format(obj.perc) end
if obj.toohard then
local skill=""
if obj.item.ore then skill=(" (Mining %d)"):format(obj.item.ore) end
if obj.item.skin then skill=(" (Skinning %d)"):format(obj.item.skin) end
if obj.item.herb then skill=(" (Herbalism %d)"):format(obj.item.herb) end
obj.string = data..perc..skill
else
obj.string = data..perc
end
obj.icon = "|T"..(GetItemIcon(obj.item.id) or "")..":13:13:0:0:64:64:4:60:4:60|t"
obj.iconstring = obj.icon.." "..obj.string
else
obj.string = ""
obj.iconstring = ""
end
end
function MapSpot:UpdateVisibility()
local visible,possible=0,0
if self.objects then
for o,obj in ipairs(self.objects) do
possible=possible+1
if obj.type=="item" then
local req = ZGV.db.profile.goldreqmode
local noskill = (obj.item.herb and ZGV:GetSkill("Herbalism").level==0)
or (obj.item.ore and ZGV:GetSkill("Mining").level==0)
or (obj.item.skin and ZGV:GetSkill("Skinning").level==0)
obj.toohard = (obj.item.herb and obj.item.herb>ZGV:GetSkill("Herbalism").level)
or (obj.item.ore and obj.item.ore>ZGV:GetSkill("Mining").level)
or (obj.item.skin and obj.item.skin>ZGV:GetSkill("Skinning").level)
if req==3 and obj.toohard then
obj.hidden=true
elseif req==2 and noskill then
obj.hidden=true
else
obj.hidden=nil
visible=visible+1
end
else
visible=visible+1
end
MapSpot_ObjectToString(obj)
end
end
--ZGV:Debug("Updating visibility for mapspot")
self.hidden = (possible>0 and visible==0)
if self.waypoint then self.waypoint.hidden=self.hidden end
end
function MapSpot:Hide()
if self.waypoint then
ZGV.Pointer:RemoveWaypoint(self.waypoint)
end
end
local itemsources={"vendor","drop","ore","herb","skin"}
function MapSpot:FillTooltip(tooltip)
ZGV:Debug("Filling tooltip (MS set)") MS=self
if self.hidden then return false end
tooltip:AddLine(self.desc,1,1,1,true)
if self.objects then
for s,source in ipairs(itemsources) do
local objs = self:GetObjectsOfType(source,true)
if objs then
local mobs = source=="drop" and self.mobs
local mobtext
if mobs then
mobtext = ""
for i,mob in ipairs(self.mobs) do
if #mobtext>0 then mobtext = mobtext .. ", " end
mobtext = mobtext .. mob.name
end
elseif self.vendorid then
mobtext = self.vendor
end
tooltip:AddLine(L['gold_header_'..source]:format(mobtext),0.7,0.7,0.4,true)
for o,obj in ipairs(objs) do
if obj.toohard then tooltip:AddLine(obj.iconstring,1,0,0,true) else tooltip:AddLine(obj.iconstring,1,1,1,true) end
end
end
end
end
tooltip:SetWidth(200)
end
function MapSpot:OnUpdate()
if not self.waypoint then return end
local minimapframe = self.waypoint.minimapFrame
--print("onupdate "..self.title)
local oldhide = self.waypoint.hideminimap
if minimapframe.dist and (minimapframe.dist<ZGV.db.profile.golddetectiondist) then
self.waypoint.hideminimap=nil
else
self.waypoint.hideminimap=true
end
if self.waypoint.hideminimap~=oldhide then
ZGV:UpdateFrame(true)
end
end
function MapSpot:OnEnter(tooltip)
return self:FillTooltip(tooltip)
end
function MapSpot:OnLeave(tooltip)
tooltip:Hide()
end
function MapSpot:OnEvent()
self:UpdateVisibility()
--if GetCurrentMapZone()==0 then self.waypoint.hidden=true end
end
function MapSpot:OnClick()
if self.waypoint then
ZGV.Pointer:ShowArrow(self.waypoint)
end
end