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-07-24 17:33:23 +08:00
|
|
|
|
using Gameplay.Guide;
|
2024-08-14 15:00:35 +08:00
|
|
|
|
using NLDPB;
|
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;
|
2024-06-27 13:22:21 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 剧情加载完成后是否立即播放
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private bool isPlay;
|
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;
|
2024-05-31 14:06:02 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 退出关卡是否切换主场景回调
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Func<bool> ExitLevelChangeMainFunc;
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2024-04-11 19:02:11 +08:00
|
|
|
|
private int _bgmID;
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-29 12:05:14 +08:00
|
|
|
|
private async void OnServerResponseExitLevel(ItemList itemList)
|
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
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("当前未处于关卡中");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
|
|
|
|
|
if (CurrLevel.IsStory)
|
2024-01-03 16:40:57 +08:00
|
|
|
|
{
|
2024-08-14 15:00:35 +08:00
|
|
|
|
var filterItemList = CommonUtils.GetLevelRewardFilterItemList(itemList);
|
|
|
|
|
|
var listItem = new ListItem(filterItemList);
|
2024-07-31 16:52:31 +08:00
|
|
|
|
CommonUtils.FilterListItem(listItem);
|
2024-07-25 19:27:59 +08:00
|
|
|
|
if (listItem.Length > 0)
|
|
|
|
|
|
{
|
2024-07-31 17:10:02 +08:00
|
|
|
|
_EnterStorySettle(listItem);
|
2024-07-25 19:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ExitLevelDirectly(_exitLevelFinishCallBack);
|
|
|
|
|
|
_exitLevelFinishCallBack = null;
|
|
|
|
|
|
}
|
2024-08-14 15:00:35 +08:00
|
|
|
|
|
2024-01-03 16:40:57 +08:00
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-04-11 19:02:11 +08:00
|
|
|
|
StopBGM();
|
2023-11-22 15:05:43 +08:00
|
|
|
|
if (IsSuccess)
|
|
|
|
|
|
{
|
2024-03-29 12:05:14 +08:00
|
|
|
|
// CommonUtils.CaptureScreenshot();
|
2024-04-08 18:58:23 +08:00
|
|
|
|
// UIManager.Instance.OpenWindow(UINameConst.UIMissionWin, itemList).Forget();
|
|
|
|
|
|
await ShowTransitionMgr.Instance.ShowLevelTransition(UI_LevelTransitionController.OpenType.Success);
|
2024-03-29 12:05:14 +08:00
|
|
|
|
await SettleSceneProcess(itemList);
|
2023-11-22 15:05:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2024-04-08 18:58:23 +08:00
|
|
|
|
await ShowTransitionMgr.Instance.ShowLevelTransition(UI_LevelTransitionController.OpenType.Fail);
|
2023-11-22 15:05:43 +08:00
|
|
|
|
if (!UIManager.Instance.IsWindowOpening(UINameConst.UIDefeatGame))
|
|
|
|
|
|
{
|
2024-04-03 12:52:49 +08:00
|
|
|
|
UIDefeatGameController.Open().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-06-27 13:22:21 +08:00
|
|
|
|
GameStateManager.Instance.ChangeState(new GameStateStory(levelInfo.StoryID + "", isPlay));
|
2024-01-03 16:40:57 +08:00
|
|
|
|
else
|
|
|
|
|
|
GameStateManager.Instance.ChangeState(new GameStateLevel(levelID));
|
|
|
|
|
|
CurrLevel = levelInfo;
|
|
|
|
|
|
IsInLevel = true;
|
|
|
|
|
|
_enterLevelFinishCallBack?.Invoke();
|
|
|
|
|
|
_enterLevelFinishCallBack = null;
|
2024-07-08 15:28:18 +08:00
|
|
|
|
if (!levelInfo.IsStory)
|
|
|
|
|
|
PlayBGM();
|
2024-01-03 16:40:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void _ExitLevelDirectly()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!CurrLevel.IsStory)
|
|
|
|
|
|
TeamManager.Instance.Release();
|
2024-05-31 14:06:02 +08:00
|
|
|
|
|
2024-06-24 13:55:42 +08:00
|
|
|
|
var levelID = CurrLevel.ID;
|
2024-06-28 18:45:54 +08:00
|
|
|
|
var isPVP = false;
|
|
|
|
|
|
if (CurrentLevel != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
isPVP = CurrentLevel.IsPvPLevel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-03 16:40:57 +08:00
|
|
|
|
CurrLevel = null;
|
|
|
|
|
|
IsInLevel = false;
|
2024-05-31 14:06:02 +08:00
|
|
|
|
|
|
|
|
|
|
if (null != ExitLevelChangeMainFunc && !ExitLevelChangeMainFunc.Invoke())
|
|
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.GuideExitLevel);
|
|
|
|
|
|
else
|
2024-06-28 15:53:24 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (isPVP)
|
|
|
|
|
|
GameStateManager.Instance.ChangeState(new GameStateMainScene());
|
|
|
|
|
|
// GameStateManager.Instance.ChangeState(new GameStateMainScene(
|
|
|
|
|
|
// () => { JumpToManager.JumpFunc(cfg.JumpFuncType.PVP_Main); }));
|
|
|
|
|
|
else
|
2024-07-12 15:21:16 +08:00
|
|
|
|
GameStateManager.Instance.ChangeState(new GameStateMainScene(false,
|
2024-06-24 13:55:42 +08:00
|
|
|
|
() => { JumpToManager.JumpFunc(cfg.JumpFuncType.Level_Select, levelID); }));
|
2024-06-28 15:53:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-31 14:06:02 +08:00
|
|
|
|
|
|
|
|
|
|
ExitLevelChangeMainFunc = null;
|
2024-01-03 16:40:57 +08:00
|
|
|
|
_exitLevelFinishCallBack?.Invoke();
|
|
|
|
|
|
_exitLevelFinishCallBack = null;
|
2024-01-17 12:57:07 +08:00
|
|
|
|
_cacheSettleData = null;
|
2024-01-03 16:40:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-31 17:10:02 +08:00
|
|
|
|
private async void _EnterStorySettle(ListItem listItem)
|
|
|
|
|
|
{
|
2024-08-14 15:00:35 +08:00
|
|
|
|
await CommonUtils.CaptureScreenshot();
|
2024-08-06 14:12:49 +08:00
|
|
|
|
await ShowTransitionMgr.Instance.EnterBlackTransition(true);
|
2024-07-31 17:10:02 +08:00
|
|
|
|
await ShowTransitionMgr.Instance.EnterBlack();
|
2024-08-14 15:00:35 +08:00
|
|
|
|
await UniTask.Delay(150);
|
2024-07-31 17:10:02 +08:00
|
|
|
|
await UI_GetItemWindowController.Open(listItem, UI_GetItemWindowController.EShowType.StorySettle);
|
2024-08-14 15:00:35 +08:00
|
|
|
|
await UniTask.Delay(250);
|
2024-07-31 17:10:02 +08:00
|
|
|
|
await ShowTransitionMgr.Instance.ExitBlack();
|
|
|
|
|
|
ShowTransitionMgr.Instance.ExitTransition();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#region API
|
2023-11-22 15:05:43 +08:00
|
|
|
|
|
2024-06-27 13:22:21 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 向服务器发送消息准备进入关卡
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
|
/// <param name="finishCallback"></param>
|
|
|
|
|
|
/// <param name="param"></param>
|
|
|
|
|
|
/// <param name="isPlay">剧情加载完成后是否立即播放</param>
|
|
|
|
|
|
public void TryEnterLevel(int id, Action finishCallback = null, object param = null, bool isPlay = true)
|
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-08-14 16:05:29 +08:00
|
|
|
|
//清掉上次的奖励
|
|
|
|
|
|
Actor.Instance.RewardItems.Clear();
|
|
|
|
|
|
|
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;
|
2024-06-27 13:22:21 +08:00
|
|
|
|
this.isPlay = isPlay;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//向服务器发送消息退出关卡
|
|
|
|
|
|
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);
|
2024-07-08 15:28:18 +08:00
|
|
|
|
var levelInfo = GetLevelInfoByID(levelID);
|
|
|
|
|
|
if (!levelInfo.IsStory)
|
|
|
|
|
|
PlayBGM();
|
2024-01-03 16:40:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//直接退出关卡,不走服务器
|
|
|
|
|
|
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-08-13 16:04:49 +08:00
|
|
|
|
if (dicLevelGroupInfo.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
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-24 17:33:23 +08:00
|
|
|
|
public void PlayBGM()
|
2024-04-11 19:02:11 +08:00
|
|
|
|
{
|
2024-07-22 19:35:34 +08:00
|
|
|
|
//_bgmID = await AudioManager.Instance.PlayAudio("NLD_BGM_01");
|
2024-07-25 17:43:14 +08:00
|
|
|
|
_bgmID = AudioManager.Instance.PlayAudio("bgm_1", AudioCriManager.EPlayType.Music);
|
2024-04-11 19:02:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void StopBGM()
|
|
|
|
|
|
{
|
|
|
|
|
|
AudioManager.Instance.AudioMgrObj.StopMusicById(_bgmID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-05 16:06:48 +08:00
|
|
|
|
public async UniTask OnPVPSettle()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CurrentLevel.IsPvPLevel)
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowTransitionMgr.Instance.ExitTransition();
|
|
|
|
|
|
await ShowTransitionMgr.Instance.EnterBlack();
|
|
|
|
|
|
await UniTask.Delay(250);
|
|
|
|
|
|
await UI_PVPSettlementController.Open(PVPManager.Instance.IsWin);
|
|
|
|
|
|
await ShowTransitionMgr.Instance.ExitBlack();
|
|
|
|
|
|
ShowTransitionMgr.Instance.ExitTransition();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
#endregion API
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|