123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- 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<XmdsInstancePlayer> 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<XmdsInstancePlayer>();
- }
- 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<XmdsInstancePlayer> GetTeamMembers(){
- return this.teamMembers;
- }
- public class TeamFollow
- {
- private XmdsTeamVirtual mTeamVirtual;
- private List<XmdsInstancePlayer> followMembers;
- public TeamFollow(XmdsTeamVirtual mTeamVirtual)
- {
- this.mTeamVirtual = mTeamVirtual;
- followMembers = new List<XmdsInstancePlayer>();
- }
- 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;
- }
- }
- }
- }
- }
- }
|