PageRenderTime 132ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/com/lele/Manager/PlayerManager.as

https://gitlab.com/Treeky-NULL/LezaiNiubi
ActionScript | 721 lines | 667 code | 25 blank | 29 comment | 89 complexity | a3538e0e2b151f571c82a1cdc33f957e MD5 | raw file
  1. package com.lele.Manager
  2. {
  3. import com.lele.Controller.Avatar.Enum.AvatarState;
  4. import com.lele.Data.IClothAnimation;
  5. import com.lele.Data.IThrowItemAnimationData;
  6. import com.lele.Manager.Events.APIEvent;
  7. import com.lele.Map.ThrowItemBase;
  8. import com.lele.MathTool.LeleMath;
  9. import com.lele.Data.GloableData;
  10. import com.lele.Controller.Avatar.CAvatar;
  11. import com.lele.Controller.Avatar.Events.Avatar_PlayerController_Event;
  12. import com.lele.Controller.Avatar.Interface.IAvatar;
  13. import com.lele.Controller.Avatar.Interface.ICommunication;
  14. import com.lele.Controller.NetWorkController;
  15. import com.lele.Controller.PlayerController;
  16. import com.lele.Data.IAnimationData;
  17. import com.lele.Manager.Events.App_Game_ManagerEvent;
  18. import com.lele.Manager.Events.ManagerEventBase;
  19. import com.lele.Manager.Events.Player_Game_ManagerEvent;
  20. import com.lele.Manager.Events.PLC_Player_ManagerEvent;
  21. import com.lele.Manager.Interface.IReport;
  22. import com.lele.Manager.Interface.IResourceLoader;
  23. import flash.display.Loader;
  24. import flash.display.MovieClip;
  25. import flash.display.Sprite;
  26. import flash.events.Event;
  27. import flash.events.TimerEvent;
  28. import flash.geom.Point;
  29. import flash.net.URLRequest;
  30. import flash.utils.getDefinitionByName;
  31. import flash.utils.getQualifiedClassName;
  32. import flash.utils.Timer;
  33. /**
  34. * ...
  35. * @author Lele
  36. */
  37. public class PlayerManager extends Sprite implements IReport
  38. {
  39. private var _chatStyle:Class;
  40. private var _resourceLoader:IResourceLoader;
  41. private var _repoter:IReport;
  42. private var _playerController:PlayerController;
  43. private var _playerAvatar:CAvatar;
  44. private var _animationData:IAnimationData;
  45. private var _moleData:Object;
  46. private var _multiplyPlayer:Array;
  47. private const _stateCheckTime:int = 5000;//这里是毫秒
  48. private var _stateCheckTimer:Timer;
  49. private var _throwItemAnimationData:IThrowItemAnimationData;
  50. public function PlayerManager(resourceLoader:IResourceLoader,report:IReport)
  51. {
  52. _moleData = new Object();
  53. _multiplyPlayer = new Array();
  54. _playerController = new PlayerController(this);
  55. _resourceLoader = resourceLoader;
  56. _repoter = report;
  57. _stateCheckTimer = new Timer(_stateCheckTime);
  58. _stateCheckTimer.addEventListener(TimerEvent.TIMER, AvatarStateCheck);
  59. _stateCheckTimer.start();
  60. _playerController.GetNetAvatarArray = GetNetAvatars;
  61. }
  62. public function get playerController():PlayerController
  63. {
  64. return _playerController;
  65. }
  66. public function get playerAvatar():CAvatar
  67. {
  68. return _playerAvatar;
  69. }
  70. public function ResetAvatar():void//重置本玩家的Avatar
  71. {
  72. _playerAvatar.Reset();
  73. }
  74. public function LoadAndStart(url:String,useUI:Boolean=false,UIType:String="NULL")
  75. {
  76. _resourceLoader.LoadResource("PlayerManager", "Animation/ThrowItemAnimation.swf", OnLoadThrowItemAnimationComplete);
  77. _resourceLoader.LoadResource("PlayerManager", url, OnLoadComplete, useUI, UIType);
  78. _resourceLoader.LoadResource("PlayerManager", "Animation/skin.swf", OnLoadSkinComplete, useUI, UIType);
  79. _resourceLoader.LoadResource("PlayerManager", "Animation/bone.swf", OnLoadBoneComplete, useUI, UIType);
  80. _resourceLoader.LoadResource("PlayerManager", "Animation/effect.swf", OnLoadEffectComplete, useUI, UIType);
  81. }
  82. public function ResetPlayer()
  83. {
  84. if(_playerController!=null)
  85. _playerController.Reset();
  86. /*var playerAddEvt:APIEvent = new APIEvent(APIEvent.OnPlayerAdded);
  87. playerAddEvt.data = GloableData.TempID;
  88. GameManager.GetEventDispatcher().dispatchEvent(playerAddEvt);*/
  89. }
  90. public function MoveTo(po:Point)
  91. {
  92. _playerController.MoveTo(po);
  93. }
  94. public function AttachTo(sp:Sprite, target:String)
  95. {
  96. trace(sp);
  97. if (target == GloableData.TempID) { _playerAvatar.AddtoOtherLayer(sp); return; }
  98. var iav:IAvatar = GetNetAvatarByID(target);
  99. if (iav != null) { iav.AddtoOtherLayer(sp); }
  100. }
  101. private function OnLoadComplete(evt:Event)
  102. {
  103. _animationData = evt.target.content as IAnimationData;
  104. LoadedCheck();
  105. }
  106. private function OnLoadSkinComplete(evt:Event)
  107. {
  108. _moleData.skin = evt.target.content;
  109. LoadedCheck();
  110. }
  111. private function OnLoadBoneComplete(evt:Event)
  112. {
  113. _moleData.bone = evt.target.content;
  114. LoadedCheck();
  115. }
  116. private function OnLoadEffectComplete(evt:Event)
  117. {
  118. _moleData.effect = evt.target.content;
  119. LoadedCheck();
  120. }
  121. private function OnLoadThrowItemAnimationComplete(evt:Event)//加载投掷物品动画
  122. {
  123. _throwItemAnimationData = evt.target.content as IThrowItemAnimationData;
  124. }
  125. private function GetPlayerByID(ID:String):NetPlayerUnit
  126. {
  127. for (var a:int = 0; a < _multiplyPlayer.length; a++ )
  128. {
  129. if (ID == (_multiplyPlayer[a] as NetPlayerUnit).PlayerID)
  130. {
  131. return _multiplyPlayer[a];
  132. }
  133. }
  134. return null;
  135. }
  136. private function LoadedCheck()
  137. {
  138. if (_animationData != null && _moleData.skin != null && _moleData.bone != null && _moleData.effect != null)
  139. {
  140. _playerAvatar = new CAvatar(_moleData, _animationData, true,GloableData.MoleColor,GloableData.MoleName);
  141. if (_chatStyle != null)
  142. {
  143. _playerAvatar.SetComDialog(new _chatStyle());
  144. }
  145. var loadedEvt:ManagerEventBase =new Player_Game_ManagerEvent(Player_Game_ManagerEvent.PLAYERLOADED)//向上级发送事件
  146. _repoter.OnReport(loadedEvt);
  147. RefreshPlayerDress();
  148. }
  149. }
  150. //refresh playerCloth//临时代码 test 2016 1 24
  151. public function RefreshPlayerDress()
  152. {
  153. _playerAvatar.InitAllDress();
  154. //load cloth //临时代码 test 2016/1/23
  155. if (GloableData.MoleDress_Cloth != "-")
  156. {
  157. _resourceLoader.LoadResource("Animation_Cloth", "Animation/Cloth/"+GloableData.MoleDress_Cloth+".swf", function(evt:Event)
  158. {
  159. _playerAvatar.OnClothLoaded(evt.target.content as IClothAnimation);
  160. },false,"NULL",true);
  161. }
  162. if (GloableData.MoleDress_Shoes != "-")
  163. {
  164. _resourceLoader.LoadResource("Animation_Cloth", "Animation/Cloth/"+GloableData.MoleDress_Shoes+".swf", function(evt:Event)
  165. {
  166. _playerAvatar.OnClothLoaded(evt.target.content as IClothAnimation);
  167. },false,"NULL",true);
  168. }
  169. if (GloableData.MoleDress_Eyes != "-")
  170. {
  171. _resourceLoader.LoadResource("Animation_Cloth", "Animation/Cloth/"+GloableData.MoleDress_Eyes+".swf", function(evt:Event)
  172. {
  173. _playerAvatar.OnClothLoaded(evt.target.content as IClothAnimation);
  174. },false,"NULL",true);
  175. }
  176. if (GloableData.MoleDress_Hand != "-")
  177. {
  178. _resourceLoader.LoadResource("Animation_Cloth", "Animation/Cloth/"+GloableData.MoleDress_Hand+".swf", function(evt:Event)
  179. {
  180. _playerAvatar.OnClothLoaded(evt.target.content as IClothAnimation);
  181. },false,"NULL",true);
  182. }
  183. if (GloableData.MoleDress_Hat != "-")
  184. {
  185. _resourceLoader.LoadResource("Animation_Cloth", "Animation/Cloth/"+GloableData.MoleDress_Hat+".swf", function(evt:Event)
  186. {
  187. _playerAvatar.OnClothLoaded(evt.target.content as IClothAnimation);
  188. },false,"NULL",true);
  189. }
  190. if (GloableData.MoleDress_Necklace != "-")
  191. {
  192. _resourceLoader.LoadResource("Animation_Cloth", "Animation/Cloth/"+GloableData.MoleDress_Necklace+".swf", function(evt:Event)
  193. {
  194. _playerAvatar.OnClothLoaded(evt.target.content as IClothAnimation);
  195. },false,"NULL",true);
  196. }
  197. }
  198. //获取所有网络玩家信息列表
  199. public function GetNetPlayerData():Array//双层Array 第二层 1 id 2 color 3 name
  200. {
  201. var result:Array = new Array();
  202. for (var a:int = 0; a < _multiplyPlayer.length; a++ )
  203. {
  204. var temp:Array = new Array();
  205. temp.push((_multiplyPlayer[a] as NetPlayerUnit).PlayerID);
  206. temp.push((_multiplyPlayer[a] as NetPlayerUnit).PlayerColor);
  207. temp.push((_multiplyPlayer[a] as NetPlayerUnit).PlayerName);
  208. result.push(temp);
  209. }
  210. return result;
  211. }
  212. public function GetNetAvatarByID(id:String):IAvatar
  213. {
  214. return GetPlayerByID(id).Avatar;
  215. }
  216. private function GetNetAvatars(array:Array)
  217. {
  218. if (_multiplyPlayer == null) { return; }
  219. for (var a:int = 0; a < _multiplyPlayer.length; a++)
  220. {
  221. if ((_multiplyPlayer[a] as NetPlayerUnit).Avatar != null)
  222. {
  223. array.push((_multiplyPlayer[a] as NetPlayerUnit).Avatar);
  224. }
  225. }
  226. }
  227. private function MapAddThrowItem(mc:MovieClip)
  228. {
  229. var addto:Player_Game_ManagerEvent = new Player_Game_ManagerEvent(Player_Game_ManagerEvent.ADDITEMTOMAPFRONT);
  230. addto.ADDITEMTOMAPFRONT_sprite = mc;
  231. _repoter.OnReport(addto);
  232. }
  233. //撞击位置Avatar做动作
  234. private function CheckAndDoAction(exp:Point, action:String, dir:String,hurt:Number=0)
  235. {
  236. for (var a:int = 0; a < _multiplyPlayer.length; a++ )
  237. {
  238. if ((_multiplyPlayer[a] as NetPlayerUnit).GetAvatarState() == AvatarState.SWIM)
  239. {
  240. continue;
  241. }
  242. var tempAvatar:IAvatar = (_multiplyPlayer[a] as NetPlayerUnit).Avatar;
  243. if (LeleMath.CheckArea(exp.x, tempAvatar.A_X - tempAvatar.Avatar.width / 2, tempAvatar.A_X + tempAvatar.Avatar.width / 2))
  244. {
  245. if (LeleMath.CheckArea(exp.y, tempAvatar.A_Y - tempAvatar.Avatar.height / 2, tempAvatar.A_Y + tempAvatar.Avatar.height / 2))
  246. {
  247. tempAvatar.DoAction(action, dir);
  248. }
  249. }
  250. }
  251. if (_playerController.AState != AvatarState.SWIM)
  252. {
  253. if (LeleMath.CheckArea(exp.x, _playerAvatar.A_X - _playerAvatar.Avatar.width / 2, _playerAvatar.A_X + _playerAvatar.Avatar.width / 2))
  254. {
  255. if (LeleMath.CheckArea(exp.y, _playerAvatar.A_Y - _playerAvatar.Avatar.height / 2, _playerAvatar.A_Y + _playerAvatar.Avatar.height / 2))
  256. {
  257. //这里hurt代码,触发被打击到事件
  258. var apiEvent:APIEvent = new APIEvent(APIEvent.OnHurt);
  259. apiEvent.data = hurt;
  260. GameManager.GetEventDispatcher().dispatchEvent(apiEvent);
  261. _playerAvatar.DoAction(action, dir);
  262. }
  263. }
  264. }
  265. }
  266. private function AvatarStateCheck(evt:Event)
  267. {
  268. for (var i:int = 0; i < _multiplyPlayer.length; i++ )
  269. {
  270. (_multiplyPlayer[i] as NetPlayerUnit).AvatarStateCheck();
  271. }
  272. _playerController.AvatarStateCheck();
  273. }
  274. public function OnReport(evt:Event):void
  275. {
  276. var event:PLC_Player_ManagerEvent = evt as PLC_Player_ManagerEvent;
  277. switch(event.EvtType)
  278. {
  279. case PLC_Player_ManagerEvent.LOCALPLAYERMOVE:
  280. {
  281. var eventToSend:Player_Game_ManagerEvent = new Player_Game_ManagerEvent(Player_Game_ManagerEvent.LOCALPLAYERMOVE);
  282. eventToSend.LOCALPLAYERMOVE_target = event.LOCALPLAYERMOVE_target;
  283. _repoter.OnReport(eventToSend);
  284. break;
  285. }
  286. case PLC_Player_ManagerEvent.LOCALPLAYERDOACTION:
  287. {
  288. var ets:Player_Game_ManagerEvent = new Player_Game_ManagerEvent(Player_Game_ManagerEvent.LOCALPLAYERDOACTION);
  289. ets.LOCALPLAYERDOACTION_dir = event.LOCALPLAYERDOACTION_dir;
  290. ets.LOCALPLAYERDOACTION_name = event.LOCALPLAYERDOACTION_name;
  291. _repoter.OnReport(ets);
  292. break;
  293. }
  294. case PLC_Player_ManagerEvent.LOCALPLAYERBECLICK:
  295. {
  296. //打开玩家面板
  297. var startUserInfoPanel:Player_Game_ManagerEvent = new Player_Game_ManagerEvent(Player_Game_ManagerEvent.LOADSTARTAPP);
  298. startUserInfoPanel.LOADSTARTAPP_name = "UserInfoPanelApp";
  299. startUserInfoPanel.LOADSTARTAPP_useUI = false;
  300. startUserInfoPanel.LOADSTARTAPP_params = null;
  301. _repoter.OnReport(startUserInfoPanel);
  302. break;
  303. }
  304. case PLC_Player_ManagerEvent.LOCALMAPCLICKED:
  305. {
  306. var mbcG:Player_Game_ManagerEvent = new Player_Game_ManagerEvent(Player_Game_ManagerEvent.LOCALMAPCLICKED);
  307. mbcG.LOCALMAPCLICKED_position =event.LOCALMAPCLICKED_position;
  308. _repoter.OnReport(mbcG);
  309. break;
  310. }
  311. }
  312. }
  313. public function OnReceive(evt:Event):void//接收上级命令
  314. {
  315. var recEvt:Player_Game_ManagerEvent = evt as Player_Game_ManagerEvent;
  316. switch(recEvt.EvtType)
  317. {
  318. case Player_Game_ManagerEvent.ONTHROWITEM_GAME:
  319. {
  320. if ((recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_owner == "this")
  321. {
  322. if (_playerController.AState == AvatarState.SWIM) { return; }
  323. //创建投掷物品实例
  324. var itemStyle:ThrowItemBase = _throwItemAnimationData.GetThrowItemByName((recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_itemStyle);
  325. //3级回调
  326. var tempFunc3:Function = function(position:Point) {
  327. CheckAndDoAction(position, (recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_actionName, (recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_actionDir,(recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_blood);
  328. }
  329. //设置回调
  330. var tempFunc:Function = function(position:Point):void
  331. {
  332. //传播网络事件
  333. var callNet:Player_Game_ManagerEvent = new Player_Game_ManagerEvent(Player_Game_ManagerEvent.CALLNETTHROWITEM);
  334. callNet.CALLNETTHROWITEM_action = (recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_actionName;
  335. callNet.CALLNETTHROWITEM_blood = (recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_blood;
  336. callNet.CALLNETTHROWITEM_dir = (recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_actionDir;
  337. callNet.CALLNETTHROWITEM_itemStyle = (recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_itemStyle;
  338. callNet.CALLNETTHROWITEM_position = new Point(position.x, position.y);
  339. _repoter.OnReport(callNet);
  340. MapAddThrowItem(itemStyle);
  341. itemStyle.SetCallBack(tempFunc3);
  342. //2级回调
  343. var tempFunc2:Function = function() {
  344. itemStyle.Start(new Point(_playerAvatar.x, _playerAvatar.y - 60), position);
  345. }
  346. _playerAvatar.DoAction("throw",LeleMath.GetDirectionSimple(LeleMath.DealRDifference(LeleMath.GetDigree(new Point(_playerAvatar.x, _playerAvatar.y - 60), position))),tempFunc2);
  347. }
  348. var interact:Player_Game_ManagerEvent = new Player_Game_ManagerEvent(Player_Game_ManagerEvent.INTERACTMOUSECLICK);
  349. interact.INTERACTMOUSECLICK_callBack = tempFunc;
  350. interact.INTERACTMOUSECLICK_style = (recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_aimStyle;
  351. _repoter.OnReport(interact);
  352. }
  353. else
  354. {
  355. var throwCallback:Function = function(position:Point) {
  356. CheckAndDoAction(position, (recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_actionName, (recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_actionDir,(recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_blood);
  357. }
  358. if (GetPlayerByID((recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_owner).GetAvatarState() == AvatarState.SWIM)
  359. {
  360. return;
  361. }
  362. //创建投掷物品实例
  363. var itemStyle:ThrowItemBase = _throwItemAnimationData.GetThrowItemByName((recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_itemStyle);
  364. MapAddThrowItem(itemStyle);
  365. itemStyle.SetCallBack(throwCallback);
  366. //获取控制器
  367. var plut:NetPlayerUnit = GetPlayerByID((recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_owner);
  368. //创建点
  369. var source:Point = new Point(plut.Avatar.Avatar.x, plut.Avatar.Avatar.y-60);
  370. var newPo:Point = (recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_position;
  371. var func2:Function = function() {
  372. itemStyle.Start(source,newPo);
  373. }
  374. GetPlayerByID((recEvt as Player_Game_ManagerEvent).ONTHROWITEM_GAME_owner).DoAction("throw", LeleMath.GetDirectionSimple(LeleMath.DealRDifference(LeleMath.GetDigree(source, newPo))),func2);
  375. }
  376. return;
  377. }
  378. case Player_Game_ManagerEvent.CALLDOACTION_GAME:
  379. {
  380. _playerController.SetStatePlay();
  381. _playerController.DoAction((recEvt as Player_Game_ManagerEvent).CALLDOACTION_GAME_actionName, "dd", function() { if ((recEvt as Player_Game_ManagerEvent).CALLDOACTION_GAME_func != null) { (recEvt as Player_Game_ManagerEvent).CALLDOACTION_GAME_func(); } _playerController.SetStateIdle(); } );
  382. return;
  383. }
  384. case Player_Game_ManagerEvent.CALLCLEANNETPLAYER:
  385. {
  386. for (var a:int = 0; a < _multiplyPlayer.length; a++ )
  387. {
  388. var apiEvt:APIEvent = new APIEvent(APIEvent.OnPlayerRemove);
  389. apiEvt.data = ((_multiplyPlayer[a] as NetPlayerUnit).PlayerID);
  390. GameManager.GetEventDispatcher().dispatchEvent(apiEvt);
  391. (_multiplyPlayer[a] as NetPlayerUnit).Clean();
  392. }
  393. _multiplyPlayer = new Array();
  394. return;
  395. }
  396. case Player_Game_ManagerEvent.NETAVATARACTION_GAME:
  397. {
  398. var netPl:NetPlayerUnit = GetPlayerByID((recEvt as Player_Game_ManagerEvent).NETAVATARACTION_GAME_ID);
  399. if (netPl != null)
  400. netPl.DoAction((recEvt as Player_Game_ManagerEvent).NETAVATARACTION_GAME_name,(recEvt as Player_Game_ManagerEvent).NETAVATARACTION_GAME_direction);
  401. return;
  402. }
  403. case Player_Game_ManagerEvent.ADDNETPLAYER_GAME:
  404. {
  405. if (GloableData.CurrentMap != (recEvt as Player_Game_ManagerEvent).ADDNETPLAYER_GAME_map) {trace("refuse Add"); return ; }
  406. if (GetPlayerByID((recEvt as Player_Game_ManagerEvent).ADDNETPLAYER_GAME_ID) != null ) { trace("refuse Add"); return; }//已经有了
  407. var tempNetUnit:NetPlayerUnit = new NetPlayerUnit((recEvt as Player_Game_ManagerEvent).ADDNETPLAYER_GAME_color, (recEvt as Player_Game_ManagerEvent).ADDNETPLAYER_GAME_spownPoint, _repoter, (recEvt as Player_Game_ManagerEvent).ADDNETPLAYER_GAME_ID,(recEvt as Player_Game_ManagerEvent).ADDNETPLAYER_GAME_name,(recEvt as Player_Game_ManagerEvent).ADDNETPLAYER_GAME_dress).LoadAndStart();
  408. _multiplyPlayer.push(tempNetUnit);
  409. tempNetUnit._styleClass = _chatStyle;
  410. return;
  411. }
  412. case Player_Game_ManagerEvent.NETPLAYERMOVE_GAME:
  413. {
  414. var netPlayer:NetPlayerUnit = GetPlayerByID((recEvt as Player_Game_ManagerEvent).NETPLAYERMOVE_GAME_ID);
  415. if(netPlayer!=null)
  416. netPlayer.Move((recEvt as Player_Game_ManagerEvent).NETPLAYERMOVE_GAME_target);
  417. return;
  418. }
  419. case Player_Game_ManagerEvent.REMOVENETPLAYER_GAME:
  420. {
  421. try
  422. {
  423. var tempUnit:NetPlayerUnit = GetPlayerByID((recEvt as Player_Game_ManagerEvent).REMOVENETPLAYER_GAME_ID);
  424. var toGame:Player_Game_ManagerEvent = new Player_Game_ManagerEvent(Player_Game_ManagerEvent.CALLMAPREMOVENETPLAYER);
  425. toGame.CALLMAPREMOVENETPLAYER_avatar = tempUnit.Avatar;
  426. _repoter.OnReport(toGame);
  427. var apiEvt:APIEvent = new APIEvent(APIEvent.OnPlayerRemove);
  428. apiEvt.data = tempUnit.PlayerID;
  429. GameManager.GetEventDispatcher().dispatchEvent(apiEvt);
  430. }
  431. catch (er:Error)
  432. {
  433. //这个try必报错,问题未知待修复 2015/7/4
  434. }
  435. tempUnit.Clean();
  436. _multiplyPlayer.splice(_multiplyPlayer.indexOf(tempUnit), 1);
  437. return;
  438. }
  439. case Player_Game_ManagerEvent.PASSDIALOGSTYLE_GAME:
  440. {
  441. _chatStyle = (recEvt as Player_Game_ManagerEvent).PASSDIALOGSTYLE_GAME_body;
  442. _playerController.SetMsgDialog(new _chatStyle());
  443. for (var a:int = 0; a < _multiplyPlayer.length; a++ )
  444. {
  445. (_multiplyPlayer[a] as NetPlayerUnit).Avatar.SetComDialog(new _chatStyle());
  446. }
  447. return;
  448. }
  449. case Player_Game_ManagerEvent.SHOWMSG_GAME:
  450. {
  451. if ((recEvt as Player_Game_ManagerEvent).SHOWMSG_GAME_id == "local")
  452. {
  453. //本地
  454. _playerController.SetMsgDialog(new _chatStyle());
  455. _playerController.ShowMsgDialog((recEvt as Player_Game_ManagerEvent).SHOWMSG_GAME_msg);
  456. return;
  457. }
  458. else
  459. {
  460. var tempp:NetPlayerUnit=GetPlayerByID((recEvt as Player_Game_ManagerEvent).SHOWMSG_GAME_id);
  461. if (tempp != null)
  462. {
  463. tempp.Avatar.ShowDialog((recEvt as Player_Game_ManagerEvent).SHOWMSG_GAME_msg);
  464. }
  465. }
  466. return;
  467. }
  468. case Player_Game_ManagerEvent.NCHANGEDRESS_GAME:
  469. {
  470. GetPlayerByID((recEvt as Player_Game_ManagerEvent).NCHANGEDRESS_GAME_id).DoAction("cce", "dd");
  471. GetPlayerByID((recEvt as Player_Game_ManagerEvent).NCHANGEDRESS_GAME_id).RefreshDress((recEvt as Player_Game_ManagerEvent).NCHANGEDRESS_GAME_HENHSC);
  472. return;
  473. }
  474. }
  475. }
  476. }
  477. }
  478. import com.lele.Controller.Avatar.Enum.AvatarState;
  479. import com.lele.Controller.Avatar.Events.NetWorkController_NetPlayerUnit_Event;
  480. import com.lele.Controller.Avatar.Interface.IAvatar;
  481. import com.lele.Controller.NetWorkController;
  482. import com.lele.Data.FriendDataUnit;
  483. import com.lele.Data.IAnimationData;
  484. import com.lele.Data.IClothAnimation;
  485. import com.lele.Manager.Events.APIEvent;
  486. import com.lele.Manager.Events.Player_Game_ManagerEvent;
  487. import com.lele.Manager.Interface.IReport;
  488. import com.lele.Data.GloableData;
  489. import flash.display.Loader;
  490. import flash.events.Event;
  491. import flash.geom.Point;
  492. import flash.net.URLRequest;
  493. import com.lele.Manager.GameManager;
  494. class NetPlayerUnit implements IReport//玩家单元
  495. {
  496. private var _color:String;
  497. private var _name:String;
  498. private var _spownPoint:Point;
  499. private var _dress:String;
  500. private var _unitAnimationData:IAnimationData;
  501. private var _unitMoleData:Object;
  502. private var _unitController:NetWorkController;
  503. private var _unitDressLoaders:Array;
  504. private var _repoter:IReport;//直接向外界的report
  505. private var _playerID:String;
  506. public var _styleClass:Class;
  507. public function NetPlayerUnit(color:String, spownPoint:Point,repoter:IReport,playerID:String,name:String,dress:String)
  508. {
  509. _color = color;
  510. _name = name;
  511. _spownPoint = spownPoint;
  512. _unitMoleData = new Object();
  513. _repoter = repoter;
  514. _playerID = playerID;
  515. _dress = dress;
  516. _unitDressLoaders = new Array();
  517. for (var a:int = 0; a < 6; a++ )
  518. {
  519. _unitDressLoaders.push(new Loader());
  520. }
  521. }
  522. public function LoadAndStart():NetPlayerUnit
  523. {
  524. var skinLoader:Loader = new Loader();
  525. var boneLoader:Loader = new Loader();
  526. var effectLoader:Loader = new Loader();
  527. var animationLoader:Loader = new Loader();
  528. skinLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, OnSkinLoaded);
  529. boneLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, OnBoneLoaded);
  530. effectLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, OnEffectLoaded);
  531. animationLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, OnAnimationLoaded);
  532. skinLoader.load(new URLRequest("Animation/skin.swf"));
  533. boneLoader.load(new URLRequest("Animation/bone.swf"));
  534. effectLoader.load(new URLRequest("Animation/effect.swf"));
  535. animationLoader.load(new URLRequest("Animation/AnimationData.swf"));
  536. return this;
  537. }
  538. public function get PlayerID():String
  539. {
  540. return _playerID;
  541. }
  542. public function get PlayerColor():String
  543. {
  544. return _color;
  545. }
  546. public function get PlayerName():String
  547. {
  548. return _name;
  549. }
  550. public function GetAvatarState():AvatarState
  551. {
  552. return _unitController.AState;
  553. }
  554. public function AvatarStateCheck()
  555. {
  556. if (_unitController == null) { return; }
  557. try
  558. {
  559. _unitController.AvatarStateCheck();
  560. }
  561. catch (er:Error) { trace(er.message); }
  562. }
  563. private function OnSkinLoaded(evt:Event)
  564. {
  565. _unitMoleData.skin = evt.target.content;
  566. LoadedCheck();
  567. }
  568. private function OnBoneLoaded(evt:Event)
  569. {
  570. _unitMoleData.bone = evt.target.content;
  571. LoadedCheck();
  572. }
  573. private function OnEffectLoaded(evt:Event)
  574. {
  575. _unitMoleData.effect = evt.target.content;
  576. LoadedCheck();
  577. }
  578. private function OnAnimationLoaded(evt:Event)
  579. {
  580. _unitAnimationData = evt.target.content;
  581. LoadedCheck();
  582. }
  583. private function LoadedCheck()
  584. {
  585. if (_unitMoleData.skin != null && _unitMoleData.bone != null && _unitMoleData.effect != null && _unitAnimationData != null)
  586. {
  587. _unitController = new NetWorkController(_unitMoleData, _unitAnimationData, _color, _spownPoint, _name);
  588. _unitController.Repoter = this;
  589. var evtToStart:Player_Game_ManagerEvent = new Player_Game_ManagerEvent(Player_Game_ManagerEvent.CALLADDNETPLAYERTOMAP);
  590. evtToStart.CALLADDNETPLAYERTOMAP_iavatar = _unitController._netAvatar;
  591. evtToStart.CALLADDNETPLAYERTOMAP_controller = _unitController;
  592. if (_styleClass != null)
  593. {
  594. Avatar.SetComDialog(new _styleClass());
  595. }
  596. _repoter.OnReport(evtToStart);
  597. LoadDress();
  598. //
  599. //添加网络玩家事件触发,这次是因为AcivityManager添加
  600. //
  601. var netAddevt:APIEvent = new APIEvent(APIEvent.OnPlayerAdded);
  602. netAddevt.data = _playerID;
  603. GameManager.GetEventDispatcher().dispatchEvent(netAddevt);
  604. }
  605. }
  606. ///测试2016 1 23
  607. public function LoadDress()
  608. {
  609. for (var a:int = 0; a < _unitDressLoaders.length; a++ )
  610. {
  611. (_unitDressLoaders[a] as Loader).unloadAndStop(true);
  612. }
  613. var dressTemp:Array = _dress.split("|");
  614. for (var a:int = 0; a < dressTemp.length-1; a++ )
  615. {
  616. if (dressTemp[a] != "-")
  617. {
  618. var clothLoader:Loader = new Loader();
  619. clothLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,OnDressLoaded);
  620. var urlRequest:URLRequest = new URLRequest( "Animation/Cloth/" + dressTemp[a] + ".swf");
  621. clothLoader.load(urlRequest);
  622. _unitDressLoaders[a] = clothLoader;
  623. }
  624. }
  625. }
  626. private function OnDressLoaded(evt:Event)
  627. {
  628. _unitController._netAvatar.OnClothLoaded(evt.target.content as IClothAnimation);
  629. evt.target.removeEventListener(Event.COMPLETE, OnDressLoaded);
  630. }
  631. public function RefreshDress(dressStr:String)
  632. {
  633. _dress = dressStr;
  634. Avatar.InitAllDress();
  635. LoadDress();
  636. }
  637. //以上
  638. ///
  639. public function get Avatar():IAvatar
  640. {
  641. return _unitController._netAvatar;
  642. }
  643. public function DoAction(actName:String, actDir:String,callback:Function=null)
  644. {
  645. _unitController.DoAction(actName, actDir,callback);
  646. }
  647. public function Move(target:Point)
  648. {
  649. _unitController.Move(target);
  650. }
  651. public function OnReport(evt:Event):void
  652. {
  653. var event:NetWorkController_NetPlayerUnit_Event = evt as NetWorkController_NetPlayerUnit_Event;
  654. switch(event.EvtType)
  655. {
  656. case NetWorkController_NetPlayerUnit_Event.SHOWOTHERPLAYERINFO:
  657. var showInfoPanelEvt:Player_Game_ManagerEvent = new Player_Game_ManagerEvent(Player_Game_ManagerEvent.LOADSTARTAPP);
  658. showInfoPanelEvt.LOADSTARTAPP_name = "InfoPanelApp";
  659. var teF:Array = GloableData.FriendData;
  660. var isFriend:Boolean = false;
  661. if (teF != null)
  662. {
  663. for (var b:int = 0; b < teF.length; b++)
  664. {
  665. if ((teF[b] as FriendDataUnit).ID == _playerID)
  666. {
  667. isFriend = true;
  668. break;
  669. }
  670. }
  671. }
  672. var params:Array = new Array();
  673. params.push(_color);
  674. params.push(_name);
  675. params.push(_playerID);
  676. params.push("0");
  677. params.push("0");
  678. params.push("0");
  679. params.push("0");
  680. params.push(isFriend);
  681. showInfoPanelEvt.LOADSTARTAPP_params = params;
  682. showInfoPanelEvt.LOADSTARTAPP_uiType = "";
  683. showInfoPanelEvt.LOADSTARTAPP_useUI = false;
  684. _repoter.OnReport(showInfoPanelEvt);
  685. break;
  686. }
  687. }
  688. public function Clean()
  689. {
  690. _spownPoint = null;
  691. _unitAnimationData = null;
  692. _unitController.Clean();
  693. _unitController = null;
  694. _unitMoleData = null;
  695. }
  696. }