public void ShootContinually()
 {
     if (playerAim.IsAiming && SelectedWeapon.shootsContinually)
     {
         SelectedWeapon.Shoot();
     }
 }
 public void ShootOnce()
 {
     if (playerAim.IsAiming)
     {
         SelectedWeapon.Shoot();
     }
 }
 // Start is called before the first frame update
 void Start()
 {
     rigidBody      = GetComponent <Rigidbody>();
     animator       = GetComponentInChildren <Animator>();
     targetRotation = Quaternion.Euler(transform.forward);
     foreach (var weapon in weapons)
     {
         weapon.SetActive(false);
     }
     SelectedWeapon.SetActive(true);
 }
 void FixedUpdate()
 {
     if (IsDead || Input == null || !Input.EnabledControl || BattleEntity.GameInPause)
     {
         return;
     }
     UpdateMoveCharacter();
     if (SelectedWeapon != null)
     {
         SelectedWeapon.FixedUpdate();
     }
 }
Example #5
0
        public void AttackNPC(GameManager gm, NPC npc)
        {
            double dmg;

            dmg = Rnd.NextDouble() * SelectedWeapon.AttackPower;
            npc.TakeDamage(gm, dmg);

            if (Rnd.NextDouble() < 1 - SelectedWeapon.Durability)
            {
                SelectedWeapon = null;
                gm.messages.Add("The weapon you were using " +
                                SelectedWeapon.ToString() + " just broke");
            }
        }
 public void ChangeWeapon(int direction)
 {
     SelectedWeapon.SetActive(false);
     weaponIndex += Math.Sign(direction);
     if (weaponIndex < 0)
     {
         weaponIndex = weapons.Length - 1;
     }
     else if (weaponIndex >= weapons.Length)
     {
         weaponIndex = 0;
     }
     SelectedWeapon.SetActive(true);
 }
Example #7
0
        /// <summary>
        ///     Disable and enable weapons
        /// </summary>
        /// <param name="selection"> The weapon that was selected </param>
        internal void ChangeWeapon(int selection)
        {
            if (selection > Weapons.Count - 1 || selection == SelectedWeapon)
            {
                return;
            }

            switchWeapons(selection);

            if (ShowLogs)
            {
                Debug.Log($"{gameObject.name} changed selected weapon has been changed to " +
                          $"number {SelectedWeapon.ToString()}: {CurrentWeapon.gameObject.name}");
            }
        }
Example #8
0
    private void Update()
    {
        /*
         * Weapon firing
         */
        if (Input.GetButton("Fire") && Commons.PlayerHealth.IsAlive)
        {
            //Player does not hold a weapon, use fallback if available
            if (SelectedWeapon == null || (SelectedWeapon.Durability == 0 && !Cheats.InfiniteAmmo))
            {
                if (FallbackWeaponInstance.CanFire(ignoreDurability: true))
                {
                    FallbackWeaponInstance.Fire(this.GetPlayer().GetComponent <WeaponShooterBase>());
                    LastFireTime = DateTime.Now;
                }
            }

            //Player has weapon. Fire it if it can be fired
            else
            {
                if (SelectedWeapon.CanFire(ignoreDurability: false))
                {
                    SelectedWeapon.Fire(this.GetPlayer().GetComponent <WeaponShooterBase>());
                    LastFireTime = DateTime.Now;
                }
            }
        }

        /*
         * Switch weapon with button
         */
        if (Input.GetButtonDown("QuickSwitchWeapon"))
        {
            SelectedWeaponSlot = (SelectedWeaponSlot + 1) % MAX_WEAPON_SLOTS;
        }
        if (Input.GetButtonDown("SwitchToWeapon1"))
        {
            SelectedWeaponSlot = 0;
        }
        if (Input.GetButtonDown("SwitchToWeapon2"))
        {
            SelectedWeaponSlot = 1;
        }
    }
    /// <summary> Update Input </summary>
    private void UpdateInput()
    {
        //Hands(Weapon) input logic
        if (Input.Shot)
        {
            SelectedWeapon.Shot(DirectionToAim);
        }

        if (Input.ShotPressed)
        {
            SelectedWeapon.ShotPressed(DirectionToAim);
        }

        if (Input.Reload && !InAir)
        {
            SelectedWeapon.Reload();
        }

        if (Input.NextGun)
        {
            SelectNextWeapon();
        }

        if (Input.Interaction)
        {
            Interaction();
        }

        //Start jump logic
        if (Input.Jump && !InAir)
        {
            if (GetRenderer.isVisible)
            {
                SoundController.PlaySound(JumpSound);
            }
            Animator.SetTrigger(C.InAir);
            RB.velocity = new Vector2(RB.velocity.x, 0);
            RB.AddForce(new Vector2(0, Description.JumpForce), ForceMode2D.Impulse);
        }
    }
Example #10
0
    void Start()
    {
        _wallLine = -100;

        _selectedWeapon = GameObject.Find("SelectedWeapon").GetComponent <SelectedWeapon>();
    }
Example #11
0
 void Start()
 {
     m_Player = GameObject.FindGameObjectWithTag("Player");
     m_SelectedWeaponScript = m_Player.GetComponent<SelectedWeapon>();
 }
Example #12
0
        /// <summary>
        /// Main update loop that will automatically create and delete black knight weapons if needed
        /// </summary>
        /// <param name="createWeapon">If it should automatically create the weapon</param>
        /// <param name="deleteShield">If it should automatically delete the shield</param>
        public void UpdateLoop(bool createWeapon, bool deleteShield)
        {
            bool CurrentLoaded = Loaded;

            if (CurrentLoaded)
            {
                bool IsBlackKnightDead  = SelectedWeapon.IsConditionSatisfied();
                bool IsBlackKnightAlive = !IsBlackKnightDead;
                bool JustLoaded         = !PreviousLoaded && CurrentLoaded;

                /**
                 * If the black knight is still alive, we reset the state of the Weapon and Shield
                 * Only checks after the player just loaded back in because it is the only
                 * reliable moment
                 */
                if (JustLoaded && IsBlackKnightAlive)
                {
                    DeathProcessed = false;
                }

                /**
                 * Only run logic when the black is dead and only run that logic once,
                 * until the black knight is alive again
                 */
                if (IsBlackKnightDead && !DeathProcessed)
                {
                    // weapon
                    if (createWeapon)
                    {
                        bool needsToCreate = !DarkSouls.FindBlackKnightWeapon(SelectedWeapon);

                        if (needsToCreate)
                        {
                            /**
                             * If the black knight is dead, the player doesn't have the
                             * weapon and we didn't already gave it, then we give it
                             */
                            CreateWeapon();
                        }
                    }

                    // shield
                    if (deleteShield)
                    {
                        bool needsToDelete = DarkSouls.FindBlackKnightWeapon(BlackKnightShield);

                        if (needsToDelete)
                        {
                            /**
                             * If the black knight is dead and the player has the shield
                             * so we need to delete it
                             */
                            DeleteShield();
                        }
                    }

                    // only execute this once per black knight death
                    DeathProcessed = true;
                }
            }

            PreviousLoaded = CurrentLoaded;
        }
Example #13
0
 public void ReloadWeapon()
 {
     SelectedWeapon.Reload();
 }