You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
407 lines
16 KiB
407 lines
16 KiB
using AX.Network.Protocols; |
|
using AX.NetworkSystem; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using System; |
|
using AX.Serialization; |
|
|
|
public class CommandingCtrl : MonoBehaviour { |
|
|
|
private List<bool> isCommandbools = new List<bool>();//当前登陆用户所有上级的是否为总指挥值的集合 |
|
|
|
public GameObject PoliceInfo; |
|
|
|
//缓存已存在的总指挥所属组织机构级别 |
|
private int generalCommanderDeptLevel; |
|
//缓存辖区中队所有直属上级(包括跨级)的组织机构id |
|
private List<int> supIdsOfXQZD = new List<int>(); |
|
|
|
// Use this for initialization |
|
void Start () { |
|
PoliceInfo = GameObject.Find("Canvas").transform.Find("Police/Main/PoliceInfo").gameObject; |
|
|
|
NetworkMessageDispatcher.AddListener("GET_SUP_ISCOMMAND_SYNC", GetSupIsCommand); |
|
|
|
NetworkMessageDispatcher.AddListener("ISCOMMAND_SYNC", SetSupIsCommand); |
|
|
|
NetworkMessageDispatcher.AddListener("EXIST_OTHER_DEPT_ISCMD_SYNC", ExistOtherDeptIsCMD); |
|
NetworkMessageDispatcher.AddListener("EXIST_OTHER_USER_ISCMD_SYNC", ExistOtherUserIsCMD); |
|
|
|
NetworkMessageDispatcher.AddListener("EXIST_OTHER_DEPT_ISCMD_RESP_SYNC", ExistOtherDeptIsCMDResp); |
|
NetworkMessageDispatcher.AddListener("EXIST_OTHER_USER_ISCMD_RESP_SYNC", ExistOtherUserIsCMDResp); |
|
|
|
NetworkMessageDispatcher.AddListener("EXIST_OTHER_EXCEPTZD_DEPT_ISCMD_SYNC", ExistOtherExceptZDDeptIsCMD); |
|
|
|
NetworkMessageDispatcher.AddListener("EXIST_OTHER_EXCEPTZD_DEPT_ISCMD_RESP_SYNC", ExistOtherExceptZDDeptIsCMDResp); |
|
|
|
} |
|
|
|
private void OnDestroy() |
|
{ |
|
NetworkMessageDispatcher.RemoveListener("GET_SUP_ISCOMMAND_SYNC", GetSupIsCommand); |
|
|
|
NetworkMessageDispatcher.RemoveListener("ISCOMMAND_SYNC", SetSupIsCommand); |
|
|
|
NetworkMessageDispatcher.RemoveListener("EXIST_OTHER_DEPT_ISCMD", ExistOtherDeptIsCMD); |
|
NetworkMessageDispatcher.RemoveListener("EXIST_OTHER_USER_ISCMD_SYNC", ExistOtherUserIsCMD); |
|
|
|
NetworkMessageDispatcher.RemoveListener("EXIST_OTHER_DEPT_ISCMD_RESP_SYNC", ExistOtherDeptIsCMDResp); |
|
NetworkMessageDispatcher.RemoveListener("EXIST_OTHER_USER_ISCMD_RESP_SYNC", ExistOtherUserIsCMDResp); |
|
|
|
NetworkMessageDispatcher.RemoveListener("EXIST_OTHER_EXCEPTZD_DEPT_ISCMD_SYNC", ExistOtherExceptZDDeptIsCMD); |
|
|
|
NetworkMessageDispatcher.RemoveListener("EXIST_OTHER_EXCEPTZD_DEPT_ISCMD_RESP_SYNC", ExistOtherExceptZDDeptIsCMDResp); |
|
} |
|
|
|
/// <summary> |
|
/// 不存在大队指挥,支队指挥,总队指挥为总指挥,是中队为总指挥 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
private void ExistOtherExceptZDDeptIsCMDResp(BinaryMessage obj) |
|
{ |
|
var data = obj.Body.Deserialize<KeyValuePair<long, IsComdDatas>>(); |
|
|
|
PoliceInfo.GetComponent<PoliceInfoMsgBind>().isExistCmdRoles.Add(data.Value.generalCommanding); |
|
|
|
if (PoliceInfo.GetComponent<PoliceInfoMsgBind>().isExistCmdRoles.Count != data.Value.count) |
|
{ |
|
return; |
|
} |
|
|
|
if (!PoliceInfo.GetComponent<PoliceInfoMsgBind>().isExistCmdRoles.Contains(true)) |
|
{//不存在大队指挥,支队指挥,总队指挥为总指挥,是中队为总指挥 |
|
if (CurrentUserInfo.organization.DisplayName == "龙泾中队") |
|
{//若登陆辖区中队 |
|
CurrentUserInfo.generalCommanding = true;//设置当前登陆用户为总指挥 |
|
|
|
foreach (UserData item in CurrentUserInfo.room.UserList) |
|
{ |
|
if (CurrentUserInfo.mySelf.Id != item.UserInfo.Id) |
|
{//不发给自己 |
|
NetworkManager.Default.SendAsync("GENERAL_COMMANDING_UPDATE_SYNC", item.UserInfo.Id); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 是否存在大队指挥,支队指挥,总队指挥为总指挥 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
private void ExistOtherExceptZDDeptIsCMD(BinaryMessage obj) |
|
{ |
|
var data = obj.Body.Deserialize<KeyValuePair<long, List<long>>>(); |
|
|
|
var isComdDatas = new IsComdDatas(); |
|
isComdDatas.generalCommanding = CurrentUserInfo.generalCommanding; |
|
isComdDatas.count = data.Value.Count; |
|
|
|
NetworkManager.Default.SendAsync("EXIST_OTHER_EXCEPTZD_DEPT_ISCMD_RESP_SYNC", |
|
new KeyValuePair<long, IsComdDatas>(data.Key, isComdDatas)); |
|
} |
|
|
|
/// <summary> |
|
/// 看看是否有组织机构已为总指挥的处理 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
private void ExistOtherDeptIsCMDResp(BinaryMessage obj) |
|
{ |
|
var data = obj.Body.Deserialize<KeyValuePair<long, IsComdDatas>>(); |
|
|
|
PoliceInfo.GetComponent<PoliceInfoMsgBind>().isExistCmdRoles.Add(data.Value.generalCommanding); |
|
|
|
if (PoliceInfo.GetComponent<PoliceInfoMsgBind>().isExistCmdRoles.Count != data.Value.count) |
|
{ |
|
return; |
|
} |
|
|
|
if (!PoliceInfo.GetComponent<PoliceInfoMsgBind>().isExistCmdRoles.Contains(true)) |
|
{ |
|
if (CurrentUserInfo.role == Role.总队指挥 |
|
|| CurrentUserInfo.role == Role.支队指挥 |
|
|| CurrentUserInfo.role == Role.大队指挥 |
|
|| CurrentUserInfo.role == Role.中队指挥) |
|
{ |
|
CurrentUserInfo.generalCommanding = true;//设置当前登陆用户为总指挥 |
|
|
|
foreach (UserData item in CurrentUserInfo.room.UserList) |
|
{ |
|
if (CurrentUserInfo.mySelf.Id != item.UserInfo.Id) |
|
{//不发给自己 |
|
NetworkManager.Default.SendAsync("GENERAL_COMMANDING_UPDATE_SYNC", item.UserInfo.Id); |
|
} |
|
} |
|
} |
|
} |
|
else |
|
{//处理没有大队指挥,支队指挥,总队指挥为总指挥情况下,已有某中队为总指挥,辖区中队进入后,总指挥移交辖区中队 |
|
|
|
//是否存在大队指挥,支队指挥,总队指挥为总指挥 |
|
PoliceInfo.GetComponent<PoliceInfoMsgBind>().isExistCmdRoles = new List<bool>(); |
|
|
|
List<long> Uids = new List<long>(); |
|
foreach (UserData item in CurrentUserInfo.room.UserList) |
|
{ |
|
if ((item.Role == Role.总队指挥 |
|
|| item.Role == Role.支队指挥 |
|
|| item.Role == Role.大队指挥) |
|
&& item.UserInfo.Id != CurrentUserInfo.mySelf.Id |
|
) |
|
{ |
|
Uids.Add(item.UserInfo.Id); |
|
} |
|
} |
|
|
|
if (Uids.Count == 0) |
|
{//说明存在中队为总指挥 |
|
if (CurrentUserInfo.organization.DisplayName == "龙泾中队") |
|
{//若登陆辖区中队 |
|
CurrentUserInfo.generalCommanding = true;//设置当前登陆用户为总指挥 |
|
|
|
foreach (UserData item in CurrentUserInfo.room.UserList) |
|
{ |
|
if (CurrentUserInfo.mySelf.Id != item.UserInfo.Id) |
|
{//不发给自己 |
|
NetworkManager.Default.SendAsync("GENERAL_COMMANDING_UPDATE_SYNC", item.UserInfo.Id); |
|
} |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
//是否存在大队指挥,支队指挥,总队指挥为总指挥 |
|
NetworkManager.Default.SendAsync("EXIST_OTHER_EXCEPTZD_DEPT_ISCMD_SYNC", |
|
new KeyValuePair<long, List<long>>(CurrentUserInfo.mySelf.Id, Uids)); |
|
} |
|
|
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 是否有用户已为总指挥的回复处理 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
private void ExistOtherUserIsCMDResp(BinaryMessage obj) |
|
{ |
|
var data = obj.Body.Deserialize<KeyValuePair<long, IsGeneralCommanderData>>(); |
|
|
|
PoliceInfo.GetComponent<PoliceInfoMsgBind>().isExistCmdRoles.Add(data.Value.generalCommanding); |
|
|
|
if (data.Value.generalCommanding) |
|
{ |
|
generalCommanderDeptLevel = data.Value.organizationLevel; |
|
} |
|
|
|
if (PoliceInfo.GetComponent<PoliceInfoMsgBind>().isExistCmdRoles.Count != data.Value.count) |
|
{ |
|
return; |
|
} |
|
|
|
if (!PoliceInfo.GetComponent<PoliceInfoMsgBind>().isExistCmdRoles.Contains(true)) |
|
{ |
|
if (CurrentUserInfo.role == Role.总队指挥 |
|
|| CurrentUserInfo.role == Role.支队指挥 |
|
|| CurrentUserInfo.role == Role.大队指挥 |
|
|| CurrentUserInfo.role == Role.中队指挥) |
|
{ |
|
CurrentUserInfo.generalCommanding = true;//设置当前登陆用户为总指挥 |
|
|
|
foreach (UserData item in CurrentUserInfo.room.UserList) |
|
{ |
|
if (CurrentUserInfo.mySelf.Id != item.UserInfo.Id) |
|
{//不发给自己 |
|
NetworkManager.Default.SendAsync("GENERAL_COMMANDING_UPDATE_SYNC", item.UserInfo.Id); |
|
} |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
if (generalCommanderDeptLevel != 0) |
|
{ |
|
if (CurrentUserInfo.organization.Level < generalCommanderDeptLevel) |
|
{//当前到场用户所属组织机构级别小于已是总指挥用户的组织机构级别 |
|
CurrentUserInfo.generalCommanding = true;//设置当前到场用户为总指挥 |
|
|
|
foreach (UserData item in CurrentUserInfo.room.UserList) |
|
{ |
|
if (CurrentUserInfo.mySelf.Id != item.UserInfo.Id) |
|
{//不发给自己 |
|
NetworkManager.Default.SendAsync("GENERAL_COMMANDING_UPDATE_SYNC", item.UserInfo.Id); |
|
} |
|
} |
|
} |
|
|
|
if (CurrentUserInfo.organization.Level == generalCommanderDeptLevel) |
|
{//当前到场用户所属组织机构级别等于已为总指挥用户的组织机构级别 |
|
|
|
if (generalCommanderDeptLevel == 4 && CurrentUserInfo.organization.DisplayName == "龙泾中队") |
|
{//已为总指挥用户的组织机构为中队,并且当前到场用户所属组织机构为辖区中队 |
|
|
|
CurrentUserInfo.generalCommanding = true;//设置当前到场用户为总指挥 |
|
|
|
foreach (UserData item in CurrentUserInfo.room.UserList) |
|
{ |
|
if (CurrentUserInfo.mySelf.Id != item.UserInfo.Id) |
|
{//不发给自己 |
|
NetworkManager.Default.SendAsync("GENERAL_COMMANDING_UPDATE_SYNC", item.UserInfo.Id); |
|
} |
|
} |
|
} |
|
if (generalCommanderDeptLevel < 4 )//4表示中队 |
|
{//当前到场用户所属组织机构级别等于已为总指挥用户的组织机构级别,并且已为总指挥用户的组织机构级别小于4 |
|
|
|
int xqzdParentId = FindXQZDParentId("龙泾中队"); |
|
FindAllSupIdsOfXQZD(xqzdParentId); |
|
if (supIdsOfXQZD.Contains(CurrentUserInfo.organization.Id)) |
|
{ |
|
CurrentUserInfo.generalCommanding = true;//设置当前到场用户为总指挥 |
|
|
|
foreach (UserData item in CurrentUserInfo.room.UserList) |
|
{ |
|
if (CurrentUserInfo.mySelf.Id != item.UserInfo.Id) |
|
{//不发给自己 |
|
NetworkManager.Default.SendAsync("GENERAL_COMMANDING_UPDATE_SYNC", item.UserInfo.Id); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 查找辖区中队直接上级(辖区大队)id |
|
/// </summary> |
|
/// <param name="xqzdName"></param> |
|
/// <returns></returns> |
|
private int FindXQZDParentId(string xqzdName) |
|
{ |
|
int xqzdParentId = -1; |
|
|
|
foreach (var item in GameSettings.othersSettings.orgs) |
|
{ |
|
if (item.DisplayName == xqzdName) |
|
{ |
|
xqzdParentId = item.ParentId; |
|
break; |
|
} |
|
} |
|
|
|
return xqzdParentId; |
|
} |
|
|
|
/// <summary> |
|
/// 查找辖区中队的所有上级组织机构的id |
|
/// </summary> |
|
/// <param name="xqzdParentId">辖区中队的直接上级组织机构(辖区大队)id</param> |
|
private void FindAllSupIdsOfXQZD(int xqzdParentId) |
|
{ |
|
foreach (var item in GameSettings.othersSettings.orgs) |
|
{ |
|
if (item.Id == xqzdParentId && item.Level != 5) |
|
{ |
|
supIdsOfXQZD.Add(item.Id); |
|
//继续查找item的上级是否存在上级 |
|
FindAllSupIdsOfXQZD(item.ParentId); |
|
} |
|
} |
|
} |
|
|
|
public struct IsComdDatas |
|
{ |
|
public bool generalCommanding; |
|
public int count; |
|
} |
|
|
|
public struct IsGeneralCommanderData |
|
{ |
|
public bool generalCommanding; |
|
public int count; |
|
public int organizationLevel; |
|
} |
|
|
|
/// <summary> |
|
/// 看看是否有组织机构已为总指挥 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
private void ExistOtherDeptIsCMD(BinaryMessage obj) |
|
{ |
|
var data = obj.Body.Deserialize<KeyValuePair<long, List<long>>>(); |
|
|
|
var isComdDatas = new IsComdDatas(); |
|
isComdDatas.generalCommanding = CurrentUserInfo.generalCommanding; |
|
isComdDatas.count = data.Value.Count; |
|
|
|
NetworkManager.Default.SendAsync("EXIST_OTHER_DEPT_ISCMD_RESP_SYNC", |
|
new KeyValuePair<long, IsComdDatas>(data.Key, isComdDatas)); |
|
} |
|
|
|
/// <summary> |
|
/// 是否有用户已为总指挥 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
private void ExistOtherUserIsCMD(BinaryMessage obj) |
|
{ |
|
var data = obj.Body.Deserialize<KeyValuePair<long, List<long>>>(); |
|
|
|
var isGeneralCommanderData = new IsGeneralCommanderData(); |
|
isGeneralCommanderData.generalCommanding = CurrentUserInfo.generalCommanding; |
|
isGeneralCommanderData.count = data.Value.Count; |
|
isGeneralCommanderData.organizationLevel = CurrentUserInfo.organization.Level; |
|
|
|
//发回给刚到场的用户:data.Key |
|
NetworkManager.Default.SendAsync("EXIST_OTHER_USER_ISCMD_RESP_SYNC", |
|
new KeyValuePair<long, IsGeneralCommanderData>(data.Key, isGeneralCommanderData)); |
|
} |
|
|
|
private void GetSupIsCommand(BinaryMessage message) |
|
{ |
|
var data = message.Body.Deserialize<KeyValuePair<long, List<UserData>>>(); |
|
|
|
var isComdDatas = new IsComdDatas(); |
|
isComdDatas.generalCommanding = CurrentUserInfo.generalCommanding; |
|
isComdDatas.count = data.Value.Count; |
|
|
|
NetworkManager.Default.SendAsync("ISCOMMAND_SYNC", new KeyValuePair<long , IsComdDatas>(data.Key, isComdDatas)); |
|
} |
|
|
|
private void SetSupIsCommand(BinaryMessage message) |
|
{ |
|
var data = message.Body.Deserialize<KeyValuePair<long, IsComdDatas>>(); |
|
|
|
isCommandbools.Add(data.Value.generalCommanding); |
|
|
|
if (isCommandbools.Count != data.Value.count) |
|
{ |
|
return; |
|
} |
|
|
|
if (!isCommandbools.Contains(true)) |
|
{ |
|
CurrentUserInfo.generalCommanding = true; |
|
|
|
foreach (UserData item in CurrentUserInfo.room.UserList) |
|
{ |
|
if (CurrentUserInfo.mySelf.Id != item.UserInfo.Id) |
|
{ |
|
//通知当前登陆用户的下级移交总指挥(接收处理时设置CurrentUserInfo.generalCommanding为false) |
|
NetworkManager.Default.SendAsync("GENERAL_COMMANDING_UPDATE_SYNC", item.UserInfo.Id); |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
CurrentUserInfo.generalCommanding = false; |
|
} |
|
} |
|
|
|
// Update is called once per frame |
|
void Update () { |
|
|
|
} |
|
|
|
}
|
|
|