Beispiel #1
0
    void SpawnWeaponAmmoMenu(int i)
    {
        // Instantiatea (buy ammo menu...)
        GameObject _shopItem = Instantiate(shopitem_alreadyBought);

        if (!_shopItem.activeSelf)
        {
            _shopItem.SetActive(true);
        }

        RectTransform r = _shopItem.GetComponent <RectTransform>();

        _shopItem.transform.SetParent(scrollRect_weapons.transform);

        // Aseta paikka ja koko
        _shopItem.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, (-r.sizeDelta.y * shopItems.Count) - r.sizeDelta.y / 2);
        r.sizeDelta = new Vector2(0, r.sizeDelta.y);

        // Aseta aseen nimi ja teksti
        WeaponPrefab w = gamemanager.GetComponent <GameManager>().weapons[i];

        FindTextFromParent("weapon-name", _shopItem.transform).text = w.weaponName;

        // Aseta aseen pikku kuva
        _shopItem.GetComponentInChildren <RawImage>().texture = w.shopImage;

        ShopItem s = new ShopItem(_shopItem, w);

        shopItems.Add(s);
    }
    IEnumerator SwapWeaponSequence(WeaponPrefab newPrefab, Weapon oldWeapon, bool destroyOld, int newIndex, int clipAmmo, int ammo)
    {
        //make old disappear
        float putAwayTime = oldWeapon.PutAwayWeapon();

        yield return(new WaitForSeconds(putAwayTime));

        if (destroyOld)
        {
            Destroy(oldWeapon);
        }
        else
        {
            oldWeapon.gameObject.SetActive(false);
        }

        //spawn new
        Weapon instance    = Instantiate(newPrefab.weaponPrefab, transform.position, transform.rotation, transform);
        float  takeOutTime = instance.TakeOutWeapon();

        weapons[newIndex] = instance;
        instance.SetAmmo(clipAmmo);
        instance.ammunition.SetAmmo(ammo);

        yield return(new WaitForSeconds(takeOutTime));

        switchingWeapons = false;
    }
    public Vector3 GetProjectileSpawn(WeaponPrefab weaponPrefab, string projectilePool)
    {
        Vector3 pos = Vector3.zero;

        for (int i = 0; i < projectileSettings.Count; i++)
        {
            if (projectileSettings[i].projectilePool == projectilePool)
            {
                switch (projectileSettings[i].projectileSpawn)
                {
                case ProjectileSettings.ProjectileSpawn.Weapon:

                    pos = weaponPrefab.projectileSpawn.position;
                    break;

                case ProjectileSettings.ProjectileSpawn.Mouse:

                    pos = PlayerController.mouseInWorldPos;
                    break;

                case ProjectileSettings.ProjectileSpawn.Player:

                    pos = Player.localPlayer.transform.position;
                    break;
                }
            }
        }

        return(pos);
    }
Beispiel #4
0
 public void OnStart()
 {
     w               = WeaponPrefab.GetWeaponPrefabByName(weaponName.text, GameManager.Instance.weapons);
     slider.value    = 0;
     slider.maxValue = w.weaponStats.ammo.GetRemainingAmmoTillMax();
     buy.GetComponentInChildren <Text>().text = "Valitse määrä";
 }
Beispiel #5
0
    public static WeaponPrefab LoadPrefabInfo(WeaponPrefab wp)
    {
        wp.position = wp.prefab.transform.localPosition;
        wp.rotation = new Vector3(wp.prefab.transform.localRotation.x, wp.prefab.transform.localRotation.y, wp.prefab.transform.localRotation.z);
        wp.scale    = wp.prefab.transform.localScale;

        return(wp);
    }
Beispiel #6
0
    public Weapon(WeaponData weaponData) : base(weaponData, false)
    {
        WeaponPrefab weaponPrefab = Resources.Load <WeaponPrefab>("Items/Weapons/" + itemPrefabName);

        damage        = weaponData.damage;
        model         = weaponPrefab.model;
        sprite        = weaponPrefab.sprite;
        isDualWielded = weaponPrefab.isDualWelded;
        type          = weaponPrefab.weaponType;
        enchantment   = new Enchantment(weaponData.enchantment);
    }
Beispiel #7
0
 public void SpawnWeapons()
 {
     foreach (var card in WeaponsToShow)
     {
         GameObject   newGO      = Instantiate(WeaponPrefab, WeaponsPanel, false);
         WeaponPrefab cardPrefab = newGO.GetComponent <WeaponPrefab>();
         cardPrefab.SetCard(card.Name, card.Description, card.Image, card);
         Button cardButton = newGO.GetComponent <Button>();
         cardButton.onClick.AddListener(delegate { SelectWeapon(cardPrefab); });
     }
 }
Beispiel #8
0
    public void AddWeapon(WeaponPrefab w)
    {
        if (w != null)
        {
            w.owned = true;
            if (!weapons.Contains(w))
            {
                weapons.Add(w);
            }
        }

        maxWeapon = weapons.Count - 1;
    }
    public bool SwapWeapon(WeaponNames newWeapon, Transform pickup, int totalAmmo, int clipAmmo = -1)
    {
        WeaponPrefab newPrefab = PlayerWeaponLoader.GetWeapon(newWeapon);
        Weapon       old       = weapons[currentWeapon];
        int          slot      = (currentWeapon == 0) ? 1 : 0;

        if (!old.Ready || !old.gameObject.activeSelf || switchingWeapons || newPrefab.weaponPrefab == null || old.gunLocked)
        {
            return(false);
        }

        if (weapons[1] != null)
        {
            if (weapons[slot] != null)
            {
                slot = currentWeapon;
            }

            old = weapons[slot];
            switchingWeapons = true;

            Vector2Int dropAmmo = new Vector2Int();
            dropAmmo.x = old.GetAmmo();
            dropAmmo.y = old.ammunition.AmmoLeft();

            if (dropAmmo.magnitude > 0)
            {
                SpawnDrop(old.thisWeapon, pickup, dropAmmo);
            }

            StartCoroutine(SwapWeaponSequence(newPrefab, old, (slot == currentWeapon), slot, clipAmmo, totalAmmo));
        }
        else
        {
            Weapon instance = Instantiate(newPrefab.weaponPrefab, transform.position, transform.rotation, transform);
            weapons[1] = instance;
            instance.SetAmmo(clipAmmo);
            instance.ammunition.SetAmmo(totalAmmo);
            instance.gameObject.SetActive(false);
            SwitchWeapon();
        }

        if (OnPickedUpWeapon != null)
        {
            OnPickedUpWeapon();
        }
        return(true);
    }
Beispiel #10
0
    private void WeaponSlot_OnUsePrimary()
    {
        WeaponPrefab wp = Player.localPlayer.weaponSlot.equipedItem.GetComponent <WeaponPrefab>();

        spawnPosition              = spawnAtCursor ? PlayerController.mouseInWorldPos : wp.projectileSpawn.position;
        spawnPosition             += spawnOffset;
        spawnRotation              = projectileRotation == ProjectileRotation.Player ? Player.localPlayer.playerController.body.transform.rotation : Quaternion.identity;
        spawnRotation.eulerAngles += spawnRotOffset;

        ProjectileManager.instance.FireProjectile(new ProjectileManager.ProjectileData
        {
            spawnPosition  = spawnPosition,
            spawnRotation  = spawnRotation,
            projectilePool = projecileToSpawnOnAttack,
            speed          = speed,
            damage         = projectile.fireData.damage
        });
    }
Beispiel #11
0
    /// <summary>
    /// Creates a weapon from the inputs
    /// </summary>
    /// <param name="name"></param>
    /// <param name="level"></param>
    /// <param name="value"></param>
    /// <param name="rarity"></param>
    /// <param name="itemPrefabName"></param>
    /// <param name="damage"></param>
    /// <param name="enchantment"></param>
    /// <returns>returns the weapon</returns>
    public static Weapon CreateWeapon(string name, int level, int value, ItemRarity rarity, string itemPrefabName, float damage, Enchantment enchantment)
    {
        WeaponPrefab weaponPrefab = Resources.Load <WeaponPrefab>("Items/Weapons/" + itemPrefabName);
        Weapon       weapon       = new Weapon
        {
            name           = name,
            level          = level,
            value          = value,
            rarity         = rarity,
            itemPrefabName = itemPrefabName,
            model          = weaponPrefab.model,
            sprite         = weaponPrefab.sprite,
            damage         = damage,
            enchantment    = enchantment,
            type           = weaponPrefab.weaponType,
            isDualWielded  = weaponPrefab.isDualWelded
        };

        return(weapon);
    }
Beispiel #12
0
 void SelectWeapon(WeaponPrefab weapon)
 {
     if (WeaponsSelected.Count >= MaxCardsSelected)
     {
         if (weapon.IsSelected)
         {
             weapon.IsSelected = false;
             WeaponsSelected.Remove(weapon.Weapon);
         }
         return;
     }
     if (weapon.IsSelected)
     {
         WeaponsSelected.Remove(weapon.Weapon);
     }
     else
     {
         WeaponsSelected.Add(weapon.Weapon);
     }
     weapon.IsSelected = !weapon.IsSelected;
 }
Beispiel #13
0
    void SpawnWeaponMenu(int i)
    {
        GameObject _shopItem = Instantiate(shopitem);

        if (!_shopItem.activeSelf)
        {
            _shopItem.SetActive(true);
        }

        RectTransform r = _shopItem.GetComponent <RectTransform>();

        _shopItem.transform.SetParent(scrollRect_weapons.transform);

        // Aseta paikka ja koko
        _shopItem.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, (-r.sizeDelta.y * shopItems.Count) - r.sizeDelta.y / 2);
        r.sizeDelta = new Vector2(0, r.sizeDelta.y);

        // Aseta aseen nimi ja teksti
        WeaponPrefab w = gamemanager.GetComponent <GameManager>().weapons[i];

        FindTextFromParent("weapon-name", _shopItem.transform).text = w.weaponName;
        FindTextFromParent("weapon-info", _shopItem.transform).text =
            "Vahinko pisteet: " + w.weaponStats.damage * w.weaponStats.bulletsPerShot + "\n" +
            "Tarkkuus: " + (100 - ((w.weaponStats.bulletSpread / GameManager.largestBulletSpread) * 100)) + "%" + "\n" +
            "Ampumisnopeus: " + (w.weaponStats.rateOfFire) + "\n" +
            "Latausaika: " + (w.weaponStats.reloadTime);

        // Aseta hinta
        _shopItem.GetComponentInChildren <Button>().GetComponentInChildren <Text>().text = w.price.ToString();

        // Aseta aseen pikku kuva
        _shopItem.GetComponentInChildren <RawImage>().texture = w.shopImage;

        //InstantiatedShopItems[i] = _shopItem;

        ShopItem s = new ShopItem(_shopItem, w);

        shopItems.Add(s);
    }
Beispiel #14
0
    public void BuyWeapon()
    {
        int price;

        if (int.TryParse(priceText.text.Trim(), out price))
        {
            if (Player.money > price)
            {
                WeaponPrefab _w = WeaponPrefab.GetWeaponPrefabByName(weaponName.text.Trim(), GameManager.Instance.weapons);
                Player.Money(-price);

                // Laita aseen omistus arvo "true" ja lisää ase pelaajan ase listaan.
                Player.Instance.AddWeapon(_w);

                print(weaponName.text);

                Shop.Instance.LoadWeapons();
            }
        }

        Shop.Instance.UpdateShopMoney();
    }
Beispiel #15
0
    private void Start()
    {
        Timer(true);

        for (int i = 0; i < weapons.Count; i++)
        {
            if (weapons[i].weaponStats.bulletSpread > largestBulletSpread)
            {
                largestBulletSpread = weapons[i].weaponStats.bulletSpread;
            }

            if (!weapons[i].useCustomAdjustments)
            {
                weapons[i] = WeaponPrefab.LoadPrefabInfo(weapons[i]);
            }
        }

        Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Player"), LayerMask.NameToLayer("Bullet"));
        Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Player"), LayerMask.NameToLayer("Shell"));

        //currentTimer = 1000;

        //TogglePause();

        //GameObject.FindGameObjectWithTag("Player").GetComponent<UnityStandardAssets.Characters.FirstPerson.FirstPersonController>().enabled = false;

        /*
         * Cursor.lockState = CursorLockMode.None;
         * Cursor.visible = true;
         */

        // Load defaults
        //Colors.ShopColors.LoadDefaults();
        //weapons = Weapon.InitializeWeapon(weapons);
        RestartGame();
    }
Beispiel #16
0
 public void SetWeaponPrefab(WeaponPrefab w)
 {
     prefabInstance = w;
     raycastOrigin  = w.ShootOrigin;
 }
Beispiel #17
0
 public ShopItem(GameObject shopItem, WeaponPrefab w)
 {
     this.shopItem = shopItem;
     this.w        = w;
 }