Esempio n. 1
0
        private IEnumerator WaitForAttack(WeaponBehaviourScript weapon)
        {
            canAttack = false;
            int layerMask = GetLayerMask(weapon);

            switch (meleeShapeType)
            {
            case MeleeShapeType.BoxCast:
                ProcessRayCastHits(Physics2D.BoxCastAll(weapon.WeaponShootLocation, size, angle, direction.Equals(Vector2.zero) ? weapon.Direction : new Vector2(direction.x * weapon.Direction.x, direction.y), distance == 0.0f ? Mathf.Infinity : distance, layerMask), weapon);
                break;

            case MeleeShapeType.CircleCast:
                ProcessRayCastHits(Physics2D.CircleCastAll(weapon.WeaponShootLocation, radius, direction.Equals(Vector2.zero) ? weapon.Direction : direction, distance == 0.0f ? Mathf.Infinity : distance, layerMask), weapon);
                break;

            case MeleeShapeType.RayCast:
                ProcessRayCastHits(Physics2D.RaycastAll(weapon.WeaponShootLocation, direction.Equals(Vector2.zero) ? weapon.Direction : direction, distance == 0.0f ? Mathf.Infinity : distance, layerMask), weapon);
                break;

            case MeleeShapeType.OverlapCircle:
                ProcessColliderHits(Physics2D.OverlapCircleAll(weapon.WeaponShootLocation, radius, layerMask), weapon);
                break;

            case MeleeShapeType.OverlapBox:
                ProcessColliderHits(Physics2D.OverlapBoxAll(weapon.WeaponShootLocation, size, angle, layerMask), weapon);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            yield return(new WaitForSeconds(1.0f / attackRate));

            canAttack = true;
        }
Esempio n. 2
0
        private static int GetLayerMask(WeaponBehaviourScript weapon)
        {
            var weaponOwnerLayer = LayerMask.LayerToName(weapon.transform.parent.gameObject.layer);
            var layersToSkip     = new[] { weaponOwnerLayer };

            return(~LayerMask.GetMask(layersToSkip));
        }
Esempio n. 3
0
        protected override void SpawnProjectile(WeaponBehaviourScript weapon)
        {
            var projectile = Instantiate(weapon.WeaponData.ProjectileData.ProjectilePrefab,
                                         weapon.WeaponShootLocation, Quaternion.identity);

            // calculates the angle required to shoot towards the player
            if (weapon.transform.parent.CompareTag("Boss"))
            {
                var player = GameObject.FindWithTag("Player");
                var emu2   = GameObject.FindWithTag("Boss");

                var direction = player.transform.position - emu2.transform.position;
                var angleRads = Mathf.Atan2(direction.y, direction.x);
                var projDir   =
                    Vector2.ClampMagnitude(
                        new Vector2(weapon.Direction.x, (float)Math.Tan(angleRads) * weapon.Direction.x), 1.0f);
                projectile.GetComponent <ProjectileBehaviourScript>().Init(weapon.WeaponData.ProjectileData,
                                                                           projDir, !weapon.transform.parent.CompareTag("Player"));
            }
            else
            {
                projectile.GetComponent <ProjectileBehaviourScript>().Init(weapon.WeaponData.ProjectileData,
                                                                           weapon.Direction, !weapon.transform.parent.CompareTag("Player"));
            }

            projectile.SetActive(true);
        }
Esempio n. 4
0
 public override void Reload(WeaponBehaviourScript weapon)
 {
     if (canReload && weapon.CurrentMagazineAmmunition <= 0 && weapon.CurrentTotalAmmunition >= 1)
     {
         weapon.StartCoroutine(WaitForReload(weapon));
     }
 }
Esempio n. 5
0
        protected override void SpawnProjectile(WeaponBehaviourScript weapon)
        {
            GameObject projectile = Instantiate(weapon.WeaponData.ProjectileData.ProjectilePrefab, weapon.WeaponShootLocation, Quaternion.identity);

            projectile.GetComponent <ProjectileBehaviourScript>().Init(weapon.WeaponData.ProjectileData, weapon.Direction, !weapon.transform.parent.CompareTag("Player"));
            projectile.GetComponent <ProjectileBehaviourScript>().enabled = true;
            projectile.SetActive(true);
        }
Esempio n. 6
0
 public override void Shoot(WeaponBehaviourScript weapon)
 {
     if (canShoot && weapon.CurrentMagazineAmmunition >= 0)
     {
         canShoot = false;
         weapon.StartCoroutine(WaitForShot(weapon));
     }
 }
Esempio n. 7
0
 public override void Reload(WeaponBehaviourScript weapon)
 {
     if (canReload)
     {
         weapon.StartCoroutine(WaitForReload(weapon));
         weapon.GetComponent <AudioSource>()?.PlayOneShot(weapon.WeaponData.ReloadAudioClip);
     }
 }
Esempio n. 8
0
 public override void Reload(WeaponBehaviourScript weapon)
 {
     if (canReload && weapon.CurrentMagazineAmmunition < weapon.WeaponData.MagazineCapacity && weapon.CurrentTotalAmmunition >= 1)
     {
         weapon.StartCoroutine(WaitForReload(weapon));
         weapon.GetComponent <AudioSource>()?.PlayOneShot(weapon.WeaponData.ReloadAudioClip);
     }
 }
Esempio n. 9
0
 public override void Shoot(WeaponBehaviourScript weapon)
 {
     if (canShoot && weapon.CurrentMagazineAmmunition >= 1)
     {
         weapon.StartCoroutine(WaitForShot(weapon));
         weapon.GetComponent <AudioSource>()?.PlayOneShot(weapon.WeaponData.ShootAudioClip);
     }
 }
Esempio n. 10
0
 public override void Shoot(WeaponBehaviourScript weapon)
 {
     if (canAttack)
     {
         weapon.StartCoroutine(WaitForAttack(weapon));
         weapon.GetComponent <AudioSource>()?.PlayOneShot(weapon.WeaponData.ShootAudioClip);
     }
 }
Esempio n. 11
0
        private IEnumerator WaitForShot(WeaponBehaviourScript weapon)
        {
            canShoot = false;
            SpawnProjectile(weapon);
            weapon.CurrentMagazineAmmunition -= 1;
            yield return(new WaitForAndWhile(() => Input.GetKeyUp(KeyCode.G), 1.0f / weapon.WeaponData.FireRate)); //todo what if we change the keybinding?

            canShoot = true;
        }
Esempio n. 12
0
        private IEnumerator WaitForShot(WeaponBehaviourScript weapon)
        {
            canShoot = false;
            SpawnProjectile(weapon);
            weapon.CurrentMagazineAmmunition -= 1;
            yield return(new WaitForSeconds(1.0f / weapon.WeaponData.FireRate));

            canShoot = true;
        }
Esempio n. 13
0
        private IEnumerator WaitForShot(WeaponBehaviourScript weapon)
        {
            canShoot  = false;
            canReload = false;
            SpawnProjectile(weapon);
            weapon.CurrentMagazineAmmunition = 0;
            yield return(new WaitForSeconds(0.1f));

            canReload = true;
        }
Esempio n. 14
0
        protected virtual void SpawnProjectile(WeaponBehaviourScript weapon)
        {
            var projectile = Instantiate(weapon.WeaponData.ProjectileData.ProjectilePrefab,
                                         weapon.WeaponShootLocation, Quaternion.identity);

            // Make sure the weapon has a parent gameobject of this line is gonna cause a Nullptrexception
            projectile.GetComponent <ProjectileBehaviourScript>().Init(weapon.WeaponData.ProjectileData,
                                                                       weapon.Direction, !weapon.transform.parent.CompareTag("Player"));
            projectile.SetActive(true);
        }
Esempio n. 15
0
        private IEnumerator WaitForReload(WeaponBehaviourScript weapon)
        {
            canReload = false;
            canShoot  = false;
            yield return(new WaitForSeconds(weapon.WeaponData.ReloadTime));

            weapon.CurrentMagazineAmmunition = 1;
            weapon.CurrentTotalAmmunition   -= 1;
            canShoot  = true;
            canReload = true;
        }
Esempio n. 16
0
        private IEnumerator WaitForShot(WeaponBehaviourScript weapon)
        {
            canShoot  = false;
            canReload = false;
            SpawnProjectile(weapon);
            weapon.CurrentMagazineAmmunition -= 1;
            yield return(new WaitForAndWhile(() => Input.GetKeyUp(KeyCode.K), 1.0f / weapon.WeaponData.FireRate));

            canReload = true;
            canShoot  = true;
        }
Esempio n. 17
0
        protected override void SpawnProjectile(WeaponBehaviourScript weapon)
        {
            var throwable       = Instantiate(weapon.WeaponData.ProjectileData.ProjectilePrefab, weapon.WeaponShootLocation, Quaternion.identity);
            var throwableScript = throwable.GetComponent <ThrowableBehaviourScript>();

            if (throwableScript == null)
            {
                Destroy(throwable);
                throw new MissingComponentException("Required a ThrowableBehaviourScript Monobehaviour, but didn't find one!");
            }
            throwableScript.Init(weapon.WeaponData.ProjectileData, weapon.Direction);
        }
Esempio n. 18
0
 public void AddWeaponToInventorySlot(WeaponBehaviourScript weaponScript)
 {
     _weaponScript = weaponScript;
     _image.sprite = _weaponScript.gameObject.GetComponent <SpriteRenderer>().sprite;
     if (_weaponScript.WeaponData.WeaponName is WeaponName.Grenade)
     {
         _text.text = _weaponScript.CurrentMagazineAmmunition.ToString();
     }
     else
     {
         _text.text = _weaponScript.CurrentMagazineAmmunition + "/" + _weaponScript.CurrentTotalAmmunition;
     }
 }
Esempio n. 19
0
 protected override void SpawnProjectile(WeaponBehaviourScript weapon)
 {
     for (int i = 0; i < numProjectiles; i++)
     {
         var angle = -(spread / 2) + i * (spread / (numProjectiles - 1));
         angle = (float)(Math.PI / 180) * angle;
         var projectile = Instantiate(weapon.WeaponData.ProjectileData.ProjectilePrefab, weapon.WeaponShootLocation, Quaternion.identity);
         var projDir    =
             Vector2.ClampMagnitude(new Vector2(weapon.Direction.x, (float)Math.Tan(angle) * weapon.Direction.x), 1.0f);
         projectile.GetComponent <ProjectileBehaviourScript>().Init(weapon.WeaponData.ProjectileData, projDir, !weapon.transform.parent.CompareTag("Player"));
         projectile.SetActive(true);
     }
 }
Esempio n. 20
0
        private IEnumerator WaitForReload(WeaponBehaviourScript weapon)
        {
            canReload = false;
            canShoot  = false;
            int reloadAmount = weapon.WeaponData.MagazineCapacity - weapon.CurrentMagazineAmmunition;

            reloadAmount = Math.Min(reloadAmount, weapon.CurrentTotalAmmunition);
            yield return(new WaitForSeconds(weapon.WeaponData.ReloadTime));

            weapon.CurrentTotalAmmunition    -= reloadAmount;
            weapon.CurrentMagazineAmmunition += reloadAmount;
            canShoot  = true;
            canReload = true;
        }
Esempio n. 21
0
        private InventoryIndex?GetInventoryIndexByWeapon(WeaponBehaviourScript weaponScript)
        {
            if (_weaponSlots[InventoryIndex.First] != null && _weaponSlots[InventoryIndex.First].WeaponData.WeaponName.Equals(weaponScript.WeaponData.WeaponName))
            {
                return(InventoryIndex.First);
            }
            else if (_weaponSlots[InventoryIndex.Second] != null && _weaponSlots[InventoryIndex.Second].WeaponData.WeaponName.Equals(weaponScript.WeaponData.WeaponName))
            {
                return(InventoryIndex.Second);
            }
            else if (_weaponSlots[InventoryIndex.Throwable] != null && _weaponSlots[InventoryIndex.Throwable].WeaponData.WeaponName.Equals(weaponScript.WeaponData.WeaponName))
            {
                return(InventoryIndex.Throwable);
            }

            return(null);
        }
    public void Btn_UpgradeWeapon()
    {
        WeaponBehaviourScript _nextwep = WeaponInfoScreenWeaponGo.GetComponent <WeaponBehaviourScript>().NextWeapon.GetComponent <WeaponBehaviourScript>();

        if (GameControllerScript.currendCredits >= _nextwep.price)
        {
            GameControllerScript.currendCredits -= _nextwep.price;


            _nextwep.isBought = true;
            WeaponsViewGO.GetComponent <WeaponsViewControllerScript>().UpdateWeaponsView();
            UpdateUI();
            PlayButtonSound();
            OpenWeaponInfoScreen(WeaponInfoScreenWeaponGo.GetComponent <WeaponBehaviourScript>().NextWeapon);
        }
        else
        {
            PlayButtonSoundNo();
        }
    }
Esempio n. 23
0
        private void ProcessColliderHits(IEnumerable <Collider2D> colliderHits, WeaponBehaviourScript weapon)
        {
            foreach (var hit in colliderHits)
            {
                Debug.Log("Hit " + hit.gameObject.name);

                if (hit.gameObject.CompareTag("Enemy"))
                {
                    hit.gameObject.GetComponent <EnemyController>()?.ReceiveDamage(baseAttackDamage);
                }
                else if (hit.gameObject.CompareTag("Breakable"))
                {
                    hit.gameObject.GetComponent <IBreakable>()?.Break();
                }
                else if (hit.transform.gameObject.CompareTag("Player"))
                {
                    var playerController = hit.transform.gameObject.GetComponent <Controller>();
                    playerController.LoseHitPoints(baseAttackDamage);
                }
            }
        }
Esempio n. 24
0
 /// <summary>
 /// Adds a weapon to the inventory, at the given inventory slot. If there already is a weapon there, drops it.
 /// </summary>
 /// <param name="slot">The inventory slot to add the weapon to</param>
 /// <param name="weaponScript">The WeaponBehaviourScript attached to the weapon gameobject</param>
 /// <returns>A boolean indicating if the addition was successful</returns>
 private bool AddWeapon(InventoryIndex slot, WeaponBehaviourScript weaponScript)
 {
     if (_weaponSlots[slot] != null)
     {
         if (_weaponSlots[slot].WeaponData.WeaponName.Equals(weaponScript.WeaponData.WeaponName))
         {
             if (_weaponSlots[slot].WeaponData.WeaponName is WeaponName.Grenade)
             {
                 _weaponSlots[slot].CurrentMagazineAmmunition += weaponScript.CurrentMagazineAmmunition + weaponScript.CurrentTotalAmmunition;
             }
             else
             {
                 _weaponSlots[slot].CurrentTotalAmmunition += weaponScript.CurrentMagazineAmmunition + weaponScript.CurrentTotalAmmunition;
             }
             Destroy(weaponScript.gameObject);
             weaponScript.gameObject.transform.parent = gameObject.transform;
             return(true);
         }
         else
         {
             _weaponSlots[slot].WeaponStateProp  = WeaponState.OnGround;
             _weaponSlots[slot].transform.parent = null;
             weaponScript.WeaponStateProp        = WeaponState.InInventory;
             _weaponSlots[slot] = weaponScript;
             AddWeaponHUD?.Invoke(slot, weaponScript);
             weaponScript.gameObject.transform.parent = gameObject.transform;
             return(true);
         }
     }
     else
     {
         weaponScript.WeaponStateProp = WeaponState.InInventory;
         _weaponSlots[slot]           = weaponScript;
         AddWeaponHUD?.Invoke(slot, weaponScript);
         weaponScript.gameObject.transform.parent = gameObject.transform;
         return(true);
     }
 }
Esempio n. 25
0
 protected override void SpawnProjectile(WeaponBehaviourScript weapon)
 {
 }
Esempio n. 26
0
 public override void Reload(WeaponBehaviourScript weapon)
 {
 }
Esempio n. 27
0
 public void AddToInventory(InventoryIndex slot, WeaponBehaviourScript weaponScript)
 {
     _inventoryContainer[slot].SendMessage("AddWeaponToInventorySlot", weaponScript, SendMessageOptions.DontRequireReceiver);
 }
Esempio n. 28
0
 public abstract void Reload(WeaponBehaviourScript weapon);
Esempio n. 29
0
 public abstract void Shoot(WeaponBehaviourScript weapon);
Esempio n. 30
0
 public void RemoveWeaponFromInventorySlot()
 {
     _weaponScript = null;
     _image.sprite = defaultImage;
     _text.text    = defaultText;
 }