using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using LitJson;
|
using UnityEngine;
|
|
public class HeroDebutManager : GameSystemManager<HeroDebutManager>, IOpenServerActivity
|
{
|
public int[] xbGridArr;
|
public Dictionary<int, int[][]> heroQaulityColor;
|
public override void Init()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += OnBeforePlayerDataInitializeEventOnRelogin;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
OperationTimeHepler.Instance.operationTimeUpdateEvent += OperationTimeUpdateEvent;
|
OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
|
StoreModel.Instance.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
|
GeneralActInfoManager.Instance.OnUpdateActSignInfosEvent += OnUpdateActSignInfosEvent;
|
HeroManager.Instance.onHeroChangeEvent += OnHeroChangeEvent;
|
TimeMgr.Instance.OnDayEvent += OnDayEvent;
|
|
|
var config = FuncConfigConfig.Get("HeroAppear");
|
xbGridArr = JsonMapper.ToObject<int[]>(config.Numerical1);
|
heroQaulityColor = ConfigParse.ParseIntArray2Dict(config.Numerical2);
|
|
InitRedPointId();
|
}
|
|
public void SetheroQaulityColor(GradientText text, int qaulity)
|
{
|
if (!heroQaulityColor.TryGetValue(qaulity, out var colors)) return;
|
if (colors?.Length < 2) return;
|
text.SetVerticalGradient(ParseColor32(colors[0]), ParseColor32(colors[1]));
|
}
|
|
public override void Release()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= OnBeforePlayerDataInitializeEventOnRelogin;
|
DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
OperationTimeHepler.Instance.operationTimeUpdateEvent -= OperationTimeUpdateEvent;
|
OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent -= OperationAdvanceEvent;
|
StoreModel.Instance.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
|
GeneralActInfoManager.Instance.OnUpdateActSignInfosEvent -= OnUpdateActSignInfosEvent;
|
HeroManager.Instance.onHeroChangeEvent -= OnHeroChangeEvent;
|
TimeMgr.Instance.OnDayEvent -= OnDayEvent;
|
}
|
|
private void OnDayEvent()
|
{
|
UpdateRedpoint();
|
}
|
|
private void OnHeroChangeEvent(HeroInfo info)
|
{
|
UpdateRedpoint();
|
}
|
|
private void OnUpdateActSignInfosEvent(int arg1, int arg2)
|
{
|
UpdateRedpoint();
|
}
|
|
private void RefreshBuyShopLimitEvent()
|
{
|
UpdateRedpoint();
|
}
|
|
private void OnBeforePlayerDataInitializeEventOnRelogin()
|
{
|
isSendFirst = true;
|
starHeroIndexDict.Clear();
|
starFreeAwardDict.Clear();
|
callHeroIndexDict.Clear();
|
}
|
|
private void OnPlayerLoginOk()
|
{
|
TryPopWin();
|
}
|
|
private void OnFuncStateChangeEvent(int obj)
|
{
|
if (obj != (int)FuncOpenEnum.HeroDebut)
|
return;
|
TryPopWin();
|
}
|
public readonly int sendRankType = 6;
|
public int loadRankType => actNum * 1000 + sendRankType;
|
public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_DateActivity;
|
public const int activityID = (int)NewDayActivityID.HeroDebutAct;
|
public static OperationType operaType = OperationType.HeroDebut;
|
public Redpoint redPoint = new Redpoint(MainRedDot.HeroDebutRepoint);
|
|
public bool IsOpen => OperationTimeHepler.Instance.SatisfyOpenCondition(operaType);
|
|
public bool IsAdvance => OperationTimeHepler.Instance.SatisfyAdvanceCondition(operaType);
|
|
public bool priorityOpen => redPoint.state == RedPointState.Simple;
|
public readonly int actNum = 10;
|
public event Action<int> onStateUpdate;
|
|
private void OperationTimeUpdateEvent(OperationType type)
|
{
|
if (type == operaType)
|
{
|
if (UIManager.Instance.IsOpened<HeroDebutPopWin>())
|
UIManager.Instance.CloseWindow<HeroDebutPopWin>();
|
if (UIManager.Instance.IsOpened<HeroDebutWin>())
|
UIManager.Instance.CloseWindow<HeroDebutWin>();
|
UpdateRedpoint();
|
}
|
}
|
|
private void OperationStartEvent(OperationType type, int state)
|
{
|
if (type == operaType && state == 0)
|
{
|
onStateUpdate?.Invoke(activityID);
|
TryPopWin();
|
UpdateRedpoint();
|
}
|
}
|
|
private void OperationEndEvent(OperationType type, int state)
|
{
|
if (type == operaType)
|
{
|
onStateUpdate?.Invoke(activityID);
|
if (UIManager.Instance.IsOpened<HeroDebutPopWin>())
|
UIManager.Instance.CloseWindow<HeroDebutPopWin>();
|
if (UIManager.Instance.IsOpened<HeroDebutWin>())
|
UIManager.Instance.CloseWindow<HeroDebutWin>();
|
UpdateRedpoint();
|
}
|
}
|
private void OperationAdvanceEvent(OperationType type)
|
{
|
if (type == operaType)
|
{
|
onStateUpdate?.Invoke(activityID);
|
UpdateRedpoint();
|
}
|
}
|
|
public OperationHeroAppearInfo GetOperationHeroAppearInfo()
|
{
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out OperationHeroAppearInfo act);
|
return act;
|
}
|
|
public void SetHeroSquareIcon(ImageEx image, string name)
|
{
|
var sprite = UILoader.LoadSprite("HeroHead", name);
|
if (sprite != null)
|
{
|
image.overrideSprite = sprite;
|
return;
|
}
|
|
image.SetSprite("herohead_default");
|
}
|
|
public void GetActTimeStr(TextEx timeText, string key = "TimeRush05")
|
{
|
var act = GetOperationHeroAppearInfo();
|
if (act == null)
|
{
|
timeText.text = Language.Get("OSActivity6");
|
return;
|
}
|
timeText.text = Language.Get(key, TimeUtility.SecondsToShortDHMS(act.GetResetSurplusTime()));
|
}
|
|
public void SetGradientTextColor(GradientText text, int[][] colors)
|
{
|
if (colors?.Length < 4) return;
|
text.topLeftColor = ParseColor32(colors[0]);
|
text.topRightColor = ParseColor32(colors[1]);
|
text.bottomLeftColor = ParseColor32(colors[2]);
|
text.bottomRightColor = ParseColor32(colors[3]);
|
text.SetVerticesDirty();
|
}
|
|
public Color32 ParseColor32(int[] colorArr)
|
{
|
return new Color32()
|
{
|
r = (byte)(colorArr.Length > 0 ? colorArr[0] : 0),
|
g = (byte)(colorArr.Length > 1 ? colorArr[1] : 0),
|
b = (byte)(colorArr.Length > 2 ? colorArr[2] : 0),
|
a = (byte)(colorArr.Length > 3 ? colorArr[3] : 255),
|
};
|
}
|
|
|
public int GetDefaultSkinID(int heroID)
|
{
|
HeroConfig heroConfig = HeroConfig.Get(heroID);
|
if (heroConfig == null || heroConfig.SkinIDList.IsNullOrEmpty()) return 0;
|
return heroConfig.SkinIDList[0];
|
}
|
|
public bool IsHeroDebutOpen()
|
{
|
if (!IsOpen) return false;
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.HeroDebut)) return false;
|
return true;
|
}
|
|
|
public int GetHeroIdIndex(int cfgID, int heroID)
|
{
|
var config = ActHeroAppearConfig.Get(cfgID);
|
if (config == null) return 0;
|
|
var heroArr = config.ActHeroIDList;
|
if (heroArr.IsNullOrEmpty()) return 0;
|
|
int index = Array.IndexOf(heroArr, heroID);
|
return index;
|
}
|
|
|
|
public event Action OnNowCallChooseHeroIDChangeEvent;
|
private int m_heroAppearActNum = 0;
|
public int nowCallChooseHeroID
|
{
|
get { return m_heroAppearActNum; }
|
set
|
{
|
if (m_heroAppearActNum == value) return;
|
m_heroAppearActNum = value;
|
OnNowCallChooseHeroIDChangeEvent?.Invoke();
|
}
|
}
|
public event Action<int> OnUpdateHeroAppearPlayerInfoEvent;
|
public void UpdateHeroAppearPlayerInfo(HAA22_tagSCActHeroAppearPlayerInfo vNetData)
|
{
|
if (vNetData == null) return;
|
int actNum = vNetData.ActNum;
|
starHeroIndexDict[actNum] = vNetData.StarHeroIndex;
|
callHeroIndexDict[actNum] = vNetData.CallHeroIndex;
|
|
if (!starFreeAwardDict.TryGetValue(actNum, out var dict))
|
{
|
dict = new Dictionary<int, uint>();
|
starFreeAwardDict[actNum] = dict;
|
}
|
dict[vNetData.StarHeroIndex] = vNetData.StarFreeAward;
|
UpdateRedpoint();
|
OnUpdateHeroAppearPlayerInfoEvent?.Invoke(actNum);
|
}
|
|
public void SendHeroAppearStarHeroSelect(int actNum, int starHeroIndex)
|
{
|
var pack = new CAA01_tagCSActHeroAppearStarHeroSelect();
|
pack.ActNum = (byte)actNum; // 活动编号
|
pack.StarHeroIndex = (byte)starHeroIndex; // 升星计划选择的武将ID索引
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public void SnedHeroAppearCallHeroSelect(int actNum, int callHeroIndex)
|
{
|
var pack = new CAA02_tagCSActHeroAppearCallHeroSelect();
|
pack.ActNum = (byte)actNum; // 活动编号
|
pack.CallHeroIndex = (byte)callHeroIndex; // 招募选择的武将ID索引
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public void SendGetStarReward()
|
{
|
var pack = new CA504_tagCMPlayerGetReward();
|
pack.RewardType = 10;
|
pack.DataEx = (uint)actNum;
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
#region 红点
|
public int GetRedPointId(HeroDebutRedPointType type)
|
{
|
return MainRedDot.HeroDebutRepoint * 10 + (int)type;
|
}
|
public Redpoint checkInRedpoint;
|
public Redpoint starUpRedpoint;
|
public Redpoint shopRedpoint;
|
public Redpoint giftRedpoint;
|
public void InitRedPointId()
|
{
|
checkInRedpoint ??= new Redpoint(MainRedDot.HeroDebutRepoint, GetRedPointId(HeroDebutRedPointType.CheckIn));
|
starUpRedpoint ??= new Redpoint(MainRedDot.HeroDebutRepoint, GetRedPointId(HeroDebutRedPointType.StarUp));
|
shopRedpoint ??= new Redpoint(MainRedDot.HeroDebutRepoint, GetRedPointId(HeroDebutRedPointType.Shop));
|
giftRedpoint ??= new Redpoint(MainRedDot.HeroDebutRepoint, GetRedPointId(HeroDebutRedPointType.Gift));
|
}
|
|
public void UpdateRedpoint()
|
{
|
redPoint.state = RedPointState.None;
|
checkInRedpoint.state = RedPointState.None;
|
starUpRedpoint.state = RedPointState.None;
|
shopRedpoint.state = RedPointState.None;
|
giftRedpoint.state = RedPointState.None;
|
|
if (!IsHeroDebutOpen()) return;
|
|
if (HasCheckInCanHave()) //签到赠礼
|
{
|
checkInRedpoint.state = RedPointState.Simple;
|
}
|
|
if (HasStarUpCanHave())//星级提升
|
{
|
starUpRedpoint.state = RedPointState.Simple;
|
}
|
|
//兑换商店每天0点显示红点,点击进入一次界面后消失
|
if (!IsShopVisitedToday) //兑换商店
|
{
|
shopRedpoint.state = RedPointState.Simple;
|
}
|
|
if (HasGiftCanHave())//皇权礼包
|
{
|
giftRedpoint.state = RedPointState.Simple;
|
}
|
}
|
#endregion
|
|
#region 拍脸界面
|
public bool IsTodayPop
|
{
|
get
|
{
|
int lastPopTime = LoadPopTimeData();
|
int todayStartTime = TimeUtility.GetTodayStartTick();
|
return lastPopTime < todayStartTime;
|
}
|
}
|
private string PopTimeDataKey { get { return $"HeroDebutManager_PopTimeData_{PlayerDatas.Instance.PlayerId}"; } }
|
|
private int LoadPopTimeData()
|
{
|
return LocalSave.GetInt(PopTimeDataKey);
|
}
|
|
public void SavePopTimeData()
|
{
|
LocalSave.SetInt(PopTimeDataKey, TimeUtility.AllSeconds);
|
}
|
|
private void TryPopWin()
|
{
|
if (!IsHeroDebutOpen()) return;
|
if (!IsTodayPop) return;
|
if (UIManager.Instance.IsOpened<HeroDebutPopWin>()) return;
|
if (UIManager.Instance.IsOpened<HeroDebutWin>()) return;
|
PopupWindowsProcessor.Instance.Add("HeroDebutPopWin");
|
}
|
#endregion
|
|
#region 签到
|
private int GetNowDayNum()
|
{
|
var act = GetOperationHeroAppearInfo();
|
if (act == null) return 0;
|
|
int dayNum = act.IndexOfDays(TimeUtility.ServerNow);
|
return dayNum < 0 ? 0 : dayNum + 1;
|
}
|
|
private bool IsCheckInGridUnlock(int gridDayNum)
|
{
|
int nowDayNum = GetNowDayNum();
|
if (nowDayNum <= 0) return false;
|
|
return nowDayNum >= gridDayNum;
|
}
|
|
/// <summary>
|
/// 0-未解锁 1-可签 2-已签
|
/// </summary>
|
public int GetCheckInState(int gridDayNum)
|
{
|
var act = GetOperationHeroAppearInfo();
|
if (act == null) return 0;
|
|
int actType = act.ActType;
|
if (GeneralActInfoManager.Instance.IsDaySigned(actType, actNum, gridDayNum)) return 2;
|
if (IsCheckInGridUnlock(gridDayNum)) return 1;
|
return 0;
|
}
|
|
public void SendGetCheckInReward()
|
{
|
var act = GetOperationHeroAppearInfo();
|
if (act == null) return;
|
|
int actType = act.ActType;
|
GeneralActInfoManager.Instance.SendGetSignReward(actType, actNum);
|
}
|
|
public bool HasCheckInCanHave()
|
{
|
var act = GetOperationHeroAppearInfo();
|
if (act == null) return false;
|
|
var config = ActHeroAppearConfig.Get(act.CfgID);
|
if (config == null) return false;
|
|
int templateID = config.SignTempID;
|
var list = ActSignAwardConfig.GetDayNumSortList(templateID);
|
if (list == null) return false;
|
|
for (int i = 0; i < list.Count; i++)
|
{
|
int dayNum = list[i];
|
int state = GetCheckInState(dayNum);
|
if (state == 1) return true;
|
}
|
return false;
|
}
|
#endregion
|
|
#region 升星计划
|
|
//<活动编号,升星计划选择的武将ID索引>
|
public Dictionary<int, int> starHeroIndexDict = new();
|
|
//<活动编号,<升星计划选择的武将ID索引,升星计划免费奖励记录>>
|
public Dictionary<int, Dictionary<int, uint>> starFreeAwardDict = new();
|
|
/// <summary>
|
/// 当前升星计划选中的武将ID
|
/// </summary>
|
public int GetCurrentDisplayStarUpHeroId()
|
{
|
var act = GetOperationHeroAppearInfo();
|
if (act == null) return 0;
|
if (!starHeroIndexDict.TryGetValue(actNum, out int index)) return 0;
|
|
var config = ActHeroAppearConfig.Get(act.CfgID);
|
if (config == null || config.ActHeroIDList?.Length <= index) return 0;
|
|
return config.ActHeroIDList[index];
|
}
|
|
private Dictionary<int, Dictionary<int, int[][]>> showHeroGiftItemInfoDict = new();
|
public bool TryGetStarUpAwardArr(int id, int heroID, out int[][] arr)
|
{
|
arr = null;
|
var config = ActHeroAppearStarConfig.Get(id);
|
if (config == null) return false;
|
|
var ctgConfig = CTGConfig.Get(config.StarGiftCTGID);
|
if (ctgConfig == null) return false;
|
|
if (!showHeroGiftItemInfoDict.TryGetValue(id, out var dict))
|
{
|
dict = new Dictionary<int, int[][]>();
|
showHeroGiftItemInfoDict[id] = dict;
|
}
|
|
if (!dict.TryGetValue(heroID, out arr))
|
{
|
// 如果缓存里没有当前武将的数据,才进行解析
|
var giftdict = ConfigParse.ParseIntArray2Dict(config.HeroGiftItemInfo);
|
int[][] ctgArray = ctgConfig.GainItemList;
|
|
foreach (var kvp in giftdict)
|
{
|
int hId = kvp.Key;
|
int[][] hGift = kvp.Value ?? Array.Empty<int[]>();
|
dict[hId] = hGift.Concat(ctgArray).ToArray();
|
}
|
|
// 如果遍历完发现配表里根本没有这个 heroID
|
if (!dict.TryGetValue(heroID, out arr))
|
{
|
arr = ctgArray;
|
dict[heroID] = arr;
|
}
|
}
|
|
return true;
|
}
|
|
/// <summary>
|
/// 0 - 未解锁 1 - 可领取 2 - 已领取
|
/// </summary>
|
public int GetStarUpFreeState(int id)
|
{
|
var config = ActHeroAppearStarConfig.Get(id);
|
if (config == null) return 0;
|
|
int heroId = GetCurrentDisplayStarUpHeroId();
|
var heroConfig = HeroConfig.Get(heroId);
|
if (heroConfig == null) return 0;
|
|
if (!starHeroIndexDict.TryGetValue(actNum, out int index)) return 0;
|
if (IsStarUpFreeHave(index, config.AwardIndex)) return 2;
|
if (IsHeroStarCntOk(heroConfig.HeroID, config.NeedStar)) return 1;
|
return 0;
|
}
|
|
private bool IsStarUpFreeHave(int starHeroIndex, int awardIndex)
|
{
|
if (!starFreeAwardDict.TryGetValue(actNum, out var dict)) return false;
|
if (!dict.TryGetValue(starHeroIndex, out uint freeAward)) return false;
|
return ((freeAward >> awardIndex) & 1u) == 1u;
|
}
|
|
public bool IsHeroStarCntOk(int heroId, int needStar)
|
{
|
return GetNowHeroMaxStarCnt(heroId) >= needStar;
|
}
|
|
public int GetNowHeroMaxStarCnt(int heroId)
|
{
|
int res = 0;
|
foreach (var item in HeroManager.Instance.GetHeroList())
|
{
|
if (item == null) continue;
|
if (item.heroId == heroId)
|
{
|
if (res < item.heroStar)
|
res = item.heroStar;
|
}
|
}
|
return res;
|
}
|
|
public bool TryGetStarUpStateIndex(int starGiftTempID, int tarState, out int index)
|
{
|
index = 0;
|
var list = ActHeroAppearStarConfig.GetAwardIndexSortList(starGiftTempID);
|
if (list == null) return false;
|
|
for (int i = 0; i < list.Count; i++)
|
{
|
var awardIndex = list[i];
|
var config = ActHeroAppearStarConfig.GetConfig(starGiftTempID, awardIndex);
|
if (config == null) continue;
|
|
int state = GetStarUpFreeState(config.ID);
|
if (state == tarState)
|
{
|
index = i;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public int GetStarUpJumpIndex(int starGiftTempID)
|
{
|
// 优先查找可领取的奖励
|
if (TryGetStarUpStateIndex(starGiftTempID, 1, out int index)) return index;
|
|
// 若没有可领取的,则查找未达到条件的奖励
|
if (TryGetStarUpStateIndex(starGiftTempID, 0, out index)) return index;
|
|
// 都没有
|
return 0;
|
}
|
|
public bool HasStarUpCanHave()
|
{
|
var act = GetOperationHeroAppearInfo();
|
if (act == null) return false;
|
|
var config = ActHeroAppearConfig.Get(act.CfgID);
|
if (config == null) return false;
|
|
int starGiftTempID = config.StarGiftTempID;
|
return TryGetStarUpStateIndex(starGiftTempID, 1, out _);
|
}
|
#endregion
|
|
#region 兑换商店
|
|
|
private string ShopVisitTimeDataKey { get { return $"HeroDebutManager_ShopVisitTime_{PlayerDatas.Instance.PlayerId}"; } }
|
|
private int LoadShopVisitTimeData()
|
{
|
return LocalSave.GetInt(ShopVisitTimeDataKey);
|
}
|
|
public void SaveShopVisitTimeData()
|
{
|
LocalSave.SetInt(ShopVisitTimeDataKey, TimeUtility.AllSeconds);
|
}
|
public bool IsShopVisitedToday
|
{
|
get
|
{
|
int lastVisitTime = LoadShopVisitTimeData();
|
int todayStartTime = TimeUtility.GetTodayStartTick();
|
return lastVisitTime >= todayStartTime;
|
}
|
}
|
#endregion
|
|
#region 皇权礼包
|
//没售罄
|
public bool IsCanBuyToday(int ctgID)
|
{
|
CTGConfig config = CTGConfig.Get(ctgID);
|
if (config == null) return false;
|
if (!RechargeManager.Instance.TryGetRechargeCount(ctgID, out var rechargeCount)) return false;
|
|
if (config.DailyBuyCount == 0) return true;
|
return rechargeCount.todayCount < config.DailyBuyCount;
|
}
|
|
public bool IsNoSellOutCTGID(int ctgID)
|
{
|
CTGConfig config = CTGConfig.Get(ctgID);
|
if (config == null) return false;
|
if (!RechargeManager.Instance.TryGetRechargeCount(ctgID, out var rechargeCount)) return false;
|
return rechargeCount.totalCount < config.TotalBuyCount;
|
}
|
|
// 免费商品
|
public bool IsFreeShop(int shopID)
|
{
|
StoreConfig config = StoreConfig.Get(shopID);
|
if (config == null) return false;
|
return config.MoneyNum == 0;
|
}
|
|
//没售罄
|
public bool IsNoSellOutShopID(int shopID)
|
{
|
StoreConfig config = StoreConfig.Get(shopID);
|
if (config == null) return false;
|
|
StoreModel.Instance.TryGetIsSellOut(config, out int remainNum);
|
return remainNum > 0;
|
}
|
|
public List<HeroDebutGiftItem> GetGiftItemList(bool isSort = false)
|
{
|
var act = GetOperationHeroAppearInfo();
|
if (act == null) return null;
|
|
var config = ActHeroAppearConfig.Get(act.CfgID);
|
if (config == null) return null;
|
|
List<HeroDebutGiftItem> res = new List<HeroDebutGiftItem>();
|
|
var list = StoreModel.Instance.storeTypeDict[config.GiftShopType];
|
if (!list.IsNullOrEmpty())
|
{
|
for (int i = 0; i < list.Count; i++)
|
{
|
var item = list[i];
|
if (item.storeConfig == null)
|
continue;
|
res.Add(new HeroDebutGiftItem
|
{
|
type = 0,
|
id = item.storeConfig.ID,
|
});
|
}
|
}
|
|
if (config.GiftCTGIDList != null)
|
{
|
for (int i = 0; i < config.GiftCTGIDList.Length; i++)
|
{
|
var item = config.GiftCTGIDList[i];
|
res.Add(new HeroDebutGiftItem
|
{
|
type = 1,
|
id = item,
|
});
|
}
|
}
|
|
if (isSort)
|
{
|
res = res.OrderBy(item =>
|
{
|
bool isCanBuy = item.type == 0 ? IsNoSellOutShopID(item.id) : IsCanBuyToday(item.id);
|
return !isCanBuy;
|
})
|
.ThenBy(item => item.type)
|
.ThenBy(item => item.id)
|
.ToList();
|
}
|
|
return res;
|
}
|
|
public bool HasGiftCanHave()
|
{
|
var list = GetGiftItemList(false);
|
if (list.IsNullOrEmpty())
|
return false;
|
|
for (int i = 0; i < list.Count; i++)
|
{
|
var item = list[i];
|
if (item.type == 0)
|
{
|
bool isFree = IsFreeShop(item.id);
|
bool isCanBuy = IsNoSellOutShopID(item.id);
|
if (isFree && isCanBuy)
|
return true;
|
}
|
}
|
return false;
|
}
|
|
#endregion
|
#region 招募
|
public int ToInt(OperationDate date)
|
{
|
return date.year * 10000 + date.month * 100 + date.day;
|
}
|
private string GetCallSkipKey(int cfgID, OperationDate startDate, OperationDate endDate)
|
{
|
return string.Concat("HeroDebutManager_CallSkip_", cfgID, ToInt(startDate), ToInt(endDate), PlayerDatas.Instance.PlayerId);
|
}
|
|
public bool LoadCallSkipData(int cfgID, OperationDate startDate, OperationDate endDate)
|
{
|
return LocalSave.GetBool(GetCallSkipKey(cfgID, startDate, endDate));
|
}
|
|
public void SaveCallSkipData(int cfgID, OperationDate startDate, OperationDate endDate, bool value)
|
{
|
LocalSave.SetBool(GetCallSkipKey(cfgID, startDate, endDate), value);
|
}
|
|
//<活动编号,招募选择的武将ID索引>
|
public Dictionary<int, int> callHeroIndexDict = new();
|
|
/// <summary>
|
/// 当前招募选中的武将ID
|
/// </summary>
|
public int GetCurrentDisplayCallHeroId()
|
{
|
var act = GetOperationHeroAppearInfo();
|
if (act == null) return 0;
|
if (!callHeroIndexDict.TryGetValue(actNum, out int index)) return 0;
|
|
var config = ActHeroAppearConfig.Get(act.CfgID);
|
if (config == null || config.ActHeroIDList?.Length <= index) return 0;
|
|
return config.ActHeroIDList[index];
|
}
|
|
|
#endregion
|
|
#region 时装特卖
|
|
public event Action OnCurrentChooseSkinIDChangeEevent;
|
private int m_currentChooseSkinID = 0;
|
|
public int currentChooseSkinID
|
{
|
get
|
{
|
return m_currentChooseSkinID;
|
}
|
set
|
{
|
if (m_currentChooseSkinID == value) return;
|
m_currentChooseSkinID = value;
|
OnCurrentChooseSkinIDChangeEevent?.Invoke();
|
}
|
}
|
|
/// <summary>
|
/// 通过skinID获取对应的heroID
|
/// </summary>
|
public int GetHeroIDBySkinID(int skinID)
|
{
|
foreach (var heroConfig in HeroConfig.GetValues())
|
{
|
if (heroConfig.SkinIDList != null && heroConfig.SkinIDList.Contains(skinID))
|
{
|
return heroConfig.HeroID;
|
}
|
}
|
return 0;
|
}
|
|
/// <summary>
|
/// 获取skinID在HeroConfig.SkinIDList中的索引
|
/// </summary>
|
public int GetSkinIndexInHeroConfig(int heroID, int skinID)
|
{
|
var heroConfig = HeroConfig.Get(heroID);
|
if (heroConfig?.SkinIDList == null) return int.MaxValue;
|
|
for (int i = 0; i < heroConfig.SkinIDList.Length; i++)
|
{
|
if (heroConfig.SkinIDList[i] == skinID)
|
return i;
|
}
|
return int.MaxValue;
|
}
|
|
//<skinID,ctgID>
|
Dictionary<int, int> ctgDict = new();
|
public int GetCtgIDBySkinID(int skinID)
|
{
|
if (ctgDict.IsNullOrEmpty())
|
{
|
GetSkinIDToCtgIDDict();
|
}
|
|
int ctgID;
|
ctgDict.TryGetValue(skinID, out ctgID);
|
return ctgID;
|
}
|
|
Dictionary<int, int> GetSkinIDToCtgIDDict()
|
{
|
if (!ctgDict.IsNullOrEmpty())
|
{
|
return ctgDict;
|
}
|
|
foreach (var config in ActHeroAppearConfig.GetValues())
|
{
|
if (config == null || config.SkinCTGIDList == null) return null;
|
|
for (int i = 0; i < config.SkinCTGIDList.Length; i++)
|
{
|
var ctgID = config.SkinCTGIDList[i];
|
var ctgConfig = CTGConfig.Get(ctgID);
|
if (ctgConfig == null || ctgConfig.GainItemList == null) continue;
|
|
for (int j = 0; j < ctgConfig.GainItemList.Length; j++)
|
{
|
var itemID = ctgConfig.GainItemList[j][0];
|
var itemConfig = ItemConfig.Get(itemID);
|
|
if (itemConfig == null) continue;
|
if (!HeroSkinAttrConfig.TryGetSkinIDByItemID(itemID, out var skinID)) continue;
|
if (ctgDict.ContainsKey(skinID)) continue;
|
ctgDict[skinID] = ctgID;
|
}
|
}
|
}
|
|
return ctgDict;
|
}
|
|
public bool HasItemInSkinCTGIDList(int cfgID, int findItemID)
|
{
|
var config = ActHeroAppearConfig.Get(cfgID);
|
if (config == null || config.SkinCTGIDList == null) return false;
|
|
for (int i = 0; i < config.SkinCTGIDList.Length; i++)
|
{
|
var ctgID = config.SkinCTGIDList[i];
|
var ctgConfig = CTGConfig.Get(ctgID);
|
if (ctgConfig == null || ctgConfig.GainItemList == null) continue;
|
|
for (int j = 0; j < ctgConfig.GainItemList.Length; j++)
|
{
|
var itemID = ctgConfig.GainItemList[j][0];
|
if (itemID == findItemID) return true;
|
}
|
}
|
return false;
|
}
|
|
|
public List<int> GetSkinIDList(int cfgID, int heroID, int mainSkinID)
|
{
|
var config = ActHeroAppearConfig.Get(cfgID);
|
if (config == null || config.SkinCTGIDList == null) return null;
|
|
var res = new List<int>();
|
for (int i = 0; i < config.SkinCTGIDList.Length; i++)
|
{
|
var ctgID = config.SkinCTGIDList[i];
|
var ctgConfig = CTGConfig.Get(ctgID);
|
if (ctgConfig == null || ctgConfig.GainItemList == null) continue;
|
|
for (int j = 0; j < ctgConfig.GainItemList.Length; j++)
|
{
|
var itemID = ctgConfig.GainItemList[j][0];
|
var itemConfig = ItemConfig.Get(itemID);
|
|
if (itemConfig == null) continue;
|
if (!HeroSkinAttrConfig.TryGetSkinIDByItemID(itemID, out var skinID)) continue;
|
if (res.Contains(skinID)) continue;
|
|
res.Add(skinID);
|
}
|
}
|
// 自定义排序
|
res.Sort((a, b) =>
|
{
|
// 1. 判断是否是传入heroID的皮肤,优先排前面
|
int heroIDA = GetHeroIDBySkinID(a);
|
int heroIDB = GetHeroIDBySkinID(b);
|
|
bool isPriorityA = (heroIDA == heroID);
|
bool isPriorityB = (heroIDB == heroID);
|
|
if (isPriorityA != isPriorityB)
|
return isPriorityA ? -1 : 1;
|
|
// 2. 相同武将的多个皮肤连续挨在一起
|
if (heroIDA != heroIDB)
|
return heroIDA.CompareTo(heroIDB);
|
|
// 3. 如果heroid相同,和MainSkinID相同的排在最前面
|
if (a == mainSkinID) return -1;
|
if (b == mainSkinID) return 1;
|
|
// 4. 其他按SkinIDList索引排序
|
int indexA = GetSkinIndexInHeroConfig(heroIDA, a);
|
int indexB = GetSkinIndexInHeroConfig(heroIDB, b);
|
|
return indexA.CompareTo(indexB);
|
});
|
return res;
|
}
|
|
#endregion
|
|
#region 获奖记录
|
public static readonly int RecordType = 311;
|
|
public void SendViewGameRecPack(int treasureType)
|
{
|
CA008_tagCSViewGameRec pack = new CA008_tagCSViewGameRec();
|
pack.RecType = (ushort)RecordType;
|
pack.RecID = (uint)treasureType;
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
public bool isSendFirst = true;
|
|
List<HeroDebutGameRec> gameRecDict = new();
|
|
public List<HeroDebutGameRec> GetGameRecList()
|
{
|
return gameRecDict;
|
}
|
public List<HeroDebutGameRec> GetLastFourRecords()
|
{
|
if (gameRecDict == null || gameRecDict.Count == 0) return new List<HeroDebutGameRec>();
|
|
int count = gameRecDict.Count;
|
int takeCount = Math.Min(4, count);
|
return gameRecDict.GetRange(count - takeCount, takeCount);
|
}
|
|
public event Action OnUpdateGameRecInfo;
|
public void UpdateGameRecInfo(HA009_tagSCGameRecInfo vNetData)
|
{
|
|
var act = GetOperationHeroAppearInfo();
|
if (act == null) return;
|
|
var config = ActHeroAppearConfig.Get(act.CfgID);
|
if (config == null) return;
|
|
int treasureType = config.ActTreasureType;
|
if (vNetData.RecType != RecordType || treasureType != (int)vNetData.RecID) return;
|
|
if (vNetData.RecList.IsNullOrEmpty()) return;
|
|
if (isSendFirst)
|
{
|
gameRecDict.Clear();
|
}
|
|
foreach (var rec in vNetData.RecList)
|
{
|
try
|
{
|
var playerName = JsonMapper.ToObject(rec.UserData)["Name"].ToString();
|
var arenaGameRec = new HeroDebutGameRec
|
{
|
Time = (int)rec.Time,
|
ItemID = (int)rec.Value1,
|
ItemCount = rec.Value2,
|
PlayerID = (int)rec.Value3,
|
ServerID = (int)rec.Value4,
|
PlayerName = playerName,
|
};
|
gameRecDict.Add(arenaGameRec);
|
}
|
catch (Exception ex)
|
{
|
Debug.LogError($"JSON解析错误: {ex.Message}, UserData: {rec.UserData}");
|
continue;
|
}
|
}
|
|
if (isSendFirst)
|
{
|
isSendFirst = !isSendFirst;
|
gameRecDict.Sort((x, y) => x.Time.CompareTo(y.Time));
|
}
|
|
OnUpdateGameRecInfo?.Invoke();
|
|
}
|
|
#endregion
|
}
|
|
|
public class HeroDebutGiftItem
|
{
|
public int type;//0 商店id 1 充值id
|
public int id;
|
}
|
|
public enum HeroDebutRedPointType
|
{
|
CheckIn = 1,
|
StarUp = 2,
|
Shop = 3,
|
Gift = 4,
|
}
|
|
public class HeroDebutGameRec
|
{
|
public int Time;
|
public int ItemID;
|
public long ItemCount;
|
public int PlayerID;
|
public int ServerID;
|
public string PlayerName;
|
}
|