#include "NetCli_Item.h"

//-------------------------------------------------------------------
NetCli_Item*    NetCli_Item::This         = NULL;

//-------------------------------------------------------------------
bool NetCli_Item::_Init()
{
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_GetItemResult         , _PG_Item_LtoC_GetItemResult          );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_ClsItemInBuffer       , _PG_Item_LtoC_ClsItemInBuffer        );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_NewItemInBuffer       , _PG_Item_LtoC_NewItemInBuffer        );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_DeleteItem            , _PG_Item_LtoC_DeleteItem             );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_ExchangeField         , _PG_Item_LtoC_ExchangeField          );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_BodyBankMoneyExchange , _PG_Item_LtoC_BodyBankMoneyExchange  );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_FixItemInfo           , _PG_Item_LtoC_FixItemInfo            );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_FixAllItemInfo        , _PG_Item_LtoC_FixAllItemInfo         );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_FixMoney              , _PG_Item_LtoC_FixMoney               );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_MaxItemCount          , _PG_Item_LtoC_MaxItemCount           );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_OpenBank              , _PG_Item_LtoC_OpenBank               );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_CloseBank             , _PG_Item_LtoC_CloseBank              );
    _Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_UseItemResult         , _PG_Item_LtoC_UseItemResult          );
	_Net.RegOnSrvPacketFunction	( EM_PG_Item_LtoC_SetKeyItemFlag        , _PG_Item_LtoC_SetKeyItemFlag         );

    return true;
}
//-------------------------------------------------------------------
bool NetCli_Item::_Release()
{
    return true;
}
//-------------------------------------------------------------------
void NetCli_Item::_PG_Item_LtoC_GetItemResult            ( int Sockid , int Size , void* Data )
{
    PG_Item_LtoC_GetItemResult*  PG = (PG_Item_LtoC_GetItemResult*)Data;
    switch( PG->Result )
    {
    case EM_Item_ItemOK:
        This->R_GetItemOK(  );
        break;
    case EM_Item_GetGroundItemFailed:
        This->R_GetGroundItemFailed( );
        break;
    case EM_Item_GetItemInBufferFailed:
        This->R_GetBufferItemFailed( );
        break;
	case EM_Item_GetItemInBufferOK:
		This->R_GetBufferItemOK( PG->Count );
		break;
    }

}
void NetCli_Item::_PG_Item_LtoC_SetKeyItemFlag          ( int Sockid , int Size , void* Data )  
{
	PG_Item_LtoC_SetKeyItemFlag*  PG = (PG_Item_LtoC_SetKeyItemFlag*)Data;
	This->R_SetKeyItemFlag( PG->KeyItemID  , PG->Value );
}
void NetCli_Item::_PG_Item_LtoC_ClsItemInBuffer          ( int Sockid , int Size , void* Data )  
{
    PG_Item_LtoC_ClsItemInBuffer*  PG = (PG_Item_LtoC_ClsItemInBuffer*)Data;
    This->R_ClsItemInBuffer();
}
void NetCli_Item::_PG_Item_LtoC_NewItemInBuffer          ( int Sockid , int Size , void* Data )  
{
    PG_Item_LtoC_NewItemInBuffer*  PG = (PG_Item_LtoC_NewItemInBuffer*)Data;
    This->R_NewItemInBuffer( PG->Item );
}
void NetCli_Item::_PG_Item_LtoC_DeleteItem               ( int Sockid , int Size , void* Data )  
{
    PG_Item_LtoC_DeleteItem*  PG = (PG_Item_LtoC_DeleteItem*)Data;
    switch( PG->Result )
    {
    case EM_Item_ItemOK:
        {
            switch( PG->Type )
            {
                case Def_Item_Pos_Body:
                    This->R_DeleteItemOK_Body( );
                    break;
                case Def_Item_Pos_Bank:
                    This->R_DeleteItemOK_Bank( );
                    break;
                case Def_Item_Pos_EQ:
                    This->R_DeleteItemOK_EQ( );
                    break;
            }
        }
        break;
    case EM_Item_DeleteItemFailed:
        This->R_DeleteItemFailed();
        break;
    }
}
void NetCli_Item::_PG_Item_LtoC_ExchangeField            ( int Sockid , int Size , void* Data )  
{
    PG_Item_LtoC_ExchangeField*  PG = (PG_Item_LtoC_ExchangeField*)Data;
    if(  PG->Result  == EM_Item_ItemOK )
    {
        if(		PG->Type[0] == Def_Item_Pos_Body 
            &&	PG->Type[1] == Def_Item_Pos_Body )
        {
            This->R_ExchangeFieldOK_Body( );
        }
        else if(PG->Type[0] == Def_Item_Pos_Body 
            &&	PG->Type[1] == Def_Item_Pos_Bank )
        {
            This->R_ExchangeFieldOK_BodyBank( );
        }
        else if(PG->Type[0] == Def_Item_Pos_Bank
            &&	PG->Type[1] == Def_Item_Pos_Body )
        {
            This->R_ExchangeFieldOK_BodyBank( );
        }
        else if( PG->Type[0] == Def_Item_Pos_Bank 
            &&	 PG->Type[1] == Def_Item_Pos_Bank )
        {
            This->R_ExchangeFieldOK_Bank( );
        }
    }
    else if( PG->Result  == EM_Item_ExchangeFieldFailed )
    {
        if(		PG->Type[0] == Def_Item_Pos_Body 
            &&	PG->Type[1] == Def_Item_Pos_Body )
        {
            This->R_ExchangeFieldFailed_Body( );
        }
        else if(PG->Type[0] == Def_Item_Pos_Body 
            &&	PG->Type[1] == Def_Item_Pos_Bank )
        {
            This->R_ExchangeFieldFailed_BodyBank( );
        }
        else if(PG->Type[0] == Def_Item_Pos_Bank
            &&	PG->Type[1] == Def_Item_Pos_Body )
        {
            This->R_ExchangeFieldFailed_BodyBank( );
        }
        else if( PG->Type[0] == Def_Item_Pos_Bank 
            &&	 PG->Type[1] == Def_Item_Pos_Bank )
        {
            This->R_ExchangeFieldFailed_Bank( );
        }
    }

}
void NetCli_Item::_PG_Item_LtoC_BodyBankMoneyExchange    ( int Sockid , int Size , void* Data )  
{
    PG_Item_LtoC_BodyBankMoneyExchange* PG = (PG_Item_LtoC_BodyBankMoneyExchange*)Data;
    if( PG->Result == EM_Item_ItemOK )
        This->R_BodyBankMoneyExchangeOK();
    else
        This->R_BodyBankMoneyExchangeFalse();
}
void NetCli_Item::_PG_Item_LtoC_FixItemInfo              ( int Sockid , int Size , void* Data )   
{
    PG_Item_LtoC_FixItemInfo* PG = (PG_Item_LtoC_FixItemInfo*)Data;
    switch( PG->Type )
    {
    case Def_Item_Pos_Body:
        This->R_FixItemInfo_Body( PG->Item , PG->Pos );
        break;
    case Def_Item_Pos_Bank:
        This->R_FixItemInfo_Bank( PG->Item , PG->Pos );
        break;
    case Def_Item_Pos_EQ:
        This->R_FixItemInfo_EQ( PG->Item , PG->Pos );
        break;
    }
}
void NetCli_Item::_PG_Item_LtoC_FixAllItemInfo           ( int Sockid , int Size , void* Data )  
{
    PG_Item_LtoC_FixAllItemInfo* PG = (PG_Item_LtoC_FixAllItemInfo*)Data;
    This->R_FixAllItemInfo( PG->Body , PG->Bank , PG->EQ );
}
void NetCli_Item::_PG_Item_LtoC_FixMoney                 ( int Sockid , int Size , void* Data )   
{
    PG_Item_LtoC_FixMoney* PG = (PG_Item_LtoC_FixMoney*)Data;
    This->R_FixMoney( PG->BodyMoney , PG->BankMoney );
}
void NetCli_Item::_PG_Item_LtoC_MaxItemCount             ( int Sockid , int Size , void* Data )  
{
    PG_Item_LtoC_MaxItemCount* PG = (PG_Item_LtoC_MaxItemCount*)Data;
    This->R_MaxItemCount( PG->MaxBody , PG->MaxBank );
}
void NetCli_Item::_PG_Item_LtoC_OpenBank                 ( int Sockid , int Size , void* Data )   
{
	PG_Item_LtoC_OpenBank* PG = (PG_Item_LtoC_OpenBank*)Data;
	This->R_OpenBank( PG->GItemID );
}

void NetCli_Item::_PG_Item_LtoC_CloseBank                 ( int Sockid , int Size , void* Data )   
{
	PG_Item_LtoC_CloseBank* PG = (PG_Item_LtoC_CloseBank*)Data;
	This->R_CloseBank( );
}

void NetCli_Item::_PG_Item_LtoC_UseItemResult            ( int Sockid , int Size , void* Data )   
{
   PG_Item_LtoC_UseItemResult* PG = (PG_Item_LtoC_UseItemResult*)Data; 
   if( PG->Result )
   {
       This->R_UseItemOK( PG->Pos );
   }
   else
   {
       This->R_UseItemFailed( PG->Pos );
   }
   
}
//------------------------------------------------------------------------------------------------------------------------
void NetCli_Item::_GetGroundItem                  ( int ItemID , int Pos )            
{
    PG_Item_CtoL_GetGroundItem Send;
    Send.ItemID = ItemID;
    Send.Pos = Pos;
    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_GetBufferItem                  ( ItemFieldStruct Item , int Pos , int Count )
{
    PG_Item_CtoL_GetBufferItem Send;
    Send.Item = Item;
    Send.Pos = Pos;
    Send.Count = Count;
    SendToLocal( sizeof(Send) , &Send );
}

void NetCli_Item::_DelBufferItem                  ( ItemFieldStruct Item )
{
    PG_Item_CtoL_GetBufferItem Send;
    Send.Item = Item;
    Send.Pos = -1;
    SendToLocal( sizeof(Send) , &Send );
}

void NetCli_Item::_DeleteItem_Body                     ( ItemFieldStruct Item , int Pos )
{

    PG_Item_CtoL_DeleteItem Send;
    Send.Item = Item;
    Send.Pos = Pos;
    Send.Type = Def_Item_Pos_Body;

    if( Send.Item.Pos == EM_ItemState_CliDisabled )
        Send.Item.Pos = EM_ItemState_NONE;

    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_DeleteItem_Bank                     ( ItemFieldStruct Item , int Pos )
{
    PG_Item_CtoL_DeleteItem Send;
    Send.Item = Item;
    Send.Pos = Pos;
    Send.Type = Def_Item_Pos_Bank;

    if( Send.Item.Pos == EM_ItemState_CliDisabled )
        Send.Item.Pos = EM_ItemState_NONE;

    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_DeleteItem_EQ                     ( ItemFieldStruct Item , int Pos )
{

    PG_Item_CtoL_DeleteItem Send;
    Send.Item = Item;
    Send.Pos = Pos;
    Send.Type = Def_Item_Pos_EQ;

    if( Send.Item.Pos == EM_ItemState_CliDisabled )
        Send.Item.Pos = EM_ItemState_NONE;

    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_ExchangeField_Body                  ( ItemFieldStruct Item1 , int Pos1 , ItemFieldStruct Item2 , int Pos2 )
{
    PG_Item_CtoL_ExchangeField Send;
    Send.Item[0] = Item1;
    Send.Item[1] = Item2;
    Send.Pos[0] = Pos1;
    Send.Pos[1] = Pos2;
    Send.Type[0] = Def_Item_Pos_Body;
    Send.Type[1] = Def_Item_Pos_Body;

    if( Send.Item[0].Pos == EM_ItemState_CliDisabled )
        Send.Item[0].Pos = EM_ItemState_NONE;
    if( Send.Item[1].Pos == EM_ItemState_CliDisabled )
        Send.Item[1].Pos = EM_ItemState_NONE;

    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_ExchangeField_Bank                  ( ItemFieldStruct Item1 , int Pos1 , ItemFieldStruct Item2 , int Pos2 )
{

    PG_Item_CtoL_ExchangeField Send;
    Send.Item[0] = Item1;
    Send.Item[1] = Item2;
    Send.Pos[0] = Pos1;
    Send.Pos[1] = Pos2;
    Send.Type[0] = Def_Item_Pos_Bank;
    Send.Type[1] = Def_Item_Pos_Bank;

    if( Send.Item[0].Pos == EM_ItemState_CliDisabled )
        Send.Item[0].Pos = EM_ItemState_NONE;
    if( Send.Item[1].Pos == EM_ItemState_CliDisabled )
        Send.Item[1].Pos = EM_ItemState_NONE;

    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_ExchangeField_BankBody                  ( ItemFieldStruct Item1 , int Pos1 , ItemFieldStruct Item2 , int Pos2 )
{
    PG_Item_CtoL_ExchangeField Send;
    Send.Item[0] = Item1;
    Send.Item[1] = Item2;
    Send.Pos[0] = Pos1;
    Send.Pos[1] = Pos2;
    Send.Type[0] = Def_Item_Pos_Bank;
    Send.Type[1] = Def_Item_Pos_Body;

    if( Send.Item[0].Pos == EM_ItemState_CliDisabled )
        Send.Item[0].Pos = EM_ItemState_NONE;
    if( Send.Item[1].Pos == EM_ItemState_CliDisabled )
        Send.Item[1].Pos = EM_ItemState_NONE;

    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_ExchangeField_BodyBank                  ( ItemFieldStruct Item1 , int Pos1 , ItemFieldStruct Item2 , int Pos2 )
{

    PG_Item_CtoL_ExchangeField Send;
    Send.Item[0] = Item1;
    Send.Item[1] = Item2;
    Send.Pos[0] = Pos1;
    Send.Pos[1] = Pos2;
    Send.Type[0] = Def_Item_Pos_Body;
    Send.Type[1] = Def_Item_Pos_Bank;
    
    if( Send.Item[0].Pos == EM_ItemState_CliDisabled )
        Send.Item[0].Pos = EM_ItemState_NONE;
    if( Send.Item[1].Pos == EM_ItemState_CliDisabled )
        Send.Item[1].Pos = EM_ItemState_NONE;

    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_RequestBodyBankMoneyExchange   ( int Count )
{
    PG_Item_CtoL_RequestBodyBankMoneyExchange Send;
    Send.Count = Count;
    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_RequestBufferInfo              ()
{
    PG_Item_CtoL_RequestBufferInfo Send;
    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_RequestApartBodyItem           ( ItemFieldStruct Item , int SrcPos , int DesCount , int DesPos )
{
    PG_Item_CtoL_RequestApartBodyItem Send;
    Send.Item = Item;
    Send.CountDes = DesCount;
    Send.PosDes = DesPos;
    Send.PosSrc = SrcPos;

    if( Send.Item.Pos == EM_ItemState_CliDisabled )
        Send.Item.Pos = EM_ItemState_NONE;

    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_RequestFixAllItemInfo          ()
{
    PG_Item_CtoL_RequestFixAllItemInfo Send;
    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_CloseBank                      ()
{
    PG_Item_CtoL_CloseBank Send;
    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_UseItem_Body                        ( ItemFieldStruct Item , int Pos , int TargetID , float TargetX , float TargetY , float TargetZ )
{
    PG_Item_CtoL_UseItem Send;
    Send.Item = Item;
    Send.Pos = Pos;
    Send.TargetID = TargetID;
    Send.Type = Def_Item_Pos_Body;
	Send.TargetX = TargetX;
	Send.TargetY = TargetY;
	Send.TargetZ = TargetZ;

    if( Send.Item.Pos == EM_ItemState_CliDisabled )
        Send.Item.Pos = EM_ItemState_NONE;
    
    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_UseItem_Bank                        ( ItemFieldStruct Item , int Pos , int TargetID , float TargetX , float TargetY , float TargetZ )
{
    PG_Item_CtoL_UseItem Send;
    Send.Item = Item;
    Send.Pos = Pos;
    Send.TargetID = TargetID;
    Send.Type = Def_Item_Pos_Bank;

    if( Send.Item.Pos == EM_ItemState_CliDisabled )
        Send.Item.Pos = EM_ItemState_NONE;

    SendToLocal( sizeof(Send) , &Send );
}
void NetCli_Item::_UseItem_EQ                        ( ItemFieldStruct Item , int Pos , int TargetID , float TargetX , float TargetY , float TargetZ )
{
    PG_Item_CtoL_UseItem Send;
    Send.Item = Item;
    Send.Pos = Pos;
    Send.TargetID = TargetID;
    Send.Type = Def_Item_Pos_EQ;

    if( Send.Item.Pos == EM_ItemState_CliDisabled )
        Send.Item.Pos = EM_ItemState_NONE;

    SendToLocal( sizeof(Send) , &Send );
}