初始化仓库
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameFramework.Fsm;
|
||||
using GameFramework.Procedure;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Procedure
|
||||
{
|
||||
public abstract class GameStateBase
|
||||
{
|
||||
public abstract GameStateType GameStateType { get; }
|
||||
public abstract void OnInit(ProcedureGame master);
|
||||
public abstract void OnEnter(IFsm<IProcedureManager> procedureOwner);
|
||||
|
||||
public abstract void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||
float realElapseSeconds);
|
||||
|
||||
public abstract void OnLeave(IFsm<IProcedureManager> procedureOwner);
|
||||
public abstract void OnDestroy(IFsm<IProcedureManager> procedureOwner);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3b8b3f058f54514089ba32980f52235
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,79 @@
|
||||
using CustomComponent;
|
||||
using Entity;
|
||||
using GameFramework.Fsm;
|
||||
using GameFramework.Procedure;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace Procedure
|
||||
{
|
||||
public class GameStateBattle : GameStateBase
|
||||
{
|
||||
public override GameStateType GameStateType => GameStateType.Battle;
|
||||
|
||||
private EnemyManagerComponent _enemyManager = null;
|
||||
private int _currentLevel = 0;
|
||||
private bool _levelOver;
|
||||
|
||||
private ProcedureGame _procedureGame = null;
|
||||
|
||||
public void LevelOver()
|
||||
{
|
||||
if (_levelOver) return;
|
||||
_levelOver = true;
|
||||
}
|
||||
|
||||
#region FSM
|
||||
|
||||
public override void OnInit(ProcedureGame master)
|
||||
{
|
||||
_enemyManager = GameEntry.EnemyManager;
|
||||
_procedureGame = master;
|
||||
}
|
||||
|
||||
public override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
_currentLevel = _procedureGame.CurrentLevel;
|
||||
_levelOver = false;
|
||||
_enemyManager.OnInit(_currentLevel, this);
|
||||
Player player = _procedureGame.Player;
|
||||
if (player != null) player.Enable = false;
|
||||
}
|
||||
|
||||
public override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||
float realElapseSeconds)
|
||||
{
|
||||
_enemyManager.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
|
||||
if (_levelOver)
|
||||
{
|
||||
procedureOwner.SetData<VarByte>("CurrentLevel", (byte)(_currentLevel + 1));
|
||||
_procedureGame.BattleToShop();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnLeave(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
// 隐藏所有敌人实体
|
||||
_enemyManager.OnReset();
|
||||
|
||||
// 停止玩家逻辑
|
||||
Player player = _procedureGame.Player;
|
||||
player.Enable = false;
|
||||
|
||||
// 隐藏所有掉落物实体
|
||||
var entities = GameEntry.Entity.GetEntityGroup("Drop").GetAllEntities();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
GameEntry.Entity.HideEntity(entity.Id);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnDestroy(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
_enemyManager = null;
|
||||
_procedureGame = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8444985d27db86a45b2b494bd6d39d3c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,204 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DataTable;
|
||||
using Definition.Enum;
|
||||
using Entity;
|
||||
using GameFramework.DataTable;
|
||||
using GameFramework.Event;
|
||||
using GameFramework.Fsm;
|
||||
using GameFramework.Procedure;
|
||||
using UI;
|
||||
using UnityGameFramework.Runtime;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Procedure
|
||||
{
|
||||
public struct ShopFormContext
|
||||
{
|
||||
public GameStateShop GameStateShop;
|
||||
public int CurrentLevel;
|
||||
public int RefreshPrice;
|
||||
public int PlayerCoin;
|
||||
public List<GoodsItemViewData> GoodsItems;
|
||||
}
|
||||
|
||||
public class GameStateShop : GameStateBase
|
||||
{
|
||||
public override GameStateType GameStateType => GameStateType.Shop;
|
||||
|
||||
private ProcedureGame _procedureGame = null;
|
||||
private bool _shopOver = false;
|
||||
private ShopForm _shopForm = null;
|
||||
|
||||
private DRGoods[] _drGoods = null;
|
||||
private IDataTable<DRProp> _propDataTable = null;
|
||||
private IDataTable<DRWeapon> _weaponDataTable = null;
|
||||
|
||||
private Player _player = null;
|
||||
|
||||
private ShopFormContext _shopFormContext;
|
||||
|
||||
public void ShopOver()
|
||||
{
|
||||
if (_shopOver) return;
|
||||
_shopOver = true;
|
||||
}
|
||||
|
||||
public void PurchaseGoods(int index)
|
||||
{
|
||||
if (_player.Coin < _shopFormContext.GoodsItems[index].Price) return;
|
||||
_player.Coin -= _shopFormContext.GoodsItems[index].Price;
|
||||
//TODO:OnGoodsPurchased
|
||||
}
|
||||
|
||||
public void RefreshGoods()
|
||||
{
|
||||
if (_player.Coin < _shopFormContext.RefreshPrice) return;
|
||||
_player.Coin -= _shopFormContext.RefreshPrice;
|
||||
_shopFormContext = new ShopFormContext()
|
||||
{
|
||||
GameStateShop = this,
|
||||
CurrentLevel = _procedureGame.CurrentLevel,
|
||||
RefreshPrice = _shopFormContext.RefreshPrice + _procedureGame.CurrentLevel,
|
||||
PlayerCoin = _player.Coin,
|
||||
GoodsItems = InitRandomGoodsItems()
|
||||
};
|
||||
_shopForm.UpdateForm(_shopFormContext);
|
||||
}
|
||||
|
||||
private List<GoodsItemViewData> InitRandomGoodsItems()
|
||||
{
|
||||
// 1. 随机生成商店商品数量
|
||||
int count = Random.Range(4, 6);
|
||||
|
||||
// 2. 获取数据表中配置的商品总数
|
||||
int totalCount = _drGoods.Length;
|
||||
|
||||
// 3. 创建要返回的商品列表
|
||||
List<GoodsItemViewData> items = new List<GoodsItemViewData>(count);
|
||||
|
||||
// 4. 填充商品列表
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
// 4.1 获取要添加的商品Id
|
||||
int index = Random.Range(0, totalCount);
|
||||
|
||||
// 4.2 从数据表中获取商品数据
|
||||
var drGoods = _drGoods[index];
|
||||
|
||||
// 4.3 构建商品数据类
|
||||
var goodsItem = new GoodsItemViewData();
|
||||
|
||||
// 4.4 填充商品数据(价格、名字、类型、图标、描述)
|
||||
goodsItem.Price = Random.Range(drGoods.MinPrice, drGoods.MaxPrice);
|
||||
|
||||
if (drGoods.GoodsType == GoodsType.Prop)
|
||||
{
|
||||
DRProp drProp = _propDataTable.GetDataRow(drGoods.GoodsTypeId);
|
||||
|
||||
goodsItem.Title = drProp.Title;
|
||||
goodsItem.Type = "道具";
|
||||
GameEntry.SpriteCache.GetSprite(drProp.IconAssetName, sprite => goodsItem.Icon = sprite);
|
||||
goodsItem.Description = GoodsItemViewData.CreatePropDescription(drProp.Modifiers);
|
||||
}
|
||||
else if (drGoods.GoodsType is GoodsType.Weapon)
|
||||
{
|
||||
DRWeapon drWeapon = _weaponDataTable.GetDataRow(drGoods.GoodsTypeId);
|
||||
|
||||
goodsItem.Title = drWeapon.Title;
|
||||
goodsItem.Type = "武器";
|
||||
GameEntry.SpriteCache.GetSprite(drWeapon.IconAssetName, sprite => goodsItem.Icon = sprite);
|
||||
goodsItem.Description = GoodsItemViewData.CreateWeaponDescription(drWeapon);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warning("Goods type not supported.");
|
||||
}
|
||||
|
||||
// 4.5 添加到商品列表
|
||||
items.Add(goodsItem);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
#region FSM
|
||||
|
||||
public override void OnInit(ProcedureGame master)
|
||||
{
|
||||
Log.Debug("GameStateShop::OnInit");
|
||||
_procedureGame = master;
|
||||
_shopOver = false;
|
||||
_drGoods = GameEntry.DataTable.GetDataTable<DRGoods>().ToArray();
|
||||
_propDataTable = GameEntry.DataTable.GetDataTable<DRProp>();
|
||||
_weaponDataTable = GameEntry.DataTable.GetDataTable<DRWeapon>();
|
||||
}
|
||||
|
||||
public override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
Log.Debug("GameStateShop::OnEnter");
|
||||
|
||||
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
|
||||
_shopOver = false;
|
||||
_player = _procedureGame.Player;
|
||||
|
||||
_shopFormContext = new ShopFormContext()
|
||||
{
|
||||
GameStateShop = this,
|
||||
CurrentLevel = _procedureGame.CurrentLevel,
|
||||
RefreshPrice = _procedureGame.CurrentLevel,
|
||||
PlayerCoin = _player.Coin,
|
||||
GoodsItems = InitRandomGoodsItems()
|
||||
};
|
||||
GameEntry.UI.OpenUIForm(UIFormType.ShopForm, _shopFormContext);
|
||||
}
|
||||
|
||||
public override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||
float realElapseSeconds)
|
||||
{
|
||||
Log.Debug("GameStateShop::OnUpdate");
|
||||
|
||||
if (_shopOver)
|
||||
{
|
||||
_shopForm.Close();
|
||||
_procedureGame.ShopToBattle();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnLeave(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
Log.Debug("GameStateShop::OnLeave");
|
||||
|
||||
_shopForm = null;
|
||||
|
||||
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OpenUIFormSuccess);
|
||||
}
|
||||
|
||||
public override void OnDestroy(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
_procedureGame = null;
|
||||
_drGoods = null;
|
||||
_propDataTable = null;
|
||||
_weaponDataTable = null;
|
||||
|
||||
Log.Debug("GameStateShop::OnDestroy");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void OpenUIFormSuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is OpenUIFormSuccessEventArgs args)) return;
|
||||
if (!(args.UserData is ShopFormContext data)) return;
|
||||
if (data.GameStateShop == this)
|
||||
{
|
||||
_shopForm = args.UIForm.Logic as ShopForm;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 847f4de71cf7c514895de6d12f07b59d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,155 @@
|
||||
using System.Collections.Generic;
|
||||
using CustomComponent;
|
||||
using CustomEvent;
|
||||
using DataTable;
|
||||
using Definition.Enum;
|
||||
using Entity;
|
||||
using Entity.EntityData;
|
||||
using GameFramework.Event;
|
||||
using GameFramework.Fsm;
|
||||
using GameFramework.Procedure;
|
||||
using StarForce;
|
||||
using UnityGameFramework.Runtime;
|
||||
using UI;
|
||||
|
||||
namespace Procedure
|
||||
{
|
||||
public enum GameStateType
|
||||
{
|
||||
None = 0,
|
||||
Battle = 1,
|
||||
Shop = 2,
|
||||
}
|
||||
|
||||
public class ProcedureGame : ProcedureBase
|
||||
{
|
||||
public override bool UseNativeDialog => false;
|
||||
|
||||
private HudForm _hudForm = null;
|
||||
private bool _hudInitialized = false;
|
||||
|
||||
private IFsm<IProcedureManager> _procedureOwner = null;
|
||||
private PlayerData _currentPlayerData = null;
|
||||
public int CurrentLevel = 1;
|
||||
|
||||
private GameStateType _currentGameState = GameStateType.None;
|
||||
private Dictionary<GameStateType, GameStateBase> _gameStates;
|
||||
public Player Player;
|
||||
|
||||
private void InitGameState()
|
||||
{
|
||||
_gameStates = new Dictionary<GameStateType, GameStateBase>
|
||||
{
|
||||
{ GameStateType.Battle, new GameStateBattle() },
|
||||
{ GameStateType.Shop, new GameStateShop() },
|
||||
};
|
||||
_gameStates[GameStateType.Battle].OnInit(this);
|
||||
_gameStates[GameStateType.Shop].OnInit(this);
|
||||
|
||||
_currentGameState = GameStateType.Battle;
|
||||
_gameStates[_currentGameState].OnEnter(_procedureOwner);
|
||||
}
|
||||
|
||||
public void BattleToShop()
|
||||
{
|
||||
if (_currentGameState == GameStateType.Shop) return;
|
||||
|
||||
_gameStates[_currentGameState].OnLeave(_procedureOwner);
|
||||
_currentGameState = GameStateType.Shop;
|
||||
_gameStates[_currentGameState].OnEnter(_procedureOwner);
|
||||
}
|
||||
|
||||
public void ShopToBattle()
|
||||
{
|
||||
if (_currentGameState == GameStateType.Battle) return;
|
||||
|
||||
_gameStates[_currentGameState].OnLeave(_procedureOwner);
|
||||
_currentGameState = GameStateType.Battle;
|
||||
_gameStates[_currentGameState].OnEnter(_procedureOwner);
|
||||
}
|
||||
|
||||
#region FSM
|
||||
|
||||
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
{
|
||||
base.OnEnter(procedureOwner);
|
||||
|
||||
_procedureOwner = procedureOwner;
|
||||
|
||||
GameEntry.Event.Subscribe(OpenUIFormSuccessEventArgs.EventId, OnOpenUIFormSuccess);
|
||||
GameEntry.Event.Subscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
|
||||
|
||||
CurrentLevel = 1;
|
||||
_currentPlayerData = new PlayerData(-1, 1001);
|
||||
GameEntry.Entity.ShowPlayer(_currentPlayerData);
|
||||
|
||||
GameEntry.UI.OpenUIForm(UIFormType.HudForm, this);
|
||||
|
||||
InitGameState();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
_gameStates[_currentGameState].OnUpdate(procedureOwner, elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
|
||||
protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
|
||||
{
|
||||
foreach (var state in _gameStates.Values)
|
||||
{
|
||||
state.OnDestroy(procedureOwner);
|
||||
}
|
||||
|
||||
_gameStates.Clear();
|
||||
|
||||
_hudForm.Close();
|
||||
_hudForm = null;
|
||||
Player = null;
|
||||
_procedureOwner = null;
|
||||
|
||||
GameEntry.Event.Unsubscribe(OpenUIFormSuccessEventArgs.EventId, OnOpenUIFormSuccess);
|
||||
GameEntry.Event.Unsubscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
|
||||
|
||||
base.OnLeave(procedureOwner, isShutdown);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handler
|
||||
|
||||
private void OnOpenUIFormSuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is OpenUIFormSuccessEventArgs args)) return;
|
||||
|
||||
if (args.UserData == this)
|
||||
{
|
||||
_hudForm = args.UIForm.Logic as HudForm;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnShowEntitySuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is ShowEntitySuccessEventArgs args)) return;
|
||||
|
||||
if (args.EntityLogicType == typeof(Player))
|
||||
{
|
||||
Player = args.Entity.Logic as Player;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59780d3b0b2903249a2b496c91fdf98f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user