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

99 lines
2.6 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-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; }
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;
MSG_PvpDefenceData defenceData = MSG_PvpDefenceData.Parser.ParseFrom(pvpActor.DefenceData);
pvpDefenderData = new PVPDefenderData(defenceData);
}
}
2023-12-29 15:07:04 +08:00
public partial class PVPManager : Singlenton<PVPManager>, IInitable
{
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; }
//当前备选敌人
public IEnumerable<PVPEnemyInfo> Enemies => _enemies;
2023-12-29 15:07:04 +08:00
public void Init()
{
2024-01-03 14:56:46 +08:00
EventManager.Instance.Register<G_Clt_PvpInformation>(EventManager.EventName.OnGetPVPInformation,
OnGetPVPInformation);
2023-12-29 15:07:04 +08:00
EventManager.Instance.Register(EventManager.EventName.AllConfigLoad, OnAllConfigLoad);
2024-01-03 14:56:46 +08:00
InitFight();
2023-12-29 15:07:04 +08:00
}
public void Release()
{
2024-01-03 14:56:46 +08:00
EventManager.Instance.Register<G_Clt_PvpInformation>(EventManager.EventName.OnGetPVPInformation,
OnGetPVPInformation);
2023-12-29 15:07:04 +08:00
EventManager.Instance.Unregister(EventManager.EventName.AllConfigLoad, OnAllConfigLoad);
2024-01-03 14:56:46 +08:00
ReleaseFight();
2023-12-29 15:07:04 +08:00
}
private void OnAllConfigLoad()
{
var pvpLevelID = TableManager.Instance.Tables.GlobalConfig.PVPLevelID;
_pvpLevelInfo = LevelManager.Instance.GetLevelInfoByID(pvpLevelID);
if (_pvpLevelInfo == null)
{
DebugUtil.LogError($"找不到关卡配置,id:{pvpLevelID}");
return;
}
}
#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
}
#endregion
2024-01-03 14:56:46 +08:00
private void OnGetPVPInformation(G_Clt_PvpInformation information)
{
score = (int)information.Score;
order = (int)information.Order;
_enemies.Clear();
foreach (var actor in information.Rivals)
{
PVPEnemyInfo enemyInfo = new(actor);
_enemies.Add(enemyInfo);
}
}
2023-12-29 15:07:04 +08:00
}