XmdsTeamVirtual.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. using CommonAI.Data;
  2. using CommonLang;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using XmdsCommon.Message;
  8. using XmdsCommonServer.Message;
  9. using XmdsCommonServer.Plugin.Units;
  10. public class XmdsTeamVirtual
  11. {
  12. private XmdsInstancePlayer mTeamLeader;
  13. private List<XmdsInstancePlayer> teamMembers = null;
  14. private TeamFollow mTeamFollow;
  15. //队伍玩家宠物的天命数据加成
  16. private long [] mFateRefreshTime = new long[5];
  17. private int[] mFateValue = new int[5];
  18. public XmdsInstancePlayer TeamLeader
  19. {
  20. set
  21. {
  22. mTeamLeader = value;
  23. }
  24. get
  25. {
  26. return mTeamLeader;
  27. }
  28. }
  29. public bool isTeamLeader(XmdsInstancePlayer player)
  30. {
  31. return mTeamLeader == player;
  32. }
  33. public bool isTeamLeader(string uuid)
  34. {
  35. if(mTeamLeader != null)
  36. {
  37. return mTeamLeader.PlayerUUID == uuid;
  38. }
  39. return false;
  40. }
  41. public static XmdsTeamVirtual createTeamVirtual(XmdsInstancePlayer leader)
  42. {
  43. var teamVirtual = new XmdsTeamVirtual();
  44. teamVirtual.mTeamFollow = new TeamFollow(teamVirtual);
  45. teamVirtual.changeLeader(leader, null);
  46. return teamVirtual;
  47. }
  48. public void changeMemberAutoFollow()
  49. {
  50. this.mTeamFollow.changeMembersFollow(this);
  51. }
  52. public void addMember(XmdsInstancePlayer player)
  53. {
  54. if(this.teamMembers == null)
  55. {
  56. this.teamMembers = new List<XmdsInstancePlayer>();
  57. }
  58. if (!this.teamMembers.Contains(player))
  59. {
  60. teamMembers.RemoveAll((e) => e.PlayerUUID == player.PlayerUUID);
  61. this.teamMembers.Add(player);
  62. }
  63. }
  64. public void cancelAutoFollow(XmdsInstancePlayer player)
  65. {
  66. for(int i = 0; i < this.teamMembers.Count; i++)
  67. {
  68. if(this.teamMembers[i].PlayerUUID == player.PlayerUUID)
  69. {
  70. player.canFollowTeam = false;
  71. this.mTeamFollow.removeFollowMember(player);
  72. break;
  73. }
  74. }
  75. }
  76. public bool acceptAutoFollow(XmdsInstancePlayer player)
  77. {
  78. for (int i = 0; i < this.teamMembers.Count; i++)
  79. {
  80. if (teamMembers[i].PlayerUUID == player.PlayerUUID)
  81. {
  82. player.canFollowTeam = true;
  83. this.mTeamFollow.addFollowMember(player);
  84. return true;
  85. }
  86. }
  87. return false;
  88. //if (this.teamMembers.Contains(player))
  89. //{
  90. // player.canFollowTeam = true;
  91. // this.mTeamFollow.addFollowMember(player);
  92. // //this.mTeamFollow.changeMembersFollow();
  93. //}
  94. }
  95. public void removeMember(XmdsInstancePlayer player)
  96. {
  97. for(int i = 0;i< this.teamMembers.Count; i++)
  98. {
  99. if(teamMembers[i].PlayerUUID == player.PlayerUUID)
  100. {
  101. cancelAutoFollow(player);
  102. this.teamMembers.Remove(player);
  103. break;
  104. }
  105. }
  106. }
  107. public void changeLeader(XmdsInstancePlayer player, TeamDataEventR2B eventData)
  108. {
  109. if(TeamLeader == null || TeamLeader.PlayerUUID != player.PlayerUUID)
  110. //if (TeamLeader != player)
  111. {
  112. var oldLeader = TeamLeader;
  113. TeamLeader = player;
  114. if (TeamLeader != null)
  115. {
  116. TeamLeader.Leader = null;
  117. TeamLeader.canFollowTeam = false;
  118. this.mTeamFollow.removeFollowMember(TeamLeader);
  119. if (TeamLeader.IsGuard)
  120. {
  121. var guard = TeamLeader.IsGuard;
  122. //TeamLeader.cancelGuard();
  123. SetAutoBattleB2C evt = new SetAutoBattleB2C();
  124. evt.isAutoBattle = guard ? 1 : 0;
  125. TeamLeader.queueEvent(evt);
  126. }
  127. var stateFollow = new SetAutoFollowB2C();
  128. stateFollow.stateFollow = 0;
  129. TeamLeader.queueEvent(stateFollow);
  130. }
  131. if(oldLeader != null && eventData != null && eventData.ContainMem(oldLeader.PlayerUUID))
  132. {
  133. oldLeader.Leader = TeamLeader;
  134. //oldLeader.canFollowTeam = true;
  135. // this.mTeamFollow.addFollowMember(oldLeader);
  136. if (oldLeader.IsGuard)
  137. {
  138. oldLeader.cancelGuard();
  139. SetAutoBattleB2C evt = new SetAutoBattleB2C();
  140. evt.isAutoBattle = 0;
  141. oldLeader.queueEvent(evt);
  142. }
  143. }
  144. //this.mTeamFollow.changeMembersFollow(this);
  145. }
  146. }
  147. public void notifyTeamerRide()
  148. {
  149. if (TeamLeader != null)
  150. {
  151. for (int i = 0; i < teamMembers.Count; i++)
  152. {
  153. var member = teamMembers[i];
  154. if (member != TeamLeader && member.canFollowTeam)
  155. {
  156. var virt = member.Virtual as XmdsCommonServer.Plugin.XmdsVirtual;
  157. if (!virt.IsMounted && !virt.IsInDebuffStatus())
  158. {
  159. PlayerSummonMountEventR2B r2b = new PlayerSummonMountEventR2B();
  160. r2b.TimeMS = 0;
  161. r2b.IsSummonMount = true;
  162. member.VirtualPlayer.ReceiveMsgR2B(r2b);
  163. }
  164. }
  165. }
  166. }
  167. }
  168. /** 根据玩家宠物,获取队伍属性加成 */
  169. public int GetTeamFateValue(UnitFateType fateType)
  170. {
  171. if (fateType < UnitFateType.One || fateType > UnitFateType.Five)
  172. {
  173. return 0;
  174. }
  175. int type = (int)fateType - 1;
  176. //每10s钟,重新获取下加成值
  177. if (mFateRefreshTime[type] + 10 < CommonLang.CUtils.localTimeMS)
  178. {
  179. mFateValue[type] = 0;
  180. for (int i = 0; i < this.teamMembers.Count; i++)
  181. {
  182. mFateValue[type] = Math.Max(mFateValue[type], teamMembers[i].Virtual.GetPetTalentAddition(fateType));
  183. }
  184. mFateRefreshTime[type] = CommonLang.CUtils.localTimeMS;
  185. }
  186. return mFateValue[type];
  187. }
  188. public class TeamFollow
  189. {
  190. private XmdsTeamVirtual mTeamVirtual;
  191. private List<XmdsInstancePlayer> followMembers;
  192. public TeamFollow(XmdsTeamVirtual mTeamVirtual)
  193. {
  194. this.mTeamVirtual = mTeamVirtual;
  195. followMembers = new List<XmdsInstancePlayer>();
  196. }
  197. public void addFollowMember(XmdsInstancePlayer player)
  198. {
  199. bool found = false;
  200. for (int i = 0; i < followMembers.Count; i++)
  201. {
  202. if (followMembers[i].PlayerUUID == player.PlayerUUID)
  203. {
  204. found = true;
  205. break;
  206. }
  207. }
  208. if (!found)
  209. {
  210. followMembers.Add(player);
  211. }
  212. }
  213. public void removeFollowMember(XmdsInstancePlayer player)
  214. {
  215. followMembers.RemoveAll((e) => e.PlayerUUID == player.PlayerUUID);
  216. }
  217. public void changeMembersFollow(XmdsTeamVirtual team)
  218. {
  219. for(byte i = 0; i < followMembers.Count; i++)
  220. {
  221. var member = followMembers[i];
  222. member.FollowIndex = i;
  223. mTeamVirtual.TeamLeader = team.TeamLeader;
  224. member.Leader = team.TeamLeader;
  225. if (team.TeamLeader != null
  226. && member.Leader.Enable && member.Parent == mTeamVirtual.TeamLeader.Parent)
  227. {
  228. if(member.Enable && member.canFollowTeam)
  229. {
  230. member.moveToLeader();
  231. }
  232. else
  233. {
  234. member.Leader = null;
  235. }
  236. }
  237. }
  238. }
  239. }
  240. }