using GeometryTD.Definition; using GeometryTD.Entity.EntityData; using GeometryTD; using UnityEngine; namespace Components { [DisallowMultipleComponent] public class ShooterMuzzleComp : MonoBehaviour { [SerializeField] [Min(1f)] private int _attackDamage = 10; [SerializeField] private AttackMethodType _attackMethodType = AttackMethodType.NormalBullet; [SerializeField] [Min(1)] private int _bulletTypeId = 501; [SerializeField] private Transform _muzzlePoint; [SerializeField] [Min(0.1f)] private float _bulletSpeed = 12f; public int AttackDamage => _attackDamage; public AttackMethodType AttackMethodType => _attackMethodType; public void OnInit(int attackDamage, AttackMethodType attackMethodType = AttackMethodType.NormalBullet, int bulletTypeId = 501) { _attackDamage = Mathf.Max(1, attackDamage); _attackMethodType = attackMethodType; _bulletTypeId = Mathf.Max(1, bulletTypeId); } public void OnReset() { _attackDamage = 1; _attackMethodType = AttackMethodType.None; _bulletTypeId = 501; } public bool Attack(Transform target) { return Attack(target, AttackPropertyType.None); } public bool Attack(Transform target, AttackPropertyType attackPropertyType) { if (_attackMethodType != AttackMethodType.NormalBullet) { return false; } if (target == null) { return false; } Transform spawnPoint = _muzzlePoint != null ? _muzzlePoint : transform; int bulletEntityId = GameEntry.Entity.GenerateSerialId(); BulletData bulletData = new BulletData( bulletEntityId, _bulletTypeId, spawnPoint.position, spawnPoint.rotation, target, _attackDamage, _bulletSpeed, attackPropertyType); GameEntry.Entity.ShowBullet(bulletData); return true; } } }