summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/HighJump.java
blob: 722a5edf8ed8b8c8110ae93aef8964f1a7b1c537 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package NET.worlds.scape;

import NET.worlds.console.Main;
import NET.worlds.console.MainCallback;
import NET.worlds.core.Std;
import java.util.Enumeration;

public class HighJump extends InventoryAction implements MainCallback {
   int start;
   SmoothDriver sd;

   public HighJump(String id, String name) {
      super(id, name);
   }

   public HighJump(String id, String name, int qty) {
      super(id, name, qty);
   }

   public HighJump(HighJump in) {
      super(in);
   }

   @Override
   public InventoryItem cloneItem() {
      return new HighJump(this);
   }

   private SmoothDriver findSD(Pilot p) {
      Enumeration e = p.getHandlers();

      while (e.hasMoreElements()) {
         Object o = e.nextElement();
         if (o instanceof SmoothDriver) {
            return (SmoothDriver)o;
         }
      }

      return null;
   }

   @Override
   public boolean doAction() {
      if (this.itemQuantity_ > 0) {
         Pilot p = Pilot.getActive();
         if (p == null) {
            return false;
         } else {
            this.sd = this.findSD(p);
            if (this.sd == null) {
               return false;
            } else {
               if (this.sd != null) {
                  Main.register(this);
                  this.start = Std.getRealTime();
                  this.itemQuantity_--;
               }

               return true;
            }
         }
      } else {
         return false;
      }
   }

   @Override
   public void mainCallback() {
      int now = Std.getFastTime();
      if (now > this.start + 6000) {
         Main.unregister(this);
         this.sd.setEyeHeight(150.0F);
      } else {
         float t = 1.0F - (float)Math.pow(1.0F - (now - this.start) / 3000.0F, 4.0);
         this.sd.setEyeHeight(150.0F + 150.0F * t);
      }
   }
}