⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 felwoodgather.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
			FelwoodGather_OnUpdate();
		end
	end
	-- countdown check
	if(FelwoodGather_PickupCount.inProgress) then
		FelwoodGather_PickupCount.elapse = FelwoodGather_PickupCount.elapse + elapsed;
		if(FelwoodGather_PickupCount.elapse > 1 ) then
			FelwoodGather_PickupCount.elapse = FelwoodGather_PickupCount.elapse -1;
			FelwoodGather_PickupCountDown(false);
		end
	end
end

-- parser for share timer message
function FelwoodGather_ParseMessage(msg)
	if( not FelwoodGather_Config.acceptTimer ) then
		return;
	end
	local useless1, useless2, var0, var1, var2, var3 = string.find(msg, FELWOODGATHER_PARSE_FORMAT);
--	FelwoodGather_Print(useless1 .. ", "..  useless2 .. ", "..  var1 .. ", "..  var2);
	curTime = GetTime();
	if ( tonumber(var1) and tonumber(var2) and tonumber(var3)) then
		FelwoodGather_SetTimer(tonumber(var1), curTime + tonumber(var2)*60 + tonumber(var3) - FELWOODGATHER_TIMER);
	end

end

-- Main drawer function
function FelwoodGather_MainDraw()
	FelwoodGather_DebugPrint("FelwoodGather_MainDraw called.");
	if(not FELWOODGATHER_ACTIVE) then
		return;
	end
	local curTime = GetTime();
	local eta;
	local etatext;
	for n, Objs in FelwoodGather_WorldObjs do 
		-- set texture
		local mainNoteTexture = getglobal("FelwoodMain"..n.."Texture");
		if (mainNoteTexture == nil) then 
			FelwoodGather_Print("get texture failed" .. n);
		else 
			mainNoteTexture:SetTexture(Objs.texture);
		end

		-- draw icon
		local mainNote = getglobal("FelwoodMain"..n);

		mnX = Objs.x/100 * FelwoodGather_WorldMapDetailFrameWidth;
		mnY = -Objs.y/100 * FelwoodGather_WorldMapDetailFrameHeight;
--		FelwoodGather_Print("position["..n.."]=("..mnX..","..mnY..")");
		mainNote:SetPoint("CENTER", "FelwoodMapOverlayFrame", "TOPLEFT", mnX, mnY);
		mainNote:SetAlpha(FelwoodGather_Config.alpha);
		mainNote:SetWidth(FelwoodGather_Config.scale);
		mainNote:SetHeight(FelwoodGather_Config.scale);
		mainNote:Show();

		-- calculate estimation time
		if (Objs.timer == 0) then
			eta = nil;
			etatext = FWG_NO_TIMER;
		else
			eta = (Objs.timer + FELWOODGATHER_TIMER) - curTime;
			if(eta < 0 ) then
				est = "-";
			else 
				est = "";
			end
			d, h, m, s = ChatFrame_TimeBreakDown(math.abs(eta));
			etatext = format("%s%02d:%02d", est, m, s);
		end

		-- set tooltip text
		mainNote.toolTip = format(FWG_TOOLTIP_TEXT, Objs.item, Objs.location, etatext);
--		mainNote:SetText(Objs.toolTip);

		-- set label text
		local mainNoteLabel = getglobal("FelwoodMain"..n.."Label");
		if (mainNoteLabel == nil) then 
--			FelwoodGather_Print("get label failed" .. n);
		else 
			mainNoteLabel:SetText(etatext);
			if (FelwoodGather_Latest.index == n ) then
--				mainNoteLabel:SetTextColor(0,1,1);
				mainNoteLabel:SetTextColor(FelwoodGather_LabelColorHighlight.r, 
							FelwoodGather_LabelColorHighlight.g, 
							FelwoodGather_LabelColorHighlight.b);
			else
--				mainNoteLabel:SetTextColor(1,1,1);
--[[
				local r = 1; g = 1; b = 1;
				local r = 1; g = 1; b = 1;
				if( eta < 0) then
					r=1; g=0; b=0;
				elseif (eta == 0) then
					r=0.7; g=0.7; b=0.7;
				else 
					r=1; g=1;
					b = eta / FELWOODGATHER_TIMER;
					if( b > 1) then
						b = 1;
					end
				end
]]--
				if ( Objs.timer == 0 ) then
					mainNoteLabel:SetTextColor(
						FelwoodGather_LabelColorPast.r, 
						FelwoodGather_LabelColorPast.g, 
						FelwoodGather_LabelColorPast.b);
				else
					if( eta < 0) then
						mainNoteLabel:SetTextColor(
							FelwoodGather_LabelColorWarn2.r, 
							FelwoodGather_LabelColorWarn2.g, 
							FelwoodGather_LabelColorWarn2.b);
					elseif (Objs.status == 2) then
						mainNoteLabel:SetTextColor(
							FelwoodGather_LabelColorWarn2.r, 
							FelwoodGather_LabelColorWarn2.g, 
							FelwoodGather_LabelColorWarn2.b);
					elseif (Objs.status == 1) then
						mainNoteLabel:SetTextColor(
							FelwoodGather_LabelColorWarn1.r, 
							FelwoodGather_LabelColorWarn1.g, 
							FelwoodGather_LabelColorWarn1.b);
					else
						mainNoteLabel:SetTextColor(
							FelwoodGather_LabelColorNormal.r, 
							FelwoodGather_LabelColorNormal.g, 
							FelwoodGather_LabelColorNormal.b);
					end
				end
--				mainNoteLabel:SetTextColor(r, g, b);
			end
			mainNoteLabel:Show();
		end
	end
end

-- trigger timer function
function FelwoodGather_CheckAndStart(arg1) 
	if(not FELWOODGATHER_ACTIVE) then
		return;
	end
--	local iStart, iEnd, sItem = string.find(arg1, FWG_LOOTMSG_MATCH_PATTERN);
--	if(( sItem ~= nil ) and ((sItem == "[夜龙之息]") or (sItem =="[鞭根块茎]"))) then
	if(( string.find(arg1, FWG_NIGHT_DRAGON_BREATH)) 
		or (string.find(arg1, FWG_WINDBLOSSOM_BERRIES))
		or (string.find(arg1, FWG_WHIPPER_ROOT_TUBER))) then

		x, y = GetPlayerMapPosition("player");
		x= x*100;
		y= y*100;
		curTime = GetTime();
		for n, Objs in FelwoodGather_WorldObjs do 
			if( (Objs.x - x)*(Objs.x - x)+(Objs.y - y)*(Objs.y - y) < 2) then
				Objs.timer = curTime;
				Objs.status = 0;
			else 
				if ((Objs.timer + FELWOODGATHER_TIMER > curTime ) and
				((FelwoodGather_Latest.timer == 0) or (FelwoodGather_Latest.timer > Objs.timer))) then
					FelwoodGather_Latest.index = n;
					FelwoodGather_Latest.timer = Objs.timer;
				end
			end
		end
	else 
		FelwoodGather_DebugPrint("FelwoodGather_CheckAndStart checked but ignored this loot.");
	end
end

-- hide window
function FelwoodGather_HideAll()
	for n, Objs in FelwoodGather_WorldObjs do 
		local mainNote = getglobal("FelwoodMain"..n);
		mainNote:Hide();
	end
end

-- timer update function with notification check.
function FelwoodGather_OnUpdate()
	FelwoodGather_DebugPrint("FelwoodGather_OnUpdate called");
	local curTime = GetTime();

	if (curTime > FelwoodGather_Latest.timer + FELWOODGATHER_TIMER ) then
		FelwoodGather_Latest.index = 0;
		FelwoodGather_Latest.timer = 0;
	end
	for n, Objs in FelwoodGather_WorldObjs do 
		if (Objs.timer == 0) then
		else
			eta = (Objs.timer + FELWOODGATHER_TIMER) - curTime;
			if ((eta < FelwoodGather_Config.warn1) and (Objs.status < 1)) then
				Objs.status = 1;
				FelwoodGather_NotifyEstimate(Objs, eta, false);
			elseif ( (eta < FelwoodGather_Config.warn2) and (Objs.status <2) ) then
				Objs.status = 2;
				FelwoodGather_NotifyEstimate(Objs, eta, false);
			end
			if ((Objs.timer + FELWOODGATHER_TIMER > curTime ) and
			(((FelwoodGather_Latest.timer == 0) and (eta > 0)) or (FelwoodGather_Latest.timer > Objs.timer))) then
				FelwoodGather_Latest.index = n;
				FelwoodGather_Latest.timer = Objs.timer;
			end
		end
		
	end
end

-- notifier
function FelwoodGather_NotifyEstimate(Objs, eta, useChannel) 
	if (not FelwoodGather_Config.notify ) then
		return;
	end
	local d, h, m, s = ChatFrame_TimeBreakDown(math.abs(eta));
	local message = format(FWG_NOTIFY_MESSAGE, Objs.item, Objs.location, m, s);
	if (useChannel) then
		local channel;
		if (GetNumRaidMembers() > 0) then
			channel = "RAID";
		elseif (GetNumPartyMembers() > 0) then
			channel = "PARTY";
		else
			return;
		end
		SendChatMessage(message, channel);
	else 
		FelwoodGather_Print(message);
	end
	PlaySound(FELWOODGATHER_NOTIFY);
end

-- broadcast timers 
-- test needed. I dont know whether the GetTime() values are same for everyone.
-- if not, this should send delta value.
function FelwoodGather_ShareTimer() 
	local channel;
	if (GetNumRaidMembers() > 0) then
		channel = "RAID";
	elseif (GetNumPartyMembers() > 0) then
		channel = "PARTY";
	else
		return;
	end
	local curTime = GetTime();
	local message;
	local count = 0;
	for n, Objs in FelwoodGather_WorldObjs do 
		if ((Objs.timer ~= 0) and (Objs.timer + FELWOODGATHER_TIMER > curTime)) then
			eta = Objs.timer + FELWOODGATHER_TIMER - curTime;
			d, h, m, s = ChatFrame_TimeBreakDown(eta);
			
			message = string.format(FELWOODGATHER_SHARE_TIMER_FORMAT, FWG_BROADCAST_HEADER, n, m, s, Objs.item, Objs.location, Objs.x, Objs.y);
			SendChatMessage(message, channel);
			count = count + 1;
		end
	end
	FelwoodGather_Print(count .. FWG_BROADCAST_COUNTS);
end

--for test
function FelwoodGather_SetTimer(n, time)
	FelwoodGather_WorldObjs[n].timer=time;
	FelwoodGather_WorldObjs[n].status=0;

	FelwoodGather_Latest.index = 0;
	FelwoodGather_Latest.timer = 0;
	curTime = GetTime();
	for n, Objs in FelwoodGather_WorldObjs do 
		if ((Objs.timer + FELWOODGATHER_TIMER > curTime ) and
		((FelwoodGather_Latest.timer == 0) or (FelwoodGather_Latest.timer > Objs.timer))) then
			FelwoodGather_Latest.index = n;
			FelwoodGather_Latest.timer = Objs.timer;
		end
	end
end

function FelwoodGather_Print(message)
	if ( DEFAULT_CHAT_FRAME ) then 
		DEFAULT_CHAT_FRAME:AddMessage(message, 1.0, 0.5, 0.25);
	end
end

function FelwoodGather_DebugPrint(message)
	if (FelwoodGather_DebugMode) then
		FelwoodGather_Print(message);
	end
end	
-- ************** menu handler **********************
-- click handler
function FelwoodGather_OnClick(button, id, parent) 
	ToggleDropDownMenu(1, id, FelwoodMainMenu, parent, 0, 0);
end

-- Menu initializer
function FelwoodMainMenu_Initialize() 
	local info = {};

	if (UIDROPDOWNMENU_MENU_LEVEL == 2) then
	else
		info.isTitle = true;
		info.text = FELWOODGATHER_FELWOODGATHER.." "..FELWOODGATHER_VERSION;
		UIDropDownMenu_AddButton(info);

		info = {};
		info.func = FelwoodGather_Menu_Announce;

		info.text = FELWOODGATHER_ANNOUNCE;
		UIDropDownMenu_AddButton(info);

		info = {};
		info.func = FelwoodGather_Menu_ClearTimer;
		info.text = FELWOODGATHER_CLEARTIMER;
		UIDropDownMenu_AddButton(info);

		info = {};
		info.func = FelwoodGather_ShareTimer;
		info.text = FELWOODGATHER_SHARETIMER;
		UIDropDownMenu_AddButton(info);
	end
end

function FelwoodGather_Menu_ClearTimer() 
--	FelwoodGather_Print(UIDROPDOWNMENU_MENU_VALUE);
	FelwoodGather_SetTimer(UIDROPDOWNMENU_MENU_VALUE, 0);
end

function FelwoodGather_Menu_Announce()
	Objs = FelwoodGather_WorldObjs[UIDROPDOWNMENU_MENU_VALUE];
	if ( (Objs ~= nil) and (Objs.timer ~= 0) ) then
		local eta = (Objs.timer + FELWOODGATHER_TIMER) - GetTime();
		FelwoodGather_NotifyEstimate(Objs, eta, true);
	else 
		FelwoodGather_Print(FWG_NOT_HAVE_TIMER);
	end
end

function FelwoodGather_ToggleConfigWindow()
	if(FelwoodGather_OptionsFrame:IsVisible()) then
		FelwoodGather_OptionsFrame:Hide();
	else
		FelwoodGather_OptionsFrame:Show();
	end
end

function FelwoodGather_Options_OnLoad()
	UIPanelWindows['FelwoodGather_OptionsFrame'] = {area = 'center', pushable = 0};
end

function FelwoodGather_Options_Init()
	FelwoodGather_SliderWarn1:SetValue(FelwoodGather_Config.warn1);
	FelwoodGather_SliderWarn2:SetValue(FelwoodGather_Config.warn2);
	FelwoodGather_SliderAlpha:SetValue(FelwoodGather_Config.alpha);
	FelwoodGather_SliderScale:SetValue(FelwoodGather_Config.scale);
	FelwoodGather_Notify:SetChecked(FelwoodGather_Config.notify);
	FelwoodGather_AcceptTimer:SetChecked(FelwoodGather_Config.acceptTimer);
	FelwoodGather_DebugPrint("Option_Init()");
end

function FelwoodGather_Options_OnHide()
--	if(MYADDONS_ACTIVE_OPTIONSFRAME == this) then
--		ShowUIPanel(myAddOnsFrame);
--	end
end

function FelwoodGather_GetLatestObject()
	if (FelwoodGather_Latest.index ~= 0) then
		return FelwoodGather_WorldObjs[FelwoodGather_Latest.index];
	else
		return nil;
	end
end

function FelwoodGather_PickupCountDown(byUI)
	if(FelwoodGather_PickupCount.inProgress and byUI) then
		-- count down in progress. ignored
		return;
	end

	if(not FelwoodGather_PickupCount.inProgress ) then
		-- start count down
		FelwoodGather_PickupCount.count = FelwoodGather_Config.countdown;
		FelwoodGather_PickupCount.elapse = 0;
		FelwoodGather_PickupCount.inProgress = true;
	end
	-- counter in progress.
	if(FelwoodGather_PickupCount.count == FelwoodGather_Config.countdown) then
		SendChatMessage(FELWOODGATHER_OPENNOW, "SAY");
	elseif (FelwoodGather_PickupCount.count <= 0) then 
		SendChatMessage(FELWOODGATHER_PICKUP, "SAY");
		FelwoodGather_PickupCount.inProgress = false;
	else
		SendChatMessage(""..FelwoodGather_PickupCount.count, "SAY");
	end
	FelwoodGather_PickupCount.count = FelwoodGather_PickupCount.count - 1;
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -