XmdsTeamVirtual.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. if (player.CurrentState is StateFollowLeader)
  73. {
  74. player.doSomething();
  75. }
  76. break;
  77. }
  78. }
  79. }
  80. public bool acceptAutoFollow(XmdsInstancePlayer player)
  81. {
  82. for (int i = 0; i < this.teamMembers.Count; i++)
  83. {
  84. if (teamMembers[i].PlayerUUID == player.PlayerUUID)
  85. {
  86. player.canFollowTeam = true;
  87. this.mTeamFollow.addFollowMember(player);
  88. return true;
  89. }
  90. }
  91. return false;
  92. //if (this.teamMembers.Contains(player))
  93. //{
  94. // player.canFollowTeam = true;
  95. // this.mTeamFollow.addFollowMember(player);
  96. // //this.mTeamFollow.changeMembersFollow();
  97. //}
  98. }
  99. public void removeMember(XmdsInstancePlayer player)
  100. {
  101. for (int i = 0; i < this.teamMembers.Count; i++)
  102. {
  103. if (teamMembers[i].PlayerUUID == player.PlayerUUID)
  104. {
  105. cancelAutoFollow(player);
  106. this.teamMembers.Remove(player);
  107. break;
  108. }
  109. }
  110. }
  111. public void changeLeader(XmdsInstancePlayer player, TeamDataEventR2B eventData)
  112. {
  113. if (TeamLeader == null || TeamLeader.PlayerUUID != player.PlayerUUID)
  114. //if (TeamLeader != player)
  115. {
  116. var oldLeader = TeamLeader;
  117. TeamLeader = player;
  118. if (TeamLeader != null)
  119. {
  120. TeamLeader.Leader = null;
  121. TeamLeader.canFollowTeam = false;
  122. this.mTeamFollow.removeFollowMember(TeamLeader);
  123. if (TeamLeader.IsGuard)
  124. {
  125. var guard = TeamLeader.IsGuard;
  126. //TeamLeader.cancelGuard();
  127. SetAutoBattleB2C evt = new SetAutoBattleB2C();
  128. evt.isAutoBattle = guard ? 1 : 0;
  129. TeamLeader.queueEvent(evt);
  130. }
  131. var stateFollow = new SetAutoFollowB2C();
  132. stateFollow.stateFollow = 0;
  133. TeamLeader.queueEvent(stateFollow);
  134. }
  135. if (oldLeader != null && eventData != null && eventData.ContainMem(oldLeader.PlayerUUID))
  136. {
  137. oldLeader.Leader = TeamLeader;
  138. //oldLeader.canFollowTeam = true;
  139. // this.mTeamFollow.addFollowMember(oldLeader);
  140. if (oldLeader.IsGuard)
  141. {
  142. oldLeader.cancelGuard();
  143. SetAutoBattleB2C evt = new SetAutoBattleB2C();
  144. evt.isAutoBattle = 0;
  145. oldLeader.queueEvent(evt);
  146. }
  147. }
  148. //this.mTeamFollow.changeMembersFollow(this);
  149. }
  150. }
  151. public void notifyTeamerRide()
  152. {
  153. if (TeamLeader != null)
  154. {
  155. for (int i = 0; i < teamMembers.Count; i++)
  156. {
  157. var member = teamMembers[i];
  158. if (member != TeamLeader && member.canFollowTeam)
  159. {
  160. var virt = member.Virtual as XmdsCommonServer.Plugin.XmdsVirtual;
  161. if (!virt.IsMounted && !virt.IsInDebuffStatus())
  162. {
  163. PlayerSummonMountEventR2B r2b = new PlayerSummonMountEventR2B();
  164. r2b.TimeMS = 0;
  165. r2b.IsSummonMount = true;
  166. member.VirtualPlayer.ReceiveMsgR2B(r2b);
  167. }
  168. }
  169. }
  170. }
  171. }
  172. /** 根据玩家宠物,获取队伍属性加成 */
  173. public int GetTeamFateValue(UnitFateType fateType)
  174. {
  175. if (fateType < UnitFateType.One || fateType > UnitFateType.Five)
  176. {
  177. return 0;
  178. }
  179. int type = (int)fateType - 1;
  180. //每10s钟,重新获取下加成值
  181. if (mFateRefreshTime[type] + 10 < CommonLang.CUtils.localTimeMS)
  182. {
  183. mFateValue[type] = 0;
  184. for (int i = 0; i < this.teamMembers.Count; i++)
  185. {
  186. mFateValue[type] = Math.Max(mFateValue[type], teamMembers[i].Virtual.GetPetTalentAddition(fateType));
  187. }
  188. mFateRefreshTime[type] = CommonLang.CUtils.localTimeMS;
  189. }
  190. return mFateValue[type];
  191. }
  192. /** 获取队伍成员 */
  193. public List<XmdsInstancePlayer> GetTeamMembers(){
  194. return this.teamMembers;
  195. }
  196. public class TeamFollow
  197. {
  198. private XmdsTeamVirtual mTeamVirtual;
  199. private List<XmdsInstancePlayer> followMembers;
  200. public TeamFollow(XmdsTeamVirtual mTeamVirtual)
  201. {
  202. this.mTeamVirtual = mTeamVirtual;
  203. followMembers = new List<XmdsInstancePlayer>();
  204. }
  205. public void addFollowMember(XmdsInstancePlayer player)
  206. {
  207. bool found = false;
  208. for (int i = 0; i < followMembers.Count; i++)
  209. {
  210. if (followMembers[i].PlayerUUID == player.PlayerUUID)
  211. {
  212. found = true;
  213. break;
  214. }
  215. }
  216. if (!found)
  217. {
  218. followMembers.Add(player);
  219. }
  220. }
  221. public void removeFollowMember(XmdsInstancePlayer player)
  222. {
  223. followMembers.RemoveAll((e) => e.PlayerUUID == player.PlayerUUID);
  224. }
  225. public void changeMembersFollow(XmdsTeamVirtual team)
  226. {
  227. for(byte i = 0; i < followMembers.Count; i++)
  228. {
  229. var member = followMembers[i];
  230. member.FollowIndex = i;
  231. mTeamVirtual.TeamLeader = team.TeamLeader;
  232. member.Leader = team.TeamLeader;
  233. if (team.TeamLeader != null
  234. && member.Leader.Enable && member.Parent == mTeamVirtual.TeamLeader.Parent)
  235. {
  236. if(member.Enable && member.canFollowTeam)
  237. {
  238. member.moveToLeader();
  239. }
  240. else
  241. {
  242. member.Leader = null;
  243. }
  244. }
  245. }
  246. }
  247. }
  248. }