Пример #1
0
  /**
   * Requests a shot to be fired or not.
   *
   * @param message [0] contains the entityID of the entity that is firing [1] contains whether a
   *     shot is requested or not
   */
  private void requestFire(final Map<IPayload, String> data) {
    if (data == null || data.size() < 2) {
      return;
    }
    WeaponInfoPack wip =
        core.getInfoPackFrom(data.get(COMMAND_FIRE.ENTITY_ID), WeaponInfoPack.class);

    if (wip != null) {
      wip.setFireRequested(Boolean.parseBoolean(data.get(COMMAND_FIRE.IS_FIRE_REQUESTED)));
    }
  }
Пример #2
0
  /**
   * Fires a shot.
   *
   * @param now the current time
   * @param pack the InfoPack of the entity to fire for
   */
  private void fire(final long now, final WeaponInfoPack pack) {
    for (int shotNum = 0; shotNum < pack.getNumShots(); shotNum++) {
      int type = pack.getShotType();
      String shotType;

      switch (type) {
        case 9:
          shotType = "EXPLOSIVE";
          break;
        default:
          shotType = "BULLET";
          break;
      }
      Map<IPayload, String> parameters = new HashMap<IPayload, String>();
      parameters.put(COMMAND_CREATE.TYPE_TO_CREATE, shotType);
      parameters.put(COMMAND_CREATE.OWNER_ID, pack.getEntity().getID());
      core.send(DefaultMessage.COMMAND_CREATE, parameters);
    }
  }
Пример #3
0
  /**
   * Fires the weapon of all entities if they requested it.
   *
   * @param now the current time
   */
  public void fire(final long now) {
    Iterator<IEntity> packs = core.getEntitiesWithPack(WeaponInfoPack.class);
    WeaponInfoPack pack = core.getInfoPackOfType(WeaponInfoPack.class);

    while (packs.hasNext()) {
      if (!pack.setEntity(packs.next())) {
        continue;
      }

      if (pack.isFireRequested() || pack.isInBurst()) {
        if (now - pack.getLastFired() >= pack.getConsecutiveShotDelay()) {
          fire(now, pack);
          pack.setLastFired(now);

          if (pack.getFireMode() == FireMode.SEMI.ordinal()) {
            // Fire mode semi automatic
            pack.setFireRequested(false);
          } else if (pack.getFireMode() == FireMode.BURST.ordinal()) {
            // Fire mode burst fire
            if (pack.getShotsThisBurst() < pack.getBurstSize() - 1) {
              // If still in a burst...
              pack.setInBurst(true);
              pack.setShotsThisBurst(pack.getShotsThisBurst() + 1);
            } else { // If burst is over.
              pack.setInBurst(false);
              pack.setShotsThisBurst(0);
              pack.setLastFired(now + pack.getBurstDelay());
            }
          }
        }
      }
    }
  }