NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Procedure/ProcedureBase.cs

184 lines
4.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using cfg.ProcedureCfg;
using Gameplay;
using Gameplay.Level;
/// <summary>
/// 强制流程基类
/// </summary>
public abstract class ProcedureBase
{
/// <summary>
/// 配置数据
/// </summary>
public DataProcedure Cfg
{
get;
private set;
}
public ProcedureBase(DataProcedure cfg)
{
Cfg = cfg;
}
/// <summary>
/// 是否可以开始
/// </summary>
/// <returns></returns>
public abstract bool IsCanStart();
/// <summary>
/// 是否正在流程中
/// </summary>
/// <returns></returns>
public abstract bool IsProceduring();
/// <summary>
/// 开始强制流程
/// </summary>
public abstract void Begin();
}
/// <summary>
/// 进入关卡
/// </summary>
public sealed class EnterLevel_Procedure : ProcedureBase
{
private readonly int levelId;
public EnterLevel_Procedure(DataProcedure cfg) : base(cfg)
{
if (cfg.ProcedureParams.Length < 1)
{
DebugUtil.LogError($"强制流程id:{cfg.Id}参数数量错误需要1个参数关卡id");
return;
}
if (!int.TryParse(cfg.ProcedureParams[0], out int id))
{
DebugUtil.LogError($"强制流程id:{cfg.Id}参数类型错误需要1个参数关卡id");
return;
}
levelId = id;
}
public override void Begin()
{
LevelManager.Instance.TryEnterLevel(levelId, null, null, true);
}
public override bool IsCanStart()
{
if (!LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo))
return false;
return !levelInfo.IsPass;
}
public override bool IsProceduring()
{
if (!LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo))
return false;
return !levelInfo.IsPass; // 没有通关,则在该流程中
}
}
/// <summary>
/// 进入队伍信息界面
/// </summary>
public sealed class EnterTeamInfoUI_Procedure : ProcedureBase
{
private readonly int levelId;
public EnterTeamInfoUI_Procedure(DataProcedure cfg) : base(cfg)
{
if (cfg.ProcedureParams.Length < 1)
{
DebugUtil.LogError($"强制流程id:{cfg.Id}参数数量错误需要1个参数关卡id");
return;
}
if (!int.TryParse(cfg.ProcedureParams[0], out int id))
{
DebugUtil.LogError($"强制流程id:{cfg.Id}参数类型错误需要1个参数关卡id");
return;
}
levelId = id;
}
public override void Begin()
{
GameStateManager.Instance.ChangeState(new GameStateMainScene(false, false, async () =>
{
await JumpToManager.JumpFuncAsync(cfg.JumpFuncType.TeamInfoByGuide, levelId);
}));
}
public override bool IsCanStart()
{
if (!LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo))
return false;
return !levelInfo.IsPass;
}
public override bool IsProceduring()
{
if (!LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo))
return false;
return !levelInfo.IsPass; // 没有通关,则在该流程中
}
}
/// <summary>
/// 进入编队信息界面
/// </summary>
public sealed class EnterEditTeamUI_Procedure : ProcedureBase
{
private readonly int levelId;
public EnterEditTeamUI_Procedure(DataProcedure cfg) : base(cfg)
{
if (cfg.ProcedureParams.Length < 1)
{
DebugUtil.LogError($"强制流程id:{cfg.Id}参数数量错误需要1个参数关卡id");
return;
}
if (!int.TryParse(cfg.ProcedureParams[0], out int id))
{
DebugUtil.LogError($"强制流程id:{cfg.Id}参数类型错误需要1个参数关卡id");
return;
}
levelId = id;
}
public override void Begin()
{
GameStateManager.Instance.ChangeState(new GameStateMainScene(false, false, async () =>
{
await JumpToManager.JumpFuncAsync(cfg.JumpFuncType.TeamSelect, levelId);
}));
}
public override bool IsCanStart()
{
if (!LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo))
return false;
return !levelInfo.IsPass;
}
public override bool IsProceduring()
{
if (!LevelManager.Instance.TryGetLevelInfoByID(levelId, out LevelInfo levelInfo))
return false;
return !levelInfo.IsPass; // 没有通关,则在该流程中
}
}