RuneHive-Game
Loading...
Searching...
No Matches
AnimationDefinition.java
Go to the documentation of this file.
1package com.runehive.fs.cache.decoder;
2
3import io.netty.buffer.ByteBuf;
4
5public final class AnimationDefinition {
6
7 public final int id;
8
9 public int length;
10 public int[] primary;
11 public int secondary[];
12 public int[] duration;
13 public int padding;
14 public int interleaveOrder[];
15 public boolean allowsRotation;
16 public int priority;
17 public int shield;
18 public int weapon;
19 public int resetCycle;
20 public int runFlag;
21 public int walkFlag;
22 public int type;
23
24 public AnimationDefinition(final int id) {
25 this.id = id;
26
27 padding = -1;
28 allowsRotation = false;
29 priority = 5;
30 shield = -1;
31 weapon = -1;
32 resetCycle = 99;
33 runFlag = -1;
34 walkFlag = -1;
35 type = 1;
36 }
37
38 public void decode(ByteBuf buffer) {
39 while(true) {
40 final int opcode = buffer.readUnsignedByte();
41
42 if (opcode == 0) {
43 break;
44 } else if (opcode == 1) {
45 length = buffer.readUnsignedShort();
46 primary = new int[length];
47 secondary = new int[length];
48 duration = new int[length];
49
50 for (int i = 0; i < length; i++) {
51 duration[i] = buffer.readUnsignedShort();
52 }
53
54 for (int i = 0; i < length; i++) {
55 primary[i] = buffer.readUnsignedShort();
56 secondary[i] = -1;
57 }
58
59 for (int i = 0; i < length; i++) {
60 primary[i] += buffer.readUnsignedShort() << 16;
61 }
62 } else if (opcode == 2) {
63 padding = buffer.readUnsignedShort();
64 } else if (opcode == 3) {
65 int len = buffer.readUnsignedByte();
66 interleaveOrder = new int[len + 1];
67 for (int i = 0; i < len; i++) {
68 interleaveOrder[i] = buffer.readUnsignedByte();
69 }
70 interleaveOrder[len] = 9999999;
71 } else if (opcode == 4) {
72 allowsRotation = true;
73 } else if (opcode == 5) {
74 priority = buffer.readUnsignedByte();
75 } else if (opcode == 6) {
76 shield = buffer.readUnsignedShort();
77 } else if (opcode == 7) {
78 weapon = buffer.readUnsignedShort();
79 } else if (opcode == 8) {
80 resetCycle = buffer.readUnsignedByte();
81 } else if (opcode == 9) {
82 runFlag = buffer.readUnsignedByte();
83 } else if (opcode == 10) {
84 walkFlag = buffer.readUnsignedByte();
85 } else if (opcode == 11) {
86 type = buffer.readUnsignedByte();
87 } else if (opcode == 12) {
88 int len = buffer.readUnsignedByte();
89
90 for (int i = 0; i < len; i++) {
91 buffer.readUnsignedShort();
92 }
93
94 for (int i = 0; i < len; i++) {
95 buffer.readUnsignedShort();
96 }
97 } else if (opcode == 13) {
98 int len = buffer.readUnsignedByte();
99 for (int i = 0; i < len; i++) {
100 buffer.readUnsignedMedium();
101 }
102 } else if (opcode == 14) {
103 buffer.readUnsignedInt();
104 } else if (opcode == 15) {
105 int len = buffer.readUnsignedShort();
106
107 for (int index = 0; index < len; ++index) {
108 buffer.readUnsignedShort();
109 buffer.readUnsignedMedium();
110 }
111 } else if (opcode == 16) {
112 buffer.readUnsignedShort();
113 buffer.readUnsignedShort();
114 } else if (opcode == 17) {
115
116 int len = buffer.readUnsignedByte();
117 for (int i = 0; i < len; ++i) {
118 buffer.readUnsignedByte();
119 }
120 }
121 }
122 if (length == 0) {
123 length = 1;
124 primary = new int[1];
125 primary[0] = -1;
126 secondary = new int[1];
127 secondary[0] = -1;
128 duration = new int[1];
129 duration[0] = -1;
130 }
131
132 if (runFlag == -1) {
133 runFlag = (interleaveOrder == null) ? 0 : 2;
134 }
135
136 if (priority == -1) {
137 priority = (interleaveOrder == null) ? 0 : 2;
138 }
139
141 }
142
143 public int durationTime = 0;
144
145 private int calculateDuration() {
146 int duration = 0;
147 if (this.duration == null) {
148 return 0;
149 }
150 for (final int i : this.duration) {
151 /*if (i < 0 || i > 30) {
152 continue;
153 }*/
154 duration += Math.abs(i) * 20;
155 }
156 return duration;
157 }
158
159}