Example #1
0
// All ai controlled creatures can be controlled by a gm
// or by their owner if tamed
void AbstractAI::onSpeechInput( P_PLAYER pTalker, const QString &comm ) {
	if (!pTalker->isGM() && (!m_npc->isTamed() || m_npc->owner() != pTalker)) {
		return;
	}

	// too far away to hear us
	if (pTalker->dist(m_npc) > 7) {
		return;
	}
	
	if (comm.contains(" FOLLOW")) {
		if (comm.contains(" ME")) {
			m_npc->setWanderFollowTarget(pTalker);
			m_npc->setWanderType(enFollowTarget);
			m_npc->bark(cBaseChar::Bark_Attacking);
		} else {
			pTalker->socket()->attachTarget(new cFollowTarget(m_npc));
		}
	} else if ((comm.contains(" KILL")) || (comm.contains(" ATTACK"))) {
		if (m_npc->inGuardedArea()) {
			pTalker->message(tr("You can't have pets attack in town!"));
		}
	} else if ((comm.contains(" FETCH")) || (comm.contains(" GET"))) {
		//pPlayer->setGuarded(false);
		// >> LEGACY
		//addx[s]=pPet->serial();
		//target(s, 0, 1, 0, 124, "Click on the object to fetch.");
	} else if (comm.contains(" COME")) {
		m_npc->setWanderDestination(pTalker->pos());
		m_npc->setWanderType(enDestination);
		m_npc->bark(cBaseChar::Bark_Attacking);
	} else if (comm.contains(" GUARD")) {
	} else if ((comm.contains(" STOP")) || (comm.contains(" STAY"))) {
		m_npc->fight(0);
		m_npc->setWanderType( enHalt );
		m_npc->bark(cBaseChar::Bark_Attacking);
	} else if (comm.contains(" TRANSFER")) {
	} else if (comm.contains(" RELEASE")) {
		// Has it been summoned ? Let's dispel it
		if (m_npc->summoned()) {
			m_npc->setSummonTime(uiCurrentTime);
		}

		m_npc->setWanderType(enFreely);
		m_npc->setOwner(0);
		m_npc->setTamed(false);
		m_npc->bark(cBaseChar::Bark_Attacking);
		if (SrvParams->tamedDisappear()) {
			m_npc->soundEffect(0x01Fe);
			cCharStuff::DeleteChar(m_npc);
		}
	}
}
void commandWhere( cUOSocket *socket, const QString &command, QStringList &args ) throw()
{
	Q_UNUSED(args);
	Q_UNUSED(command);
	P_PLAYER pChar = socket->player();

	if( !pChar )
		return;

	cTerritory *mRegion = AllTerritories::instance()->region( pChar->pos().x, pChar->pos().y, pChar->pos().map );

	QString message = tr( "You are" );

	if( mRegion )
		message.append( " " + tr( "in %1" ).arg( mRegion->name() ) );

	message.append( " " + tr( "at %1,%2,%3 on map %4" ).arg( pChar->pos().x ).arg( pChar->pos().y ).arg( pChar->pos().z ).arg( pChar->pos().map ) );
	pChar->message( message );
}
Example #3
0
// All ai controlled creatures can be controlled by a gm
// or by their owner if tamed
void AbstractAI::onSpeechInput( P_PLAYER pTalker, const QString& comm )
{
	if ( !pTalker->isGM() && ( !m_npc->isTamed() || m_npc->owner() != pTalker ) )
	{
		return;
	}

	// too far away to hear us
	if ( pTalker->dist( m_npc ) > 7 )
	{
		return;
	}

	if ( comm.contains( " FOLLOW" ) )
	{
		if ( comm.contains( " ME" ) )
		{
			m_npc->setWanderFollowTarget( pTalker );
			m_npc->setWanderType( enFollowTarget );
			m_npc->bark( cBaseChar::Bark_Attacking );
		}
		else
		{
			pTalker->socket()->attachTarget( new cFollowTarget( m_npc ) );
		}
	}
	else if ( ( comm.contains( " KILL" ) ) || ( comm.contains( " ATTACK" ) ) )
	{
		if ( m_npc->inGuardedArea() )
		{
			pTalker->message( tr( "You can't have pets attack in town!" ) );
		}
	}
	else if ( ( comm.contains( " FETCH" ) ) || ( comm.contains( " GET" ) ) )
	{
//#pragma note( Implement me )
		pTalker->message( tr( "Sorry, not implemented yet :(" ) );
	}
	else if ( comm.contains( " COME" ) )
	{
		m_npc->setWanderDestination( pTalker->pos() );
		m_npc->setWanderType( enDestination );
		m_npc->bark( cBaseChar::Bark_Attacking );
	}
	else if ( comm.contains( " GUARD" ) )
	{
	}
	else if ( ( comm.contains( " STOP" ) ) || ( comm.contains( " STAY" ) ) )
	{
		m_npc->fight( 0 );
		m_npc->setWanderType( enHalt );
		m_npc->bark( cBaseChar::Bark_Attacking );
	}
	else if ( comm.contains( " TRANSFER" ) )
	{
	}
	else if ( comm.contains( " RELEASE" ) )
	{
		// Has it been summoned ? Let's dispel it
		if ( m_npc->summoned() )
		{
			m_npc->setSummonTime( Server::instance()->time() );
		}

		m_npc->setWanderType( enFreely );
		m_npc->setOwner( 0 );
		m_npc->setTamed( false );
		m_npc->bark( cBaseChar::Bark_Attacking );
		if ( Config::instance()->tamedDisappear() )
		{
			m_npc->soundEffect( 0x01Fe );
			m_npc->remove();
		}
	}
}
Example #4
0
bool PetCommand( cUOSocket *socket, P_PLAYER pPlayer, P_NPC pPet, const QString& comm )
{
	if( pPet->owner() != pPlayer && !pPlayer->isGM() )
		return false;

	// player vendor
/*	if( pPet->npcaitype() == 17 )
		return false;*/
	
	// too far away to hear us
	if( pPlayer->dist( pPet ) > 7 )
		return false;
	
	QString petname = pPet->name();
	bool bAllCommand = false;

	if( !comm.contains( petname, false ) )
		if( comm.contains( "ALL", false ) )
			bAllCommand = true;
		else
			return false;
	
	bool bReturn = false;
	
	if( comm.contains( " FOLLOW" ) )
	{
		if( comm.contains( " ME" ) )
		{
#pragma note( "TODO: implement state change here" )
//			pPet->setWanderFollowTarget( pPlayer->serial() );
//			pPet->setWanderType( enFollowTarget );
			playmonstersound( pPet, pPet->bodyID(), SND_STARTATTACK );
		}
		else
		{
			// LEGACY: target( s, 0, 1, 0, 117, "Click on the target to follow." );
		}

		bReturn = true;
	}
	else if( ( comm.contains( " KILL" ) ) || ( comm.contains( " ATTACK" ) ) )
	{
		if( pPet->inGuardedArea() ) // Ripper..No pet attacking in town.
		{
			pPlayer->message( tr( "You can't have pets attack in town!" ) );
			return false;
		}

		//pPlayer->setGuarded( false );
		// >> LEGACY
		//addx[s]=pPet->serial();
		//target(s, 0, 1, 0, 118, "Select the target to attack.");//AntiChrist
		bReturn = true;
	}
	else if( ( comm.contains( " FETCH" ) ) || ( comm.contains( " GET" ) ) )
	{
		//pPlayer->setGuarded(false);
		// >> LEGACY
		//addx[s]=pPet->serial();
		//target(s, 0, 1, 0, 124, "Click on the object to fetch.");
		bReturn = true;
	}
	else if( comm.contains( " COME" ) )
	{
		//pPlayer->setGuarded( false );
#pragma note( "TODO: implement state change here" )
//		pPet->setWanderFollowTarget( pPlayer->serial() );
//		pPet->setWanderType( enFollowTarget );
		pPet->setNextMoveTime();
		pPlayer->message( tr( "Your pet begins following you." ) );
		bReturn = true;
	}
	else if( comm.contains( " GUARD" ) )
	{
		// LEGACY
		/*addx[s] = pPet->serial();	// the pet's serial
		addy[s] = 0;

		if( comm.find( " ME" ) != string::npos )
			addy[s]=1;	// indicates we already know whom to guard (for future use)
		
		// for now they still must click on themselves (Duke)
		target(s, 0, 1, 0, 120, "Click on the char to guard.");*/
		bReturn = true;
	}
	else if( ( comm.contains( " STOP" ) ) || ( comm.contains(" STAY") ) )
	{
		//pPlayer->setGuarded( false );
#pragma note( "TODO: implement state change here" )
//		pPet->setWanderFollowTarget( INVALID_SERIAL );
		pPet->setCombatTarget( INVALID_SERIAL );

		if (pPet->isAtWar()) 
			pPet->toggleCombat();

		pPet->setWanderType( enHalt );
		bReturn = true;
	}
	else if( comm.contains( " TRANSFER" ) )
	{
		//pPlayer->setGuarded( false );
		// >> LEGACY
		/*addx[s]=pPet->serial();
		target(s, 0, 1, 0, 119, "Select character to transfer your pet to.");*/
		bReturn = true;
	}
	else if( comm.contains( " RELEASE" ) )
	{
		//pPlayer->setGuarded( false );

		// Has it been summoned ? Let's dispel it
		if( pPet->summonTime() > uiCurrentTime )
			pPet->setSummonTime( uiCurrentTime );

#pragma note( "TODO: implement state change here" )
//		pPet->setWanderFollowTarget( INVALID_SERIAL );
		pPet->setWanderType( enFreely );
		pPet->setOwner( NULL );
		pPet->setTamed( false );
		pPet->emote( tr( "%1 appears to have decided that it is better off without a master" ).arg( pPet->name() ) );
		if( SrvParams->tamedDisappear() ==1 )
		{
			pPet->soundEffect( 0x01FE );
			cCharStuff::DeleteChar( pPet );
		}
		bReturn = true;
	}

	// give other pets opotunity to process command
	if ( bReturn && bAllCommand )
		return false; 
	else
		return bReturn;
}
Example #5
0
void cSkills::SkillUse( cUOSocket* socket, Q_UINT16 id ) // Skill is clicked on the skill list
{
	P_PLAYER pChar = socket->player();

	// No Char no Skill use
	if ( !pChar )
		return;

	/* TODO: reimplementation of jail system
		if( pChar->cell() > 0 )
		{
			socket->sysMessage( tr( "You are in jail and cant use skills here!" ) );
			return;
		}
	*/

	if ( pChar->isDead() )
	{
		socket->sysMessage( tr( "You cannot do that as a ghost." ) );
		return;
	}

	if ( id != STEALTH )
		pChar->unhide(); // Don't unhide if we're trying to stealth

	pChar->disturbMed(); // Disturb meditation if we're using a skill

	if ( pChar->isCasting() )
	{
		socket->sysMessage( tr( "You can't do that while you are casting." ) );
		return;
	}

	if ( pChar->skillDelay() > Server::instance()->time() && !pChar->isGM() )
	{
		socket->sysMessage( tr( "You must wait a few moments before using another skill." ) );
		return;
	}

	if ( pChar->onSkillUse( id ) )
		return;

	cTargetRequest* targetRequest = NULL;
	QString message;

	switch ( id )
	{
	case MEDITATION:
		Skills::instance()->Meditation( socket );
		break;
	default:
		socket->sysMessage( tr( "That skill has not been implemented yet." ) );
		return;
	}

	if ( targetRequest )
		socket->attachTarget( targetRequest );

	if ( !message.isEmpty() )
		pChar->message( message );

	pChar->setSkillDelay( Server::instance()->time() + Config::instance()->skillDelay() * MY_CLOCKS_PER_SEC );
}
void cNewMagic::castSpell( P_PLAYER pMage, UINT8 spell )
{
	P_PLAYER pp = dynamic_cast<P_PLAYER>(pMage);

	if( !pp || !pp->socket() )
		return;

	stNewSpell *sInfo = findSpell( spell );

	if( !sInfo )
	{
		pp->socket()->sysMessage( tr( "This spell is either not implemented or invalid" ) );
		return;
	}

	// Check if we can cast this spell
	if( !hasSpell( pMage, spell ) )
	{
		pp->socket()->sysMessage( tr( "You don't know this spell." ) );
		return;
	}

	// Check for required mana and required reagents, if not present: cancel casting
	if( !checkMana( pMage, spell ) )
	{
		pp->message( tr( "You don't have enough mana to cast this spell." ) );
		return;
	}
	
	if( !pp->isGM() && !checkReagents( pMage, spell ) )
		return;

	if( pMage->isCasting() )
		disturb( pMage, true );

	// We start casting here
	pMage->setCasting( true );

	// We get frozen here too
	pMage->setFrozen( true );

	// Say the mantra
	// Type 0x0A : Spell
	pMage->talk( sInfo->mantra, pMage->saycolor() );

	// This is a very interesting move of OSI 
	// They send all action-packets the character has to perform in a row. 
	// But they use the action 0xE9 instead of 0x10, maybe it's a bitmask 
	// of 0xD9 but i am unsure. 
	// This will repeat the animation until
	// We are done casting or until we are being
	// disturbed.
	//pMage->startRepeatedAction( sInfo->action, sInfo->actiondelay ); // Repeat every 1250 ms
	// I *do* know that this is a drawback but for now a single animation is exactly what we need.
	pMage->action( sInfo->action );

	// Now we have to do the following: 
	// We show the target cursor after a given amount of time (set in the scripts)
	// So what we are adding here is cEndCasting() supplying the Serial of our Mage 
	// And the ID of our Spell.
	TempEffects::instance()->insert( new cEndCasting( pMage, spell, CT_BOOK, sInfo->delay ) );
}
/*!
	Just like useReagents this function is checking 
	for required reagents on a characater to cast a 
	spell. But unlike useReagents it wont really 
	consume the reagents but just return false if 
	the required reagents are not present.
*/
bool cNewMagic::checkReagents( P_CHAR pMage, UINT8 spell )
{
	// Check for each reagent.
	// So we dont need to loop trough all items over and over again we'll use ONE loop (will be a bit less clean)
	P_ITEM pPack = pMage->getBackpack();

	stNewSpell *sInfo = findSpell( spell );
	UINT8 ginseng = sInfo->reagents.ginseng;
	UINT8 bloodmoss = sInfo->reagents.bloodmoss;
	UINT8 mandrake = sInfo->reagents.mandrake;
	UINT8 blackpearl = sInfo->reagents.blackpearl;
	UINT8 spidersilk = sInfo->reagents.spidersilk;
	UINT8 garlic = sInfo->reagents.garlic;
	UINT8 nightshade = sInfo->reagents.nightshade;
	UINT8 sulfurash = sInfo->reagents.sulfurash;

	QPtrList< cItem > content = pPack->getContainment();

	for( P_ITEM pItem = content.first(); pItem; pItem = content.next() )
	{
		checkReagent( blackpearl, 0xF7A )
		else checkReagent( bloodmoss, 0xF7B )
		else checkReagent( garlic, 0xF84 )
		else checkReagent( ginseng, 0xF85 )
		else checkReagent( mandrake, 0xF86 )
		else checkReagent( nightshade, 0xF88 )
		else checkReagent( sulfurash, 0xF8C )
		else checkReagent( spidersilk, 0xF8D )		
	}

	QStringList missing;

	if( ginseng > 0 )
		missing.append( tr( "Ginseng" ) );
	if( bloodmoss > 0 )
		missing.append( tr( "Bloodmoss" ) );
	if( mandrake > 0 )
		missing.append( tr( "Mandrake" ) );
	if( blackpearl > 0 )
		missing.append( tr( "Black Pearls" ) );
	if( spidersilk > 0 )
		missing.append( tr( "Spider's Silk" ) );
	if( garlic > 0 )
		missing.append( tr( "Garlic" ) );
	if( nightshade > 0 )
		missing.append( tr( "Nightshade" ) );
	if( sulfurash > 0 )
		missing.append( tr( "Sulfurous Ash" ) );

	bool enoughReagents = true;

	if( missing.count() > 0 )
	{
		if( pMage->objectType() == enPlayer )
		{
			P_PLAYER pp = dynamic_cast<P_PLAYER>(pMage);
			if( pp->socket() )
			{
				pp->message( tr( "You don't have enough reagents." ) );
				pp->socket()->sysMessage( tr( "You lack the following reagents: %1" ).arg( missing.join( ", ") ) );
			}
		}
		enoughReagents = false;
	}

	return enoughReagents;
}
Example #8
0
void cSkills::SkillUse( cUOSocket* socket, quint16 id ) // Skill is clicked on the skill list
{
	P_PLAYER pChar = socket->player();

	// No Char no Skill use
	if ( !pChar )
		return;

	if ( pChar->isJailed() ) {
		socket->sysMessage( tr("You cannot use skills while you are in jail.") );
		return;
	}

	if ( pChar->isDead() )
	{
		socket->clilocMessage( 1019048 ); // I am dead and cannot do that.
		return;
	}

	/*
	if ( id != STEALTH )
		pChar->unhide(); // Don't unhide if we're trying to stealth
	*/

	pChar->disturbMed(); // Disturb meditation if we're using a skill

	if ( pChar->isCasting() )
	{
		socket->sysMessage( 1061131 ); // You cannot do that while casting a spell.
		return;
	}

	if ( pChar->skillDelay() > Server::instance()->time() && !pChar->isGM() )
	{
		socket->sysMessage( 500118 ); // You must wait a few moments to use another skill.
		return;
	}

	if ( pChar->onSkillUse( id ) )
		return;

	cTargetRequest* targetRequest = NULL;
	QString message;

	switch ( id )
	{
	case MEDITATION:
		Skills::instance()->Meditation( socket );
		break;
	default:
		socket->sysMessage( tr( "That skill has not been implemented yet." ) );
		return;
	}

	if ( targetRequest )
		socket->attachTarget( targetRequest );

	if ( !message.isEmpty() )
		pChar->message( message );

	pChar->setSkillDelay( Server::instance()->time() + Config::instance()->skillDelay() * MY_CLOCKS_PER_SEC );
}