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.
210 lines
5.5 KiB
210 lines
5.5 KiB
using System; |
|
using System.Collections; |
|
using Ability; |
|
using Ai; |
|
using Equip; |
|
using UnityEngine; |
|
|
|
namespace Player |
|
{ |
|
public class ShootingManager : MonoBehaviour |
|
{ |
|
|
|
[SerializeField] private GameObject[] _originalShoota; |
|
[SerializeField] private GameObject[] _additinalShoota; |
|
[SerializeField] private GameObject _sideShoota; |
|
[SerializeField] private Shooting[] _allShotas; |
|
[SerializeField] private Bullet _ricochetBullet; |
|
|
|
[SerializeField] private float _reloadTime; |
|
[SerializeField] private float _animationOffset; |
|
[SerializeField] private MainCharacter _character; |
|
[SerializeField] private GameObject _shootFx; |
|
[SerializeField] private Transform _FXrotatingTransform; |
|
[SerializeField] private Vector3 _shootFxOffset; |
|
|
|
private float _reload; |
|
private float _currentTime; |
|
private bool _shoota; |
|
private GameObject _currentShoota; |
|
private GameObject _additionalCurrentShoota; |
|
public event Action ShootEvent; |
|
|
|
private void Start() |
|
{ |
|
_currentTime = _reload = _reloadTime; |
|
} |
|
|
|
private void FixedUpdate() |
|
{ |
|
if (_shoota || ( _character && _character.IsDead ) || _character && _character.GetState() != CharacterState.DEFAULT || |
|
GlobalsVar.gBoard != null && GlobalsVar.gBoard.DialogsCount > 0 || |
|
AiController.Instance.TargetingEnemies.Count <= 0) |
|
return; |
|
|
|
_currentTime -= Time.fixedDeltaTime; |
|
if (_currentTime <= 0) |
|
{ |
|
ShootPermamently(); |
|
} |
|
} |
|
|
|
public void ShootPermamently() |
|
{ |
|
if (_shoota || ( _character && _character.IsDead ) || _character && _character.GetState() != CharacterState.DEFAULT || |
|
GlobalsVar.gBoard != null && GlobalsVar.gBoard.DialogsCount > 0 || |
|
AiController.Instance.TargetingEnemies.Count <= 0) |
|
return; |
|
|
|
StopCoroutine(ShootCoroutine()); |
|
StartCoroutine(ShootCoroutine()); |
|
} |
|
|
|
private IEnumerator ShootCoroutine() |
|
{ |
|
if (ShootEvent != null) |
|
ShootEvent(); |
|
|
|
_shoota = true; |
|
|
|
yield return new WaitForSeconds(0.2f); |
|
yield return new WaitForSeconds(_animationOffset); |
|
|
|
if (_shootFx != null) |
|
{ |
|
var fx = Instantiate(_shootFx); |
|
fx.transform.position = _FXrotatingTransform.transform.position + _shootFxOffset; |
|
fx.transform.rotation = Quaternion.Euler(0, _FXrotatingTransform.transform.rotation.eulerAngles.y, 0); |
|
} |
|
|
|
if ((_character && _character.IsDead) || _character && _character.GetState() != CharacterState.DEFAULT || |
|
GlobalsVar.gBoard != null && GlobalsVar.gBoard.DialogsCount > 0 || |
|
AiController.Instance.TargetingEnemies.Count <= 0) |
|
{ |
|
_currentTime = _reload; |
|
_shoota = false; |
|
yield break; |
|
} |
|
|
|
foreach (var shoota in _allShotas) |
|
{ |
|
if (!shoota.isActiveAndEnabled) |
|
continue; |
|
shoota.Shoot(); |
|
} |
|
|
|
_shoota = false; |
|
|
|
_currentTime = _reload; |
|
} |
|
|
|
private void OnValidate() |
|
{ |
|
if (_FXrotatingTransform == null) |
|
_FXrotatingTransform = transform; |
|
} |
|
|
|
private void AddSpeed(float value) |
|
{ |
|
_reload -= value; |
|
} |
|
|
|
public void AddAbility(InGameAbType type, float value) |
|
{ |
|
switch (type) |
|
{ |
|
case InGameAbType.ADD_BULLET_AFTER: |
|
foreach (var shoota in _allShotas) |
|
{ |
|
shoota.Row++; |
|
} |
|
break; |
|
case InGameAbType.ADD_BULLET_45: |
|
_sideShoota.SetActive(true); |
|
break; |
|
case InGameAbType.ADD_BULLET_PARALLEL: |
|
_additionalCurrentShoota.SetActive(true); |
|
_currentShoota.SetActive(false); |
|
break; |
|
case InGameAbType.ADD_BULLET_RICOCHET: |
|
foreach (var shoota in _allShotas) |
|
{ |
|
shoota.Bullet = _ricochetBullet; |
|
} |
|
break; |
|
case InGameAbType.ADD_MINOR_SPEED: |
|
case InGameAbType.ADD_ATTACK_SPEED: |
|
AddSpeed(value); |
|
break; |
|
case InGameAbType.ADD_MINOR_DAMAGE: |
|
case InGameAbType.ADD_DAMAGE: |
|
foreach (var shoota in _allShotas) |
|
{ |
|
shoota.AddDamage(value); |
|
} |
|
break; |
|
case InGameAbType.ADD_HEADSHOT: |
|
foreach (var shoota in _allShotas) |
|
{ |
|
shoota.AddCritChance(value); |
|
} |
|
break; |
|
} |
|
} |
|
|
|
public void AddMainAbility(MainAbilityType type, float value) |
|
{ |
|
switch (type) |
|
{ |
|
case MainAbilityType.ADD_ATTACK_SPEED: |
|
foreach (var shoota in _allShotas) |
|
{ |
|
float val = value / 100f; |
|
AddSpeed(val); |
|
} |
|
break; |
|
case MainAbilityType.ADD_DAMAGE: |
|
foreach (var shoota in _allShotas) |
|
{ |
|
shoota.AddDamage(value); |
|
} |
|
break; |
|
} |
|
} |
|
|
|
public void ApplyEquip(EquipItem item) |
|
{ |
|
if (item.AddDamage > 0) |
|
{ |
|
foreach(var shoota in _allShotas) |
|
shoota.AddDamage(item.AddDamage); |
|
} |
|
|
|
if (item.AddSpeed > 0) |
|
{ |
|
_reloadTime = _reloadTime * item.AddSpeed; |
|
} |
|
|
|
if (item.AddCrit > 0) |
|
{ |
|
foreach (var shoota in _allShotas) |
|
shoota.AddCritChance(item.AddCrit); |
|
} |
|
|
|
if (item.DamageMult > 0) |
|
{ |
|
foreach (var shoota in _allShotas) |
|
shoota.SetMult(item.DamageMult); |
|
} |
|
} |
|
|
|
public void SetShoota(int p0) |
|
{ |
|
if (_currentShoota != null) |
|
_currentShoota.SetActive(false); |
|
_currentShoota = _originalShoota[p0]; |
|
_additionalCurrentShoota = _additinalShoota[p0]; |
|
_currentShoota.SetActive(true); |
|
} |
|
} |
|
}
|
|
|