Advertisement
DarkRevenant

Untitled

Jun 2nd, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. package data.scripts.weapons;
  2.  
  3. import com.fs.starfarer.api.AnimationAPI;
  4. import com.fs.starfarer.api.combat.CombatEngineAPI;
  5. import com.fs.starfarer.api.combat.EveryFrameWeaponEffectPlugin;
  6. import com.fs.starfarer.api.combat.WeaponAPI;
  7. import java.util.*;
  8.  
  9. public class BaseAnimateOnFireEffect implements EveryFrameWeaponEffectPlugin {
  10.  
  11. // Default to 15 frames per second
  12. private float timeSinceLastFrame, timeBetweenFrames = 1.0f / 15f;
  13. private final Map pauseFrames = new HashMap();
  14. private int curFrame = 0, pausedFor = 0;
  15. private boolean isFiring = false;
  16.  
  17. protected void setFramesPerSecond(float fps) {
  18. timeBetweenFrames = 1.0f / fps;
  19. }
  20.  
  21. protected void pauseOnFrame(int frame, int pauseFor) {
  22. pauseFrames.put(frame, pauseFor);
  23. }
  24.  
  25. private void incFrame(AnimationAPI anim) {
  26. if (pauseFrames.containsKey(curFrame)) {
  27. if (pausedFor < (Integer) pauseFrames.get(curFrame)) {
  28. pausedFor++;
  29. return;
  30. } else {
  31. pausedFor = 0;
  32. }
  33. }
  34.  
  35. curFrame = Math.min(curFrame + 1, anim.getNumFrames() - 1);
  36. }
  37.  
  38. @Override
  39. public void advance(float amount, CombatEngineAPI engine, WeaponAPI weapon) {
  40. if (engine.isPaused()) {
  41. return;
  42. }
  43.  
  44. AnimationAPI anim = weapon.getAnimation();
  45. if (anim == null) {
  46. return;
  47. }
  48.  
  49. anim.setFrame(curFrame);
  50.  
  51. if (isFiring) {
  52. timeSinceLastFrame += amount;
  53.  
  54. if (timeSinceLastFrame >= timeBetweenFrames) {
  55. timeSinceLastFrame = 0f;
  56. incFrame(anim);
  57. anim.setFrame(curFrame);
  58.  
  59. if (curFrame == anim.getNumFrames() - 1) {
  60. isFiring = false;
  61. }
  62. }
  63. } else {
  64. if (weapon.isFiring() && weapon.getChargeLevel() == 1.0f) {
  65. isFiring = true;
  66. incFrame(anim);
  67. anim.setFrame(curFrame);
  68. } else {
  69. curFrame = 0;
  70. anim.setFrame(curFrame);
  71. }
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement