428 lines
12 KiB
C#
428 lines
12 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using cfg.LegionCfg;
|
|
using Framework;
|
|
using Gameplay;
|
|
using Gameplay.Common;
|
|
using Gameplay.Net;
|
|
using NLDPB;
|
|
using PhxhSDK;
|
|
using Sirenix.Utilities;
|
|
using UnityEngine;
|
|
|
|
public partial class LegionManager: Singlenton<LegionManager>, IInitable
|
|
{
|
|
public bool Belong2Legion => _myLegion != null;
|
|
|
|
#region API
|
|
|
|
public void Init()
|
|
{
|
|
_RegisterEvents();
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
_UnregisterEvents();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置客户端的 MyLegion Base数据
|
|
/// </summary>
|
|
public void SetMyLegionBase()
|
|
{
|
|
_myLegion = _ParseLegionData(NetLegionBaseData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置客户端的 MyLegion Member数据
|
|
/// </summary>
|
|
public void SetMyLegionMembers()
|
|
{
|
|
if (_myLegionMemberList == null)
|
|
{
|
|
_myLegionMemberList = new();
|
|
}
|
|
else
|
|
{
|
|
_myLegionMemberList.Clear();
|
|
}
|
|
|
|
foreach (var memberData in NetLegionMemberList)
|
|
{
|
|
//TODO Debug
|
|
DebugUtil.LogError($"MyLegionMember ID:{memberData.ActorId}");
|
|
_myLegionMemberList.Add(new ActorLegionData(memberData));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置客户端的 MyLegion ApplyMember数据
|
|
/// </summary>
|
|
public void SetMyLegionApplyMembers()
|
|
{
|
|
if (_applyMemberList == null)
|
|
{
|
|
_applyMemberList = new();
|
|
}
|
|
else
|
|
{
|
|
_applyMemberList.Clear();
|
|
}
|
|
|
|
foreach (var applyData in NetLegionApplyDataList)
|
|
{
|
|
_applyMemberList.Add(new ActorLegionData(applyData));
|
|
//TODO Debug
|
|
DebugUtil.LogError($"申请列表, 玩家ID:{applyData.ActorId}, 玩家名:{applyData.ActorId}");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置客户端的 MyLegion 记录数据
|
|
/// </summary>
|
|
public void SetMyLegionLogs()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新军团列表
|
|
/// </summary>
|
|
public void SetLegionList()
|
|
{
|
|
_legions.Clear();
|
|
var legionDataList = NetLegionInfoDataList;
|
|
foreach (var legionData in legionDataList)
|
|
{
|
|
var legion = ParseLegion(legionData);
|
|
CorrectLegionData(legion);
|
|
_legions.Add(legion);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 确认是否有权限
|
|
/// </summary>
|
|
/// <param name="eventID"></param>
|
|
/// <returns></returns>
|
|
public bool CheckIsPermission(Permission eventID)
|
|
{
|
|
if (_myLegion == null)
|
|
return false;
|
|
var eventCfg = TableManager.Instance.Tables.LegionPermissions.GetOrDefault(eventID);
|
|
if (eventCfg != null)
|
|
{
|
|
var post = GetMyPost();
|
|
if (post != Position.None)
|
|
{
|
|
switch (post)
|
|
{
|
|
case Position.Member:
|
|
{
|
|
return eventCfg.Member > 0;
|
|
}
|
|
case Position.RegimentalCommander:
|
|
{
|
|
return eventCfg.RegimentalCommander > 0;
|
|
}
|
|
case Position.AssistantRegimentalCommander:
|
|
{
|
|
return eventCfg.AssistantRegimentalCommander > 0;
|
|
}
|
|
case Position.Leroy:
|
|
{
|
|
return eventCfg.Leroy > 0;
|
|
}
|
|
case Position.Diplomatist:
|
|
{
|
|
return eventCfg.Diplomatist > 0;
|
|
}
|
|
|
|
case Position.Commander:
|
|
{
|
|
return eventCfg.Commander > 0;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public Position GetMyPost()
|
|
{
|
|
if (_myLegion == null)
|
|
return Position.None;
|
|
if (_myLegionMemberList == null || _myLegionMemberList.Count <= 0)
|
|
return Position.None;
|
|
|
|
var myLegionActorData = _myLegionMemberList.Find(
|
|
data => data.ActorID == Actor.Instance.Base.GetProp(ActorProp.ActorId));
|
|
if (myLegionActorData != null)
|
|
{
|
|
return myLegionActorData.Post;
|
|
}
|
|
|
|
return Position.None;
|
|
}
|
|
|
|
public string GetPostStr(Position post)
|
|
{
|
|
switch (post)
|
|
{
|
|
case Position.Commander:
|
|
return CommonUtils.GetLocalizeText("legion_post_commander");
|
|
case Position.RegimentalCommander:
|
|
return CommonUtils.GetLocalizeText("legion_post_president");
|
|
case Position.AssistantRegimentalCommander:
|
|
return CommonUtils.GetLocalizeText("legion_post_assist_president");
|
|
case Position.Leroy:
|
|
return CommonUtils.GetLocalizeText("legion_post_leroy");
|
|
case Position.Diplomatist:
|
|
return CommonUtils.GetLocalizeText("legion_post_diplomatist");
|
|
case Position.Member:
|
|
return CommonUtils.GetLocalizeText("legion_post_member");
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否合法军团标签
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool CheckIsLegalLabelList(List<int> idxList)
|
|
{
|
|
for (int i = 0; i < idxList.Count; i++)
|
|
{
|
|
var tabIdx = idxList[i];
|
|
if (!CheckIsLegalLabel(tabIdx))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool CheckIsLegalLabel(int idx)
|
|
{
|
|
if (!GLConfig.Inst.data.LegionLabelList.Contains(idx))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否合法军团宣言
|
|
/// </summary>
|
|
/// <param name="idx"></param>
|
|
/// <returns></returns>
|
|
public bool CheckIsLegalManifesto(int idx)
|
|
{
|
|
if (GLConfig.Inst.data.LegionDeclarationList.Contains(idx))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void CorrectMyLegion()
|
|
{
|
|
CorrectLegionData(_myLegion);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 校正军团不符合配置的数据
|
|
/// </summary>
|
|
/// <param name="legion"></param>
|
|
public void CorrectLegionData(Legion legion)
|
|
{
|
|
CorrectTabList(legion);
|
|
CorrectManifesto(legion);
|
|
}
|
|
|
|
public void CorrectManifesto(Legion legion)
|
|
{
|
|
var manifestoList = GLConfig.Inst.data.LegionDeclarationList;
|
|
if (!manifestoList.Contains(legion.ManifestoID))
|
|
{
|
|
legion.ManifestoID = manifestoList[0];
|
|
}
|
|
}
|
|
|
|
public void CorrectTabList(Legion legion)
|
|
{
|
|
var count = legion.TabIdxList.Count;
|
|
var labelList = GLConfig.Inst.data.LegionLabelList;
|
|
if (count > labelList.Count)
|
|
{
|
|
legion.TabIdxList.Clear();
|
|
legion.TabIdxList = new List<int>(labelList);
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
var idx = legion.TabIdxList[i];
|
|
if (!CheckIsLegalLabel(idx))
|
|
{
|
|
legion.TabIdxList.Remove(idx);
|
|
}
|
|
}
|
|
|
|
if (legion.TabIdxList.Count < 1)
|
|
{
|
|
legion.TabIdxList.Add(labelList[0]);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取宣言文本
|
|
/// </summary>
|
|
/// <param name="idx"></param>
|
|
/// <returns></returns>
|
|
public string GetLegionLabelStr(int idx)
|
|
{
|
|
var labelIdxList = GLConfig.Inst.data.LegionLabelList;
|
|
var index = labelIdxList.Find(item => item == idx);
|
|
if (index > -1)
|
|
{
|
|
return CommonUtils.GetLocalizeText(E_LocalizePrefix.Legion_Label, idx);
|
|
}
|
|
|
|
DebugUtil.LogError($"无法获取军团标签文本, ID:{idx}");
|
|
return "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取
|
|
/// </summary>
|
|
/// <param name="idx"></param>
|
|
/// <returns></returns>
|
|
public string GetLegionManifestoStr(int idx)
|
|
{
|
|
var manifestoIdxList = GLConfig.Inst.data.LegionDeclarationList;
|
|
var index = manifestoIdxList.Find(item => item == idx);
|
|
if (index > -1)
|
|
{
|
|
return CommonUtils.GetLocalizeText(E_LocalizePrefix.Legion_Declaration, idx);
|
|
}
|
|
|
|
DebugUtil.LogError($"无法获取军团宣言文本, ID:{idx}");
|
|
return "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 随机获取一个宣言
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public int GetRandomManifestoIdx()
|
|
{
|
|
var manifestoIdxList = GLConfig.Inst.data.LegionDeclarationList;
|
|
if (manifestoIdxList.Count > 0)
|
|
{
|
|
var ranIdx = Random.Range(0, manifestoIdxList.Count);
|
|
return manifestoIdxList[ranIdx];
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
private void _RegisterEvents()
|
|
{
|
|
EventManager.Instance.Register(EventManager.EventName.LegionBaseData, _OnLegionBaseUpdate);
|
|
EventManager.Instance.Register(EventManager.EventName.LegionMemberData, _OnLegionMemberUpdate);
|
|
EventManager.Instance.Register(EventManager.EventName.LegionApplyData, _OnLegionApplyListUpdate);
|
|
EventManager.Instance.Register(EventManager.EventName.LegionCreateSuccess, _OnCreateSuccess);
|
|
EventManager.Instance.Register(EventManager.EventName.LegionQuitSuccess, _OnQuitSuccess);
|
|
EventManager.Instance.Register(EventManager.EventName.LegionJoinSendSuccess, _OnJoinApplySendSuccess);
|
|
EventManager.Instance.Register(EventManager.EventName.LegionMemberPostUpdate, _OnMemberPostUpdate);
|
|
}
|
|
|
|
private void _UnregisterEvents()
|
|
{
|
|
EventManager.Instance.Unregister(EventManager.EventName.LegionBaseData, _OnLegionBaseUpdate);
|
|
EventManager.Instance.Unregister(EventManager.EventName.LegionMemberData, _OnLegionMemberUpdate);
|
|
EventManager.Instance.Unregister(EventManager.EventName.LegionApplyData, _OnLegionApplyListUpdate);
|
|
EventManager.Instance.Unregister(EventManager.EventName.LegionCreateSuccess, _OnCreateSuccess);
|
|
EventManager.Instance.Unregister(EventManager.EventName.LegionQuitSuccess, _OnQuitSuccess);
|
|
EventManager.Instance.Unregister(EventManager.EventName.LegionJoinSendSuccess, _OnJoinApplySendSuccess);
|
|
EventManager.Instance.Unregister(EventManager.EventName.LegionMemberPostUpdate, _OnMemberPostUpdate);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 军团BaseData更新
|
|
/// </summary>
|
|
private void _OnLegionBaseUpdate()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 军团成员列表更新
|
|
/// </summary>
|
|
private void _OnLegionMemberUpdate()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 军团申请成员列表更新
|
|
/// </summary>
|
|
private void _OnLegionApplyListUpdate()
|
|
{
|
|
|
|
}
|
|
|
|
private void _OnLegionLogUpdate()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建军团成功
|
|
/// </summary>
|
|
private void _OnCreateSuccess()
|
|
{
|
|
DebugUtil.LogError("创建军团成功!");
|
|
if (IsPresident)
|
|
{
|
|
DebugUtil.LogG($"军团ID:{_myLegion.ID}");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 退出军团成功
|
|
/// </summary>
|
|
private void _OnQuitSuccess()
|
|
{
|
|
_myLegion = null;
|
|
_myLegionMemberList?.Clear();
|
|
_applyMemberList?.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加入军团成功
|
|
/// </summary>
|
|
private void _OnJoinApplySendSuccess()
|
|
{
|
|
DebugUtil.LogError("申请加入军团成功!!!");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改成员职位
|
|
/// </summary>
|
|
private void _OnMemberPostUpdate()
|
|
{
|
|
DebugUtil.LogError("成员职位修改成功!!!");
|
|
}
|
|
#endregion
|
|
} |