XmdsVirtual_Player.Message.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. using CommonAI.Zone;
  2. using CommonAI.Zone.Helper;
  3. using CommonAI.Zone.Instance;
  4. using CommonAI.Zone.ZoneEditor;
  5. using CommonLang;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using XmdsCommon.EditorData;
  11. using XmdsCommon.Message;
  12. using XmdsCommon.Plugin;
  13. using XmdsCommonServer.Message;
  14. using XmdsCommonServer.Plugin.Scene;
  15. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  16. namespace XmdsCommonServer.Plugin
  17. {
  18. partial class XmdsVirtual_Player
  19. {
  20. #region 协议监听.
  21. public override void ReceiveMsgR2B(object status)
  22. {
  23. if (status == null)
  24. {
  25. FormatLog("ReceiveMsgR2B status is null", null);
  26. return;
  27. }
  28. if (status is XmdsUnitPropEventB2C)
  29. {
  30. OnPlayerPropertiesChanged(status as XmdsUnitPropEventB2C);
  31. }
  32. else if (status is PlayerSkillChangeEventR2B)
  33. {
  34. OnPlayerSkillsChanged(status as PlayerSkillChangeEventR2B);
  35. }
  36. else if (status is XmdsUnitBaseInfoEventB2C)
  37. {
  38. OnPlayerBaseInfoChanged(status as XmdsUnitBaseInfoEventB2C);
  39. }
  40. else if (status is PlayerRebirthEventR2B)
  41. {
  42. OnReceivePlayerRebirthOrder(status as PlayerRebirthEventR2B);
  43. }
  44. else if (status is PlayerSummonMountEventR2B)
  45. {
  46. OnReceivePlayerSummonMountEventR2B(status as PlayerSummonMountEventR2B);
  47. }
  48. else if (status is PlayAvatarEventB2C)
  49. {
  50. OnReceivePlayerAvatarEventB2C(status as PlayAvatarEventB2C);
  51. }
  52. else if (status is SyncPlayerInventorySizeEventR2B)
  53. {
  54. OnReceiveSyncPlayerInventorySizeEventR2B(status as SyncPlayerInventorySizeEventR2B);
  55. }
  56. else if (status is TeamInfoEventR2B)
  57. {
  58. OnReceiveTeamInfoEventR2B(status as TeamInfoEventR2B);
  59. }
  60. else if (status is TeamDataEventR2B)
  61. {
  62. OnReceiveTeamDataEventR2B(status as TeamDataEventR2B);
  63. }
  64. else if (status is PlayerPKLevelChangeEventR2B)
  65. {
  66. OnReceivePlayerPKLvChangeEventR2B(status as PlayerPKLevelChangeEventR2B);
  67. }
  68. else if (status is PlayerPKModeChangeEventR2B)
  69. {
  70. OnReceivePlayerPKModeChangeEventR2B(status as PlayerPKModeChangeEventR2B);
  71. }
  72. else if (status is PlayerPKValueChangeEventR2B)
  73. {
  74. OnReceivePlayerPKValueChangeEventR2B(status as PlayerPKValueChangeEventR2B);
  75. }
  76. else if (status is PropertyChangeEventR2B)
  77. {
  78. OnRceivePropertyChangeEventR2B(status as PropertyChangeEventR2B);
  79. }
  80. else if (status is PetDataChangeEventR2B)
  81. {
  82. OnReceivePetDataChangeEventR2B(status as PetDataChangeEventR2B);
  83. }
  84. else if (status is PetBaseInfoChangeEventR2B)
  85. {
  86. OnReceivePetBaseInfoChangeEventR2B(status as PetBaseInfoChangeEventR2B);
  87. }
  88. else if (status is PetSkillChangeEventR2B)
  89. {
  90. OnReceivePetSkillChangeEventR2B(status as PetSkillChangeEventR2B);
  91. }
  92. else if (status is TeamInventorySizeChangeEventR2B)
  93. {
  94. OnReceiveTeamInventorySizeChangeEventR2B(status as TeamInventorySizeChangeEventR2B);
  95. }
  96. else if (status is PetPropertyChangeEventR2B)
  97. {
  98. OnReceivePetPropertyChangeEventR2B(status as PetPropertyChangeEventR2B);
  99. }
  100. else if (status is PetFollowModeChangeEventR2B)
  101. {
  102. OnReceivePetFollowModeChangeEventR2B(status as PetFollowModeChangeEventR2B);
  103. }
  104. }
  105. /// <summary>
  106. /// 基础属性变更.
  107. /// </summary>
  108. private void OnPlayerBaseInfoChanged(XmdsUnitBaseInfoEventB2C evt)
  109. {
  110. if (evt != null && evt.Props != null)
  111. {
  112. FormatLog("OnPlayerBaseInfoChanged", null);
  113. //重置基础信息.
  114. InitBaseInfo(evt.Props);
  115. SyncPlayerVisibleData();
  116. //广播级事件统一由游戏服转给客户端广播.
  117. this.mUnit.queueEvent(evt);
  118. }
  119. else
  120. {
  121. FormatLog("OnPlayerBaseInfoChanged Error :XmdsUnitBaseInfoEventB2C.Props is null", null);
  122. }
  123. }
  124. /// <summary>
  125. /// 重生通知.
  126. /// </summary>
  127. private void OnReceivePlayerRebirthOrder(PlayerRebirthEventR2B msg)
  128. {
  129. FormatLog("OnReceivePlayerRebirthOrder", null);
  130. if (this.mUnit.IsDead() == true)
  131. {
  132. //Console.WriteLine(" ------- 复活------ " + msg.type);
  133. switch (msg.type)
  134. {
  135. case 1://原地复活.
  136. if(this.mUnit.GetSceneType() >= CommonAI.Data.SceneType.CROSS_SERVER_NEW)
  137. {
  138. DoRebirthInStartRegion(msg);
  139. }
  140. else
  141. {
  142. this.mUnit.startRebirth(msg.HP, msg.MP);
  143. this.mUnit.queueEvent(msg.Callback);
  144. }
  145. break;
  146. case 2://出生点复活.
  147. DoRebirthInStartRegion(msg);
  148. break;
  149. case 3://复活点复活.
  150. {
  151. XmdsServerScene zss = this.mUnit.Parent as XmdsServerScene;
  152. ZoneRegion ret = zss.GetNearestRebirthRegion(this.mUnit.X, this.mUnit.Y, this.mUnit.Force);
  153. if (ret == null)
  154. {
  155. DoRebirthInStartRegion(msg);
  156. }
  157. else
  158. {
  159. this.mUnit.transport(ret.X, ret.Y);
  160. this.mUnit.startRebirth(msg.HP, msg.MP);
  161. this.mUnit.queueEvent(msg.Callback);
  162. }
  163. }
  164. break;
  165. case 4://技能复活.
  166. this.mUnit.startRebirth(msg.HP, msg.MP);
  167. break;
  168. case 5://随机复活点复活
  169. {
  170. XmdsServerScene zss = this.mUnit.Parent as XmdsServerScene;
  171. ZoneRegion ret = zss.GetRandomRebirthRegion(this.mUnit.Force);
  172. if (ret == null)
  173. {
  174. DoRebirthInStartRegion(msg);
  175. }
  176. else
  177. {
  178. this.mUnit.transport(ret.X, ret.Y);
  179. this.mUnit.startRebirth(msg.HP, msg.MP);
  180. this.mUnit.queueEvent(msg.Callback);
  181. }
  182. }
  183. break;
  184. default:
  185. break;
  186. }
  187. }
  188. }
  189. private void DoRebirthInStartRegion(PlayerRebirthEventR2B msg)
  190. {
  191. EditorScene es = this.mUnit.Parent as EditorScene;
  192. ZoneRegion zr = es.GetEditStartRegion(this.mUnit.Force);
  193. if (zr != null)
  194. {
  195. this.mUnit.transport(zr.X, zr.Y);
  196. //log.WarnFormat("无法找到场景ID为{0}阵营为{1}的出生点", es.Data.ID, this.mUnit.Force);
  197. }
  198. else
  199. {
  200. this.mUnit.transport(mBirthPosX, mBirthPosY);
  201. }
  202. this.mUnit.startRebirth(msg.HP, msg.MP);
  203. this.mUnit.queueEvent(msg.Callback);
  204. }
  205. /// <summary>
  206. /// 援救通知.
  207. /// </summary>
  208. private void OnReceivePlayerSaveEventR2B(PlayerSaveEventR2B msg)
  209. {
  210. FormatLog("OnReceivePlayerSaveEventR2B", null);
  211. if (msg.Saver == null || msg.Decedent == null) { return; }
  212. mUnit_OnPickUnit(msg.Saver, msg.Decedent, msg.SaveTime);
  213. }
  214. /// <summary>
  215. /// 召唤坐骑通知.
  216. /// </summary>
  217. private void OnReceivePlayerSummonMountEventR2B(PlayerSummonMountEventR2B evt)
  218. {
  219. //((this.mUnit.Parent as XmdsServerScene).mListener as XmdsZoneNode)
  220. XmdsServerScene scene = this.mUnit.Parent as XmdsServerScene;
  221. FormatLog("OnReceivePlayerSummonMountEventR2B", null);
  222. //需要判断一些特殊状态.晕眩,变身,战斗中等等.
  223. if (evt.IsSummonMount == true)
  224. {
  225. bool canRiding = scene.Data.canRiding;
  226. if (!canRiding || this.IsInPVP() || this.IsInPVE())
  227. {
  228. return;
  229. }
  230. //战斗状态下无法上马或处于异常状态下.
  231. if (IsInDebuffStatus() || IsBusy() || this.mUnit.IsDead())
  232. {
  233. SendMsgToClient(CommonAI.XmdsConstConfig.TIPS_CAN_NOT_RIDE);
  234. return;
  235. }
  236. if(this.mUnit.CurrentActionStatus == UnitActionStatus.DaZuo || this.mUnit.CurrentActionStatus == UnitActionStatus.ClearYaoQi
  237. || this.mUnit.CurrentActionStatus == UnitActionStatus.Pick || this.mUnit.CurrentActionStatus == UnitActionStatus.DaZuoRecoveryAttr)
  238. {
  239. this.mUnit.startIdle(true);
  240. //this.mUnit.SendForceSync();
  241. }
  242. //清除与坐骑状态冲突的BUFF.
  243. ClearSPBuffState();
  244. }
  245. this.StartSummonMount(evt.TimeMS, evt.IsSummonMount, "summonmount");
  246. }
  247. /// <summary>
  248. /// 清除与坐骑状态冲突的BUFF(隐身).
  249. /// </summary>
  250. private void ClearSPBuffState()
  251. {
  252. //取当前所有BUFF,判断如果有隐身BUFF立即解除该BUFF.
  253. using (var buffList = ListObjectPool<InstanceUnit.BuffState>.AllocAutoRelease())
  254. {
  255. InstanceUnit.BuffState bfs = null;
  256. List<XmdsBuffVirtual> list = null;
  257. XmdsBuffProperties prop = null;
  258. BuffTemplate bt = null;
  259. this.mUnit.GetAllBuffStatus(buffList);
  260. if (buffList != null && buffList.Count > 0)
  261. {
  262. for (int i = 0; i < buffList.Count; i++)
  263. {
  264. bfs = buffList[i];
  265. bt = bfs.Data;
  266. prop = bt.Properties as XmdsBuffProperties;
  267. list = prop.GetBuffVirtualList();
  268. if (list != null && list.Count != 0)
  269. {
  270. for (int k = 0; k < list.Count; k++)
  271. {
  272. UnitBuff ub = list[k] as UnitBuff;
  273. if (ub.GetAbilityID() == (int)XmdsBuffProperties.XmdsBuffAbility.Stealth)
  274. {
  275. this.mUnit.removeBuff(bt.ID, "summonmount");
  276. }
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
  283. /// <summary>
  284. /// 收到外观变更.
  285. /// </summary>
  286. private void OnReceivePlayerAvatarEventB2C(PlayAvatarEventB2C evt)
  287. {
  288. string extData = "";
  289. foreach (XmdsAvatarInfo temp in evt.AvatarList)
  290. {
  291. extData += (temp.PartTag + ", " + temp.FileName + "; ");
  292. }
  293. //log.Info("OnReceivePlayAvatarEventB2C: " + this.GetPlayerUUID() + ", " + extData);
  294. if (evt != null)
  295. {
  296. this.mProp.ServerData.AvatarList = evt.AvatarList;
  297. SyncPlayerVisibleData();
  298. this.mUnit.queueEvent(evt);
  299. }
  300. }
  301. /// <summary>
  302. /// 收到同步可用背包格子数量.
  303. /// </summary>
  304. /// <param name="evt"></param>
  305. private void OnReceiveSyncPlayerInventorySizeEventR2B(SyncPlayerInventorySizeEventR2B evt)
  306. {
  307. FormatLog("OnReceiveSyncPlayerInventorySizeEventR2B", null);
  308. SetInventorySize(evt.Size);
  309. }
  310. /// <summary>
  311. /// 单位PK等级变更.
  312. /// </summary>
  313. /// <param name="evt"></param>
  314. private void OnReceivePlayerPKLvChangeEventR2B(PlayerPKLevelChangeEventR2B evt)
  315. {
  316. FormatLog("OnReceivePlayerPKLvChangeEventR2B", null);
  317. this.mProp.ServerData.UnitPKInfo.CurPKLevel = evt.CurPKLv;
  318. SyncPlayerVisibleData();
  319. PlayerPKLvChangeEventB2C evtb2c = new PlayerPKLvChangeEventB2C();
  320. evtb2c.CurLv = evt.CurPKLv;
  321. this.mUnit.queueEvent(evtb2c);
  322. }
  323. /// <summary>
  324. /// 单位PK模式变更.
  325. /// </summary>
  326. /// <param name="evt"></param>
  327. private void OnReceivePlayerPKModeChangeEventR2B(PlayerPKModeChangeEventR2B evt)
  328. {
  329. log.Info("OnReceivePlayerPKLvChangeEventR2B:" + this.mUnit.PlayerUUID + ", " + evt.CurPKMode);
  330. this.mProp.ServerData.UnitPKInfo.CurPKMode = evt.CurPKMode;
  331. SyncPlayerVisibleData();
  332. this.mUnit.queueEvent(new PlayerPKModeChangeEventB2C(this.mUnit.ID, evt.CurPKMode));
  333. }
  334. protected virtual void OnReceivePlayerPKValueChangeEventR2B(PlayerPKValueChangeEventR2B evt)
  335. {
  336. FormatLog("OnReceivePlayerPKValueChangeEventR2B", null);
  337. int c = this.mProp.ServerData.UnitPKInfo.CurPKValue + evt.ChangeValue;
  338. SyncPKValue(c);
  339. }
  340. protected virtual void OnRceivePropertyChangeEventR2B(PropertyChangeEventR2B evt)
  341. {
  342. FormatLog("OnRceivePropertyChangeOrder", null);
  343. bool success = false;
  344. switch (evt.ChangeType)
  345. {
  346. case PropertyChangeEventR2B.PropertyChangeType.HP:
  347. //药水效果加成
  348. int valueExt = (int)(mProp.ServerData.BaseInfo.potionAddition * evt.ChangeValue);
  349. evt.ChangeValue = evt.ChangeValue + valueExt;
  350. if (evt.Duration > 0)
  351. {
  352. mHPRecoveryTask.Init(this, evt, true);
  353. }
  354. else
  355. {
  356. success = AddHP(evt.ChangeValueType, evt.ChangeValue, false);
  357. }
  358. break;
  359. case PropertyChangeEventR2B.PropertyChangeType.NPC:
  360. {
  361. bool sendEvent = false;
  362. //单位未满血满蓝.
  363. if (this.mUnit.IsDead() == false &&
  364. ((this.mUnit.CurrentHP != this.mUnit.MaxHP) ||
  365. (this.mUnit.CurrentMP != this.mUnit.MaxMP)))
  366. {
  367. DoCure();
  368. sendEvent = true;
  369. }
  370. //宠物未满血满蓝.
  371. if (mPet != null && mPet.mUnit.IsDead() == false &&
  372. ((this.mPet.mUnit.CurrentHP != this.mPet.mUnit.MaxHP) ||
  373. (this.mPet.mUnit.CurrentMP != this.mPet.mUnit.MaxMP)))
  374. {
  375. mPet.DoCure();
  376. sendEvent = true;
  377. }
  378. //召唤物.
  379. if (mSummonList != null && mSummonList.Count > 0)
  380. {
  381. XmdsVirtual_SummonUnit zv = null;
  382. for (int i = 0; i < mSummonList.Count; i++)
  383. {
  384. zv = mSummonList[i];
  385. if (zv.mUnit.IsDead() == false &&
  386. ((zv.mUnit.CurrentHP != zv.mUnit.MaxHP ||
  387. zv.mUnit.CurrentMP != zv.mUnit.MaxMP)))
  388. {
  389. sendEvent = true;
  390. mSummonList[i].DoCure();
  391. }
  392. }
  393. }
  394. if (sendEvent)
  395. {
  396. this.mUnit.queueEvent(new NPCCureEventB2C());
  397. }
  398. }
  399. break;
  400. default: break;
  401. }
  402. }
  403. private void OnReceivePetDataChangeEventR2B(PetDataChangeEventR2B evt)
  404. {
  405. FormatLog("OnReceivePetDataChangeEventR2B", null);
  406. switch (evt.OpType)
  407. {
  408. case PetDataChangeEventR2B.PetDataChangeType.Add:
  409. ChangePet(evt.Data);
  410. break;
  411. case PetDataChangeEventR2B.PetDataChangeType.Delete:
  412. DismissPet();
  413. break;
  414. case PetDataChangeEventR2B.PetDataChangeType.Replace:
  415. ChangePet(evt.Data);
  416. break;
  417. case PetDataChangeEventR2B.PetDataChangeType.Reset:
  418. UpdatePetData(evt.Data);
  419. break;
  420. }
  421. }
  422. private void OnReceivePetBaseInfoChangeEventR2B(PetBaseInfoChangeEventR2B evt)
  423. {
  424. FormatLog("OnReceivePetBaseInfoChangeEventR2B", null);
  425. UpdatePetBaseInfo(evt.BaseInfo);
  426. }
  427. private void OnReceivePetSkillChangeEventR2B(PetSkillChangeEventR2B evt)
  428. {
  429. FormatLog("OnReceivePetSkillChangeEventR2B", null);
  430. UpdatePetSkillInfo(evt);
  431. }
  432. private void OnReceiveTeamInventorySizeChangeEventR2B(TeamInventorySizeChangeEventR2B evt)
  433. {
  434. FormatLog("OnReceivePetSkillChangeEventR2B", null);
  435. this.mProp.ServerData.Prop.CurTeamInventorySize = evt.size;
  436. }
  437. private void OnReceivePetPropertyChangeEventR2B(PetPropertyChangeEventR2B evt)
  438. {
  439. FormatLog("OnReceivePetPropertyChangeEventR2B", null);
  440. if (mPet != null)
  441. {
  442. mPet.OnRceivePropertyChangeEventR2B(evt.Order);
  443. }
  444. }
  445. private void OnReceivePetFollowModeChangeEventR2B(PetFollowModeChangeEventR2B evt)
  446. {
  447. FormatLog("OnReceivePetFollowModeChangeEventR2B", null);
  448. if (mPet != null)
  449. {
  450. mPet.OnReceivePetFollowModeChangeEventR2B(evt);
  451. }
  452. }
  453. #endregion
  454. }
  455. }