

hunter_list = {};

--This is an example
hunter_list[1] = {};
hunter_list[1].target = {}
hunter_list[1].reward = {};
hunter_list[1].reward.item = {};
hunter_list[1].name = "õСڤ";
hunter_list[1].level_min = 1;
hunter_list[1].level_max = 150;
hunter_list[1].limit = 2;
hunter_list[1].target[1] = {};
hunter_list[1].target[1].name = "Сʯ";
hunter_list[1].target[1].amount = 5;
hunter_list[1].reward.gold = 100;
hunter_list[1].reward.fame = 20;
hunter_list[1].reward.experience = 200;
hunter_list[1].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 2;
};

hunter_list[2] = {};
hunter_list[2].target = {}
hunter_list[2].reward = {};
hunter_list[2].reward.item = {};
hunter_list[2].name = "Ż";
hunter_list[2].level_min = 1;
hunter_list[2].level_max = 150;
hunter_list[2].limit = 3;
hunter_list[2].target[1] = {};
hunter_list[2].target[1].name = "粼";
hunter_list[2].target[1].amount = 10;
hunter_list[2].target[2] = {};
hunter_list[2].target[2].name = "";
hunter_list[2].target[2].amount = 10;
hunter_list[2].reward.gold = 500;
hunter_list[2].reward.fame = 30;
hunter_list[2].reward.experience = 5000;
hunter_list[2].reward.item[1] = 
{
					id = 7001;
					name = "Ӷ";
					amount = 3;
};

hunter_list[3] = {};
hunter_list[3].target = {}
hunter_list[3].reward = {};
hunter_list[3].reward.item = {};
hunter_list[3].name = "Ķ硷";
hunter_list[3].level_min = 10;
hunter_list[3].level_max = 150;
hunter_list[3].limit = 1;
hunter_list[3].target[1] = {};
hunter_list[3].target[1].name = "";
hunter_list[3].target[1].amount = 20;
hunter_list[3].target[2] = {};
hunter_list[3].target[2].name = "Ưը";
hunter_list[3].target[2].amount = 20;
hunter_list[3].reward.gold = 800;
hunter_list[3].reward.fame = 50;
hunter_list[3].reward.experience = 15000;
hunter_list[3].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 5;
};

hunter_list[4] = {};
hunter_list[4].target = {}
hunter_list[4].reward = {};
hunter_list[4].reward.item = {};
hunter_list[4].name = "·һ";
hunter_list[4].level_min = 20;
hunter_list[4].level_max = 150;
hunter_list[4].limit = 10;
hunter_list[4].target[1] = {};
hunter_list[4].target[1].name = "ˮ";
hunter_list[4].target[1].amount = 20;
hunter_list[4].target[2] = {};
hunter_list[4].target[2].name = "սʿ";
hunter_list[4].target[2].amount = 20;
hunter_list[4].reward.gold = 120;
hunter_list[4].reward.fame = 20;
hunter_list[4].reward.experience = 15000;
hunter_list[4].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 10;
};


hunter_list[5] = {};
hunter_list[5].target = {}
hunter_list[5].reward = {};
hunter_list[5].reward.item = {};
hunter_list[5].name = "ϡ";
hunter_list[5].level_min = 20;
hunter_list[5].level_max = 150;
hunter_list[5].limit = 5;
hunter_list[5].target[1] = {};
hunter_list[5].target[1].name = "";
hunter_list[5].target[1].amount = 1;
hunter_list[5].reward.gold = 150;
hunter_list[5].reward.fame = 100;
hunter_list[5].reward.experience = 18000;
hunter_list[5].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 15;
};


hunter_list[6] = {};
hunter_list[6].target = {}
hunter_list[6].reward = {};
hunter_list[6].reward.item = {};
hunter_list[6].name = "˹Σ";
hunter_list[6].level_min = 30;
hunter_list[6].level_max = 150;
hunter_list[6].limit = 10;
hunter_list[6].target[1] = {};
hunter_list[6].target[1].name = "ҷ";
hunter_list[6].target[1].amount = 20;
hunter_list[6].target[2] = {};
hunter_list[6].target[2].name = "";
hunter_list[6].target[2].amount = 20;
hunter_list[6].reward.gold = 180;
hunter_list[6].reward.fame = 20;
hunter_list[6].reward.experience = 28000;
hunter_list[6].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 20;
};



hunter_list[7] = {};
hunter_list[7].target = {}
hunter_list[7].reward = {};
hunter_list[7].reward.item = {};
hunter_list[7].name = "ϵı";
hunter_list[7].level_min = 25;
hunter_list[7].level_max = 150;
hunter_list[7].limit = 5;
hunter_list[7].target[1] = {};
hunter_list[7].target[1].name = "";
hunter_list[7].target[1].amount = 1;
hunter_list[7].reward.gold = 200;
hunter_list[7].reward.fame = 100;
hunter_list[7].reward.experience = 30000;
hunter_list[7].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 25;
};



hunter_list[8] = {};
hunter_list[8].target = {}
hunter_list[8].reward = {};
hunter_list[8].reward.item = {};
hunter_list[8].name = "ʦϮ¼";
hunter_list[8].level_min = 25;
hunter_list[8].level_max = 155;
hunter_list[8].limit = 5;
hunter_list[8].target[1] = {};
hunter_list[8].target[1].name = "¶";
hunter_list[8].target[1].amount = 1;
hunter_list[8].reward.gold = 210;
hunter_list[8].reward.fame = 100;
hunter_list[8].reward.experience = 32000;
hunter_list[8].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 25;
};



hunter_list[9] = {};
hunter_list[9].target = {}
hunter_list[9].reward = {};
hunter_list[9].reward.item = {};
hunter_list[9].name = "֮衷";
hunter_list[9].level_min = 40;
hunter_list[9].level_max = 150;
hunter_list[9].limit = 5;
hunter_list[9].target[1] = {};
hunter_list[9].target[1].name = "";
hunter_list[9].target[1].amount = 1;
hunter_list[9].reward.gold = 250;
hunter_list[9].reward.fame = 100;
hunter_list[9].reward.experience = 34000;
hunter_list[9].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 30;
};


hunter_list[10] = {};
hunter_list[10].target = {}
hunter_list[10].reward = {};
hunter_list[10].reward.item = {};
hunter_list[10].name = "ߵ";
hunter_list[10].level_min = 50;
hunter_list[10].level_max = 150;
hunter_list[10].limit = 5;
hunter_list[10].target[1] = {};
hunter_list[10].target[1].name = "̴";
hunter_list[10].target[1].amount = 1;
hunter_list[10].reward.gold = 270;
hunter_list[10].reward.fame = 100;
hunter_list[10].reward.experience = 35000;
hunter_list[10].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 35;
};


hunter_list[11] = {};
hunter_list[11].target = {}
hunter_list[11].reward = {};
hunter_list[11].reward.item = {};
hunter_list[11].name = "ѩеʥ";
hunter_list[11].level_min = 60;
hunter_list[11].level_max = 150;
hunter_list[11].limit = 5;
hunter_list[11].target[1] = {};
hunter_list[11].target[1].name = "";
hunter_list[11].target[1].amount = 1;
hunter_list[11].reward.gold = 280;
hunter_list[11].reward.fame = 100;
hunter_list[11].reward.experience = 40000;
hunter_list[11].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 50;
};



hunter_list[12] = {};
hunter_list[12].target = {}
hunter_list[12].reward = {};
hunter_list[12].reward.item = {};
hunter_list[12].name = "˹֮桷";
hunter_list[12].level_min = 65;
hunter_list[12].level_max = 150;
hunter_list[12].limit = 5;
hunter_list[12].target[1] = {};
hunter_list[12].target[1].name = "˹";
hunter_list[12].target[1].amount = 1;
hunter_list[12].reward.gold = 300;
hunter_list[12].reward.fame = 100;
hunter_list[12].reward.experience = 42000;
hunter_list[12].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 60;
};


hunter_list[13] = {};
hunter_list[13].target = {}
hunter_list[13].reward = {};
hunter_list[13].reward.item = {};
hunter_list[13].name = "˫޽ӡ";
hunter_list[13].level_min = 70;
hunter_list[13].level_max = 150;
hunter_list[13].limit = 5;
hunter_list[13].target[1] = {};
hunter_list[13].target[1].name = "";
hunter_list[13].target[1].amount = 1;
hunter_list[13].target[2] = {};
hunter_list[13].target[2].name = "˹";
hunter_list[13].target[2].amount = 1;
hunter_list[13].reward.gold = 350;
hunter_list[13].reward.fame = 100;
hunter_list[13].reward.experience = 45000;
hunter_list[13].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 60;
};


hunter_list[14] = {};
hunter_list[14].target = {}
hunter_list[14].reward = {};
hunter_list[14].reward.item = {};
hunter_list[14].name = "˹";
hunter_list[14].level_min = 80;
hunter_list[14].level_max = 150;
hunter_list[14].limit = 5;
hunter_list[14].target[1] = {};
hunter_list[14].target[1].name = "˹";
hunter_list[14].target[1].amount = 1;
hunter_list[14].reward.gold = 500;
hunter_list[14].reward.fame = 100;
hunter_list[14].reward.experience = 50000;
hunter_list[14].reward.item[1] = 
{
					id = 70012;
					name = "Ӷ";
					amount = 70;
};


--This is the end of the example

hunter_list.count = table.getn(hunter_list);
for i = 1, hunter_list.count do
	hunter_list[i].target.count = table.getn(hunter_list[i].target);
end

local HUNTER_WINDOW_SEQUENCE_NONE = 0;
local HUNTER_WINDOW_SEQUENCE_MAIN = 10000;
local HUNTER_WINDOW_SEQUENCE_ONGOING = 10001;
local HUNTER_WINDOW_SEQUENCE_SUBMIT = 10002;
local HUNTER_WINDOW_SEQUENCE_CANCEL = 10003;
local HUNTER_WINDOW_SEQUENCE_SUBMIT_CONFIRM = 10004;
local HUNTER_WINDOW_SEQUENCE_LIST = 20000;
local HUNTER_WINDOW_SEQUENCE_QUEST = 30000;


Delegate.RegInit("hunter_Init");


function hunter_Init()
	
hunter_create();

end




Delegate.RegDelTalkEvent("hunter_talk_Event");

function hunter_talk_Event(player,msg,color,range,size)
	if(msg=="")then
		return hunter_talk_check( player,msg,color,range,size);
	end
end



function hunter_create() --Ӷ
	if(hunter_index == nil)then
		hunter_index = NL.CreateNpc("lua/Module/hunter.lua","hunter_initialize")
		Char.SetData(hunter_index,%_%,100454);
		Char.SetData(hunter_index,%_ԭ%,100454);
		Char.SetData(hunter_index,%_X%,107);
		Char.SetData(hunter_index,%_Y%,83);
		Char.SetData(hunter_index,%_ͼ%,1000);
		Char.SetData(hunter_index,%_%,4);
		Char.SetData(hunter_index,%_%,"Ӷ񷢷Ա");
		NLG.UpChar(hunter_index);
		Char.SetWindowTalkedEvent("lua/Module/hunter.lua", "hunter_callback_window", hunter_index);
		Char.SetTalkedEvent("lua/Module/hunter.lua", "hunter_callback_talk", hunter_index)
	end

end

Delegate.RegDelBattleStartEvent("hunter_BattleStart_Event");
Delegate.RegDelBattleOverEvent("hunter_BattleOver_Event");

function hunter_BattleStart_Event(battle)
	hunter_battle_precount(battle);
end

function hunter_BattleOver_Event(battle)
	for PwhI=0,4 do
		local PIndex = Battle.GetPlayer(battle,PwhI);
		if(VaildChar(PIndex)==true) then
			if(Char.GetData(PIndex,%_Ѫ%) ~= 0) then
				hunter_battle_count(battle,PIndex);
			end
		end
	end
end



function hunter_initialize( _index_me)

	return true;
end

function hunter_callback_talk( _index_me, _index_tome)
	local message = "5"..
			"\\nãӶ񷢷Ա"..
			"\\nҪṩ"..
			"\\nϸҪŶ "..
			"\\nĿǰΪλ߷"..
			"\\n"..
			"\\n鿴б"..
			"\\n鿴ѽ"..
			"\\nύ"..
			"\\n";
	NLG.ShowWindowTalked( _index_tome, _index_me, 2, %ť_ر%, 
			HUNTER_WINDOW_SEQUENCE_MAIN, message);	
end
function hunter_action_reward_generate( _id)
	local message = "";
	if( hunter_list[_id].reward.gold ~= 0)then
		message = message .. "ҡ".. hunter_list[_id].reward.gold.." ";
	end
	if( hunter_list[_id].reward.fame ~= 0)then
		message = message .. "".. hunter_list[_id].reward.fame.." ";
	end
	if( hunter_list[_id].reward.experience ~= 0)then
		message = message .. "".. hunter_list[_id].reward.experience.." ";
	end
	for i = 1, table.getn( hunter_list[_id].reward.item)do
		message = message .. ""..hunter_list[_id].reward.item[i].name..""..hunter_list[_id].reward.item[i].amount.." ";
	end
	return message;
end
function hunter_show_list( _index_me, _index_tome, _page)
	local button;
	if( _page*5-4 >= hunter_list.count)then
		button = %ť_ȡ%;
	else
		if( _page > 1 and _page*5-4 < hunter_list.count)then
			button = %ť_ȡ%;
		else
			button = %ť_ȡ%;
		end
	end
	local message = "4"..
			"\\nѡԼΧڵ"..
			"\\nԼΪµͽӶ."..
			"\\nעȡɲѯǰ."..
			"\\n";
	for i = _page*5-4, hunter_list.count do
		message = message..
			"\\n"..hunter_list[i].name.."...ȼ"..hunter_list[i].level_min..""..hunter_list[i].level_max;
		if( i == 5)then
			break;
		end
	end

	NLG.ShowWindowTalked( _index_tome, _index_me, 2, button, 
				HUNTER_WINDOW_SEQUENCE_LIST+_page, message);
end

function hunter_show_quest( _index_me, _index_tome, _number)
	local lasttime = tonumber( Field.Get( _index_tome, "hunter_lasttime_".._number));
	local nowtime = tonumber(os.date( "%d",os.time()));
	local times = tonumber( Field.Get( _index_tome, "hunter_limit_".._number));
	if( times == nil or lasttime == nil or lasttime ~= nowtime)then
		times = 0;
	end

	local message = "\\nƣ"..hunter_list[_number].name..
			"\\nȼƣ"..hunter_list[_number].level_min..""..(hunter_list[_number].level_max) ..
			"\\nҪ";
	for i = 1, hunter_list[_number].target.count do
		message = message ..
			hunter_list[_number].target[i].name..""..hunter_list[_number].target[i].amount.." ";
	end

 	message = message ..
		"\\n"..hunter_action_reward_generate( _number);
	message = message ..
		"\\nÿƣ"..times.."/"..hunter_list[_number].limit..
		"\\n\\nע⣺һܣ֮ǰΥԼ鿴ѽб";

	NLG.ShowWindowTalked( _index_tome, _index_me, 2, %ť_Ƿ%, 
				HUNTER_WINDOW_SEQUENCE_QUEST+_number, message);
end

function hunter_show_ongoing( _index_me, _index_tome)
	local flag = tonumber( Field.Get( _index_tome, "hunter_flag"));
	local message = nil;
	if( flag == nil or flag == 0)then
		message = "\\nûڽе";
	else
		local ongoing = tonumber( Field.Get( _index_tome, "hunter_ongoing_quest"));
		local lasttime = tonumber( Field.Get( _index_tome, "hunter_lasttime_"..ongoing));
		local nowtime = tonumber(os.date( "%d",os.time()));
		local times = tonumber( Field.Get( _index_tome, "hunter_limit_"..ongoing));
		if( times == nil or lasttime == nil or lasttime ~= nowtime)then
			times = 0;
		end
		
		message = "\\nƣ"..hunter_list[ongoing].name..
				"\\nȼƣ"..hunter_list[ongoing].level_min..""..(hunter_list[ongoing].level_max) ..
				"\\nҪ";
		for i = 1, hunter_list[ongoing].target.count do
			message = message ..
				hunter_list[ongoing].target[i].name..""..Field.Get( _index_tome, "hunter_target_"..i).."/"..hunter_list[ongoing].target[i].amount.." ";
		end
		message = message ..
			"\\n"..hunter_action_reward_generate( ongoing);
		message = message ..
			"\\nÿƣ"..times.."/"..hunter_list[ongoing].limit;
	end
	--NLG.ShowWindowTalked( _index_tome, _index_me, 2, 1, HUNTER_WINDOW_SEQUENCE_ONGOING, message);
	--NLG.ShowWindowTalked( _index_tome, _index_me, 2, 1, HUNTER_WINDOW_SEQUENCE_ONGOING, message);
	NLG.ShowWindowTalked( _index_tome, _index_me, 2, 1, HUNTER_WINDOW_SEQUENCE_ONGOING, message);

end

function hunter_submit( _index_me, _index_tome)
	local flag = tonumber( Field.Get( _index_tome, "hunter_flag"));
	local message = nil;
	local sequence = nil;
	local button = nil;
	if( flag == nil or flag == 0)then
		message = "\\nûнκ";
		sequence = HUNTER_WINDOW_SEQUENCE_NONE;
		button = 1;
	end
	if( flag == 1)then
		message = "\\nδɡ";
		sequence = HUNTER_WINDOW_SEQUENCE_NONE;
		button = 1;
	end
	if( flag == 2)then
		local number = tonumber( Field.Get( _index_tome, "hunter_ongoing_quest"));
		message = "\\nǷȷύ"..
			"\\n㽫ã"..hunter_action_reward_generate( number);

		sequence = HUNTER_WINDOW_SEQUENCE_SUBMIT_CONFIRM;
		button = %ť_Ƿ%;
	end
	NLG.ShowWindowTalked( _index_tome, _index_me, 2, button, sequence, message);
end

function hunter_submit_reward( _index_me, _index_tome)
	local quest = tonumber( Field.Get( _index_tome, "hunter_ongoing_quest"));
	for i = 1, table.getn( hunter_list[quest].reward.item)do
		Char.GiveItem( _index_tome, hunter_list[quest].reward.item[i].id, hunter_list[quest].reward.item[i].amount);
	end

	Char.AddGold( _index_tome, hunter_list[quest].reward.gold);
	Char.SetData( _index_tome, %_%, Char.GetData( _index_tome,%_%)+hunter_list[quest].reward.fame);
	Char.SetData( _index_tome, %_%, Char.GetData( _index_tome,%_%)+hunter_list[quest].reward.experience);
	NLG.UpChar( _index_tome);
	Field.Set( _index_tome, "hunter_flag", 0);
	for i = 1, hunter_list[quest].target.count do
		Field.Set( _index_tome, "hunter_target_temporary_"..i, 0);
		Field.Set( _index_tome, "hunter_target_"..i, 0);
	end
	Field.Set( _index_tome, "hunter_ongoing_quest", 0);
	local message = "ã"..hunter_action_reward_generate( quest);
	NLG.SystemMessage( _index_tome, message);
end

function hunter_show_cancel( _index_me, _index_tome)
	local flag = tonumber( Field.Get( _index_tome, "hunter_flag"));
	local message = nil;
	if( flag == 0 or flag == nil)then
		local message = "\\nûڽе";
		NLG.ShowWindowTalked( _index_tome, _index_me, 2, 1, HUNTER_WINDOW_SEQUENCE_NONE, message);
		return;
	end
	local message = "\\nΥԼħ1000һУȷ";
	NLG.ShowWindowTalked( _index_tome, _index_me, 2, %ť_Ƿ%, HUNTER_WINDOW_SEQUENCE_CANCEL, message);
end
function hunter_callback_window( _index_me, _index_tome, _sequence, _select, _data)
	if( _sequence == HUNTER_WINDOW_SEQUENCE_MAIN)then
		argument = tonumber( _data);
		if( argument == 1)then
			hunter_show_list( _index_me, _index_tome, 1);
		end
		if( argument == 2)then
			hunter_show_ongoing( _index_me, _index_tome);
		end
		if( argument == 3)then
			hunter_submit( _index_me, _index_tome);
		end
		if( argument == 4)then
			hunter_show_cancel( _index_me, _index_tome);
		end
	end
	if( _sequence == HUNTER_WINDOW_SEQUENCE_CANCEL)then
		if( _select == %ť_%)then
			local quest = tonumber( Field.Get( _index_tome, "hunter_ongoing_quest"));
			Field.Set( _index_tome, "hunter_flag", 0);
			for i = 1, hunter_list[quest].target.count do
				Field.Set( _index_tome, "hunter_target_temporary_"..i, 0);
				Field.Set( _index_tome, "hunter_target_"..i, 0);
			end
			Field.Set( _index_tome, "hunter_ongoing_quest", 0);
			Char.AddGold( _index_tome, -1000);
			NLG.SystemMessage( _index_tome, "ѷ۳ħ1000");
		end
	end
	if( _sequence == HUNTER_WINDOW_SEQUENCE_SUBMIT_CONFIRM)then
		if( _select == %ť_%)then
			hunter_submit_reward( _index_me, _index_tome);
		end
	end
	if( _sequence >= HUNTER_WINDOW_SEQUENCE_LIST and _sequence < HUNTER_WINDOW_SEQUENCE_QUEST)then
		if( _select == %ť_ر%)then
			return;
		end
		if( _select == %ť_ȡ% - %ť_ر%)then
			hunter_show_list( _index_me, _index_tome, _sequence-HUNTER_WINDOW_SEQUENCE_LIST+1);
		end
		if( _select == %ť_ȡ% - %ť_ر%)then
			hunter_show_list( _index_me, _index_tome, _sequence-HUNTER_WINDOW_SEQUENCE_LIST-1);
		end
		hunter_show_quest( _index_me, _index_tome, tonumber(_data)+(_sequence-HUNTER_WINDOW_SEQUENCE_LIST-1)*5)
	end

	if( _sequence >= HUNTER_WINDOW_SEQUENCE_QUEST)then
		if( _select == %ť_%)then
			local level = Char.GetData( _index_tome, %_ȼ%);
			local i = _sequence-HUNTER_WINDOW_SEQUENCE_QUEST;
			local flag = tonumber( Field.Get( _index_tome, "hunter_flag"));
			local lasttime = tonumber( Field.Get( _index_tome, "hunter_lasttime_"..i));
			local nowtime = tonumber(os.date( "%d",os.time()));
			local times = tonumber( Field.Get( _index_tome, "hunter_limit_"..i));
			if( times == nil)then
				times = 0;
			end
			if( lasttime == nowtime)then
				if( times >= hunter_list[i].limit)then
					local message = "\\nһڿɵĴѡ";
					NLG.ShowWindowTalked( _index_tome, _index_me, 2, 1, HUNTER_WINDOW_SEQUENCE_NONE, message);
					return;
				end
			else
				Field.Set( _index_tome, "hunter_limit_"..i, 0);
				times = 0;
			end

			if( flag == 1 or flag == 2)then
				local message = "\\nѾڽе񣬻δύ";
				NLG.ShowWindowTalked( _index_tome, _index_me, 2, 1, HUNTER_WINDOW_SEQUENCE_NONE, message);
				return;
			end
			if( level < hunter_list[i].level_min or level > hunter_list[i].level_max)then
				local message = "\\nȼѡӦȼ"
				NLG.ShowWindowTalked( _index_tome, _index_me, 2, 1, HUNTER_WINDOW_SEQUENCE_NONE, message);
				return;
			end
			Field.Set( _index_tome, "hunter_flag", tostring(1));
			Field.Set( _index_tome, "hunter_ongoing_quest", tostring(i));
			Field.Set( _index_tome, "hunter_lasttime_"..i, nowtime);
			Field.Set( _index_tome, "hunter_limit_"..i, times+1);
			for j = 1, hunter_list[i].target.count do
				Field.Set( _index_tome, "hunter_target_temporary_"..j, 0);
				Field.Set( _index_tome, "hunter_target_"..j, 0);
			end

			local message = "\\nѽܡ";
			NLG.ShowWindowTalked( _index_tome, _index_me, 2, 1, HUNTER_WINDOW_SEQUENCE_NONE, message);
			return;
		end
	end
end





function hunter_battle_precount( _index_battle)
	for pos = 0, 4 do
		local index = Battle.GetPlayer( _index_battle, pos);
		if( VaildChar(index)==true)then
			local flag = tonumber( Field.Get( index, "hunter_flag"));
			if( flag == 1)then
				local quest = tonumber( Field.Get( index, "hunter_ongoing_quest"));
				if( quest ~= nil and quest ~= 0)then
					for i = 1, hunter_list[quest].target.count do
						Field.Set( index, "hunter_target_temporary_"..i, 0);
					end
					for oppos = 10, 19 do
						local opindex = Battle.GetPlayer( _index_battle, oppos);
						if( VaildChar(opindex)==true)then
							for i = 1, hunter_list[quest].target.count do
								if( Char.GetData( opindex, %_%) == hunter_list[quest].target[i].name)then
									if( tonumber( Field.Get( index, "hunter_target_"..i)) < hunter_list[quest].target[i].amount)then
										Field.Set( index, "hunter_target_temporary_"..i, tostring( tonumber( Field.Get( index, "hunter_target_temporary_"..i))+1));
									end
								end
							end
						end
					end
				
					local sum=0;
					for i = 1, hunter_list[quest].target.count do
						local target_count = tonumber( Field.Get( index, "hunter_target_"..i));
						if( target_count ~= nil)then
							if( target_count >= hunter_list[quest].target[i].amount)then
								sum = sum + 1;
							end
						end
					end
					if( sum == hunter_list[quest].target.count)then
						Field.Set( index, "hunter_flag", tostring( 2));
					end
				end
			end
		end
	end
end

function hunter_battle_count( _index_battle, _index_me)
	local quest = tonumber( Field.Get( _index_me, "hunter_ongoing_quest"));
	if( quest ~= nil and quest ~= 0)then
		local flag = tonumber( Field.Get( _index_me, "hunter_flag"));
		if( flag ~= nil)then
			if( flag == 1)then
				for i = 1, hunter_list[quest].target.count do
					precount = tonumber( Field.Get( _index_me, "hunter_target_temporary_"..i));
					count = tonumber( Field.Get( _index_me, "hunter_target_"..i));
					if( precount == nil)then
						precount = 0;
					end
					if( count == nil)then
						count = 0;
					end
					
					count = count + precount;
					
					Field.Set( _index_me, "hunter_target_"..i, tostring( count));
				end
			end
			local sum=0;
			for i = 1, hunter_list[quest].target.count do
				local target_count = tonumber( Field.Get( _index_me, "hunter_target_"..i));
				if( target_count ~= nil)then
					if( target_count >= hunter_list[quest].target[i].amount)then
						sum = sum + 1;
					end
				end
			end
			if( sum == hunter_list[quest].target.count)then
				Field.Set( _index_me, "hunter_flag", tostring( 2));
			end
		end
	end
end

function hunter_talk_check( _index, _message, _color, _range, _size)
	if( tonumber( Field.Get( _index,"hunter_flag")) == 0 or tonumber( Field.Get( _index, "hunter_flag")) == nil)then
		NLG.SystemMessage( _index, "[Ӷ]ûн");
	end
	if( tonumber( Field.Get( _index, "hunter_flag")) == 1)then
		local i = tonumber( Field.Get( _index, "hunter_ongoing_quest"));
		
		for j = 1, hunter_list[i].target.count do
			local message = "[Ӷ]";
			message = message..
				""..hunter_list[i].name.."ɱ"..
				hunter_list[i].target[j].name..
				"("..
				Field.Get( _index, "hunter_target_"..j)..
				"/"..
				hunter_list[i].target[j].amount..
				")" ;
			NLG.SystemMessage( _index, message);
		end
		
	end
	if( tonumber( Field.Get( _index, "hunter_flag")) == 2)then
		NLG.SystemMessage( _index, "[Ӷ]Ѿɣύ");
	end
	return false;
end