Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.70 KB | None | 0 0
  1. package tibia.appearances
  2. {
  3. public class AppearanceAnimator
  4. {
  5.  
  6. private static const ENVIRONMENTAL_EFFECTS:Array = [];
  7.  
  8. public static const ANIMATION_DELAY_BEFORE_RESET:int = 1000;
  9.  
  10. public static const FRAME_GROUP_WALKING:uint = 1;
  11.  
  12. public static const PHASE_AUTOMATIC:int = -1;
  13.  
  14. protected static const APPEARANCE_EFFECT:uint = 2;
  15.  
  16. public static const SPRITE_CACHE_PAGE_DIMENSION:uint = 512;
  17.  
  18. public static const FRAME_GROUP_DEFAULT:uint = FRAME_GROUP_IDLE;
  19.  
  20. private static const MAX_SPEED_DELAY:int = 100;
  21.  
  22. public static const FRAME_GROUP_IDLE:uint = 0;
  23.  
  24. public static const COMPRESSED_IMAGES_CACHE_MEMORY:uint = 4 * 768 * 768 * 15;
  25.  
  26. public static const ANIMATION_ASYNCHRON:int = 0;
  27.  
  28. protected static const APPEARANCE_MISSILE:uint = 3;
  29.  
  30. public static const PHASE_RANDOM:int = 254;
  31.  
  32. private static const MINIMUM_SPEED_FRAME_DURATION:int = 90 * 8;
  33.  
  34. public static const PHASE_ASYNCHRONOUS:int = 255;
  35.  
  36. public static const SPRITE_CACHE_PAGE_COUNT:uint = 5 * 5;
  37.  
  38. private static const MIN_SPEED_DELAY:int = 550;
  39.  
  40. protected static const APPEARANCE_OBJECT:uint = 0;
  41.  
  42. private static const MAXIMUM_SPEED_FRAME_DURATION:int = 35 * 8;
  43.  
  44. protected static const APPEARANCE_OUTFIT:uint = 1;
  45.  
  46. public static const ANIMATION_SYNCHRON:int = 1;
  47.  
  48. private var m_PhaseCount:uint;
  49.  
  50. private var m_LastAnimationTick:Number = 0;
  51.  
  52. private var m_NextFrameStrategy:NextFrameStrategy;
  53.  
  54. private var m_FrameDurations:Vector.<tibia.appearances.FrameDuration>;
  55.  
  56. private var m_CurrentPhaseDuration:uint;
  57.  
  58. private var m_HasFinishedAnimation:Boolean = false;
  59.  
  60. private var m_StartPhase:int;
  61.  
  62. private var m_AnimationType:int;
  63.  
  64. private var m_CurrentPhase:uint;
  65.  
  66. public function AppearanceAnimator(param1:uint, param2:int, param3:int, param4:int, param5:Vector.<tibia.appearances.FrameDuration>)
  67. {
  68. super();
  69. if(param4 != ANIMATION_ASYNCHRON && param4 != ANIMATION_SYNCHRON)
  70. {
  71. throw new ArgumentError("AppearanceAnimator: Unexpected animation type " + param4);
  72. }
  73. if(param5.length != param1)
  74. {
  75. throw new ArgumentError("AppearanceAnimator: Frameduration differs from phase count");
  76. }
  77. if(param2 < -1 || param2 >= param1)
  78. {
  79. throw new ArgumentError("AppearanceAnimator: Invalid start phase " + param2);
  80. }
  81. this.m_PhaseCount = param1;
  82. this.m_StartPhase = param2;
  83. this.m_AnimationType = param4;
  84. this.m_FrameDurations = param5;
  85. this.m_LastAnimationTick = Tibia.s_FrameTibiaTimestamp > 0?Number(Tibia.s_FrameTibiaTimestamp):Number(Tibia.s_GetTibiaTimer());
  86. if(param3 < 0)
  87. {
  88. this.m_NextFrameStrategy = new PingPongFrameStrategy();
  89. }
  90. else
  91. {
  92. this.m_NextFrameStrategy = new LoopFrameStrategy(param3);
  93. }
  94. this.phase = PHASE_AUTOMATIC;
  95. }
  96.  
  97. public function get frameDurations() : Vector.<tibia.appearances.FrameDuration>
  98. {
  99. return this.m_FrameDurations;
  100. }
  101.  
  102. public function setEndless() : void
  103. {
  104. this.m_NextFrameStrategy = new LoopFrameStrategy(0);
  105. this.reset();
  106. }
  107.  
  108. public function get lastAnimationTick() : Number
  109. {
  110. return this.m_LastAnimationTick;
  111. }
  112.  
  113. public function reset() : void
  114. {
  115. this.phase = PHASE_AUTOMATIC;
  116. this.m_HasFinishedAnimation = false;
  117. this.m_NextFrameStrategy.reset();
  118. }
  119.  
  120. public function get phaseCount() : uint
  121. {
  122. return this.m_PhaseCount;
  123. }
  124.  
  125. public function clone() : AppearanceAnimator
  126. {
  127. var _loc1_:AppearanceAnimator = null;
  128. if(this.m_AnimationType == ANIMATION_SYNCHRON)
  129. {
  130. return this;
  131. }
  132. _loc1_ = new AppearanceAnimator(this.m_PhaseCount,this.m_StartPhase,0,this.m_AnimationType,this.m_FrameDurations);
  133. _loc1_.m_NextFrameStrategy = this.m_NextFrameStrategy.clone();
  134. _loc1_.phase = PHASE_AUTOMATIC;
  135. return _loc1_;
  136. }
  137.  
  138. public function get animationType() : int
  139. {
  140. return this.m_AnimationType;
  141. }
  142.  
  143. public function get finished() : Boolean
  144. {
  145. return this.m_HasFinishedAnimation;
  146. }
  147.  
  148. public function animate(param1:Number, param2:int = 0) : void
  149. {
  150. var _loc3_:Number = NaN;
  151. var _loc4_:uint = 0;
  152. var _loc5_:int = 0;
  153. if(param1 != this.m_LastAnimationTick && !this.m_HasFinishedAnimation)
  154. {
  155. _loc3_ = param1 - this.m_LastAnimationTick;
  156. if(_loc3_ >= this.m_CurrentPhaseDuration)
  157. {
  158. _loc4_ = this.m_NextFrameStrategy.nextFrame(this.m_CurrentPhase,this.m_PhaseCount);
  159. if(this.m_CurrentPhase != _loc4_)
  160. {
  161. _loc5_ = param2 == 0?int(this.m_FrameDurations[_loc4_].duration - (_loc3_ - this.m_CurrentPhaseDuration)):int(this.calculateMovementPhaseDuration(param2));
  162. if(_loc5_ < 0 && this.m_AnimationType == ANIMATION_SYNCHRON)
  163. {
  164. this.calculateSynchronousPhase();
  165. }
  166. else
  167. {
  168. this.m_CurrentPhase = _loc4_;
  169. this.m_CurrentPhaseDuration = Math.max(0,_loc5_);
  170. }
  171. }
  172. else
  173. {
  174. this.m_HasFinishedAnimation = true;
  175. }
  176. }
  177. else
  178. {
  179. this.m_CurrentPhaseDuration = this.m_CurrentPhaseDuration - _loc3_;
  180. }
  181. this.m_LastAnimationTick = param1;
  182. }
  183. }
  184.  
  185. public function set phase(param1:int) : void
  186. {
  187. if(this.m_AnimationType == ANIMATION_ASYNCHRON)
  188. {
  189. if(param1 == PHASE_ASYNCHRONOUS)
  190. {
  191. this.m_CurrentPhase = 0;
  192. }
  193. else if(param1 == PHASE_RANDOM)
  194. {
  195. this.m_CurrentPhase = Math.floor(Math.random() * this.m_PhaseCount);
  196. }
  197. else if(param1 >= 0 && param1 < this.m_PhaseCount)
  198. {
  199. this.m_CurrentPhase = param1;
  200. }
  201. else
  202. {
  203. this.m_CurrentPhase = this.startPhase;
  204. }
  205. this.m_HasFinishedAnimation = false;
  206. this.m_CurrentPhaseDuration = this.m_FrameDurations[this.m_CurrentPhase].duration;
  207. }
  208. else
  209. {
  210. this.calculateSynchronousPhase();
  211. }
  212. }
  213.  
  214. private function calculateSynchronousPhase() : void
  215. {
  216. var _loc6_:tibia.appearances.FrameDuration = null;
  217. var _loc7_:Number = NaN;
  218. var _loc8_:Number = NaN;
  219. var _loc1_:Number = 0;
  220. var _loc2_:uint = 0;
  221. while(_loc2_ < this.m_PhaseCount)
  222. {
  223. _loc6_ = this.m_FrameDurations[_loc2_];
  224. _loc1_ = _loc1_ + _loc6_.duration;
  225. _loc2_++;
  226. }
  227. var _loc3_:Number = Tibia.s_FrameTibiaTimestamp > 0?Number(Tibia.s_FrameTibiaTimestamp):Number(Tibia.s_GetTibiaTimer());
  228. var _loc4_:Number = _loc3_ % _loc1_;
  229. var _loc5_:Number = 0;
  230. _loc2_ = 0;
  231. while(_loc2_ < this.m_PhaseCount)
  232. {
  233. _loc7_ = this.m_FrameDurations[_loc2_].duration;
  234. if(_loc4_ >= _loc5_ && _loc4_ < _loc5_ + _loc7_)
  235. {
  236. this.m_CurrentPhase = _loc2_;
  237. _loc8_ = _loc4_ - _loc5_;
  238. this.m_CurrentPhaseDuration = _loc7_ - _loc8_;
  239. break;
  240. }
  241. _loc5_ = _loc5_ + _loc7_;
  242. _loc2_++;
  243. }
  244. this.m_LastAnimationTick = _loc3_;
  245. }
  246.  
  247. public function get startPhase() : uint
  248. {
  249. if(this.m_StartPhase > -1)
  250. {
  251. return this.m_StartPhase;
  252. }
  253. return Math.floor(Math.random() * this.m_PhaseCount);
  254. }
  255.  
  256. private function calculateMovementPhaseDuration(param1:int) : Number
  257. {
  258. var _loc2_:int = 0;
  259. var _loc3_:int = 0;
  260. _loc2_ = MAX_SPEED_DELAY;
  261. _loc3_ = MIN_SPEED_DELAY;
  262. var _loc4_:int = Math.min(Math.max(_loc2_,param1),_loc3_);
  263. var _loc5_:Number = Number(_loc4_ - _loc2_) / Number(_loc3_ - _loc2_);
  264. var _loc6_:int = MINIMUM_SPEED_FRAME_DURATION / this.m_PhaseCount;
  265. var _loc7_:int = MAXIMUM_SPEED_FRAME_DURATION / this.m_PhaseCount;
  266. return (_loc6_ - _loc7_) * _loc5_ + _loc7_;
  267. }
  268.  
  269. public function get phase() : int
  270. {
  271. return this.m_CurrentPhase;
  272. }
  273.  
  274. public function set finished(param1:Boolean) : void
  275. {
  276. this.m_HasFinishedAnimation = param1;
  277. }
  278. }
  279. }
  280.  
  281. class PingPongFrameStrategy extends NextFrameStrategy
  282. {
  283.  
  284. private static const PHASE_FORWARD:int = 0;
  285.  
  286. private static const PHASE_BACKWARD:int = 1;
  287.  
  288. private var m_CurrentDirection:int = 0;
  289.  
  290. function PingPongFrameStrategy()
  291. {
  292. super();
  293. }
  294.  
  295. override public function nextFrame(param1:uint, param2:uint) : uint
  296. {
  297. var _loc3_:int = this.m_CurrentDirection == PHASE_FORWARD?1:-1;
  298. var _loc4_:int = param1 + _loc3_;
  299. if(_loc4_ < 0 || _loc4_ >= param2)
  300. {
  301. this.m_CurrentDirection = this.m_CurrentDirection == PHASE_FORWARD?int(PHASE_BACKWARD):int(PHASE_FORWARD);
  302. _loc3_ = _loc3_ * -1;
  303. }
  304. return param1 + _loc3_;
  305. }
  306.  
  307. override public function clone() : NextFrameStrategy
  308. {
  309. var _loc1_:PingPongFrameStrategy = new PingPongFrameStrategy();
  310. _loc1_.m_CurrentDirection = this.m_CurrentDirection;
  311. return _loc1_;
  312. }
  313.  
  314. override public function reset() : void
  315. {
  316. this.m_CurrentDirection = PHASE_FORWARD;
  317. }
  318. }
  319.  
  320. class LoopFrameStrategy extends NextFrameStrategy
  321. {
  322.  
  323. private var m_LoopCount:uint;
  324.  
  325. private var m_CurrentLoop:uint = 0;
  326.  
  327. function LoopFrameStrategy(param1:uint)
  328. {
  329. super();
  330. this.m_LoopCount = param1;
  331. }
  332.  
  333. override public function nextFrame(param1:uint, param2:uint) : uint
  334. {
  335. var _loc3_:uint = param1 + 1;
  336. if(_loc3_ < param2)
  337. {
  338. return _loc3_;
  339. }
  340. if(this.m_CurrentLoop < this.m_LoopCount - 1 || this.m_LoopCount == 0)
  341. {
  342. this.m_CurrentLoop++;
  343. return 0;
  344. }
  345. return param1;
  346. }
  347.  
  348. override public function clone() : NextFrameStrategy
  349. {
  350. var _loc1_:LoopFrameStrategy = new LoopFrameStrategy(this.m_LoopCount);
  351. _loc1_.m_CurrentLoop = this.m_CurrentLoop;
  352. return _loc1_;
  353. }
  354.  
  355. override public function reset() : void
  356. {
  357. this.m_CurrentLoop = 0;
  358. }
  359. }
  360.  
  361. import flash.errors.IllegalOperationError;
  362.  
  363. class NextFrameStrategy
  364. {
  365.  
  366. function NextFrameStrategy()
  367. {
  368. super();
  369. }
  370.  
  371. public function nextFrame(param1:uint, param2:uint) : uint
  372. {
  373. throw new IllegalOperationError("NextFrameStrategy.nextFrame: Must override in subclass");
  374. }
  375.  
  376. public function clone() : NextFrameStrategy
  377. {
  378. throw new IllegalOperationError("NextFrameStrategy.clone: Must override in subclass");
  379. }
  380.  
  381. public function reset() : void
  382. {
  383. }
  384. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement