171 lines
5.7 KiB
C#
171 lines
5.7 KiB
C#
using System.Collections.Generic;
|
||
using cfg.BattlePassCfg;
|
||
using Gameplay.Net;
|
||
using System.Linq;
|
||
using Framework;
|
||
using PhxhSDK;
|
||
using NLDPB;
|
||
|
||
public class BattlePassManager : Singlenton<BattlePassManager>
|
||
{
|
||
public struct LevelReward
|
||
{
|
||
public int BasicRewardID;
|
||
public int BasicRewardCount;
|
||
public int AdvancedRewardID;
|
||
public int AdvancedRewardCount;
|
||
|
||
public LevelReward(DataBattlePassRewards rewardsData)
|
||
{
|
||
var basicReward = rewardsData.BasicReward;
|
||
var advancedReward = rewardsData.AdvancedReward;
|
||
if (basicReward.Length != 2 || advancedReward.Length != 2)
|
||
{
|
||
DebugUtil.LogError("赛季{0} 的 {1} 等级奖励配置错误", Instance.curBattlePassID,
|
||
rewardsData.PassLevel);
|
||
}
|
||
|
||
BasicRewardID = basicReward[0];
|
||
BasicRewardCount = basicReward[1];
|
||
AdvancedRewardID = advancedReward[0];
|
||
AdvancedRewardCount = advancedReward[1];
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通行证等级结构
|
||
/// </summary>
|
||
public struct BattlePassLevel
|
||
{
|
||
/// <summary>
|
||
/// 普通等级
|
||
/// </summary>
|
||
public int NormalLevel;
|
||
|
||
/// <summary>
|
||
/// 高级等级
|
||
/// </summary>
|
||
public int AdvancedLevel;
|
||
|
||
public BattlePassLevel(int normalLevel, int advancedLevel)
|
||
{
|
||
NormalLevel = normalLevel;
|
||
AdvancedLevel = advancedLevel;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 当前赛季通行证数据
|
||
/// </summary>
|
||
private DataBattlePass curBattlePassData;
|
||
|
||
public DataBattlePass CurBattlePassData => curBattlePassData;
|
||
|
||
/// <summary>
|
||
/// 当前赛季通行证ID
|
||
/// </summary>
|
||
private int curBattlePassID;
|
||
|
||
private DataBattlePassRewards curBattlePassRewards;
|
||
|
||
/// <summary>
|
||
/// 当前赛季的等级奖励
|
||
/// </summary>
|
||
private Dictionary<int, LevelReward> curLevelRewards;
|
||
|
||
/// <summary>
|
||
/// 当前等级
|
||
/// </summary>
|
||
private int unLockLevel;
|
||
|
||
/// <summary>
|
||
/// 当前已经领取奖励的等级
|
||
/// </summary>
|
||
private BattlePassLevel getRewardLevel;
|
||
|
||
/// <summary>
|
||
/// 醒目等级
|
||
/// </summary>
|
||
private List<int> specialRewardLevels;
|
||
|
||
public int UnLockLevel => unLockLevel;
|
||
|
||
public BattlePassLevel GetRewardLevel => getRewardLevel;
|
||
|
||
public Dictionary<int, LevelReward> CurLevelRewards => curLevelRewards;
|
||
|
||
public List<int> SpecialRewardLevels => specialRewardLevels;
|
||
|
||
public bool IsAdvancedAccount;
|
||
|
||
public void Init()
|
||
{
|
||
EventManager.Instance.Register(EventManager.EventName.BattlePassBuyLevelSuccess, RefreshBattlePassLevel);
|
||
EventManager.Instance.Register(EventManager.EventName.BattlePassGetAllReward, RefreshGetRewardLevel);
|
||
|
||
curBattlePassID = (int)Actor.Instance.Logic.GetCount((uint)LogicID.BattlePassId);
|
||
/*DebugUtil.LogError("赛季ID:{0},是否购买VIP标识:{1},当前等级:{2},普通领取等级:{3},VIP领取等级:{4}",
|
||
Actor.Instance.Logic.GetCount((uint)LogicID.BattlePassId),
|
||
Actor.Instance.Logic.GetCount((uint)LogicID.BattlePassIsAdvanced),
|
||
Actor.Instance.Logic.GetCount((uint)LogicID.BattlePassLevel),
|
||
Actor.Instance.Logic.GetCount((uint)LogicID.BattlePassRewardLevel),
|
||
Actor.Instance.Logic.GetCount((uint)LogicID.BattlePassAdvancedRewardLevel));*/
|
||
|
||
// 当前赛季配置
|
||
var cfg = TableManager.Instance.Tables.BattlePassConfig.DataMap;
|
||
if (!cfg.TryGetValue(curBattlePassID, out var dataBattlePass))
|
||
{
|
||
DebugUtil.LogError("服务器下发的赛季ID[{0}] ,没有对应配置, 使用默认配置", curBattlePassID);
|
||
curBattlePassData = cfg[0];
|
||
curBattlePassID = curBattlePassData.ID;
|
||
}
|
||
|
||
curBattlePassData = dataBattlePass;
|
||
|
||
// 筛选当前赛季奖励
|
||
curLevelRewards = new Dictionary<int, LevelReward>();
|
||
var rewardsList = TableManager.Instance.Tables.BattlePassRewardsConfig.DataList;
|
||
var rewardsData = rewardsList.Where(data => data.ID == curBattlePassID).ToList();
|
||
|
||
foreach (var data in rewardsData)
|
||
{
|
||
var levelReward = new LevelReward(data);
|
||
curLevelRewards[data.PassLevel] = levelReward;
|
||
}
|
||
|
||
// 醒目奖励等级
|
||
specialRewardLevels = curBattlePassData.SpecialRewardLevel;
|
||
specialRewardLevels.Sort();
|
||
|
||
// 高级账号
|
||
IsAdvancedAccount = Actor.Instance.Logic.GetCount((uint)LogicID.BattlePassIsAdvanced) == 1;
|
||
|
||
RefreshBattlePassLevel();
|
||
|
||
RefreshGetRewardLevel();
|
||
}
|
||
|
||
public void Release()
|
||
{
|
||
EventManager.Instance.Unregister(EventManager.EventName.BattlePassBuyLevelSuccess, RefreshBattlePassLevel);
|
||
EventManager.Instance.Unregister(EventManager.EventName.BattlePassGetAllReward, RefreshGetRewardLevel);
|
||
}
|
||
|
||
public uint GetPointItemCount()
|
||
{
|
||
return Actor.Instance.Item.GetItemCount(curBattlePassData.PointItem);
|
||
}
|
||
|
||
private void RefreshBattlePassLevel()
|
||
{
|
||
// 解锁和领取等级
|
||
unLockLevel = (int)Actor.Instance.Logic.GetCount((uint)LogicID.BattlePassLevel);
|
||
}
|
||
|
||
private void RefreshGetRewardLevel()
|
||
{
|
||
var rewardNormal = (int)Actor.Instance.Logic.GetCount((uint)LogicID.BattlePassRewardLevel);
|
||
var rewardAdvanced = (int)Actor.Instance.Logic.GetCount((uint)LogicID.BattlePassAdvancedRewardLevel);
|
||
getRewardLevel = new BattlePassLevel(rewardNormal, rewardAdvanced);
|
||
}
|
||
} |