You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.3 KiB
85 lines
2.3 KiB
using System; |
|
using Player; |
|
using UnityEngine; |
|
|
|
namespace Ai |
|
{ |
|
[Serializable] |
|
public class SequenceBullet |
|
{ |
|
public Bullet[] Bullets; |
|
} |
|
|
|
public class SequenceGun : Gun |
|
{ |
|
|
|
[SerializeField] private float _sequenceTime; |
|
[SerializeField] private AnimationCurve _burstShots; |
|
[SerializeField] private AnimationCurve _angle; |
|
[SerializeField] private AnimationCurve _bulletsInRow; |
|
[SerializeField] private SequenceBullet[] _bullets; |
|
|
|
private float _currentSequenceTime; |
|
private int _currentBulletSequence; |
|
|
|
protected override void Update() |
|
{ |
|
if (!CanShoot && GlobalsVar.gBoard.DialogsCount > 0) |
|
return; |
|
|
|
_currentSequenceTime += Time.deltaTime; |
|
if (_currentSequenceTime >= _sequenceTime) |
|
_currentSequenceTime = 0; |
|
|
|
_shotsPerBurst = (int)_burstShots.Evaluate(_currentSequenceTime); |
|
|
|
base.Update(); |
|
} |
|
|
|
protected override void Shoot() |
|
{ |
|
var row = _bulletsInRow.Evaluate(_currentSequenceTime); |
|
var angle = _angle.Evaluate(_currentSequenceTime); |
|
var currentBulletSeq = _bullets != null && _bullets.Length > 0 ? _bullets[_currentBulletSequence] : null; |
|
_currentBulletSequence++; |
|
if (_bullets == null || _currentBulletSequence > _bullets.Length - 1) |
|
_currentBulletSequence = 0; |
|
|
|
var currentBullet = 0; |
|
|
|
for (var i = 0; i < row; i++) |
|
{ |
|
var targetAngle = 0f; |
|
if (row > 0) |
|
{ |
|
var currentModify = i == (int) (i / row) ? 0 : i < i / row ? -i / row : i / row; |
|
targetAngle = angle * currentModify; |
|
} |
|
|
|
var bullet = _bullet; |
|
if (currentBulletSeq != null && currentBulletSeq.Bullets != null && currentBulletSeq.Bullets.Length > 0) |
|
{ |
|
bullet = currentBulletSeq.Bullets[currentBullet]; |
|
currentBullet++; |
|
if (currentBullet > currentBulletSeq.Bullets.Length - 1) |
|
currentBullet = 0; |
|
} |
|
|
|
CustomShoot(targetAngle, bullet); |
|
} |
|
} |
|
|
|
private void CustomShoot(float angle, Bullet bulletPrefab) |
|
{ |
|
var bullet = Instantiate(bulletPrefab); |
|
bullet.transform.position = transform.position; |
|
var direction = _toPlayer ? AiController.Instance.PlayerPosition : transform.forward; |
|
direction = Quaternion.Euler(new Vector3(0, angle, 0)) * direction; |
|
bullet.Init(direction, 0, 0, _toPlayer); |
|
|
|
string shootSound = GetShootSoundByBulletName(bullet.name); |
|
if (shootSound != "") |
|
SoundsManager.Instance.PlaySound(shootSound); |
|
} |
|
} |
|
}
|
|
|