@ReceiveEvent
  public void onDamaged(
      OnDamagedEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    if (characterSounds.lastSoundTime + CharacterSoundSystem.MIN_TIME < time.getGameTimeInMs()) {

      // play the sound of damage hitting the character for everyone
      DamageSoundComponent damageSounds = event.getType().getComponent(DamageSoundComponent.class);
      if (damageSounds != null && !damageSounds.sounds.isEmpty()) {
        StaticSound sound = random.nextItem(damageSounds.sounds);
        if (sound != null) {
          entity.send(new PlaySoundEvent(sound, 1f));
        }
      }

      // play the sound of a client's character being damaged to the client
      if (!characterSounds.damageSounds.isEmpty()) {
        StaticSound sound = random.nextItem(characterSounds.damageSounds);
        if (sound != null) {
          entity.send(new PlaySoundForOwnerEvent(sound, characterSounds.damageVolume));
        }
      }

      characterSounds.lastSoundTime = time.getGameTimeInMs();
      entity.saveComponent(characterSounds);
    }
  }
  /**
   * @param seed the random seed
   * @param training the training data
   */
  public TrainingGenerator(long seed, Collection<String> training) {

    this.names = Lists.newArrayList(training);
    Random random = new FastRandom(seed);

    for (int i = names.size(); i > 1; i--) {
      Collections.swap(names, i - 1, random.nextInt(i));
    }
  }
예제 #3
0
 /**
  * @param event An instance of the ActivateEvent event
  * @param entity An instance of EntityRef Deal with the real activation event (No predicted) and
  *     play a sound.
  */
 @ReceiveEvent(components = {PlaySoundActionComponent.class})
 public void onActivate(ActivateEvent event, EntityRef entity) {
   if (event.getInstigator().equals(localPlayer.getCharacterEntity())) {
     return; // owner has heard sound from prediction
   }
   PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
   StaticSound sound = random.nextItem(playSound.sounds);
   verifyAndPlaySound(event, playSound, sound);
 }
예제 #4
0
 /**
  * @param event An instance of the ActivationPredicted event
  * @param entity An instance of EntityRef Deal with the predicted activation events and play a
  *     sound.
  */
 @ReceiveEvent(components = {PlaySoundActionComponent.class})
 public void onActivationPredicted(ActivationPredicted event, EntityRef entity) {
   PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
   StaticSound sound = random.nextItem(playSound.sounds);
   if (sound != null) {
     Vector3f pos = null;
     switch (playSound.relativeTo) {
       case Target:
         pos = event.getTargetLocation();
         break;
       default:
         pos = event.getInstigatorLocation();
         break;
     }
     if (pos == null) {
       pos = event.getOrigin();
     }
     audioManager.playSound(sound, pos, playSound.volume, AudioManager.PRIORITY_NORMAL);
   }
 }
  @ReceiveEvent
  public void onCrash(
      HorizontalCollisionEvent event,
      EntityRef entity,
      CharacterSoundComponent characterSounds,
      HealthComponent healthComponent) {
    Vector3f horizVelocity = new Vector3f(event.getVelocity());
    horizVelocity.y = 0;
    float velocity = horizVelocity.length();

    if (velocity > healthComponent.horizontalDamageSpeedThreshold) {
      if (characterSounds.lastSoundTime + CharacterSoundSystem.MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = random.nextItem(characterSounds.landingSounds);
        if (sound != null) {
          entity.send(new PlaySoundEvent(sound, characterSounds.landingVolume));
          characterSounds.lastSoundTime = time.getGameTimeInMs();
          entity.saveComponent(characterSounds);
        }
      }
    }
  }
예제 #6
0
  @ReceiveEvent
  public void onActivate(
      ActivateEvent event, EntityRef entity, TunnelActionComponent tunnelActionComponent) {

    Vector3f dir = new Vector3f(event.getDirection());
    dir.scale(4.0f);
    Vector3f origin = new Vector3f(event.getOrigin());
    origin.add(dir);
    Vector3i blockPos = new Vector3i();

    int particleEffects = 0;
    int blockCounter = tunnelActionComponent.maxDestroyedBlocks;
    for (int s = 0; s <= tunnelActionComponent.maxTunnelDepth; s++) {
      origin.add(dir);
      if (!worldProvider.isBlockRelevant(origin)) {
        break;
      }

      for (int i = 0; i < tunnelActionComponent.maxRaysCast; i++) {
        Vector3f direction = random.nextVector3f();
        Vector3f impulse = new Vector3f(direction);
        impulse.scale(tunnelActionComponent.explosiveForce);

        for (int j = 0; j < 3; j++) {
          Vector3f target = new Vector3f(origin);

          target.x += direction.x * j;
          target.y += direction.y * j;
          target.z += direction.z * j;

          blockPos.set((int) target.x, (int) target.y, (int) target.z);

          Block currentBlock = worldProvider.getBlock(blockPos);

          if (currentBlock.isDestructible()) {
            if (particleEffects < tunnelActionComponent.maxParticalEffects) {
              EntityBuilder builder = entityManager.newBuilder("engine:smokeExplosion");
              builder.getComponent(LocationComponent.class).setWorldPosition(target);
              builder.build();
              particleEffects++;
            }
            if (random.nextFloat() < tunnelActionComponent.thoroughness) {
              EntityRef blockEntity = blockEntityRegistry.getEntityAt(blockPos);
              blockEntity.send(
                  new DoDamageEvent(
                      tunnelActionComponent.damageAmount, tunnelActionComponent.damageType));
            }

            blockCounter--;
          }

          if (blockCounter <= 0) {
            return;
          }
        }
      }
    }
    // No blocks were destroyed, so cancel the event
    if (blockCounter == tunnelActionComponent.maxDestroyedBlocks) {
      event.consume();
    }
  }