84 lines
2.2 KiB
C#
84 lines
2.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Framework;
|
|
using Gameplay.Level;
|
|
using Gameplay.Net;
|
|
using NLDPB;
|
|
using UnityEngine;
|
|
|
|
public partial class PVPManager
|
|
{
|
|
private PVPEnemyInfo _currEnemy;
|
|
|
|
private uint _fightKey;
|
|
|
|
public bool IsFighting { get; set; }
|
|
|
|
public bool IsWin { get; private set; }
|
|
|
|
private void InitFight()
|
|
{
|
|
EventManager.Instance.Register<uint>(EventManager.EventName.OnPVPFightStart, OnStartPVPFight);
|
|
EventManager.Instance.Register(EventManager.EventName.OnPVPFightFinish, OnFinishPVPFight);
|
|
}
|
|
|
|
private void ReleaseFight()
|
|
{
|
|
EventManager.Instance.Unregister<uint>(EventManager.EventName.OnPVPFightStart, OnStartPVPFight);
|
|
EventManager.Instance.Unregister(EventManager.EventName.OnPVPFightFinish, OnFinishPVPFight);
|
|
}
|
|
|
|
#region API
|
|
|
|
public void StartPVPFight(uint actorID)
|
|
{
|
|
if (IsFighting)
|
|
{
|
|
DebugUtil.LogError("cant enter PVP!current pvp fighting is not finish!");
|
|
return;
|
|
}
|
|
|
|
_currEnemy = _enemies.FirstOrDefault(enemy => enemy.actorID == actorID);
|
|
if (_currEnemy == null)
|
|
{
|
|
DebugUtil.LogError($"cant find enemy! actor ID:{actorID}");
|
|
return;
|
|
}
|
|
|
|
DebugUtil.Log($"enter PVP fight! enemy actor ID:{actorID}");
|
|
NetHelper.StartPVPFight(actorID);
|
|
}
|
|
|
|
public void FinishPVPFight(bool isWin)
|
|
{
|
|
if (!IsFighting)
|
|
{
|
|
DebugUtil.LogError("cant finish PVP!there is no pvp fighting now");
|
|
return;
|
|
}
|
|
|
|
IsWin = isWin;
|
|
DebugUtil.Log($"finish PVP fight!");
|
|
NetHelper.FinishPVPFight(isWin, _fightKey);
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void OnStartPVPFight(uint key)
|
|
{
|
|
if (_currEnemy == null)
|
|
return;
|
|
IsFighting = true;
|
|
_fightKey = key;
|
|
LevelManager.Instance.PvpSettleData = new PVPSettleData();
|
|
LevelManager.Instance.EnterLevelDirectly(_pvpLevelInfo.Cfg.Id, null, _currEnemy.pvpDefenderData);
|
|
}
|
|
|
|
private void OnFinishPVPFight()
|
|
{
|
|
IsFighting = false;
|
|
_currEnemy = null;
|
|
//LevelManager.Instance.ExitLevelDirectly();
|
|
}
|
|
} |