XmdsVirtual.Team.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. using CommonAI.Data;
  2. using CommonAI.Zone;
  3. using CommonAI.Zone.Helper;
  4. using CommonAI.Zone.Instance;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using XmdsCommon.Message;
  10. using XmdsCommon.Plugin;
  11. using XmdsCommonServer.Message;
  12. using XmdsCommonServer.Plugin.Units;
  13. namespace XmdsCommonServer.Plugin
  14. {
  15. /// <summary>
  16. /// 负责组队相关功能.
  17. /// </summary>
  18. partial class XmdsVirtual
  19. {
  20. private List<string> mTeamList = null;
  21. public IList<string> TeamList
  22. {
  23. get
  24. {
  25. if (mTeamList != null)
  26. {
  27. return new List<string>(mTeamList);
  28. }
  29. else
  30. {
  31. return null;
  32. }
  33. }
  34. }
  35. public int TeamListCount
  36. {
  37. get
  38. {
  39. return mTeamList == null ? 0 : mTeamList.Count;
  40. }
  41. }
  42. /// <summary>
  43. /// 接受组队信息.
  44. /// </summary>
  45. /// <param name="evt"></param>
  46. protected void OnReceiveTeamInfoEventR2B(TeamInfoEventR2B evt)
  47. {
  48. mTeamList = evt.UUIDList;
  49. PlayerTeamIntoEventB2C b2c = new PlayerTeamIntoEventB2C();
  50. b2c.Members = mTeamList;
  51. this.mUnit.queueEvent(b2c);
  52. }
  53. protected void OnReceiveTeamDataEventR2B(TeamDataEventR2B evt)
  54. {
  55. if (evt == null)
  56. {
  57. return;
  58. }
  59. string leaderID = evt.LeaderId;
  60. var player = this.mUnit as XmdsInstancePlayer;
  61. if (leaderID == null || string.IsNullOrEmpty(leaderID))
  62. {
  63. //离开队伍
  64. player.Leader = null;
  65. if(player.TeamVirtual != null)
  66. {
  67. if(player.TeamVirtual.TeamLeader == player)
  68. {
  69. //我是队长
  70. player.TeamVirtual.TeamLeader = null;
  71. }
  72. else
  73. {
  74. //不是队长
  75. player.TeamVirtual.removeMember(player);
  76. }
  77. player.TeamVirtual = null;
  78. }
  79. var stateFollow = new SetAutoFollowB2C();
  80. stateFollow.stateFollow = 0;
  81. player.queueEvent(stateFollow);
  82. return;
  83. }
  84. if(player.PlayerUUID == leaderID)
  85. {
  86. XmdsTeamVirtual teamVirtual = player.TeamVirtual;
  87. //我是队长
  88. if (teamVirtual == null)
  89. {
  90. teamVirtual = XmdsTeamVirtual.createTeamVirtual(player);
  91. player.TeamVirtual = teamVirtual;
  92. }
  93. else
  94. {
  95. player.TeamVirtual.changeLeader(player, evt);
  96. }
  97. foreach (TeamMemberEventR2B member in evt.TeamMembers)
  98. {
  99. string id = member.uuid;
  100. var tm = player.Parent.getPlayerByUUID(id) as XmdsInstancePlayer;
  101. if (tm != null)
  102. {
  103. //队员已经在场景中
  104. if(id == leaderID)
  105. {
  106. teamVirtual.addMember(tm);
  107. continue;
  108. }
  109. //try to fix cancelGuard bug by wfy 20180109
  110. //if (tm.TeamVirtual == null)
  111. //{
  112. // if (tm.IsGuard)
  113. // {
  114. // tm.cancelGuard();
  115. // }
  116. //}
  117. tm.TeamVirtual = teamVirtual;
  118. bool follow = member.followLeader == 1 ? true : false;
  119. var perFollow = tm.canFollowTeam;
  120. tm.canFollowTeam = follow;
  121. teamVirtual.addMember(tm);
  122. if (follow)
  123. {
  124. if (tm.IsGuard)
  125. {//try to fix cancelGuard bug by wfy 20180109
  126. tm.cancelGuard();
  127. }
  128. teamVirtual.acceptAutoFollow(tm);
  129. }
  130. else
  131. {
  132. teamVirtual.cancelAutoFollow(tm);
  133. }
  134. if ((perFollow != follow) && tm.IsGuard)
  135. {
  136. if (!player.is_dead())
  137. {
  138. tm.cancelGuard();
  139. }
  140. }
  141. }
  142. }
  143. teamVirtual.changeMemberAutoFollow();
  144. }
  145. else
  146. {
  147. //我是队员
  148. var leader = player.Parent.getPlayerByUUID(leaderID) as XmdsInstancePlayer;
  149. if (leader != null)
  150. {
  151. //队长已经在场景中
  152. if (leader.TeamVirtual == null)
  153. {
  154. leader.TeamVirtual = XmdsTeamVirtual.createTeamVirtual(leader);
  155. }
  156. else
  157. {
  158. leader.TeamVirtual.changeLeader(leader, evt);
  159. }
  160. player.TeamVirtual = leader.TeamVirtual;
  161. foreach (TeamMemberEventR2B member in evt.TeamMembers)
  162. {
  163. if (member.uuid == player.PlayerUUID)
  164. {
  165. bool follow = member.followLeader == 1 ? true : false;
  166. var perFollow = player.canFollowTeam;
  167. player.canFollowTeam = follow;
  168. player.TeamVirtual.addMember(player);
  169. if (follow)
  170. {
  171. player.TeamVirtual.acceptAutoFollow(player);
  172. }
  173. else
  174. {
  175. player.TeamVirtual.cancelAutoFollow(player);
  176. }
  177. if ((perFollow != follow) && player.IsGuard)
  178. {
  179. if (!leader.is_dead())
  180. {
  181. player.cancelGuard();
  182. }
  183. }
  184. player.TeamVirtual.changeMemberAutoFollow();
  185. break;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. //protected void OnReceiveTeamDataEventR2B(TeamDataEventR2B evt)
  192. //{
  193. // if(evt == null)
  194. // {
  195. // return;
  196. // }
  197. // string leaderID = evt.LeaderId;
  198. // var player = this.mUnit as XmdsInstancePlayer;
  199. // if (leaderID == null || string.IsNullOrEmpty(leaderID))
  200. // {
  201. // player.canFollowTeam = false;
  202. // player.Leader = null;
  203. // if (player.TeamInfo != null)
  204. // {
  205. // player.TeamInfo.removeMember(player);
  206. // }
  207. // player.TeamInfo = null;
  208. // var stateFollow = new SetAutoFollowB2C();
  209. // stateFollow.stateFollow = 0;
  210. // player.queueEvent(stateFollow);
  211. // return;
  212. // }
  213. // XmdsTeamInfo info = player.TeamInfo;
  214. // if (player.PlayerUUID == leaderID)
  215. // {
  216. // if(info == null)
  217. // {
  218. // info = XmdsTeamInfo.createTeamInfo(player);
  219. // info.addMember(player);
  220. // }
  221. // info.changeLeader(player);
  222. // //队长不跟随
  223. // player.canFollowTeam = false;
  224. // foreach (TeamMemberEventR2B member in evt.TeamMembers)
  225. // {
  226. // string id = member.uuid;
  227. // var tm = player.Parent.getPlayerByUUID(id) as XmdsInstancePlayer;
  228. // if(tm != null)
  229. // {
  230. // tm.TeamInfo = info;
  231. // info.addMember(tm);
  232. // bool follow = member.followLeader == 1 ? true : false;
  233. // var perCanFollowTeam = tm.canFollowTeam;
  234. // tm.canFollowTeam = follow;
  235. // //if(perCanFollowTeam && !follow)
  236. // if ((perCanFollowTeam && !follow)|| (!perCanFollowTeam && follow))
  237. // {
  238. // if (tm.IsGuard)
  239. // {
  240. // tm.cancelGuard();
  241. // }
  242. // }
  243. // }
  244. // }
  245. // info.changeMemberAutoFollow();
  246. // }
  247. // else
  248. // {
  249. // var leader = player.Parent.getPlayerByUUID(leaderID) as XmdsInstancePlayer;
  250. // if (leader != null)
  251. // {
  252. // XmdsTeamInfo tInfo = leader.TeamInfo;
  253. // if(tInfo != null)
  254. // {
  255. // player.TeamInfo = tInfo;
  256. // tInfo.addMember(player);
  257. // foreach (TeamMemberEventR2B member in evt.TeamMembers)
  258. // {
  259. // if (member.uuid == player.PlayerUUID)
  260. // {
  261. // bool follow = member.followLeader == 1 ? true : false;
  262. // var perCanFollowTeam = player.canFollowTeam;
  263. // player.canFollowTeam = follow;
  264. // if ((perCanFollowTeam && !follow)|| (!perCanFollowTeam && follow))
  265. // {
  266. // if (player.IsGuard)
  267. // {
  268. // player.cancelGuard();
  269. // }
  270. // }
  271. // break;
  272. // }
  273. // }
  274. // tInfo.changeMemberAutoFollow();
  275. // }
  276. // }
  277. // }
  278. //}
  279. /// <summary>
  280. /// 是否为队友.
  281. /// </summary>
  282. /// <param name="uuid"></param>
  283. /// <returns></returns>
  284. public virtual bool IsTeamMember(string uuid)
  285. {
  286. //先判断是否是自己.
  287. if (uuid == this.GetPlayerUUID()) { return true; }
  288. if (mTeamList == null || mTeamList.Contains(uuid) == false) { return false; }
  289. return true;
  290. }
  291. public virtual bool IsTeamMember(InstanceUnit unit)
  292. {
  293. var uuid = (unit.Virtual as XmdsVirtual).GetPlayerUUID();
  294. return IsTeamMember(uuid);
  295. }
  296. /// <summary>
  297. /// 是否为公会成员.
  298. /// </summary>
  299. /// <param name="id"></param>
  300. /// <returns></returns>
  301. public virtual bool IsGuildMember(string id)
  302. {
  303. string g = GetGuildID();
  304. if (string.IsNullOrEmpty(g)) { return false; }
  305. return g == id ? true : false;
  306. }
  307. /// <summary>
  308. ///是否为同服成员.
  309. /// </summary>
  310. /// <param name="id"></param>
  311. /// <returns></returns>
  312. public virtual bool IsServerMember(int id)
  313. {
  314. int s = this.GetServerID();
  315. return s == id ? true : false;
  316. }
  317. public virtual int GetBaseSkillID()
  318. {
  319. return this.SkillHelper == null ? 0 : this.SkillHelper.GetBaseSkillID();
  320. }
  321. /// <summary>
  322. /// 是否相同阵营势力.
  323. /// </summary>
  324. /// <param name="type"></param>
  325. /// <returns></returns>
  326. public virtual bool IsCampMember(int type)
  327. {
  328. int r = this.GetForceID();
  329. return type == r ? true : false;
  330. }
  331. #region Attackable判定.
  332. /// <summary>
  333. /// 是否为同盟.
  334. /// </summary>
  335. public virtual bool IsAllies(XmdsVirtual target, SkillTemplate.CastTarget expectTarget, AttackReason reason)
  336. {
  337. bool ret = false;
  338. bool includeSelf = true;
  339. ret = IsMember(target, this.GetCurPKMode(), includeSelf);
  340. return ret;
  341. }
  342. /// <summary>
  343. /// 判断是否为友军,不同类型Vitrual逻辑不同.
  344. /// </summary>
  345. /// <param name="target"></param>
  346. /// <param name="mode"></param>
  347. /// <param name="includeSelf"></param>
  348. /// <returns></returns>
  349. public virtual bool IsMember(XmdsVirtual target, PKMode mode, bool includeSelf, bool onlyForTeam = false)
  350. {
  351. bool ret = this.mUnit.Force == target.mUnit.Force ? true : false;
  352. if (ret && !includeSelf && this.mUnit == target.mUnit)
  353. {
  354. return false;
  355. }
  356. return ret;
  357. }
  358. ///////////////////////////////新增组队跟随相关//////////////////////////////
  359. //protected XmdsTeamInfo teamInfo;
  360. #endregion
  361. }
  362. }