476 lines
18 KiB
C#
476 lines
18 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2021-03-10
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "RedpointProxy" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 类功能描述
|
|
/// </summary>
|
|
public class RedPointProxy : F.GameProxy
|
|
{
|
|
public delegate void OnRedpointBroadcast(int num);
|
|
|
|
#region Field
|
|
|
|
// 红点树Root节点
|
|
readonly Dictionary<RedPointType, RedPointNode> _rootNodeDic = new Dictionary<RedPointType, RedPointNode>();
|
|
readonly Dictionary<string, string[]> _nodeSplitNames = new Dictionary<string, string[]>();
|
|
int _stagger;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
private void InitRedPointTreeNode()
|
|
{
|
|
var tmpTreeList = F.ListPool<string>.Get();
|
|
tmpTreeList.Add(RedPointConst.Cha);
|
|
tmpTreeList.Add(RedPointConst.ChaFull);
|
|
var rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.ChaPanel, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.Home);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.Home, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.World);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.World, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.Kungfu);
|
|
tmpTreeList.Add(RedPointConst.KungfuBook);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.KungfuPanel, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.Pet);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.Pet, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.Title);
|
|
tmpTreeList.Add(RedPointConst.TitleStudy);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.Title, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.Shop);
|
|
tmpTreeList.Add(RedPointConst.ShopCollect);
|
|
tmpTreeList.Add(RedPointConst.ShopRefresh);
|
|
tmpTreeList.Add(RedPointConst.ShopSpeedUp);
|
|
tmpTreeList.Add(RedPointConst.ShopCommon);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.ShopPanel, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.Activity);
|
|
tmpTreeList.Add(RedPointConst.ActivityFreeEnery);
|
|
tmpTreeList.Add(RedPointConst.ActivitySevenSign);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.Activity, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.Mission);
|
|
tmpTreeList.Add(RedPointConst.MissionAch);
|
|
tmpTreeList.Add(RedPointConst.MissionDay);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.Mission, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.BattlePass);
|
|
tmpTreeList.Add(RedPointConst.BattlePassActivation);
|
|
tmpTreeList.Add(RedPointConst.BattlePassMission);
|
|
tmpTreeList.Add(RedPointConst.BattlePassReward);
|
|
tmpTreeList.Add(RedPointConst.BattlePassMissionAndReward);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.BattlePass, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.Mail);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.Mail, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.Vip);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.Vip, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.FirstPay);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.FirstPay, rootNode);
|
|
|
|
tmpTreeList.Clear();
|
|
tmpTreeList.Add(RedPointConst.Extend);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.Extend, rootNode);
|
|
|
|
//tmpTreeList.Clear(); //女神节
|
|
//tmpTreeList.Add(RedPointConst.Woman);
|
|
//tmpTreeList.Add(RedPointConst.WomanSign);
|
|
//tmpTreeList.Add(RedPointConst.WomanExchange);
|
|
//tmpTreeList.Add(RedPointConst.WomanGift);
|
|
//tmpTreeList.Add(RedPointConst.WomanMission);
|
|
//rootNode = CreateNodes(tmpTreeList);
|
|
//_rootNodeDic.Add(RedPointType.Woman, rootNode);
|
|
|
|
tmpTreeList.Clear(); //清明节
|
|
tmpTreeList.Add(RedPointConst.QingMing);
|
|
tmpTreeList.Add(RedPointConst.QingMingSign);
|
|
tmpTreeList.Add(RedPointConst.QingMingExchange);
|
|
//tmpTreeList.Add(RedPointConst.QingMingGift);
|
|
//tmpTreeList.Add(RedPointConst.QingMingRecharge);
|
|
tmpTreeList.Add(RedPointConst.QingMingMission);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.QingMing, rootNode);
|
|
|
|
tmpTreeList.Clear();//功能解锁
|
|
tmpTreeList.Add(RedPointConst.Function);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.Function, rootNode);
|
|
|
|
tmpTreeList.Clear();//活动框
|
|
tmpTreeList.Add(RedPointConst.ActivityBox);
|
|
rootNode = CreateNodes(tmpTreeList);
|
|
_rootNodeDic.Add(RedPointType.ActivityBox, rootNode);
|
|
|
|
F.ListPool<string>.Release(tmpTreeList);
|
|
}
|
|
|
|
private void UpdateRedPointTreeNode()
|
|
{
|
|
_stagger++;
|
|
|
|
int state = BusinessProxy.Instance.GetRedPoint();
|
|
SetRpNum(RedPointType.Home, RedPointConst.Home, state);
|
|
|
|
state = CityProxy.Instance.GetRedPoint();
|
|
SetRpNum(RedPointType.World, RedPointConst.World, state);
|
|
|
|
state = BagProxy.Instance.GetRedPoint();
|
|
SetRpNum(RedPointType.ChaPanel, RedPointConst.ChaFull, state);
|
|
|
|
state = KungfuProxy.Instance.GetRedPoint();
|
|
SetRpNum(RedPointType.KungfuPanel, RedPointConst.Kungfu, state);
|
|
state = BookProxy.Instance.GetRedPoint();
|
|
SetRpNum(RedPointType.KungfuPanel, RedPointConst.KungfuBook, state);
|
|
|
|
state = SwordProxy.Instance.GetTitleRedPoint();
|
|
SetRpNum(RedPointType.Title, RedPointConst.TitleStudy, state);
|
|
//state = AffairProxy.Instance.GetTitleStudyRedPoint();
|
|
//SetRpNum(RedPointType.Title, RedPointConst.TitleStudy, state);
|
|
|
|
//
|
|
//state =ShopProxy.Instance.GetRedPoint1();
|
|
//SetRpNum(RedPointType.ShopPanel, RedPointConst.ShopCollect, state);
|
|
state = ShopProxy.Instance.GetRedPoint2();
|
|
SetRpNum(RedPointType.ShopPanel, RedPointConst.ShopRefresh, state);
|
|
state = ShopProxy.Instance.GetRedPoint3();
|
|
SetRpNum(RedPointType.ShopPanel, RedPointConst.ShopSpeedUp, state);
|
|
//state = ShopProxy.Instance.GetRedPoint4();
|
|
//SetRpNum(RedPointType.ShopPanel, RedPointConst.ShopCommon, state);
|
|
|
|
|
|
if (_stagger % 2 == 0)
|
|
{
|
|
state = PetProxy.Instance.GetRedPoint();
|
|
SetRpNum(RedPointType.Pet, RedPointConst.Pet, state);
|
|
|
|
var bpProxy = BattlePassProxy.Instance;
|
|
if (bpProxy)
|
|
{
|
|
state = bpProxy.GetRedPoint1();
|
|
SetRpNum(RedPointType.BattlePass, RedPointConst.BattlePassActivation, state);
|
|
state = bpProxy.GetRedPoint2();
|
|
SetRpNum(RedPointType.BattlePass, RedPointConst.BattlePassMission, state);
|
|
state = bpProxy.GetRedPoint3();
|
|
SetRpNum(RedPointType.BattlePass, RedPointConst.BattlePassReward, state);
|
|
state = bpProxy.GetRedPoint4();
|
|
SetRpNum(RedPointType.BattlePass, RedPointConst.BattlePassMissionAndReward, state);
|
|
}
|
|
|
|
state = VipProxy.Instance.GetRedPoint();
|
|
SetRpNum(RedPointType.Vip, RedPointConst.Vip, state);
|
|
|
|
state = FunctionProxy.Instance.GetRedPoint();
|
|
SetRpNum(RedPointType.Function, RedPointConst.Function, state);
|
|
|
|
}
|
|
|
|
if (_stagger % 2 == 1)
|
|
{
|
|
int extend = 0;
|
|
state = MissionProxy.Instance.GetRedPointDay();
|
|
//extend += state;
|
|
SetRpNum(RedPointType.Mission, RedPointConst.MissionDay, state);
|
|
state = MissionProxy.Instance.GetRedPointAch();
|
|
//extend += state;
|
|
SetRpNum(RedPointType.Mission, RedPointConst.MissionAch, state);
|
|
|
|
if (FunctionProxy.Instance.GetFunctionUnlock(FunctionProxy.FunctionId.解锁客栈功能))
|
|
{
|
|
state = ActivityProxy.Instance.GetRedPoint1();
|
|
extend += state;
|
|
SetRpNum(RedPointType.Activity, RedPointConst.ActivityFreeEnery, state);
|
|
state = ActivityProxy.Instance.GetRedPoint2();
|
|
extend += state;
|
|
SetRpNum(RedPointType.Activity, RedPointConst.ActivitySevenSign, state);
|
|
}
|
|
|
|
state = MailProxy.Instance.GetRedPoint1();
|
|
extend += state;
|
|
SetRpNum(RedPointType.Mail, RedPointConst.Mail, state);
|
|
|
|
SetRpNum(RedPointType.Extend, RedPointConst.Extend, extend);
|
|
}
|
|
|
|
if (_stagger % 3 == 1)
|
|
{
|
|
int extend = 0;
|
|
state = FirstPayProxy.Instance.GetRedPoint();
|
|
extend += state;
|
|
SetRpNum(RedPointType.FirstPay, RedPointConst.FirstPay, state);
|
|
|
|
//state = WomenActivity.Instance.GetRedPointSign();
|
|
//extend += state;
|
|
//SetRpNum(RedPointType.Woman, RedPointConst.WomanSign, state);
|
|
//state = WomenActivity.Instance.GetRedPointExchange();
|
|
//extend += state;
|
|
//SetRpNum(RedPointType.Woman, RedPointConst.WomanExchange, state);
|
|
//state = WomenActivity.Instance.GetRedPointGift();
|
|
//extend += state;
|
|
//SetRpNum(RedPointType.Woman, RedPointConst.WomanGift, state);
|
|
//state = WomenActivity.Instance.GetRedPointMission();
|
|
//extend += state;
|
|
//SetRpNum(RedPointType.Woman, RedPointConst.WomanMission, state);
|
|
|
|
state = QingMingActivity.Instance.GetRedPointSign();
|
|
extend += state;
|
|
SetRpNum(RedPointType.QingMing, RedPointConst.QingMingSign, state);
|
|
state = QingMingActivity.Instance.GetRedPointExchange();
|
|
extend += state;
|
|
SetRpNum(RedPointType.QingMing, RedPointConst.QingMingExchange, state);
|
|
//state = QingMingActivity.Instance.GetRedPointGift();
|
|
//extend += state;
|
|
//SetRpNum(RedPointType.QingMing, RedPointConst.QingMingGift, state);
|
|
//state = QingMingActivity.Instance.GetRedPointRecharge();
|
|
//extend += state;
|
|
//SetRpNum(RedPointType.QingMing, RedPointConst.QingMingRecharge, state);
|
|
state = QingMingActivity.Instance.GetRedPointMission();
|
|
extend += state;
|
|
SetRpNum(RedPointType.QingMing, RedPointConst.QingMingMission, state);
|
|
|
|
SetRpNum(RedPointType.ActivityBox, RedPointConst.ActivityBox, extend);
|
|
}
|
|
|
|
//公告
|
|
if (_stagger % 10 == 1)
|
|
{
|
|
state = KRemoteConfig.Instance.newNotice ? 1 : 0;
|
|
SetRpNum(RedPointType.Notice, RedPointConst.Notice, state);
|
|
}
|
|
}
|
|
|
|
private string[] GetNodeSplitNames(string nodeName)
|
|
{
|
|
if (_nodeSplitNames.TryGetValue(nodeName, out var result))
|
|
return result;
|
|
|
|
result = nodeName.Split('.');
|
|
_nodeSplitNames.Add(nodeName, result);
|
|
return result;
|
|
}
|
|
|
|
public void SetRpNum(RedPointType type, string nodeName, int rpNum)
|
|
{
|
|
var nodeList = GetNodeSplitNames(nodeName);
|
|
if (nodeList == null || nodeList.Length == 0)
|
|
return;
|
|
|
|
if (_rootNodeDic.TryGetValue(type, out RedPointNode node))
|
|
{
|
|
if (nodeList[0] != node.nodeName)
|
|
{
|
|
throw new Exception(string.Format("RedpointType和NodeName不对应,RedpointType:{0},NodeName:{1}", type, node.nodeName));
|
|
}
|
|
|
|
if (nodeList.Length == 1)
|
|
{
|
|
node.SetRedPointNum(rpNum);
|
|
return;
|
|
}
|
|
|
|
for (int i = 1; i < nodeList.Length; i++)
|
|
{
|
|
var subNodeName = nodeList[i];
|
|
if (!node.childs.ContainsKey(subNodeName))
|
|
{
|
|
Debug.Log("Does Not Contains Child Node :" + nodeList[i]);
|
|
return;
|
|
}
|
|
node = node.childs[subNodeName];
|
|
|
|
if (i == nodeList.Length - 1)
|
|
{
|
|
node.SetRedPointNum(rpNum);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void AddListener(RedPointType type, string nodeName, OnRedpointBroadcast callback)
|
|
{
|
|
var nodeList = GetNodeSplitNames(nodeName);
|
|
|
|
if (_rootNodeDic.TryGetValue(type, out RedPointNode node))
|
|
{
|
|
if (nodeList.Length == 1 && node.nodeName == nodeList[0])
|
|
{
|
|
node.numChangeFunc = callback;
|
|
node.SyncRedPoint();
|
|
return;
|
|
}
|
|
else if (nodeList[0] != node.nodeName)
|
|
{
|
|
throw new Exception(string.Format("RedpointType和NodeName不对应,RedpointType:{0},NodeName:{1}", type, nodeName));
|
|
}
|
|
|
|
for (int i = 1; i < nodeList.Length; i++)
|
|
{
|
|
var subNodeName = nodeList[i];
|
|
if (!node.childs.ContainsKey(subNodeName))
|
|
{
|
|
Debug.Log("Does Not Contains Child Node :" + nodeList[i]);
|
|
return;
|
|
}
|
|
node = node.childs[subNodeName];
|
|
if (i == nodeList.Length - 1)
|
|
{
|
|
node.numChangeFunc = callback;
|
|
node.SyncRedPoint();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RemoveLisnener(RedPointType type, string nodeName)
|
|
{
|
|
var nodeList = GetNodeSplitNames(nodeName);
|
|
|
|
if (_rootNodeDic.TryGetValue(type, out RedPointNode node))
|
|
{
|
|
if (nodeList.Length == 1 && node.nodeName == nodeList[0])
|
|
{
|
|
if (node.numChangeFunc != null) node.numChangeFunc = null;
|
|
return;
|
|
}
|
|
else if (nodeList[0] != node.nodeName)
|
|
{
|
|
throw new Exception(string.Format("RedpointType和NodeName不对应,RedpointType:{0},NodeName:{1}", type, nodeName));
|
|
}
|
|
|
|
for (int i = 1; i < nodeList.Length; i++)
|
|
{
|
|
var subNodeName = nodeList[i];
|
|
if (!node.childs.ContainsKey(subNodeName))
|
|
{
|
|
Debug.Log("Does Not Contains Child Node :" + nodeList[i]);
|
|
return;
|
|
}
|
|
node = node.childs[subNodeName];
|
|
if (i == nodeList.Length - 1)
|
|
{
|
|
if (node.numChangeFunc != null) node.numChangeFunc = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private RedPointNode CreateNodes(IList<string> treeList)
|
|
{
|
|
if (treeList == null || treeList.Count == 0)
|
|
return null;
|
|
|
|
var rootNode = new RedPointNode
|
|
{
|
|
nodeName = treeList[0],
|
|
};
|
|
|
|
for (int i = 1; i < treeList.Count; i++)
|
|
{
|
|
var tree = treeList[i];
|
|
var node = rootNode;
|
|
|
|
var treeSplit = GetNodeSplitNames(tree);
|
|
if (treeSplit[0] != rootNode.nodeName)
|
|
{
|
|
Debug.Log("RedPointTree Root Node Error:" + treeSplit[0]);
|
|
continue;
|
|
}
|
|
|
|
for (int j = 1; j < treeSplit.Length; j++)
|
|
{
|
|
var treeName = treeSplit[j];
|
|
if (!node.childs.TryGetValue(treeName, out var tmpNode))
|
|
{
|
|
tmpNode = new RedPointNode
|
|
{
|
|
nodeName = treeName,
|
|
parentNode = node,
|
|
};
|
|
node.childs.Add(treeName, tmpNode);
|
|
}
|
|
node = tmpNode;
|
|
}
|
|
}
|
|
|
|
return rootNode;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
public static RedPointProxy Instance;
|
|
|
|
// Use this for initialization
|
|
private void Start()
|
|
{
|
|
Instance = this;
|
|
|
|
InitRedPointTreeNode();
|
|
}
|
|
|
|
bool _loadCompleted;
|
|
public override void ReadArchive()
|
|
{
|
|
_loadCompleted = true;
|
|
}
|
|
|
|
public override void UpdatePerSecond()
|
|
{
|
|
if (_loadCompleted && !GlobalVar.IsBattling)
|
|
UpdateRedPointTreeNode();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|