清理 Player 以及相关组件
This commit is contained in:
@@ -64,7 +64,7 @@ namespace SepCore.Entity
|
||||
get => _exp;
|
||||
set
|
||||
{
|
||||
if (_expRequires != null && _currentLevel + 1 < _expRequires.Length && value >= _expRequires[_currentLevel + 1])
|
||||
if (_currentLevel + 1 < _expRequires.Length && value >= _expRequires[_currentLevel + 1])
|
||||
{
|
||||
value -= _expRequires[_currentLevel + 1];
|
||||
_currentLevel++;
|
||||
@@ -72,9 +72,9 @@ namespace SepCore.Entity
|
||||
GameEntry.Event.Fire(this, PlayerLevelUpEventArgs.Create());
|
||||
}
|
||||
|
||||
int requiredExp = _expRequires != null && _currentLevel + 1 < _expRequires.Length
|
||||
int requiredExp = _currentLevel + 1 < _expRequires.Length
|
||||
? _expRequires[_currentLevel + 1]
|
||||
: 100;
|
||||
: _expRequires[^1];
|
||||
GameEntry.Event.Fire(this, PlayerExpChangeEventArgs.Create(value, requiredExp));
|
||||
_exp = value;
|
||||
}
|
||||
@@ -84,24 +84,25 @@ namespace SepCore.Entity
|
||||
|
||||
public int PendingLevelPoints { get; set; }
|
||||
|
||||
public IReadOnlyList<WeaponBase> Weapons => _backpackComponent != null ? _backpackComponent.Weapons : null;
|
||||
public IReadOnlyList<PropItem> Props => _backpackComponent != null ? _backpackComponent.Props : null;
|
||||
public int WeaponCapacity => _backpackComponent != null ? _backpackComponent.WeaponCapacity : 0;
|
||||
public IReadOnlyList<WeaponBase> Weapons => _backpackComponent.Weapons;
|
||||
public IReadOnlyList<PropItem> Props => _backpackComponent.Props;
|
||||
public int WeaponCapacity => _backpackComponent.WeaponCapacity;
|
||||
|
||||
public bool AddProp(PropItem prop)
|
||||
{
|
||||
if (prop == null || _backpackComponent == null) return false;
|
||||
if (prop == null) return false;
|
||||
return _backpackComponent.AttachProp(prop);
|
||||
}
|
||||
|
||||
public async UniTask<WeaponBase> AddWeaponAsync(WeaponData weaponData, float timeout = 30f)
|
||||
public async UniTask<WeaponBase> AddWeaponAsync(WeaponData weaponData, float? timeout = null)
|
||||
{
|
||||
if (weaponData == null || _backpackComponent == null)
|
||||
if (weaponData == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
WeaponBase weapon = await GameEntry.Entity.ShowWeaponAsync(weaponData, timeout);
|
||||
float actualTimeout = timeout ?? (GameEntry.Luban.Global.EntityAsyncTimeout / 1000f);
|
||||
WeaponBase weapon = await GameEntry.Entity.ShowWeaponAsync(weaponData, actualTimeout);
|
||||
if (weapon == null)
|
||||
{
|
||||
return null;
|
||||
@@ -118,7 +119,7 @@ namespace SepCore.Entity
|
||||
|
||||
public bool RemoveWeapon(WeaponBase weapon)
|
||||
{
|
||||
if (weapon == null || _backpackComponent == null)
|
||||
if (weapon == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -150,7 +151,7 @@ namespace SepCore.Entity
|
||||
public void SetWeaponEnabled(bool enabled)
|
||||
{
|
||||
_weaponEnabled = enabled;
|
||||
_backpackComponent?.SetWeaponState(_enable && _weaponEnabled);
|
||||
_backpackComponent.SetWeaponState(_enable && _weaponEnabled);
|
||||
}
|
||||
|
||||
public void InitRole(RoleConfig role, LevelExperienceConfig expConfig)
|
||||
@@ -168,22 +169,18 @@ namespace SepCore.Entity
|
||||
AddWeaponAsync(EntityDataFactory.Create(GameEntry.Entity.NextId(), WeaponType.Knife, Id, _playerData.Camp)).Forget();
|
||||
|
||||
// StatComponent
|
||||
if (role.Modifiers != null)
|
||||
foreach (var modifier in role.Modifiers)
|
||||
{
|
||||
foreach (var modifier in role.Modifiers)
|
||||
{
|
||||
_statComponent.AddModifier(modifier);
|
||||
}
|
||||
_statComponent.AddModifier(modifier);
|
||||
}
|
||||
|
||||
_expRequires = expConfig != null ? expConfig.ToTargetLevelArray() : null;
|
||||
_expRequires = expConfig.ToTargetLevelArray();
|
||||
|
||||
// Fire Events
|
||||
GameEntry.Event.Fire(this,
|
||||
PlayerHealthChangeEventArgs.Create(0, _healthComponent.CurrentHealth, _healthComponent.MaxHealth));
|
||||
|
||||
int initialTargetExp = _expRequires != null && _expRequires.Length > 1 ? _expRequires[1] : 100;
|
||||
GameEntry.Event.Fire(this, PlayerExpChangeEventArgs.Create(0, initialTargetExp));
|
||||
GameEntry.Event.Fire(this, PlayerExpChangeEventArgs.Create(0, _expRequires[1]));
|
||||
|
||||
GameEntry.Event.Fire(this, PlayerCoinChangeEventArgs.Create(Coin, Coin));
|
||||
}
|
||||
@@ -203,13 +200,7 @@ namespace SepCore.Entity
|
||||
_movementComponent = GetComponent<MovementComponent>();
|
||||
_absorbComponent = GetComponent<AbsorbComponent>();
|
||||
_statComponent = GetComponent<StatComponent>();
|
||||
_healthComponent = GetComponent<HealthComponent>();
|
||||
_backpackComponent = GetComponent<BackpackComponent>();
|
||||
|
||||
if (_absorbComponent == null)
|
||||
{
|
||||
_absorbComponent = gameObject.AddComponent<AbsorbComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnShow(object userData)
|
||||
@@ -235,8 +226,6 @@ namespace SepCore.Entity
|
||||
{
|
||||
base.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
|
||||
_inputComponent.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
|
||||
_movementComponent.SetDirection(_inputComponent.Direction);
|
||||
_absorbComponent.OnUpdate(elapseSeconds, realElapseSeconds);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user