📄 gatherer.lua
字号:
elseif (strfind(event, "UI_ERROR_MESSAGE") or (strfind(event, "SPELLCAST_STOP") and Gatherer_RecordFlag == 1)) then
-- process event to record, normally not possible gather (low/inexistant skill)
gather = string.lower(Gatherer_ExtractItemFromTooltip());
if ( Gatherer_currentNode and Gatherer_currentNode ~= gather and event == "SPELLCAST_STOP" and Gatherer_RecordFlag == 1) then
gather = string.lower(Gatherer_currentNode);
end;
if (not arg1 and Gatherer_currentAction==nil and event == "SPELLCAST_STOP" and Gatherer_RecordFlag == 1) then
chatline="";
elseif (event ~= "UI_ERROR_MESSAGE" ) then
chatline = Gatherer_currentAction;
end
--Gatherer_Print("DEBUG: gather="..gather.." chatline="..chatline);
-- process non gatherable item because of low/lack of skill
if( gather and not gather ~= "" and (strfind(chatline, TRADE_HERBALISM) or strfind(chatline, OLD_TRADE_HERBALISM) or strfind(chatline, GATHER_HERBALISM)) ) then -- Herb
--Gatherer_Print("DEBUG record Herb");
record = true;
gatherType = 1;
gatherIcon = Gatherer_FindHerbType(gather);
gatherEventType = 1;
elseif (gather and not gather ~= "" and strfind(chatline, TRADE_MINING)) then -- Ore
--Gatherer_Print("DEBUG record Ore");
record = true;
gatherType = 2;
gatherIcon = Gatherer_FindOreType(gather);
gatherEventType = 1;
elseif(gather and not gather ~= "" and (strfind(chatline, TRADE_OPENING) or chatline=="")) then -- Treasure
--Gatherer_Print("DEBUG record Treasure");
record = true
gatherType = 0;
gatherIcon, gatherCanonicalName = Gatherer_FindTreasureType(gather);
-- if (not gatherIcon) then
--Gatherer_Print("DEBUG record Treasure, no icon abort record");
-- Gatherer_RecordFlag = 0;
-- return;
-- end;
if ( gatherCanonicalName ) then gather = gatherCanonicalName; end;
gatherEventType = 1;
end
if (not gatherIcon) then
Gatherer_Print("Gatherer: no icon identified, aborting record.");
Gatherer_RecordFlag = 0;
return;
end
if (event == "SPELLCAST_STOP" and Gatherer_RecordFlag == 1) then
gatherEventType = 0;
end
Gatherer_RecordFlag = 0;
else
Gatherer_RecordFlag = 0;
return;
end
--Gatherer_Print("DEBUG: record type: "..gatherEventType);
if (record == true) then
Gatherer_AddGatherHere(gather, gatherType, gatherIcon, gatherEventType);
end
end
-- this function can be used as an interface by other addons to record things
-- in Gatherer's database, though display is still based only on what is defined
-- in Gatherer items and icons tables.
-- Parameters:
-- gather (string): gather name (string printed in chat)
-- gatherType (number): gather type (0 treasure, 1 herbs, 2 ore)
-- gatherIcon (string): matching icon from Gatherer icon table (match gather name)
-- gatherEventType (number): 0 normal gather, 1 gather without required skill, 2 fishing node
function Gatherer_AddGatherHere(gather, gatherType, gatherIcon, gatherEventType)
if ( GatherConfig.users[Gather_Player].filterRecording[gatherType] and
GatherConfig.users[Gather_Player].interested and
GatherConfig.users[Gather_Player].interested[gatherType] and
not GatherConfig.users[Gather_Player].interested[gatherType][gatherIcon] )
then
return;
end
local px, py = Gatherer_PlayerPos(1);
if (px == 0 and py == 0) then
--Gatherer_Print("Gatherer: Cannot record item position as client is reporting position 0,0");
return;
end
local gatherC, gatherZ = Gatherer_GetCurrentZone();
if (gatherC == 0 or gatherZ == 0) then
--Gatherer_Print("Gatherer: Cannot record item, invalid continent/zone.");
return;
end
local gatherX = px * 100;
local gatherY = py * 100;
if (not GatherItems) then
Gatherer_Print("Initializing empty gatherable database");
GatherItems = { };
end
local function Gatherer_AddGatherToBase(gather, gatherType, gatherC, gatherZ, gatherX, gatherY, gatherIcon, gatherEventType)
local hPos, gatherData;
if (not GatherItems[gatherC]) then GatherItems[gatherC] = { }; end
if (not GatherItems[gatherC][gatherZ]) then GatherItems[gatherC][gatherZ] = { }; end
if (not GatherItems[gatherC][gatherZ][gather]) then GatherItems[gatherC][gatherZ][gather] = { }; end
local found = 0;
local lastGather = 0;
local first_hole = 0;
local count = 0;
local closest = 0;
for hPos, gatherData in GatherItems[gatherC][gatherZ][gather] do
count = count + 1;
if ( first_hole == 0 and hPos ~= count ) then
first_hole = count;
end
local dist, deltaX, deltaY = Gatherer_Distance(gatherX,gatherY, gatherData.x,gatherData.y);
local maxCheckDist = 0.5;
if ( gatherEventType and gatherEventType == 2 ) then maxCheckDist = 1; end
if ((dist < maxCheckDist) and ((closest == 0) or (closest > dist))) then -- same gather
gatherX = (gatherX + gatherData.x) / 2;
gatherY = (gatherY + gatherData.y) / 2;
closest = dist;
found = hPos;
end
if (hPos > lastGather) then
lastGather = hPos;
end
end
if (found == 0 and first_hole == 0) then -- need to create a new one (at hPos+1)
found = lastGather+1;
elseif ( found == 0 and first_hole ~= 0 ) then -- not found but there's a hole, let's fill it
found = first_hole;
end
local gatherCount = 1;
if ( gatherEventType and gatherEventType == 1 )
then
if (GatherItems[gatherC][gatherZ][gather][found] == nil) then
GatherItems[gatherC][gatherZ][gather][found] = { };
gatherCount = 0;
else
gatherCount = GatherItems[gatherC][gatherZ][gather][found].count;
end
else
if (GatherItems[gatherC][gatherZ][gather][found] == nil) then
GatherItems[gatherC][gatherZ][gather][found] = { };
else
gatherCount = GatherItems[gatherC][gatherZ][gather][found].count + 1;
end
end
-- Round off those coordinates
gatherX = math.floor(gatherX * 100)/100;
gatherY = math.floor(gatherY * 100)/100;
GatherItems[gatherC][gatherZ][gather][found].x = gatherX;
GatherItems[gatherC][gatherZ][gather][found].y = gatherY;
GatherItems[gatherC][gatherZ][gather][found].gtype = gatherType;
GatherItems[gatherC][gatherZ][gather][found].count = gatherCount;
GatherItems[gatherC][gatherZ][gather][found].icon = Gatherer_GetDB_IconIndex(gatherIcon, gatherType);
end
Gatherer_AddGatherToBase(gather, gatherType, gatherC, gatherZ, gatherX, gatherY, gatherIcon, gatherEventType);
Gatherer_OnUpdate(0,true);
GatherMain_Draw();
end
-- *************************************************************************
-- Miscellaneous functions (clearing DB, dumping DB content)
function Gatherer_Clear()
Gatherer_Print("Clearing your gather data");
GatherItems = { };
ClosestList = { };
ClosestSearchGather = "";
Gatherer_OnUpdate(0,true);
GatherMain_Draw();
end
function Gatherer_Show()
local gatherCont, gatherZone, gatherName, contData, zoneData, nameData, gatherPos, gatherItem;
for gatherCont, contData in GatherItems do
for gatherZone, zoneData in contData do
for gatherName, nameData in zoneData do
for gatherPos, gatherItem in nameData do
Gatherer_Print(Gather_DB_TypeIndex[gatherItem.gtype].." "..gatherName.." was found in zone "..gatherCont..":"..gatherZone.." at "..gatherItem.x..","..gatherItem.y.." ("..gatherItem.count.." times)");
end
end
end
end
end
-- *************************************************************************
-- String display related functions
function Gatherer_ChatPrint(str)
if ( DEFAULT_CHAT_FRAME ) then
DEFAULT_CHAT_FRAME:AddMessage(str, 1.0, 0.5, 0.25);
end
end
function Gatherer_Print(str, add)
if ((Gather_LastPrinted) and (str == Gather_LastPrinted)) then
return;
end
Gather_LastPrinted = str;
if (add) then
str = str..": "..add;
end
if(ChatFrame2) then
ChatFrame2:AddMessage(str, 1.0, 1.0, 0.0);
end
end
function Gatherer_TitleCase(str)
if (GetLocale() == "frFR") then return str; end
local function ucaseWord(first, rest)
return string.upper(first)..string.lower(rest)
end
return string.gsub(str, "([a-zA-Z])([a-zA-Z']*)", ucaseWord);
end
function Gatherer_MakeName(frameID)
local tmpClosest = ClosestGathers;
local tmpItemIDtable = { }
local tmpCount = 1;
if ( GATHERER_LOADED ) then
local gatherInfo = tmpClosest.items[frameID];
tmpItemIDtable[tmpCount] = {};
tmpItemIDtable[tmpCount].name = Gatherer_GetMenuName(gatherInfo.name);
tmpItemIDtable[tmpCount].count = gatherInfo.item.count;
tmpItemIDtable[tmpCount].dist = math.floor(gatherInfo.dist*10000)/10;
tmpCount = tmpCount + 1;
for id in tmpClosest.items do
if (id ~= frameID and
(abs(gatherInfo.item.x - tmpClosest.items[id].item.x) <= GATHERER_CLOSESTCHECK or
Gatherer_Round(gatherInfo.item.x * 10) == Gatherer_Round(tmpClosest.items[id].item.x * 10)) and
(abs(gatherInfo.item.y - tmpClosest.items[id].item.y) <= GATHERER_CLOSESTCHECK or
Gatherer_Round(gatherInfo.item.y * 10) == Gatherer_Round(tmpClosest.items[id].item.y * 10))) then
tmpItemIDtable[tmpCount] = {};
tmpItemIDtable[tmpCount].name = Gatherer_GetMenuName(tmpClosest.items[id].name);
tmpItemIDtable[tmpCount].count = tmpClosest.items[id].item.count;
tmpItemIDtable[tmpCount].dist = math.floor(tmpClosest.items[id].dist*10000)/10;
tmpCount = tmpCount + 1;
end
end
else
tmpItemIDtable[1].name = "Unknown";
tmpItemIDtable[1].count = 0;
tmpItemIDtable[1].dist = 0;
end
return tmpItemIDtable;
end
-- *************************************************************************
-- Position/Map related functions
function Gatherer_LoadZoneData()
local continentData = {GetMapContinents()};
for continentIndex, continentName in continentData do
local zoneData = {GetMapZones(continentIndex)};
for zoneIndex, zoneName in zoneData do
GatherZoneData[zoneName] = { [1] = continentIndex, [2] = zoneIndex };
end
end
end
function Gatherer_GetCurrentZone()
local zoneData = GatherZoneData[GetRealZoneText()];
if ( zoneData ) then
return zoneData[1], zoneData[2];
else
return 0,0;
end
end
Gatherer_LastZone = {};
function Gatherer_ChangeMap()
local mapContinent = GetCurrentMapContinent();
local mapZone = GetCurrentMapZone();
local minderCurZone = false;
if ((Gatherer_CloseMap ~= nil) and (Gatherer_CloseMap.continent == Gatherer_LastZone.continent) and (Gatherer_CloseMap.zone == Gatherer_LastZone.zone)) then
minderCurZone = true;
end
local playerContinent, playerZone = Gatherer_GetCurrentZone();
Gatherer_LastZone = { continent = playerContinent, zone = playerZone };
if ((playerContinent == 0) or (playerZone == 0)) then return false; end
if ((playerContinent == mapContinent) and (playerZone == mapZone)) then return true; end
if ( GetCurrentMapContinent()>0 and playerZone and playerZone > 0 ) then
if (not WorldMapFrame:IsVisible()) then
SetMapZoom(playerContinent, playerZone);
end
end
local lastTime = 0;
if ((Gatherer_CloseMap ~= nil) and (Gatherer_CloseMap.time ~= nil)) then
lastTime = Gatherer_CloseMap.time;
end
if (minderCurZone) then
Gatherer_MapOpen = false;
Gatherer_CloseMap = { continent = playerContinent, zone = playerZone, time = lastTime };
end
return true;
end
function Gatherer_PlayerPos(forced)
local currentZoneName = GetRealZoneText();
if (currentZoneName ~= Gather_LastZone) then
forced = true;
end
Gather_LastZone = currentZoneName;
if (forced) then Gatherer_ChangeMap(); end
local px, py = GetPlayerMapPosition("player");
if ((px == 0) and (py == 0)) then
if (not forced) then
if (Gatherer_ChangeMap()) then
px, py = GetPlayerMapPosition("player");
else
return 0,0;
end
end
end
return px, py;
end
-- *************************************************************************
-- Special Item handling functions: Database manipulation from world map.
-- following 2 functions have to take scope into account.
function Gatherer_DeleteItem()
local gathIdx = 0;
local zoneIdx = 0;
local cntIdx = 0;
if ( GatherMainMapItem.scope == "Node" ) then
GatherItems[GatherMainMapItem.continent][GatherMainMapItem.zoneIndex][GatherMainMapItem.gatherName][GatherMainMapItem.localIndex] = nil;
elseif ( GatherMainMapItem.scope == "Zone" ) then
GatherItems[GatherMainMapItem.continent][GatherMainMapItem.zoneIndex][GatherMainMapItem.gatherName] = nil;
elseif ( GatherMainMapItem.scope == "Continent" ) then
local search_index;
for search_index in GatherItems[GatherMainMapItem.continent] do
if ( GatherItems[GatherMainMapItem.continent][search_index][GatherMainMapItem.gatherName] ) then
GatherItems[GatherMainMapItem.continent][search_index][GatherMainMapItem.gatherName] = nil;
end
end
elseif ( GatherMainMapItem.scope == "Wo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -