void pawsExchangeWindow::HandleMessage( MsgEntry* me )
{
    switch ( me->GetType() )    
    {
        /////////////////////////////////////
        //  Starting a new Exchange
        /////////////////////////////////////
        case MSGTYPE_EXCHANGE_REQUEST:
        {            
            psExchangeRequestMsg msg(me);
            StartExchange( msg.player, msg.withPlayer );
            break;    
        }
        
        ///////////////////////////////////////////////////////////
        //  Close Exchange ( either by rejection or normal end )
        ///////////////////////////////////////////////////////////
        case MSGTYPE_EXCHANGE_END:
        {     
            Hide();
            pawsWidget * widget = PawsManager::GetSingleton().FindWidget("SmallInventoryWindow");
            if (widget && !wasSmallInventoryOpen)
                widget->Close();
            totalTriasOffered->SetText("");
            totalTriasReceived->SetText("");
            for (int i = 0; i < EXCHANGE_SLOT_COUNT; i++)
            {                   
                offeringSlots[i]->Clear();
                receivingSlots[i]->Clear();
            }
            break;
        }
        
        ///////////////////////////////////////////////////////////
        //  Update the accept status for the exchange.
        ///////////////////////////////////////////////////////////        
        case MSGTYPE_EXCHANGE_STATUS:
        {
            psExchangeStatusMsg mesg(me);
            if ( mesg.playerAccept )
                offeringBG->SetBackground("Accepted Background");
            else 
                offeringBG->SetBackground("Standard Background");            
                
            if ( mesg.otherAccept )
                receivingBG->SetBackground("Accepted Background");                
            else
                receivingBG->SetBackground("Standard Background");
            break;
        }
        ///////////////////////////////////////////////////////////
        //  Incomming money update
        ///////////////////////////////////////////////////////////                        
        case MSGTYPE_EXCHANGE_MONEY:
        {
            HandleMoney( me );
            break;
        }
        
        ///////////////////////////////////////////////////////////
        //  An item has been removed from the exchange
        ///////////////////////////////////////////////////////////                
        case MSGTYPE_EXCHANGE_REMOVE_ITEM:
        {
            psExchangeRemoveItemMsg item(me);            
            pawsSlot* itemSlot = 0;
            
            if ( item.container == CONTAINER_EXCHANGE_OFFERING )
            {
                itemSlot = offeringSlots[item.slot];
            }
            else if ( item.container == CONTAINER_EXCHANGE_RECEIVING )
            {
                itemSlot = receivingSlots[item.slot];
            }
            
            if ( itemSlot )
            {
                itemSlot->StackCount(item.newStackCount);
                break;
            }
            
            break;
        }
        
        ///////////////////////////////////////////////////////////
        //  An item has been added to the exchange
        ///////////////////////////////////////////////////////////        
        case MSGTYPE_EXCHANGE_ADD_ITEM:
        {
            psExchangeAddItemMsg item(me, psengine->GetMsgStrings());                        
            pawsSlot* itemSlot = 0;
            
            if ( item.container == CONTAINER_EXCHANGE_OFFERING )
            {
                itemSlot = offeringSlots[item.slot];
            }
            else if ( item.container == CONTAINER_EXCHANGE_RECEIVING )
            {
                itemSlot = receivingSlots[item.slot];
            }
            
            if ( itemSlot )
            {
                itemSlot->Clear();
                itemSlot->PlaceItem( item.icon, item.meshFactName, item.materialName, item.stackCount );
                itemSlot->SetToolTip( item.name );
                itemSlot->SetContainer( item.container );
                itemSlot->SetSlotID( item.slot );
            }

            break;
        }
    }
}
Beispiel #2
0
void CExchangeGoods::RecvRemoteExchangeOperationMsg( struct SQAQuestRemoteExchangeMsg *pMsg )
{
	if (!pMsg)
	{
		rfalse(4, 1, "ExchangeGoods.cpp - RecvRemoteExchangeOperationMsg() - !pMsg");
		return;
	}

    // 远程交易思路,为每一个角色添加一个商贸信息表,map<DWORD, DWORD>( itemIdx, time )
    // 只要是发布过交易信息的,就会在这个表里边添加一条信息(同时清除已经过期的信息)
    // 交易中的操作(确认、取消)
    CPlayer *src = static_cast<CPlayer *>(this);
    if (src == NULL)
        return;

    // 这个逻辑是客户端发起远程交易请求
    if ( pMsg->dnidClient == 0 )
    {
        CPlayer *dst = ( CPlayer* )GetPlayerByName( pMsg->name )->DynamicCast( IID_PLAYER );

        if ( dst == NULL || dst->m_ClientIndex == 0 || dst == src )
        { 
            TalkToDnid( src->m_ClientIndex, "远程交易目标玩家不在线!" );
            return;
        }

        //正在游戏大厅
        if ( src->IsBetting() || dst->IsBetting() )
        {
            TalkToDnid( src->m_ClientIndex, src->IsBetting() ? 
                "游戏大厅中你不能进行交易……" : "对方正在游戏大厅中,没办法和阁下交易……" );
            return;
        }

        if ( src->m_ParentRegion == NULL || dst->m_ParentRegion == NULL ||
            src->m_ParentRegion->DynamicCast( IID_DYNAMICREGION ) || dst->m_ParentRegion->DynamicCast( IID_DYNAMICREGION ) )
        {
            TalkToDnid( src->m_ClientIndex, "当角色位于动态场景时,不能使用远程交易" );
            return;
        }

        if ( src->InExchange() || dst->InExchange() )
        {
            TalkToDnid( src->m_ClientIndex, src->InExchange() ? 
                "当前状态限制你不能进行交易……" : "对方正在交易中,没办法和阁下交易……" );
            return;
        }

//         if ( src->GetSaleState() != 0 || dst->GetSaleState() )
//         {
//             TalkToDnid( src->m_ClientIndex, ( src->GetSaleState() != 0 ) ? 
//                 "阁下正在摆摊中,不能进行交易……" : "对方正在摆摊中,没办法和阁下交易……" );
//             return;
//         }

        std::map< DWORD, time_t >::iterator it = dst->excInfoMap.find( pMsg->item );
        if ( it == dst->excInfoMap.end() || abs( ( int )( time( NULL ) - it->second ) ) > 5*60 )
        { 
            TalkToDnid( src->m_ClientIndex, "你请求的信息已经过期!" );
            return;
        }

        SQAQuestRemoteExchangeMsg msg;
        msg.dnidClient = src->m_ClientIndex;
        msg.dwSrcGID = src->GetGID();
        msg.dwDestGID = dst->GetGID();
        msg.item = pMsg->item;
        dwt::strcpy( msg.name, src->GetName(), sizeof( msg.name ) );
        if ( g_StoreMessage( dst->m_ClientIndex, &msg, sizeof( msg ) ) )
            TalkToDnid( src->m_ClientIndex, "已经向目标转达了你的交易请求!" );
        else
            TalkToDnid( src->m_ClientIndex, "向目标转达交易请求的过程中出现错误!" );
    }
    else
    {
        CPlayer *dst = ( CPlayer* )GetPlayerByDnid( pMsg->dnidClient )->DynamicCast( IID_PLAYER );
        if ( dst == NULL || dst->m_ClientIndex == 0 || dst == src )
        { 
            TalkToDnid( src->m_ClientIndex, "远程交易目标玩家不在线!" );
            return;
        }

        if ( pMsg->item == 0 || pMsg->dwSrcGID != src->GetGID() || pMsg->dwDestGID != dst->GetGID() )
            TalkToDnid( src->m_ClientIndex, FormatString( "%s拒绝了你的交易请求!", dst->GetName() ) );
        else
        {
            if ( src->m_ParentRegion == NULL || dst->m_ParentRegion == NULL ||
                src->m_ParentRegion->DynamicCast( IID_DYNAMICREGION ) || dst->m_ParentRegion->DynamicCast( IID_DYNAMICREGION ) )
            {
                TalkToDnid( src->m_ClientIndex, "当角色位于动态场景时,不能使用远程交易" );
                return;
            }

            std::map< DWORD, time_t >::iterator it = src->excInfoMap.find( pMsg->item );
            if ( it == src->excInfoMap.end() || abs( ( int )( time( NULL ) - it->second ) ) > 5*60 )
                TalkToDnid( src->m_ClientIndex, "你响应的远程交易请求已经过期!" );
            else
                StartExchange( dst ); // 尝试启动交易
        }
    }
}