--------------------------------------------------
-- 2012 olympic event
----------------------------------------------------

quest olympic_badge begin
	state start begin
		function has_it()
			local a = pc.count_item(30265)
			local b = pc.count_item(30266)
			local c = pc.count_item(30267)
			local d = pc.count_item(30268)
			local e = pc.count_item(30269)

			local perfect = a > 0 and b > 0 and  c > 0 and d > 0 and e > 0 
			local notyet = a >0 or b > 0 or  c > 0 or d > 0 or  e > 0 
			if perfect then 
				return 1
			elseif notyet  then
				return 0
			end
		end
		when login with game.get_event_flag("medal_part_drop") >= 1  begin
			set_state(information)
		end
	end

	state information begin
		when letter with pc.level>=30 begin
			local v = find_npc_by_vnum(20017)
			if 0 != v then
				target.vid("__TARGET__", v, "")
			end
			send_letter(gameforge.olympic_badge._060_npcChat)
		end

		when info or button with pc.level>=30 begin
			say("")
			say(gameforge.olympic_badge._190_say)
			say("")
		end
		when __TARGET__.target.click or 20017.chat.gameforge.olympic_badge._010_npcChat	with  game.get_event_flag("medal_part_drop") >= 1 and pc.level>=30 begin
			target.delete("__TARGET__")

			say("")
			say_title(mob_name(20017))
			say(gameforge.olympic_badge._020_say)
			say(gameforge.olympic_badge._030_say)
			wait()
			say("")
			say_title(mob_name(20017))
			say(gameforge.olympic_badge._040_say)
			say(gameforge.olympic_badge._050_say)
			local s = select(locale.yes, locale.no)
			if 2 == s then
				say(gameforge.olympic_badge._140_say)
				local a = select(locale.yes, locale.no)
				if 2 == a then
					say_title(mob_name(20017))
					say(gameforge.olympic_badge._150_say)
					say("")
					return
				end
				say("")
				say_title(mob_name(20017))
				say(gameforge.olympic_badge._160_say)
				set_state(__GIVEUP__)
				return
			end	
			
			say("")
			say_title(mob_name(20017))
			say(gameforge.olympic_badge._170_say)
			set_state(step1)
		end	
	end

	state step1 begin
		when letter with pc.level>=30 begin
			send_letter(gameforge.olympic_badge._060_npcChat)
		end

		when info or button with pc.level>=30 begin
			say("")
			say(gameforge.olympic_badge._180_say)
			say("")
		end
		
		when login or enter with game.get_event_flag("medal_part_drop") == 0 begin
			test = pc.getqf("medal_done")
			if test != 0 then
				pc.setqf("medal_done", 0)
			end
		end
		
		when 20017.chat.gameforge.olympic_badge._060_npcChat with  game.get_event_flag("medal_part_drop") >= 1 and pc.level>=30 begin
			say_title(mob_name(20017))
			say(gameforge.olympic_badge._070_say)
			wait()
			if  count_item_range(30265,30269)== 0  then
				say(gameforge.olympic_badge._100_say)
				return
			elseif olympic_badge.has_it() ==0  then
				say(gameforge.olympic_badge._110_say)
				return
			else 
				say_title(mob_name(20017))
				say(gameforge.olympic_badge._120_say)
				wait()	
				pc.remove_item(30265)
				pc.remove_item(30266) 
				pc.remove_item(30267) 
				pc.remove_item(30268) 
				pc.remove_item(30269) 
				if pc.getqf ("medal_done") == 0 then
					say_title(mob_name(20017))
					say(gameforge.olympic_badge._130_say)
					-- show items
					say_item_vnum(71158)
					--say_item_vnum(71159)
					
					pc.give_item2(71158)
					if 0== pc.get_sex() then
						pc.give_item2(71159)
                        say_item_vnum(71159)
					else
						pc.give_item2(71160)
                        say_item_vnum(71160)
					end
					pc.setqf("medal_done", 1)
					return
				end   --if
				
				say_title(mob_name(20017))
				say(gameforge.olympic_badge._130_say)
				say_item_vnum(50249)
				pc.give_item2(50249)
			end    --if 

		end	   --when 

		end   --state

	state __GIVEUP__ begin
	end
end  --quest
