NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/PVP/PVPManager.cs

222 lines
6.4 KiB
C#
Raw Normal View History

2023-12-29 15:07:04 +08:00
using System.Collections;
using System.Collections.Generic;
using Framework;
using Gameplay;
using Gameplay.Level;
2024-01-03 14:56:46 +08:00
using Gameplay.Net;
2023-12-29 15:07:04 +08:00
using Gameplay.SubSystems;
2024-06-13 16:40:53 +08:00
using Google.Protobuf.Collections;
2024-01-03 14:56:46 +08:00
using NLDPB;
2023-12-29 15:07:04 +08:00
using PhxhSDK;
using UnityEngine;
2024-01-03 14:56:46 +08:00
public class PVPEnemyInfo
{
public uint actorID { get; private set; }
public string nickName { get; private set; }
public int score { get; private set; }
public int order { get; private set; }
2024-05-31 15:57:22 +08:00
public int level { get; private set; }
2024-01-03 14:56:46 +08:00
public PVPDefenderData pvpDefenderData { get; private set; }
public PVPEnemyInfo(MSG_PvpActor pvpActor)
{
actorID = pvpActor.ActorId;
nickName = pvpActor.Nickname;
score = (int)pvpActor.Socre;
order = (int)pvpActor.Order;
2024-05-31 15:57:22 +08:00
level = (int)pvpActor.Level;
2024-01-03 14:56:46 +08:00
MSG_PvpDefenceData defenceData = MSG_PvpDefenceData.Parser.ParseFrom(pvpActor.DefenceData);
pvpDefenderData = new PVPDefenderData(defenceData);
DebugUtil.Log($"PVPEnemyInfo: ID:{actorID}, NickName:{nickName}, defenceData:{defenceData.ToString()}");
2024-01-03 14:56:46 +08:00
}
}
2024-06-13 16:40:53 +08:00
public class PvpRankInfo
{
private int _total;
private int _page;
private List<PvpRankItem> _rankDataList;
public int Total => _total;
public int Page => _page;
public List<PvpRankItem> RankDataList => _rankDataList;
public PvpRankInfo(uint total, uint page, RepeatedField<MSG_PvpOrderData> pvpOrderDatas)
{
_total = (int)total;
_page = (int)page;
_rankDataList = new List<PvpRankItem>();
foreach (var pvpOrderData in pvpOrderDatas)
{
if (pvpOrderData.ActorId > 0)
{
var pvpRankItem = new PvpRankItem()
{
Order = (int)pvpOrderData.Order,
ActorID = (int)pvpOrderData.ActorId,
NickName = pvpOrderData.Nickname,
2024-06-20 15:15:40 +08:00
Score = (int)pvpOrderData.Score,
2024-10-17 17:21:13 +08:00
Index = (int)pvpOrderData.Index,
Level = (int)pvpOrderData.Level
2024-06-13 16:40:53 +08:00
};
_rankDataList.Add(pvpRankItem);
}
}
}
2024-06-13 19:14:54 +08:00
//test
public PvpRankInfo(int page)
{
_total = 1000;//(int)total;
_page = page;
_rankDataList = new List<PvpRankItem>();
//test
2024-06-14 13:41:23 +08:00
for (int i = page * 200; i < (page + 1) * 200; i++)
2024-06-13 19:14:54 +08:00
{
var pvpRankItem = new PvpRankItem()
{
Order = i,
ActorID = i,
NickName = "order:" + i,
Score = i * 100
};
_rankDataList.Add(pvpRankItem);
}
return;
}
2024-06-13 16:40:53 +08:00
}
public struct PvpRankItem
{
public int Order;
public int ActorID;
public int Score;
2024-06-20 15:15:40 +08:00
public int Level;
2024-08-05 18:23:50 +08:00
public int Index; //排序唯一标识
2024-06-13 16:40:53 +08:00
public string NickName;
}
2024-06-21 13:35:07 +08:00
public partial class PVPManager : Singlenton<PVPManager>, IInitable, IUpdatable
2023-12-29 15:07:04 +08:00
{
private LevelInfo _pvpLevelInfo;
2024-01-03 14:56:46 +08:00
public LevelInfo PVPLevelInfo => _pvpLevelInfo;
private List<PVPEnemyInfo> _enemies = new();
//当前玩家的分数
public int score { get; private set; }
//当前玩家的排名
public int order { get; private set; }
2024-08-05 18:23:50 +08:00
public int index { get; private set; }
2024-01-03 14:56:46 +08:00
//当前备选敌人
2024-05-31 15:57:22 +08:00
public List<PVPEnemyInfo> Enemies => _enemies;
2024-01-03 14:56:46 +08:00
2024-06-13 16:40:53 +08:00
public PvpRankInfo PvpRankInfo;
2024-06-21 13:35:07 +08:00
public float RefreshDownTime;
2023-12-29 15:07:04 +08:00
public void Init()
{
2024-01-08 19:14:33 +08:00
EventManager.Instance.Register<G_Clt_PvpInformation>(EventManager.EventName.OnGetPVPInformationFromServer,
2024-01-03 14:56:46 +08:00
OnGetPVPInformation);
2023-12-29 15:07:04 +08:00
EventManager.Instance.Register(EventManager.EventName.AllConfigLoad, OnAllConfigLoad);
2024-01-09 19:30:53 +08:00
EventManager.Instance.Register<Mg_Clt_PvpOrderListData>(EventManager.EventName.OnGetPVPRankInfo, OnGetPVPRankInfo);
2024-01-03 14:56:46 +08:00
InitFight();
2023-12-29 15:07:04 +08:00
}
public void Release()
{
2024-01-09 19:30:53 +08:00
EventManager.Instance.Unregister<G_Clt_PvpInformation>(EventManager.EventName.OnGetPVPInformationFromServer,
2024-01-03 14:56:46 +08:00
OnGetPVPInformation);
2023-12-29 15:07:04 +08:00
EventManager.Instance.Unregister(EventManager.EventName.AllConfigLoad, OnAllConfigLoad);
2024-01-09 19:30:53 +08:00
EventManager.Instance.Unregister<Mg_Clt_PvpOrderListData>(EventManager.EventName.OnGetPVPRankInfo, OnGetPVPRankInfo);
2024-01-03 14:56:46 +08:00
ReleaseFight();
2024-06-17 14:33:34 +08:00
IsFighting = false;
2023-12-29 15:07:04 +08:00
}
private void OnAllConfigLoad()
{
2024-09-05 13:41:39 +08:00
int pvpLevelID = TableManager.Instance.Tables.GlobalConfig.PVPLevelID;
if (!LevelManager.Instance.TryGetLevelInfoByID(pvpLevelID, out _pvpLevelInfo))
2023-12-29 15:07:04 +08:00
DebugUtil.LogError($"找不到关卡配置,id:{pvpLevelID}");
}
2024-06-21 13:35:07 +08:00
public void Update(float dt)
{
if (RefreshDownTime >= 0)
{
RefreshDownTime -= dt;
}
}
2023-12-29 15:07:04 +08:00
#region API
2024-01-03 14:56:46 +08:00
public void GetPVPInformation()
2023-12-29 15:07:04 +08:00
{
2024-01-03 14:56:46 +08:00
NetHelper.GetPVPInformation();
2023-12-29 15:07:04 +08:00
}
2024-01-09 19:30:53 +08:00
public void GetPVPRankInfo(int page)
{
2024-06-13 19:14:54 +08:00
//test
//SetPVPRankInfo(page);
2024-01-09 19:30:53 +08:00
NetHelper.GetPvpOrderList((uint)page);
}
2023-12-29 15:07:04 +08:00
#endregion
2024-01-03 14:56:46 +08:00
private void OnGetPVPInformation(G_Clt_PvpInformation information)
{
//DebugUtil.Log($"PVPEnemyInfo:{information.ToString()}");
2024-01-03 14:56:46 +08:00
score = (int)information.Score;
order = (int)information.Order;
2024-08-05 18:23:50 +08:00
index = (int)information.Index;
2024-01-03 14:56:46 +08:00
_enemies.Clear();
foreach (var actor in information.Rivals)
{
//DebugUtil.LogError($"construct PVP Enemy, actor id:{actor.ActorId}");
2024-01-03 14:56:46 +08:00
PVPEnemyInfo enemyInfo = new(actor);
_enemies.Add(enemyInfo);
}
2024-06-14 15:46:18 +08:00
_enemies.Sort((a, b) => a.order < b.order ? 1 : -1);
2024-01-08 19:14:33 +08:00
EventManager.Instance.Send(EventManager.EventName.OnGetPVPInformation);
2024-01-03 14:56:46 +08:00
}
2024-01-09 19:30:53 +08:00
2024-06-13 16:40:53 +08:00
private async void OnGetPVPRankInfo(Mg_Clt_PvpOrderListData pb)
2024-01-09 19:30:53 +08:00
{
2024-06-13 16:40:53 +08:00
PvpRankInfo = new PvpRankInfo(pb.Total, pb.Page, pb.Datas);
2024-06-13 19:14:54 +08:00
if (!UIManager.Instance.CheckWindowCreated(UINameConst.UI_PVPRankInfo))
{
await UI_PVPRankInfoController.Open();
}
else
{
EventManager.Instance.Send(EventManager.EventName.OnPVPRankInfoUpdate);
}
}
//test
public async void SetPVPRankInfo(int page)
{
PvpRankInfo = new PvpRankInfo(page);
if (!UIManager.Instance.CheckWindowCreated(UINameConst.UI_PVPRankInfo))
2024-06-13 16:40:53 +08:00
{
await UI_PVPRankInfoController.Open();
}
else
{
EventManager.Instance.Send(EventManager.EventName.OnPVPRankInfoUpdate);
}
2024-01-09 19:30:53 +08:00
}
2023-12-29 15:07:04 +08:00
}