Esempio n. 1
0
	void CIARunAway::process(const std::shared_ptr<Logic::IMessage> &message)
	{

		if (message->getType() == "CHANGE_TARGET")
		{
			CEntity* ent = dynamic_cast<CHANGE_TARGET*>(message.get())->getLogicEntity();
			if(ent != NULL)
			{
				if(!ent->getIsDead())
				{
					_target = ent; 
					if (_target->getCenterPosition().x > _entity->getCenterPosition().x)
					{
						_direction = -1;
					}
					else
					{
						_direction = 1;
					}
						
					std::shared_ptr<Logic::TURN> m(new Logic::TURN());
					m->setInt(_direction);
					_entity->emitMessage(m);
				}
			}  

			
		}
	} // process
Esempio n. 2
0
void CIADodge::process(const std::shared_ptr<Logic::IMessage> &message)
{
    if(message->getType() == "DAMAGED")
    {
        // Si no está esquivando....
        if (!_initIA && _canIA)
        {
            // Comprobamos primero si el enemigo está cerca del personaje
            Vector3 dist = _target->getCenterPosition() - _entity->getCenterPosition();
            float distLength = dist.length();

            if (distLength < _rangeDetect)
            {
                // Comprobamos si el aleatorio es un % viable
                int random = rand()% 101;

                if (random <= _successPercent)
                {
                    _initIA = true;

                    std::shared_ptr<CAN_MOVE> m(new CAN_MOVE);
                    m->setBool(false);
                    _entity->emitMessage(m);
                }
            }
        }

        // Si sigue sin activarse la IA (es decir, no se cumplen las condiciones), restamos vida al enemigo.
        if (!_initIA || !_canIA)
        {
            CLifeEnemy* compLife = (CLifeEnemy*)_entity->getComponent("CLifeEnemy");

            if (!compLife->getInvincible())
            {
                compLife->damageEntity(dynamic_cast<DAMAGED*>(message.get())->getFloat(),
                                       dynamic_cast<DAMAGED*>(message.get())->getString());
            }
        }
    }

    else if(message->getType().compare("FALLING") == 0)
    {
        _isFalling = dynamic_cast<FALLING*>(message.get())->getBool();
    }

    else if (message->getType() == "CHANGE_TARGET")
    {
        CEntity* ent = dynamic_cast<CHANGE_TARGET*>(message.get())->getLogicEntity();
        if(ent != NULL)
        {
            if(!ent->getIsDead())
            {
                _target = ent;
            }
        }
    }

    else if (message->getType() == "CAN_IA")
    {
        _canIA = dynamic_cast<CAN_IA*>(message.get())->getBool();
    }
} // process