PageRenderTime 156ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/com/lele/Controller/Avatar/CAvatar.as

https://gitlab.com/Treeky-NULL/LezaiNiubi
ActionScript | 915 lines | 802 code | 51 blank | 62 comment | 50 complexity | 30e2b36854ad275bdd583510469e021f MD5 | raw file
  1. package com.lele.Controller.Avatar
  2. {
  3. import com.lele.Controller.Avatar.Interface.ICommunication;
  4. import com.lele.Controller.Avatar.Layer.ClothLayer;
  5. import com.lele.Data.IClothAnimation;
  6. import com.lele.Map.Interface.IDepthObj;
  7. import com.lele.Controller.Avatar.Events.Avatar_PlayerController_Event;
  8. import com.lele.Manager.Interface.IReport;
  9. import fl.motion.Color;
  10. import com.lele.Controller.Avatar.Enum.AvatarState;
  11. import com.lele.Controller.Avatar.Interface.IAvatar;
  12. import com.lele.Controller.Avatar.Interface.IControllerClickAble;
  13. import com.lele.Data.IAnimationData;
  14. import flash.display.ColorCorrection;
  15. import flash.display.MovieClip;
  16. import flash.display.Sprite;
  17. import flash.events.Event;
  18. import flash.events.MouseEvent;
  19. import flash.geom.Matrix;
  20. import flash.globalization.StringTools;
  21. import flash.text.TextField;
  22. import flash.text.TextFieldAutoSize;
  23. import flash.text.TextFormat;
  24. /**
  25. * ...
  26. * @author Lele
  27. */
  28. //这个类其实不应该放在这里
  29. //抽象成抽象类才能放在这里
  30. //CAvatar作为PlayerController的子对象,是一个容纳显示部分的对象
  31. public class CAvatar extends MovieClip implements IAvatar,IControllerClickAble,IDepthObj//用这个类可以来完成一些动画,,一个包装各种动作在一起的容器,同时只有一个MovieClip在子对象列表中
  32. {
  33. private var _repoter:IReport;
  34. private var _resourcePack:IAnimationData;
  35. private var _skin:Object;
  36. private var _bone:Object;
  37. private var _effect:Object;
  38. private var shadow:Sprite;
  39. private var _clothLayer:ClothLayer;
  40. private var _bodyLayer:Sprite;
  41. private var _effectLayer:Sprite;
  42. private var _shadowLayer:Sprite;
  43. private var _otherLayer:Sprite;
  44. private var _isSelfOwner:Boolean;
  45. private var _body_skin:Sprite;
  46. private var _body_bone:Sprite;
  47. private var _body_effect:Sprite;
  48. private var MoleState:Function;
  49. private var _currentDir:String;
  50. private var _currentState:String;
  51. private var _timeCounter:Object;
  52. private var _depth:int;
  53. private var _chatDialog:Sprite;//聊天弹窗
  54. private var _nameTxt:TextField;
  55. public function Reset()
  56. {
  57. (_effect.down as MovieClip).stop();
  58. (_effect.up as MovieClip).stop();
  59. (_effect.leftdown as MovieClip).stop();
  60. (_effect.leftup as MovieClip).stop();
  61. (_effect.left as MovieClip).stop();
  62. }
  63. public function InitAllDress()
  64. {
  65. _clothLayer.InitAllDress();
  66. }
  67. public function OnClothLoaded(cloth:IClothAnimation)
  68. {
  69. _clothLayer.OnClothLoaded(cloth);
  70. }
  71. public function SetComDialog(dialog:Sprite)
  72. {
  73. if (_chatDialog != null) { return; }
  74. _chatDialog = dialog;
  75. _otherLayer.addChild(_chatDialog);
  76. _chatDialog.y = -95;
  77. }
  78. public function AddtoOtherLayer(target:Sprite)
  79. {
  80. if (target == null) { return; }
  81. _otherLayer.addChildAt(target,0);
  82. }
  83. public function ShowDialog(txt:String)
  84. {
  85. (_chatDialog as ICommunication).ShowTxt(txt);
  86. _chatDialog.x = ( -_chatDialog.width / 2) + 5;
  87. }
  88. //test Func
  89. public function CAvatar(moleAct:Object,resourcePack:IAnimationData,isSelfOwner:Boolean,color:String="white",name:String=null)
  90. {
  91. _timeCounter = new Object();
  92. _depth = 0;
  93. shadow = resourcePack.shadow;
  94. //创建名字框
  95. _nameTxt = new TextField();
  96. _nameTxt.autoSize = TextFieldAutoSize.CENTER;
  97. _nameTxt.text = name;
  98. _nameTxt.x -= 48;
  99. _nameTxt.y = 8;
  100. _skin = moleAct.skin;
  101. _bone = moleAct.bone;
  102. _effect = moleAct.effect;
  103. (_skin.down as MovieClip).transform.matrix = new Matrix();//重置数据
  104. (_skin.up as MovieClip).transform.matrix = new Matrix();
  105. (_skin.left as MovieClip).transform.matrix = new Matrix();
  106. (_skin.leftdown as MovieClip).transform.matrix = new Matrix();
  107. (_skin.leftup as MovieClip).transform.matrix = new Matrix();
  108. (_bone.down as MovieClip).transform.matrix = new Matrix();
  109. (_bone.up as MovieClip).transform.matrix = new Matrix();
  110. (_bone.left as MovieClip).transform.matrix = new Matrix();
  111. (_bone.leftdown as MovieClip).transform.matrix = new Matrix();
  112. (_bone.leftup as MovieClip).transform.matrix = new Matrix();
  113. (_effect.down as MovieClip).transform.matrix = new Matrix();
  114. (_effect.up as MovieClip).transform.matrix = new Matrix();
  115. (_effect.left as MovieClip).transform.matrix = new Matrix();
  116. (_effect.leftdown as MovieClip).transform.matrix = new Matrix();
  117. (_effect.leftup as MovieClip).transform.matrix = new Matrix();
  118. //设置颜色
  119. SetColor(color, _bone.up);
  120. SetColor(color, _bone.down);
  121. SetColor(color, _bone.leftup);
  122. SetColor(color, _bone.leftdown);
  123. SetColor(color, _bone.left);
  124. _clothLayer = new ClothLayer();//构建容器
  125. _bodyLayer = new Sprite();
  126. _shadowLayer = new Sprite();
  127. _otherLayer = new Sprite();
  128. _effectLayer = new Sprite();
  129. (_effect.down as MovieClip).stop();//停止效果
  130. (_effect.up as MovieClip).stop();
  131. (_effect.leftdown as MovieClip).stop();
  132. (_effect.leftup as MovieClip).stop();
  133. (_effect.left as MovieClip).stop();
  134. (_effect.down as MovieClip).cacheAsBitmap = true;
  135. (_effect.up as MovieClip).cacheAsBitmap = true;
  136. (_effect.leftdown as MovieClip).cacheAsBitmap = true;
  137. (_effect.leftup as MovieClip).cacheAsBitmap = true;
  138. (_effect.left as MovieClip).cacheAsBitmap = true;
  139. (_bone.down as MovieClip).cacheAsBitmap = true;
  140. (_bone.up as MovieClip).cacheAsBitmap = true;
  141. (_bone.left as MovieClip).cacheAsBitmap = true;
  142. (_bone.leftdown as MovieClip).cacheAsBitmap = true;
  143. (_bone.leftup as MovieClip).cacheAsBitmap = true;
  144. this.addChild(_shadowLayer);//添加层
  145. this.addChild(_bodyLayer);
  146. this.addChild(_clothLayer);
  147. this.addChild(_effectLayer);
  148. this.addChild(_otherLayer);
  149. _body_bone = new Sprite();//添加Body的子层
  150. _body_effect = new Sprite();
  151. _body_skin = new Sprite();
  152. _bodyLayer.addChild(_body_bone);
  153. _bodyLayer.addChild(_body_skin);
  154. _effectLayer.addChild(_body_effect);
  155. _shadowLayer.addChild(shadow);//添加阴影
  156. _otherLayer.addChild(_nameTxt);//添加名字
  157. _isSelfOwner = isSelfOwner;
  158. MoleState = function() { }
  159. this.addEventListener(Event.ENTER_FRAME, EnterFrame);
  160. DoAction("stand", "dd");
  161. }
  162. public function DoAction(actionName:String, direction:String,callBack:Function=null)
  163. {
  164. var act = ActionSuggest.SuggestAction(actionName);//对动作名进行解释
  165. //
  166. if (_currentState == act && _currentDir == direction)
  167. return;
  168. MoleActivity(act, direction,callBack);
  169. }
  170. //动作解析调度
  171. private function MoleActivity(act:String,dir:String,callBack:Function=null)//动作总调度
  172. {
  173. if (_shadowLayer.numChildren == 0) { _shadowLayer.addChild(shadow); }
  174. _currentState = act;
  175. transformDirection(dir);
  176. switch(act)
  177. {
  178. case "run":
  179. {
  180. PlayAct(act, 50,-1,function(){
  181. // _body_effect.removeChildAt(0);
  182. });
  183. return;
  184. }
  185. case "swim":
  186. {
  187. PlayAct(act, 78, -1, null, true);
  188. if (_shadowLayer.numChildren > 0) { _shadowLayer.removeChildAt(0); }
  189. return;
  190. }
  191. case "stand":
  192. {
  193. PlayAct(act, 10);
  194. return;
  195. }
  196. case "brake":
  197. {
  198. PlayAct(act, 68, 1, function() {
  199. // _body_effect.removeChildAt(0);
  200. },true);
  201. return;
  202. }
  203. case "disdain":
  204. {
  205. //请求停止自动旋转
  206. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  207. _repoter.OnReport(stopRotEvt);
  208. PlayAct(act, 745, 4, function() {
  209. if (callBack != null)
  210. callBack();
  211. DoAction("stand", "dd");
  212. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  213. _repoter.OnReport(startRotEvt);
  214. // _body_effect.removeChildAt(0);
  215. });
  216. return;
  217. }
  218. case "big_smile":
  219. {
  220. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  221. _repoter.OnReport(stopRotEvt);
  222. PlayAct(act, 856, 5, function() {
  223. if(callBack!=null)
  224. callBack();
  225. DoAction("stand", "dd");
  226. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  227. _repoter.OnReport(startRotEvt);
  228. // _body_effect.removeChildAt(0);
  229. },true);
  230. return;
  231. }
  232. case "bad_smile":
  233. {
  234. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  235. _repoter.OnReport(stopRotEvt);
  236. PlayAct(act, 773, 1, function() {
  237. if(callBack!=null)
  238. callBack();
  239. DoAction("stand", "dd");
  240. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  241. _repoter.OnReport(startRotEvt);
  242. },true);
  243. return;
  244. }
  245. case "pudency":
  246. {
  247. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  248. _repoter.OnReport(stopRotEvt);
  249. PlayAct(act, 782, 3, function() {
  250. if(callBack!=null)
  251. callBack();
  252. DoAction("stand", "dd");
  253. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  254. _repoter.OnReport(startRotEvt);
  255. // _body_effect.removeChildAt(0);
  256. },true);
  257. return;
  258. }
  259. case "complacent":
  260. {
  261. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  262. _repoter.OnReport(stopRotEvt);
  263. PlayAct(act, 811, 3, function() {
  264. if(callBack!=null)
  265. callBack();
  266. DoAction("stand", "dd");
  267. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  268. _repoter.OnReport(startRotEvt);
  269. // _body_effect.removeChildAt(0);
  270. },true);
  271. return;
  272. }
  273. case "spit":
  274. {
  275. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  276. _repoter.OnReport(stopRotEvt);
  277. PlayAct(act, 846, 1, function() {
  278. if(callBack!=null)
  279. callBack();
  280. DoAction("stand", "dd");
  281. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  282. _repoter.OnReport(startRotEvt);
  283. },true);
  284. return;
  285. }
  286. case "embarrassed":
  287. {
  288. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  289. _repoter.OnReport(stopRotEvt);
  290. PlayAct(act, 899, 1, function() {
  291. if(callBack!=null)
  292. callBack();
  293. DoAction("stand", "dd");
  294. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  295. _repoter.OnReport(startRotEvt);
  296. },true);
  297. return;
  298. }
  299. case "cry":
  300. {
  301. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  302. _repoter.OnReport(stopRotEvt);
  303. PlayAct(act, 1013, 10, function() {
  304. if(callBack!=null)
  305. callBack();
  306. DoAction("stand", "dd");
  307. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  308. _repoter.OnReport(startRotEvt);
  309. // _body_effect.removeChildAt(0);
  310. },true);
  311. return;
  312. }
  313. case "naughty":
  314. {
  315. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  316. _repoter.OnReport(stopRotEvt);
  317. PlayAct(act, 907, 4, function() {
  318. if(callBack!=null)
  319. callBack();
  320. DoAction("stand", "dd");
  321. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  322. _repoter.OnReport(startRotEvt);
  323. });
  324. return;
  325. }
  326. case "surprised":
  327. {
  328. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  329. _repoter.OnReport(stopRotEvt);
  330. PlayAct(act, 932, 1, function() {
  331. if(callBack!=null)
  332. callBack();
  333. DoAction("stand", "dd");
  334. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  335. _repoter.OnReport(startRotEvt);
  336. },true);
  337. return;
  338. }
  339. case "sweat":
  340. {
  341. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  342. _repoter.OnReport(stopRotEvt);
  343. PlayAct(act, 973, 3, function() {
  344. if(callBack!=null)
  345. callBack();
  346. DoAction("stand", "dd");
  347. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  348. _repoter.OnReport(startRotEvt);
  349. // _body_effect.removeChildAt(0);
  350. },true);
  351. return;
  352. }
  353. case "dizzy":
  354. {
  355. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  356. _repoter.OnReport(stopRotEvt);
  357. PlayAct(act, 997, 4, function() {
  358. if(callBack!=null)
  359. callBack();
  360. DoAction("stand", "dd");
  361. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  362. _repoter.OnReport(startRotEvt);
  363. // _body_effect.removeChildAt(0);
  364. },true);
  365. return;
  366. }
  367. case "angry":
  368. {
  369. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  370. _repoter.OnReport(stopRotEvt);
  371. PlayAct(act, 1021, 4, function() {
  372. if(callBack!=null)
  373. callBack();
  374. DoAction("stand", "dd");
  375. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  376. _repoter.OnReport(startRotEvt);
  377. // _body_effect.removeChildAt(0);
  378. },true);
  379. return;
  380. }
  381. case "think":
  382. {
  383. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  384. _repoter.OnReport(stopRotEvt);
  385. PlayAct(act, 1029, 3, function() {
  386. if(callBack!=null)
  387. callBack();
  388. DoAction("stand", "dd");
  389. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  390. _repoter.OnReport(startRotEvt);
  391. // _body_effect.removeChildAt(0);
  392. },true);
  393. return;
  394. }
  395. case "hello":
  396. {
  397. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  398. _repoter.OnReport(stopRotEvt);
  399. PlayAct(act, 630, 1, function() {
  400. if(callBack!=null)
  401. callBack();
  402. DoAction("stand", "dd");
  403. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  404. _repoter.OnReport(startRotEvt);
  405. },true);
  406. return;
  407. }
  408. case "feel_wronged":
  409. {
  410. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  411. _repoter.OnReport(stopRotEvt);
  412. PlayAct(act, 733, 3, function() {
  413. if(callBack!=null)
  414. callBack();
  415. DoAction("stand", "dd");
  416. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  417. _repoter.OnReport(startRotEvt);
  418. });
  419. return;
  420. }
  421. case "sitdown_1":
  422. {
  423. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  424. _repoter.OnReport(stopRotEvt);
  425. PlayAct(act, 20, -1, null,false);
  426. return;
  427. }
  428. case "dance":
  429. {
  430. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  431. _repoter.OnReport(stopRotEvt);
  432. PlayAct(act, 1233, 2, function() {
  433. if(callBack!=null)
  434. callBack();
  435. DoAction("stand", "dd");
  436. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  437. _repoter.OnReport(startRotEvt);
  438. },false);
  439. return;
  440. }
  441. case "wave":
  442. {
  443. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  444. _repoter.OnReport(stopRotEvt);
  445. PlayAct(act, 598, 3, function() {
  446. if(callBack!=null)
  447. callBack();
  448. DoAction("stand", "dd");
  449. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  450. _repoter.OnReport(startRotEvt);
  451. });
  452. return;
  453. }
  454. case "superdance":
  455. {
  456. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  457. _repoter.OnReport(stopRotEvt);
  458. PlayAct("dance", 1233, -1, function() {
  459. },false);
  460. return;
  461. }
  462. case "yawn":
  463. {
  464. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  465. _repoter.OnReport(stopRotEvt);
  466. PlayAct("yawn", 182, 1, function() {
  467. if(callBack!=null)
  468. callBack();
  469. DoAction("stand", "dd");
  470. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  471. _repoter.OnReport(startRotEvt);
  472. });
  473. return;
  474. }
  475. case "scratch_buns":
  476. {
  477. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  478. _repoter.OnReport(stopRotEvt);
  479. PlayAct("scratch_buns", 222, 1, function() {
  480. if(callBack!=null)
  481. callBack();
  482. DoAction("stand", "dd");
  483. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  484. _repoter.OnReport(startRotEvt);
  485. });
  486. return;
  487. }
  488. case "scratch_nose":
  489. {
  490. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  491. _repoter.OnReport(stopRotEvt);
  492. PlayAct("scratch_nose", 265, 1, function() {
  493. if(callBack!=null)
  494. callBack();
  495. DoAction("stand", "dd");
  496. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  497. _repoter.OnReport(startRotEvt);
  498. });
  499. return;
  500. }
  501. case "look":
  502. {
  503. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  504. _repoter.OnReport(stopRotEvt);
  505. PlayAct("look", 307, 1, function() {
  506. if(callBack!=null)
  507. callBack();
  508. DoAction("stand", "dd");
  509. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  510. _repoter.OnReport(startRotEvt);
  511. });
  512. return;
  513. }
  514. case "scratch_head":
  515. {
  516. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  517. _repoter.OnReport(stopRotEvt);
  518. PlayAct("scratch_head", 348, 1, function() {
  519. if(callBack!=null)
  520. callBack();
  521. DoAction("stand", "dd");
  522. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  523. _repoter.OnReport(startRotEvt);
  524. });
  525. return;
  526. }
  527. case "throw":
  528. {
  529. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  530. _repoter.OnReport(stopRotEvt);
  531. PlayAct("throw", 99, 1, function() {
  532. if(callBack!=null)
  533. callBack();
  534. DoAction("stand", dir);
  535. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  536. _repoter.OnReport(startRotEvt);
  537. });
  538. return;
  539. }
  540. case "change_cloth_start":
  541. {
  542. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  543. _repoter.OnReport(stopRotEvt);
  544. PlayAct("change_cloth_start",1251, 1, function() {
  545. if(callBack!=null)
  546. callBack();
  547. DoAction("stand", dir);
  548. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  549. _repoter.OnReport(startRotEvt);
  550. },true);
  551. return;
  552. }
  553. case "change_cloth_end":
  554. {
  555. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  556. _repoter.OnReport(stopRotEvt);
  557. PlayAct("change_cloth_end",1272, 1, function() {
  558. if(callBack!=null)
  559. callBack();
  560. DoAction("stand", dir);
  561. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  562. _repoter.OnReport(startRotEvt);
  563. },true);
  564. return;
  565. }
  566. case "cce":
  567. {
  568. var stopRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLOFFROTATEAROUND);
  569. _repoter.OnReport(stopRotEvt);
  570. PlayAct("change_cloth_start",1272, 1, function() {
  571. if(callBack!=null)
  572. callBack();
  573. DoAction("stand", dir);
  574. var startRotEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.CALLONROTATEAROUND);
  575. _repoter.OnReport(startRotEvt);
  576. },true);
  577. return;
  578. }
  579. }
  580. }
  581. private function EnterFrame(evt:Event)
  582. {
  583. MoleState();
  584. }
  585. private function PlayAct(act:String, deadLine:int,loopTimes:int=-1,onStop:Function=null,hasEffect:Boolean=false)
  586. {
  587. _timeCounter[act + "now"] = 1;
  588. _timeCounter[act + "target"] = loopTimes;
  589. var temp:Function;
  590. //set cloth to go
  591. _clothLayer.PlayAct(act);
  592. //set body to go
  593. (_body_bone.getChildAt(0) as MovieClip).gotoAndPlay(act);
  594. (_body_skin.getChildAt(0) as MovieClip).gotoAndPlay(act);
  595. (_body_effect.getChildAt(0) as MovieClip).gotoAndStop(act);
  596. if (hasEffect) { (_body_effect.getChildAt(0) as MovieClip).gotoAndPlay(act); }
  597. //设置方法
  598. temp = function() {
  599. if ((_body_bone.getChildAt(0) as MovieClip).currentFrame == deadLine)
  600. {
  601. if (_timeCounter[act + "now"]== _timeCounter[act + "target"])
  602. {
  603. //set cloth stop
  604. _clothLayer.StopAct();
  605. //set bone stop
  606. (_body_bone.getChildAt(0) as MovieClip).stop();
  607. (_body_skin.getChildAt(0) as MovieClip).stop();
  608. if (hasEffect) { (_body_effect.getChildAt(0) as MovieClip).stop(); }
  609. if (onStop != null)
  610. {
  611. onStop();
  612. return;
  613. }
  614. }
  615. //set cloth play
  616. _clothLayer.PlayAct(act);
  617. //set bone play
  618. (_body_bone.getChildAt(0) as MovieClip).gotoAndPlay(act);
  619. (_body_skin.getChildAt(0) as MovieClip).gotoAndPlay(act);
  620. if (hasEffect) { (_body_effect.getChildAt(0) as MovieClip).gotoAndPlay(act); }
  621. _timeCounter[act + "now"] = _timeCounter[act + "now"] + 1;
  622. }
  623. }
  624. MoleState = temp;
  625. /*if (loop)
  626. {
  627. temp = function() {
  628. if ((_body_bone.getChildAt(0) as MovieClip).currentFrame == deadLine)
  629. {
  630. (_body_bone.getChildAt(0) as MovieClip).gotoAndPlay(act);
  631. (_body_skin.getChildAt(0) as MovieClip).gotoAndPlay(act);
  632. if (hasEffect){(_body_effect.getChildAt(0) as MovieClip).gotoAndPlay(act);}
  633. }
  634. }
  635. }
  636. else
  637. {
  638. temp = function() {
  639. if ((_body_bone.getChildAt(0) as MovieClip).currentFrame == deadLine)
  640. {
  641. (_body_bone.getChildAt(0) as MovieClip).stop();
  642. (_body_skin.getChildAt(0) as MovieClip).stop();
  643. if (hasEffect) { (_body_effect.getChildAt(0) as MovieClip).stop(); }
  644. if (onStop != null)
  645. {
  646. onStop();
  647. }
  648. }
  649. }
  650. }*/
  651. //MoleState = temp;
  652. }
  653. private function transformDirection(dir:String)//改变方向
  654. {
  655. if (_currentDir == dir) { return; }
  656. _currentDir = dir;
  657. switch(dir)
  658. {
  659. case "dd":
  660. {
  661. SideBack(_bone.down);
  662. SideBack(_skin.down);
  663. SideBack(_effect.down);
  664. CAddChild(_body_bone, _bone.down);
  665. CAddChild(_body_skin, _skin.down);
  666. CAddChild(_body_effect, _effect.down);
  667. break;
  668. }
  669. case "dl":
  670. {
  671. SideBack(_bone.leftdown);
  672. SideBack(_skin.leftdown);
  673. SideBack(_effect.leftdown);
  674. CAddChild(_body_bone, _bone.leftdown);
  675. CAddChild(_body_skin, _skin.leftdown);
  676. CAddChild(_body_effect, _effect.leftdown);
  677. break;
  678. }
  679. case "ll":
  680. {
  681. SideBack(_bone.left);
  682. SideBack(_skin.left);
  683. SideBack(_effect.left);
  684. CAddChild(_body_bone, _bone.left);
  685. CAddChild(_body_skin, _skin.left);
  686. CAddChild(_body_effect, _effect.left);
  687. break;
  688. }
  689. case "lu":
  690. {
  691. SideBack(_bone.leftup);
  692. SideBack(_skin.leftup);
  693. SideBack(_effect.leftup);
  694. CAddChild(_body_bone, _bone.leftup);
  695. CAddChild(_body_skin, _skin.leftup);
  696. CAddChild(_body_effect, _effect.leftup);
  697. break;
  698. }
  699. case "uu":
  700. {
  701. SideBack(_bone.up);
  702. SideBack(_skin.up);
  703. SideBack(_effect.up);
  704. CAddChild(_body_bone, _bone.up);
  705. CAddChild(_body_skin, _skin.up);
  706. CAddChild(_body_effect, _effect.up);
  707. break;
  708. }
  709. case "ur":
  710. {
  711. SideDown(_bone.leftup);
  712. SideDown(_skin.leftup);
  713. SideDown(_effect.leftup);
  714. CAddChild(_body_bone, _bone.leftup);
  715. CAddChild(_body_skin, _skin.leftup);
  716. CAddChild(_body_effect, _effect.leftup);
  717. break;
  718. }
  719. case "rr":
  720. {
  721. SideDown(_bone.left);
  722. SideDown(_skin.left);
  723. SideDown(_effect.left);
  724. CAddChild(_body_bone, _bone.left);
  725. CAddChild(_body_skin, _skin.left);
  726. CAddChild(_body_effect, _effect.left);
  727. break;
  728. }
  729. case "rd":
  730. {
  731. SideDown(_bone.leftdown);
  732. SideDown(_skin.leftdown);
  733. SideDown(_effect.leftdown);
  734. CAddChild(_body_bone, _bone.leftdown);
  735. CAddChild(_body_skin, _skin.leftdown);
  736. CAddChild(_body_effect, _effect.leftdown);
  737. break;
  738. }
  739. }
  740. _clothLayer.SetDirection(dir);
  741. (_body_effect.getChildAt(0) as MovieClip).gotoAndStop(1);//效果先停止
  742. }
  743. private function SetColor(color:String,targetMC:MovieClip)
  744. {
  745. var co:Color;
  746. switch(color)
  747. {
  748. case "blue":
  749. {
  750. co = new Color(0.109803, 0.705882, 0.992156);
  751. break;
  752. }
  753. case "white":
  754. co = new Color(1, 1, 1);
  755. break;
  756. case "black":
  757. {
  758. co = new Color(0, 0, 0);
  759. break;
  760. }
  761. case "orange":
  762. {
  763. co = new Color(0.988, 0.494, 0.094);
  764. break;
  765. }
  766. case "green":
  767. {
  768. co = new Color(0.152, 0.913, 0.454);
  769. break;
  770. }
  771. case "red":
  772. {
  773. co = new Color(0.890, 0.133, 0.066);
  774. break;
  775. }
  776. case "brown":
  777. {
  778. co = new Color(0.705, 0.490, 0.164);
  779. break;
  780. }
  781. case "purple":
  782. {
  783. co = new Color(0.807, 0.152, 0.811);
  784. break;
  785. }
  786. case "grey":
  787. {
  788. co = new Color(0.639, 0.627, 0.635);
  789. break;
  790. }
  791. case "pink":
  792. {
  793. co = new Color(0.952, 0.301, 0.592);
  794. break;
  795. }
  796. }
  797. targetMC.transform.colorTransform=co;
  798. }
  799. private function SideDown(mc:MovieClip)
  800. {
  801. SideBack(mc);//倒置前先清理状态
  802. mc.x = -mc.width;
  803. var mtx:Matrix = new Matrix();
  804. mtx.a = -1;
  805. mtx.tx = mc.width;
  806. mtx.concat(mc.transform.matrix);
  807. mc.transform.matrix = mtx;
  808. }
  809. private function SideBack(mc:MovieClip)
  810. {
  811. mc.transform.matrix = new Matrix();
  812. }
  813. private function CAddChild(container:Sprite,child:Sprite)
  814. {
  815. for (var a:int = 0; a < container.numChildren; a++ )
  816. {
  817. container.removeChildAt(0);
  818. }
  819. container.addChild(child);
  820. }
  821. public function get Avatar():Sprite
  822. {
  823. return this;
  824. }
  825. public function set Repoter(repoter:IReport)
  826. {
  827. _repoter = repoter;
  828. }
  829. //对深度接口的实现
  830. public function get Depth():int { return _depth; }
  831. public function set Depth(depth:int) { _depth = depth; }
  832. //对IAvatar接口实现
  833. public function get A_X():Number { return this.x; }
  834. public function get A_Y():Number { return this.y; }
  835. //对IControllerClickAble接口的实现
  836. public function OnClick():Boolean//Exit?//返回一个标准返回态度的决定,即是否让ControllerBase中函数的子函数继续执行 ,当true则不再执行后续函数
  837. {
  838. var beClickEvt:Avatar_PlayerController_Event = new Avatar_PlayerController_Event(Avatar_PlayerController_Event.BECLICKED);
  839. _repoter.OnReport(beClickEvt);
  840. //trace("MoleClick");
  841. return true;
  842. }
  843. public function get _x():Number
  844. {
  845. return this.x;
  846. }
  847. public function get _y():Number
  848. {
  849. return this.y-25;
  850. }
  851. public function get _width():Number
  852. {
  853. return 25;
  854. }
  855. public function get _height():Number
  856. {
  857. return 52;
  858. }
  859. public function get IsSelfOwner():Boolean
  860. {
  861. return _isSelfOwner;
  862. }
  863. }
  864. }