Ejemplo n.º 1
0
// Tries to equip an item
// if that fails it tries to put the item in the users backpack
// if *that* fails it puts it at the characters feet
// That works for NPCs as well
void equipItem( P_CHAR wearer, P_ITEM item )
{
	tile_st tile = TileCache::instance()->getTile( item->id() );

	// User cannot wear the item
	if ( tile.layer == 0 )
	{
		if ( wearer->objectType() == enPlayer )
		{
			P_PLAYER pp = dynamic_cast<P_PLAYER>( wearer );
			if ( pp->socket() )
				pp->socket()->sysMessage( tr( "You cannot wear that item." ) );
		}

		item->toBackpack( wearer );
		return;
	}

	cBaseChar::ItemContainer container = wearer->content();
	cBaseChar::ItemContainer::const_iterator it( container.begin() );
	for ( ; it != container.end(); ++it )
	{
		P_ITEM equip = *it;

		// Unequip the item and free the layer that way
		if ( equip && ( equip->layer() == tile.layer ) )
			equip->toBackpack( wearer );
	}

	// *finally* equip the item
	wearer->addItem( static_cast<cBaseChar::enLayer>( item->layer() ), item );
}
Ejemplo n.º 2
0
void cCharStuff::DeleteChar (P_CHAR pc_k) // Delete character
{
	if( !pc_k )
		return;

	P_PLAYER pp_k = dynamic_cast<P_PLAYER>(pc_k);
	P_NPC pn_k = dynamic_cast<P_NPC>(pc_k);

	if( pn_k )
	{
		pn_k->setOwner( 0 );
	}

	pc_k->setGuarding( 0 );
	
	// We need to remove the equipment here.
	cBaseChar::ItemContainer container(pc_k->content());
	cBaseChar::ItemContainer::const_iterator it (container.begin());
	cBaseChar::ItemContainer::const_iterator end(container.end());
	for (; it != end; ++it )
	{
		P_ITEM pItem = *it;
		if( !pItem )
			continue;

		Items->DeleItem( pItem );
	}

	// multi check
	if( pc_k->multis() != INVALID_SERIAL )
	{
		cMulti* pMulti = dynamic_cast< cMulti* >( FindItemBySerial( pc_k->multis() ) );
		if( pMulti )
		{
			pMulti->removeChar( pc_k );
		}
	}

	pc_k->removeFromView( false ); // Remove the character from all in-range sockets view
	MapObjects::instance()->remove( pc_k ); // taking it out of mapregions BEFORE x,y changed
	pc_k->del(); // Remove from Database
	pc_k->free = true;
	World::instance()->deleteObject( pc_k );
}