Start Tag System
This commit is contained in:
@@ -4,6 +4,6 @@ namespace Components
|
||||
{
|
||||
public interface IDamageReceiver
|
||||
{
|
||||
void TakeDamage(int damage, AttackPropertyType attackPropertyType);
|
||||
void TakeDamage(AttackPayload attackPayload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,13 @@ namespace Components
|
||||
private bool _isMoving = false;
|
||||
private Vector3 _direction = Vector3.forward;
|
||||
private float _speed = 0;
|
||||
private float _speedMultiplier = 1f;
|
||||
private Transform _cachedTransform;
|
||||
|
||||
public void OnInit(float speed, Transform transform)
|
||||
{
|
||||
_speed = speed;
|
||||
_speedMultiplier = 1f;
|
||||
_cachedTransform = transform;
|
||||
}
|
||||
|
||||
@@ -26,16 +28,18 @@ namespace Components
|
||||
public void OnReset()
|
||||
{
|
||||
_speed = 0;
|
||||
_speedMultiplier = 1f;
|
||||
_cachedTransform = null;
|
||||
_isMoving = false;
|
||||
}
|
||||
|
||||
private void Move(float deltaTime = 0)
|
||||
{
|
||||
_cachedTransform.Translate(_direction * _speed * deltaTime);
|
||||
_cachedTransform.Translate(_direction * (_speed * _speedMultiplier) * deltaTime);
|
||||
}
|
||||
|
||||
public void SetMove(bool isMoving) => _isMoving = isMoving;
|
||||
public void SetDirection(Vector3 direction) => _direction = direction;
|
||||
public void SetSpeedMultiplier(float speedMultiplier) => _speedMultiplier = Mathf.Max(0f, speedMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ namespace Components
|
||||
|
||||
private Transform _target;
|
||||
private float _speed;
|
||||
private int _damage;
|
||||
private AttackPropertyType _attackPropertyType;
|
||||
private AttackPayload _attackPayload;
|
||||
private float _lifetime;
|
||||
private float _runtimeMaxLifetime;
|
||||
private bool _isRunning;
|
||||
@@ -23,8 +22,7 @@ namespace Components
|
||||
public void OnShow(BulletData bulletData)
|
||||
{
|
||||
_target = bulletData != null ? bulletData.Target : null;
|
||||
_damage = bulletData != null ? Mathf.Max(0, bulletData.Damage) : 0;
|
||||
_attackPropertyType = bulletData != null ? bulletData.AttackPropertyType : AttackPropertyType.None;
|
||||
_attackPayload = bulletData?.AttackPayload?.Clone() ?? new AttackPayload();
|
||||
_speed = bulletData != null && bulletData.Speed > 0f ? bulletData.Speed : _defaultSpeed;
|
||||
_runtimeMaxLifetime = bulletData != null && bulletData.MaxLifetime > 0f ? bulletData.MaxLifetime : _maxLifetime;
|
||||
_lifetime = 0f;
|
||||
@@ -46,8 +44,7 @@ namespace Components
|
||||
{
|
||||
_target = null;
|
||||
_speed = 0f;
|
||||
_damage = 0;
|
||||
_attackPropertyType = AttackPropertyType.None;
|
||||
_attackPayload = new AttackPayload();
|
||||
_lifetime = 0f;
|
||||
_runtimeMaxLifetime = _maxLifetime;
|
||||
_isRunning = false;
|
||||
@@ -117,7 +114,7 @@ namespace Components
|
||||
{
|
||||
if (mono is IDamageReceiver damageReceiver)
|
||||
{
|
||||
damageReceiver.TakeDamage(_damage, _attackPropertyType);
|
||||
damageReceiver.TakeDamage(_attackPayload);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,21 @@ namespace Components
|
||||
|
||||
[SerializeField] private SpriteRenderer _renderer;
|
||||
|
||||
private TagRuntimeData[] _tagRuntimes = System.Array.Empty<TagRuntimeData>();
|
||||
|
||||
public int AttackDamage => _attackDamage;
|
||||
public AttackMethodType AttackMethodType => _attackMethodType;
|
||||
|
||||
public void OnInit(int attackDamage, AttackMethodType attackMethodType = AttackMethodType.NormalBullet, int bulletTypeId = 501)
|
||||
public void OnInit(
|
||||
int attackDamage,
|
||||
AttackMethodType attackMethodType = AttackMethodType.NormalBullet,
|
||||
int bulletTypeId = 501,
|
||||
TagRuntimeData[] tagRuntimes = null)
|
||||
{
|
||||
_attackDamage = Mathf.Max(1, attackDamage);
|
||||
_attackMethodType = attackMethodType;
|
||||
_bulletTypeId = Mathf.Max(1, bulletTypeId);
|
||||
_tagRuntimes = CloneTagRuntimes(tagRuntimes);
|
||||
}
|
||||
|
||||
public void OnReset()
|
||||
@@ -35,6 +42,7 @@ namespace Components
|
||||
_attackDamage = 1;
|
||||
_attackMethodType = AttackMethodType.None;
|
||||
_bulletTypeId = 501;
|
||||
_tagRuntimes = System.Array.Empty<TagRuntimeData>();
|
||||
}
|
||||
|
||||
public void SetColor(Color color)
|
||||
@@ -64,16 +72,47 @@ namespace Components
|
||||
|
||||
Transform spawnPoint = _muzzlePoint != null ? _muzzlePoint : transform;
|
||||
int bulletEntityId = GameEntry.Entity.GenerateSerialId();
|
||||
AttackPayload attackPayload = new AttackPayload
|
||||
{
|
||||
BaseDamage = _attackDamage,
|
||||
AttackPropertyType = attackPropertyType,
|
||||
TagRuntimes = CloneTagRuntimes(_tagRuntimes)
|
||||
};
|
||||
BulletData bulletData = new BulletData(
|
||||
bulletEntityId,
|
||||
_bulletTypeId,
|
||||
spawnPoint.position,
|
||||
target,
|
||||
_attackDamage,
|
||||
_bulletSpeed,
|
||||
attackPropertyType);
|
||||
attackPayload,
|
||||
_bulletSpeed);
|
||||
GameEntry.Entity.ShowBullet(bulletData);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static TagRuntimeData[] CloneTagRuntimes(TagRuntimeData[] tagRuntimes)
|
||||
{
|
||||
if (tagRuntimes == null || tagRuntimes.Length <= 0)
|
||||
{
|
||||
return System.Array.Empty<TagRuntimeData>();
|
||||
}
|
||||
|
||||
TagRuntimeData[] cloned = new TagRuntimeData[tagRuntimes.Length];
|
||||
for (int i = 0; i < tagRuntimes.Length; i++)
|
||||
{
|
||||
TagRuntimeData runtime = tagRuntimes[i];
|
||||
if (runtime == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
cloned[i] = new TagRuntimeData
|
||||
{
|
||||
TagType = runtime.TagType,
|
||||
TotalStack = runtime.TotalStack
|
||||
};
|
||||
}
|
||||
|
||||
return cloned;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace Components
|
||||
private Color _muzzleColor = Color.white;
|
||||
private Color _bearingColor = Color.white;
|
||||
private Color _baseColor = Color.white;
|
||||
private TagRuntimeData[] _tagRuntimes = System.Array.Empty<TagRuntimeData>();
|
||||
|
||||
public Transform CurrentTarget => _currentTarget;
|
||||
|
||||
@@ -63,8 +64,9 @@ namespace Components
|
||||
float rotateSpeed = ResolveFloatValue(stats.RotateSpeed, _towerLevel, 180f, 1f);
|
||||
float attackRange = ResolveFloatValue(stats.AttackRange, _towerLevel, 5f, 0.1f);
|
||||
float attackSpeed = ResolveFloatValue(stats.AttackSpeed, _towerLevel, 1f, 0.01f);
|
||||
_tagRuntimes = ResolveRuntimeTags(stats);
|
||||
|
||||
_muzzleComp?.OnInit(attackDamage, stats.AttackMethodType);
|
||||
_muzzleComp?.OnInit(attackDamage, stats.AttackMethodType, tagRuntimes: _tagRuntimes);
|
||||
_bearingComp?.OnInit(rotateSpeed, attackRange);
|
||||
_baseComp?.OnInit(attackSpeed, stats.AttackPropertyType);
|
||||
ApplyComponentColors();
|
||||
@@ -80,6 +82,7 @@ namespace Components
|
||||
_currentTarget = null;
|
||||
_retargetTimer = 0f;
|
||||
_towerLevel = MinTowerLevel;
|
||||
_tagRuntimes = System.Array.Empty<TagRuntimeData>();
|
||||
_muzzleComp?.OnReset();
|
||||
_bearingComp?.OnReset();
|
||||
_baseComp?.OnReset();
|
||||
@@ -221,6 +224,47 @@ namespace Components
|
||||
return target != null && target.gameObject.activeInHierarchy;
|
||||
}
|
||||
|
||||
private static TagRuntimeData[] CloneTagRuntimes(TagRuntimeData[] source)
|
||||
{
|
||||
if (source == null || source.Length <= 0)
|
||||
{
|
||||
return System.Array.Empty<TagRuntimeData>();
|
||||
}
|
||||
|
||||
TagRuntimeData[] cloned = new TagRuntimeData[source.Length];
|
||||
for (int i = 0; i < source.Length; i++)
|
||||
{
|
||||
TagRuntimeData runtime = source[i];
|
||||
if (runtime == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
cloned[i] = new TagRuntimeData
|
||||
{
|
||||
TagType = runtime.TagType,
|
||||
TotalStack = runtime.TotalStack
|
||||
};
|
||||
}
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
private static TagRuntimeData[] ResolveRuntimeTags(TowerStatsData stats)
|
||||
{
|
||||
if (stats == null)
|
||||
{
|
||||
return System.Array.Empty<TagRuntimeData>();
|
||||
}
|
||||
|
||||
if (stats.TagRuntimes != null && stats.TagRuntimes.Length > 0)
|
||||
{
|
||||
return CloneTagRuntimes(stats.TagRuntimes);
|
||||
}
|
||||
|
||||
return TowerTagAggregationService.BuildRuntimeTagsFromUniqueTags(stats.Tags);
|
||||
}
|
||||
|
||||
private static int ResolveIntValue(int[] values, int level, int fallback, int minValue)
|
||||
{
|
||||
int resolved = Mathf.Max(minValue, fallback);
|
||||
|
||||
Reference in New Issue
Block a user