コード例 #1
0
  private void addGameManifestToSaveTransaction(SaveTransactionBuilder saveTransactionBuilder) {
    BlockManager blockManager = CoreRegistry.get(BlockManager.class);
    BiomeManager biomeManager = CoreRegistry.get(BiomeManager.class);
    WorldProvider worldProvider = CoreRegistry.get(WorldProvider.class);
    Time time = CoreRegistry.get(Time.class);
    Game game = CoreRegistry.get(Game.class);

    GameManifest gameManifest =
        new GameManifest(game.getName(), game.getSeed(), time.getGameTimeInMs());
    for (Module module : CoreRegistry.get(ModuleManager.class).getEnvironment()) {
      gameManifest.addModule(module.getId(), module.getVersion());
    }

    List<String> registeredBlockFamilies = Lists.newArrayList();
    for (BlockFamily family : blockManager.listRegisteredBlockFamilies()) {
      registeredBlockFamilies.add(family.getURI().toString());
    }
    gameManifest.setRegisteredBlockFamilies(registeredBlockFamilies);
    gameManifest.setBlockIdMap(blockManager.getBlockIdMap());
    List<Biome> biomes = biomeManager.getBiomes();
    Map<String, Short> biomeIdMap = new HashMap<>(biomes.size());
    for (Biome biome : biomes) {
      short shortId = biomeManager.getBiomeShortId(biome);
      String id = biomeManager.getBiomeId(biome);
      biomeIdMap.put(id, shortId);
    }
    gameManifest.setBiomeIdMap(biomeIdMap);
    gameManifest.addWorld(worldProvider.getWorldInfo());
    saveTransactionBuilder.setGameManifest(gameManifest);
  }
コード例 #2
0
  @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);
    }
  }
コード例 #3
0
 private void doDamage(
     EntityRef entity,
     int damageAmount,
     Prefab damageType,
     EntityRef instigator,
     EntityRef directCause) {
   HealthComponent health = entity.getComponent(HealthComponent.class);
   CharacterMovementComponent characterMovementComponent =
       entity.getComponent(CharacterMovementComponent.class);
   boolean ghost = false;
   if (characterMovementComponent != null) {
     ghost = (characterMovementComponent.mode == MovementMode.GHOSTING);
   }
   if ((health != null) && !ghost) {
     int damagedAmount = health.currentHealth - Math.max(health.currentHealth - damageAmount, 0);
     health.currentHealth -= damagedAmount;
     health.nextRegenTick =
         time.getGameTimeInMs() + TeraMath.floorToInt(health.waitBeforeRegen * 1000);
     entity.saveComponent(health);
     entity.send(new OnDamagedEvent(damageAmount, damagedAmount, damageType, instigator));
     if (health.currentHealth == 0 && health.destroyEntityOnNoHealth) {
       entity.send(new DestroyEvent(instigator, directCause, damageType));
     }
   }
 }
コード例 #4
0
 private void updateBreathBar(
     DrownsComponent drownsComponent, DrowningComponent drowningComponent) {
   if (drownsComponent != null && drowningComponent != null) {
     float breath = drowningComponent.getPercentageBreath(time.getGameTimeInMs());
     if (breath <= 0) {
       for (UIImage breathBubble : breathBubbles) {
         breathBubble.setVisible(true);
         breathBubble.setTextureOrigin(new Vector2f(25f, 18f));
       }
     } else {
       breath *= NUM_BUBBLE_ICONS;
       for (int i = 0; i < breathBubbles.length; ++i) {
         breathBubbles[i].setVisible(true);
         if (NUM_BUBBLE_ICONS - i - 1 < breath) {
           breathBubbles[i].setTextureOrigin(new Vector2f(16f, 18f));
         } else {
           breathBubbles[i].setTextureOrigin(new Vector2f(25f, 18f));
         }
       }
     }
   } else {
     for (UIImage breathBubble : breathBubbles) {
       breathBubble.setVisible(false);
     }
   }
 }
コード例 #5
0
 private int regenerateHealth(HealthComponent health, int healAmount) {
   int newHeal = healAmount;
   while (time.getGameTimeInMs() >= health.nextRegenTick) {
     newHeal++;
     health.nextRegenTick = health.nextRegenTick + (long) (1000 / health.regenRate);
   }
   return newHeal;
 }
コード例 #6
0
  private void signalButtonActivated(EntityRef block, SignalProducerComponent producerComponent) {
    if (block.hasComponent(SignalDelayedActionComponent.class)) {
      block.removeComponent(SignalDelayedActionComponent.class);
    }

    SignalDelayedActionComponent actionComponent = new SignalDelayedActionComponent();
    actionComponent.executeTime = time.getGameTimeInMs() + BUTTON_PRESS_TIME;
    block.addComponent(actionComponent);

    startProducingSignal(block, -1);
  }
コード例 #7
0
  @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);
        }
      }
    }
  }
コード例 #8
0
 private void deleteOldSignalChangesForGates() {
   long worldTime = time.getGameTimeInMs();
   if (lastSignalCleanupExecuteTime + SIGNAL_CLEANUP_INTERVAL < worldTime) {
     final TObjectLongIterator<ImmutableBlockLocation> iterator =
         gateLastSignalChangeTime.iterator();
     while (iterator.hasNext()) {
       iterator.advance();
       if (iterator.value() + GATE_MINIMUM_SIGNAL_CHANGE_INTERVAL < worldTime) {
         iterator.remove();
       }
     }
     lastSignalCleanupExecuteTime = worldTime;
   }
 }
コード例 #9
0
 private void signalChangedForDelayOnGate(
     EntityRef entity, SignalConsumerStatusComponent consumerStatusComponent) {
   SignalTimeDelayComponent delay = entity.getComponent(SignalTimeDelayComponent.class);
   if (consumerStatusComponent.hasSignal) {
     // Schedule for the gate to be looked at when the time passes
     SignalDelayedActionComponent delayedAction = new SignalDelayedActionComponent();
     delayedAction.executeTime = time.getGameTimeInMs() + delay.delaySetting;
     entity.addComponent(delayedAction);
   } else {
     // Remove any signal-delayed actions on the entity and turn off signal from it, if it has any
     if (entity.hasComponent(SignalDelayedActionComponent.class)) {
       entity.removeComponent(SignalDelayedActionComponent.class);
     }
     stopProducingSignal(entity);
   }
 }
コード例 #10
0
 private void delayGateSignalChangeIfNeeded(EntityRef entity) {
   if (!entity.hasComponent(SignalDelayedActionComponent.class)) {
     // Schedule for the gate to be looked either immediately (during "update" method) or at least
     // GATE_MINIMUM_SIGNAL_CHANGE_INTERVAL from the time it has last changed, whichever is later
     SignalDelayedActionComponent delayedAction = new SignalDelayedActionComponent();
     long whenToLookAt;
     final ImmutableBlockLocation location =
         new ImmutableBlockLocation(entity.getComponent(BlockComponent.class).getPosition());
     if (gateLastSignalChangeTime.containsKey(location)) {
       whenToLookAt = gateLastSignalChangeTime.get(location) + GATE_MINIMUM_SIGNAL_CHANGE_INTERVAL;
     } else {
       whenToLookAt = time.getGameTimeInMs();
     }
     delayedAction.executeTime = whenToLookAt;
     entity.addComponent(delayedAction);
   }
 }
コード例 #11
0
  private void handleDelayedActionsEvents() {
    long worldTime = time.getGameTimeInMs();
    BlockAtLocationDelayedAction action;
    while ((action = delayedActions.peek()) != null && action.executeTime <= worldTime) {
      action = delayedActions.poll();

      final Vector3i actionLocation = action.blockLocation.toVector3i();
      if (worldProvider.isBlockRelevant(actionLocation)) {
        final Block block = worldProvider.getBlock(actionLocation);
        final BlockFamily blockFamily = block.getBlockFamily();

        final EntityRef blockEntity = blockEntityRegistry.getBlockEntityAt(actionLocation);

        if (blockFamily == signalOnDelayGate) {
          startProducingSignal(blockEntity, -1);
        } else if (blockFamily == signalOffDelayGate) {
          stopProducingSignal(blockEntity);
        } else if (blockFamily == signalOrGate
            || blockFamily == signalAndGate
            || blockFamily == signalXorGate) {
          if (processOutputForNormalGate(blockEntity)) {
            gateLastSignalChangeTime.put(new ImmutableBlockLocation(actionLocation), worldTime);
          }
        } else if (blockFamily == signalNandGate) {
          if (processOutputForRevertedGate(blockEntity)) {
            gateLastSignalChangeTime.put(new ImmutableBlockLocation(actionLocation), worldTime);
          }
        } else if (blockFamily == signalSetResetGate) {
          if (processOutputForSetResetGate(blockEntity)) {
            gateLastSignalChangeTime.put(new ImmutableBlockLocation(actionLocation), worldTime);
          }
        } else if (block == signalButton) {
          stopProducingSignal(blockEntity);
        }

        blockEntity.removeComponent(SignalDelayedActionComponent.class);
      } else {
        // TODO Remove this workaround when BlockEntities will be stored with the chunk they belong
        // to
        action.executeTime += NOT_LOADED_BLOCK_RETRY_DELAY;
        delayedActions.add(action);
      }
    }
  }
コード例 #12
0
 @Override
 public String getMetrics() {
   // only update the metric a minimum once a second, cache the result
   long currentTime = time.getGameTimeInMs();
   long timeDifference = currentTime - lastTime;
   if (timeDifference >= 1000) {
     StringBuilder builder = new StringBuilder();
     builder.append(getName());
     builder.append("\n");
     builder.append(String.format("Elapsed: %dms%n", timeDifference));
     builder.append(String.format("In Msg: %d%n", networkSystem.getIncomingMessagesDelta()));
     builder.append(String.format("In Bytes: %d%n", networkSystem.getIncomingBytesDelta()));
     builder.append(String.format("Out Msg: %d%n", networkSystem.getOutgoingMessagesDelta()));
     builder.append(String.format("Out Bytes: %d%n", networkSystem.getOutgoingBytesDelta()));
     if (lastTime != 0) {
       // ignore the first update as it will not have useful data
       lastMetric = builder.toString();
     }
     lastTime = currentTime;
   }
   return lastMetric;
 }
コード例 #13
0
ファイル: UILoadBar.java プロジェクト: jinbing/Terasology
 @Override
 public void onDraw(Canvas canvas) {
   if (fillTexture != null) {
     int size = TeraMath.floorToInt(canvas.size().x * getValue());
     int barWidth = fillTexture.getWidth();
     int offset = 0;
     if (time != null && animate) {
       offset = TeraMath.floorToInt(time.getRealTimeInMs() / 10) % barWidth;
     }
     int drawnWidth = 0;
     // Draw Offset
     if (offset != 0) {
       int drawWidth = Math.min(size, offset);
       canvas.drawTextureRaw(
           fillTexture,
           Rect2i.createFromMinAndSize(0, 0, drawWidth, canvas.size().y),
           ScaleMode.STRETCH,
           barWidth - offset,
           0,
           drawWidth,
           canvas.size().y);
       drawnWidth += drawWidth;
     }
     // Draw Remainder
     while (drawnWidth < size) {
       int drawWidth = Math.min(size - drawnWidth, barWidth);
       canvas.drawTextureRaw(
           fillTexture,
           Rect2i.createFromMinAndSize(drawnWidth, 0, drawWidth, canvas.size().y),
           ScaleMode.STRETCH,
           0,
           0,
           drawWidth,
           canvas.size().y);
       drawnWidth += drawWidth;
     }
   }
 }