203 lines
6.7 KiB
C#
203 lines
6.7 KiB
C#
using Framework;
|
|
using Gameplay.Net;
|
|
using Google.Protobuf.Collections;
|
|
using NLDPB;
|
|
using PhxhSDK;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Gameplay.LegionBattle
|
|
{
|
|
public sealed partial class LegionBattleManager : Singlenton<LegionBattleManager>, IUpdatable
|
|
{
|
|
/// <summary>
|
|
/// 是否军团战中
|
|
/// </summary>
|
|
public bool IsLegionBattle { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 是否进入军团战完成
|
|
/// </summary>
|
|
public bool IsLegionBattleOK { get; private set; }
|
|
|
|
private void InitAction()
|
|
{
|
|
IsLegionBattle = false;
|
|
IsLegionBattleOK = false;
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.EnterLegionBattle, OnServerEnterLegionBattle);
|
|
EventManager.Instance.Register(EventManager.EventName.EnterLegionBattleSuccess, OnServerEnterLegionBattleOK);
|
|
EventManager.Instance.Register(EventManager.EventName.ExitLegionBattle, OnServerExitLegionBattle);
|
|
}
|
|
|
|
private void ReleaseAction()
|
|
{
|
|
EventManager.Instance.Unregister(EventManager.EventName.ExitLegionBattle, OnServerExitLegionBattle);
|
|
EventManager.Instance.Unregister(EventManager.EventName.EnterLegionBattleSuccess, OnServerEnterLegionBattleOK);
|
|
EventManager.Instance.Unregister(EventManager.EventName.EnterLegionBattle, OnServerEnterLegionBattle);
|
|
}
|
|
|
|
#region 进入军团战
|
|
/// <summary>
|
|
/// 向服务器发送消息进入军团战
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="finishCallback"></param>
|
|
/// <param name="param"></param>
|
|
/// <param name="isPlay">剧情加载完成后是否立即播放</param>
|
|
public void TryEnterLegionBattleByServer()
|
|
{
|
|
WaitingForServer.Instance.EventWaiting(WaitingForServer.EventName.FightEnter, false);
|
|
|
|
if (IsLegionBattle)
|
|
{
|
|
DebugUtil.LogError($"进入军团战失败!当前正处于军团战中!");
|
|
WaitingForServer.Instance.EventDone(WaitingForServer.EventName.FightEnter);
|
|
return;
|
|
}
|
|
|
|
CurLegionBattle = new();
|
|
|
|
NetHelper.EnterLegionBattle(); // 进入军团战消息
|
|
}
|
|
|
|
/// <summary>
|
|
/// 向服务器发送消息退出军团战
|
|
/// </summary>
|
|
public void TryExitLegionBattleByServer()
|
|
{
|
|
WaitingForServer.Instance.EventWaiting(WaitingForServer.EventName.FightEnter, false);
|
|
|
|
if (!IsLegionBattleOK)
|
|
{
|
|
DebugUtil.LogError($"退出军团战失败!当前不处于军团战中!");
|
|
WaitingForServer.Instance.EventDone(WaitingForServer.EventName.FightEnter);
|
|
return;
|
|
}
|
|
|
|
NetHelper.ExitLegionBattle(); // 退出军团战消息
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入军团战(不经过服务器)
|
|
/// </summary>
|
|
public void EnterLegionBattle()
|
|
{
|
|
IsLegionBattle = true;
|
|
|
|
GameStateManager.Instance.ChangeState(new GameStateLegionBattle());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 退出军团战(经过服务器)
|
|
/// </summary>
|
|
public void ExitLegionBattle()
|
|
{
|
|
IsLegionBattleOK = false;
|
|
IsLegionBattle = false;
|
|
|
|
GameStateManager.Instance.ChangeState(new GameStateMainScene(false, true));
|
|
}
|
|
#endregion
|
|
|
|
#region 同步数据
|
|
/// <summary>
|
|
/// 同步初始化军团战军团数据
|
|
/// </summary>
|
|
public void InitLegionData(int mapId, uint startTime, int timeLength, MSG_LB_Legion legionAData, MSG_LB_Legion legionBData)
|
|
{
|
|
CurLegionBattle.InitLegionData(mapId, startTime, timeLength, legionAData, legionBData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 同步初始化军团战玩家数据
|
|
/// </summary>
|
|
public void InitActorData(MSG_LB_Actor actorData)
|
|
{
|
|
CurLegionBattle.InitActorUnit(actorData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 同步初始化军团战建筑数据
|
|
/// </summary>
|
|
public void InitBuildingData(MSG_LB_Building buildingData)
|
|
{
|
|
CurLegionBattle.InitBuildingInfo(buildingData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新军团战玩家信息
|
|
/// </summary>
|
|
/// <param name="index"></param>
|
|
/// <param name="actorData"></param>
|
|
public void UpdateActorData(MSG_LB_ActorUpdate actorData)
|
|
{
|
|
CurLegionBattle.UpdateActorData(actorData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过id更新军团战玩家信息
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <param name="command"></param>
|
|
/// <param name="x"></param>
|
|
/// <param name="z"></param>
|
|
/// <param name="pathX"></param>
|
|
/// <param name="pathZ"></param>
|
|
public void UpdateActorDataById(uint id, BattlefieldActorCommand command, int x, int z, RepeatedField<uint> pathX, RepeatedField<uint> pathZ)
|
|
{
|
|
CurLegionBattle.UpdateActorInfoById(id, command, x, z, pathX, pathZ);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过索引更新军团战建筑数据
|
|
/// </summary>
|
|
public void UpdateBuildingDataByIndex(int index, BattlefieldActorCamp camp, int defCount, int total)
|
|
{
|
|
CurLegionBattle.UpdateBuildingInfoByIndex(index, camp, defCount, total);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置军团战分数
|
|
/// </summary>
|
|
/// <param name="aScore"></param>
|
|
/// <param name="bScore"></param>
|
|
public void SetScore(int aScore, int bScore)
|
|
{
|
|
CurLegionBattle.SetScore(aScore, bScore);
|
|
|
|
if (IsLegionBattle)
|
|
EventManager.Instance.Send(EventManager.EventName.UpdateLegionBattleScore);
|
|
}
|
|
#endregion
|
|
|
|
#region 回调
|
|
/// <summary>
|
|
/// 服务器回调进入军团战
|
|
/// </summary>
|
|
private void OnServerEnterLegionBattle()
|
|
{
|
|
WaitingForServer.Instance.EventDone(WaitingForServer.EventName.FightEnter);
|
|
|
|
EnterLegionBattle();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 服务器回调进入军团战完成
|
|
/// </summary>
|
|
private void OnServerEnterLegionBattleOK()
|
|
{
|
|
IsLegionBattleOK = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 服务器退出军团战
|
|
/// </summary>
|
|
private void OnServerExitLegionBattle()
|
|
{
|
|
WaitingForServer.Instance.EventDone(WaitingForServer.EventName.FightEnter);
|
|
|
|
ExitLegionBattle();
|
|
}
|
|
#endregion
|
|
}
|
|
} |