
quest main_quest_lv40 begin
	state start begin
	end
	state run begin
		when login or levelup or enter with pc.get_level() >= 40 begin
			set_state ( information )
		end
	end
	state information begin
		when letter begin
			send_letter(gameforge.main_quest_lv32._110_npcChat)
		end
		when button or info begin
		        ----"12345678901234567890123456789012345678901234567890"|
			say_title(gameforge.main_quest_lv40._10_sayTitle)
			say(gameforge.main_quest_lv40._20_say)
		end

		when 731.kill begin
			local s = number(1, 100)
			if s <= 5 and pc.count_item("30150")==0 then
				pc.give_item2(30150, 1)
				set_state (gototeacher)
			end
		end
	end

	state gototeacher begin
		when letter begin

			send_letter(gameforge.main_quest_lv32._670_sendLetter)
			local v=find_npc_by_vnum(20011)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.main_quest_lv32._310_targetVid)
			end
		end
		when button or info begin
			
			say_title(gameforge.main_quest_lv40._30_sayTitle)
			say(gameforge.main_quest_lv40._40_say)
		end
		when __TARGET__.target.click or	20011.chat.gameforge.main_quest_lv32._670_sendLetter begin
			target.delete("__TARGET__")

			say_title(gameforge.main_quest_lv30._40_sayTitle)
   			say(gameforge.main_quest_lv40._50_say)
			wait()
			say_title(gameforge.main_quest_lv40._60_sayTitle)
			   			say_reward(gameforge.main_quest_lv40._70_sayReward)
						wait()
			say_title(gameforge.main_quest_lv30._40_sayTitle)
			say(gameforge.main_quest_lv40._80_say)
			wait()
			say_title(gameforge.main_quest_lv30._40_sayTitle)
			say(gameforge.main_quest_lv40._90_say)
			say_reward(gameforge.main_quest_lv40._100_sayReward)
			pc.give_exp2(2000000)

			say_reward(gameforge.main_quest_lv40._110_sayReward)
			pc.change_money(50000)

			say_reward(gameforge.main_quest_lv40._120_sayReward)
			pc.give_item2(71018)
			pc.remove_item(30150)
			set_state ( godoc4 )

		end
	end

	state godoc4 begin
		when letter begin

			send_letter(gameforge.main_quest_lv40._130_sendLetter)
			local v=find_npc_by_vnum(20360)
			if 0==v then
			else
				target.vid("__TARGET1__", v, gameforge.main_quest_lv40._140_targetVid)
			end

			local v=find_npc_by_vnum(20361)
			if 0==v then
			else
				target.vid("__TARGET2__", v, gameforge.main_quest_lv40._150_targetVid)
			end
		end

		when button or info begin
			
			say_title(gameforge.main_quest_lv40._160_sayTitle)
			say(gameforge.main_quest_lv40._170_say)
		end
		when __TARGET1__.target.click or	20360.chat.gameforge.main_quest_lv40._150_targetVid begin
			target.delete("__TARGET1__")
			say_pc_name()
			say(gameforge.main_quest_lv40._180_say)
			pc.setqf("click1",1)

			if pc.getqf("click2") == 1 then
				pc.setqf("click1",0)
				pc.setqf("click2",0)

				pc.give_item2(30150)
				set_state ( gototeacher2)
				return
			end


			say(gameforge.main_quest_lv40._190_say)
		end

		when __TARGET2__.target.click or	20361.chat.gameforge.main_quest_lv40._200_npcChat begin
			target.delete("__TARGET2__")
			say_pc_name()
			say(gameforge.main_quest_lv40._210_say)
			pc.setqf("click2",1);

			if pc.getqf("click1") == 1 then
				pc.setqf("click1",0)
				pc.setqf("click2",0)
				pc.give_item2(30150)
				set_state ( gototeacher2)
				return
			end
			say(gameforge.main_quest_lv40._220_say)
		end
	end

	state gototeacher2 begin
		when letter begin

			send_letter(gameforge.main_quest_lv40._230_sendLetter)
			local v=find_npc_by_vnum(20011)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.main_quest_lv32._310_targetVid)
			end
		end
		when button or info begin
			say_title(gameforge.main_quest_lv40._240_sayTitle)
			say(gameforge.main_quest_lv40._250_say)
		end
		when __TARGET__.target.click or	20011.chat.gameforge.main_quest_lv40._260_npcChat begin
			target.delete("__TARGET__")
			say_title(gameforge.main_quest_lv30._40_sayTitle)
			say(gameforge.main_quest_lv40._270_say)
			wait()
			say_title(gameforge.main_quest_lv40._280_sayTitle)
						say_reward(gameforge.main_quest_lv40._290_sayReward)
						wait()
			say_title(gameforge.main_quest_lv40._300_sayTitle)
						say_reward(gameforge.main_quest_lv40._310_sayReward)
						wait()
			say_title(gameforge.main_quest_lv30._40_sayTitle)
			say(gameforge.main_quest_lv40._320_say)
			wait()
			say_title(gameforge.main_quest_lv30._40_sayTitle)
			say(gameforge.main_quest_lv40._330_say)
			say_reward(gameforge.main_quest_lv40._340_sayReward)
			pc.give_exp2(2000000)

			say_reward(gameforge.main_quest_lv32._430_sayReward)
			pc.change_money(50000)

			say_reward(gameforge.main_quest_lv40._350_sayReward)
			pc.give_item2(71019)

			pc.remove_item(30150)

						set_state ( goboss )

		end
	end

	state goboss begin
		when letter begin

			send_letter(gameforge.main_quest_lv40._360_sendLetter)
			local v=find_npc_by_vnum(20355)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.main_quest_lv40._370_targetVid)
			end
		end
		when button or info begin
			say_title(gameforge.main_quest_lv40._380_sayTitle)
			say(gameforge.main_quest_lv40._390_say)
		end
		when __TARGET__.target.click or	20355.chat.gameforge.main_quest_lv40._400_npcChat begin
			target.delete("__TARGET__")
			say_title(gameforge.main_quest_lv10._30_sayTitle)
			say(gameforge.main_quest_lv40._410_say)
			wait()
			say_title(gameforge.main_quest_lv10._30_sayTitle)
			say(gameforge.main_quest_lv40._420_say)
			set_state (survey)
		end
	end


	state survey begin
		when letter begin

			send_letter(gameforge.main_quest_lv40._430_sendLetter)
			local v=find_npc_by_vnum(20364)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.main_quest_lv40._430_sendLetter)
			end
		end
		when button or info begin
			say_title(gameforge.main_quest_lv40._430_sendLetter)
			                        ---"12345678901234567890123456789012345678901234567890"|
			say(gameforge.main_quest_lv40._440_say)
		end
		when __TARGET__.target.click or	20364.chat.gameforge.main_quest_lv40._450_npcChat begin
			target.delete("__TARGET__")
		
			say_title(gameforge.main_quest_lv40._460_sayTitle)
			say(gameforge.main_quest_lv40._470_say)
			wait()
			say_title(gameforge.main_quest_lv40._460_sayTitle)
			say(gameforge.main_quest_lv40._480_say)
			wait()
			say_title(gameforge.main_quest_lv40._460_sayTitle)
			say(gameforge.main_quest_lv40._490_say)
			set_state (survey2)
		end
	end

	state survey2 begin
		when letter begin
			send_letter(gameforge.main_quest_lv40._500_sendLetter)
		end

		when button or info begin
			say_title(gameforge.main_quest_lv40._500_sendLetter)
			say(gameforge.main_quest_lv40._510_say)
		end
		when 591.kill begin
			local s = number(1, 100)
			if s <= 10 and pc.count_item("30150")==0 then
				pc.give_item2(30150, 1)
				set_state (_end_)
			end
		end
	end

	state _end_ begin

		when letter begin
			send_letter(gameforge.main_quest_lv40._520_sendLetter)
		end

		when button or info begin
			say_title(gameforge.main_quest_lv40._520_sendLetter)
			say(gameforge.main_quest_lv40._530_say)
			wait()
			say_title(gameforge.main_quest_lv40._540_sayTitle)
						say_reward(gameforge.main_quest_lv40._550_sayReward)
						clear_letter()
			set_state (__COMPLETE__)
			set_quest_state("main_quest_lv47", "run")
		end

	end
	state __COMPLETE__ begin
	end


end



