void atacarJack(unsigned int entityID) { Logic::CEntity * jack = Logic::CServer::getSingletonPtr()->getMap()->getEntityByID(entityID); Logic::CEntity* * entidadesColision; int numColisiones = Physics::CServer::getSingletonPtr()->detectCollisions(jack->getPosition(), 40, entidadesColision); for(int i = 0; i < numColisiones; ++i) { if (!entidadesColision[i]->getTag().compare("enemy")) { //Entidad enemiga que atacará a Jack Logic::CEntity * entidad = entidadesColision[i]; std::stringstream script; script << "enemyEvent(\"AttackJack\", " << entidad->getEntityID() << ")"; ScriptManager::CServer::getSingletonPtr()->executeScript(script.str().c_str()); Logic::MAttackEntity *message = new Logic::MAttackEntity(); message->setAttack(true); message->setEntity(jack); entidad->emitMessage(message); } } }
std::pair<CVolumetricLightScattering::ScatteringParams, bool> CVolumetricLightScattering::getClosestLightSource(const std::list<ScatteringParams>& lightList) { std::pair<ScatteringParams, bool> closestLightSrc; closestLightSrc.second = false; // Obtenemos el puntero a la entidad del jugador que en este caso es lo que nos interesa Logic::CEntity* player = Input::CServer::getSingletonPtr()->getPlayerController()->getControllerAvatar(); if(player != NULL) { Vector3 playerPosition = player->getPosition(); Vector2 playerPos2d(playerPosition.x, playerPosition.z); auto it = lightList.begin(); Vector2 pos2d(it->lightPosition.x, it->lightPosition.z); auto closestLight = it++; float closestDist = (playerPos2d - pos2d).length(); float dist; for(; it != lightList.end(); ++it) { pos2d.x = it->lightPosition.x; pos2d.y = it->lightPosition.z; dist = (playerPos2d - pos2d).length(); if(dist < closestDist) { closestLight = it; closestDist = dist; } } closestLightSrc.second = true; closestLightSrc.first = *closestLight; } return closestLightSrc; }
void enemigosContraEnemigos(unsigned int entityID) { Logic::CEntity * norah = Logic::CServer::getSingletonPtr()->getMap()->getEntityByID(entityID); Logic::CEntity* * entidadesColision; int numColisiones = Physics::CServer::getSingletonPtr()->detectCollisions( norah->getPosition(),80,entidadesColision); //Iniciamos la tabla de los enemigos afectados std::stringstream script1; script1 << "enemigosConfundidos = {}"; ScriptManager::CServer::getSingletonPtr()->executeScript(script1.str().c_str()); for(int i = 0; i < numColisiones; ++i) { if ( !entidadesColision[i]->getTag().compare("enemy") ) { //Entidad enemiga que atacara a otros enemigos Logic::CEntity * entidad = entidadesColision[i]; float distX = entidad->getPosition().x - norah->getPosition().x; float distZ = entidad->getPosition().z - norah->getPosition().z; float distance2 = distX * distX + distZ * distZ; //Solo entraran al estado los que esten a una distancia menor de 40 if (distance2 < 40 * 40) { std::stringstream script2; script2 << "enemyEvent(\"AttackOtherEnemies\", " << entidad->getEntityID() << ")"; ScriptManager::CServer::getSingletonPtr()->executeScript(script2.str().c_str()); //Mandamos un mensaje para que salga el icono de aturdido Logic::MAturdido *message = new Logic::MAturdido(); message->setAturdido(true); entidad->emitMessage(message); } //Atacaran hasta a los que esten a una distancia de 80 //Añadimos el enemigo a la tabla de los enemigos afectados entre los que se pueden atacar std::stringstream script3; script3 << "enemigosConfundidos[" << i+1 << "] = " << entidad->getEntityID(); ScriptManager::CServer::getSingletonPtr()->executeScript(script3.str().c_str()); } } }