2025-04-11 13:47:41 +08:00
|
|
|
using cfg.FunctionLockCfg;
|
|
|
|
|
using Framework;
|
|
|
|
|
using Framework.Condition;
|
2025-04-10 15:19:01 +08:00
|
|
|
using Gameplay.Net;
|
2025-04-11 13:47:41 +08:00
|
|
|
using Gameplay.PopUp;
|
2025-04-10 15:19:01 +08:00
|
|
|
using NLDPB;
|
2025-04-10 13:36:39 +08:00
|
|
|
using PhxhSDK;
|
2025-04-14 15:12:01 +08:00
|
|
|
using System;
|
2025-04-11 13:47:41 +08:00
|
|
|
using System.Collections.Generic;
|
2025-04-10 13:36:39 +08:00
|
|
|
|
|
|
|
|
namespace Gameplay.FunctionLock
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 功能锁管理器
|
|
|
|
|
/// </summary>
|
2025-04-11 13:47:41 +08:00
|
|
|
public sealed class FunctionLockManager : Singlenton<FunctionLockManager>, IInitable
|
2025-04-10 13:36:39 +08:00
|
|
|
{
|
2025-04-10 15:19:01 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 服务器功能锁id(按位存)
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int ServerFunctionLockId;
|
2025-04-11 13:47:41 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 功能锁弹窗
|
|
|
|
|
/// </summary>
|
2025-04-14 15:12:01 +08:00
|
|
|
private FunctionUnlock_PopUp functionUnlockPopUp;
|
2025-04-11 15:18:23 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 功能锁字典
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Dictionary<int, FunctionLock> dicFunctionLock;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 记录本地功能是否解锁
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Dictionary<int, bool> dicIsFunctionUnLock;
|
2025-04-11 17:38:09 +08:00
|
|
|
private List<FunctionLock> listTemp;
|
2025-04-14 15:12:01 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 播放中的动画数量
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int playingAnimCount;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 回调
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Action callback;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 是否播放解锁动画中
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsPlayingUnlockAnim { get { return playingAnimCount > 0; } }
|
2025-04-11 13:47:41 +08:00
|
|
|
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
2025-04-11 17:38:09 +08:00
|
|
|
listTemp = new();
|
2025-04-11 15:18:23 +08:00
|
|
|
dicFunctionLock = new Dictionary<int, FunctionLock>();
|
|
|
|
|
dicIsFunctionUnLock = new Dictionary<int, bool>();
|
2025-04-14 15:12:01 +08:00
|
|
|
playingAnimCount = 0;
|
2025-04-11 13:47:41 +08:00
|
|
|
|
2025-04-14 15:12:01 +08:00
|
|
|
EventManager.Instance.Register<string>(EventManager.EventName.UIOpenByAnimComplete, OnUIOpenByAnimComplte);
|
2025-04-11 13:47:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Release()
|
|
|
|
|
{
|
2025-04-14 15:12:01 +08:00
|
|
|
EventManager.Instance.Unregister<string>(EventManager.EventName.UIOpenByAnimComplete, OnUIOpenByAnimComplte);
|
2025-04-11 13:47:41 +08:00
|
|
|
|
2025-04-11 15:18:23 +08:00
|
|
|
dicIsFunctionUnLock.Clear();
|
|
|
|
|
dicFunctionLock?.Clear();
|
2025-04-11 13:47:41 +08:00
|
|
|
}
|
2025-04-10 15:19:01 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 初始化功能锁
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void InitFunctionLock()
|
|
|
|
|
{
|
2025-04-11 17:38:09 +08:00
|
|
|
#if FUNCTION_LOCK
|
2025-04-10 15:19:01 +08:00
|
|
|
ServerFunctionLockId = (int)Actor.Instance.Logic.GetCount((uint)LogicID.LockStatus);
|
2025-04-11 15:18:23 +08:00
|
|
|
|
|
|
|
|
foreach (DataFunctionLock cfg in TableManager.Instance.Tables.FunctionLockConfig.DataList)
|
|
|
|
|
{
|
2025-04-24 14:40:03 +08:00
|
|
|
if (IsUnlock(cfg.FunctionType)) // 已经解锁的不管
|
2025-04-11 15:18:23 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
dicIsFunctionUnLock[cfg.Id] = false;
|
|
|
|
|
ConditionReactor.Instance.AddReaction(cfg.UnlockCondition, OnFunctionUnlockByCondition, cfg, true);
|
|
|
|
|
}
|
2025-04-11 17:38:09 +08:00
|
|
|
#endif
|
2025-04-10 15:19:01 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-10 13:36:39 +08:00
|
|
|
/// <summary>
|
2025-04-24 14:40:03 +08:00
|
|
|
/// 功能是否解锁
|
2025-04-10 13:36:39 +08:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
2025-04-24 14:40:03 +08:00
|
|
|
public bool IsUnlock(E_Function functionType)
|
2025-04-10 13:36:39 +08:00
|
|
|
{
|
2025-04-24 14:40:03 +08:00
|
|
|
int id = (int)functionType;
|
|
|
|
|
|
2025-04-10 15:19:01 +08:00
|
|
|
return (id & ServerFunctionLockId) == id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-11 15:18:23 +08:00
|
|
|
/// 添加功能锁
|
2025-04-10 15:19:01 +08:00
|
|
|
/// </summary>
|
2025-04-11 15:18:23 +08:00
|
|
|
public void AddFunctionLock(FunctionLock functionLock)
|
2025-04-10 15:19:01 +08:00
|
|
|
{
|
2025-04-11 15:18:23 +08:00
|
|
|
dicFunctionLock[functionLock.FunctionLockCfgId] = functionLock;
|
2025-04-10 13:36:39 +08:00
|
|
|
}
|
2025-04-11 13:47:41 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
2025-04-11 15:18:23 +08:00
|
|
|
/// 移除功能锁
|
2025-04-11 13:47:41 +08:00
|
|
|
/// </summary>
|
2025-04-11 15:18:23 +08:00
|
|
|
/// <param name="id"></param>
|
|
|
|
|
public void RemoveFunctionLock(int id)
|
2025-04-11 13:47:41 +08:00
|
|
|
{
|
2025-04-11 15:18:23 +08:00
|
|
|
dicFunctionLock.Remove(id);
|
|
|
|
|
}
|
2025-04-11 13:47:41 +08:00
|
|
|
|
2025-04-11 15:18:23 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 保存服务器
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="flag"></param>
|
|
|
|
|
public void SaveServer(int flag)
|
|
|
|
|
{
|
|
|
|
|
int savaId = 1 << (flag - 1);
|
|
|
|
|
ServerFunctionLockId |= savaId;
|
|
|
|
|
NetHelper.SaveFunctionLock(ServerFunctionLockId);
|
2025-04-25 16:23:55 +08:00
|
|
|
EventManager.Instance.Send(EventManager.EventName.FunctionUnLock, (E_Function)flag);
|
2025-04-11 13:47:41 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-14 15:12:01 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 添加动画状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void AddAnimState()
|
|
|
|
|
{
|
|
|
|
|
++playingAnimCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 移除动画状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void RemoveAnimState()
|
|
|
|
|
{
|
|
|
|
|
if (playingAnimCount > 0)
|
|
|
|
|
--playingAnimCount;
|
|
|
|
|
|
|
|
|
|
if (0 == playingAnimCount)
|
|
|
|
|
{
|
|
|
|
|
callback?.Invoke();
|
|
|
|
|
callback = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加回调
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="callbackAction"></param>
|
|
|
|
|
public void AddCallback(Action callbackAction)
|
|
|
|
|
{
|
|
|
|
|
callback += callbackAction;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-11 13:47:41 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 根据条件进行功能解锁
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void OnFunctionUnlockByCondition(bool conditionResult, object callBackParam, int reactionID)
|
|
|
|
|
{
|
|
|
|
|
if (!conditionResult)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-04-11 15:18:23 +08:00
|
|
|
ConditionReactor.Instance.RemoveReaction(reactionID);
|
|
|
|
|
if (callBackParam is not DataFunctionLock dataFunctionLock)
|
|
|
|
|
{
|
|
|
|
|
DebugUtil.LogError("参数错误");
|
2025-04-11 13:47:41 +08:00
|
|
|
return;
|
2025-04-11 15:18:23 +08:00
|
|
|
}
|
2025-04-11 13:47:41 +08:00
|
|
|
|
2025-04-11 15:18:23 +08:00
|
|
|
DataFunctionLock cfg = dataFunctionLock;
|
|
|
|
|
dicIsFunctionUnLock[cfg.Id] = true;
|
2025-04-11 13:47:41 +08:00
|
|
|
|
|
|
|
|
if (null == functionUnlockPopUp)
|
2025-04-14 15:12:01 +08:00
|
|
|
functionUnlockPopUp = new FunctionUnlock_PopUp();
|
2025-04-11 13:47:41 +08:00
|
|
|
|
2025-04-11 17:38:09 +08:00
|
|
|
functionUnlockPopUp.AddFunctionLockCfg(cfg);
|
2025-04-11 13:47:41 +08:00
|
|
|
|
|
|
|
|
PopUpManager.Instance.AddPopUp(functionUnlockPopUp);
|
|
|
|
|
}
|
2025-04-11 15:18:23 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// UI完全打开完成
|
|
|
|
|
/// </summary>
|
2025-04-14 15:12:01 +08:00
|
|
|
private void OnUIOpenByAnimComplte(string uiName)
|
2025-04-11 15:18:23 +08:00
|
|
|
{
|
|
|
|
|
foreach (FunctionLock functionLock in dicFunctionLock.Values)
|
|
|
|
|
{
|
|
|
|
|
if (null == functionLock)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (functionLock.UIName != uiName)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!dicIsFunctionUnLock.TryGetValue(functionLock.FunctionLockCfgId, out bool isUnlock))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (isUnlock)
|
2025-04-11 17:38:09 +08:00
|
|
|
listTemp.Add(functionLock);
|
2025-04-11 15:18:23 +08:00
|
|
|
}
|
2025-04-11 17:38:09 +08:00
|
|
|
|
|
|
|
|
foreach (FunctionLock functionLock in listTemp)
|
|
|
|
|
{
|
|
|
|
|
RemoveFunctionLock(functionLock.FunctionLockCfgId);
|
|
|
|
|
functionLock.PlayUnlockAnim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listTemp.Clear();
|
2025-04-11 15:18:23 +08:00
|
|
|
}
|
2025-04-10 13:36:39 +08:00
|
|
|
}
|
|
|
|
|
}
|