📄 gatherer.lua
字号:
local mainNoteTexture = getglobal("GatherMain"..lastUnused.."Texture");
mainNoteTexture:SetTexture(texture);
if ( GatherConfig and GatherConfig.IconSize ~= nil ) then
mainNote:SetWidth(GatherConfig.IconSize);
mainNote:SetHeight(GatherConfig.IconSize);
end
-- setting value for editing
if (type(gatherInfo.icon) == "string" ) then
numGatherIcon = Gather_DB_IconIndex[numGatherType];
else
numGatherIcon = gatherInfo.icon;
end
mainNote.continent = mapContinent;
mainNote.zoneIndex = mapZone;
mainNote.gatherName = gatherName;
mainNote.localIndex = hPos;
mainNote.gatherType = numGatherType;
mainNote.gatherIcon = numGatherIcon;
if ( not mainNote:IsShown() ) then
mainNote:Show();
end
lastUnused = lastUnused + 1;
end
end
end
end
end
end
local i=1000;
for i=lastUnused, maxNotes, 1 do
-- Delay code to try to work around the delay display problem, pause for 50 ms each 100 items
local overlayFrameNumber = math.floor((i - 1000) / 100 +1);
if ( i < maxNotes and mod(i, 100) == 0 )
then
getglobal("GathererMapOverlayFrame"..overlayFrameNumber):Hide();
end
local mainNote = getglobal("GatherMain"..i);
if ( mainNote and mainNote:IsShown() ) then
mainNote:SetPoint("CENTER", "GathererMapOverlayFrame", "TOPLEFT", Gatherer_WorldMapDetailFrameWidth+16, Gatherer_WorldMapDetailFrameHeight+16);
end
end
Gatherer_UpdateWorldMap = -1;
end
function Gatherer_FindClosest(num, interested)
local gatherLocal = {playerC=0,playerZ=0,playerX=0,playerY=0,px=0,py=0,items={},count=0};
if (not GATHERER_LOADED) then return gatherLocal; end
if (Gatherer_InWorld == false ) then return gatherLocal; end
local continent, zone = Gatherer_GetCurrentZone();
if ((continent == 0) or (zone == 0)) then return gatherLocal; end
local px,py = Gatherer_PlayerPos();
if ((px == 0) and (py == 0)) then return gatherLocal; end
local absPx, absPy = Gatherer_AbsCoord(continent, zone, px, py);
gatherLocal = { playerC=continent, playerZ=zone, playerX=absPx, playerY=absPy, px=px, py=py, items={}, count=0 };
local gatherCount = 0;
local maxAllowable = 0;
if ((GatherConfig.maxDist) and (GatherConfig.maxDist > 0)) then
maxAllowable = GatherConfig.maxDist / 1000;
end
if (not GatherItems[continent] or (GatherItems[continent] and not GatherItems[continent][zone])) then return gatherLocal; end
-- local gatherZone, gathersInZone;
-- for gatherZone, gathersInZone in GatherItems[continent] do
local gatherName, gatherData;
for gatherName, gatherData in GatherItems[continent][zone] do
-- for gatherName, gatherData in gathersInZone do
local gatherType = "Default";
local specificType = "";
local allowed = true;
specificType = Gatherer_FindOreType(gatherName);
if (specificType) then -- Ore
gatherType = 2;
allowed = Gatherer_GetFilter("mining");
else
specificType = Gatherer_FindTreasureType(gatherName);
if (specificType) then -- Treasure
gatherType = 0;
allowed = Gatherer_GetFilter("treasure");
else -- Herb
specificType = gatherName;
gatherType = 1;
allowed = Gatherer_GetFilter("herbs");
end
end
if (not specificType) then
specificType = "default";
end
local userConfig = GatherConfig.users[Gather_Player];
local idx_count=0;
if (userConfig) then
if ( userConfig.interested and userConfig.interested[gatherType] ) then
for interest_index in userConfig.interested[gatherType] do
idx_count= idx_count +1;
end
end
if( gatherType == 2 ) then -- Ore
minSetSkillLevel = userConfig.minSetOreSkill;
if ( not minSetSkillLevel ) then minSetSkillLevel = -1; end
elseif ( gatherType == 1 ) then -- Herb
minSetSkillLevel = userConfig.minSetHerbSkill;
if ( not minSetSkillLevel ) then minSetSkillLevel = -1; end
end
if ( allowed == true and Gather_SkillLevel[specificType] and
minSetSkillLevel > 0 and
(minSetSkillLevel > Gather_SkillLevel[specificType] or
(GatherConfig.rareOre == 1 and Gather_SkillLevel[Gather_RareMatch[specificType]] and
minSetSkillLevel > Gather_SkillLevel[Gather_RareMatch[specificType]] ))
) then
allowed = false;
end
end
if ((allowed == true) and
((userConfig == nil) or
(userConfig.interested == nil) or (idx_count == 0) or userConfig.interested[gatherType] == nil or
(userConfig.interested[gatherType][specificType] == true or
(GatherConfig.rareOre == 1 and userConfig.interested[gatherType][Gather_RareMatch[specificType]])
)
)
) then
local maxNum=100;
local gatherInfo;
for _, gatherInfo in gatherData do
local absHx;
local absHy;
if ((not gatherInfo.gtype) or (gatherInfo.gtype == "")) then
gatherInfo.gtype = gatherType;
end
if ((not gatherInfo.icon) or (gatherInfo.icon == "")) then
gatherInfo.icon = Gatherer_GetDB_IconIndex(specificType, gatherType);
end
absHx, absHy = Gatherer_AbsCoord(continent, zone, gatherInfo.x/100, gatherInfo.y/100);
-- absHx, absHy = Gatherer_AbsCoord(continent, gatherZone, gatherInfo.x/100, gatherInfo.y/100); absHx = math.floor(absHx * 100000)/100000;
absHy = math.floor(absHy * 100000)/100000;
if ((absHx ~= 0) and (absHy ~= 0)) then
local maxLocalPos = 0;
local replCandidate = 0;
local dist, deltaX, deltaY = Gatherer_Distance(absPx, absPy, absHx, absHy);
if ((maxAllowable == 0) or (dist < maxAllowable)) then
local localPos, localInfo;
for localPos, localInfo in gatherLocal.items do
if ( localPos <= num ) then
if (localPos > maxLocalPos) then maxLocalPos = localPos; end
-- take node at the same approximate spot into consideration
if ( (abs(gatherInfo.x - localInfo.item.x) <= GATHERER_CLOSESTCHECK or
Gatherer_Round(gatherInfo.x * 10) == Gatherer_Round(localInfo.item.x * 10)) and
(abs(gatherInfo.y - localInfo.item.y) <= GATHERER_CLOSESTCHECK or
Gatherer_Round(gatherInfo.y * 10) == Gatherer_Round(localInfo.item.y * 10)) )
then
replCandidate = maxNum;
maxNum = maxNum + 1;
-- shorter distance
elseif (localInfo.dist > dist) then
if ((replCandidate == 0) or (gatherLocal.items[replCandidate] and (localInfo.dist > gatherLocal.items[replCandidate].dist)))
then
replCandidate = localPos;
end
end
end
end
-- select candidate
if ( maxLocalPos < num ) then
replCandidate = maxLocalPos+1;
elseif ( maxLocalPos == num and gatherLocal.items[replCandidate] and dist > gatherLocal.items[replCandidate].dist ) then
replCandidate = 0;
end
if (replCandidate > 0) then
local setItem = {};
setItem.name = gatherName;
setItem.item = gatherInfo;
setItem.dist = dist;
setItem.deltax = deltaX;
setItem.deltay = deltaY;
gatherLocal["items"][replCandidate] = setItem;
gatherCount = gatherCount+1;
end
end
end
end
end
-- end
end
gatherLocal.count = gatherCount;
return gatherLocal;
end
-- *************************************************************************
-- Coordinates computing related functions
function isMinimapInCity()
local tempzoom = 0;
local inCity = false;
if (GetCVar("minimapZoom") == GetCVar("minimapInsideZoom")) then
if (GetCVar("minimapInsideZoom")+0 >= 3) then
Minimap:SetZoom(Minimap:GetZoom() - 1);
tempzoom = 1;
else
Minimap:SetZoom(Minimap:GetZoom() + 1);
tempzoom = -1;
end
end
if (GetCVar("minimapInsideZoom")+0 == Minimap:GetZoom()) then inCity = true; end
Minimap:SetZoom(Minimap:GetZoom() + tempzoom);
return inCity;
end
function Gatherer_AbsCoord(continent, zone, x, y)
if ((continent == 0) or (zone == 0)) then return x, y; end
local r = GatherRegionData[continent][zone];
local absX = x * r.scale + r.xoffset;
local absY = y * r.scale + r.yoffset;
return absX, absY;
end
function Gatherer_Distance(originX, originY, targetX, targetY)
local dx = (targetX - originX);
local dy = (targetY - originY);
local d = Gatherer_Pythag(dx, dy);
return d, dx, dy;
end
function Gatherer_Pythag(dx, dy)
local d = math.sqrt(dx*dx + dy*dy); -- (a*a) is usually computationally faster than math.pow(a,2)
if (d == 0) then d = 0.0000000001; end -- to avoid divide by zero errors.
return d;
end
function Gatherer_GetMapScale(continent, zone, inCity, zoomLevel)
if ((continent == nil) or (zoomLevel == nil)) then return 0,0; end
if ((not GatherRegionData) or
(not GatherRegionData[continent]) or
(not GatherRegionData[continent].scales) or
(not GatherRegionData[continent].scales[zoomLevel]) or
(not GatherRegionData[continent].scales[zoomLevel].xscale) or
(not GatherRegionData[continent].scales[zoomLevel].yscale)) then
return 0,0;
end
local scaleX = GatherRegionData[continent].scales[zoomLevel].xscale;
local scaleY = GatherRegionData[continent].scales[zoomLevel].yscale;
if (inCity == true) then
local cityScale = GatherRegionData.cityZoom[zoomLevel];
scaleX = scaleX * cityScale;
scaleY = scaleY * cityScale;
end
return scaleX, scaleY;
end
function Gatherer_MiniMapPos(deltaX, deltaY, scaleX, scaleY) -- works out the distance on the minimap
local mapX = deltaX * scaleX;
local mapY = deltaY * scaleY;
local mapDist = 0;
mapDist = Gatherer_Pythag(mapX, mapY);
if (mapDist >= 57) then
-- Remap it to just inside the minimap, by:converting dx,dy to angle,distance
-- then truncate distance to 58 and convert angle,58 to dx,dy
local flipAxis = 1;
if (mapX == 0) then mapX = 0.0000000001;
elseif (mapX < 0) then flipAxis = -1;
end
local angle = math.atan(mapY / mapX);
mapX = math.cos(angle) * 58 * flipAxis;
mapY = math.sin(angle) * 58 * flipAxis;
end
return mapX, mapY, mapDist;
end
-- *************************************************************************
-- Recording related functions
-- Test: /script arg1="You perform Herb Gathering on Mageroyal."; Gatherer_ReadBuff("event");
function Gatherer_ReadBuff(event, fishItem, fishTooltip)
local record = false;
local gather, chatline;
local gatherType, gatherIcon, gatherCanonicalName;
local gatherEventType = 0;
if (not arg1 and not event == "SPELLCAST_STOP") then
Gatherer_Print("Gatherer: error, no arg recording aborted.");
Gatherer_RecordFlag = 0;
return;
elseif (arg1) then
chatline = string.gsub(arg1, GATHERER_NOTEXT, "");
end
if ( strfind(event, "CHAT_MSG_LOOT") ) then
-- process loot received message for fishing node recording
gather = Gatherer_FindFishType(fishItem, fishTooltip);
if ( gather ) then
gatherIcon = gather;
gatherType = 0; -- considered as treasure
gatherEventType = 2;
record = true;
end
elseif( strfind(event, "CHAT_MSG") or strfind(event, "CHAT_MSG_SPELL_SELF_BUFF")) then
if (string.find(chatline, HERB_GATHER_STRING)) then
record = true;
gather = string.lower(strsub(chatline, HERB_GATHER_LENGTH, HERB_GATHER_END))
gatherType = 1;
gatherIcon = gather;
elseif (string.find(chatline, ORE_GATHER_STRING)) then
record = true;
gather = string.lower(strsub(chatline, ORE_GATHER_LENGTH, ORE_GATHER_END))
gatherType = 2;
gatherIcon = Gatherer_FindOreType(gather);
if (not gatherIcon) then return; end;
elseif (string.find(chatline, TREASURE_GATHER_STRING)) then
record = true;
gather = string.lower(strsub(chatline, TREASURE_GATHER_LENGTH, TREASURE_GATHER_END));
gatherType = 0;
gatherIcon, gatherCanonicalName = Gatherer_FindTreasureType(gather);
if (not gatherIcon) then return; end;
if ( gatherCanonicalName ) then gather = gatherCanonicalName; end;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -