예제 #1
0
/*!
	Returns the variant as a double if the variant has type()
	StringType, CString, DoubleType, IntType, UInt, or Bool; or 0.0 otherwise.

	If \a ok is non-null, \a *ok is set to TRUE if the value could be
	converted to a double and FALSE otherwise.

	\sa asDouble()
*/
double cVariant::toDouble( bool* ok ) const
{
	if ( typ == StringType )
		return ( ( QString * ) value.ptr )->toDouble( ok );

	if ( ok )
		*ok = canCast( DoubleType );

	if ( typ == DoubleType )
		return value.d;

	if ( typ == IntType )
		return ( double ) value.i;

	if ( typ == LongType )
		return ( double ) value.d;

	if ( typ == BaseCharType )
	{
		P_CHAR pChar = static_cast<P_CHAR>( value.ptr );
		return pChar ? ( double ) pChar->serial() : ( double ) INVALID_SERIAL;
	}

	if ( typ == ItemType )
	{
		P_ITEM pItem = static_cast<P_ITEM>( value.ptr );
		return pItem ? ( double ) pItem->serial() : ( double ) INVALID_SERIAL;
	}

	return 0.0;
}
예제 #2
0
/*!
	Returns the variant as an int if the variant has type()
	StringType, CString, IntType, UInt, DoubleType, Bool or KeySequence; or 0 otherwise.

	If \a ok is non-null, \a *ok is set to TRUE if the value could be
	converted to an int and FALSE otherwise.

	\sa asInt() canCast()
*/
int cVariant::toInt( bool* ok ) const
{
	if ( typ == StringType )
		return hex2dec( *( ( QString * ) value.ptr ) ).toInt( ok );

	if ( ok )
		*ok = canCast( IntType );

	if ( typ == IntType )
		return value.i;

	if ( typ == LongType )
		return ( int ) value.d;

	if ( typ == DoubleType )
		return ( int ) value.d;

	if ( typ == BaseCharType )
	{
		P_CHAR pChar = static_cast<P_CHAR>( value.ptr );
		return pChar ? pChar->serial() : INVALID_SERIAL;
	}

	if ( typ == ItemType )
	{
		P_ITEM pItem = static_cast<P_ITEM>( value.ptr );
		return pItem ? pItem->serial() : INVALID_SERIAL;
	}

	return 0;
}
void cAllSpawnRegions::postWorldLoading()
{
	cItemIterator iItems;
	for( P_ITEM pItem = iItems.first(); pItem; pItem = iItems.next() )
	{
		QString srname = pItem->spawnregion();
		if( !srname.isNull() )
		{
			cSpawnRegion* spawnregion = region( srname );
			if( spawnregion )
				spawnregion->add( pItem->serial() );
		}
	}
}
// do one spawn and reset the timer
void cSpawnRegion::reSpawn( void )
{
	this->checkForDeleted();

	UI16 i = 0;
	for( i = 0; i < this->npcsPerCycle_; i++ )
	{
		if( this->npcSerials_.size() < this->maxNpcAmt_ )
		{
			// spawn a random npc
			// first find a valid position for the npc
			Coord_cl pos;
			if( this->findValidSpot( pos ) )
			{
				QString NpcSect = this->npcSections_[ RandomNum( 1, this->npcSections_.size() ) - 1 ];
				P_NPC pc = cCharStuff::createScriptNpc( NpcSect, pos );
				if( pc != NULL )
				{
					this->npcSerials_.push_back( pc->serial() );
					pc->setSpawnregion( this->name_ );
				}
			}
		}
	}

	for( i = 0; i < this->itemsPerCycle_; i++ )
	{
		if( this->itemSerials_.size() < this->maxItemAmt_ )
		{
			// spawn a random item
			// first find a valid position for the item
			Coord_cl pos;
			if( this->findValidSpot( pos ) )
			{
				QString ItemSect = this->itemSections_[ RandomNum( 1, this->itemSections_.size() ) - 1 ];
				P_ITEM pi = cItem::createFromScript( ItemSect );
				if( pi != NULL )
				{
					pi->moveTo( pos );
					this->itemSerials_.push_back( pi->serial() );
//					pi->setSpawnRegion( this->name_ );
				}
			}
		}
	}

	this->nextTime_ = uiCurrentTime + RandomNum( this->minTime_, this->maxTime_ ) * MY_CLOCKS_PER_SEC;
}
void cSpawnRegion::reSpawnToMax( void )
{
	this->checkForDeleted();

	while( this->npcSerials_.size() < this->maxNpcAmt_ )
	{
		// spawn a random npc
		// first find a valid position for the npc
		Coord_cl pos;
		if( this->findValidSpot( pos ) )
		{
			QString NpcSect = this->npcSections_[ RandomNum( 1, static_cast<uint>(this->npcSections_.size()) ) - 1 ];
			P_NPC pc = cCharStuff::createScriptNpc( NpcSect, pos );
			if( pc != NULL )
			{
				this->npcSerials_.push_back( pc->serial() );
				pc->setSpawnregion( this->name_ );
				pc->update();
			}
		}
	}

	while( this->npcSerials_.size() < this->maxNpcAmt_ )
	{
		// spawn a random item
		// first find a valid position for the item
		Coord_cl pos;
		if( this->findValidSpot( pos ) )
		{
			QString ItemSect = this->itemSections_[ RandomNum( 1, this->itemSections_.size() ) - 1 ];
			P_ITEM pi = cItem::createFromScript( ItemSect );
			if( pi != NULL )
			{
				pi->setPos( pos );
				this->itemSerials_.push_back( pi->serial() );
//				pi->setSpawnRegion( this->name_ );
			}
		}
	}

	this->nextTime_ = uiCurrentTime + RandomNum( this->minTime_, this->maxTime_ ) * MY_CLOCKS_PER_SEC;
}
예제 #6
0
/*!
	Returns the variant as a QString if the variant has type()
	StringType, CString, ByteArray, IntType, Uint, Bool, DoubleType, Date, Time, or DateTime,
	or QString::null otherwise.

	\sa asString()
*/
const QString cVariant::toString() const
{
	if ( typ == IntType )
		return QString::number( value.i );

	if ( typ == LongType )
		return QString::number( value.d );

	if ( typ == DoubleType )
		return QString::number( toDouble() );

	if ( typ == BaseCharType )
	{
		P_CHAR pChar = static_cast<P_CHAR>( value.ptr );
		if ( pChar )
			return "0x" + QString::number( ( unsigned int ) pChar->serial(), 16 );
		else
			return "0x" + QString::number( ( unsigned int ) INVALID_SERIAL, 16 );
	}

	if ( typ == ItemType )
	{
		P_ITEM pItem = static_cast<P_ITEM>( value.ptr );
		if ( pItem )
			return "0x" + QString::number( ( unsigned int ) pItem->serial(), 16 );
		else
			return "0x" + QString::number( ( unsigned int ) INVALID_SERIAL, 16 );
	}

	if ( typ == CoordType )
	{
		Coord* pos = static_cast<Coord*>( value.ptr );
		return QString( "%1,%2,%3,%4" ).arg( pos->x ).arg( pos->y ).arg( pos->z ).arg( pos->map );
	}

	if ( typ != StringType )
		return QString();

	return *( ( QString * ) value.ptr );
}
예제 #7
0
void cDragItems::dropOnChar( cUOSocket *socket, P_ITEM pItem, P_CHAR pOtherChar )
{
	// Three possibilities:
	// If we're dropping it on ourself: packintobackpack
	// If we're dropping it on some other player: trade-window
	// If we're dropping it on some NPC: checkBehaviours
	// If not handeled: Equip the item if the NPC is owned by us

	// To prevent bad effects remove it from the clients view first
	cUOTxRemoveObject rObject;
	rObject.setSerial( pItem->serial() );
	socket->send( &rObject );

	P_CHAR pChar = socket->player();

	if( pItem->onDropOnChar( pOtherChar ) )
	{
		// Still dragging? Bounce!
		if( socket->dragging() == pItem )
			socket->bounceItem( pItem, BR_NO_REASON );

		return;
	}

	if( pOtherChar->onDropOnChar( pItem ) )
	{
		// Still dragging? Bounce!
		if( socket->dragging() == pItem )
			socket->bounceItem( pItem, BR_NO_REASON );

		return;
	}

	// Dropped on ourself
	if( pChar == pOtherChar )
	{
		pItem->toBackpack( pChar );
		return;
	}

	// Are we in range of our target
	if( !inrange1p( pChar, pOtherChar ) )
	{
		socket->bounceItem( pItem, BR_OUT_OF_REACH );
		return;
	}

	// Can wee see our target
	if( !lineOfSight( pChar->pos(), pOtherChar->pos(), TREES_BUSHES|WALLS_CHIMNEYS|DOORS|ROOFING_SLANTED|FLOORS_FLAT_ROOFING|LAVA_WATER ) )
	{
		socket->bounceItem( pItem, BR_OUT_OF_SIGHT );
		return;
	}

	// Open a secure trading window
	if( pOtherChar->objectType() == enPlayer && dynamic_cast<P_PLAYER>(pOtherChar)->socket() )
	{
		// Check if we're already trading, 
		// if not create a new window
		P_ITEM tradeWindow = pChar->atLayer( cBaseChar::TradeWindow );

		//if( !tradeWindow )
		//	tradeWindow = Trade->tradestart( client->socket(), pOtherChar );
		socket->bounceItem( pItem, BR_NO_REASON );
		socket->sysMessage( "Trading is disabled" );
		return;

		tradeWindow->addItem( pItem, false, false );
		pItem->setPos( Coord_cl(rand() % 60, rand() % 60, 9) );
		pItem->removeFromView( false );
		pItem->update();
		return;
	}

	// Dropping based on AI Type
	/*switch( pOtherChar->npcaitype() )
	{
	case 4:
		dropOnGuard( client, pItem, pOtherChar );
		break;
	case 5:
		dropOnBeggar( client, pItem, pOtherChar );
		break;
	case 8:
		dropOnBanker( client, pItem, pOtherChar );
		break;
	case 19:
		dropOnBroker( client, pItem, pOtherChar );
		break;
	};

	// Try to train - works for any NPC
	if( pOtherChar->cantrain() )
		if( pChar->trainer() == pOtherChar->serial )
			dropOnTrainer( client, pItem, pOtherChar );
		else
			pOtherChar->talk( "You need to tell me what you want to learn first" );*/

	// Finally lets check if it is simple food
	if( pItem->type() == 14 )
	{
		dropFoodOnChar( socket, pItem, pOtherChar );
		return;
	}

	socket->sysMessage( tr("The character does not seem to want the item.") );
	socket->bounceItem( pItem, BR_NO_REASON );
	return;
}
예제 #8
0
void cTempEffect::saveItem(unsigned int id, QString key, P_ITEM item ) {
	unsigned int value = item->serial();
	persistentBroker->executeQuery( QString( "REPLACE INTO effects_properties VALUES(%1,'%2','%3','%4');" ).arg( id ).arg( persistentBroker->quoteString( key ) ).arg( "item" ).arg( value ) );
}