220 lines
6.2 KiB
C#
220 lines
6.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Framework;
|
|
using Gameplay;
|
|
using Gameplay.Level;
|
|
using Gameplay.Net;
|
|
using Gameplay.SubSystems;
|
|
using Google.Protobuf.Collections;
|
|
using NLDPB;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
|
|
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; }
|
|
|
|
public int level { get; private set; }
|
|
|
|
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;
|
|
level = (int)pvpActor.Level;
|
|
MSG_PvpDefenceData defenceData = MSG_PvpDefenceData.Parser.ParseFrom(pvpActor.DefenceData);
|
|
pvpDefenderData = new PVPDefenderData(defenceData);
|
|
}
|
|
}
|
|
|
|
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,
|
|
Score = (int)pvpOrderData.Score,
|
|
Index = (int)pvpOrderData.Index
|
|
//Level = (int)pvpOrderData.
|
|
};
|
|
_rankDataList.Add(pvpRankItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
//test
|
|
public PvpRankInfo(int page)
|
|
{
|
|
_total = 1000;//(int)total;
|
|
_page = page;
|
|
_rankDataList = new List<PvpRankItem>();
|
|
|
|
//test
|
|
for (int i = page * 200; i < (page + 1) * 200; i++)
|
|
{
|
|
var pvpRankItem = new PvpRankItem()
|
|
{
|
|
Order = i,
|
|
ActorID = i,
|
|
NickName = "order:" + i,
|
|
Score = i * 100
|
|
};
|
|
_rankDataList.Add(pvpRankItem);
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
public struct PvpRankItem
|
|
{
|
|
public int Order;
|
|
public int ActorID;
|
|
public int Score;
|
|
public int Level;
|
|
public int Index; //排序唯一标识
|
|
public string NickName;
|
|
}
|
|
|
|
public partial class PVPManager : Singlenton<PVPManager>, IInitable, IUpdatable
|
|
{
|
|
private LevelInfo _pvpLevelInfo;
|
|
|
|
public LevelInfo PVPLevelInfo => _pvpLevelInfo;
|
|
|
|
private List<PVPEnemyInfo> _enemies = new();
|
|
|
|
//当前玩家的分数
|
|
public int score { get; private set; }
|
|
|
|
//当前玩家的排名
|
|
public int order { get; private set; }
|
|
|
|
public int index { get; private set; }
|
|
|
|
//当前备选敌人
|
|
public List<PVPEnemyInfo> Enemies => _enemies;
|
|
|
|
public PvpRankInfo PvpRankInfo;
|
|
|
|
public float RefreshDownTime;
|
|
|
|
public void Init()
|
|
{
|
|
EventManager.Instance.Register<G_Clt_PvpInformation>(EventManager.EventName.OnGetPVPInformationFromServer,
|
|
OnGetPVPInformation);
|
|
EventManager.Instance.Register(EventManager.EventName.AllConfigLoad, OnAllConfigLoad);
|
|
EventManager.Instance.Register<Mg_Clt_PvpOrderListData>(EventManager.EventName.OnGetPVPRankInfo, OnGetPVPRankInfo);
|
|
InitFight();
|
|
}
|
|
|
|
public void Release()
|
|
{
|
|
EventManager.Instance.Unregister<G_Clt_PvpInformation>(EventManager.EventName.OnGetPVPInformationFromServer,
|
|
OnGetPVPInformation);
|
|
EventManager.Instance.Unregister(EventManager.EventName.AllConfigLoad, OnAllConfigLoad);
|
|
EventManager.Instance.Unregister<Mg_Clt_PvpOrderListData>(EventManager.EventName.OnGetPVPRankInfo, OnGetPVPRankInfo);
|
|
ReleaseFight();
|
|
IsFighting = false;
|
|
}
|
|
|
|
private void OnAllConfigLoad()
|
|
{
|
|
int pvpLevelID = TableManager.Instance.Tables.GlobalConfig.PVPLevelID;
|
|
if (!LevelManager.Instance.TryGetLevelInfoByID(pvpLevelID, out _pvpLevelInfo))
|
|
DebugUtil.LogError($"找不到关卡配置,id:{pvpLevelID}");
|
|
}
|
|
|
|
public void Update(float dt)
|
|
{
|
|
if (RefreshDownTime >= 0)
|
|
{
|
|
RefreshDownTime -= dt;
|
|
}
|
|
}
|
|
|
|
#region API
|
|
|
|
public void GetPVPInformation()
|
|
{
|
|
NetHelper.GetPVPInformation();
|
|
}
|
|
|
|
public void GetPVPRankInfo(int page)
|
|
{
|
|
//test
|
|
//SetPVPRankInfo(page);
|
|
NetHelper.GetPvpOrderList((uint)page);
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void OnGetPVPInformation(G_Clt_PvpInformation information)
|
|
{
|
|
score = (int)information.Score;
|
|
order = (int)information.Order;
|
|
index = (int)information.Index;
|
|
_enemies.Clear();
|
|
foreach (var actor in information.Rivals)
|
|
{
|
|
//DebugUtil.LogError($"construct PVP Enemy, actor id:{actor.ActorId}");
|
|
PVPEnemyInfo enemyInfo = new(actor);
|
|
_enemies.Add(enemyInfo);
|
|
}
|
|
_enemies.Sort((a, b) => a.order < b.order ? 1 : -1);
|
|
EventManager.Instance.Send(EventManager.EventName.OnGetPVPInformation);
|
|
}
|
|
|
|
private async void OnGetPVPRankInfo(Mg_Clt_PvpOrderListData pb)
|
|
{
|
|
PvpRankInfo = new PvpRankInfo(pb.Total, pb.Page, pb.Datas);
|
|
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))
|
|
{
|
|
await UI_PVPRankInfoController.Open();
|
|
}
|
|
else
|
|
{
|
|
EventManager.Instance.Send(EventManager.EventName.OnPVPRankInfoUpdate);
|
|
}
|
|
}
|
|
} |