Beispiel #1
0
void Actor::onCreatureFound(Creature* creature, bool pushFront /*= false*/)
{
  if(isFriend(creature)){
    assert(creature != this);
    if(std::find(friendList.begin(), friendList.end(), creature) == friendList.end()){
      creature->addRef();
      friendList.push_back(creature);
    }
  }

  if(isOpponent(creature)){
    assert(creature != this);
    if(std::find(targetList.begin(), targetList.end(), creature) == targetList.end()){
      creature->addRef();
      if(pushFront){
        targetList.push_front(creature);
      }
      else{
        targetList.push_back(creature);
      }
    }
  }

  updateIdleStatus();
}
Beispiel #2
0
void Actor::onCreatureConvinced(const Creature* convincer, const Creature* creature)
{
  if(convincer != this && (isFriend(creature) || isOpponent(creature))){
    updateTargetList();
    updateIdleStatus();
  }
}
Beispiel #3
0
void Client::startConversation(const std::string& playerName) const
{
	// rest assured the client is connected to a server before trying to access it
	if(!_isConnected)
		throw NotConnectedException("not connected.");
	else if(!_userTerminal.hasKnownTerminal())
		throw std::runtime_error("no known terminal.");
	else if(playerName == _name)
		throw std::runtime_error("chatting with yourself is not allowed.");
	else if(!isFriend(playerName))
		throw std::runtime_error("you are only allowed to chat with your friends.");
	std::string cmd
	{
		_userTerminal.startProgram(
		"WizardPoker_chat",
		{
			"caller",  // parameter 1 is caller/callee
			_serverAddress.toString(),  // parameter 2 is the address to connect to
			std::to_string(_serverPort),  // parameter 3 is the port to connect to
			_name,  // parameter 4 is caller's name
			playerName, // parameter 5 is callee's name
			(_isGui ? "gui" : "terminal")
			// there is not more parameters!
		},
		not _isGui)
	};
	system(cmd.c_str());
}
Beispiel #4
0
void Monster::onCreatureConvinced(const Creature* convincer, const Creature* creature)
{
	if(convincer == this || (!isFriend(creature) && !isOpponent(creature)))
		return;

	updateTargetList();
	updateIdleStatus();
}
Beispiel #5
0
void PlayersListModel::checkFriendIgnore(const QModelIndex &mi)
{
    setData(mi, isFriend(mi.data().toString()), Friend);
    setData(mi, isIgnored(mi.data().toString()), Ignore);

    updateIcon(mi);
    updateSortData(mi);
}
QList<ServerPlayer *> AI::getFriends() const{
    QList<ServerPlayer *> players = room->getOtherPlayers(self);
    QList<ServerPlayer *> friends;
    foreach (ServerPlayer *p, players)
        if (isFriend(p)) friends << p;

    return friends;
}
Beispiel #7
0
const Card *TrustAI::askForPindian(ServerPlayer *requestor, const QString &)
{
    QList<const Card *> cards = self->getHandcards();
    qSort(cards.begin(), cards.end(), CompareByNumber);

    if (requestor != self && isFriend(requestor))
        return cards.first();
    else
        return cards.last();
}
void Monster::onCreatureConvinced(const Creature* convincer, const Creature* creature)
{
	if(convincer != this && (isFriend(creature) || isOpponent(creature))){
		updateTargetList();
		updateIdleStatus();
	}
	#ifdef __MIN_PVP_LEVEL_APPLIES_TO_SUMMONS__
	g_game.forceClientsToReloadCreature(creature);
	#endif
}
Beispiel #9
0
void Monster::onCreatureFound(Creature* creature, bool pushFront/* = false*/)
{
	if (isFriend(creature)) {
		addFriend(creature);
	}

	if (isOpponent(creature)) {
		addTarget(creature, pushFront);
	}

	updateIdleStatus();
}
Beispiel #10
0
const Card *TrustAI::askForPindian(ServerPlayer *requestor, const QString &reason) {
    QList<const Card *> cards = self->getHandcards();
    qSort(cards.begin(), cards.end(), CompareByNumber);

    // zhiba special case
    if (reason == "zhiba_pindian" && self->hasLordSkill("sunce_zhiba"))
        return cards.last();

    if (requestor != self && isFriend(requestor))
        return cards.first();
    else
        return cards.last();
}
Beispiel #11
0
bool PlayersListModel::isFlagSet(const QString & nickname, StateFlag flagType)
{
    QModelIndex mi = nicknameIndex(nickname);

    if(mi.isValid())
        return mi.data(flagType).toBool();
    else if(flagType == Friend)
        return isFriend(nickname);
    else if(flagType == Ignore)
        return isIgnored(nickname);
    else
        return false;
}
Beispiel #12
0
void Monster::onCreatureLeave(Creature* creature)
{
#ifdef __DEBUG__
	std::clog << "onCreatureLeave - " << creature->getName() << std::endl;
#endif
	if(isSummon() && master == creature)
	{
		if(!g_config.getBool(ConfigManager::TELEPORT_SUMMONS) && (!master->getPlayer()
			|| !g_config.getBool(ConfigManager::TELEPORT_PLAYER_SUMMONS)))
		{
			//Turn the monster off until its master comes back
			isMasterInRange = false;
			updateIdleStatus();
		}
		else if(!doTeleportToMaster())
			teleportToMaster = true;
	}

	//update friendList
	if(isFriend(creature))
	{
		CreatureList::iterator it = std::find(friendList.begin(), friendList.end(), creature);
		if(it != friendList.end())
		{
			(*it)->unRef();
			friendList.erase(it);
		}
#ifdef __DEBUG__
		else
			std::clog << "Monster: " << creature->getName() << " not found in the friendList." << std::endl;
#endif
	}

	//update targetList
	if(isOpponent(creature))
	{
		CreatureList::iterator it = std::find(targetList.begin(), targetList.end(), creature);
		if(it != targetList.end())
		{
			(*it)->unRef();
			targetList.erase(it);
			if(targetList.empty())
				updateIdleStatus();
		}
#ifdef __DEBUG__
		else
			std::clog << "Player: " << creature->getName() << " not found in the targetList." << std::endl;
#endif
	}
}
Beispiel #13
0
void Client::removeFriend(const std::string& name)
{
	if(!_isConnected)
		throw NotConnectedException("unable to remove friend.");
	if(!isFriend(name))
		throw std::runtime_error(name + "is not a friend of yours.");
	sf::Packet packet;
	// send that the user remove name from its friend list
	packet << TransferType::REMOVE_FRIEND;
	packet << name;
	_socket.send(packet);
	_socket.receive(packet);
	TransferType responseHeader;
	packet >> responseHeader;
	if(responseHeader != TransferType::ACKNOWLEDGE)
		throw std::runtime_error("failed to remove " + name + " from your friend list.");
}
Beispiel #14
0
void Monster::onCreatureLeave(Creature* creature)
{
	// std::cout << "onCreatureLeave - " << creature->getName() << std::endl;

	if(getMaster() == creature)
	{
		//Turn the monster off until its master comes back
		isMasterInRange = false;
		updateIdleStatus();
	}

	//update friendList
	if(isFriend(creature))
	{
		CreatureList::iterator it = std::find(friendList.begin(), friendList.end(), creature);
		if(it != friendList.end())
		{
			(*it)->releaseThing2();
			friendList.erase(it);
		}
#ifdef __DEBUG__
		else
			std::cout << "Monster: " << creature->getName() << " not found in the friendList." << std::endl;
#endif
	}

	//update targetList
	if(isOpponent(creature))
	{
		CreatureList::iterator it = std::find(targetList.begin(), targetList.end(), creature);
		if(it != targetList.end())
		{
			(*it)->releaseThing2();
			targetList.erase(it);
			if(targetList.empty())
				updateIdleStatus();
		}
#ifdef __DEBUG__
		else
			std::cout << "Player: " << creature->getName() << " not found in the targetList." << std::endl;
#endif
	}
}
Beispiel #15
0
void NounStructure::inflictDamage( dword nWhen, Noun * pFrom, int damage, dword type, const Vector3 & direction )
{
	// don't allow more damage than possible
	int possible = maxDamage() - m_Damage;
	if ( damage > possible )
		damage = possible;

	if ( pFrom != NULL)
	{
		float ratio = float( damage ) / maxDamage();
		if ( isFriend( pFrom ) )
			gameContext()->gameUser()->onFriendlyFire( pFrom, ratio );
		else
			gameContext()->gameUser()->onPlanetsDamaged( pFrom, ratio );
	}

	m_Damage += damage;
	if ( isServer() && m_Damage >= maxDamage() )
		Verb::Ref( new VerbDestroyStructure( this, pFrom ) );
}
Beispiel #16
0
void Client::sendFriendshipRequest(const std::string& name)
{
	if(!_isConnected)
		throw NotConnectedException("unable to ask a new friend.");
	// Cannot be friend with yourself
	if(name == _name)
		throw std::runtime_error("can't be friend with yourself.");
	// Don't ask a friend to become your friend
	if(isFriend(name))
		throw std::runtime_error(name + "is already your friend.");
	sf::Packet packet;
	packet << TransferType::NEW_FRIEND << name;
	_socket.send(packet);
	// server acknowledges with ACKNOWLEDGE if request was correctly made and by NOT_EXISTING_FRIEND otherwise
	_socket.receive(packet);
	TransferType responseHeader;
	packet >> responseHeader;
	if(responseHeader != TransferType::ACKNOWLEDGE)
		throw std::runtime_error("failed to send a request to " + name + ".");
}
Beispiel #17
0
void Monster::onCreatureLeave(Creature* creature)
{
	// std::cout << "onCreatureLeave - " << creature->getName() << std::endl;

	if (getMaster() == creature) {
		//Take random steps and only use defense abilities (e.g. heal) until its master comes back
		isMasterInRange = false;
	}

	//update friendList
	if (isFriend(creature)) {
		removeFriend(creature);
	}

	//update targetList
	if (isOpponent(creature)) {
		removeTarget(creature);
		if (targetList.empty()) {
			updateIdleStatus();
		}
	}
}
Beispiel #18
0
void NounShip::updateFireCheck()
{
	if ( userId() == 0 && isLocal() && m_Command == ENGAGE && m_CommandTarget.valid() )
	{
		dword nNextFireCheck = m_nLastFireCheck + (CHECK_FIRE_INTERVAL * TICKS_PER_SECOND);
		if ( tick() > nNextFireCheck  )
		{
			m_nLastFireCheck = tick();
			m_pLastFireTarget = m_CommandTarget;
			m_fLastFireDistance = (m_CommandTarget->worldPosition() - worldPosition()).magnitude();

			CollisionInfo info;
			if ( checkForCollision( m_CommandTarget, &info, false ) )
			{
				if ( WidgetCast<NounShip>( info.m_pCollide ) == NULL || isFriend( info.m_pCollide ) )
					m_bWeaponsFree = false;		// something is in the way, no firing unless it's a enemy ship ..
				else
					m_bWeaponsFree = true;
			}
			else
				m_bWeaponsFree = true;		// no collision, allow firing...
		}
	}
}
Beispiel #19
0
void NounShip::inflictDamage( dword nWhen, Noun * pFrom, int damage, dword type, const Vector3 & direction )
{
	if ( isDestroyed() )		// don't bother if ship is already destroyed!
		return;

	// only increase timer if an enemy is attacking us - we don't want to promote griefing
	if ( isEnemy( pFrom ) )
		setOutOfCombat(); // update combat timer

	// if we are not the server, then halve the damage applied to avoid over estimatation the damage we are
	// inflicting on another ship.. 
	if (! isServer() )
		damage = damage * CLIENT_SIDE_DAMAGE;

	Facing eFacing = getFacing( atan2( direction.x, direction.z ), false );

	// apply any damage modifiers
	damage = damage * calculateModifier( MT_DAMAGE_REDUCTION, true );

	LOG_DEBUG_LOW( "NounShip", CharString().format("Damaged inflicted, When: %u, From: %s, Damage: %d, Type: 0x%X, Facing: %u", 
		nWhen, pFrom != NULL ? pFrom->name() : "NULL", damage, type, eFacing) );

	// callback so AI controlled ships can receive notification that they have been damaged by someone
	onAttacked( pFrom, damage, type );

	// calculate the points we're going to award to the attacker now before shields/armor reduce 
	// the damage applied to the hull.
	float fDamagePoints = float( damage ) / DAMAGE_POINTS_DIV; 

	// check shields
	if( damage > 0 )
	{	
		for(int i=0;i<m_Shields.size();i++)
			damage = m_Shields[i]->deflect( type, damage, eFacing, direction );
	}

	// check armor
	if ( damage > 0 )
	{
		for(int i=0;i<m_Armor.size();i++)
			damage = m_Armor[i]->deflect( type, damage, eFacing );
	}

	int internalDamage = damage;

	// inflict internal damage if hull is 50% or less
	int halfHull = maxDamage() >> 1;
	if ( damage > 0 && m_Damage > halfHull && (type & DAMAGE_EMP) == 0 )
	{
		// once hull is under 50%, start causing internal damage
		type |= DAMAGE_EMP;
		// scale internal damage up based on how much under 50% the hull 
		internalDamage = (damage * (m_Damage - halfHull)) / halfHull;
	}

	if ( damage > 0 && (type & (DAMAGE_EMP|DAMAGE_ELF)) )
	{
		// get the radius of this ship
		float myRadius = radius();
		ASSERT( myRadius > 0.0f );

		// calculate the hit position in object space of this ship
		Vector3 hitPosition( direction );
		hitPosition.normalize();				// direction is not normalized, it's the delta from the projectile/explosion, to the center of the ship
		hitPosition *= -(myRadius * 0.5f);		// flip the direction so it goes away from the center of the ship

		if ( isServer() && m_Gadgets.size() > 0 )
		{
			// seed with the time-stamp of the damage so we get the same gadget damaged
			// on all clients.
			srand( nWhen );
			int nPicked = rand() % m_Gadgets.size();

			NounGadget * pDamageGadget = m_Gadgets[ nPicked ];
			if ( pDamageGadget != NULL )
			{
				float fDistance = (pDamageGadget->position() - hitPosition).magnitude();
				float fScale = (1.0f - (fDistance / myRadius));

				if ( fScale > 0.0f )
					pDamageGadget->inflictDamage( nWhen, pFrom, fScale * internalDamage, type, direction );
			}
		}
	}

	if ( damage > 0 && (type & DAMAGE_ELF) )
	{
		// drain energy from main energy bank
		int drained = Min( energy(), damage );
		setEnergy( energy() - drained );

		// give energy to attacking ship
		if ( WidgetCast<NounShip>( pFrom ) )
			((NounShip *)pFrom)->setEnergy( ((NounShip *)pFrom)->energy() + drained );
	}

	// update the stats if it is another ship - NOTE this needs to happen before the DestroyShip
	// code below otherwise a player who is damaging this ship may not get credit/loot.
	if ( WidgetCast<NounShip>( pFrom ) )
	{
		NounShip * pFromShip = (NounShip *)pFrom;
		ASSERT( pFromShip );

		// set combat timer on attacking ship
		pFromShip->setOutOfCombat();

		// non-hull damages gives a lessor percentage of points..
		if ( damage <= 0 )
			fDamagePoints *= NOHULL_DAMAGE_POINTS_SCALE;

		if (! isFriend( pFrom ) )
		{
			// if the attacking ship is destroyed, then treat this as kamikaze points
			if ( pFromShip->isDestroyed() )
				gameContext()->gameUser()->onKamikaze( pFrom, 1.0f );
			else
				gameContext()->gameUser()->onDamageShip( pFrom, fDamagePoints, this);
		}
		else
		{
			gameContext()->gameUser()->onFriendlyFire( pFrom, fDamagePoints );
		}
	}

	if ( damage > 0 && (type & (DAMAGE_KINETIC|DAMAGE_ENERGY)) )
	{
		ASSERT( context() );

		// cap the damage, 
		damage = Min( maxDamage() - m_Damage, damage );

		// add the damage to the hull
		m_Damage = Min( m_Damage + damage, maxDamage() );
		// update the damage bits
		updateDamageBits();

		// check if the ship was destroyed
		if ( isServer() && isDestroyed() )
		{
			// ship is destroyed, send out verb to destroy this ship to all local clients
			Verb::Ref( new VerbDestroyShip( this, pFrom, false ) );
		}
	}
}
Beispiel #20
0
//adds a friend to friend list of user
void User::addFriend(string nameIn)//
{
    //add friend IFF friend is not already in friendsList
    if (!isFriend(nameIn))
    friendsList.push_back(nameIn);
}
bool GadgetBeamWeapon::updateLogic()
{
	if ( useActive() || usableWhen() > 0 )
		return true;		// early out if not ready to fire or currently in use...

	if ( WidgetCast<NounShip>( parent() ) )
	{
		NounShip * pShip = (NounShip *)parent();
		
		// turn on point defense if not on already...
		if ( !pointDefense() && type() != WEAPON_BOMB && allowPointDefense() )
			setPointDefense( true );

		NounGame * pTarget = WidgetCast<NounGame>( pShip->commandTarget() );
		if (! pTarget )
			return true;	// no current target
		if ( pTarget != pShip->lastFireTarget() || !pShip->isWeaponsFree() )
			return true;	// can't hit target
		if ( isFriend( pTarget ) )
			return true;	// don't attack friendly targets
		if( WidgetCast<NounJumpGate>( pTarget ) 
			|| WidgetCast<CargoResource>( pTarget ) )
			return true;	// don't attack jump gates or resources
		if (! pTarget->canDamage( damageType() ) )
			return true;	// can't damage this target, so don't use this weapon
		if ( type() == WEAPON_BOMB && WidgetCast<NounPlanet>( pTarget ) == NULL )
			return true;	// only use bomb weapons on planets..

		if ( usable( pTarget, false ) )
			pShip->useGadget( this, pTarget, false );
	}
	else if ( WidgetCast<StructureDefense>( parent() ) )
	{
		StructureDefense * pStructure = (StructureDefense *)parent();
		if (! pStructure->active() )
			return true;
		NounPlanet * pPlanet = pStructure->planet();
		if (! pPlanet )
			return false;

		Noun *	pBestTarget = NULL;
		float	fBestRange = 0.0f;;

		// look for incoming enemy projectiles, pick the best target
		for(int j=0;j<pPlanet->contactCount();j++)
		{
			NounGame * pContact = WidgetCast<NounGame>( pPlanet->contact( j ) );
			if ( pContact != NULL && pContact->enablePD() && !pPlanet->isFriend( pContact ) )
			{
				float fRange = (worldPosition() - pContact->worldPosition()).magnitude();
				if ( (!pBestTarget || fRange < fBestRange) && usable( pContact, false ) 
					&& !StructureDefense::isTargeted( pPlanet, pContact) )
				{
					pBestTarget = pContact;
					fBestRange = fRange;
				}
			}
		}

		if ( pBestTarget )
		{
			// set the target now, so no other beam weapon tries to destroy the projectile
			setTarget( pBestTarget );
			// use the beam weapon on the projectile
			pStructure->useGadget( pBestTarget, this );
			return true;
		}

		for(int j=0;j<pPlanet->contactCount();j++)
		{
			NounShip * pShip = WidgetCast<NounShip>( pPlanet->contact( j ) );
			if ( pShip != NULL && pPlanet->isEnemy( pShip ) )
			{
				float fRange = (worldPosition() - pShip->worldPosition()).magnitude();
				if ( (!pBestTarget || fRange < fBestRange) && usable( pShip, false ) )
				{
					pBestTarget = pShip;
					fBestRange = fRange;
				}
			}
		}

		if ( pBestTarget != NULL )
			pStructure->useGadget( pBestTarget, this );

		return true;
	}

	return false;
}