quest find_squareguard begin
	state start begin
	end

	state run begin
		when login with pc.level<=5 begin
			set_state(find)
		end
	end
	state find begin
		when letter begin
			local find_npc_vnum = 0
			if pc.get_empire()==1 then
				find_npc_vnum = 11000
			elseif pc.get_empire()==2 then
				find_npc_vnum = 11002
			elseif pc.get_empire()==3 then
				find_npc_vnum = 11004
			end

			local v=find_npc_by_vnum(find_npc_vnum)
			if 0==v then
			else
				target.vid("__TARGET__1", v, gameforge.find_squareguard._10_targetVid)
			end
		end
		when letter begin
			send_letter(gameforge.find_squareguard._10_targetVid)
		end
		when button or info begin
			say_title(gameforge.buy_fishrod._210_sayTitle)
			say(gameforge.find_squareguard._20_sayReward)
		end
		when __TARGET__1.target.click begin
			target.delete("__TARGET__1")
			say_title(gameforge.find_squareguard._30_sayTitle)
			say(gameforge.find_squareguard._40_say)
			local b= select(gameforge.find_squareguard._50_select)
			if 1==b then
				say_title(gameforge.buy_fishrod._210_sayTitle)
				say_reward(gameforge.find_squareguard._60_sayReward)
				pc.changemoney(200)
				set_state(buy)
			elseif 2==b then
			else
				say(string.format(gameforge.find_squareguard._70_say, b))
			end
		end
	end
	state buy begin
		when letter begin
			send_letter(gameforge.find_squareguard._80_sendLetter)
	
			local v=find_npc_by_vnum(9003)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.find_squareguard._131_targetVid )
			end

		end
		when button or info begin
			say_title(gameforge.buy_fishrod._210_sayTitle)
			say(gameforge.find_squareguard._90_sayReward)
		end
		when 11000.chat.gameforge.find_squareguard._100_npcChat or 11002.chat.gameforge.find_squareguard._100_npcChat or 11004.chat.gameforge.find_squareguard._100_npcChat begin
			say_title(gameforge.find_squareguard._110_sayTitle)
			say(gameforge.find_squareguard._120_say)
		end
		when __TARGET__.target.click  begin 
			target.delete("__TARGET__")
			say_title(gameforge.find_squareguard._130_sayTitle)
      		say(gameforge.find_squareguard._140_say)
	  		wait()
	  		say_title(gameforge.find_squareguard._130_sayTitle)
	  		say(gameforge.find_squareguard._150_say)
	  		wait()
	  		say_title(gameforge.buy_fishrod._210_sayTitle)
	  		say_reward(gameforge.find_squareguard._160_sayReward)
	  		----------"12345678901234567890123456789012345678901234567890"|
	  		say_reward(gameforge.find_squareguard._170_sayReward)
			pc.give_item2(27001,5)
			setstate(deliver)
		end
	end
	state deliver begin
		when letter begin
			local find_npc_vnum = 0
			if pc.get_empire()==1 then
				find_npc_vnum = 11000
			elseif pc.get_empire()==2 then
				find_npc_vnum = 11002
			elseif pc.get_empire()==3 then
				find_npc_vnum = 11004
			end

			local v=find_npc_by_vnum(find_npc_vnum)
			if 0==v then
			else
				target.vid("__TARGET__1", v, gameforge.find_squareguard._10_targetVid)
			end
		end
		when letter begin
			send_letter(gameforge.find_squareguard._180_sendLetter)
		end
		when button or info begin
			say_title(gameforge.buy_fishrod._210_sayTitle)
			say(gameforge.find_squareguard._190_sayReward)
		end
		
		when __TARGET__1.target.click with pc.countitem("27001")<1 begin
			target.delete("__TARGET__1")
			say_title(gameforge.find_squareguard._30_sayTitle)
			say(gameforge.find_squareguard._200_say)
			-- genereate a error, we have another quest for the skills. Here are the orignal korean linked
			-- set_quest_state("find_skillteacher", "find")
			clear_letter()
			set_state(__COMPLETE__)
		end
		when __TARGET__1.target.click with pc.countitem("27001")>=1 begin
			target.delete("__TARGET__1")
			
			say_title(gameforge.find_squareguard._30_sayTitle)
			say(gameforge.find_squareguard._210_say)
			wait()
			say_title(gameforge.find_squareguard._30_sayTitle)
			say(gameforge.find_squareguard._220_say)
			if pc.countitem("27001")>=1 then
				pc.removeitem("27001", 1)
				local r=number(1, 3)
				if r==1 then
					pc.give_item2("14000", 1)
				elseif r==2 then
					pc.give_item2("16000", 1)
				elseif r==3 then
					pc.give_item2("17000", 1)
				end
			end
			clear_letter()
			set_state(__COMPLETE__)
			-- genereate a error, we have another quest for the skills. Here are the orignal korean linked
			-- set_quest_state("find_skillteacher", "find")
		end
	end
	state __COMPLETE__ begin
	end
end
