define checker 20001
quest dragon_soul_daily_gift_mgr begin
	state start begin
		function is_event_on()
			-- 지금 시각이 dragon_soul_daily_gift_mgr.quest에서 셋팅한 시간 대역인지 확인.
			local s_time = game.get_event_flag("ds_dg_st")
			local e_time = game.get_event_flag("ds_dg_et")
			local now = os.time()
			return now > s_time and now < e_time
		end
		function date_getter()
			say(gameforge.dragon_soul_gift_mgr._040_say)
			say("yy-mm-dd hh:mm")
			local date = input()
			local _, _, y, m, d, hour, min = string.find(date, "(%d+)-(%d+)-(%d+) (%d+):(%d+)")
			return y, m, d, hour, min
		end
		function print_quest_info()
			local s_time = game.get_event_flag("ds_dg_st")
			local e_time = game.get_event_flag("ds_dg_et")
			local gift_vnum = game.get_event_flag("ds_dg_item")
			
			say(os.date("start time[ENTER]	year:%Y, month:%m, day:%d hour:%H minite:%M", s_time))
			say(os.date("  end time[ENTER]	year:%Y, month:%m, day:%d hour:%H minite:%M", e_time))

			say(string.format("gift item[ENTER]	vnum : %d", gift_vnum))
			say_item_vnum(gift_vnum)
		end
		when checker.chat.gameforge.dragon_soul_gift_mgr._010_npcChat with pc.is_gm() begin
			local sel = 0
			if dragon_soul_daily_gift_mgr.is_event_on() then
				say(locale.event_on_going)
				local sel = select(locale.event_modify, locale.event_info_print, locale.event_cancel, locale.close)
				if 2 == sel then
					dragon_soul_daily_gift_mgr.print_quest_info()
					return
				elseif 3 == sel then
					game.set_event_flag("ds_dg_et", 0)
					return
				elseif 4 == sel then
					return
				end
				
			end
			-- Get start time and end time.
			local s_y, s_m, s_d, s_hour, s_min
			repeat
				say(gameforge.dragon_soul_gift_mgr._020_say)
				s_y, s_m, s_d, s_hour, s_min = dragon_soul_daily_gift_mgr.date_getter()
				s_y = s_y + 2000
				say(string.format("year:%d month:%d day:%d hour:%d min:%d", s_y, s_m, s_d, s_hour, s_min))
			until 1 == select(gameforge.locale.yes, gameforge.locale.no)
			local e_y, e_m, e_d, e_hour, e_min
			repeat
				say(gameforge.dragon_soul_gift_mgr._030_say)
				e_y, e_m, e_d, e_hour, e_min = dragon_soul_daily_gift_mgr.date_getter()
				e_y = e_y + 2000
				say(string.format("year:%d month:%d day:%d hour:%d min:%d", e_y, e_m, e_d, e_hour, e_min))
			until 1 == select(gameforge.locale.yes, gameforge.locale.no)

			local s_time = os.time{year=s_y, month=s_m, day=s_d, hour=s_hour, min=s_min}
			local e_time = os.time{year=e_y, month=e_m, day=e_d, hour=e_hour, min=e_min}
		
			-- Get gift item vnum
			local gift_vnum = input_number("gift vnum")

			-- Print settings and confirm.
			say(os.date("start time[ENTER]	year:%Y, month:%m, day:%d hour:%H minite:%M", s_time))
			say(os.date("  end time[ENTER]	year:%Y, month:%m, day:%d hour:%H minite:%M", e_time))

			say(string.format("gift item[ENTER]	vnum : %d", gift_vnum))
			say_item_vnum(gift_vnum)

			say(gameforge.dragon_soul_gift_mgr._050_say)
			if 2 == select(gameforge.locale.yes, gameforge.locale.no) then
				return
			end

			-- 이벤트 수정인 경우는 event_id를 바꾸면 안됨.
			if 0 == sel then
				local event_id = game.get_event_flag("ds_dg_id")
				game.set_event_flag("ds_dg_id", event_id + 1)
			end
			game.set_event_flag("ds_dg_st", s_time)
			game.set_event_flag("ds_dg_et", e_time)
			game.set_event_flag("ds_dg_item", gift_vnum)

			say (gameforge.dragon_soul_gift_mgr._060_say)
		end
	end
end
