2023-10-19 15:00:19 +08:00
|
|
|
|
using Framework;
|
|
|
|
|
|
using Gameplay.Net;
|
|
|
|
|
|
using System;
|
2024-01-30 15:10:12 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-11-22 15:05:43 +08:00
|
|
|
|
using Code.Scripts.Gameplay.Game;
|
2024-03-22 12:09:11 +08:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
2024-01-19 19:20:05 +08:00
|
|
|
|
using UnityEngine;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using Debug = DebugUtil;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Gameplay.Level
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class LevelManager
|
|
|
|
|
|
{
|
|
|
|
|
|
//todo 修改服务器回消息底层逻辑后处理进入关卡失败的逻辑
|
|
|
|
|
|
|
|
|
|
|
|
const int NO_LEVEL_FLAG = -1;
|
|
|
|
|
|
|
|
|
|
|
|
private int _levelIDTryToEnter = NO_LEVEL_FLAG;
|
2023-12-26 18:19:05 +08:00
|
|
|
|
private object _levelParam;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
private Action _enterLevelFinishCallBack;
|
|
|
|
|
|
private Action _exitLevelFinishCallBack;
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
|
|
|
|
|
public bool IsInLevel { get; private set; }
|
2023-10-19 15:00:19 +08:00
|
|
|
|
public bool IsSuccess { get; private set; }
|
2023-11-22 15:05:43 +08:00
|
|
|
|
public LevelInfo CurrLevel { get; private set; }
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
private void InitAction()
|
|
|
|
|
|
{
|
2023-11-22 15:05:43 +08:00
|
|
|
|
IsInLevel = false;
|
|
|
|
|
|
CurrLevel = null;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
RegisterEventAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ReleaseAction()
|
|
|
|
|
|
{
|
|
|
|
|
|
UnregisterEventAction();
|
|
|
|
|
|
_enterLevelFinishCallBack = null;
|
|
|
|
|
|
_exitLevelFinishCallBack = null;
|
2023-12-26 18:19:05 +08:00
|
|
|
|
_levelParam = null;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void RegisterEventAction()
|
|
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.ServerResponseEnterLevel, OnServerResponseEnterLevel);
|
2023-11-22 15:05:43 +08:00
|
|
|
|
EventManager.Instance.Register<ItemList>(EventManager.EventName.ServerResponseExitLevel,
|
|
|
|
|
|
OnServerResponseExitLevel);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void UnregisterEventAction()
|
|
|
|
|
|
{
|
2023-11-22 15:05:43 +08:00
|
|
|
|
EventManager.Instance.Unregister(EventManager.EventName.ServerResponseEnterLevel,
|
|
|
|
|
|
OnServerResponseEnterLevel);
|
|
|
|
|
|
EventManager.Instance.Unregister<ItemList>(EventManager.EventName.ServerResponseExitLevel,
|
|
|
|
|
|
OnServerResponseExitLevel);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//服务器回消息,进入关卡
|
|
|
|
|
|
private void OnServerResponseEnterLevel()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_levelIDTryToEnter != NO_LEVEL_FLAG)
|
|
|
|
|
|
{
|
2024-01-03 16:40:57 +08:00
|
|
|
|
_EnterLevelDirectly(_levelIDTryToEnter);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
Debug.LogError($"levelID 不合法,无法进入关卡,levelID:{_levelIDTryToEnter}");
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
_levelIDTryToEnter = NO_LEVEL_FLAG;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnServerResponseExitLevel(ItemList itemList)
|
|
|
|
|
|
{
|
2023-11-22 15:05:43 +08:00
|
|
|
|
if (!IsInLevel)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("当前未处于关卡中");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
|
|
|
|
|
if (CurrLevel.IsStory)
|
2024-01-03 16:40:57 +08:00
|
|
|
|
{
|
|
|
|
|
|
ExitLevelDirectly(_exitLevelFinishCallBack);
|
|
|
|
|
|
_exitLevelFinishCallBack = null;
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2023-11-22 15:05:43 +08:00
|
|
|
|
if (IsSuccess)
|
|
|
|
|
|
{
|
2024-03-21 16:08:31 +08:00
|
|
|
|
CommonUtils.CaptureScreenshot();
|
2024-03-22 12:09:11 +08:00
|
|
|
|
UIManager.Instance.OpenWindow(UINameConst.UIMissionWin, itemList).Forget();
|
2023-11-22 15:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2023-11-22 15:05:43 +08:00
|
|
|
|
if (!UIManager.Instance.IsWindowOpening(UINameConst.UIDefeatGame))
|
|
|
|
|
|
{
|
2024-03-21 16:08:31 +08:00
|
|
|
|
CommonUtils.CaptureScreenshot();
|
2024-03-22 12:09:11 +08:00
|
|
|
|
UIManager.Instance.OpenWindow(UINameConst.UIDefeatGame).Forget();
|
2023-11-22 15:05:43 +08:00
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-19 19:20:05 +08:00
|
|
|
|
|
|
|
|
|
|
SaveFightLevel(CurrLevel);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-03 16:40:57 +08:00
|
|
|
|
private void _EnterLevelDirectly(int levelID)
|
|
|
|
|
|
{
|
|
|
|
|
|
var levelInfo = Instance.GetLevelInfoByID(levelID);
|
|
|
|
|
|
if (levelInfo == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"关卡不存在,id:{levelID}");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (levelInfo.IsStory)
|
2024-01-05 19:45:53 +08:00
|
|
|
|
GameStateManager.Instance.ChangeState(new GameStateStory(levelInfo.StoryID + ""));
|
2024-01-03 16:40:57 +08:00
|
|
|
|
else
|
|
|
|
|
|
GameStateManager.Instance.ChangeState(new GameStateLevel(levelID));
|
|
|
|
|
|
CurrLevel = levelInfo;
|
|
|
|
|
|
IsInLevel = true;
|
|
|
|
|
|
_enterLevelFinishCallBack?.Invoke();
|
|
|
|
|
|
_enterLevelFinishCallBack = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void _ExitLevelDirectly()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!CurrLevel.IsStory)
|
|
|
|
|
|
TeamManager.Instance.Release();
|
|
|
|
|
|
CurrLevel = null;
|
|
|
|
|
|
IsInLevel = false;
|
|
|
|
|
|
GameStateManager.Instance.ChangeState(new GameStateMainScene());
|
|
|
|
|
|
_exitLevelFinishCallBack?.Invoke();
|
|
|
|
|
|
_exitLevelFinishCallBack = null;
|
2024-01-17 12:57:07 +08:00
|
|
|
|
_cacheSettleData = null;
|
2024-01-03 16:40:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#region API
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
//向服务器发送消息准备进入关卡
|
2023-12-26 18:19:05 +08:00
|
|
|
|
public void TryEnterLevel(int id, Action finishCallback = null, object param = null)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2023-11-22 15:05:43 +08:00
|
|
|
|
if (IsInLevel)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2023-11-22 15:05:43 +08:00
|
|
|
|
Debug.LogError($"进入关卡失败!当前正处于关卡中!当前关卡ID:{CurrLevel.ID}");
|
2023-10-19 15:00:19 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
var levelInfo = GetLevelInfoByID(id);
|
|
|
|
|
|
if (levelInfo == null)
|
|
|
|
|
|
{
|
2024-01-03 16:40:57 +08:00
|
|
|
|
Debug.LogError($"关卡不存在,id:{id}");
|
2023-10-19 15:00:19 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
if (!levelInfo.CanEnter)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"关卡无法进入,id:{id}");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-01-19 19:20:05 +08:00
|
|
|
|
|
2024-01-15 13:53:01 +08:00
|
|
|
|
var team = TeamEditManager.Instance.GetSelectTeam();
|
|
|
|
|
|
_cacheSettleData = new LevelSettleData(id, team);
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
NetHelper.EnterLevel((uint)id, 0);
|
|
|
|
|
|
_enterLevelFinishCallBack = finishCallback;
|
2023-12-26 18:19:05 +08:00
|
|
|
|
_levelParam = param;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
_levelIDTryToEnter = id;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//向服务器发送消息退出关卡
|
|
|
|
|
|
public void TryExitLevel(bool isSuccess, Action finishCallback = null)
|
|
|
|
|
|
{
|
2023-11-22 15:05:43 +08:00
|
|
|
|
if (!IsInLevel)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("当前未处于关卡中");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-11-08 15:05:19 +08:00
|
|
|
|
|
2024-01-30 15:10:12 +08:00
|
|
|
|
var StarResult = CurrentLevel?.StarResult ?? new List<uint>();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
IsSuccess = isSuccess;
|
2024-01-30 15:10:12 +08:00
|
|
|
|
NetHelper.ExitLevel(isSuccess, StarResult);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
_exitLevelFinishCallBack = finishCallback;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-03 16:40:57 +08:00
|
|
|
|
//直接进入关卡,不通过服务器
|
|
|
|
|
|
public void EnterLevelDirectly(int levelID, Action enterLevelFinishCallBack = null, object param = null)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2024-01-03 16:40:57 +08:00
|
|
|
|
_enterLevelFinishCallBack = enterLevelFinishCallBack;
|
|
|
|
|
|
_levelParam = param;
|
|
|
|
|
|
_EnterLevelDirectly(levelID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//直接退出关卡,不走服务器
|
|
|
|
|
|
public void ExitLevelDirectly(Action exitLevelFinishCallBack = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_exitLevelFinishCallBack = exitLevelFinishCallBack;
|
|
|
|
|
|
_ExitLevelDirectly();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
2023-10-30 18:33:18 +08:00
|
|
|
|
|
2024-01-05 19:20:50 +08:00
|
|
|
|
public void GetStarReward(int levelGroupID, int index)
|
2023-10-30 18:33:18 +08:00
|
|
|
|
{
|
2024-01-05 19:20:50 +08:00
|
|
|
|
if (_levelGroupDic.TryGetValue(levelGroupID, out var chapterInfo))
|
2023-10-30 18:33:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (chapterInfo.CanGetReward(index))
|
|
|
|
|
|
{
|
2024-01-05 19:20:50 +08:00
|
|
|
|
DebugUtil.Log($"[Level] 发送领取章节奖励!章节ID{levelGroupID} index:{index}");
|
2024-01-08 19:14:33 +08:00
|
|
|
|
NetHelper.LevelGroupReward((uint)levelGroupID, (uint)index);
|
2023-10-30 18:33:18 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-05 19:20:50 +08:00
|
|
|
|
Debug.LogError($"无法领取章节奖励,chapter ID:{levelGroupID} index:{index}");
|
2023-10-30 18:33:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#endregion API
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|