Пример #1
0
 public void SetState(WeaponSyncValues sync)
 {
     sync.Heat          = Heat;
     sync.CurrentAmmo   = CurrentAmmo;
     sync.CurrentMags   = CurrentMags;
     sync.CurrentCharge = CurrentCharge;
     sync.Overheated    = Overheated;
     sync.Reloading     = Reloading;
     sync.Charging      = Charging;
 }
Пример #2
0
        internal void SyncWeapon(Weapon weapon, WeaponTimings timings, ref WeaponSyncValues weaponData, bool setState = true)
        {
            var comp   = weapon.Comp;
            var cState = comp.State.Value;
            var wState = weapon.State;

            var wasReloading = wState.Sync.Reloading;

            if (setState)
            {
                comp.CurrentHeat     -= weapon.State.Sync.Heat;
                cState.CurrentCharge -= weapon.State.Sync.CurrentCharge;


                weaponData.SetState(wState.Sync);

                comp.CurrentHeat     += weapon.State.Sync.Heat;
                cState.CurrentCharge += weapon.State.Sync.CurrentCharge;
            }

            comp.WeaponValues.Timings[weapon.WeaponId] = timings;
            weapon.Timings = timings;

            var hasMags = weapon.State.Sync.CurrentMags > 0 || IsCreative;
            var hasAmmo = weapon.State.Sync.CurrentAmmo > 0;

            var canReload = weapon.CanReload;

            if (!canReload)
            {
                weapon.ActiveAmmoDef = weapon.System.WeaponAmmoTypes[weapon.Set.AmmoTypeId];
            }

            if (canReload)
            {
                weapon.StartReload();
            }

            else if (wasReloading && !weapon.State.Sync.Reloading && hasAmmo)
            {
                if (!weapon.ActiveAmmoDef.AmmoDef.Const.MustCharge && weapon.ReloadSubscribed)
                {
                    weapon.ReloadSubscribed        = false;
                    weapon.CancelableReloadAction -= weapon.Reloaded;
                }

                weapon.EventTriggerStateChanged(EventTriggers.Reloading, false);
            }
            else if (wasReloading && weapon.State.Sync.Reloading && !weapon.ActiveAmmoDef.AmmoDef.Const.MustCharge)
            {
                if (weapon.ReloadSubscribed)
                {
                    weapon.ReloadSubscribed        = false;
                    weapon.CancelableReloadAction -= weapon.Reloaded;
                }

                comp.Session.FutureEvents.Schedule(weapon.Reloaded, null, weapon.Timings.ReloadedTick);
            }

            else if (weapon.ActiveAmmoDef.AmmoDef.Const.MustCharge && weapon.State.Sync.Reloading && !comp.Session.ChargingWeaponsCheck.ContainsKey(weapon))
            {
                weapon.ChargeReload(true);
            }

            if (weapon.State.Sync.Heat > 0 && !weapon.HeatLoopRunning)
            {
                weapon.HeatLoopRunning = true;
                var delay = weapon.Timings.LastHeatUpdateTick > 0 ? weapon.Timings.LastHeatUpdateTick : 20;
                comp.Session.FutureEvents.Schedule(weapon.UpdateWeaponHeat, null, delay);
            }
        }