123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- using CommonAI.Data;
- using CommonAI.Zone;
- using CommonAI.Zone.Helper;
- using CommonAI.Zone.Instance;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using XmdsCommon.Message;
- using XmdsCommon.Plugin;
- using XmdsCommonServer.Message;
- using XmdsCommonServer.Plugin.Units;
- namespace XmdsCommonServer.Plugin
- {
- /// <summary>
- /// 负责组队相关功能.
- /// </summary>
- partial class XmdsVirtual
- {
- private List<string> mTeamList = null;
- public IList<string> TeamList
- {
- get
- {
- if (mTeamList != null)
- {
- return new List<string>(mTeamList);
- }
- else
- {
- return null;
- }
- }
- }
- public int TeamListCount
- {
- get
- {
- return mTeamList == null ? 0 : mTeamList.Count;
- }
- }
- /// <summary>
- /// 接受组队信息.
- /// </summary>
- /// <param name="evt"></param>
- protected void OnReceiveTeamInfoEventR2B(TeamInfoEventR2B evt)
- {
- mTeamList = evt.UUIDList;
- PlayerTeamIntoEventB2C b2c = new PlayerTeamIntoEventB2C();
- b2c.Members = mTeamList;
- this.mUnit.queueEvent(b2c);
- }
- protected void OnReceiveTeamDataEventR2B(TeamDataEventR2B evt)
- {
- if (evt == null)
- {
- return;
- }
- string leaderID = evt.LeaderId;
- var player = this.mUnit as XmdsInstancePlayer;
- if (leaderID == null || string.IsNullOrEmpty(leaderID))
- {
- //离开队伍
- player.Leader = null;
- if(player.TeamVirtual != null)
- {
- if(player.TeamVirtual.TeamLeader == player)
- {
- //我是队长
- player.TeamVirtual.TeamLeader = null;
- }
- else
- {
- //不是队长
- player.TeamVirtual.removeMember(player);
- }
- player.TeamVirtual = null;
- }
- var stateFollow = new SetAutoFollowB2C();
- stateFollow.stateFollow = 0;
- player.queueEvent(stateFollow);
- return;
- }
-
- if(player.PlayerUUID == leaderID)
- {
- XmdsTeamVirtual teamVirtual = player.TeamVirtual;
- //我是队长
- if (teamVirtual == null)
- {
- teamVirtual = XmdsTeamVirtual.createTeamVirtual(player);
- player.TeamVirtual = teamVirtual;
- }
- else
- {
- player.TeamVirtual.changeLeader(player, evt);
- }
- foreach (TeamMemberEventR2B member in evt.TeamMembers)
- {
- string id = member.uuid;
- var tm = player.Parent.getPlayerByUUID(id) as XmdsInstancePlayer;
- if (tm != null)
- {
- //队员已经在场景中
- if(id == leaderID)
- {
- teamVirtual.addMember(tm);
- continue;
- }
- //try to fix cancelGuard bug by wfy 20180109
- //if (tm.TeamVirtual == null)
- //{
- // if (tm.IsGuard)
- // {
- // tm.cancelGuard();
- // }
- //}
- tm.TeamVirtual = teamVirtual;
- bool follow = member.followLeader == 1 ? true : false;
- var perFollow = tm.canFollowTeam;
- tm.canFollowTeam = follow;
- teamVirtual.addMember(tm);
- if (follow)
- {
- if (tm.IsGuard)
- {//try to fix cancelGuard bug by wfy 20180109
- tm.cancelGuard();
- }
- teamVirtual.acceptAutoFollow(tm);
- }
- else
- {
- teamVirtual.cancelAutoFollow(tm);
- }
- if ((perFollow != follow) && tm.IsGuard)
- {
- if (!player.is_dead())
- {
- tm.cancelGuard();
- }
- }
- }
- }
- teamVirtual.changeMemberAutoFollow();
- }
- else
- {
- //我是队员
- var leader = player.Parent.getPlayerByUUID(leaderID) as XmdsInstancePlayer;
- if (leader != null)
- {
- //队长已经在场景中
- if (leader.TeamVirtual == null)
- {
- leader.TeamVirtual = XmdsTeamVirtual.createTeamVirtual(leader);
- }
- else
- {
- leader.TeamVirtual.changeLeader(leader, evt);
- }
- player.TeamVirtual = leader.TeamVirtual;
- foreach (TeamMemberEventR2B member in evt.TeamMembers)
- {
- if (member.uuid == player.PlayerUUID)
- {
- bool follow = member.followLeader == 1 ? true : false;
- var perFollow = player.canFollowTeam;
- player.canFollowTeam = follow;
- player.TeamVirtual.addMember(player);
- if (follow)
- {
- player.TeamVirtual.acceptAutoFollow(player);
- }
- else
- {
- player.TeamVirtual.cancelAutoFollow(player);
- }
- if ((perFollow != follow) && player.IsGuard)
- {
- if (!leader.is_dead())
- {
- player.cancelGuard();
- }
- }
- player.TeamVirtual.changeMemberAutoFollow();
- break;
- }
- }
- }
- }
- }
- //protected void OnReceiveTeamDataEventR2B(TeamDataEventR2B evt)
- //{
- // if(evt == null)
- // {
- // return;
- // }
- // string leaderID = evt.LeaderId;
- // var player = this.mUnit as XmdsInstancePlayer;
- // if (leaderID == null || string.IsNullOrEmpty(leaderID))
- // {
- // player.canFollowTeam = false;
- // player.Leader = null;
- // if (player.TeamInfo != null)
- // {
- // player.TeamInfo.removeMember(player);
- // }
- // player.TeamInfo = null;
- // var stateFollow = new SetAutoFollowB2C();
- // stateFollow.stateFollow = 0;
- // player.queueEvent(stateFollow);
- // return;
- // }
- // XmdsTeamInfo info = player.TeamInfo;
- // if (player.PlayerUUID == leaderID)
- // {
- // if(info == null)
- // {
- // info = XmdsTeamInfo.createTeamInfo(player);
- // info.addMember(player);
- // }
- // info.changeLeader(player);
- // //队长不跟随
- // player.canFollowTeam = false;
- // foreach (TeamMemberEventR2B member in evt.TeamMembers)
- // {
- // string id = member.uuid;
- // var tm = player.Parent.getPlayerByUUID(id) as XmdsInstancePlayer;
- // if(tm != null)
- // {
- // tm.TeamInfo = info;
- // info.addMember(tm);
- // bool follow = member.followLeader == 1 ? true : false;
- // var perCanFollowTeam = tm.canFollowTeam;
- // tm.canFollowTeam = follow;
- // //if(perCanFollowTeam && !follow)
- // if ((perCanFollowTeam && !follow)|| (!perCanFollowTeam && follow))
- // {
- // if (tm.IsGuard)
- // {
- // tm.cancelGuard();
- // }
- // }
- // }
- // }
- // info.changeMemberAutoFollow();
- // }
- // else
- // {
- // var leader = player.Parent.getPlayerByUUID(leaderID) as XmdsInstancePlayer;
- // if (leader != null)
- // {
- // XmdsTeamInfo tInfo = leader.TeamInfo;
- // if(tInfo != null)
- // {
- // player.TeamInfo = tInfo;
- // tInfo.addMember(player);
- // foreach (TeamMemberEventR2B member in evt.TeamMembers)
- // {
- // if (member.uuid == player.PlayerUUID)
- // {
- // bool follow = member.followLeader == 1 ? true : false;
- // var perCanFollowTeam = player.canFollowTeam;
- // player.canFollowTeam = follow;
- // if ((perCanFollowTeam && !follow)|| (!perCanFollowTeam && follow))
- // {
- // if (player.IsGuard)
- // {
- // player.cancelGuard();
- // }
- // }
- // break;
- // }
- // }
- // tInfo.changeMemberAutoFollow();
- // }
- // }
- // }
- //}
- /// <summary>
- /// 是否为队友.
- /// </summary>
- /// <param name="uuid"></param>
- /// <returns></returns>
- public virtual bool IsTeamMember(string uuid)
- {
- //先判断是否是自己.
- if (uuid == this.GetPlayerUUID()) { return true; }
- if (mTeamList == null || mTeamList.Contains(uuid) == false) { return false; }
- return true;
- }
- public virtual bool IsTeamMember(InstanceUnit unit)
- {
- var uuid = (unit.Virtual as XmdsVirtual).GetPlayerUUID();
- return IsTeamMember(uuid);
- }
- /// <summary>
- /// 是否为公会成员.
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public virtual bool IsGuildMember(string id)
- {
- string g = GetGuildID();
- if (string.IsNullOrEmpty(g)) { return false; }
- return g == id ? true : false;
- }
- /// <summary>
- ///是否为同服成员.
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public virtual bool IsServerMember(int id)
- {
- int s = this.GetServerID();
- return s == id ? true : false;
- }
- public virtual int GetBaseSkillID()
- {
- return this.SkillHelper == null ? 0 : this.SkillHelper.GetBaseSkillID();
- }
- /// <summary>
- /// 是否相同阵营势力.
- /// </summary>
- /// <param name="type"></param>
- /// <returns></returns>
- public virtual bool IsCampMember(int type)
- {
- int r = this.GetForceID();
- return type == r ? true : false;
- }
- #region Attackable判定.
- /// <summary>
- /// 是否为同盟.
- /// </summary>
- public virtual bool IsAllies(XmdsVirtual target, SkillTemplate.CastTarget expectTarget, AttackReason reason)
- {
- bool ret = false;
- bool includeSelf = true;
- ret = IsMember(target, this.GetCurPKMode(), includeSelf);
- return ret;
- }
- /// <summary>
- /// 判断是否为友军,不同类型Vitrual逻辑不同.
- /// </summary>
- /// <param name="target"></param>
- /// <param name="mode"></param>
- /// <param name="includeSelf"></param>
- /// <returns></returns>
- public virtual bool IsMember(XmdsVirtual target, PKMode mode, bool includeSelf, bool onlyForTeam = false)
- {
- bool ret = this.mUnit.Force == target.mUnit.Force ? true : false;
- if (ret && !includeSelf && this.mUnit == target.mUnit)
- {
- return false;
- }
- return ret;
- }
- ///////////////////////////////新增组队跟随相关//////////////////////////////
- //protected XmdsTeamInfo teamInfo;
- #endregion
- }
- }
|