Пример #1
0
void ScheduleNewsCmd::Execute() const
{
    if ( m_spContext == NULL )
    {
        return;
    }

    PlayerPtr spPlayer = m_spContext->GetPlayer();
    if ( spPlayer == NULL )
    {
        return;
    }

    // Get news component
    PlayerCompNewsPtr spCompNews = spPlayer->GetCompNews();

    if ( m_spNews != NULL )
    {
        // Pay the news
        Budget& budget = spPlayer->GetBudget();
        budget.Book( CMadTV::ACCOUNT_CASH, CMadTV::ACCOUNT_NEWS_COSTS, m_spNews->GetCurrentPrice(), m_spContext->GetGame()->GetDateTime(), "Bought news" );
    }

    // Schedule
    spCompNews->SetPlannedNews( m_u32Slot, m_spNews );
}
Пример #2
0
Unsigned32 ScheduleNewsCmd::Verify() const
{
    if ( m_spContext == NULL )
    {
        return ERROR_NONE;
    }

    PlayerPtr spPlayer = m_spContext->GetPlayer();
    if ( spPlayer == NULL )
    {
        return ERROR_NONE;
    }

    // Get news component
    PlayerCompNewsPtr spCompNews = spPlayer->GetCompNews();

    // Check if slot is valid
    if ( m_u32Slot >= PlayerCompNews::NUM_PLANNED_NEWS )
    {
        return ERROR_INVALID_SLOT;
    }

    // Check if player has news
    if ( m_spNews != NULL &&
        !spCompNews->HasNews( m_spNews ) )
    {
        return ERROR_NEWS_NOT_AVAILABLE;
    }

    // Check if enough money available
    Budget& budget = spPlayer->GetBudget();
    if ( m_spNews != NULL &&
         budget.GetCash() < m_spNews->GetCurrentPrice() )
    {
        return ERROR_INSUFFICIENT_MONEY;
    }

    return ERROR_NONE;
}