

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