quest horse_upgrade2 begin
	state start begin
		when 20349.chat.gameforge.horse_upgrade2._10_npcChat with horse.get_grade()==2 and horse.get_level()==20 begin
			if horse.is_dead() then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._20_say)
			elseif pc.level<=49 then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._30_say)
			elseif horse.get_level()<=19 then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._40_say)
			elseif pc.countitem("50050")<1 then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._50_say)
				setstate(need_item50050)
			elseif pc.countitem("50052")<1 then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._60_say)
			elseif horse.get_level()==20 and not horse.is_dead() and pc.countitem("50050")>=1 and pc.level>=50 then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._70_say)
				local b= select(gameforge.find_brother_article._90_select, gameforge.find_brother_article._100_select)
				if 1==b then
					if pc.countitem("50050")>=1 then
						pc.removeitem("50050", 1)
						setstate(test)
					end
				elseif 2==b then
					say(gameforge.horse_upgrade2._80_say)
				else
					say(string.format(gameforge.buy_fishrod._80_say, b))
				end
			else
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._90_say)
			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_upgrade2._100_makequestbutton)
			q.set_title(gameforge.horse_upgrade2._100_makequestbutton)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_upgrade2._100_makequestbutton)
						say_reward(gameforge.horse_upgrade2._110_sayReward)
						setstate(start)
			q.done()
		end
		when info begin
			say_title(gameforge.horse_upgrade2._100_makequestbutton)
						say_reward(gameforge.horse_upgrade2._110_sayReward)
						setstate(start)
			q.done()
		end
		when 20349.chat.gameforge.horse_upgrade2._10_npcChat with horse.get_grade()==2 and horse.get_level()==20 begin
			if horse.is_dead() then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._20_say)
			elseif pc.level<=49 then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._30_say)
			elseif horse.get_level()<=19 then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._40_say)
			elseif pc.countitem("50050")<1 then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._50_say)
			elseif pc.countitem("50052")<1 then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._60_say)
			elseif horse.get_level()==20 and not horse.is_dead() and pc.countitem("50050")>=1 and pc.level>=50 then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._70_say)
				local b= select(gameforge.find_brother_article._90_select, gameforge.find_brother_article._100_select)
				if 1==b then
					if pc.countitem("50050")>=1 then
						pc.removeitem("50050", 1)
						setstate(test)
					end
				elseif 2==b then
					say(gameforge.horse_upgrade2._80_say)
				else
					say(string.format(gameforge.buy_fishrod._80_say, b))
				end
			else
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._90_say)
			end
		end
	end
	state test begin
		when letter begin
			q.set_counter(gameforge.horse_upgrade2._test_1002_count, 300-pc.getqf("kill_count"))
		end
		when 1002.party_kill begin
			pc.setqf("kill_count", pc.getqf("kill_count")+1)
			q.set_counter(gameforge.horse_upgrade2._test_1002_count, 300-pc.getqf("kill_count"))
			if get_time()>=pc.getqf("limit_time") then
				setstate(failure)
				q.done()
			end
		end
		when letter begin
			q.set_clock(gameforge.horse_upgrade2.rest_time, pc.getqf("limit_time")-get_time())
		end
		when enter begin
			pc.setqf("limit_time", get_time()+30*60)
			pc.setqf("kill_count", 0)
		end
		when leave begin
			q.done()
		end
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_upgrade2._120_makequestbutton)
			q.set_title(gameforge.horse_upgrade2._120_makequestbutton)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_upgrade2._120_makequestbutton)
						say_reward(gameforge.horse_upgrade2._130_sayReward)
						say_reward(gameforge.horse_upgrade2._140_sayReward)
					end
		when info begin
			say_title(gameforge.horse_upgrade2._120_makequestbutton)
						say_reward(gameforge.horse_upgrade2._130_sayReward)
						say_reward(gameforge.horse_upgrade2._140_sayReward)
					end
		when 1002.party_kill with pc.getqf("kill_count") >= 300 and pc.getqf("limit_time")>=get_time() begin
			setstate(report)
		end
		when 20349.chat.gameforge.horse_upgrade2._150_npcChat begin
			say_title(gameforge.horse_exchange_ticket._20_sayTitle)
			say(gameforge.horse_upgrade2._160_say)
			local b= select(gameforge.locale.levelup.prev_quest_go, gameforge.locale.cancel)
			if 1==b then
			elseif 2==b then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._170_say)
				local b= select(gameforge.horse_upgrade2._180_select, gameforge.horse_upgrade2._190_select)
				if 1==b then
					say_title(gameforge.horse_exchange_ticket._20_sayTitle)
					say(gameforge.horse_upgrade2._200_say)
					setstate(start)
					q.done()
				elseif 2==b then
					say_title(gameforge.horse_exchange_ticket._20_sayTitle)
					say(gameforge.horse_upgrade2._210_say)
				else
					say(string.format(gameforge.horse_upgrade2._220_say, b))
				end
			else
				say(string.format(gameforge.horse_upgrade2._220_say, b))
			end
		end
	end
	state report begin
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_upgrade2._230_makequestbutton)
			q.set_title(gameforge.horse_upgrade2._230_makequestbutton)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_upgrade2._230_makequestbutton)
						say_reward(gameforge.horse_upgrade2._240_sayReward)
					end
		when info begin
			say_title(gameforge.horse_upgrade2._230_makequestbutton)
						say_reward(gameforge.horse_upgrade2._240_sayReward)
					end
		when 20349.chat.gameforge.horse_upgrade2._250_npcChat with horse.get_grade()!=2 begin
			setstate(start)
			q.done()
		end
		when 20349.chat.gameforge.horse_upgrade2._260_npcChat with horse.get_grade()==2 begin
			say_title(gameforge.horse_exchange_ticket._20_sayTitle)
			say(gameforge.horse_upgrade2._270_say)
			if is_test_server() then
				pc.setqf("make_time", get_time()+10)
			else
				pc.setqf("make_time", get_time()+number(8, 16)*60*60)
			end
			setstate(wait)
		end
	end
	state wait begin
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_upgrade2._280_makequestbutton)
			q.set_title(gameforge.horse_upgrade2._280_makequestbutton)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_upgrade2._280_makequestbutton)
						say_reward(gameforge.horse_upgrade2._290_sayReward)
					end
		when info begin
			say_title(gameforge.horse_upgrade2._280_makequestbutton)
						say_reward(gameforge.horse_upgrade2._290_sayReward)
					end
		when login with get_time()>=pc.getqf("make_time") begin
			setstate(buy)
		end
		when 20349.chat.gameforge.horse_upgrade2._300_npcChat with horse.get_grade()!=2 begin
			setstate(start)
			q.done()
		end
		when 20349.chat.gameforge.horse_upgrade2._310_npcChat with horse.get_grade()==2 begin
			say_title(gameforge.horse_exchange_ticket._20_sayTitle)
			say(gameforge.horse_upgrade2._320_say)
		end
	end
	state buy begin
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_upgrade2._330_makequestbutton)
			q.set_title(gameforge.horse_upgrade2._330_makequestbutton)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_upgrade2._330_makequestbutton)
						say_reward(gameforge.horse_upgrade2._340_sayReward)
					end
		when info begin
			say_title(gameforge.horse_upgrade2._330_makequestbutton)
						say_reward(gameforge.horse_upgrade2._340_sayReward)
					end
		when 20349.chat.gameforge.horse_upgrade2._300_npcChat with horse.get_grade()!=2 begin
			setstate(start)
			q.done()
		end
		when 20349.chat.gameforge.horse_upgrade2._300_npcChat with horse.get_grade()==2 and horse.get_level()!=20 begin
			setstate(start)
			q.done()
		end
		when 20349.chat.gameforge.horse_upgrade2._350_npcChat with horse.get_grade()==2 and horse.get_level()==20 begin
			say_title(gameforge.horse_exchange_ticket._20_sayTitle)
			say(gameforge.horse_upgrade2._360_say)
			local b= select(gameforge.horse_upgrade2._370_select, gameforge.horse_upgrade2._380_select, gameforge.horse_upgrade2._385_select)
			if 1==b then
				if pc.money>=1000000 then
					if pc.countitem("50052")>=1 then
						char_log(0, "HORSE_UPGRADE2", "BEGIN")
						pc.changemoney(-1000000)
						char_log(0, "HORSE_UPGRADE2", "DEC money 1000000")
						pc.removeitem("50052", 1)
						char_log(0, "HORSE_UPGRADE2", "DEC 50052 1")
						horse.unride()
						horse.advance()
						horse.ride()
						char_log(0, "HORSE_UPGRADE2", "INC horse_advance 1")
						pc.give_item2("50053", 1)
						char_log(0, "HORSE_UPGRADE2", "INC 50053 1")
						pc.give_item2("50060", 1)
						char_log(0, "HORSE_UPGRADE2", "INC 50060 1")
						char_log(0, "HORSE_UPGRADE2", "END")
						say_title(gameforge.horse_exchange_ticket._20_sayTitle)
						say(gameforge.horse_upgrade2._390_say)
						setstate(start)
						q.done()
					else
						say_title(gameforge.horse_exchange_ticket._20_sayTitle)
						say(gameforge.horse_upgrade2._400_say)
					end
				else
					say_title(gameforge.horse_exchange_ticket._20_sayTitle)
					say(gameforge.horse_upgrade2._410_say)
				end
			elseif 2==b then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._420_say)
			elseif 3==b then
				say_title(gameforge.horse_exchange_ticket._20_sayTitle)
				say(gameforge.horse_upgrade2._430_say)
				local b= select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
				if 1==b then
					setstate(start)
				elseif 2==b then
				else
					say(string.format(gameforge.find_squareguard._70_say, b))
				end
			else
				say(string.format(gameforge.find_squareguard._70_say, b))
			end
		end
	end
	state failure begin
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.horse_upgrade2._440_makequestbutton)
			q.set_title(gameforge.horse_upgrade2._440_makequestbutton)
			q.start()
		end
		when button begin
			say_title(gameforge.horse_upgrade2._440_makequestbutton)
						say_reward(gameforge.horse_upgrade2._450_sayReward)
						say_reward(gameforge.horse_upgrade2._460_sayReward)
						setstate(start)
			q.done()
		end
		when info begin
			say_title(gameforge.horse_upgrade2._440_makequestbutton)
						say_reward(gameforge.horse_upgrade2._450_sayReward)
						say_reward(gameforge.horse_upgrade2._460_sayReward)
						setstate(start)
			q.done()
		end
	end
	state __COMPLETE__ begin
		when enter begin
			q.done()
		end
	end
end
