/*!
	Loads Custom tags under the \a key serial from the persistent storage
*/
void cCustomTags::load( SERIAL key )
{
	if ( tags_ )
		tags_->clear();

	QSqlQuery result;
	result.setForwardOnly( true );
	result.prepare( "SELECT name,type,value FROM tags WHERE serial = ?" );
	result.addBindValue( key );
	result.exec();

	while ( result.next() )
	{
		QString name = result.value( 0 ).toString();
		QString type = result.value( 1 ).toString();
		QString value = result.value( 2 ).toString();

		if ( !tags_ )
			tags_ = new QMap<QString, cVariant>;

		if ( type == "String" )
			tags_->insert( name, cVariant( value ) );
		else if ( type == "Int" )
			tags_->insert( name, cVariant( value.toInt() ) );
		else if ( type == "Double" )
			tags_->insert( name, cVariant( value.toDouble() ) );
	}

	changed = false;
}
/*!
	Loads Custom tags under the \a key serial from the persistent storage
*/
void cCustomTags::load( SERIAL key )
{
	if ( tags_ )
		tags_->clear();

	cDBResult result = PersistentBroker::instance()->query( QString( "SELECT name,type,value FROM tags WHERE serial = '%1'" ).arg( key ) );

	while ( result.fetchrow() )
	{
		QString name = result.getString( 0 );
		QString type = result.getString( 1 );
		QString value = result.getString( 2 );

		if ( !tags_ )
			tags_ = new QMap<QString, cVariant>;

		if ( type == "StringType" )
			tags_->insert( name, cVariant( value ) );
		else if ( type == "IntType" )
			tags_->insert( name, cVariant( value.toInt() ) );
		else if ( type == "DoubleType" )
			tags_->insert( name, cVariant( value.toDouble() ) );
	}

	result.free();

	changed = false;
}
static int wpAccount_setAttr(wpAccount* self, char* name, PyObject* value) {

	cVariant val;
	if ( PyString_Check( value ) || PyUnicode_Check( value ) )
		val = cVariant( Python2QString( value ) );
	else if ( PyInt_Check( value ) )
		val = cVariant( PyInt_AsLong( value ) );
	else if ( checkWpItem( value ) )
		val = cVariant( getWpItem( value ) );
	else if ( checkWpChar( value ) )
		val = cVariant( getWpChar( value ) );
	else if ( checkWpCoord( value ) )
		val = cVariant( getWpCoord( value ) );
	else if ( PyFloat_Check( value ) )
		val = cVariant( PyFloat_AsDouble( value ) );
	else if ( value == Py_True ) 
		val = cVariant( 1 ); // True
	else if ( value == Py_False )
		val = cVariant( 0 ); // false

	stError * error = self->account->setProperty( name, val );

	if (error) {
		PyErr_Format( PyExc_TypeError, "Error while setting attribute '%s': %s", name, error->text.latin1() );
		delete error;
		return 0;
	}

	return 0;
}
void Human_Stablemaster::handleTargetInput( P_PLAYER player, cUORxTarget* target )
{
	if ( !player )
		return;

	P_ITEM pPack = m_npc->getBankbox();
	if ( !pPack )
		return;

	P_NPC pPet = dynamic_cast<P_NPC>( World::instance()->findChar( target->serial() ) );
	if ( !pPet )
	{
		m_npc->talk( tr( "I cannot stable that!" ) );
		return;
	}

	if ( pPet->owner() != player )
	{
		m_npc->talk( tr( "This does not belong to you!" ) );
		return;
	}

	// we spawn a worldgem in the stablemasters bankbox for the pet
	// it does only hold the serial of it, the serial of the owner and the
	// number of refresh signals since begin of stabling
	// the pet becomes "free", which means, that it isnt in the world
	// but will still be saved.
	P_ITEM pGem = new cItem();
	pGem->Init( true );
	pGem->setTag( "player", cVariant( player->serial() ) );
	pGem->setTag( "pet", cVariant( pPet->serial() ) );
	pGem->setId( 0x1ea7 );
	pGem->setName( tr( "petitem: %1" ).arg( pPet->name() ) );
	pGem->setVisible( 2 ); // gm visible
	pPack->addItem( pGem );
	pGem->update();


	//pPet->free = true;
	MapObjects::instance()->remove( pPet );
	pPet->setStablemasterSerial( this->m_npc->serial() );
	pPet->removeFromView();

	// we need this for db saves
    m_npc->talk( tr( "Say release to get your pet back!" ) );
}
void cUObject::processNode( const QDomElement &Tag )
{
	QString TagName = Tag.nodeName();
	QString Value = this->getNodeValue( Tag );

	// <tag type="string"> also type="value"
	//	    <key>multisection</key>
	//		<value>smallboat</value>
	// </tag>
	if( TagName == "tag" )
	{
		QString tkey, tvalue;
		QDomNode childNode = Tag.firstChild();
		while( !childNode.isNull() )
		{
			if( childNode.isElement() )
			{
				QDomElement childTag = childNode.toElement();
				QString childValue = this->getNodeValue( childTag );
				QString childName = childNode.nodeName();
				
				if( childName == "key" )
					tkey = childValue;	

				else if( childName == "value" )
					tvalue = childValue;
			}
			childNode = childNode.nextSibling();
		}

		if( !tkey.isNull() && !tvalue.isNull() )
		{
			if( Tag.attribute( "type" ) == "value" )
				this->tags_.set( tkey, cVariant( tvalue.toInt() ) );
			else
				this->tags_.set( tkey, cVariant( tvalue ) );
		}
	}
	// <events>a,b,c</events>
	else if( TagName == "events" )
	{
		eventList_ = QStringList::split( ",", Value );
		recreateEvents();
	}
}
static int wpMulti_setAttr( wpMulti *self, char *name, PyObject *value )
{
	if( !strcmp( "events", name ) )
	{
		if( !PyList_Check( value ) )
		{
			PyErr_BadArgument();
			return -1;
		}

		self->pMulti->clearEvents();
		int i;
		for( i = 0; i < PyList_Size( value ); ++i )
		{
			if( !PyString_Check( PyList_GetItem( value, i ) ) )
				continue;

			cPythonScript *script = ScriptManager::instance()->find( PyString_AsString( PyList_GetItem( value, i ) ) );
			if( script )
				self->pMulti->addEvent( script );
		}
	}
	else
	{
		cVariant val;
		if( PyString_Check( value ) )
			val = cVariant( PyString_AsString( value ) );
		else if( PyInt_Check( value ) )
			val = cVariant( PyInt_AsLong( value ) );
		else if( checkWpItem( value ) )
			val = cVariant( getWpItem( value ) );
		else if( checkWpChar( value ) )
			val = cVariant( getWpChar( value ) );
		else if( checkWpCoord( value ) )
			val = cVariant( getWpCoord( value ) );
		else if( PyFloat_Check( value ) )
			val = cVariant( PyFloat_AsDouble( value ) );

		if( !val.isValid() )
		{
			if( value->ob_type )
				PyErr_Format( PyExc_TypeError, "Unsupported object type: %s", value->ob_type->tp_name );
			else
				PyErr_Format( PyExc_TypeError, "Unknown object type" );
			return 0;
		}

		stError *error = self->pMulti->setProperty( name, val );

		if( error )
		{
			PyErr_Format( PyExc_TypeError, "Error while setting attribute '%s': %s", name, error->text.latin1() );
			delete error;
			return 0;
		}
	}

	return 0;
}
/*!
	Sets a custom tag
*/
static PyObject* wpMulti_settag( wpMulti* self, PyObject* args )
{
	if( !self->pMulti || self->pMulti->free )
		return PyFalse;

	if( PyTuple_Size( args ) < 1 || !checkArgStr( 0 ) || ( !checkArgStr( 1 ) && !checkArgInt( 1 )  ) )
	{
		PyErr_BadArgument();
		return NULL;
	}

	QString key = PyString_AsString( PyTuple_GetItem( args, 0 ) );

	self->pMulti->removeTag( key );

	if( checkArgStr( 1 ) )
		self->pMulti->setTag( key, cVariant( QString( getArgStr( 1 ) ) ) );
	else if( checkArgInt( 1 ) )
		self->pMulti->setTag( key, cVariant( (int)getArgInt( 1 ) ) );

	return PyTrue;
}
Exemple #8
0
/*
	\method socket.settag
	\description Set a custom tag on the object.
	\param name The name of the tag.
	Please keep in mind these tags are temporary in nature.
	When the socket disconnects, the tag will be gone.
	\param value The value of the tag. Possible value types
	are string, unicode, float and integer.
*/
static PyObject* wpSocket_settag( wpSocket* self, PyObject* args )
{
	char* key;
	PyObject* object;

	if ( !PyArg_ParseTuple( args, "sO:char.settag( name, value )", &key, &object ) )
		return 0;

	if ( PyString_Check( object ) || PyUnicode_Check( object ) )
	{
		self->pSock->tags().set( key, cVariant( boost::python::extract<QString>( object ) ) );
	}
	else if ( PyInt_Check( object ) )
	{
		self->pSock->tags().set( key, cVariant( ( int ) PyInt_AsLong( object ) ) );
	}
	else if ( PyFloat_Check( object ) )
	{
		self->pSock->tags().set( key, cVariant( ( double ) PyFloat_AsDouble( object ) ) );
	}

	Py_RETURN_NONE;
}
bool cVariant::cast( Type t )
{
	switch ( t )
	{
	case StringType:
		asString();
		break;
	case IntType:
		asInt();
		break;
	case DoubleType:
		asDouble();
		break;
	default:
		( *this ) = cVariant();
	}
	return canCast( t );
}
void cUObject::processNode( const cElement *Tag )
{
	QString TagName = Tag->name();
	QString Value = Tag->value();

	if( TagName == "name" )
	{
		name_ = Value;
	}
	//<direction>SE</direction>
	else if( TagName == "direction" )
	{
		if( Value == "NE" )
			this->dir_ = 1;
		else if( Value == "E" )
			this->dir_ = 2;
		else if( Value == "SE" )
			this->dir_ = 3;
		else if( Value == "S" )
			this->dir_ = 4;
		else if( Value == "SW" )
			this->dir_ = 5;
		else if( Value == "W" )
			this->dir_ = 6;
		else if( Value == "NW" )
			this->dir_ = 7;
		else if( Value == "N" )
			this->dir_ = 0;
		else
			this->dir_ = Value.toUShort();
	}

	// <tag type="string"> also type="value"
	//	    <key>multisection</key>
	//		<value>smallboat</value>
	// </tag>
	else if( TagName == "tag" )
	{
		QString name = Tag->getAttribute("name");
		QString value = Tag->getAttribute("value");

		if (!name.isNull()) {
			// If there is no value attribute, use the
			// tag content instead.
			if (value.isNull()) {
				value = Tag->text();

				if (value.isNull()) {
					value = "";
				}
			}

            QString type = Tag->getAttribute("type", "string");

			if (type == "int") {
				// If the value is separated by a ,
				// we assume it's a random gradient.
				// If it's separated by ; we assume it's a list of values
				// we should choose from randomly.
				int sep = value.find(',');

				if (sep != -1) {
					int min = hex2dec(value.left(sep)).toInt();
					int max = hex2dec(value.mid(sep + 1)).toInt();

					int value = RandomNum(min, max);
					tags_.set(name, cVariant((int)value));
				} else {
					// Choose a random value from the list.
					if (value.contains(';')) {
						QStringList values = QStringList::split(';', value);
						if (values.size() > 0) {
							value = values[RandomNum(0, values.size() - 1)];
						}
					}

					tags_.set( name, cVariant(hex2dec(value).toInt()));
				}
			} else if (type == "float") {
				tags_.set(name, cVariant(value.toFloat()));
			} else {
				tags_.set(name, cVariant(value));
			}
		}
	}
	// <events>a,b,c</events>
	else if( TagName == "events" )
	{
		if( Value.isEmpty() && eventList_.isEmpty() )
			eventList_ = QString::null;
		else
			eventList_ = eventList_.isEmpty() ? Value : eventList_ + "," + Value;

		recreateEvents();
	}
	else
	{
		if (Value.isEmpty()) {
			Value = "1";
		}

		cVariant variant( Value );
		setProperty( TagName, variant );
	}
}
Exemple #11
0
bool cPlayer::mount( P_NPC pMount )
{
	if ( !pMount )
		return false;

	if ( isDead() )
	{
		return false;
	}

	unsigned short mountId = pMount->mountId();

	if ( !mountId )
	{
		return false; // Not mountable
	}

	cUOSocket* socket = this->socket();
	if ( !inRange( pMount, Config::instance()->mountRange() ) && !isGM() )
	{
		if ( socket )
			socket->sysMessage( 500206 ); // That is too far away to ride.
		return true; // Mountable, but not in range
	}

	if ( pMount->owner() == this || isGM() )
	{
		unmount();

		P_ITEM pMountItem = new cItem;
		pMountItem->Init();
		pMountItem->setId( mountId );
		pMountItem->setColor( pMount->skin() );

		if ( direction() != pMount->direction() )
		{
			setDirection( pMount->direction() );
			update();
		}

		this->addItem( cBaseChar::Mount, pMountItem );
		pMountItem->setTag( "pet", cVariant( pMount->serial() ) );
		pMountItem->update();

		// if this is a gm lets tame the animal in the process
		if ( isGM() )
		{
			pMount->setOwner( this );
			pMount->setTamed( true );
		}

		// remove it from screen!
		pMount->bark( Bark_Idle );
		pMount->removeFromView( false );
		pMount->fight( 0 );
		pMount->setStablemasterSerial( serial_ );
	}
	else if ( pMount->owner() == 0 )
	{
		socket->clilocMessage( 501263, 0, 0x3b2, 3, this ); // That mount does not look broken! You would have to tame it to ride it.
	}
	else
		socket->clilocMessage( 501264, 0, 0x3b2, 3, this ); // This isn't your mount; it refuses to let you ride.

	return true;
}
void cPlayer::mount( P_NPC pMount )
{
	if ( !pMount )
		return;

	cUOSocket* socket = this->socket();
	if ( !inRange( pMount, 2 ) && !isGM() )
	{
		if ( socket )
			socket->sysMessage( tr( "You are too far away to mount!" ) );
		return;
	}

	if ( pMount->owner() == this || isGM() )
	{
		unmount();

		P_ITEM pMountItem = new cItem;
		pMountItem->Init();
		pMountItem->setId( 0x915 );
		pMountItem->setColor( pMount->skin() );

		switch ( static_cast<unsigned short>( pMount->body() & 0x00FF ) )
		{
		case 0xC8:
			pMountItem->setId( 0x3E9F ); break; // Horse
		case 0xE2:
			pMountItem->setId( 0x3EA0 ); break; // Horse
		case 0xE4:
			pMountItem->setId( 0x3EA1 ); break; // Horse
		case 0xCC:
			pMountItem->setId( 0x3EA2 ); break; // Horse
		case 0xD2:
			pMountItem->setId( 0x3EA3 ); break; // Desert Ostard
		case 0xDA:
			pMountItem->setId( 0x3EA4 ); break; // Frenzied Ostard
		case 0xDB:
			pMountItem->setId( 0x3EA5 ); break; // Forest Ostard
		case 0xDC:
			pMountItem->setId( 0x3EA6 ); break; // LLama
		case 0x34:
			pMountItem->setId( 0x3E9F ); break; // Brown Horse
		case 0x4E:
			pMountItem->setId( 0x3EA0 ); break; // Grey Horse
		case 0x50:
			pMountItem->setId( 0x3EA1 ); break; // Tan Horse
		case 0x74:
			pMountItem->setId( 0x3EB5 ); break; // Nightmare
		case 0x75:
			pMountItem->setId( 0x3EA8 ); break; // Silver Steed
		case 0x72:
			pMountItem->setId( 0x3EA9 ); break; // Dark Steed
		case 0x7A:
			pMountItem->setId( 0x3EB4 ); break; // Unicorn
		case 0x84:
			pMountItem->setId( 0x3EAD ); break; // Kirin
		case 0x73:
			pMountItem->setId( 0x3EAA ); break; // Etheral
		case 0x76:
			pMountItem->setId( 0x3EB2 ); break; // War Horse-Brit
		case 0x77:
			pMountItem->setId( 0x3EB1 ); break; // War Horse-Mage Council
		case 0x78:
			pMountItem->setId( 0x3EAF ); break; // War Horse-Minax
		case 0x79:
			pMountItem->setId( 0x3EB0 ); break; // War Horse-Shadowlord
		case 0xAA:
			pMountItem->setId( 0x3EAB ); break; // Etheral LLama
		case 0x3A:
			pMountItem->setId( 0x3EA4 ); break; // Forest Ostard
		case 0x39:
			pMountItem->setId( 0x3EA3 ); break; // Desert Ostard
		case 0x3B:
			pMountItem->setId( 0x3EA5 ); break; // Frenzied Ostard
		case 0x90:
			pMountItem->setId( 0x3EB3 ); break; // Seahorse
		case 0xAB:
			pMountItem->setId( 0x3EAC ); break; // Etheral Ostard
		case 0xBB:
			pMountItem->setId( 0x3EB8 ); break; // Ridgeback
		case 0x17:
			pMountItem->setId( 0x3EBC ); break; // giant beetle
		case 0x19:
			pMountItem->setId( 0x3EBB ); break; // skeletal mount
		case 0x1a:
			pMountItem->setId( 0x3EBD ); break; // swamp dragon
		case 0x1f:
			pMountItem->setId( 0x3EBE ); break; // armor dragon
		}

		this->addItem( cBaseChar::Mount, pMountItem );
		pMountItem->setTag( "pet", cVariant( pMount->serial() ) );
		pMountItem->update();

		// if this is a gm lets tame the animal in the process
		if ( isGM() )
		{
			pMount->setOwner( this );
		}

		// remove it from screen!
		pMount->bark( Bark_Idle );
		pMount->removeFromView( false );
		pMount->fight( 0 );
		pMount->setStablemasterSerial( serial_ );
	}
	else
		socket->sysMessage( tr( "You dont own that creature." ) );
}
/*! \fn QString& cVariant::asString()

	Tries to convert the variant to hold a string value. If that
	is not possible the variant is set to an empty string.

	Returns a reference to the stored string.

	\sa toString()
*/
QString& cVariant::asString()
{
	if ( typ != StringType )
		*this = cVariant( toString() );
	return *( ( QString * ) value.ptr );
}
void cUObject::processNode( const cElement* Tag, uint /*hash*/ )
{
	QString TagName( Tag->name() );
	QString Value( Tag->value() );

	if ( TagName == "name" )
	{
		name_ = Value;
	}

	// <tag type="string"> also type="value"
	//		<key>multisection</key>
	//		<value>smallboat</value>
	// </tag>
	else if ( TagName == "tag" )
	{
		QString name = Tag->getAttribute( "name" );
		QString value = Tag->getAttribute( "value" );

		if ( !name.isNull() )
		{
			// If there is no value attribute, use the
			// tag content instead.
			if ( value.isNull() )
			{
				value = Tag->text();

				if ( value.isNull() )
				{
					value = "";
				}
			}

			QString type = Tag->getAttribute( "type", "string" );

			if ( type == "int" )
			{
				// If the value is separated by a ,
				// we assume it's a random gradient.
				// If it's separated by ; we assume it's a list of values
				// we should choose from randomly.
				int sep = value.indexOf( ',' );

				if ( sep != -1 )
				{
					int min = hex2dec( value.left( sep ) ).toInt();
					int max = hex2dec( value.mid( sep + 1 ) ).toInt();

					int value = RandomNum( min, max );
					tags_.set( name, cVariant( ( int ) value ) );
				}
				else
				{
					// Choose a random value from the list.
					if ( value.contains( ';' ) )
					{
						QStringList values = value.split( ';' );
						if ( values.size() > 0 )
						{
							value = values[RandomNum( 0, values.size() - 1 )];
						}
					}

					tags_.set( name, cVariant( hex2dec( value ).toInt() ) );
				}
			}
			else if ( type == "float" )
			{
				tags_.set( name, cVariant( value.toFloat() ) );
			}
			else
			{
				tags_.set( name, cVariant( value ) );
			}
		}
	}
	// <scripts>a,b,c</scripts>
	else if ( TagName == "scripts" )
	{
		setScriptList( Value.toLatin1() );
	}
	else
	{
		if ( Value.isEmpty() )
		{
			Value = "1";
		}
		cVariant variant( Value );
		setProperty( TagName, variant );
	}
}