local TraceFrame = DEFAULT_CHAT_FRAME;

-- version 00.00.08 du 20091210
	-- maj du .toc pour wow 3.3

-- version 00.00.07 du 20091031
	--modif je ne sais plus ou, quoi ?

-- version 00.00.06 du 20090831
	-- maj du .toc pour wow 3.2
	-- le max num objet est augmenté à 55000

-- version 00.00.05 du 20090501
	-- maj du .toc pour wow 3.1

-- version 000004 du 20090305
	-- amélioration des interactions entre DBOT, DBOT_linkable et DBCS_mobs_model pour moins etre déconnecté quand nouvelle version de wow
	-- le max num objet est augmenté à 50000

-- version 000003 du 20080329
	-- le max num objet est augmenté à 36000

-- version 000002 du 20080207
	-- les fichiers sont ds le rep DBOT et non pas sans rien ....
	-- validation des fichiers de DBCS en priorité
	
DBOT_execute = true;

local DBOT_debug = 0;

local DBOT_time = 0;
local DBOT_time_1sec = 0;
--local DBOT_refresh = 30; -- = une fois toutes les n secondes
--local DBOT_refresh = 5; -- = une fois toutes les n secondes
local DBOT_refresh = 3; -- = une fois toutes les n secondes
--local DBOT_refresh = 2.5; -- = une fois toutes les n secondes
--local DBOT_refresh = 1; -- = une fois toutes les n secondes
--local DBOT_refresh = 0.5; -- = une fois toutes les n secondes
--local DBOT_refresh = 0.25; -- = une fois toutes les n secondes
--local DBOT_refresh = 0.1; -- = une fois toutes les n secondes
--local DBOT_refresh_1sec = 0.1; -- = une fois toutes les 0.1 secondes
local DBOT_refresh_1sec = 0.01; -- = une fois toutes les 0.1 secondes
--local DBOT_refresh_1sec = 1 -- = une fois toutes les 1 secondes
local DBOT_on = 1;
local DBOT_max = 100000;	--95000;	--85000;		--75000;		--70000;		--65000;		--60000;	--55000;	--50000;	--45000;	--40000;		--38000;	--36000;	--34622;	--36737
--local DBOT_indice = 0;
local DBOT_indice = DBOT_max + 1;
local DBOT_valider_DBOS = false;
--/script SetItemRef("item:0");
--/script SetItemRef("item:25");
--/script SetItemRef("item:50250");
--/script DBOT_modeon()
--/script DBOT_f_init(0)
--/script DBOT_f_init(30000)
local DBOT_bunsurdeux = 0;

local DBOT_bindice_quete = false;
local DBOT_quete_max = 35000;	--30000;	--15000;	--30000;
local DBOT_quete_attente_max = 10;
local DBOT_indice_quete = 0;
local DBOT_indice_quete_passage = 1;

local DBOT_lag_time = 0;

local DBOT_bindice_enchant = false;
local DBOT_enchant_max = 150000;	--100000;
local DBOT_enchant_attente_max = 6;
local DBOT_indice_enchant = 0;

local DBOT_serveur = GetRealmName();

function DBOT_OnLoad(self)

	self:RegisterEvent("CHAT_MSG_CHANNEL");
	self:RegisterEvent("VARIABLES_LOADED");

	DBOT = {};

	SLASH_DBOT_SUIVI_ON1 = "/dbot_suivi_on";
	SlashCmdList["DBOT_SUIVI_ON"] = function(msg)
		TraceFrame:AddMessage("je mets dbot suivi on.");
		DBOT_debug = 2;
		DBOT["suivi_on"] = DBOT_debug;
	end
	SLASH_DBOT_SUIVI_OFF1 = "/dbot_suivi_off";
	SlashCmdList["DBOT_SUIVI_OFF"] = function(msg)
		TraceFrame:AddMessage("je mets dbot suivi off.");
		DBOT_debug = 0;
		DBOT["suivi_on"] = DBOT_debug;
	end

end

function DBOT_OnEvent(self,event)

local itemName;
local sdate;

	if ( event == "" ) then
	elseif ( event == "CHAT_MSG_CHANNEL" ) then
		DBOT_OnUpdate();
	elseif ( event == "VARIABLES_LOADED" ) then
		if ( DBOT["indice"] and type(DBOT["indice"]) == "table" ) then
		else
			DBOT["indice"] = {};
		end
		--if ( DBOT["indice"] and DBOT["indice"][DBOT_serveur] ) then
		--	DBOT_indice = DBOT["indice"][DBOT_serveur] - 1;
		--end
		if ( DBOT["suivi_on"] ) then
			DBOT_debug = DBOT["suivi_on"];
		end
		--DBOT_valider_DBOS = false;
		--if ( DBOT["valider_DBOS"] ) then
		--	DBOT_valider_DBOS = DBOT["valider_DBOS"];
		--else
		--	DBOT["valider_DBOS"] = DBOT_valider_DBOS;
		--end
		if ( DBOS01 and DBOS02 ) then
			DBOT_valider_DBOS = true;
		else
			DBOT_valider_DBOS = false;
		end
		DBOT["valider_DBOS"] = DBOT_valider_DBOS;
		--if ( DBOT_valider_DBOS == true ) then
		--	if ( DBOT["indice"] and DBOT["indice"]["DBOS"] ) then
		--		DBOT_indice = DBOT["indice"]["DBOS"] - 1;
		--	end
		--else
			if ( DBOT["indice"] and DBOT["indice"][DBOT_serveur] ) then
				DBOT_indice = DBOT["indice"][DBOT_serveur] + 1;
			end
		--end
		if ( DBOT["indice_quete"] ) then
		else
			DBOT["indice_quete"] = {};
		end
		if ( DBOT["indice_quete"]["indice_quete_indice"] ) then
			DBOT_indice_quete = DBOT["indice_quete"]["indice_quete_indice"];
		end
		if ( DBOT["indice_quete"]["indice_quete_passage"] ) then
			DBOT_indice_quete_passage = DBOT["indice_quete"]["indice_quete_passage"];
		end
		if ( DBOT["indice_enchant"] ) then
		else
			DBOT["indice_enchant"] = {};
		end
		if ( DBOT["indice_enchant"]["indice_enchant_indice"] ) then
			DBOT_indice_enchant = DBOT["indice_enchant"]["indice_enchant_indice"];
		end
		if ( DBOT["indice_enchant"]["indice_enchant_passage"] ) then
			DBOT_indice_enchant_passage = DBOT["indice_enchant"]["indice_enchant_passage"];
		end
		--if ( DBOT_valider_DBOS == false ) then
		--	sdate = date("%Y%m%d");
		--	if ( DBOT["date"] ) then
		--		if ( DBOT["date"] == sdate ) then
		--		else
		--			DBOT_valider_DBOS_on();
		--		end
		--	else
		--		DBOT_valider_DBOS_on();
		--	end
		--	DBOT["date"] = sdate;
		--end
		----	647
		----itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(647);
		--itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(25);
		--if ( DBOT_valider_DBOS == false and itemName == nil ) then
		--	DBOT_valider_DBOS_on();
		--end
	end

end

function DBOT_OnUpdate()

if ( InCombatLockdown() ) then
	return nil;
end

local itime;
local itime2;
local itemName;
local itemLink;
local itemRarity;
local itemTexture;
local bbon;
local i;
local snomenchant;
local ilag;
local tobjet;

--CMS_GetItemLink
----	"@@blabla@1@10000@@
		--itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture = GetItemInfo(DBOT_indice);
--/script DBOT_modeon()
--TraceFrame:AddMessage("itemName  "..itemName);
--TraceFrame:AddMessage("itemRarity  "..itemRarity);
		--itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture = GetItemInfo(DBOT_indice);
		--DBcorpsFrame_Tooltip3:SetHyperlink("item:"..DBOS_extract_i);
--/script SetItemRef("item:14047");
		--SetItemRef("item:"..(DBOS_extract_i+1));

	if ( DBOT_on == 1 ) then
	else
		return nil;
	end

--	DBOT_Tooltip

	itime = GetTime();
	if ( DBOT_bindice_quete == false and DBOT_bindice_enchant == false ) then
--TraceFrame:AddMessage("itime = "..itime);
		bbon = false;
		if ( ( bbon == false ) and ( ( itime - DBOT_time_1sec ) > DBOT_refresh_1sec ) ) then
			itemName, itemLink, itemRarity, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
			if ( itemName ) then
				bbon = true;
				DBOT_bunsurdeux = 1;
			else
				DBOT_time_1sec = GetTime();
			end
		end
		if ( bbon == false and ( itime - DBOT_time > DBOT_refresh ) ) then
			bbon = true;
		end
		--[[
		if ( bbon == true ) then
			if ( DBOT_linkable_time_lag ) then
				bbon = false;
				_, ilag = DBOT_linkable_time_lag();
				if ( GetTime() - ilag < 1 ) then
					bbon = true;
				else
if ( DBOT_debug > 1 ) then
	itime2 = GetTime();
	if ( itime2 - DBOT_lag_time > 1 ) then
		TraceFrame:AddMessage("DBOT_lag : "..(itime2-ilag));
		DBOT_lag_time = itime2;
	end
end
				end
			end
		end
		--]]
		if ( bbon == true ) then
--TraceFrame:AddMessage("bbon = true");
			--if ( 1 == 1 or DBOT_bunsurdeux == 1 ) then
			if ( DBOT_bunsurdeux == 1 ) then
				itemName, itemLink, itemRarity, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
				if ( itemName ) then
if ( DBOT_debug > 1 ) then
TraceFrame:AddMessage(DBOT_indice.." = "..itemLink);
--TraceFrame:AddMessage(DBOT_indice.." = "..CMS_GetItemLink("@@"..itemName.."@"..itemRarity.."@"..DBOT_indice..":0:0:0:0:0:0:0@@"));
end
					if ( DBOS01 and DBOS02 ) then
--						if ( DBOS[DBOT_indice] and DBOS[DBOT_indice][1] ) then
--						else
							DBobjets_initobjet(DBOT_indice);
--						end
					end
				end
				DBOT_indice = DBOT_indice - 1;
				--if ( DBOT_valider_DBOS == false ) then
					DBOT["indice"][DBOT_serveur] = DBOT_indice;
				--else
				--	DBOT["indice"]["DBOS"] = DBOT_indice;
				--end
				----itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
				--if ( DBOT_valider_DBOS == false ) then
				--	itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
				--else
				--	itemTexture = GetItemIcon(DBOT_indice);
				--	if ( ( DBOS and itemTexture ) or DBOT_indice > DBOT_max ) then	--	DBOS[DBOT_indice]
				--		itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
				--	--elseif ( ( DBOT_objets and DBOT_objets[DBOT_indice] ) or DBOT_indice > DBOT_max ) then
				--	--	itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
				--	else
				--		itemName = "bla";
				--	end
				--end
				itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
--TraceFrame:AddMessage("objet : "..(DBOT_indice).." , itemName = "..(itemName or ""));
				if ( itemName ) then
					if ( DBOS01 and DBOS02 ) then
						if ( DBOT_indice > 50000 ) then
							tobjet = DBOS02[DBOT_indice];
						else
							tobjet = DBOS01[DBOT_indice];
						end
						if ( tobjet and ( tobjet[48] == nil ) ) then
							DBobjets_initobjet(DBOT_indice);
						end
					end
				else
					itemTexture = GetItemIcon(DBOT_indice);
--TraceFrame:AddMessage("objet : "..(DBOT_indice).." , itemTexture = "..(itemTexture or ""));
					if ( itemTexture ) then
						if ( DBOS01 and DBOS02 ) then
							if ( DBOT_indice > 50000 ) then
								tobjet = DBOS02[DBOT_indice];
							else
								tobjet = DBOS01[DBOT_indice];
							end
							if ( tobjet == nil ) then
								tobjet = {};
								tobjet[8] = itemTexture;
							end
							if ( DBOT_indice > 50000 ) then
								DBOS02[DBOT_indice] = tobjet;
							else
								DBOS01[DBOT_indice] = tobjet;
							end
						end
						----j'ignore les objets que DBCS connait déjà très bien
						--if ( DBOS == nil ) then
						--elseif ( DBOS[DBOT_indice] == nil ) then
						--elseif ( DBOS[DBOT_indice][4] == nil ) then
						--else
						--	itemName = "bla";
						--end
						----itemName = nil;
					else
						--if ( DBOT_indice > DBOT_max ) then
						if ( DBOT_indice == 0 ) then
							--itemName = nil;
						else
							itemName = "bla";
						end
					end
				end
				i = 0;
				while ( itemName and ( i < 99 ) ) do
					i = i + 1;
					DBOT_indice = DBOT_indice - 1;
					--if ( DBOT_valider_DBOS == false ) then
						DBOT["indice"][DBOT_serveur] = DBOT_indice;
					--else
					--	DBOT["indice"]["DBOS"] = DBOT_indice;
					--end
					--if ( DBOT_valider_DBOS == false ) then
					--	itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
					--else
						--itemTexture = GetItemIcon(DBOT_indice);
						--if ( ( DBOS and itemTexture ) or DBOT_indice > DBOT_max ) then	--	DBOS[DBOT_indice]
						--	itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
						----elseif ( ( DBOT_objets and DBOT_objets[DBOT_indice] ) or DBOT_indice > DBOT_max ) then
						----	itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
						--else
						--	itemName = "bla";
						--end
						itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo(DBOT_indice);
--TraceFrame:AddMessage("objet : "..(DBOT_indice).." , itemName = "..(itemName or ""));
						if ( itemName ) then
							if ( DBOS01 and DBOS02 ) then
								if ( DBOT_indice > 50000 ) then
									tobjet = DBOS02[DBOT_indice];
								else
									tobjet = DBOS01[DBOT_indice];
								end
								if ( tobjet and ( tobjet[48] == nil ) ) then
									DBobjets_initobjet(DBOT_indice);
								end
							end
						else
							itemTexture = GetItemIcon(DBOT_indice);
--TraceFrame:AddMessage("objet : "..(DBOT_indice).." , itemTexture = "..(itemTexture or ""));
							if ( itemTexture ) then
								if ( DBOS01 and DBOS02 ) then
									if ( DBOT_indice > 50000 ) then
										tobjet = DBOS02[DBOT_indice];
									else
										tobjet = DBOS01[DBOT_indice];
									end
									if ( tobjet == nil ) then
										tobjet = {};
										tobjet[8] = itemTexture;
									end
									if ( DBOT_indice > 50000 ) then
										DBOS02[DBOT_indice] = tobjet;
									else
										DBOS01[DBOT_indice] = tobjet;
									end
								end
								----j'ignore les objets que DBCS connait déjà très bien
								--if ( DBOS == nil ) then
								--elseif ( DBOS[DBOT_indice] == nil ) then
								--elseif ( DBOS[DBOT_indice][4] == nil ) then
								--else
								--	itemName = "bla";
								--end
								----itemName = nil;
							else
								--if ( DBOT_indice > DBOT_max ) then
								if ( DBOT_indice == 0 ) then
									--itemName = nil;
								else
									itemName = "bla";
								end
							end
						end
					--end
				end
if ( DBOT_debug > 1 ) then
TraceFrame:AddMessage("objet : "..(DBOT_indice));
end
				DBOT_Tooltip:SetOwner(WorldFrame,"ANCHOR_NONE");
				DBOT_Tooltip:SetHyperlink("item:"..DBOT_indice..":0:0:0:0:0:0:0:0:0");
				--SetItemRef("item:"..(DBOT_indice));
		
				--if ( DBOT_indice > DBOT_max ) then
				if ( DBOT_indice < 1 ) then
					DBOT_indice = DBOT_max + 1;
					--if ( DBOT_valider_DBOS == false ) then
						DBOT["indice"][DBOT_serveur] = DBOT_indice;
					--else
					--	DBOT["indice"]["DBOS"] = DBOT_indice;
					--	--DBOT_valider_DBOS_off();
					--	--if ( DBOT["indice"] and DBOT["indice"][DBOT_serveur] ) then
					--	--	DBOT_indice = DBOT["indice"][DBOT_serveur] - 1;
					--	--end
					--	--DBOT_indice = 0;
					--end
				end
				DBOT_bunsurdeux = 0;
			else
				DBOT_Tooltip:SetOwner(WorldFrame,"ANCHOR_NONE");
				DBOT_Tooltip:SetHyperlink("item:6948:0:0:0:0:0:0:0:0:0");	-- pierre de foyer
				--SetItemRef("item:14047");
				DBOT_bunsurdeux = 1;
			end
			DBOT_time = GetTime();
			DBOT_time_1sec = DBOT_time;
		end
	elseif ( DBOT_bindice_quete == true ) then
--local DBOT_bindice_quete = false;
--local DBOT_quete_max = 14000;
--local DBOT_quete_attente_max = 10; -- en secondes
--local DBOT_indice_quete = 0;
--local DBOT_indice_quete_passage = 1;
		bbon = false;
		if ( bbon == false and ( itime - DBOT_time_1sec > DBOT_refresh_1sec ) ) then
			if ( DBQS2_enreg_quete_tester() == false ) then
				bbon = true;
			else
				DBOT_time_1sec = GetTime();
			end
		end
		if ( bbon == false and ( itime - DBOT_time > DBOT_quete_attente_max ) ) then
			bbon = true;
		end
		if ( bbon == true ) then
			--if ( DBquetes2_Tooltip1:IsShown() ) then
			--	if ( DBOT_indice_quete_passage == 2 ) then
			--	end
			--end
			if ( DBOT_indice_quete_passage == 1 ) then
				DBOT_indice_quete = DBOT_indice_quete + 1;
				--while ( DBOT_indice_quete <= DBOT_quete_max and DBquetes2[DBOT_indice_quete] == nil ) do
				--	DBOT_indice_quete = DBOT_indice_quete + 1;
				--end
				if ( DBOT_indice_quete > DBOT_quete_max ) then
					DBOT_indice_quete = 0;
					DBOT_indice_quete_passage = 2;
				else
				end
			else
				DBOT_indice_quete = DBOT_indice_quete + 1;
				--while ( DBOT_indice_quete <= DBOT_quete_max and DBquetes2[DBOT_indice_quete] == nil ) do
				--	DBOT_indice_quete = DBOT_indice_quete + 1;
				--end
				if ( DBOT_indice_quete > DBOT_quete_max ) then
					DBOT_indice_quete = 0;
					DBOT_indice_quete_passage = 1;
					DBOT_bindice_quete = false;
if ( DBOT_debug > 1 ) then
TraceFrame:AddMessage("fin de la recherche de qu\195\170te.");
end
				else
				end
			end
			DBOT["indice_quete"]["indice_quete_indice"] = DBOT_indice_quete;
			DBOT["indice_quete"]["indice_quete_passage"] = DBOT_indice_quete_passage;
			DBquetes2_numquete_old = DBOT_indice_quete;
			DBquetes2_Tooltip1TextLeft1:SetText(nil);
			DBquetes2_Tooltip1:SetOwner(UIParent,"ANCHOR_CURSOR");
			DBquetes2_Tooltip1:SetHyperlink("quest:"..DBOT_indice_quete..":0");
			DBquetes2_Tooltip1:Show();
			DBOT_time = GetTime();
			DBOT_time_1sec = DBOT_time;
		end
	elseif ( DBOT_bindice_enchant == true ) then
		bbon = false;
		if ( bbon == false and ( itime - DBOT_time_1sec > DBOT_refresh_1sec ) ) then
			if ( DBOT_enchant_ajouterdsmobs(DBOT_indice_enchant) == false ) then
				bbon = true;
			else
				DBOT_time_1sec = GetTime();
			end
		end
		if ( bbon == false and ( itime - DBOT_time > DBOT_enchant_attente_max ) ) then
			bbon = true;
		end
		if ( bbon == true ) then
			i = 0;
			repeat
				i = i + 1;
				DBOT_indice_enchant = DBOT_indice_enchant + 1;
				DBOT["indice_enchant"]["indice_enchant_indice"] = DBOT_indice_enchant;
				DBOT_Tooltip_enchantTextLeft1:SetText(nil);
				DBOT_Tooltip_enchant:SetOwner(UIParent,"ANCHOR_CURSOR");
				DBOT_Tooltip_enchant:SetHyperlink("enchant:"..DBOT_indice_enchant);
				DBOT_Tooltip_enchant:Show();
				snomenchant = DBOT_Tooltip_enchantTextLeft1:GetText();
			until ( i == 100 or snomenchant )
			if ( snomenchant ) then
if ( DBOT_debug > 1 ) then
TraceFrame:AddMessage("enchant : "..(DBOT_indice_enchant)..":"..CMS_GetItemLink("@@"..snomenchant.."@-1@"..DBOT_indice_enchant.."@@"));
end
			end
			if ( DBOT_indice_enchant > DBOT_enchant_max ) then
				DBOT_bindice_enchant = false;
				DBOT_indice_enchant = 0;
				DBOT["indice_enchant"]["indice_enchant_indice"] = DBOT_indice_enchant;
			end
			DBOT_time = GetTime();
			DBOT_time_1sec = DBOT_time;
		end
	else
	end

end

--/script DBOT_modeon()
function DBOT_modeon()

	DBOT_on = 1;
if ( DBOT_debug > 1 ) then
TraceFrame:AddMessage("j'enclenches DBOT");
end

end

--/script DBOT_modeoff()
function DBOT_modeoff()

	DBOT_on = 0;
if ( DBOT_debug > 1 ) then
TraceFrame:AddMessage("je coupes DBOT");
end

end

--/script DBOT_valider_DBOS_on()
function DBOT_valider_DBOS_on()

	if ( DBOS01 and DBOS02 ) then
		DBOT_valider_DBOS = true;
		DBOT["valider_DBOS"] = DBOT_valider_DBOS;
		DBOT_indice = DBOT_max + 1;
		DBOT["indice"]["DBOS"] = DBOT_indice;
		--DBOT_f_init(0);
	end

end

--/script DBOT_valider_DBOS_off()
function DBOT_valider_DBOS_off()

	DBOT_valider_DBOS = false;
	DBOT["valider_DBOS"] = DBOT_valider_DBOS;
	DBOT_indice = DBOT["indice"][DBOT_serveur] + 1;

end

--/script DBOT_f_init(408)

--/script DBOT_f_init(0)
--/script DBOT_f_init(60)
--/script DBOT_f_init(1000)
--/script DBOT_f_init(3970)
--/script DBOT_f_init(8500)
--/script DBOT_f_init(8800)
--/script DBOT_f_init(9000)
--/script DBOT_f_init(12880)
--/script DBOT_f_init(13147)
--/script DBOT_f_init(14000)
--/script DBOT_f_init(14400)
--/script DBOT_f_init(20000)
--/script DBOT_f_init(24300)
--/script DBOT_f_init(25000)
--/script DBOT_f_init(26000)
--/script DBOT_f_init(26500)
--/script DBOT_f_init(27000)
--/script DBOT_f_init(27300)
--/script DBOT_f_init(27387)
--/script DBOT_f_init(27400)
--/script DBOT_f_init(27555)
--/script DBOT_f_init(28000)
--/script DBOT_f_init(28800)
--/script DBOT_f_init(29000)
--/script DBOT_f_init(30000)
--/script DBOT_f_init(30500)
--/script DBOT_f_init(31000)
--/script DBOT_f_init(31500)
--/script DBOT_f_init(32000)
--/script DBOT_f_init(33000)
--/script DBOT_f_init(33300)
--/script DBOT_f_init(34000)
--/script DBOT_f_init(34300)
--/script DBOT_f_init(34350)
--/script DBOT_f_init(34470)
--/script DBOT_f_init(34770)
--/script DBOT_f_init(35000)
--/script DBOT_f_init(35180)
--/script DBOT_f_init(35185)
--/script DBOT_f_init(35500)
--/script DBOT_f_init(35700)
--/script DBOT_f_init(36000)
--/script DBOT_f_init(37000)
--/script DBOT_f_init(37621)
--/script DBOT_f_init(38000)
--/script DBOT_f_init(38229)
--/script DBOT_f_init(38466)
--/script DBOT_f_init(38518)
--/script DBOT_f_init(38555)
--/script DBOT_f_init(38567)
--/script DBOT_f_init(38601)
--/script DBOT_f_init(39000)
--/script DBOT_f_init(39238)
--/script DBOT_f_init(40000)
--/script DBOT_f_init(41880)
--/script DBOT_f_init(42000)
--/script DBOT_f_init(42800)
--/script DBOT_f_init(43000)
--/script DBOT_f_init(44000)
--/script DBOT_f_init(45000)
--/script DBOT_f_init(46200)
--/script DBOT_f_init(46300)
--/script DBOT_f_init(46800)
--/script DBOT_f_init(47000)
--/script DBOT_f_init(48953)
--/script DBOT_f_init(49000)
--/script DBOT_f_init(49200)
--/script DBOT_f_init(50000)
--/script DBOT_f_init(50560)
--/script DBOT_f_init(52000)
--/script DBOT_f_init(62700)
--/script DBOT_f_init(69900)
--/script DBOT_f_init(71100)
--/script DBOT_f_init(75000)
--/script DBOT_f_init(80000)
--/script DBOT_f_init(85000)
function DBOT_f_init(inumobjet)

	DBOT_indice = inumobjet;
	--if ( DBOT_valider_DBOS == true ) then
	--	DBOT["indice"]["DBOS"] = DBOT_indice;
	--else
		DBOT["indice"][DBOT_serveur] = DBOT_indice;
	--end

end

--/script DBquetes2_Tooltip1:Hide();

--/script DBOT_modeon();
--/script DBOT_modeoff();

--/script DBOT_quete_on();
function DBOT_quete_on()

	DBOT_bindice_quete = true;

end

--/script DBOT_quete_off();
function DBOT_quete_off()

	DBOT_bindice_quete = false;

end

--/script DBOT_quete_on();
--/script DBOT_quete_off();
--/script DBquetes2_Tooltip1:Hide();

--/script DBOT_quete_init(0);
--/script DBOT_quete_init(1);
--/script DBOT_quete_init(1000);
--/script DBOT_quete_init(2000);
--/script DBOT_quete_init(3000);
--/script DBOT_quete_init(4000);
--/script DBOT_quete_init(5000);
--/script DBOT_quete_init(6000);
--/script DBOT_quete_init(7000);
--/script DBOT_quete_init(8000);
--/script DBOT_quete_init(9000);
--/script DBOT_quete_init(10000);
--/script DBOT_quete_init(11000);
--/script DBOT_quete_init(12000);
--/script DBOT_quete_init(13000);
--/script DBOT_quete_init(14000);
--/script DBOT_quete_on();
--/script DBOT_quete_off();
--/script DBOT_quete_init(15000);
--/script DBOT_quete_init(22000);
--/script DBOT_quete_init(23000);
--/script DBOT_quete_init(24000);
--/script DBOT_quete_init(25000);
--/script DBOT_quete_init(26000);
--/script DBOT_quete_init(27000);
--/script DBOT_quete_init(28000);
--/script DBOT_quete_init(29000);
--/script DBOT_quete_init(30000);


--/script DBOT_quete_init(19500);
--/script DBOT_quete_init(20000);
--/script DBOT_quete_init(24900);
--/script DBOT_quete_init(25000);
--/script DBOT_quete_init(29000);
--/script DBOT_quete_init(29990);
--/script DBOT_quete_init(34900);
function DBOT_quete_init(inumquete)

	DBOT_indice_quete = inumquete;

end

--/script DBOS_enchant = {};
--/script DBobjets_enchant_ajouterdsmobs_nettoyer();
--/script DBOT_enchant_init(0);
--/script DBOT_enchant_init(40000);
--/script DBOT_enchant_init(80000);
--/script DBOT_enchant_init(100000);
--/script DBOT_enchant_init(120000);
--/script DBOT_enchant_on();
--/script DBOT_modeon();
--/script DBOT_modeoff();
--/script DBOT_enchant_off();
--/script DBOT_Tooltip_enchant:Hide();

--/script DBOT_enchant_on();
function DBOT_enchant_on()

	DBOT_bindice_enchant = true;

end

--/script DBOT_Tooltip_enchant:Hide();
--/script DBOT_enchant_off();
function DBOT_enchant_off()

	DBOT_bindice_enchant = false;

end

--/script DBOT_enchant_init(0);
--/script DBOT_enchant_init(17187);
--/script DBOT_enchant_init(20000);
--/script DBOT_enchant_init(25000);
function DBOT_enchant_init(inumenchant)

	DBOT_indice_enchant = inumenchant;

end

local DBOT_tablo_compo = {};

function DBOT_enchant_ajouterdsmobs(inumenchant)

if ( InCombatLockdown() ) then
	return nil;
end

local snomobjet = nil;
local snomobjetenchant;
local inumobjet2;
local tablo;
local bbon;
local ipos;
local schamp;
local schamp_composant = nil;
local tablocompo = {};
local scompo;
local ideb;
local i;
local ilen;
local binconnu = false;
local snommetier = nil;
local bnomobjet = false;
local bobjetinconnu = false;
local tobjet = nil;

	snomobjetenchant = DBOT_Tooltip_enchantTextLeft1:GetText();
	if ( snomobjetenchant == nil ) then
		return false;
	end
--if ( DBCS_debug > 1 ) then
--DBCS_ecrirecodedutexte(snomobjetenchant);
--end
	if ( DBOS_enchant[inumenchant] == nil ) then
		DBOS_enchant[inumenchant] = {};
		DBOS_enchant[inumenchant][1] = snomobjetenchant;
		DBOS_enchant[inumenchant][48] = ""..DBCS_date().."@"..DBCS_time();
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("j'ajoute l'enchant : "..inumenchant.." = "..snomobjetenchant);
end
	end
	if ( strlower(strsub(snomobjetenchant,1,10)) == "composants" ) then
		schamp_composant = snomobjetenchant;
		binconnu = true;
	else
		DBOS_enchant[inumenchant][1] = snomobjetenchant;
		ipos = strfind(snomobjetenchant,":");
		if ( ipos ) then
			snommetier = strsub(snomobjetenchant,1,ipos-1);
		end
	end
	for i = 2 , 8 do
		schamp = _G["DBOT_Tooltip_enchantTextLeft"..i]:GetText();
		if ( schamp ) then
			if ( strlower(strsub(schamp,1,10)) == "composants" ) then
				schamp_composant = schamp;
			elseif ( schamp == "R\195\169cup\195\169ration des informations de l'objet" ) then
				bobjetinconnu = true;
			elseif ( bnomobjet == false and strsub(schamp,1,1) == "\n" ) then
				bnomobjet = true;
				snomobjet = strsub(schamp,2);
				if ( snommetier == nil and strlower(strsub(snomobjet,1,6)) == "poison" ) then
					snommetier = "Poisons";
					DBOS_enchant[inumenchant][1] = snommetier..": "..snomobjet;
				end
				DBOS_enchant[inumenchant][8] = snomobjet;
			end
		end
	end
	if ( binconnu == true ) then
		if ( snommetier == nil ) then
			if ( snomobjet == nil ) then
				snomobjet = "E"..inumenchant;
			end
			snommetier = "Inconnu";
			DBOS_enchant[inumenchant][1] = snommetier..": "..snomobjet;
		end
	else
		if ( snomobjet == nil and schamp_composant ) then
			if ( snommetier and strlower(snommetier) == "enchantement" ) then
				snomobjet = strsub(snomobjetenchant,15);
			end
		end
	end
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("nom objet = "..(snomobjet or ""));
end
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("snommetier = "..(snommetier or ""));
end
	if ( schamp_composant ) then
		schamp = schamp_composant;
		schamp = strsub(schamp,17);
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("schamp = "..schamp);
end
		i = 0;
		ideb = 1;
		ipos = strfind(schamp,", ");
		while ( ipos ) do
			scompo = strsub(schamp,ideb,ipos-1);
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("scompo = "..scompo);
end
			i = i + 1;
			tablocompo[i] = {};
			tablocompo[i][1] = scompo;
			ideb = ipos + 2;
			ipos = strfind(schamp,", ",ideb);
		end
		scompo = strsub(schamp,ideb);
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("scompo = "..scompo);
end
		i = i + 1;
		tablocompo[i] = {};
		tablocompo[i][1] = scompo;
		for i = 1 , table.getn(tablocompo) do
			ilen = strlen(tablocompo[i][1]);
			if ( strsub(tablocompo[i][1],1,1) == "|" ) then
				tablocompo[i][1] = strsub(tablocompo[i][1],11,ilen-2);
				ilen = strlen(tablocompo[i][1]);
			end
			ipos = strfind(tablocompo[i][1],"%(");
			if ( ipos ) then
				tablocompo[i][2] = tonumber(strsub(tablocompo[i][1],ipos+1,ilen-1));
				tablocompo[i][1] = strsub(tablocompo[i][1],1,ipos-2);
			else
				tablocompo[i][2] = 1;
			end
			tablocompo[i][1] = strlower(tablocompo[i][1]);
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("tablocompo["..i.."] = "..tablocompo[i][2].." "..tablocompo[i][1]);
end
			if ( DBOT_tablo_compo[tablocompo[i][1]] ) then
				tablocompo[i][3] = DBOT_tablo_compo[tablocompo[i][1]];
			else
				bbon = false;
				for inumobjet2, _ in pairs(DBOS01) do
					tobjet = DBOS01[inumobjet2];
					if ( tobjet[1] and strlower(tobjet[1]) == tablocompo[i][1] ) then
						bbon = true;
						DBOT_tablo_compo[tablocompo[i][1]] = inumobjet2;
					end
				end
				for inumobjet2, _ in pairs(DBOS02) do
					tobjet = DBOS02[inumobjet2];
					if ( tobjet[1] and strlower(tobjet[1]) == tablocompo[i][1] ) then
						bbon = true;
						DBOT_tablo_compo[tablocompo[i][1]] = inumobjet2;
					end
				end
				if ( bbon == true ) then
					tablocompo[i][3] = DBOT_tablo_compo[tablocompo[i][1]];
				end
			end
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("tablocompo["..i.."][3] = "..(tablocompo[i][3] or 0));
end
		end
	end
	tablo = {};
	if ( snomobjet ) then
		for inumobjet2, _ in pairs(DBOS01) do
			tobjet = DBOS01[inumobjet2];
			if ( tobjet[1] and strlower(tobjet[1]) == strlower(snomobjet) ) then
				tablo[inumobjet2] = 0;
				if ( DBOS_enchant[inumenchant][9] == nil ) then
					DBOS_enchant[inumenchant][9] = {};
				end
				DBOS_enchant[inumenchant][9][inumobjet2] = 1;
			end
		end
		for inumobjet2, _ in pairs(DBOS02) do
			tobjet = DBOS02[inumobjet2];
			if ( tobjet[1] and strlower(tobjet[1]) == strlower(snomobjet) ) then
				tablo[inumobjet2] = 0;
				if ( DBOS_enchant[inumenchant][9] == nil ) then
					DBOS_enchant[inumenchant][9] = {};
				end
				DBOS_enchant[inumenchant][9][inumobjet2] = 1;
			end
		end
	end
	if ( snomobjet ) then
		if ( DBMS[snomobjet] ) then
		else
			DBMS[snomobjet] = {};
		end
		if ( DBMS[snomobjet]["1"] ) then
		else
			DBMS[snomobjet]["1"] = {};
		end
		DBMS[snomobjet]["1"][3] = "artisanat";
		DBMS[snomobjet]["1"][5] = snommetier;
		DBMS[snomobjet]["1"][7] = 1;
		if ( DBMS[snomobjet]["1"][8] ) then
			DBMS[snomobjet]["1"][8] = DBmobs_champ_8_en_nombre(DBMS[snomobjet]["1"][8]);
		else
			DBMS[snomobjet]["1"][8] = {};
		end
		for inumobjet2, _ in pairs(tablo) do
			DBMS[snomobjet]["1"][8][inumobjet2] = 0;
		end
		for i = 1 , table.getn(tablocompo) do
			inumobjet2 = tablocompo[i][3];
			if ( inumobjet2 ) then
				DBMS[snomobjet]["1"][8][inumobjet2] = tablocompo[i][2];
			end
		end
	end
	if ( bobjetinconnu == true ) then
		return true;
	else
		return false;
	end

end
