/** * 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()); } } } } } }