using System.Collections.Generic;
|
using UnityEngine;
|
using LitJson;
|
using System;
|
using System.Linq;
|
|
public class QunyingManager : GameSystemManager<QunyingManager>
|
{
|
public const int challengeMoneyType = 56; //挑战 问鼎令
|
public const int challengeShopID = 16;
|
public const int rankType = 10;
|
public const int crossRankType = 150;
|
public const int recType = 312; // 挑战记录类型
|
public const int DataMapID = 32000;
|
|
public event Action OnMatchListEvent;
|
public List<QunyingMatchInfo> matchInfoList = new List<QunyingMatchInfo>();
|
//用于用来拿战斗胜利失败的头像信息
|
public Dictionary<uint, QunyingMatchInfo> allFaceInfoDict = new Dictionary<uint, QunyingMatchInfo>();
|
public Dictionary<uint, List<QunyingGameRec>> gameRecDict = new Dictionary<uint, List<QunyingGameRec>>(); // <玩家ID,QunyingGameRec>
|
public uint atkPlayerId;
|
public int tagRank; //挑战目标的排名 结果显示用
|
public event Action OnUpdateGameRecInfo;
|
|
public bool openQYWinNeedRoll = true; //打开群英界面需要滚动的情况
|
|
public uint m_RefreshCnt; // 本周已刷新匹配次数
|
public uint m_LastRecoverTime; // 上次免费恢复挑战令时间戳,为0时可不用倒计时
|
public ushort m_RankHighest; // 历史最高名次,第1名为最高
|
public uint m_RankSuccAward; // 历史最高名次成就领奖记录,按奖励记录索引位运算记录是否已领取
|
|
public event Action OnUpdateQunyingInfoEvent;
|
|
|
public override void Init()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin += BeforePlayerDataInitializeEventOnRelogin;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefresh;
|
InitTable();
|
}
|
|
public override void Release()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEventOnRelogin -= BeforePlayerDataInitializeEventOnRelogin;
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefresh;
|
}
|
|
public int resetOpenDay; //重置天8,如第一周如果是周5开服的不会重置
|
public int[] robotModelIDs;
|
public int challengeMaxCnt;
|
public int restoreTicketMinute;
|
public int refreshMoneyType;
|
public int refreshMoneyValue;
|
public int refreshMaxCnt;
|
public Dictionary<int, int[][]> dayRankAwards = new Dictionary<int, int[][]>();
|
public Dictionary<int, int[][]> weekRankAwards = new Dictionary<int, int[][]>();
|
public Dictionary<int, int[][]> achievementAwards = new Dictionary<int, int[][]>();
|
public Dictionary<int, int> achievementIndexs = new Dictionary<int, int>();
|
|
void InitTable()
|
{
|
var config = FuncConfigConfig.Get("QunyingSet");
|
resetOpenDay = int.Parse(config.Numerical1);
|
robotModelIDs = JsonMapper.ToObject<int[]>(config.Numerical2);
|
|
config = FuncConfigConfig.Get("QunyingChallenge");
|
challengeMaxCnt = int.Parse(config.Numerical1);
|
restoreTicketMinute = int.Parse(config.Numerical2);
|
|
config = FuncConfigConfig.Get("QunyingMatch");
|
var moneyInfo = ConfigParse.GetMultipleStr<int>(config.Numerical2);
|
refreshMoneyType = moneyInfo[0];
|
refreshMoneyValue = moneyInfo[1];
|
refreshMaxCnt = int.Parse(config.Numerical3);
|
|
config = FuncConfigConfig.Get("QunyingAward");
|
dayRankAwards = ConfigParse.ParseIntArray2Dict(config.Numerical1);
|
weekRankAwards = ConfigParse.ParseIntArray2Dict(config.Numerical2);
|
achievementAwards = ConfigParse.ParseIntArray2Dict(config.Numerical3);
|
achievementIndexs = ConfigParse.ParseIntDict(config.Numerical4);
|
}
|
|
public void BeforePlayerDataInitializeEventOnRelogin()
|
{
|
matchInfoList.Clear();
|
}
|
|
private void PlayerDataRefresh(PlayerDataType type)
|
{
|
if (type == PlayerDataType.QunyingWDL)
|
{
|
UpdateRedPonit();
|
}
|
}
|
|
|
|
public void UpdateQunyingMatchInfo(HA924_tagSCQunyingMatchList vNetData)
|
{
|
if (vNetData == null || vNetData.MatchList.IsNullOrEmpty())
|
return;
|
|
matchInfoList.Clear();
|
|
foreach (var item in vNetData.MatchList)
|
{
|
var matchInfo = new QunyingMatchInfo
|
{
|
Rank = item.Rank,
|
PlayerID = item.PlayerID,
|
PlayerName = item.PlayerName,
|
LV = item.LV,
|
RealmLV = item.RealmLV,
|
FightPower = (ulong)item.FightPowerEx * 100000000 + (ulong)item.FightPower,
|
Face = item.Face,
|
FacePic = item.FacePic,
|
TitleID = item.TitleID,
|
ModelMark = item.ModelMark,
|
EquipShowSwitch = item.EquipShowSwitch,
|
ServerID = item.ServerID,
|
};
|
matchInfoList.Add(matchInfo);
|
allFaceInfoDict[item.PlayerID] = matchInfo;
|
}
|
matchInfoList.Sort((a, b) => a.Rank.CompareTo(b.Rank));
|
|
UpdateRedPonit();
|
OnMatchListEvent?.Invoke();
|
}
|
|
public void UpdateQunyingInfo(HA925_tagSCQunyingPlayerInfo vNetData)
|
{
|
m_RefreshCnt = vNetData.RefreshCnt;
|
m_LastRecoverTime = vNetData.LastRecoverTime;
|
m_RankHighest = vNetData.RankHighest;
|
m_RankSuccAward = vNetData.RankSuccAward;
|
|
UpdateRedPonit();
|
OnUpdateQunyingInfoEvent?.Invoke();
|
}
|
|
public void UpdateGameRecInfo(HA009_tagSCGameRecInfo vNetData)
|
{
|
if (vNetData == null || vNetData.RecType != recType)
|
return;
|
gameRecDict.Clear();
|
uint recID = vNetData.RecID;
|
if (!gameRecDict.ContainsKey(recID))
|
gameRecDict[recID] = new List<QunyingGameRec>();
|
foreach (var rec in vNetData.RecList)
|
{
|
try
|
{
|
var userData = JsonMapper.ToObject(rec.UserData);
|
string name = userData["Name"].ToString();
|
int curRank = int.Parse(userData["CurRank"].ToString());
|
int tagRank = int.Parse(userData["TagRank"].ToString());
|
|
var gameRec = new QunyingGameRec
|
{
|
Time = rec.Time,
|
Value1 = rec.Value1,
|
Value2 = rec.Value2,
|
Value3 = rec.Value3,
|
Value4 = rec.Value4,
|
Value5 = rec.Value5,
|
Value6 = rec.Value6,
|
Value7 = rec.Value7,
|
Value8 = rec.Value8,
|
Name = name,
|
CurRank = curRank,
|
TagRank = tagRank
|
};
|
|
gameRecDict[recID].Add(gameRec);
|
|
if (recID == PlayerDatas.Instance.baseData.PlayerID)
|
{
|
allFaceInfoDict[rec.Value3] = new QunyingMatchInfo
|
{
|
Rank = (ushort)tagRank,
|
PlayerID = rec.Value3,
|
PlayerName = name,
|
LV = (ushort)rec.Value8,
|
RealmLV = (ushort)rec.Value7,
|
Face = rec.Value5,
|
FacePic = rec.Value6,
|
ServerID = rec.Value1,
|
|
};
|
}
|
|
}
|
catch (Exception ex)
|
{
|
Debug.LogError($"JSON解析错误: {ex.Message}, UserData: {rec.UserData}");
|
continue;
|
}
|
}
|
OnUpdateGameRecInfo?.Invoke();
|
}
|
|
|
public bool TryGetPlayerInfo(uint playerID, out QunyingMatchInfo info)
|
{
|
return allFaceInfoDict.TryGetValue(playerID, out info);
|
}
|
|
// 获取匹配信息中我的部分
|
public QunyingMatchInfo GetMyMatchInfo(out int index)
|
{
|
index = 0;
|
for (int i = 0; i < matchInfoList.Count; i++)
|
{
|
if (matchInfoList[i].PlayerID == PlayerDatas.Instance.baseData.PlayerID)
|
{
|
index = i;
|
return matchInfoList[i];
|
}
|
}
|
return null;
|
}
|
|
//向服务器请求刷新挑战对象
|
// 0-打开界面时查询,1-强制刷新匹配列表
|
public void RequestRefreshFighters(int refreshType)
|
{
|
var pack = new CB210_tagCSQunyingMatch();
|
pack.IsRefresh = (byte)refreshType;
|
GameNetSystem.Instance.SendInfo(pack);
|
|
}
|
public List<Item> itemInfos = new List<Item>();
|
public int quickCnt;
|
public int tagPlayerID;
|
public void UpdateFBEnd(H0320_tagFBEnd vNetData)
|
{
|
if (vNetData.Msg == null)
|
return;
|
JsonData jsonData = JsonMapper.ToObject(vNetData.Msg);
|
int dataMapID = int.Parse(jsonData["dataMapID"].ToString());
|
if (dataMapID != DataMapID)
|
return;
|
quickCnt = int.Parse(jsonData["quickCnt"].ToString());
|
tagPlayerID = int.Parse(jsonData["tagID"].ToString());
|
|
itemInfos.Clear();
|
if (jsonData["itemInfo"] != null && jsonData["itemInfo"].IsArray)
|
{
|
for (int i = 0; i < jsonData["itemInfo"].Count; i++)
|
{
|
JsonData itemData = jsonData["itemInfo"][i];
|
Item itemInfo = new Item((int)itemData["ItemID"], (long)itemData["Count"]);
|
itemInfos.Add(itemInfo);
|
}
|
}
|
UIManager.Instance.OpenWindow<QYBattleVictoryWin>();
|
}
|
|
//是否本周开启,周几开启
|
public bool TryGetOpenWeek(out bool isThisWeek, out int weekDay)
|
{
|
weekDay = 0;
|
var openServerDay = TimeUtility.OpenDay + 1; //今天是第几个开服天
|
var openFuncDay = FuncOpenLVConfig.Get((int)FuncOpenEnum.Qunying).OpenDay; //功能开启在第几个开服天开放
|
|
//判断功能是否已开启
|
if (openServerDay < openFuncDay - 1)
|
{
|
isThisWeek = false;
|
return true;
|
}
|
|
//计算本周自然周开始是开服天范围
|
//今天周几
|
int theWeekDay = (int)TimeUtility.ServerNow.DayOfWeek == 0 ? 7 : (int)TimeUtility.ServerNow.DayOfWeek;
|
int currentWeekStart = openServerDay - theWeekDay + 1;
|
int currentWeekEnd = currentWeekStart + 6;
|
|
//判断功能开启天是否在当前周内
|
isThisWeek = openFuncDay >= currentWeekStart && openFuncDay <= currentWeekEnd;
|
|
|
if (isThisWeek)
|
{
|
weekDay = openFuncDay - currentWeekStart + 1;
|
}
|
|
return true;
|
}
|
|
public string GetEndSecondStr()
|
{
|
TryGetOpenWeek(out bool isThisWeek, out int openWeekDay);
|
if (isThisWeek && resetOpenDay - FuncOpenLVConfig.Get((int)FuncOpenEnum.Qunying).OpenDay - 1 > 7 - openWeekDay)
|
{
|
//本周开启时间不足 则和下周的合并
|
return TimeUtility.SecondsToDHMS(TimeUtility.GetCommonWeekEndTime() + 7 * 24 * 60 * 60);
|
}
|
else
|
{
|
return TimeUtility.SecondsToDHMS(TimeUtility.GetCommonWeekEndTime());
|
}
|
}
|
|
|
//获取下一个成就的排名奖励
|
//0 没有下一个 最高
|
public int GetNextAchievementRank()
|
{
|
var keys = achievementAwards.Keys.ToList();
|
if (m_RankHighest == 0)
|
return keys[keys.Count - 1];
|
keys.Sort();
|
for (int i = 0; i < keys.Count; i++)
|
{
|
if (m_RankHighest <= keys[i])
|
{
|
if (i == 0)
|
{
|
return 0;
|
}
|
return keys[i - 1];
|
}
|
}
|
return keys[keys.Count - 1];
|
}
|
|
//0 未达成 1 达成 2 已领取
|
public int GetAchievementState(int rank)
|
{
|
if (m_RankHighest == 0)
|
return 0;
|
if (m_RankHighest > rank)
|
return 0;
|
|
var awardIndex = achievementIndexs[rank];
|
bool isGot = (m_RankSuccAward & (1 << awardIndex)) != 0;
|
return isGot ? 2 : 1;
|
}
|
|
public Dictionary<int, int[][]> GetRankAwardDict(int functionOrder)
|
{
|
return functionOrder == 0 ? weekRankAwards : dayRankAwards;
|
}
|
|
public int[][] GetMyRankAwards(int functionOrder, int rank)
|
{
|
if (rank == 0)
|
{
|
return null;
|
}
|
var awardDict = GetRankAwardDict(functionOrder);
|
var keys = awardDict.Keys.ToList();
|
keys.Sort();
|
for (int i = 0; i < keys.Count; i++)
|
{
|
if (rank <= keys[i])
|
{
|
return awardDict[keys[i]];
|
}
|
}
|
return null;
|
}
|
|
/// <summary>
|
/// 根据recID获取按时间从大到小排序的List<QunyingGameRec>
|
/// </summary>
|
/// <param name="recID">记录ID</param>
|
/// <param name="sortedList">输出参数:按时间从大到小排序的QunyingGameRec列表</param>
|
/// <returns>如果recID存在且成功获取列表返回true,否则返回false</returns>
|
public bool TryGetSortedGameRecList(uint recID, out List<QunyingGameRec> sortedList)
|
{
|
sortedList = null;
|
if (!gameRecDict.ContainsKey(recID))
|
return false;
|
sortedList = new List<QunyingGameRec>(gameRecDict[recID]);
|
sortedList.Sort((a, b) => b.Time.CompareTo(a.Time)); // 按时间从大到小排序
|
return true;
|
}
|
|
#region 红点
|
|
public Redpoint parentRedpoint = new Redpoint(MainRedDot.Qunying);
|
Redpoint awardRedpoint = new Redpoint(MainRedDot.Qunying, MainRedDot.Qunying * 10 + 1);
|
Redpoint matchRedpoint = new Redpoint(MainRedDot.Qunying, MainRedDot.Qunying * 10 + 2);
|
public void UpdateRedPonit()
|
{
|
awardRedpoint.state = RedPointState.None;
|
matchRedpoint.state = RedPointState.None;
|
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Qunying))
|
{
|
return;
|
}
|
|
var keys = achievementAwards.Keys.ToList();
|
for (int i = 0; i < keys.Count; i++)
|
{
|
if (GetAchievementState(keys[i]) == 1)
|
{
|
awardRedpoint.state = RedPointState.Simple;
|
break;
|
}
|
}
|
|
if (UIHelper.GetMoneyCnt(challengeMoneyType) >= challengeMaxCnt)
|
{
|
matchRedpoint.state = RedPointState.Simple;
|
}
|
|
}
|
#endregion
|
|
public int GetRankType()
|
{
|
if (CrossServerBaseManager.Instance.IsOpenCrossServer(DataMapID))
|
{
|
return crossRankType;
|
}
|
return rankType;
|
}
|
|
|
}
|
|
public class QunyingMatchInfo
|
{
|
public ushort Rank; //排名,从1开始
|
public uint PlayerID; //目标玩家ID
|
public string PlayerName;
|
public ushort LV; // 玩家等级
|
public ushort RealmLV; //境界,机器人读境界表取等级对应境界
|
public ulong FightPower; //战力
|
public uint Face; //基本脸型
|
public uint FacePic; //头像框
|
public uint TitleID; //称号
|
public uint ModelMark; //变形模型mark
|
public uint EquipShowSwitch; //其他外观信息
|
public uint ServerID;
|
|
}
|
|
|
public class QunyingGameRec
|
{
|
public uint Time; //战斗时间戳
|
public uint Value1; //sid
|
public uint Value2; //攻击类型 1-发起攻击的,2-被攻击的
|
public uint Value3; //相对攻击类型的目标玩家ID
|
public uint Value4; //是否获胜 1-获胜;2-失败
|
public uint Value5; //目标头像
|
public uint Value6; //目标头像框
|
public uint Value7; //目标官职
|
public uint Value8; //目标等级
|
public string Name; //目标名称
|
public int CurRank;
|
public int TagRank;
|
|
}
|