Exemplo n.º 1
0
        internal void StartReload()
        {
            Reloading = true;
            EventTriggerStateChanged(EventTriggers.Reloading, true);

            if (ActiveAmmoDef.AmmoDef.Const.MustCharge && !Comp.Session.ChargingWeaponsIndexer.ContainsKey(this))
            {
                ChargeReload();
            }
            else if (!ActiveAmmoDef.AmmoDef.Const.MustCharge)
            {
                if (System.ReloadTime > 0)
                {
                    CancelableReloadAction += Reloaded;
                    ReloadSubscribed        = true;
                    Comp.Session.FutureEvents.Schedule(CancelableReloadAction, null, (uint)System.ReloadTime);
                }
                else
                {
                    Reloaded();
                }
            }

            if (System.Session.MpActive && System.Session.IsServer)
            {
                System.Session.SendWeaponReload(this);
            }

            if (ReloadEmitter == null || ReloadSound == null || ReloadEmitter.IsPlaying)
            {
                return;
            }
            ReloadEmitter.PlaySound(ReloadSound, true, false, false, false, false, false);
        }
Exemplo n.º 2
0
        internal void StartReload()
        {
            Reloading = true;
            EventTriggerStateChanged(EventTriggers.Reloading, true);

            if (ActiveAmmoDef.AmmoDef.Const.MustCharge && !Comp.Session.ChargingWeaponsIndexer.ContainsKey(this))
            {
                ChargeReload();
            }
            else if (!ActiveAmmoDef.AmmoDef.Const.MustCharge)
            {
                var timeSinceShot = LastShootTick > 0 ? System.Session.Tick - LastShootTick : 0;
                var delayTime     = timeSinceShot <= System.Values.HardPoint.Loading.DelayAfterBurst ? System.Values.HardPoint.Loading.DelayAfterBurst - timeSinceShot : 0;
                var burstDelay    = ShowBurstDelayAsReload && delayTime > 0 && ShotsFired == 0;

                if (System.ReloadTime > 0 || burstDelay)
                {
                    CancelableReloadAction += Reloaded;
                    ReloadSubscribed        = true;
                    var reloadTime = (uint)(burstDelay ? System.ReloadTime + delayTime : System.ReloadTime);

                    ReloadEndTick = Comp.Session.Tick + reloadTime;

                    Comp.Session.FutureEvents.Schedule(CancelableReloadAction, null, reloadTime);
                }
                else
                {
                    Reloaded();
                }
            }

            if (System.Session.MpActive && System.Session.IsServer)
            {
                System.Session.SendWeaponReload(this);
            }

            if (ReloadEmitter == null || ReloadSound == null || ReloadEmitter.IsPlaying)
            {
                return;
            }
            ReloadEmitter.PlaySound(ReloadSound, true, false, false, false, false, false);
        }
Exemplo n.º 3
0
        public void StartReload(bool reset = false, bool isNewtorkUpdate = false)
        {
            if (reset)
            {
                State.Sync.Reloading = false;
            }

            if (State.Sync.Reloading)
            {
                return;
            }

            FinishBurst          = false;
            State.Sync.Reloading = true;

            var newAmmo = System.WeaponAmmoTypes[Set.AmmoTypeId];

            if (!ActiveAmmoDef.Equals(newAmmo))
            {
                ChangeAmmo(ref newAmmo);
            }

            if (Timings.AnimationDelayTick > Comp.Session.Tick && LastEvent != EventTriggers.Reloading)
            {
                Comp.Session.FutureEvents.Schedule(o => { StartReload(true); }, null, Timings.AnimationDelayTick - Comp.Session.Tick);
                return;
            }

            if (IsShooting)
            {
                StopShooting();
            }

            if ((State.Sync.CurrentMags == 0 && !ActiveAmmoDef.AmmoDef.Const.EnergyAmmo && !Comp.Session.IsCreative))
            {
                if (!OutOfAmmo)
                {
                    EventTriggerStateChanged(EventTriggers.OutOfAmmo, true);
                    OutOfAmmo = true;
                }
                State.Sync.Reloading = false;
            }
            else
            {
                if (OutOfAmmo)
                {
                    EventTriggerStateChanged(EventTriggers.OutOfAmmo, false);
                    OutOfAmmo = false;
                }

                uint delay;
                if (System.WeaponAnimationLengths.TryGetValue(EventTriggers.Reloading, out delay))
                {
                    Timings.AnimationDelayTick = Comp.Session.Tick + delay;
                    EventTriggerStateChanged(EventTriggers.Reloading, true);
                }

                if (ActiveAmmoDef.AmmoDef.Const.MustCharge && (State.Sync.CurrentMags > 0 || ActiveAmmoDef.AmmoDef.Const.EnergyAmmo || Comp.Session.IsCreative) && !Comp.Session.ChargingWeaponsCheck.ContainsKey(this))
                {
                    ChargeReload(isNewtorkUpdate);
                }
                else if (!ActiveAmmoDef.AmmoDef.Const.MustCharge)
                {
                    CancelableReloadAction += Reloaded;
                    ReloadSubscribed        = true;
                    Comp.Session.FutureEvents.Schedule(CancelableReloadAction, null, (uint)System.ReloadTime);
                    Timings.ReloadedTick = (uint)System.ReloadTime + Comp.Session.Tick;
                }

                if (ReloadEmitter == null || ReloadEmitter.IsPlaying)
                {
                    return;
                }
                if (ReloadSound == null)
                {
                    Log.Line($"ReloadSound is null");
                    return;
                }
                ReloadEmitter.PlaySound(ReloadSound, true, false, false, false, false, false);
            }
        }