using CommonAI.Data; using CommonLang; using System; using System.Collections.Generic; using System.Linq; using System.Text; using XmdsCommon.Message; using XmdsCommonServer.Message; using XmdsCommonServer.Plugin.Units; public class XmdsTeamVirtual { private XmdsInstancePlayer mTeamLeader; private List teamMembers = null; private TeamFollow mTeamFollow; //队伍玩家宠物的天命数据加成 private long[] mFateRefreshTime = new long[5]; private int[] mFateValue = new int[5]; public XmdsInstancePlayer TeamLeader { set { mTeamLeader = value; } get { return mTeamLeader; } } public bool isTeamLeader(XmdsInstancePlayer player) { return mTeamLeader == player; } public bool isTeamLeader(string uuid) { if (mTeamLeader != null) { return mTeamLeader.PlayerUUID == uuid; } return false; } public static XmdsTeamVirtual createTeamVirtual(XmdsInstancePlayer leader) { var teamVirtual = new XmdsTeamVirtual(); teamVirtual.mTeamFollow = new TeamFollow(teamVirtual); teamVirtual.changeLeader(leader, null); return teamVirtual; } public void changeMemberAutoFollow() { this.mTeamFollow.changeMembersFollow(this); } public void addMember(XmdsInstancePlayer player) { if (this.teamMembers == null) { this.teamMembers = new List(); } if (!this.teamMembers.Contains(player)) { teamMembers.RemoveAll((e) => e.PlayerUUID == player.PlayerUUID); this.teamMembers.Add(player); } } public void cancelAutoFollow(XmdsInstancePlayer player) { for (int i = 0; i < this.teamMembers.Count; i++) { if (this.teamMembers[i].PlayerUUID == player.PlayerUUID) { player.canFollowTeam = false; this.mTeamFollow.removeFollowMember(player); if (player.CurrentState is StateFollowLeader) { player.doSomething(); } break; } } } public bool acceptAutoFollow(XmdsInstancePlayer player) { for (int i = 0; i < this.teamMembers.Count; i++) { if (teamMembers[i].PlayerUUID == player.PlayerUUID) { player.canFollowTeam = true; this.mTeamFollow.addFollowMember(player); return true; } } return false; //if (this.teamMembers.Contains(player)) //{ // player.canFollowTeam = true; // this.mTeamFollow.addFollowMember(player); // //this.mTeamFollow.changeMembersFollow(); //} } public void removeMember(XmdsInstancePlayer player) { for (int i = 0; i < this.teamMembers.Count; i++) { if (teamMembers[i].PlayerUUID == player.PlayerUUID) { cancelAutoFollow(player); this.teamMembers.Remove(player); break; } } } public void changeLeader(XmdsInstancePlayer player, TeamDataEventR2B eventData) { if (TeamLeader == null || TeamLeader.PlayerUUID != player.PlayerUUID) //if (TeamLeader != player) { var oldLeader = TeamLeader; TeamLeader = player; if (TeamLeader != null) { TeamLeader.Leader = null; TeamLeader.canFollowTeam = false; this.mTeamFollow.removeFollowMember(TeamLeader); if (TeamLeader.IsGuard) { var guard = TeamLeader.IsGuard; //TeamLeader.cancelGuard(); SetAutoBattleB2C evt = new SetAutoBattleB2C(); evt.isAutoBattle = guard ? 1 : 0; TeamLeader.queueEvent(evt); } var stateFollow = new SetAutoFollowB2C(); stateFollow.stateFollow = 0; TeamLeader.queueEvent(stateFollow); } if (oldLeader != null && eventData != null && eventData.ContainMem(oldLeader.PlayerUUID)) { oldLeader.Leader = TeamLeader; //oldLeader.canFollowTeam = true; // this.mTeamFollow.addFollowMember(oldLeader); if (oldLeader.IsGuard) { oldLeader.cancelGuard(); SetAutoBattleB2C evt = new SetAutoBattleB2C(); evt.isAutoBattle = 0; oldLeader.queueEvent(evt); } } //this.mTeamFollow.changeMembersFollow(this); } } public void notifyTeamerRide() { if (TeamLeader != null) { for (int i = 0; i < teamMembers.Count; i++) { var member = teamMembers[i]; if (member != TeamLeader && member.canFollowTeam) { var virt = member.Virtual as XmdsCommonServer.Plugin.XmdsVirtual; if (!virt.IsMounted && !virt.IsInDebuffStatus()) { PlayerSummonMountEventR2B r2b = new PlayerSummonMountEventR2B(); r2b.TimeMS = 0; r2b.IsSummonMount = true; member.VirtualPlayer.ReceiveMsgR2B(r2b); } } } } } /** 根据玩家宠物,获取队伍属性加成 */ public int GetTeamFateValue(UnitFateType fateType) { if (fateType < UnitFateType.One || fateType > UnitFateType.Five) { return 0; } int type = (int)fateType - 1; //每10s钟,重新获取下加成值 if (mFateRefreshTime[type] + 10 < CommonLang.CUtils.localTimeMS) { mFateValue[type] = 0; for (int i = 0; i < this.teamMembers.Count; i++) { mFateValue[type] = Math.Max(mFateValue[type], teamMembers[i].Virtual.GetPetTalentAddition(fateType)); } mFateRefreshTime[type] = CommonLang.CUtils.localTimeMS; } return mFateValue[type]; } /** 获取队伍成员 */ public List GetTeamMembers(){ return this.teamMembers; } public class TeamFollow { private XmdsTeamVirtual mTeamVirtual; private List followMembers; public TeamFollow(XmdsTeamVirtual mTeamVirtual) { this.mTeamVirtual = mTeamVirtual; followMembers = new List(); } public void addFollowMember(XmdsInstancePlayer player) { bool found = false; for (int i = 0; i < followMembers.Count; i++) { if (followMembers[i].PlayerUUID == player.PlayerUUID) { found = true; break; } } if (!found) { followMembers.Add(player); } } public void removeFollowMember(XmdsInstancePlayer player) { followMembers.RemoveAll((e) => e.PlayerUUID == player.PlayerUUID); } public void changeMembersFollow(XmdsTeamVirtual team) { for(byte i = 0; i < followMembers.Count; i++) { var member = followMembers[i]; member.FollowIndex = i; mTeamVirtual.TeamLeader = team.TeamLeader; member.Leader = team.TeamLeader; if (team.TeamLeader != null && member.Leader.Enable && member.Parent == mTeamVirtual.TeamLeader.Parent) { if(member.Enable && member.canFollowTeam) { member.moveToLeader(); } else { member.Leader = null; } } } } } }