//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, October 17, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
using System;
|
|
namespace vnxbqy.UI
|
{
|
|
public struct TheirTeam
|
{
|
public int mapId;
|
public int mapEx;//如果mapex 是-1 ,那么意味着是所有分线的集合。
|
public bool matching;
|
public int captainer;
|
public string captainerName;
|
public int realm;
|
public int memberCount;
|
public int levelMin;
|
public int levelMax;
|
|
public TheirTeam(HB904_tagGCSceneTeamRefresh.tagGCSceneTeam _serverInfo)
|
{
|
this.mapId = TeamModel.CURRENTMAP_MISSION;
|
this.mapEx = -1;
|
this.matching = false;
|
this.captainer = (int)_serverInfo.PlayerID;
|
this.captainerName = _serverInfo.PlayerName;
|
this.realm = _serverInfo.RealmLV;
|
this.memberCount = _serverInfo.MemberCount;
|
this.levelMin = _serverInfo.ReqMinLV;
|
this.levelMax = _serverInfo.ReqMaxLV;
|
}
|
|
public TheirTeam(int _mapId, int _mapEx, bool _matching, HB909_tagGCTagMapTeamList.tagGCTagMapTeam _serverInfo)
|
{
|
this.mapId = _mapId;
|
this.mapEx = _mapEx;
|
this.matching = _matching;
|
this.captainer = (int)_serverInfo.PlayerID;
|
this.captainerName = _serverInfo.PlayerName;
|
this.realm = _serverInfo.RealmLV;
|
this.memberCount = _serverInfo.MemberCount;
|
this.levelMin = _serverInfo.ReqMinLV;
|
this.levelMax = _serverInfo.ReqMaxLV;
|
}
|
|
public static int Sort(TheirTeam lhs, TheirTeam rhs)
|
{
|
return lhs.memberCount < 4 && lhs.memberCount > rhs.memberCount ? -1 : 1;
|
}
|
|
}
|
|
public class MyTeam
|
{
|
int m_TeamId;
|
public int teamId {
|
get { return inTeam ? m_TeamId : 0; }
|
set { m_TeamId = value; }
|
}
|
|
TeamMission m_Mission = new TeamMission(TeamModel.CURRENTMAP_MISSION, 0);
|
public TeamMission mission {
|
get {
|
return m_Mission;
|
}
|
set {
|
|
if (m_Mission != value)
|
{
|
m_Mission = value;
|
if (autoPrepare.auto && autoPrepare.cancelWhenTargetChange)
|
{
|
autoPrepare.CancelAutoPrepare();
|
}
|
}
|
}
|
}
|
|
int m_LevelMin = 1;
|
public int levelMin {
|
get {
|
return m_LevelMin;
|
}
|
set {
|
m_LevelMin = value;
|
}
|
}
|
|
int m_LevelMax = 1;
|
public int levelMax {
|
get {
|
return m_LevelMax;
|
}
|
set {
|
m_LevelMax = value;
|
}
|
}
|
|
List<Teammate> members = new List<Teammate>();
|
public int memberCount {
|
get { return members.Count; }
|
}
|
|
public int nearByCount {
|
get {
|
var count = 0;
|
for (int i = 0; i < members.Count; i++)
|
{
|
var member = members[i];
|
if (member.id != PlayerDatas.Instance.baseData.PlayerID
|
&& member.mapId == PlayerDatas.Instance.baseData.MapID)
|
{
|
count++;
|
}
|
}
|
|
return count;
|
}
|
}
|
|
public bool inTeam {
|
get { return memberCount > 0; }
|
}
|
|
public bool iamCaptainer {
|
get {
|
if (memberCount > 0)
|
{
|
Teammate mate;
|
var playerId = (int)PlayerDatas.Instance.baseData.PlayerID;
|
if (TryGetMemberByPlayerId(playerId, out mate))
|
{
|
return mate.isCaptainer;
|
}
|
}
|
return false;
|
}
|
}
|
|
List<TeamPrepare> prepareStates = new List<TeamPrepare>();
|
|
public TeamAutoPrepare autoPrepare = new TeamAutoPrepare();
|
|
public MyTeam()
|
{
|
levelMax = GeneralDefine.playerMaxLevel;
|
}
|
|
public bool TryGetMember(int _index, out Teammate _mate)
|
{
|
if (members.Count > _index)
|
{
|
_mate = members[_index];
|
return true;
|
}
|
|
_mate = default(Teammate);
|
return false;
|
}
|
|
public int GetIndexOfMember(int _playerId)
|
{
|
for (int i = 0; i < members.Count; i++)
|
{
|
if (members[i].id == _playerId)
|
{
|
return i;
|
}
|
}
|
|
return -1;
|
}
|
|
public bool TryGetMemberByPlayerId(int _playerId, out Teammate _mate)
|
{
|
for (int i = 0; i < members.Count; i++)
|
{
|
if (members[i].id == _playerId)
|
{
|
_mate = members[i];
|
return true;
|
}
|
}
|
|
_mate = default(Teammate);
|
return false;
|
}
|
|
public void UpdateMembers(List<Teammate> _mates)
|
{
|
var oldCaptainer = memberCount > 0 ? members[0].id : 0;
|
var oldInTeam = inTeam;
|
members.Clear();
|
members.AddRange(_mates);
|
members.Sort(Teammate.SortCompare);
|
|
var newInTeam = inTeam;
|
|
if (!oldInTeam && inTeam)
|
{
|
autoPrepare.CancelAutoPrepare();
|
}
|
|
var newCaptainer = memberCount > 0 ? members[0].id : 0;
|
if ((oldCaptainer != 0 || newCaptainer != 0) && oldCaptainer != newCaptainer)
|
{
|
if (autoPrepare.auto && autoPrepare.cancelWhenCaptainerChange)
|
{
|
autoPrepare.CancelAutoPrepare();
|
}
|
}
|
}
|
|
public int GetOnlineMemberCount()
|
{
|
var onlineCount = 0;
|
for (int i = 0; i < members.Count; i++)
|
{
|
if (members[i].online)
|
{
|
onlineCount++;
|
}
|
}
|
return onlineCount;
|
}
|
|
public void ClearMembers()
|
{
|
members.Clear();
|
}
|
|
public int GetAnyNearByMember()
|
{
|
for (int i = 0; i < members.Count; i++)
|
{
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
var lineId = PlayerDatas.Instance.baseData.FBID;
|
if (members[i].mapId == mapId && members[i].lineId == lineId)
|
{
|
return members[i].id;
|
}
|
}
|
|
return 0;
|
}
|
|
}
|
|
public class Teammate
|
{
|
public int id;
|
public bool isCaptainer;
|
public string mateName;
|
public int realm;
|
public int job;
|
public int face;
|
public int facePic;
|
public int jobLevel;
|
public int level;
|
public int mapId;
|
public int lineId;
|
public bool online;
|
|
public Teammate()
|
{
|
|
}
|
|
public Teammate(HB902_tagGCTeamMemberInfo.tagGCTeamMember _serverInfo)
|
{
|
this.id = (int)_serverInfo.PlayerID;
|
this.isCaptainer = _serverInfo.MemberLV == 2;
|
this.mateName = _serverInfo.Name;
|
this.realm = _serverInfo.RealmLV;
|
this.job = _serverInfo.Job;
|
this.face = (int)_serverInfo.Face;
|
this.facePic = (int)_serverInfo.FacePic;
|
this.jobLevel = _serverInfo.JobLevel;
|
this.level = _serverInfo.LV;
|
this.lineId = _serverInfo.LineID;
|
this.online = _serverInfo.PlayerState == 1;
|
this.mapId = (int)_serverInfo.MapID;
|
}
|
|
public void UpdateMate(HB902_tagGCTeamMemberInfo.tagGCTeamMember _serverInfo)
|
{
|
this.id = (int)_serverInfo.PlayerID;
|
this.isCaptainer = _serverInfo.MemberLV == 2;
|
this.mateName = _serverInfo.Name;
|
this.realm = _serverInfo.RealmLV;
|
this.job = _serverInfo.Job;
|
this.face = (int)_serverInfo.Face;
|
this.facePic = (int)_serverInfo.FacePic;
|
this.jobLevel = _serverInfo.JobLevel;
|
this.level = _serverInfo.LV;
|
this.lineId = _serverInfo.LineID;
|
this.online = _serverInfo.PlayerState == 1;
|
this.mapId = (int)_serverInfo.MapID;
|
}
|
|
public void UpdateMap(H0913_tagTeamMemberChangeMap _serverInfo)
|
{
|
this.mapId = (int)_serverInfo.MapID;
|
this.lineId = _serverInfo.LineID;
|
}
|
|
public static int SortCompare(Teammate _lhs, Teammate _rhs)
|
{
|
return _lhs.isCaptainer && !_rhs.isCaptainer ? -1 : 1;
|
}
|
|
}
|
|
/// <summary>
|
/// 邀请别人
|
/// </summary>
|
public struct TeamInvite
|
{
|
public int playerId;
|
public string playerName;
|
public int job;
|
public int jobLevel;
|
public int face;
|
public int facePic;
|
public int realm;
|
public int playerLevel;
|
|
public TeamInvite(HB908_tagGCRecommendNearbyPlayerList.tagGCRecommendNearbyPlayer _playerInfo)
|
{
|
this.playerId = (int)_playerInfo.PlayerID;
|
this.playerName = _playerInfo.Name;
|
this.job = _playerInfo.Job;
|
this.jobLevel = 1;
|
this.face = (int)_playerInfo.Face;
|
this.facePic = (int)_playerInfo.FacePic;
|
this.realm = _playerInfo.RealmLV;
|
this.playerLevel = _playerInfo.LV;
|
}
|
|
public TeamInvite(PlayerFairyData.FairyMember _member)
|
{
|
this.playerId = (int)_member.PlayerID;
|
this.playerName = _member.Name;
|
this.job = _member.Job;
|
this.jobLevel = 1;
|
this.face = (int)_member.Face;
|
this.facePic = (int)_member.FacePic;
|
this.realm = _member.OfficialRank;
|
this.playerLevel = _member.LV;
|
}
|
|
public TeamInvite(FriendPlayer _member)
|
{
|
this.playerId = (int)_member.PlayerID;
|
this.playerName = _member.PlayerName;
|
this.job = _member.Job;
|
this.jobLevel = 1;
|
this.face = (int)_member.Face;
|
this.facePic = (int)_member.FacePic;
|
this.realm = _member.RealmLV;
|
this.playerLevel = _member.LV;
|
}
|
|
}
|
|
/// <summary>
|
/// 邀请函,别人邀请你发的请柬
|
/// </summary>
|
public struct TeamInvitation
|
{
|
public int playerId;
|
public string playerName;
|
public int level;
|
public int job;
|
public int jobLevel;
|
public int realm;
|
public TeamMission mission;
|
|
public TeamInvitation(HB901_tagGCInviteJoinTeamInfo _serverInfo)
|
{
|
this.playerId = (int)_serverInfo.PlayerID;
|
this.playerName = _serverInfo.Name;
|
this.job = _serverInfo.Job;
|
this.jobLevel = _serverInfo.JobLevel;
|
this.realm = _serverInfo.RealmLV;
|
this.level = _serverInfo.LV;
|
this.mission = new TeamMission((int)_serverInfo.TagMapID, (int)_serverInfo.TagMapEx);
|
}
|
|
}
|
|
public struct TeamApplication
|
{
|
public int playerId;
|
public string playerName;
|
public int job;
|
public int jobLevel;
|
public int face;
|
public int facePic;
|
public int realm;
|
public int playerLevel;
|
|
public TeamApplication(HB907_tagGCRequestJoinTeam _applicationInfo)
|
{
|
this.playerId = (int)_applicationInfo.PlayerID;
|
this.playerName = _applicationInfo.Name;
|
this.job = _applicationInfo.Job;
|
this.jobLevel = _applicationInfo.JobLevel;
|
this.realm = _applicationInfo.RealmLV;
|
this.playerLevel = _applicationInfo.LV;
|
this.face = (int)_applicationInfo.Face;
|
this.facePic = (int)_applicationInfo.FacePic;
|
}
|
|
}
|
|
public struct TeamMission
|
{
|
public int mapId;
|
public int mapEx;
|
|
public TeamMission(int _mapId, int _mapEx)
|
{
|
this.mapId = _mapId;
|
this.mapEx = _mapEx;
|
}
|
|
public static bool operator ==(TeamMission _lhs, TeamMission _rhs)
|
{
|
return _lhs.mapId == _rhs.mapId && _lhs.mapEx == _rhs.mapEx;
|
}
|
|
public static bool operator !=(TeamMission _lhs, TeamMission _rhs)
|
{
|
return _lhs.mapId != _rhs.mapId || _lhs.mapEx != _rhs.mapEx;
|
}
|
}
|
|
public class TeamPrepare
|
{
|
int m_MapId = 0;
|
public int mapId {
|
get { return m_MapId; }
|
private set { m_MapId = value; }
|
}
|
|
int m_MapEx;
|
public int mapEx {
|
get { return m_MapEx; }
|
private set { m_MapEx = value; }
|
}
|
|
public Dictionary<int, TeammatePrepareState> playerStates = new Dictionary<int, TeammatePrepareState>();
|
|
bool m_IsError = false;
|
public bool isError {
|
get { return m_IsError; }
|
private set {
|
m_IsError = value;
|
}
|
}
|
|
public bool isPreparing {
|
get {
|
return !IsAllOk() && !isError && !IsReject();
|
}
|
}
|
|
public TeamPrepare()
|
{
|
}
|
|
public void UpdatePrepareState(HB911_tagGCTeamEnterFBPrepare _serverInfo)
|
{
|
this.mapId = (int)_serverInfo.TagMapID;
|
this.mapEx = (int)_serverInfo.TagMapEx;
|
this.isError = _serverInfo.IsPrepareErr == 1;
|
playerStates.Clear();
|
for (int i = 0; i < _serverInfo.MemStateList.Length; i++)
|
{
|
var playerState = _serverInfo.MemStateList[i];
|
playerStates[(int)playerState.PlayerID] = (TeammatePrepareState)(playerState.PrepareState);
|
}
|
}
|
|
public TeammatePrepareState GetPlayerPrepareSate(int _playerId)
|
{
|
if (playerStates.ContainsKey(_playerId))
|
{
|
return playerStates[_playerId];
|
}
|
else
|
{
|
return TeammatePrepareState.UnPrepared;
|
}
|
}
|
|
public bool OnlyCaptainerPrepared(int _captainerId)
|
{
|
var okCount = 0;
|
var captainerOk = false;
|
foreach (var key in playerStates.Keys)
|
{
|
if (playerStates[key] == TeammatePrepareState.Prepared)
|
{
|
okCount++;
|
}
|
if (key == _captainerId)
|
{
|
captainerOk = playerStates[key] == TeammatePrepareState.Prepared;
|
}
|
}
|
|
return okCount == 1 && captainerOk;
|
}
|
|
public bool IsReject()
|
{
|
foreach (var key in playerStates.Keys)
|
{
|
if (playerStates[key] == TeammatePrepareState.Rejected)
|
{
|
return true;
|
}
|
}
|
|
return false;
|
}
|
|
public bool IsAllOk()
|
{
|
foreach (var key in playerStates.Keys)
|
{
|
if (playerStates[key] != TeammatePrepareState.Prepared)
|
{
|
return false;
|
}
|
}
|
|
return true;
|
}
|
|
}
|
|
public struct TeamTargetPreference
|
{
|
public int minLevel;
|
public int maxLevel;
|
|
public TeamTargetPreference(int _minLevel, int _maxLevel)
|
{
|
this.minLevel = _minLevel;
|
this.maxLevel = _maxLevel;
|
}
|
|
}
|
|
public class TeamAutoPrepare
|
{
|
bool m_Auto = false;
|
public bool auto {
|
get { return m_Auto; }
|
private set {
|
if (m_Auto != value)
|
{
|
m_Auto = value;
|
if (autoPrepareChangeEvent != null)
|
{
|
autoPrepareChangeEvent();
|
}
|
}
|
}
|
}
|
|
public int mapId { get; private set; }
|
public int mapEx { get; private set; }
|
|
bool m_CancelWhenTargetChange = true;
|
public bool cancelWhenTargetChange {
|
get { return m_CancelWhenTargetChange; }
|
}
|
|
bool m_CancelWhenCaptainerChange = false;
|
public bool cancelWhenCaptainerChange {
|
get { return m_CancelWhenCaptainerChange; }
|
}
|
|
public event Action autoPrepareChangeEvent;
|
|
public void CancelAutoPrepare()
|
{
|
this.mapId = 0;
|
this.mapEx = 0;
|
this.m_CancelWhenCaptainerChange = false;
|
this.m_CancelWhenTargetChange = true;
|
this.auto = false;
|
}
|
|
public void SetAutoPreapare(int mapId, int mapEx, bool cancelWhenTargetChange, bool cancelWhenCaptainerChange)
|
{
|
this.mapId = mapId;
|
this.mapEx = mapEx;
|
this.m_CancelWhenTargetChange = cancelWhenTargetChange;
|
this.m_CancelWhenCaptainerChange = cancelWhenCaptainerChange;
|
this.auto = true;
|
}
|
|
}
|
|
}
|
|
|
|