清理 Player 以及相关组件
This commit is contained in:
Binary file not shown.
@@ -3,6 +3,9 @@
|
||||
"weaponCapacity": 6,
|
||||
"propMaxCount": -1,
|
||||
"playerEntity": "Player",
|
||||
"absorbSpeed": 15000,
|
||||
"collectDistance": 350,
|
||||
"defaultAbsorbRange": 3000,
|
||||
"weaponRecycleRate": 300,
|
||||
"shopGoodsCount": 4,
|
||||
"shopPriceRandomPercent": 50,
|
||||
@@ -24,6 +27,10 @@
|
||||
"projectileLifeTime": 3000,
|
||||
"projectileHeightOffset": 600,
|
||||
"projectileSpeed": 12000,
|
||||
"projectileEntity": "Projectile"
|
||||
"projectileEntity": "Projectile",
|
||||
"damageTextYOffset": 1100,
|
||||
"entityAsyncTimeout": 30000,
|
||||
"enemyBodyRadius": 450,
|
||||
"enemySeparationIterations": 2
|
||||
}
|
||||
]
|
||||
@@ -20,6 +20,9 @@ public sealed partial class GlobalConfig : Luban.BeanBase
|
||||
PropMaxCount = _buf.ReadInt();
|
||||
PlayerEntity = _buf.ReadString();
|
||||
PlayerEntity_Ref = null;
|
||||
AbsorbSpeed = _buf.ReadInt();
|
||||
CollectDistance = _buf.ReadInt();
|
||||
DefaultAbsorbRange = _buf.ReadInt();
|
||||
WeaponRecycleRate = _buf.ReadInt();
|
||||
ShopGoodsCount = _buf.ReadInt();
|
||||
ShopPriceRandomPercent = _buf.ReadInt();
|
||||
@@ -43,6 +46,10 @@ public sealed partial class GlobalConfig : Luban.BeanBase
|
||||
ProjectileSpeed = _buf.ReadInt();
|
||||
ProjectileEntity = _buf.ReadString();
|
||||
ProjectileEntity_Ref = null;
|
||||
DamageTextYOffset = _buf.ReadInt();
|
||||
EntityAsyncTimeout = _buf.ReadInt();
|
||||
EnemyBodyRadius = _buf.ReadInt();
|
||||
EnemySeparationIterations = _buf.ReadInt();
|
||||
}
|
||||
|
||||
public static GlobalConfig DeserializeGlobalConfig(ByteBuf _buf)
|
||||
@@ -64,6 +71,18 @@ public sealed partial class GlobalConfig : Luban.BeanBase
|
||||
public readonly string PlayerEntity;
|
||||
public EntityConfig PlayerEntity_Ref;
|
||||
/// <summary>
|
||||
/// 自动收集速度
|
||||
/// </summary>
|
||||
public readonly int AbsorbSpeed;
|
||||
/// <summary>
|
||||
/// 自动收集距离
|
||||
/// </summary>
|
||||
public readonly int CollectDistance;
|
||||
/// <summary>
|
||||
/// 默认吸收距离
|
||||
/// </summary>
|
||||
public readonly int DefaultAbsorbRange;
|
||||
/// <summary>
|
||||
/// 武器回收价比例
|
||||
/// </summary>
|
||||
public readonly int WeaponRecycleRate;
|
||||
@@ -152,6 +171,22 @@ public sealed partial class GlobalConfig : Luban.BeanBase
|
||||
/// </summary>
|
||||
public readonly string ProjectileEntity;
|
||||
public EntityConfig ProjectileEntity_Ref;
|
||||
/// <summary>
|
||||
/// 伤害数字高度偏移
|
||||
/// </summary>
|
||||
public readonly int DamageTextYOffset;
|
||||
/// <summary>
|
||||
/// 实体生成超时时间
|
||||
/// </summary>
|
||||
public readonly int EntityAsyncTimeout;
|
||||
/// <summary>
|
||||
/// 敌人碰撞半径
|
||||
/// </summary>
|
||||
public readonly int EnemyBodyRadius;
|
||||
/// <summary>
|
||||
/// 敌人分离迭代次数
|
||||
/// </summary>
|
||||
public readonly int EnemySeparationIterations;
|
||||
|
||||
public const int __ID__ = -958250779;
|
||||
public override int GetTypeId() => __ID__;
|
||||
@@ -178,11 +213,18 @@ public sealed partial class GlobalConfig : Luban.BeanBase
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ProjectileEntity_Ref = tables.TbEntityConfig.GetOrDefault(ProjectileEntity);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
@@ -191,6 +233,9 @@ public sealed partial class GlobalConfig : Luban.BeanBase
|
||||
+ "weaponCapacity:" + WeaponCapacity + ","
|
||||
+ "propMaxCount:" + PropMaxCount + ","
|
||||
+ "playerEntity:" + PlayerEntity + ","
|
||||
+ "absorbSpeed:" + AbsorbSpeed + ","
|
||||
+ "collectDistance:" + CollectDistance + ","
|
||||
+ "defaultAbsorbRange:" + DefaultAbsorbRange + ","
|
||||
+ "weaponRecycleRate:" + WeaponRecycleRate + ","
|
||||
+ "shopGoodsCount:" + ShopGoodsCount + ","
|
||||
+ "shopPriceRandomPercent:" + ShopPriceRandomPercent + ","
|
||||
@@ -213,6 +258,10 @@ public sealed partial class GlobalConfig : Luban.BeanBase
|
||||
+ "projectileHeightOffset:" + ProjectileHeightOffset + ","
|
||||
+ "projectileSpeed:" + ProjectileSpeed + ","
|
||||
+ "projectileEntity:" + ProjectileEntity + ","
|
||||
+ "damageTextYOffset:" + DamageTextYOffset + ","
|
||||
+ "entityAsyncTimeout:" + EntityAsyncTimeout + ","
|
||||
+ "enemyBodyRadius:" + EnemyBodyRadius + ","
|
||||
+ "enemySeparationIterations:" + EnemySeparationIterations + ","
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,18 @@ public partial class TbGlobalConfig
|
||||
/// </summary>
|
||||
public string PlayerEntity => _data.PlayerEntity;
|
||||
/// <summary>
|
||||
/// 自动收集速度
|
||||
/// </summary>
|
||||
public int AbsorbSpeed => _data.AbsorbSpeed;
|
||||
/// <summary>
|
||||
/// 自动收集距离
|
||||
/// </summary>
|
||||
public int CollectDistance => _data.CollectDistance;
|
||||
/// <summary>
|
||||
/// 默认吸收距离
|
||||
/// </summary>
|
||||
public int DefaultAbsorbRange => _data.DefaultAbsorbRange;
|
||||
/// <summary>
|
||||
/// 武器回收价比例
|
||||
/// </summary>
|
||||
public int WeaponRecycleRate => _data.WeaponRecycleRate;
|
||||
@@ -130,6 +142,22 @@ public partial class TbGlobalConfig
|
||||
/// 投射物实体
|
||||
/// </summary>
|
||||
public string ProjectileEntity => _data.ProjectileEntity;
|
||||
/// <summary>
|
||||
/// 伤害数字高度偏移
|
||||
/// </summary>
|
||||
public int DamageTextYOffset => _data.DamageTextYOffset;
|
||||
/// <summary>
|
||||
/// 实体生成超时时间
|
||||
/// </summary>
|
||||
public int EntityAsyncTimeout => _data.EntityAsyncTimeout;
|
||||
/// <summary>
|
||||
/// 敌人碰撞半径
|
||||
/// </summary>
|
||||
public int EnemyBodyRadius => _data.EnemyBodyRadius;
|
||||
/// <summary>
|
||||
/// 敌人分离迭代次数
|
||||
/// </summary>
|
||||
public int EnemySeparationIterations => _data.EnemySeparationIterations;
|
||||
|
||||
public void ResolveRef(Tables tables)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameFramework.Fsm;
|
||||
using GameFramework.Procedure;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.Procedure
|
||||
{
|
||||
public abstract class GameStateBase
|
||||
|
||||
@@ -7,11 +7,7 @@ namespace SepCore.Components
|
||||
{
|
||||
public class AbsorbComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float _absorbRangeBase = 3f;
|
||||
[SerializeField] private float _absorbSpeed = 15f;
|
||||
[SerializeField] private float _collectDistance = 0.35f;
|
||||
[SerializeField] private int _maxDetectCount = 64;
|
||||
[SerializeField] private LayerMask _detectLayerMask = ~0;
|
||||
|
||||
private Player _player;
|
||||
private Transform _target;
|
||||
@@ -21,38 +17,34 @@ namespace SepCore.Components
|
||||
private StatProperty _absorbRangeStat;
|
||||
private Action<modifier, bool> _absorbRangeStatCallback;
|
||||
|
||||
private float AbsorbRange => Mathf.Max(0f, (_absorbRangeBase + _absorbRangeStat.Value) * _absorbRangeStat.Percent);
|
||||
private float AbsorbRangeBase => GameEntry.Luban.Global.DefaultAbsorbRange / 1000f;
|
||||
private float AbsorbSpeed => GameEntry.Luban.Global.AbsorbSpeed / 1000f;
|
||||
private float CollectDistance => GameEntry.Luban.Global.CollectDistance / 1000f;
|
||||
|
||||
public void OnInit(Player player, StatComponent statComponent = null)
|
||||
private float AbsorbRange => Mathf.Max(0f, (AbsorbRangeBase + _absorbRangeStat.Value) * _absorbRangeStat.Percent);
|
||||
|
||||
public void OnInit(Player player, StatComponent statComponent)
|
||||
{
|
||||
_player = player;
|
||||
_target = player != null ? player.CachedTransform : null;
|
||||
_target = player.CachedTransform;
|
||||
_statComponent = statComponent;
|
||||
_buffer = new Collider[Mathf.Max(1, _maxDetectCount)];
|
||||
|
||||
if (_statComponent != null)
|
||||
{
|
||||
_absorbRangeStat = _statComponent.GetStat(StatType.AbsorbRange);
|
||||
_absorbRangeStatCallback = (modifier, isApply) =>
|
||||
_statComponent.UpdateStat(_absorbRangeStat, modifier, isApply);
|
||||
_statComponent.Subscribe(StatType.AbsorbRange, _absorbRangeStatCallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
_absorbRangeStat = new StatProperty();
|
||||
}
|
||||
_absorbRangeStat = _statComponent.GetStat(StatType.AbsorbRange);
|
||||
_absorbRangeStatCallback = (modifier, isApply) =>
|
||||
_statComponent.UpdateStat(_absorbRangeStat, modifier, isApply);
|
||||
_statComponent.Subscribe(StatType.AbsorbRange, _absorbRangeStatCallback);
|
||||
}
|
||||
|
||||
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
if (_player == null || !_player.Available || _target == null || _buffer == null) return;
|
||||
if (!_player.Available) return;
|
||||
|
||||
int hitCount = Physics.OverlapSphereNonAlloc(
|
||||
_target.position,
|
||||
AbsorbRange,
|
||||
_buffer,
|
||||
_detectLayerMask,
|
||||
QueryTriggerInteraction.Collide
|
||||
Constant.Layer.DropLayerMask
|
||||
);
|
||||
|
||||
for (int i = 0; i < hitCount; i++)
|
||||
@@ -64,7 +56,7 @@ namespace SepCore.Components
|
||||
if (coin != null && coin.Available)
|
||||
{
|
||||
AbsorbDrop(coin.CachedTransform, elapseSeconds);
|
||||
coin.TryCollect(_player, _collectDistance);
|
||||
coin.TryCollect(_player, CollectDistance);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -72,7 +64,7 @@ namespace SepCore.Components
|
||||
if (exp != null && exp.Available)
|
||||
{
|
||||
AbsorbDrop(exp.CachedTransform, elapseSeconds);
|
||||
exp.TryCollect(_player, _collectDistance);
|
||||
exp.TryCollect(_player, CollectDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,8 +85,7 @@ namespace SepCore.Components
|
||||
|
||||
private void AbsorbDrop(Transform drop, float deltaTime)
|
||||
{
|
||||
if (drop == null || _target == null) return;
|
||||
drop.position = Vector3.MoveTowards(drop.position, _target.position, _absorbSpeed * deltaTime);
|
||||
drop.position = Vector3.MoveTowards(drop.position, _target.position, AbsorbSpeed * deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using SepCore.Entity;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.Components
|
||||
{
|
||||
public class AttackComponent : MonoBehaviour
|
||||
{
|
||||
private bool _isAttacking = false;
|
||||
private List<WeaponBase> _weapons;
|
||||
|
||||
public void SetIsAttacking(bool isAttacking) => _isAttacking = isAttacking;
|
||||
|
||||
public void OnInit()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnUpdate(float elapsedTime, float realElapseSeconds)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2b35b5ae4185cb4cab2d84b0569db3d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -94,7 +94,6 @@ namespace SepCore.Components
|
||||
|
||||
public void SetWeaponState(bool state)
|
||||
{
|
||||
if (_weapons == null) return;
|
||||
foreach (var weapon in _weapons)
|
||||
{
|
||||
weapon.SetEnabled(state);
|
||||
|
||||
@@ -43,8 +43,6 @@ namespace SepCore.Components
|
||||
{
|
||||
_maxHealthBase = maxHealth;
|
||||
_currentHealth = maxHealth;
|
||||
_statComponent = statComponent;
|
||||
|
||||
_statComponent = statComponent;
|
||||
if (_statComponent != null)
|
||||
{
|
||||
@@ -98,7 +96,8 @@ namespace SepCore.Components
|
||||
{
|
||||
if (_isDead) return;
|
||||
|
||||
if (_dodgeStat.Value > UnityEngine.Random.value)
|
||||
float maxDodge = GameEntry.Luban.Global.MaxDodgeRate / 1000f;
|
||||
if (UnityEngine.Random.value < Mathf.Clamp(_dodgeStat.Value, 0f, maxDodge))
|
||||
{
|
||||
damage = 0;
|
||||
}
|
||||
@@ -108,6 +107,8 @@ namespace SepCore.Components
|
||||
float defensePercent = _defenseStat.Percent;
|
||||
damage -= defenseValue;
|
||||
damage = Mathf.CeilToInt(damage / defensePercent);
|
||||
int minDamage = GameEntry.Luban.Global.MinDamage;
|
||||
if (damage < minDamage) damage = minDamage;
|
||||
}
|
||||
|
||||
_currentHealth -= damage;
|
||||
@@ -118,8 +119,9 @@ namespace SepCore.Components
|
||||
|
||||
private void CauseDamage(int damage)
|
||||
{
|
||||
if (damage <= 0 || GameEntry.DamageText == null) return;
|
||||
GameEntry.DamageText.ShowDamage(transform.position + Vector3.up * 1.1f, damage);
|
||||
if (damage <= 0) return;
|
||||
float yOffset = GameEntry.Luban.Global.DamageTextYOffset / 1000f;
|
||||
GameEntry.DamageText.ShowDamage(transform.position + Vector3.up * yOffset, damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@ namespace SepCore.Components
|
||||
GameEntry.InputModule.RegisterListener(InputActionId.Move, OnMove);
|
||||
}
|
||||
|
||||
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
{
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace SepCore.Components
|
||||
[SerializeField] private Vector3 _direction;
|
||||
[SerializeField] private Transform _cachedTransform;
|
||||
[SerializeField] private bool _avoidEnemyOverlap;
|
||||
[SerializeField] private float _enemyBodyRadius = 0.45f;
|
||||
[SerializeField] private int _separationIterations = 2;
|
||||
[SerializeField] private float _enemyBodyRadius;
|
||||
[SerializeField] private int _separationIterations;
|
||||
|
||||
public float Speed => (_speedBase + _movementStat.Value) * _movementStat.Percent;
|
||||
public bool AvoidEnemyOverlap => _avoidEnemyOverlap;
|
||||
@@ -26,19 +26,24 @@ namespace SepCore.Components
|
||||
[SerializeField] private float _speedBase;
|
||||
|
||||
private StatComponent _statComponent;
|
||||
private Player _player;
|
||||
private EnemyBase _enemy;
|
||||
|
||||
private StatProperty _movementStat;
|
||||
private Action<modifier, bool> _movementStatCallback;
|
||||
|
||||
public void OnInit(float speed, Transform target, StatComponent statComponent = null,
|
||||
bool avoidEnemyOverlap = false, float enemyBodyRadius = 0.45f, int separationIterations = 2)
|
||||
bool avoidEnemyOverlap = false, float? enemyBodyRadius = null, int? separationIterations = null)
|
||||
{
|
||||
_speedBase = speed;
|
||||
_cachedTransform = target;
|
||||
_direction = Vector3.forward;
|
||||
_avoidEnemyOverlap = avoidEnemyOverlap;
|
||||
_enemyBodyRadius = Mathf.Max(0.01f, enemyBodyRadius);
|
||||
_separationIterations = Mathf.Max(1, separationIterations);
|
||||
_enemyBodyRadius = Mathf.Max(0.01f, enemyBodyRadius ?? (GameEntry.Luban.Global.EnemyBodyRadius / 1000f));
|
||||
_separationIterations = Mathf.Max(1, separationIterations ?? GameEntry.Luban.Global.EnemySeparationIterations);
|
||||
|
||||
TryGetComponent(out _player);
|
||||
TryGetComponent(out _enemy);
|
||||
|
||||
_statComponent = statComponent;
|
||||
if (_statComponent != null)
|
||||
@@ -73,8 +78,10 @@ namespace SepCore.Components
|
||||
_direction = Vector3.zero;
|
||||
_isMoving = false;
|
||||
_avoidEnemyOverlap = false;
|
||||
_enemyBodyRadius = 0.45f;
|
||||
_separationIterations = 2;
|
||||
_enemyBodyRadius = GameEntry.Luban.Global.EnemyBodyRadius / 1000f;
|
||||
_separationIterations = GameEntry.Luban.Global.EnemySeparationIterations;
|
||||
_player = null;
|
||||
_enemy = null;
|
||||
|
||||
if (_statComponent != null)
|
||||
{
|
||||
@@ -86,8 +93,7 @@ namespace SepCore.Components
|
||||
|
||||
if (transformToUnregister != null)
|
||||
{
|
||||
var simulationWorld = GameEntry.SimulationWorld;
|
||||
simulationWorld?.UnregisterPlayerMovement(transformToUnregister);
|
||||
GameEntry.SimulationWorld.UnregisterPlayerMovement(transformToUnregister);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,12 +118,6 @@ namespace SepCore.Components
|
||||
return;
|
||||
}
|
||||
|
||||
SimulationWorld simulationWorld = GameEntry.SimulationWorld;
|
||||
if (simulationWorld == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 direction = _direction;
|
||||
direction.y = 0f;
|
||||
if (direction.sqrMagnitude > Mathf.Epsilon)
|
||||
@@ -125,15 +125,15 @@ namespace SepCore.Components
|
||||
direction.Normalize();
|
||||
}
|
||||
|
||||
if (TryGetComponent(out Player _))
|
||||
if (_player != null)
|
||||
{
|
||||
simulationWorld.SyncPlayerMovementInput(_cachedTransform, _isMoving, direction, Speed);
|
||||
GameEntry.SimulationWorld.SyncPlayerMovementInput(_cachedTransform, _isMoving, direction, Speed);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryGetComponent(out EnemyBase enemy))
|
||||
if (_enemy != null)
|
||||
{
|
||||
simulationWorld.SyncEnemyMovementInput(enemy.Id, _isMoving, direction, Speed,
|
||||
GameEntry.SimulationWorld.SyncEnemyMovementInput(_enemy.Id, _isMoving, direction, Speed,
|
||||
_avoidEnemyOverlap, _enemyBodyRadius, _separationIterations);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,11 @@ namespace SepCore.Components
|
||||
{
|
||||
public class StatComponent : MonoBehaviour
|
||||
{
|
||||
private Dictionary<StatType, List<modifier>> _statModifiers;
|
||||
private Dictionary<StatType, Action<modifier, bool>> _statModifierCallbacks;
|
||||
private readonly Dictionary<StatType, List<modifier>> _statModifiers = new();
|
||||
private readonly Dictionary<StatType, Action<modifier, bool>> _statModifierCallbacks = new();
|
||||
|
||||
public void OnInit()
|
||||
{
|
||||
_statModifiers = new Dictionary<StatType, List<modifier>>();
|
||||
_statModifierCallbacks = new Dictionary<StatType, Action<modifier, bool>>();
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
@@ -26,13 +24,10 @@ namespace SepCore.Components
|
||||
{
|
||||
if (!_statModifiers.TryGetValue(modifier.StatType, out var modifiers))
|
||||
{
|
||||
_statModifiers.Add(modifier.StatType, modifiers = new List<modifier>());
|
||||
modifiers.Add(modifier);
|
||||
}
|
||||
else
|
||||
{
|
||||
modifiers.Add(modifier);
|
||||
modifiers = new List<modifier>();
|
||||
_statModifiers.Add(modifier.StatType, modifiers);
|
||||
}
|
||||
modifiers.Add(modifier);
|
||||
|
||||
if (_statModifierCallbacks.TryGetValue(modifier.StatType, out var callbacks))
|
||||
callbacks?.Invoke(modifier, true);
|
||||
@@ -42,7 +37,7 @@ namespace SepCore.Components
|
||||
{
|
||||
if (_statModifiers.TryGetValue(modifier.StatType, out var modifiers))
|
||||
{
|
||||
_statModifiers[modifier.StatType].Remove(modifier);
|
||||
modifiers.Remove(modifier);
|
||||
}
|
||||
|
||||
if (_statModifierCallbacks.TryGetValue(modifier.StatType, out var callbacks))
|
||||
|
||||
@@ -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