Beispiel #1
0
qboolean Item::Pickupable( Entity *other )
{
	if ( level.time < _nextPickupTime )
		return false;

	if ( multiplayerManager.inMultiplayer() && other->isSubclassOf( Player ) )
	{
		if ( !multiplayerManager.canPickup( (Player *)other, getMultiplayerItemType(), getName().c_str() ) )
			return false;
	}

	if ( getSolidType() == SOLID_NOT )
	{
		return NULL;
	}
	
	if ( !other->isSubclassOf( Sentient ) )
	{
		return false;
	}
	else
	{
		Sentient * sent;
		Item * item;
		
		sent = ( Sentient * )other;

		if ( sent->deadflag || sent->health <= 0.0f )
		{
			return false;
		}
		
		item = sent->FindItem( getName() );
		
		if ( item && ( item->getAmount() >= item->MaxAmount() ) )
		{
			return false;
		}
		
		// TODO : fixme
		// If deathmatch and already in a powerup, don't pickup anymore when DF_INSTANT_ITEMS is on
		/* if ( multiplayerManager.checkFlag( MP_FLAG_INSTANT_ITEMS ) &&
		this->isSubclassOf( InventoryItem ) &&
		sent->PowerupActive()
		)
		{
		return false;
		} */
	}
	return true;
}
Beispiel #2
0
Item *PowerupBase::ItemPickup( Entity *other, qboolean add_to_inventory, qboolean )
{
	Player *player;
	str      realname;

	Q_UNUSED(add_to_inventory);

	if ( !other->isSubclassOf( Player ) )
		return NULL;

	if ( !Pickupable( other ) )
		return NULL;

	if ( multiplayerManager.inMultiplayer() )
	{
		if ( !multiplayerManager.canPickup( (Player *)other, getMultiplayerItemType(), item_name ) )
			return NULL;
	}

	player = ( Player * )other;

	// Play pickup sound
	realname = GetRandomAlias( "snd_pickup" );
	if ( realname.length() > 1 )
		player->Sound( realname, CHAN_ITEM );

	// Cancel some events
	CancelEventsOfType( EV_Item_DropToFloor );
	CancelEventsOfType( EV_Item_Respawn );
	CancelEventsOfType( EV_FadeOut );

	// Hide the model
	setSolidType( SOLID_NOT );

	if ( _missingSkin )
	{
		ChangeSkin( _missingSkin, true );
	}
	else
	{
		hideModel();
	}

	// Respawn?
	if ( !Respawnable() )
		PostEvent( EV_Remove, FRAMETIME );
	else
		PostEvent( EV_Item_Respawn, RespawnTime() );

	// fire off any pickup_thread's
	if ( pickup_thread.length() )
      {
      ExecuteThread( pickup_thread );
      }

	givePlayerItem( player );

	if ( multiplayerManager.inMultiplayer() )
	{
		multiplayerManager.pickedupItem( (Player *)other, MP_ITEM_TYPE_POWERUP, item_name );
	}

	return NULL; // This doesn't create any items
}