Starsector API
Loading...
Searching...
No Matches
VPDriverEffect.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat;
2
3import java.util.ArrayList;
4import java.util.Iterator;
5import java.util.List;
6
7import com.fs.starfarer.api.Global;
8import com.fs.starfarer.api.combat.CombatEngineAPI;
9import com.fs.starfarer.api.combat.DamagingProjectileAPI;
10import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
11import com.fs.starfarer.api.combat.OnFireEffectPlugin;
12import com.fs.starfarer.api.combat.ShipAPI;
13import com.fs.starfarer.api.combat.WeaponAPI;
14
18public class VPDriverEffect implements OnFireEffectPlugin, EveryFrameWeaponEffectPlugin {
19
20 public static float MIN_COOLDOWN = Global.getSettings().getFloat("minRefireDelay");
21 public static int MAX_SHOTS = 4;
22
23 public VPDriverEffect() {
24 }
25
26 protected List<DamagingProjectileAPI> shots;
27 //protected int hits = 0;
28 public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
29 if (shots == null) return;
30
31// if (getWeaponEffect(weapon) == null) {
32// Global.getCombatEngine().getCustomData().put(getWeaponEffectId(weapon), this);
33// }
34 Iterator<DamagingProjectileAPI> iter = shots.iterator();
35 while (iter.hasNext()) {
36 DamagingProjectileAPI shot = iter.next();
37 if (shot.isExpired() || shot.isFading()) iter.remove();
38 }
39
40 if (weapon.getCooldownRemaining() > MIN_COOLDOWN) {
41// float flightTime = weapon.getRange() / weapon.getProjectileSpeed();
42// float fireCycle = (weapon.getCooldown() + weapon.getSpec().getChargeTime()) * getRoFMult(weapon);
43//
44// int maxShots = Math.round(flightTime / fireCycle);
45// if (maxShots < 2) maxShots = 2;
46
47 //System.out.println("MAX SHOTS: " + maxShots);
48
49 //if (shots.size() < maxShots) {
50 if (shots.size() < MAX_SHOTS) {
51 weapon.setRemainingCooldownTo(MIN_COOLDOWN);
52 }
53 }
54 }
55
56 public static float getRoFMult(WeaponAPI weapon) {
57 ShipAPI ship = weapon.getShip();
58 if (ship == null) return 1f;
59
60 float rofMult = 1f;
61 switch (weapon.getSpec().getType()) {
62 case BALLISTIC:
63 rofMult = ship.getMutableStats().getBallisticRoFMult().getModifiedValue();
64 break;
65 case MISSILE:
66 rofMult = ship.getMutableStats().getMissileRoFMult().getModifiedValue();
67 break;
68 case ENERGY:
69 rofMult = ship.getMutableStats().getEnergyRoFMult().getModifiedValue();
70 break;
71 }
72 return rofMult;
73 }
74
75 public void onFire(DamagingProjectileAPI projectile, WeaponAPI weapon, CombatEngineAPI engine) {
76 if (shots == null) {
77 shots = new ArrayList<DamagingProjectileAPI>();
78 }
79 shots.add(0, projectile);
80 }
81
82
83// public String getWeaponEffectId(WeaponAPI weapon) {
84// String id = weapon.getShip().getId() + "_" + weapon.getSlot().getId() + "_" + weapon.getId();
85// return id;
86//}
87//public VPDriverEffect getWeaponEffect(WeaponAPI weapon) {
88// String id = getWeaponEffectId(weapon);
89// return (VPDriverEffect) Global.getCombatEngine().getCustomData().get(id);
90//}
91}
92
93
94
95
static SettingsAPI getSettings()
Definition Global.java:51
void onFire(DamagingProjectileAPI projectile, WeaponAPI weapon, CombatEngineAPI engine)
void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon)