quest horse_levelup begin
	state training1 begin
		when letter begin
			q.set_counter(gameforge.horse_levelup._training_1_count, 5-pc.getqf("kill_count"))
		end
		when 492.kill begin
			pc.setqf("kill_count", pc.getqf("kill_count")+1)
			q.set_counter(gameforge.horse_levelup._training_1_count, 5-pc.getqf("kill_count"))
		end
		when enter begin
			pc.setqf("kill_count", 0)
		end
		when leave begin
			q.done()
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._10_makequestbutton)
			q.set_title(gameforge.horse_levelup._10_makequestbutton)
			q.start()
			if	not pc.is_mount() then
				setstate(failure)
			end

		end
		when button begin
			say_title(gameforge.horse_levelup._10_makequestbutton)
			say(gameforge.horse_levelup._20_say)
			if	not pc.is_mount() then
				setstate(failure)
			end

		end
		when info begin
			say_title(gameforge.horse_levelup._10_makequestbutton)
			say(gameforge.horse_levelup._20_say)
			if	not pc.is_mount() then
				setstate(failure)
			end

		end
		when 492.kill with pc.getqf("kill_count") >= 5 begin
			setstate(report)
		end
		when unmount begin
			setstate(failure)
		end
	end
	state training2 begin
		when letter begin
			q.set_counter(gameforge.horse_levelup._training_2_count, 5-pc.getqf("kill_count"))
		end
		when 494.kill begin
			pc.setqf("kill_count", pc.getqf("kill_count")+1)
			q.set_counter(gameforge.horse_levelup._training_2_count, 5-pc.getqf("kill_count"))
		end
		when enter begin
			pc.setqf("kill_count", 0)
		end
		when leave begin
			q.done()
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._30_makequestbutton)
			q.set_title(gameforge.horse_levelup._30_makequestbutton)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_levelup._30_makequestbutton)
			say(gameforge.horse_levelup._40_say)
		end
		when info begin
			say_title(gameforge.horse_levelup._30_makequestbutton)
			say(gameforge.horse_levelup._50_say)
		end
		when 494.kill with pc.getqf("kill_count") >= 5 begin
			setstate(report)
		end
		when unmount begin
			setstate(failure)
		end
	end
	state training3 begin
		when letter begin
			q.set_counter(gameforge.horse_levelup._training_3_count, 10-pc.getqf("kill_count"))
		end
		when 635.kill begin
			pc.setqf("kill_count", pc.getqf("kill_count")+1)
			q.set_counter(gameforge.horse_levelup._training_3_count, 10-pc.getqf("kill_count"))
		end
		when enter begin
			pc.setqf("kill_count", 0)
		end
		when leave begin
			q.done()
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._60_makequestbutton)
			q.set_title(gameforge.horse_levelup._60_makequestbutton)
			q.start()
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when button begin
			say_title(gameforge.horse_levelup._60_makequestbutton)
			say(gameforge.horse_levelup._70_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when info begin
			say(gameforge.horse_levelup._80_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when 635.kill with pc.getqf("kill_count") >= 10 begin
			setstate(report)
		end
		when unmount begin
			setstate(failure)
		end
	end
	state training4 begin
		when letter begin
			q.set_counter(gameforge.horse_levelup._training_4_count, 10-pc.getqf("kill_count"))
		end
		when 636.kill begin
			pc.setqf("kill_count", pc.getqf("kill_count")+1)
			q.set_counter(gameforge.horse_levelup._training_4_count, 10-pc.getqf("kill_count"))
		end
		when enter begin
			pc.setqf("kill_count", 0)
		end
		when leave begin
			q.done()
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._90_makequestbutton)
			q.set_title(gameforge.horse_levelup._90_makequestbutton)
			q.start()
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when button begin
			say_title(gameforge.horse_levelup._90_makequestbutton)
			say(gameforge.horse_levelup._100_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when info begin
			say_title(gameforge.horse_levelup._90_makequestbutton)
			say(gameforge.horse_levelup._100_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when 636.kill with pc.getqf("kill_count") >= 10 begin
			setstate(report)
		end
		when unmount begin
			setstate(failure)
		end
	end
	state training5 begin
		when letter begin
			q.set_counter(gameforge.horse_levelup._training_5_count, 10-pc.getqf("kill_count"))
		end
		when 706.kill begin
			pc.setqf("kill_count", pc.getqf("kill_count")+1)
			q.set_counter(gameforge.horse_levelup._training_5_count, 10-pc.getqf("kill_count"))
		end
		when enter begin
			pc.setqf("kill_count", 0)
		end
		when leave begin
			q.done()
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._110_makequestbutton)
			q.set_title(gameforge.horse_levelup._110_makequestbutton)
			q.start()
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when button begin
			say_title(gameforge.horse_levelup._110_makequestbutton)
			say(gameforge.horse_levelup._120_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when info begin
			say_title(gameforge.horse_levelup._110_makequestbutton)
			say(gameforge.horse_levelup._120_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when 706.kill with pc.getqf("kill_count") >= 10 begin
			setstate(report)
		end
		when unmount begin
			setstate(failure)
		end
	end
	state training6 begin
		when letter begin
			q.set_counter(gameforge.horse_levelup._training_6_count, 10-pc.getqf("kill_count"))
		end
		when 2034.kill begin
			pc.setqf("kill_count", pc.getqf("kill_count")+1)
			q.set_counter(gameforge.horse_levelup._training_6_count, 10-pc.getqf("kill_count"))
		end
		when enter begin
			pc.setqf("kill_count", 0)
		end
		when leave begin
			q.done()
		end
		when letter begin

			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._130_makequestbutton)
			q.set_title(gameforge.horse_levelup._130_makequestbutton)
			q.start()
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when button begin
			say_title(gameforge.horse_levelup._130_makequestbutton)
			say(gameforge.horse_levelup._140_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when info begin
			say_title(gameforge.horse_levelup._130_makequestbutton)
			say(gameforge.horse_levelup._140_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when 2034.kill with pc.getqf("kill_count") >= 10 begin
			setstate(report)
		end
		when unmount begin
			setstate(failure)
		end
	end
	state training7 begin
		when letter begin
			q.set_counter(gameforge.horse_levelup._training_7_count, 20-pc.getqf("kill_count"))
		end
		when 2108.kill begin
			pc.setqf("kill_count", pc.getqf("kill_count")+1)
			q.set_counter(gameforge.horse_levelup._training_7_count, 20-pc.getqf("kill_count"))
		end
		when enter begin
			pc.setqf("kill_count", 0)
		end
		when leave begin
			q.done()
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._150_makequestbutton)
			q.set_title(gameforge.horse_levelup._150_makequestbutton)
			q.start()
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when button begin
			say_title(gameforge.horse_levelup._150_makequestbutton)
			say(gameforge.horse_levelup._160_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when info begin
			say_title(gameforge.horse_levelup._150_makequestbutton)
			say(gameforge.horse_levelup._160_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when 2108.kill with pc.getqf("kill_count") >= 20 begin
			setstate(report)
		end
		when unmount begin
			setstate(failure)
		end
	end
	state training8 begin
		when letter begin
			q.set_counter(gameforge.horse_levelup._training_8_count, 10-pc.getqf("kill_count"))
		end
		when 1107.kill begin
			pc.setqf("kill_count", pc.getqf("kill_count")+1)
			q.set_counter(gameforge.horse_levelup._training_8_count, 10-pc.getqf("kill_count"))
		end
		when enter begin
			pc.setqf("kill_count", 0)
		end
		when leave begin
			q.done()
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._170_makequestbutton)
			q.set_title(gameforge.horse_levelup._170_makequestbutton)
			q.start()
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when button begin
			say_title(gameforge.horse_levelup._180_sayTitle)
			say(gameforge.horse_levelup._190_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when info begin
			say_title(gameforge.horse_levelup._180_sayTitle)
			say(gameforge.horse_levelup._200_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when 1107.kill with pc.getqf("kill_count") >= 10 begin
			setstate(report)
		end
		when unmount begin
			setstate(failure)
		end
	end
	state training9 begin
		when letter begin
			q.set_counter(gameforge.horse_levelup._training_9_count, 20-pc.getqf("kill_count"))
		end
		when 2203.kill begin
			pc.setqf("kill_count", pc.getqf("kill_count")+1)
			q.set_counter(gameforge.horse_levelup._training_9_count, 20-pc.getqf("kill_count"))
		end
		when enter begin
			pc.setqf("kill_count", 0)
		end
		when leave begin
			q.done()
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._210_makequestbutton)
			q.set_title(gameforge.horse_levelup._210_makequestbutton)
			q.start()
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when button begin
			say_title(gameforge.horse_levelup._210_makequestbutton)
			say(gameforge.horse_levelup._220_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when info begin
			say_title(gameforge.horse_levelup._210_makequestbutton)
			say(gameforge.horse_levelup._220_say)
			if	not pc.is_mount() then
				setstate(failure)
			end
		end
		when 2203.kill with pc.getqf("kill_count") >= 20 begin
			setstate(report)
		end
		when unmount begin
			setstate(failure)
		end
	end
	state start begin
		when 20349.chat.gameforge.horse_levelup._230_npcChat with horse.get_grade()==2 begin
			if horse.get_level()==20 then
				say_title(gameforge.horse_levelup._240_sayTitle)
				say(gameforge.horse_levelup._250_say)
			elseif pc.countitem("50050")<1 then
				say_title(gameforge.horse_levelup._240_sayTitle)
				say(gameforge.horse_levelup._260_say)
				setstate(need_item50050)
			elseif get_time()<pc.getqf("next_time") then
				say_title(gameforge.horse_levelup._240_sayTitle)
				say(gameforge.horse_levelup._270_say)
			elseif horse.get_stamina_pct()<=10 then
				say_title(gameforge.horse_levelup._240_sayTitle)
				say(gameforge.horse_levelup._280_say)
			elseif horse.get_health_pct()<=10 then
				say_title(gameforge.horse_levelup._240_sayTitle)
				say(gameforge.horse_levelup._290_say)
			elseif horse.is_riding()==0 then
				say_title(gameforge.horse_levelup._240_sayTitle)
				say(gameforge.horse_levelup._300_say)
			elseif (horse.get_level()>=11 and horse.get_level()<=19) then
				say_title(gameforge.horse_levelup._240_sayTitle)
				say(gameforge.horse_levelup._310_say)
				if is_test_server() then
					pc.setqf("next_time", get_time()+10)
				else
					pc.setqf("next_time", get_time()+number(16, 32)*60*60)
				end
				if horse.get_level()==11 then
					setstate(training1)
				elseif horse.get_level()==12 then
					setstate(training2)
				elseif horse.get_level()==13 then
					setstate(training3)
				elseif horse.get_level()==14 then
					setstate(training4)
				elseif horse.get_level()==15 then
					setstate(training5)
				elseif horse.get_level()==16 then
					setstate(training6)
				elseif horse.get_level()==17 then
					setstate(training7)
				elseif horse.get_level()==18 then
					setstate(training8)
				elseif horse.get_level()==19 then
					setstate(training9)
				end
			end
		end
	end
	state need_item50050 begin
		when login or levelup or enter with pc.countitem("50050") >= 1 begin
			set_state(start)
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._320_makequestbutton)
			q.set_title(gameforge.horse_levelup._320_makequestbutton)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_levelup._320_makequestbutton)
			say(gameforge.horse_levelup._330_say)
			setstate(start)
			q.done()
		end
		when info begin
			say_title(gameforge.horse_levelup._320_makequestbutton)
			say(gameforge.horse_levelup._330_say)
			setstate(start)
			q.done()
		end
	end
	state failure begin
		when login or levelup or enter or letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._340_makequestbutton)
			q.set_title(gameforge.horse_levelup._340_makequestbutton)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_levelup._340_makequestbutton)
			say(gameforge.horse_levelup._350_say)
			setstate(start)
			q.done()
		end
		when info begin
			say_title(gameforge.horse_levelup._340_makequestbutton)
			say(gameforge.horse_levelup._350_say)
			setstate(start)
			q.done()
		end
	end
	state report begin
		when letter begin
			local v=find_npc_by_vnum(20349)
			if 0==v then
			else
				target.vid("__TARGET__", v, "")
			end
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._360_makequestbutton)
			q.set_title(gameforge.horse_levelup._360_makequestbutton)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_levelup._360_makequestbutton)
			say(gameforge.horse_levelup._370_say)
		end
		when info begin
			say_title(gameforge.horse_levelup._360_makequestbutton)
			say(gameforge.horse_levelup._370_say)
		end
		when __TARGET__.target.click begin
			target.delete("__TARGET__")
			say_title(gameforge.horse_levelup._240_sayTitle)
			say(gameforge.horse_levelup._380_say)
			setstate(reward)
			q.done()
		end
	end
	state reward begin
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_levelup._390_makequestbutton)
			q.set_title(gameforge.horse_levelup._400_qSetTitle)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_levelup._400_qSetTitle)
			if horse.get_level()<=10 then
				say(gameforge.horse_levelup._410_say)
			elseif horse.get_level()>=20 then
				say(gameforge.horse_levelup._420_say)
			elseif (horse.get_level()>=11 and horse.get_level()<=19) then
				local s=number(1, 2)
				if 1>=s then -- 50.00% (1/2)
					say(gameforge.horse_levelup._430_say)
					pc.setqf("next_time", 0)
				elseif 2>=s then -- 50.00% (1/2)
					say(gameforge.horse_levelup._440_say)
					if pc.countitem("50050")>=1 then
						char_log(0, "HORSE_ADVANCE", "BEGIN")
						pc.removeitem("50050", 1)
						char_log(0, "HORSE_ADVANCE", "DEC 50050 1")
						horse.unride()
						horse.advance()
						horse.ride()
						char_log(0, "HORSE_ADVANCE", "INC horse_advance 1")
						char_log(0, "HORSE_ADVANCE", "END")
						say(string.format(gameforge.horse_levelup._450_say, (horse.get_level())))
						if horse.get_level()==20 then
							say(gameforge.horse_levelup._460_say)
							pc.setqf("next_time", 0)
						else
							say(gameforge.horse_levelup._470_say)
						end
					else
						say(gameforge.horse_levelup._480_say)
					end
				end
			end
			setstate(start)
			q.done()
		end
	end
	state __COMPLETE__ begin
		when enter begin
			q.done()
		end
	end
end
