迁移 Player/ProcedureGame/ShopUseCase 里的实体方法调用风格
- Player/ShopUseCase:调整了 Weapon 实体的打开方式 - ProcedureGame:调整初始化时的 Hud 和 Player 的初始化写法,流程更清楚
This commit is contained in:
@@ -10,12 +10,11 @@ namespace SepCore.Procedure
|
||||
{
|
||||
public abstract GameStateType GameStateType { get; }
|
||||
public abstract void OnInit(ProcedureGame master);
|
||||
public abstract void OnEnter(IFsm<IProcedureManager> procedureOwner);
|
||||
public abstract void OnEnter();
|
||||
|
||||
public abstract void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||
float realElapseSeconds);
|
||||
public abstract void OnUpdate(float elapseSeconds, float realElapseSeconds);
|
||||
|
||||
public abstract void OnLeave(IFsm<IProcedureManager> procedureOwner);
|
||||
public abstract void OnDestroy(IFsm<IProcedureManager> procedureOwner);
|
||||
public abstract void OnLeave();
|
||||
public abstract void OnDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace SepCore.Procedure
|
||||
_procedureGame = master;
|
||||
}
|
||||
|
||||
public override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
public override void OnEnter()
|
||||
{
|
||||
_currentLevel = _procedureGame.CurrentLevel;
|
||||
|
||||
@@ -55,8 +55,7 @@ namespace SepCore.Procedure
|
||||
if (Player != null) Player.Enable = true;
|
||||
}
|
||||
|
||||
public override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||
float realElapseSeconds)
|
||||
public override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
if (_levelTimeLeft < 0)
|
||||
{
|
||||
@@ -77,7 +76,7 @@ namespace SepCore.Procedure
|
||||
GameEntry.Event.Fire(this, LevelProcessEventArgs.Create((int)_levelTimeLeft));
|
||||
}
|
||||
|
||||
public override void OnLeave(IFsm<IProcedureManager> procedureOwner)
|
||||
public override void OnLeave()
|
||||
{
|
||||
// 隐藏所有敌人实体
|
||||
_enemyManager.OnReset();
|
||||
@@ -97,7 +96,7 @@ namespace SepCore.Procedure
|
||||
HideEntityGroup("EnemyProjectile");
|
||||
}
|
||||
|
||||
public override void OnDestroy(IFsm<IProcedureManager> procedureOwner)
|
||||
public override void OnDestroy()
|
||||
{
|
||||
_enemyManager = null;
|
||||
_procedureGame = null;
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace SepCore.Procedure
|
||||
public override GameStateType GameStateType => GameStateType.LevelUp;
|
||||
|
||||
private ProcedureGame _procedureGame;
|
||||
|
||||
|
||||
public bool IsCompleted { get; set; }
|
||||
|
||||
#region FSM
|
||||
@@ -22,22 +22,21 @@ namespace SepCore.Procedure
|
||||
Log.Debug("GameStateLevelUp::OnInit");
|
||||
|
||||
_procedureGame = master;
|
||||
|
||||
|
||||
var useCase = new LevelUpUseCase(_procedureGame.Player, () => IsCompleted = true);
|
||||
GameEntry.UIRouter.BindUIUseCase(UIFormType.LevelUpForm, useCase);
|
||||
}
|
||||
|
||||
public override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
public override void OnEnter()
|
||||
{
|
||||
Log.Debug("GameStateLevelUp::OnEnter");
|
||||
|
||||
IsCompleted = false;
|
||||
|
||||
|
||||
GameEntry.UIRouter.OpenUIAsync(UIFormType.LevelUpForm).Forget();
|
||||
}
|
||||
|
||||
public override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||
float realElapseSeconds)
|
||||
public override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
if (IsCompleted)
|
||||
{
|
||||
@@ -45,14 +44,14 @@ namespace SepCore.Procedure
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnLeave(IFsm<IProcedureManager> procedureOwner)
|
||||
public override void OnLeave()
|
||||
{
|
||||
Log.Debug("GameStateLevelUp::OnLeave");
|
||||
|
||||
GameEntry.UIRouter.CloseUIAsync(UIFormType.LevelUpForm).Forget();
|
||||
}
|
||||
|
||||
public override void OnDestroy(IFsm<IProcedureManager> procedureOwner)
|
||||
public override void OnDestroy()
|
||||
{
|
||||
_procedureGame = null;
|
||||
|
||||
@@ -60,6 +59,5 @@ namespace SepCore.Procedure
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,13 @@ namespace SepCore.Procedure
|
||||
{
|
||||
Log.Debug("GameStateShop::OnInit");
|
||||
_procedureGame = master;
|
||||
|
||||
var shopFormUseCase = new ShopUseCase(_procedureGame.Player, _procedureGame.CurrentLevel, () => ShopFinish = true);
|
||||
|
||||
var shopFormUseCase =
|
||||
new ShopUseCase(_procedureGame.Player, _procedureGame.CurrentLevel, () => ShopFinish = true);
|
||||
GameEntry.UIRouter.BindUIUseCase(UIFormType.ShopForm, shopFormUseCase);
|
||||
}
|
||||
|
||||
public override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
public override void OnEnter()
|
||||
{
|
||||
Log.Debug("GameStateShop::OnEnter");
|
||||
|
||||
@@ -35,8 +36,7 @@ namespace SepCore.Procedure
|
||||
GameEntry.UIRouter.OpenUIAsync(UIFormType.ShopForm).Forget();
|
||||
}
|
||||
|
||||
public override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||
float realElapseSeconds)
|
||||
public override void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
if (ShopFinish)
|
||||
{
|
||||
@@ -44,14 +44,14 @@ namespace SepCore.Procedure
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnLeave(IFsm<IProcedureManager> procedureOwner)
|
||||
public override void OnLeave()
|
||||
{
|
||||
Log.Debug("GameStateShop::OnLeave");
|
||||
|
||||
GameEntry.UIRouter.CloseUIAsync(UIFormType.ShopForm).Forget();
|
||||
}
|
||||
|
||||
public override void OnDestroy(IFsm<IProcedureManager> procedureOwner)
|
||||
public override void OnDestroy()
|
||||
{
|
||||
_procedureGame = null;
|
||||
|
||||
@@ -60,4 +60,4 @@ namespace SepCore.Procedure
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using GameFramework.Event;
|
||||
using GameFramework.Fsm;
|
||||
using GameFramework.Procedure;
|
||||
using UnityGameFramework.Runtime;
|
||||
using SepCore.UI;
|
||||
using SepCore.AsyncTask;
|
||||
|
||||
namespace SepCore.Procedure
|
||||
{
|
||||
@@ -23,10 +23,6 @@ namespace SepCore.Procedure
|
||||
{
|
||||
public override bool UseNativeDialog => false;
|
||||
|
||||
private HudForm _hudForm;
|
||||
private bool _hudInitialized;
|
||||
|
||||
private IFsm<IProcedureManager> _procedureOwner;
|
||||
private PlayerData _currentPlayerData;
|
||||
public int CurrentLevel = 1;
|
||||
|
||||
@@ -50,7 +46,7 @@ namespace SepCore.Procedure
|
||||
_gameStates[GameStateType.Shop].OnInit(this);
|
||||
|
||||
_currentGameState = GameStateType.Battle;
|
||||
_gameStates[_currentGameState].OnEnter(_procedureOwner);
|
||||
_gameStates[_currentGameState].OnEnter();
|
||||
}
|
||||
|
||||
public void BattleToShopOrLevelUp()
|
||||
@@ -58,27 +54,27 @@ namespace SepCore.Procedure
|
||||
CurrentLevel++;
|
||||
if (_currentGameState == GameStateType.Shop || _currentGameState == GameStateType.LevelUp) return;
|
||||
|
||||
_gameStates[_currentGameState].OnLeave(_procedureOwner);
|
||||
_gameStates[_currentGameState].OnLeave();
|
||||
_currentGameState = Player.PendingLevelPoints > 0 ? GameStateType.LevelUp : GameStateType.Shop;
|
||||
_gameStates[_currentGameState].OnEnter(_procedureOwner);
|
||||
_gameStates[_currentGameState].OnEnter();
|
||||
}
|
||||
|
||||
public void ShopToBattle()
|
||||
{
|
||||
if (_currentGameState == GameStateType.Battle) return;
|
||||
|
||||
_gameStates[_currentGameState].OnLeave(_procedureOwner);
|
||||
_gameStates[_currentGameState].OnLeave();
|
||||
_currentGameState = GameStateType.Battle;
|
||||
_gameStates[_currentGameState].OnEnter(_procedureOwner);
|
||||
_gameStates[_currentGameState].OnEnter();
|
||||
}
|
||||
|
||||
public void LevelUpToShop()
|
||||
{
|
||||
if (_currentGameState == GameStateType.Shop) return;
|
||||
|
||||
_gameStates[_currentGameState].OnLeave(_procedureOwner);
|
||||
_gameStates[_currentGameState].OnLeave();
|
||||
_currentGameState = GameStateType.Shop;
|
||||
_gameStates[_currentGameState].OnEnter(_procedureOwner);
|
||||
_gameStates[_currentGameState].OnEnter();
|
||||
}
|
||||
|
||||
#region FSM
|
||||
@@ -87,87 +83,65 @@ namespace SepCore.Procedure
|
||||
{
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
_procedureOwner = procedureOwner;
|
||||
GameEntry.SimulationWorld?.ClearSimulationState();
|
||||
|
||||
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
GameEntry.Event.Subscribe(ShowEntitySuccessEventArgs.EventId, ShowEntitySuccess);
|
||||
|
||||
CurrentLevel = 1;
|
||||
_currentPlayerData = new PlayerData(-1, 1001);
|
||||
GameEntry.Entity.ShowPlayer(_currentPlayerData);
|
||||
|
||||
GameEntry.UIRouter.OpenUIAsync(UIFormType.HudForm).Forget();
|
||||
EnterAsync(procedureOwner).Forget();
|
||||
}
|
||||
|
||||
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||
float realElapseSeconds)
|
||||
{
|
||||
base.OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||
|
||||
_procedureOwner = procedureOwner;
|
||||
|
||||
if (!_hudInitialized && _hudForm != null && Player != null)
|
||||
{
|
||||
int selectedRoleId = _procedureOwner.GetData<VarInt32>("SelectedRoleId").Value;
|
||||
var role = GameEntry.DataTable.GetDataTableRow<DRRole>(selectedRoleId);
|
||||
Player.InitRole(role);
|
||||
_hudInitialized = true;
|
||||
InitGameState();
|
||||
}
|
||||
|
||||
if (_hudInitialized)
|
||||
_gameStates[_currentGameState].OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||
_gameStates?[_currentGameState].OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
|
||||
protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
|
||||
{
|
||||
foreach (var state in _gameStates.Values)
|
||||
if (_gameStates != null)
|
||||
{
|
||||
state.OnDestroy(procedureOwner);
|
||||
}
|
||||
foreach (var state in _gameStates.Values)
|
||||
{
|
||||
state.OnDestroy();
|
||||
}
|
||||
|
||||
_gameStates.Clear();
|
||||
_gameStates.Clear();
|
||||
}
|
||||
|
||||
GameEntry.UIRouter.CloseUIAsync(UIFormType.HudForm).Forget();
|
||||
|
||||
_hudForm = null;
|
||||
|
||||
Player = null;
|
||||
|
||||
_procedureOwner = null;
|
||||
GameEntry.SimulationWorld?.ClearSimulationState();
|
||||
|
||||
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
GameEntry.Event.Unsubscribe(ShowEntitySuccessEventArgs.EventId, ShowEntitySuccess);
|
||||
|
||||
base.OnLeave(procedureOwner, isShutdown);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handler
|
||||
|
||||
private void OpenUIFormSuccess(object sender, GameEventArgs e)
|
||||
private async UniTaskVoid EnterAsync(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
if (!(e is OpenUIFormSuccessEventArgs args)) return;
|
||||
|
||||
if (args.UIForm.Logic is HudForm hudForm)
|
||||
try
|
||||
{
|
||||
_hudForm = hudForm;
|
||||
Player = await GameEntry.Entity.ShowPlayerAsync(_currentPlayerData);
|
||||
await GameEntry.UIRouter.OpenUIAsync(UIFormType.HudForm);
|
||||
|
||||
int selectedRoleId = procedureOwner.GetData<VarInt32>("SelectedRoleId").Value;
|
||||
var role = GameEntry.DataTable.GetDataTableRow<DRRole>(selectedRoleId);
|
||||
if (role == null)
|
||||
{
|
||||
Log.Error("ProcedureGame.EnterAsync() can not load role '{0}'.", selectedRoleId.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
Player.InitRole(role);
|
||||
InitGameState();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.Error("ProcedureGame.EnterAsync() failed with exception '{0}'.", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowEntitySuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is ShowEntitySuccessEventArgs args)) return;
|
||||
|
||||
if (args.Entity.Logic is Player player)
|
||||
{
|
||||
Player = player;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user