001package com.fs.starfarer.api.impl.combat; 002 003import java.util.ArrayList; 004import java.util.Iterator; 005import java.util.List; 006 007import com.fs.starfarer.api.Global; 008import com.fs.starfarer.api.combat.CombatEngineAPI; 009import com.fs.starfarer.api.combat.DamagingProjectileAPI; 010import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin; 011import com.fs.starfarer.api.combat.OnFireEffectPlugin; 012import com.fs.starfarer.api.combat.ShipAPI; 013import com.fs.starfarer.api.combat.WeaponAPI; 014 015/** 016 * UNUSED 017 */ 018public class VPDriverEffect implements OnFireEffectPlugin, EveryFrameWeaponEffectPlugin { 019 020 public static float MIN_COOLDOWN = Global.getSettings().getFloat("minRefireDelay"); 021 public static int MAX_SHOTS = 4; 022 023 public VPDriverEffect() { 024 } 025 026 protected List<DamagingProjectileAPI> shots; 027 //protected int hits = 0; 028 public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) { 029 if (shots == null) return; 030 031// if (getWeaponEffect(weapon) == null) { 032// Global.getCombatEngine().getCustomData().put(getWeaponEffectId(weapon), this); 033// } 034 Iterator<DamagingProjectileAPI> iter = shots.iterator(); 035 while (iter.hasNext()) { 036 DamagingProjectileAPI shot = iter.next(); 037 if (shot.isExpired() || shot.isFading()) iter.remove(); 038 } 039 040 if (weapon.getCooldownRemaining() > MIN_COOLDOWN) { 041// float flightTime = weapon.getRange() / weapon.getProjectileSpeed(); 042// float fireCycle = (weapon.getCooldown() + weapon.getSpec().getChargeTime()) * getRoFMult(weapon); 043// 044// int maxShots = Math.round(flightTime / fireCycle); 045// if (maxShots < 2) maxShots = 2; 046 047 //System.out.println("MAX SHOTS: " + maxShots); 048 049 //if (shots.size() < maxShots) { 050 if (shots.size() < MAX_SHOTS) { 051 weapon.setRemainingCooldownTo(MIN_COOLDOWN); 052 } 053 } 054 } 055 056 public static float getRoFMult(WeaponAPI weapon) { 057 ShipAPI ship = weapon.getShip(); 058 if (ship == null) return 1f; 059 060 float rofMult = 1f; 061 switch (weapon.getSpec().getType()) { 062 case BALLISTIC: 063 rofMult = ship.getMutableStats().getBallisticRoFMult().getModifiedValue(); 064 break; 065 case MISSILE: 066 rofMult = ship.getMutableStats().getMissileRoFMult().getModifiedValue(); 067 break; 068 case ENERGY: 069 rofMult = ship.getMutableStats().getEnergyRoFMult().getModifiedValue(); 070 break; 071 } 072 return rofMult; 073 } 074 075 public void onFire(DamagingProjectileAPI projectile, WeaponAPI weapon, CombatEngineAPI engine) { 076 if (shots == null) { 077 shots = new ArrayList<DamagingProjectileAPI>(); 078 } 079 shots.add(0, projectile); 080 } 081 082 083// public String getWeaponEffectId(WeaponAPI weapon) { 084// String id = weapon.getShip().getId() + "_" + weapon.getSlot().getId() + "_" + weapon.getId(); 085// return id; 086//} 087//public VPDriverEffect getWeaponEffect(WeaponAPI weapon) { 088// String id = getWeaponEffectId(weapon); 089// return (VPDriverEffect) Global.getCombatEngine().getCustomData().get(id); 090//} 091} 092 093 094 095