コード例 #1
0
ファイル: Character.cs プロジェクト: Matodor/TeeSharp
        protected override bool CanFire()
        {
            var fullAuto = ActiveWeapon == Weapon.Grenade ||
                           ActiveWeapon == Weapon.Shotgun ||
                           ActiveWeapon == Weapon.Laser;

            var willFire = InputCount.Count(LatestPrevInput.Fire, LatestInput.Fire).Presses != 0 ||
                           fullAuto && (LatestInput.Fire & 1) != 0 && Weapons[(int)ActiveWeapon].Ammo != 0;

            if (!willFire)
            {
                return(false);
            }

            if (Weapons[(int)ActiveWeapon].Ammo == 0)
            {
                ReloadTimer = 125 * Server.TickSpeed / 1000;
                if (LastNoAmmoSound + Server.TickSpeed <= Server.Tick)
                {
                    GameContext.CreateSound(Position, Sound.WeaponNoAmmo);
                    LastNoAmmoSound = Server.Tick;
                }
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: Character.cs プロジェクト: moien007/TeeSharp
        protected virtual bool CanFire()
        {
            var fullAuto = ActiveWeapon == Weapon.GRENADE ||
                           ActiveWeapon == Weapon.SHOTGUN ||
                           ActiveWeapon == Weapon.RIFLE;

            var willFire = InputCount.Count(LatestPrevInput.Fire, LatestInput.Fire).Presses != 0 ||
                           fullAuto && (LatestInput.Fire & 1) != 0 && Weapons[(int)ActiveWeapon].Ammo != 0;

            if (!willFire)
            {
                return(false);
            }

            if (Weapons[(int)ActiveWeapon].Ammo == 0)
            {
                ReloadTimer = 125 * Server.TickSpeed / 1000;
                if (LastNoAmmoSound + Server.TickSpeed <= Server.Tick)
                {
                    GameContext.CreateSound(Position, Sound.WEAPON_NOAMMO);
                    LastNoAmmoSound = Server.Tick;
                }
                return(false);
            }

            return(true);
        }
コード例 #3
0
ファイル: Character.cs プロジェクト: Matodor/TeeSharp
        protected override void HandleWeaponSwitch()
        {
            var wantedWeapon = ActiveWeapon;

            if (QueuedWeapon != (Weapon)(-1))
            {
                wantedWeapon = QueuedWeapon;
            }

            var next = InputCount.Count((int)LatestPrevInput.NextWeapon,
                                        (int)LatestInput.NextWeapon).Presses;
            var prev = InputCount.Count((int)LatestPrevInput.PreviousWeapon,
                                        (int)LatestInput.PreviousWeapon).Presses;

            if (next < 128)
            {
                while (next != 0)
                {
                    wantedWeapon = (Weapon)((int)(wantedWeapon + 1) % (int)Weapon.NumWeapons);
                    if (Weapons[(int)wantedWeapon].Got)
                    {
                        next--;
                    }
                }
            }

            if (prev < 128)
            {
                while (prev != 0)
                {
                    wantedWeapon = wantedWeapon - 1 < 0
                        ? Weapon.NumWeapons - 1
                        : wantedWeapon - 1;
                    if (Weapons[(int)wantedWeapon].Got)
                    {
                        prev--;
                    }
                }
            }

            if (LatestInput.WantedWeapon != 0)
            {
                wantedWeapon = (Weapon)(Input.WantedWeapon - 1);
            }

            if (wantedWeapon >= 0 &&
                wantedWeapon < Weapon.NumWeapons &&
                wantedWeapon != ActiveWeapon &&
                Weapons[(int)wantedWeapon].Got)
            {
                QueuedWeapon = wantedWeapon;
            }

            DoWeaponSwitch();
        }