
quest subquest_40 begin
	state start begin
		when login or levelup with pc.level >= 56  and pc.level <= 58 begin
			set_state(information)
		end

	end

	state information begin
		when letter begin
			
			local v = find_npc_by_vnum(20355)

			if v != 0 then
				target.vid("__TARGET__", v, gameforge.subquest_40._10_targetVid)
			end
		end
		
		when __TARGET__.target.click or 20355.chat.gameforge.subquest_40._10_targetVid with pc.level >= 56 and pc.getqf("aborted") != 1 begin
			target.delete("__TARGET__")
                        say_title(gameforge.main_quest_lv10._30_sayTitle)
                        say(gameforge.subquest_40._20_say)
                        wait()
                        say_title(gameforge.main_quest_lv10._30_sayTitle)
                        say(gameforge.subquest_40._30_say)
                        wait()
                        say_title(gameforge.main_quest_lv10._30_sayTitle)
                        say(gameforge.subquest_40._40_say)
                        local b= select(gameforge.subquest_40._50_select, gameforge.subquest_40._60_select)
                        if 2==b then
                                say(gameforge.subquest_40._70_say)
                                local a= select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
                                if 2==a then
                                        say_title(gameforge.main_quest_lv10._30_sayTitle)
                                        say(gameforge.subquest_40._80_say)
                                        pc.setqf("aborted", 1)
                                        return
                                end
                                say_title(gameforge.main_quest_lv10._30_sayTitle)
                                say(gameforge.subquest_40._90_say)
                                pc.setqf("aborted",0)
                                set_state(__GIVEUP__)
                                return
                        end
                        say_title(gameforge.main_quest_lv10._30_sayTitle)
                        say(gameforge.subquest_40._100_say)
                        pc.setqf("aborted",0)
                        set_state(for_five_thousand_bow)
                        return
		end

		when __TARGET__.target.click or
                        20355.chat.gameforge.subquest_40._140_npcChat with pc.level >= 56 and pc.getqf("aborted") == 1 begin
			target.delete("__TARGET__")
			say_title(gameforge.main_quest_lv10._30_sayTitle)
			say(gameforge.subquest_40._20_say)
			wait()
			say_title(gameforge.main_quest_lv10._30_sayTitle)
			say(gameforge.subquest_40._30_say)
			wait()
			say_title(gameforge.main_quest_lv10._30_sayTitle)
			say(gameforge.subquest_40._40_say)
			local b= select(gameforge.subquest_40._50_select, gameforge.subquest_40._60_select)
			if 2==b then
				say(gameforge.subquest_40._70_say)
				local a= select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
				if 2==a then
					say_title(gameforge.main_quest_lv10._30_sayTitle)
					say(gameforge.subquest_40._80_say)
					pc.setqf("aborted", 1)
					return 
				end
				say_title(gameforge.main_quest_lv10._30_sayTitle)
				say(gameforge.subquest_40._90_say)
				pc.setqf("aborted",0)
				set_state(__GIVEUP__)
				return
			end
			say_title(gameforge.main_quest_lv10._30_sayTitle)
			say(gameforge.subquest_40._100_say)
			pc.setqf("aborted",0)
			set_state(for_five_thousand_bow)
			return
		end
	end
	state for_five_thousand_bow begin
		when letter begin
			send_letter(gameforge.subquest_40._10_targetVid)
			
			if 	pc.count_item("30157")>=5000 then	
				local v=find_npc_by_vnum(20355)
				if 0 == v then
				else
					target.vid("__TARGET__",v, gameforge.subquest_40._110_targetVid)
				end 
			end

		end
		when button or info begin
			if 	pc.count_item("30157")>=5000 then	
				say_title(gameforge.subquest_40._10_targetVid)
				say(gameforge.subquest_40._120_say)
				return
			end
			say_title(gameforge.subquest_40._10_targetVid)
			say(gameforge.subquest_40._130_say)
			say_item_vnum(30157)
		end

		when 20355.chat.gameforge.subquest_40._140_npcChat with pc.count_item(30157) <5000 begin
			say_title(gameforge.main_quest_lv10._30_sayTitle)
			say(gameforge.subquest_40._150_say)
			local s= select(gameforge.subquest_40._160_select, gameforge.subquest_24._200_select)
			if 2==s then
				say(gameforge.subquest_40._170_say)
				local a=  select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
				if 2==a then
					say_title(gameforge.subquest_16._340_sayTitle)
					say(gameforge.subquest_40._180_say)
					return
				end
				say(gameforge.subquest_40._190_say)
				set_state(__GIVEUP__)
				return
			end
			say_title(gameforge.main_quest_lv10._30_sayTitle)
			say(gameforge.subquest_40._200_say)
		end
		
		when 906.kill   begin
			local s = number(1, 100)
			if s <= 10 and pc.count_item("30157")<5000 then
				pc.give_item2(30157, 10)
			end

			
		end

		when __TARGET__.target.click  or 
			20355.chat.gameforge.subquest_40._210_npcChat with pc.count_item(30157)>=5000 begin
			target.delete("__TARGET__")

			say_title(gameforge.main_quest_lv10._30_sayTitle)
			say(gameforge.subquest_40._220_say)
			wait()
			say_title(gameforge.main_quest_lv10._30_sayTitle)
			say(gameforge.subquest_40._230_say)

			pc.remove_item(30157 , 5000)			
		
			say_reward(gameforge.subquest_40._240_sayReward)
			pc.give_item2(71044,3)
			pc.give_item2(71045,3)
			
			say_reward(gameforge.subquest_40._250_sayReward)
			pc.give_exp2(4500000)

			say_reward(gameforge.subquest_40._260_sayReward)
			pc.change_money(50000)
						
			clear_letter()	
			set_state(COMPLETE)
		end
	end
	state COMPLETE begin
		when enter begin
			q.done()
		end
	end
	state __GIVEUP__ begin
	end
end
