public virtual void Aggrevate()
    {
        if (_aiHealth.IsDead)
        {
            return;
        }

        //Move the last known location to the players position when the player shoots.
        _lastKnownLocation.transform.position = _player.position;

        _isAggrevated = true;

        if (stateMachine == null)
        {
            stateMachine = new AIStateMachine(this);
            stateMachine.RegisterState(new AIDeathState(this));
            stateMachine.RegisterState(new AIIdleState(this));
            stateMachine.RegisterState(new AICombatState(this));
            stateMachine.RegisterState(new AISearchForPlayerState(this));
            stateMachine.RegisterState(new AICheckPlayerState(this));
            stateMachine.RegisterState(new AIMeleeState(this));

            if (_startingWeapon)
            {
                RaycastWeapon weapon = Instantiate(_startingWeapon.Weapon);

                _aiWeapon = GetComponent <AIWeapons>();
                _aiWeapon.EquipWeapon(weapon);
            }
        }

        stateMachine.ChangeState(AiStateId.CombatState);
    }
    void DetachMagazine()
    {
        RaycastWeapon weapon = activeWeapon.GetActiveWeapon();

        magazineHand = Instantiate(weapon.magazine, leftHand, true);
        weapon.magazine.SetActive(false);
    }
Exemple #3
0
    // Player
    private void OnTriggerStay(Collider other)
    {
        ActiveWeapon activeWeapon = other.gameObject.GetComponent <ActiveWeapon>();

        if (activeWeapon && activeWeapon.PickupWeapon)
        {
            if (!activeWeapon.weapon)
            {
                RaycastWeapon newWeapon = Instantiate(weaponFab);
                activeWeapon.Equip(newWeapon);
                GameEvents.events.CallUpdateAmmo();
            }

            if (activeWeapon.weapon.weaponName != weaponName)
            {
                RaycastWeapon newWeapon = Instantiate(weaponFab);
                activeWeapon.Equip(newWeapon);
                GameEvents.events.CallUpdateAmmo();
            }

            if (activeWeapon.weapon.weaponName == weaponName)
            {
                activeWeapon.weapon.AddAmmo(amountToAdd);
                GameEvents.events.CallUpdateAmmoDelayed(0.05f);
            }
            GameEvents.events.CallUpdateAmmo();

            Destroy(gameObject);
        }
    }
    public void DropWeapon()
    {
        //Only runs if we have a weapon to drop
        if (_currentWeapon)
        {
            //removes the parentness
            _currentWeapon.transform.SetParent(null);
            //Enables the collider
            _currentWeapon.gameObject.GetComponent <BoxCollider>().enabled = true;
            //Adds a rigidbody
            if (_currentWeapon.gameObject.GetComponent <Rigidbody>())
            {
                Destroy(_currentWeapon.gameObject);
            }

            _currentWeapon.gameObject.AddComponent <Rigidbody>();

            NavMeshHit hit;
            NavMesh.SamplePosition(transform.position, out hit, 5.0f, ~0);
            //Spawns ammo for the gun, if applicable
            if (!_currentWeapon.IsMelee)
            {
                _currentWeapon.Config.SpawnAmmo(hit.position, 10);
            }
            //Sets the current weapon to null
            _currentWeapon = null;
            _weaponIK.SetWeaponTransform(null);
        }
    }
 // Start is called before the first frame update
 void Start()
 {
     mainCamera       = Camera.main;
     Cursor.visible   = false;
     Cursor.lockState = CursorLockMode.Locked;
     weapon           = GetComponentInChildren <RaycastWeapon>();
 }
Exemple #6
0
    void DetachMagazine()
    {
        var           leftHand = animator.GetBoneTransform(HumanBodyBones.LeftHand);
        RaycastWeapon weapon   = currentWeapon;

        magazineHand = Instantiate(weapon.magazine, leftHand, true);
        weapon.magazine.SetActive(false);
    }
Exemple #7
0
 public void OnRaycastHit(RaycastWeapon weapon)
 {
     health -= weapon.damage;
     if (health <= 0)
     {
         Die();
     }
 }
Exemple #8
0
 public void RecDamage(RaycastWeapon weapon)
 {
     if (Destructable)
     {
         health -= weapon.damage;
         DestroySelf();
     }
 }
    void Start()
    {
        RaycastWeapon existingWeapon = GetComponentInChildren <RaycastWeapon>();

        if (existingWeapon)
        {
            Equip(existingWeapon);
        }
    }
Exemple #10
0
 public override void Use(GameObject user, int index)
 {
     if (user.CompareTag("Player"))
     {
         //Instantiate the weapon and equip it
         RaycastWeapon weapon = Instantiate(_weapon);
         user.GetComponent <ActiveWeapon>().Equip(weapon);
     }
 }
 private void OnTriggerStay(Collider other)
 {
     activeWeapon = other.gameObject.GetComponent <ActiveWeapon>();
     if (activeWeapon && Input.GetButtonDown("Equip"))
     {
         RaycastWeapon newWeapon = Instantiate(weaponPrefab);
         activeWeapon.Equip(newWeapon);
     }
 }
Exemple #12
0
    public bool IsFiring()
    {
        RaycastWeapon currentWeapon = GetActiveWeapon();

        if (!currentWeapon)
        {
            return(false);
        }
        return(currentWeapon.isFiring);
    }
Exemple #13
0
 public void DropWeapon()
 {
     if (currentWeapon)
     {
         currentWeapon.transform.SetParent(null);
         currentWeapon.gameObject.GetComponent <BoxCollider>().enabled = true;
         currentWeapon.gameObject.AddComponent <Rigidbody>();
         currentWeapon = null;
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        weaponHandler = GetComponent <Aiming>();
        equipment     = GetComponent <Equipment>();
        RaycastWeapon existingWeapon = GetComponentInChildren <RaycastWeapon>();

        if (existingWeapon)
        {
            Equip(existingWeapon);
        }
    }
Exemple #15
0
 // Start is called before the first frame update
 void Start()
 {
     // _rb = GetComponent<Rigidbody>();
     _cc              = GetComponent <CharacterController>();
     Cursor.visible   = false;
     Cursor.lockState = CursorLockMode.Confined;
     _anim            = GetComponent <Animator>();
     isDancing        = false;
     weapon           = GetComponentInChildren <RaycastWeapon>();
     // _rb.isKinematic =
 }
 public void Equip(RaycastWeapon newWeapon)
 {
     weapon = newWeapon;
     weapon.raycastDestination      = crossHairTarget;
     weapon.transform.parent        = weaponParent;
     weapon.transform.localPosition = Vector3.zero;
     weapon.transform.localRotation = Quaternion.identity;
     rigController.Play("equip_" + weapon.weaponName);
     hasWeapon = true;
     AlignCamerasToWeapon(newWeapon);
 }
Exemple #17
0
 public void DropWeapon()
 {
     //Drop the current weapon onto the floor
     if (_weapon)
     {
         _weapon.transform.SetParent(null);
         _weapon.gameObject.GetComponent <BoxCollider>().enabled = true;
         _weapon.gameObject.AddComponent <Rigidbody>();
         _weapon = null;
     }
 }
Exemple #18
0
    void AttachMagazine()
    {
        RaycastWeapon weapon = currentWeapon;

        weapon.magazine.SetActive(true);
        Destroy(magazineHand);
        weapon.ammoCount = weapon.clipSize;
        animator.ResetTrigger("reload_weapon");

        isReloading = false;
    }
    private void OnTriggerEnter(Collider other)
    {
        ActiveWeapon activeWeapon = other.gameObject.GetComponent <ActiveWeapon>();

        if (activeWeapon)
        {
            RaycastWeapon newWeapon = Instantiate(weaponPrefab);
            activeWeapon.Equip(newWeapon);
        }

        Destroy(gameObject);
    }
Exemple #20
0
    public void OnRaycastHit(RaycastWeapon weapon, Vector3 direction, float force)
    {
        health.TakeDamage(weapon.damage, direction, force);

        if (transform.GetComponent <PlayerController>())
        {
            health.SpawnBloodEffect(transform.position + new Vector3(0, 2f, 0));
        }
        else
        {
            health.SpawnBloodEffect(transform.position);
        }
    }
    void AttachMagazine()
    {
        RaycastWeapon weapon = activeWeapon.GetActiveWeapon();

        weapon.magazine.SetActive(true);
        Destroy(magazineHand);
        weapon.ammoCount = weapon.clipSize;
        rigcontroller.ResetTrigger("reload_weapon");

        ammoWidget.Refresh(weapon.ammoCount);

        isReloading = false;
    }
Exemple #22
0
    // Start is called before the first frame update
    void Start()
    {
        _anim      = GetComponent <Animator>();
        _inventory = GetComponent <Inventory>();

        if (_startingWeapon)
        {
            RaycastWeapon weapon = Instantiate(_startingWeapon);

            Equip(weapon);

            _PlayerUI.UpdateAmmoUI(_weapon.ClipAmmo, _weapon.Config.ClipSize, _weapon.TotalAmmo);
        }
    }
Exemple #23
0
    void Start()
    {
        reload = GetComponent <ReloadWeapon>();
        RaycastWeapon existingWeapon = GetComponentInChildren <RaycastWeapon>();

        if (existingWeapon)
        {
            Equip(existingWeapon);
        }

        //TESTING
        btnCountChecker  = GameObject.FindGameObjectWithTag("ScriptHolder").GetComponent <UiButtonFuctionsScript>();
        desktopControlls = GameObject.FindGameObjectWithTag("ScriptHolder").GetComponent <DekstopControlls>();
    }
Exemple #24
0
 public void CheckHud()
 {
     if(currentWeapon.GetComponent<RaycastWeapon>() == currentWeapon.GetComponent<RaycastWeapon>()){
         rayCastClass = currentWeapon.GetComponent<RaycastWeapon>();
         ammoPool = string.Format("{0}", rayCastClass.ammoPool);
         currentAmmo = string.Format("{0}",rayCastClass.loadedMagazine);
     }
     else{
         projectileClass = currentWeapon.GetComponent<ProjectileWeapon>();
         ammoPool = string.Format("{0}", projectileClass.ammoPool);
         currentAmmo = string.Format("{0}", projectileClass.loadedMagazine);
     }
     SetHud();
 }
    private void AlignCamerasToWeapon(RaycastWeapon wpn)
    {
        Transform sight = wpn.transform.Find("Sight");

        if (!sight)
        {
            Debug.LogWarning("No 'Sight' object inside of weapon!");
        }
        else
        {
            characterAiming.aimFarVirtualCamera.Follow   = sight;
            characterAiming.aimCloseVirtualCamera.Follow = sight;
            print("Cameras attached");
        }
    }
    private void Update()
    {
        if (_health.IsDead)
        {
            return;
        }
        if (!_isWeaponActive)
        {
            return;
        }
        if (!_currentWeapon)
        {
            return;
        }

        //Generates a target to shoot at with a slight bit of added inaccuracy
        if (_currentTarget && _currentWeapon)
        {
            Vector3 target = _currentTarget.position + _weaponIK._offset;
            target += UnityEngine.Random.insideUnitSphere * _inaccuracy;
            _currentWeapon.UpdateWeapon(target);
        }

        //Stores the current bullets
        if (_currentWeapon != null)
        {
            _AiClipBullets  = _currentWeapon.ClipAmmo;
            _AiTotalBullets = _currentWeapon.TotalAmmo;
        }


        //Should the AI switch to melee
        if (_AiClipBullets == 0 && _AiTotalBullets == 0 && !_usingMelee)
        {
            //Melee
            _usingMelee = true;

            //Instantiate the weapon
            RaycastWeapon meleeweapon = Instantiate(_meleeWeapon);
            //Equip the weapon
            EquipWeapon(meleeweapon);
            //Change to melee state
            if (GetComponent <AIAgent>().Aggrevated)
            {
                GetComponent <AIAgent>().stateMachine.ChangeState(AiStateId.Melee);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        RaycastWeapon weapon = activeWeapon.GetActiveWeapon();

        if (weapon)
        {
            if (Input.GetKeyDown(KeyCode.R) || weapon.ammoCount <= 0)
            {
                rigcontroller.SetTrigger("reload_weapon");
                isReloading = true;
            }
            if (weapon.isFiring)
            {
                ammoWidget.Refresh(weapon.ammoCount);
            }
        }
    }
    void Start()
    {
        characterAnimation = GetComponent <CharacterAnimation>();
        characterAiming    = GetComponent <CharacterAiming>();

        RaycastWeapon existingWeapon = GetComponentInChildren <RaycastWeapon>();

        if (existingWeapon)
        {
            Equip(existingWeapon);
            AlignCamerasToWeapon(existingWeapon);
            hasWeapon = true;
        }
        else
        {
            hasWeapon = false;
        }
    }
    public void EquipWeapon(RaycastWeapon weapon)
    {
        //Destroys the current weapon if there is one
        if (_currentWeapon)
        {
            Destroy(_currentWeapon.gameObject);
        }

        //Sets all the details for the current weapon
        _currentWeapon = weapon;
        _currentWeapon.transform.SetParent(transform, false);
        _sockets.Attach(weapon.transform, MeshSockets.SocketID.RightHand);
        _weaponIK.SetAimTransform(_currentWeapon.RaycastOrigin);
        _weaponIK.SetWeaponTransform(_currentWeapon.transform);
        _isWeaponActive = true;
        _currentWeapon.DamageMultiplier = _damageMultiplier;
        _currentWeapon.Setup();
    }
    public void Equip(RaycastWeapon newWeapon)
    {
        int weaponSlotIndex = (int)newWeapon.weaponSlot;
        var weapon          = GetWeapon(weaponSlotIndex);

        if (weapon)
        {
            Destroy(weapon.gameObject);
        }
        weapon = newWeapon;
        weapon.raycastDestination     = crossHairTarget;
        weapon.recoil.characterAiming = characterAiming;
        weapon.recoil.rigController   = rigController;
        weapon.transform.SetParent(weaponSlots[weaponSlotIndex], false);
        equipped_weapons[weaponSlotIndex] = weapon;

        SetActiveWeapon(newWeapon.weaponSlot);
        weaponEquiped = true;
        ammoWidget.Refresh(weapon.ammoCount);
    }
Exemple #31
0
 public void GetVariables(GameObject currentWeapon)
 {
     if(currentWeapon.GetComponent<RaycastWeapon>() == currentWeapon.GetComponent<RaycastWeapon>()){
         raycastClass = currentWeapon.GetComponent<RaycastWeapon>();
         upgradeVariables[0] = (int)raycastClass.fireRatePerMinute;
         upgradeVariables[1] = raycastClass.maxPool;
         upgradeVariables[2] = raycastClass.damage;
         upgradeVariables[3] = (int)raycastClass.xSpreadMax;
     }
     else{
         projectileClass = currentWeapon.GetComponent<ProjectileWeapon>();
         upgradeVariables[0] = (int)projectileClass.fireRatePerMinute;
         upgradeVariables[1] = projectileClass.maxPool;
         upgradeVariables[2] = (int)projectileClass.fireSpeed;
         upgradeVariables[3]= projectileClass.grenade.GetComponent<ExplosiveProjectileScript>().enemyDamage;
         upgradeVariables[4]= (int)projectileClass.grenade.GetComponent<ExplosiveProjectileScript>().radius;
         //upgradeVariables[2] = projectileClass.power;
         //upgradeVariables[3] = projectileClass
     }
 }
    public void Equip(RaycastWeapon newWeapon)
    {
        int weaponSlotIndex = (int)newWeapon.weaponSlot;
        var weapon          = GetWeapon(weaponSlotIndex);

        if (weapon)
        {
            Destroy(weapon.gameObject);
        }
        weapon = newWeapon;
        weapon.raycastDestination   = crossHairTarget;
        weapon.recoil.aimCamera     = aimCamera;
        weapon.recoil.rigController = rigController;
        weapon.transform.SetParent(weaponSlots[weaponSlotIndex], false);
        //weapon.transform.localPosition = Vector3.zero;
        //weapon.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
        weaponHandler.LookForWeapon(weapon);
        equippedWeapons[weaponSlotIndex] = weapon;
        SetActiveWeapon(newWeapon.weaponSlot);
    }
Exemple #33
0
 void Start()
 {
     currentWeapon = GameObject.FindGameObjectWithTag("0");
     weaponScript = currentWeapon.GetComponent<RaycastWeapon>();
 }