states = staes or {}
states.change_effect_timer = sf.core.CTimerWrapper(sf.core.g_Application.GetTimeManager().GetTimer("game_timer").AttachTimer(""))
states.use_bottom_change_state_default = true
states.change_effect_time = 300
states.sleep_after_change_state = true

function states.change_state_ex(_draw_type, _time, _sleep, _object, _state)

	if _draw_type == nil then
		_draw_type = states.use_bottom_change_state_default
	end
	if _time == nil then
		_time = states.change_effect_time
	end
	if _sleep == nil then
		_sleep = states.sleep_after_change_state
	end
	
    local current_object = nil
    if _state == nil then
       _state = _object 
       current_object = g_QuestState.GetScriptObject()
    else
       current_object = quest.FindRootObjectById(_object)
    end
    if current_object then
        group_object = __cast(current_object, qe.CSceneGroup)
        if group_object then
            if _state == nil then
                __assert(false, "Не указаны параметры для change_state")
            else
                local state_type = type(_state)
                if state_type == "string" then
                    local formed_state = _state
                    

                    group_object.SetCurrent(formed_state, _draw_type, _time, states.change_effect_timer.Get())
                    if _time > 0 and _sleep == true then
                        sleep(_time)
                    end
                end
            end
        else
            __message("Объект "..current_object.GetId().c_str().." не является группой.", "Смена состояния невозможна")
        end
    end

end

function states.change_state(_object, _state)
	states.change_state_ex(states.use_bottom_change_state_default, states.change_effect_time, states.sleep_after_change_state, _object, _state)
end

function states.state(_object, _state)
    local current_object = nil
    if _state == nil then
       _state = _object 
       current_object = g_QuestState.GetScriptObject()
    else
       current_object = quest.FindRootObjectById(_object)
    end
	if not current_object then return false end
	
	current_object = __cast(current_object, qe.CSceneGroup)
	if not current_object then return false end

    return current_object.IsCurrent(_state)
end
