implement reloading time - all weapons have it set to 0, except rockets

This commit is contained in:
in0finite 2020-12-20 22:27:29 +01:00
parent 00a95beb66
commit 9ee8f0dfac
4 changed files with 29 additions and 4 deletions

View file

@ -128,6 +128,7 @@ MonoBehaviour:
drawLineFromGun: 0
projectilePrefab: {fileID: 8038540346792760480, guid: 858b1226127ef9f4e8d16c9610e691b6,
type: 3}
projectileReloadTime: 2.5
--- !u!114 &114529712737653322
MonoBehaviour:
m_ObjectHideFlags: 0

View file

@ -369,7 +369,10 @@ namespace SanAndreasUnity.Behaviours
this.FiresProjectile = s_weaponsUsingProjectile.Contains(this.Data.modelId1);
if (this.FiresProjectile)
{
this.ProjectilePrefab = WeaponsSettings.projectilePrefab;
this.ReloadTime = WeaponsSettings.projectileReloadTime;
}
}
@ -524,6 +527,8 @@ namespace SanAndreasUnity.Behaviours
public GameObject ProjectilePrefab { get; set; }
public float ReloadTime { get; set; } = 0;
// TODO: this function should be removed, and new one should be created: OnAnimsUpdated
public virtual void UpdateAnimWhileHolding ()

View file

@ -110,6 +110,9 @@ namespace SanAndreasUnity.Behaviours {
public bool rotatePlayerInDirectionOfAiming = true;
private float m_timeSinceStartedReloading = 0;
void Awake () {
@ -161,17 +164,31 @@ namespace SanAndreasUnity.Behaviours {
}
// reload weapon ammo clip
bool isReloadingNow = false;
if (NetStatus.IsServer)
{
if (CurrentWeapon != null) {
if (CurrentWeapon.AmmoClipSize > 0 && CurrentWeapon.AmmoInClip <= 0) {
int amountToRefill = Mathf.Min (CurrentWeapon.AmmoClipSize, CurrentWeapon.AmmoOutsideOfClip);
CurrentWeapon.AmmoInClip = amountToRefill;
CurrentWeapon.AmmoOutsideOfClip -= amountToRefill;
if (CurrentWeapon.AmmoClipSize > 0 && CurrentWeapon.AmmoInClip <= 0 && CurrentWeapon.AmmoOutsideOfClip > 0)
{
isReloadingNow = true;
m_timeSinceStartedReloading += Time.deltaTime;
if (m_timeSinceStartedReloading >= CurrentWeapon.ReloadTime)
{
m_timeSinceStartedReloading = 0;
int amountToRefill = Mathf.Min(CurrentWeapon.AmmoClipSize, CurrentWeapon.AmmoOutsideOfClip);
CurrentWeapon.AmmoInClip = amountToRefill;
CurrentWeapon.AmmoOutsideOfClip -= amountToRefill;
}
}
}
}
if (!isReloadingNow)
m_timeSinceStartedReloading = 0;
}
void LateUpdate_jdghrjgjr()
@ -304,6 +321,7 @@ namespace SanAndreasUnity.Behaviours {
this.currentWeaponSlot = slotIndex;
m_frameWhenSwitchedWeapon = Time.frameCount;
m_timeSinceStartedReloading = 0;
if (NetStatus.IsServer)
m_ped.StopFiring ();

View file

@ -51,6 +51,7 @@ namespace SanAndreasUnity.Behaviours.Weapons
public bool drawLineFromGun = false;
public GameObject projectilePrefab;
public float projectileReloadTime = 3f;
public static WeaponsManager Instance { get; private set; }