迁移 Player/ProcedureGame/ShopUseCase 里的实体方法调用风格
- Player/ShopUseCase:调整了 Weapon 实体的打开方式 - ProcedureGame:调整初始化时的 Hud 和 Player 的初始化写法,流程更清楚
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Components;
|
||||
using SepCore.Event;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using SepCore.Entity;
|
||||
using GameFramework.Event;
|
||||
using UnityGameFramework.Runtime;
|
||||
using SepCore.Entity.Weapon;
|
||||
using SepCore.CustomUtility;
|
||||
using SepCore.AsyncTask;
|
||||
|
||||
namespace SepCore.Entity
|
||||
{
|
||||
@@ -92,6 +92,28 @@ namespace SepCore.Entity
|
||||
return _backpackComponent.AttachProp(prop);
|
||||
}
|
||||
|
||||
public async UniTask<WeaponBase> AddWeaponAsync(WeaponData weaponData, float timeout = 30f)
|
||||
{
|
||||
if (weaponData == null || _backpackComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
WeaponBase weapon = await GameEntry.Entity.ShowWeaponAsync(weaponData, timeout);
|
||||
if (weapon == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!_backpackComponent.AttachWeapon(weapon))
|
||||
{
|
||||
GameEntry.Entity.HideEntity(weapon);
|
||||
return null;
|
||||
}
|
||||
|
||||
return weapon;
|
||||
}
|
||||
|
||||
public bool RemoveWeapon(WeaponBase weapon)
|
||||
{
|
||||
if (weapon == null || _backpackComponent == null)
|
||||
@@ -141,8 +163,8 @@ namespace SepCore.Entity
|
||||
// BackpackComponent
|
||||
Coin = role.Coin;
|
||||
_backpackComponent.OnInit(this, role.WeaponCapacity);
|
||||
GameEntry.Entity.ShowWeapon(EntityDataFactory.Create(GameEntry.Entity.NextId(),
|
||||
WeaponType.WeaponKnife, Id, _playerData.Camp));
|
||||
AddWeaponAsync(EntityDataFactory.Create(GameEntry.Entity.NextId(),
|
||||
WeaponType.WeaponKnife, Id, _playerData.Camp)).Forget();
|
||||
|
||||
// StatComponent
|
||||
foreach (var modifier in role.InitialProperties)
|
||||
@@ -158,8 +180,7 @@ namespace SepCore.Entity
|
||||
|
||||
GameEntry.Event.Fire(this, PlayerExpChangeEventArgs.Create(0, 100));
|
||||
|
||||
GameEntry.Event.Fire(this,
|
||||
PlayerCoinChangeEventArgs.Create(Coin, Coin));
|
||||
GameEntry.Event.Fire(this, PlayerCoinChangeEventArgs.Create(Coin, Coin));
|
||||
}
|
||||
|
||||
#region FSM
|
||||
@@ -190,8 +211,6 @@ namespace SepCore.Entity
|
||||
{
|
||||
base.OnShow(userData);
|
||||
|
||||
GameEntry.Event.Subscribe(ShowEntitySuccessEventArgs.EventId, ShowEntitySuccess);
|
||||
|
||||
_statComponent.OnInit();
|
||||
|
||||
if (userData is PlayerData playerData)
|
||||
@@ -230,18 +249,5 @@ namespace SepCore.Entity
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void ShowEntitySuccess(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is ShowEntitySuccessEventArgs args)) return;
|
||||
if (args.Entity.Logic is WeaponBase weapon)
|
||||
{
|
||||
_backpackComponent.AttachWeapon(weapon);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user