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
{
///
/// 负责组队相关功能.
///
partial class XmdsVirtual
{
private List mTeamList = null;
public IList TeamList
{
get
{
if (mTeamList != null)
{
return new List(mTeamList);
}
else
{
return null;
}
}
}
public int TeamListCount
{
get
{
return mTeamList == null ? 0 : mTeamList.Count;
}
}
///
/// 接受组队信息.
///
///
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();
// }
// }
// }
//}
///
/// 是否为队友.
///
///
///
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);
}
///
/// 是否为公会成员.
///
///
///
public virtual bool IsGuildMember(string id)
{
string g = GetGuildID();
if (string.IsNullOrEmpty(g)) { return false; }
return g == id ? true : false;
}
///
///是否为同服成员.
///
///
///
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();
}
///
/// 是否相同阵营势力.
///
///
///
public virtual bool IsCampMember(int type)
{
int r = this.GetForceID();
return type == r ? true : false;
}
#region Attackable判定.
///
/// 是否为同盟.
///
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;
}
///
/// 判断是否为友军,不同类型Vitrual逻辑不同.
///
///
///
///
///
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
}
}