#include "NetCli_RoleValueChild.h"
#include "../../mainproc/GameMain.h"
#include "../Interface/interface.h"
#include "../interface/debug/DebugMessage.h"

//-----------------------------------------------------------------------------
bool NetCli_RoleValueChild::_Init()
{
	if (This)
		return false;

	This = new NetCli_RoleValueChild;
	return NetCli_RoleValue::_Init();
}
//-----------------------------------------------------------------------------
bool NetCli_RoleValueChild::_Release()
{
	NetCli_RoleValue::_Release();
	if (This)
	{
		delete This;
		This = NULL;
	}
	return true;
}
//-----------------------------------------------------------------------------
void NetCli_RoleValueChild::R_FixAllRoleValue   ( BaseAbilityStruct& Ability )
{

}
//-----------------------------------------------------------------------------
void NetCli_RoleValueChild::R_FixRoleValue      ( RoleValueName_ENUM ValueName , float Value )
{
	//RoleDataEx*    Role    = g_pGameMain->RoleData();
	RoleDataEx*    Role    = CNetGlobal::RoleData();
	int        OrgValue = Role->GetValue( ValueName );
	Role->SetValue( ValueName , (int)Value );

	int        DValue = (int)Value - OrgValue;

	if( DValue == 0 )
		return;


	if( ValueName >= EM_RoleValue_SPMagic && ValueName < EM_RoleValue_SPMagic + _MAX_SPSkill_COUNT_ )
	{
		int SkillPos = ValueName - EM_RoleValue_SPMagic;
		//g_pDebugMessage->DebugOutput( 2, "學會技能 SPSkillID(%d) SPSkillPos(%d) LV(%d)" , Role->BaseData.Skill.SP[ SkillPos ].SkillID , SkillPos , (int)Value );        
		g_pInterface->GetUiWorld()->SendEvent( UiEvent_SkillUpdate );
//		g_pDebugMessage->DebugOutput( 2, "學會技能 SPSkillID(%d) SPSkillPos(%d) LV(%d)" , Role->BaseData.Skill.SP[ SkillPos ].SkillID , SkillPos , (int)Value );
				
	}
	else if( ValueName >= EM_RoleValue_NormalMagic && ValueName < EM_RoleValue_NormalMagic + _MAX_NormalSkill_COUNT_ )
	{
		int MagicPos = ValueName - EM_RoleValue_NormalMagic;
		g_pInterface->GetUiWorld()->SendEvent( UiEvent_SkillUpdate );
//		g_pDebugMessage->DebugOutput( 2, "學會技能 MagicID(%d) MagicPos(%d) LV(%d)" , Role->BaseData.Skill.MainJob[ MagicPos ].SkillID , MagicPos , (int)Value );        
	}
	else if( ValueName >= EM_RoleValue_SkillValue && ValueName < EM_RoleValue_SkillValue + _MAX_SKILLVALUE_TYPE )
	{
		g_pDebugMessage->DebugOutput( 2, "熟練度ID(%d)  Value=%f" , ValueName , Value );
	}
	else switch( ValueName )
	{
	 case EM_RoleValue_LV:
		 if( DValue >= 1 )
		 {  
			 g_pDebugMessage->DebugOutput( 2, "等級上升為%d" , (int)Value );
		 }
		 else
		 {
			 g_pDebugMessage->DebugOutput( 2, "等級下降為%d" , (int)Value );
		 }
		 break;
	 case EM_RoleValue_EXP:
		 if( DValue > 0  )
		 {  
			 g_pDebugMessage->DebugOutput( 2, "得到經驗值 %d" , (int)DValue );
		 }
		 else
		 {
			 g_pDebugMessage->DebugOutput( 2, "失去經驗值 %d" , (int)DValue*-1 );
		 }
		 break;
	 case EM_RoleValue_Point:
		 g_pInterface->GetUiWorld()->SendEvent( UiEvent_SkillUpdate );
		 g_pDebugMessage->DebugOutput( 2, "目前可配點數 %d" , (int)Value );
		 break;
	 case EM_RoleValue_SkillPoint:
		 g_pInterface->GetUiWorld()->SendEvent( UiEvent_SkillUpdate );
		 g_pDebugMessage->DebugOutput( 2, "目前可配 法術 點數 %d" , (int)Value );
		 break;
	}

}
//-----------------------------------------------------------------------------
void NetCli_RoleValueChild::R_SetPoint_OK       ( )
{

}
//-----------------------------------------------------------------------------
void NetCli_RoleValueChild::R_SetPoint_Failed   ( )
{

}
//-----------------------------------------------------------------------------
void NetCli_RoleValueChild::R_NotifyLvUp        ( int ItemID , int Level )
{
	g_pDebugMessage->DebugOutput( 2, "GItemID(%d)  等級上升為%d" , ItemID , Level );
	CRoleSprite* sprite = g_pGameMain->FindRoleSprite( ItemID );
	if ( sprite )
	{
		sprite->SetLevel( Level );
		CEffectSprite* pEffect = new CEffectSprite;
		if ( pEffect->LoadRuEntity("model\\fx\\level_up\\act_level_up.ros") )
		{
			pEffect->SetRelative( sprite );
			//pEffect->SetAttachPoint( ePaperdoll_Foot );
			pEffect->SetEffectMotionStep( eEffectMotion_Step_Explode );
		}
		else
			delete pEffect;
	}	
}
//-----------------------------------------------------------------------------
void NetCli_RoleValueChild::R_SetTitleFlag      ( int TitleID , bool Flag )
{

}
//-----------------------------------------------------------------------------
void NetCli_RoleValueChild::R_SetFlag           ( int FlagID , bool Flag )
{

}
//-----------------------------------------------------------------------------
void NetCli_RoleValueChild::R_SetTitle_OK       ( int TitleID )
{

}
//-----------------------------------------------------------------------------
void NetCli_RoleValueChild::R_SetTitle_Failed   ( )
{

}
//-----------------------------------------------------------------------------
void NetCli_RoleValueChild::R_Title             ( int ItemID , int TitleID )
{

}
//-----------------------------------------------------------------------------