Beispiel #1
0
        public void InterruptReload()
        {
            cancelReload = true;

            var reloadingWeapon = ReloadingWeapon.Create(GlobalTargets.OnlyServer, ReliabilityModes.ReliableOrdered);

            reloadingWeapon.Player            = player.entity;
            reloadingWeapon.WeaponId          = weapon.Id;
            reloadingWeapon.WeaponReloadState = false;
            reloadingWeapon.Send();

            //Send a command to set the ammo in magazine.
            var weaponReloaded = WeaponReloaded.Create(GlobalTargets.OnlyServer, ReliabilityModes.ReliableOrdered);

            weaponReloaded.Player           = weapon.Player;
            weaponReloaded.WeaponId         = weapon.Id;
            weaponReloaded.NewCurrentAmount = BeforeReload;
            weaponReloaded.Send();
        }
Beispiel #2
0
        /// <summary>
        /// Gets called whenever a weapon has finished reloading to set new amount in current-magazine.
        /// </summary>
        /// <param name="weaponReloaded"></param>
        public override void OnEvent(WeaponReloaded weaponReloaded)
        {
            var playerState = weaponReloaded.Player.GetState <IPlayer>();

            playerState.Weapons[weaponReloaded.WeaponId].CurrentAmmoInMagazine = weaponReloaded.NewCurrentAmount;
        }
Beispiel #3
0
        public IEnumerator Reload()
        {
            if (weapon.CurrentAmmoInMagazine == weapon.MagazineSize || weapon.EntireAmmo <= 0 || weapon.IsReloading)
            {
                yield break;
            }

            BeforeReload = weapon.CurrentAmmoInMagazine;
            cancelReload = false;

            if (cancelReload)
            {
                yield break;
            }

            //Send a command to notify that this weapon is reloading.
            var reloadingWeapon = ReloadingWeapon.Create(GlobalTargets.OnlyServer, ReliabilityModes.ReliableOrdered);

            reloadingWeapon.Player            = weapon.Player;
            reloadingWeapon.WeaponReloadState = true;
            reloadingWeapon.WeaponId          = weapon.Id;
            reloadingWeapon.Send();

            if (cancelReload)
            {
                yield break;
            }

            //Wait
            yield return(new WaitForSeconds(weapon.ReloadTime - .25f));

            if (cancelReload)
            {
                yield break;
            }

            //Send a command to notify that this weapon has reloaded.
            reloadingWeapon                   = ReloadingWeapon.Create(GlobalTargets.OnlyServer, ReliabilityModes.ReliableOrdered);
            reloadingWeapon.Player            = weapon.Player;
            reloadingWeapon.WeaponReloadState = false;
            reloadingWeapon.WeaponId          = weapon.Id;
            reloadingWeapon.Send();

            if (cancelReload)
            {
                yield break;
            }

            //Wait
            yield return(new WaitForSeconds(.25f));

            if (cancelReload)
            {
                yield break;
            }

            //Send a command to set the ammo in magazine.
            var weaponReloaded = WeaponReloaded.Create(GlobalTargets.OnlyServer, ReliabilityModes.ReliableOrdered);

            weaponReloaded.Player           = weapon.Player;
            weaponReloaded.WeaponId         = weapon.Id;
            weaponReloaded.NewCurrentAmount = weapon.EntireAmmo >= weapon.MagazineSize ? weapon.MagazineSize : weapon.EntireAmmo;
            weaponReloaded.Send();
        }