//////////////////////////////////////////////////////////////////////////////
//
// File: AVP_GUIMenu_PlayerObjectives.cpp
//
// (AJK - 10.10.2008) Created
//
// Copyright (C) 2008 Rebellion, All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////

#include "Core/Asura.h"

// This file's header.
#include "GUIMenu/AVP_GUIMenu_PlayerObjectives.h"

// Asura
#include "Core/Asura_HashedLocalisedText.h"
#include "Interface/Asura_CommandConsole.h"

// AVP
#include "Core/AVP_Game_Core.h"
#include "Entity/ObjectiveSystem/PlayerObjective/AVP_ClientEntity_PlayerObjective.h"
#include "Entity/PlayerInfo/AVP_ClientEntity_PlayerInfo.h"

void AVP_GUIMenu_PlayerObjectives::SetupConsoleCommands()
{
#if defined(ASURA_SUPPORT_COMMAND_CONSOLE)
	// Add the necessary console commands...
	Asura_CommandConsole::AddCmd( L"AVP.CMD.ObjectivesList"    , AVP_GUIMenu_PlayerObjectives::ConsoleCmd_ObjectivesList  , Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
	Asura_CommandConsole::AddCmd( L"AVP.CMD.ObjectivesStatus"  , AVP_GUIMenu_PlayerObjectives::ConsoleCmd_ObjectivesStatus, Asura_CommandConsole::REMOVE_AT_SHUTDOWN );
#endif	// defined(ASURA_SUPPORT_COMMAND_CONSOLE)
}

bool AVP_GUIMenu_PlayerObjectives::ConsoleCmd_ObjectivesList( u_int uElementIndex, bool bInterrogate, bool bHelp )
{
	if( bInterrogate || bHelp )
	{
		return true;
	}

	AVP_ClientEntity_PlayerInfo* pxPlayerInfo = AVP_ClientEntity_PlayerInfo::FindEntity( AVP_Game_Core::GetPlayerGuid() ); 
	
	if( pxPlayerInfo && ( uElementIndex < pxPlayerInfo->GetQuest().GetObjectivesCount() ) ) 
	{
		AVP_ClientEntity_PlayerObjective* pxObjective = AVP_ClientEntity_PlayerObjective::FindEntity(pxPlayerInfo->GetQuest().GetRankedObjective(uElementIndex));
        if ( pxObjective)
		{
			Asura_CommandConsole::Printf( L"%s", Asura_HashedLocalisedText::GetString(pxObjective->GetObjectiveText().GetTextPageHash(), pxObjective->GetObjectiveText().GetTextID()) );
		}
		return true;
	}
	return false;
}

bool AVP_GUIMenu_PlayerObjectives::ConsoleCmd_ObjectivesStatus( u_int uElementIndex, bool bInterrogate, bool bHelp )
{
	if( bInterrogate || bHelp )
	{
		return true;
	}

	AVP_ClientEntity_PlayerInfo* pxPlayerInfo = AVP_ClientEntity_PlayerInfo::FindEntity( AVP_Game_Core::GetPlayerGuid() ); 

	if( pxPlayerInfo && ( uElementIndex < pxPlayerInfo->GetQuest().GetObjectivesCount() ) ) 
	{
		AVP_ClientEntity_PlayerObjective* pxObjective = AVP_ClientEntity_PlayerObjective::FindEntity(pxPlayerInfo->GetQuest().GetRankedObjective(uElementIndex));
		if ( pxObjective)
		{
			Asura_CommandConsole::Printf( L"%s", pxObjective->IsCompleted()? Asura_HashedLocalisedText::GetString(uASURA_HASHEDTEXTPAGE_MENU, s_uAVP_OBJECTIVE_COMPLETED):Asura_HashedLocalisedText::GetString(uASURA_HASHEDTEXTPAGE_MENU, s_uAVP_OBJECTIVE_NOT_COMPLETED));
		}
		return true;
	}
	return false;
}