public void TestGetAttacks(AttackTestCaseData caseData)
        {
            var invWeapon     = new InventoryWeapon(caseData.Snapshot, caseData.Weapon);
            var actualAttacks = invWeapon.GetAttacks();

            AssertionHelpers.AssertEquivalentLists(actualAttacks, caseData.ExpectedAttacks, a => a.Name, AssertionHelpers.AssertEqualAttacks, string.Empty);
        }
Ejemplo n.º 2
0
    public Game()
    {
        Coins            = 0;
        Level            = 1;
        ExperiencePoints = 0;

        CurrentLevel = "Suburb";

        Bag = new Bag();

        InventoryWeapons = new List <InventoryWeapon> ();

        InventoryWeapon inventoryWeapon = new InventoryWeapon(WeaponDatabase.GetWeapon(0), true);

        InventoryWeapons.Add(inventoryWeapon);

        Bag.AddWeapon(InventoryWeapons [0].Weapon.ID);

        Heroes = new List <HeroParty> ();

        HeroParty heroParty = new HeroParty(HeroDatabase.GetHero(0), true);

        Heroes.Add(heroParty);

        CurrentHero = Heroes [0].Hero;

        Paused         = false;
        AutoAimTarget  = true;
        savedTimeScale = 1;

        achievementManager = new AchievementManager();
    }
Ejemplo n.º 3
0
    void UpdateWeapons() //TODO: Account for receiving a new weapon while the inventory is open!
    {
        for (int i = 0; i < invWeaponScripts.Length; i++)
        {
            InventoryWeapon w = invWeaponScripts[i];

            if (PlayerManager.Instance.pickedUpWeapons.Contains(w.weaponType))
            {
                w.gameObject.SetActive(true);

                if (PlayerManager.Instance.equippedWeaponInfo.weaponType == w.weaponType)
                {
                    w.outlineObj.gameObject.SetActive(true);
                }
                else
                {
                    w.outlineObj.gameObject.SetActive(false);
                }
            }
            else
            {
                w.gameObject.SetActive(false);
            }
        }
    }
Ejemplo n.º 4
0
    public void BuyWeapon(int choosenWeaponIndex)
    {
        if (Game.current == null)
        {
            return;
        }

        InventoryWeapon inventoryWeapon = Game.current.InventoryWeapons [choosenWeaponIndex];

        if (inventoryWeapon == null)
        {
            return;
        }

        if (Game.current.Coins >= inventoryWeapon.Weapon.Cost)
        {
            Game.current.Coins      -= inventoryWeapon.Weapon.Cost;
            inventoryWeapon.Unlocked = true;

            if (LobbyManagerUI.Instance != null)
            {
                LobbyManagerUI.Instance.RefreshCoins();
                LobbyManagerUI.Instance.RefreshWeaponButtons();
            }

            SetWeapon(choosenWeaponIndex);

            SaveLoad.Save();
        }
    }
Ejemplo n.º 5
0
    public void FillPurchasedPanel()
    {
        for (int i = 0; i < PurchasedWeaponButtons.Count; i++)
        {
            InventoryWeapon weaponData = Game.current.InventoryWeapons [i];

            if (weaponData.Unlocked && !Game.current.Bag.WeaponIsInBag(weaponData.Weapon.ID))
            {
                if (weaponData != null)
                {
                    Sprite sprite = Resources.Load(weaponIconPath + weaponData.Weapon.Name, typeof(Sprite)) as Sprite;
                    if (sprite != null)
                    {
                        Image image = PurchasedWeaponButtons [i].GetComponent <Image> ();
                        if (image != null)
                        {
                            image.sprite = sprite;
                        }
                    }
                }

                PurchasedWeaponButtons [i].SetWeaponPurchasedButton(weaponData.Weapon);
            }
        }
    }
Ejemplo n.º 6
0
 void SwitchWeapn()
 {
     if (!weapon.IsReloading())
     {
         if (inventory[1] != null)
         {
             AudioSource.PlayClipAtPoint(switchWeaponClip, this.transform.position);
             if (weaponIndex != inventory.Length - 1)
             {
                 weapon = inventory[1];
                 InventoryWeapon.activeIndex = 1;
                 weaponIndex           = 1;
                 spriteRenderer.sprite = inventory[weaponIndex].sprite;
             }
             else
             {
                 weapon = inventory[0];
                 InventoryWeapon.activeIndex = 0;
                 weaponIndex           = 0;
                 spriteRenderer.sprite = inventory[weaponIndex].sprite;
             }
             weapon.UpdateAmmoText();
             InventoryWeapon.ChangeInventory(this.inventory);
         }
     }
 }
Ejemplo n.º 7
0
    // Use this for initialization
    void Start()
    {
        Zombie.aliveZombies.Clear();
        life = maxLife;
        UpdateText();
        SetComponents();
        weapons.Add(gun);
        weapons.Add(shotgun);
        weapons.Add(rifle);
        weapons.Add(rpg);
        weapons.Add(sniper);

        foreach (Weapon weapon in weapons)
        {
            weapon.SetPlayerAttack(this);
        }
        weapon                = weapons[0];
        inventory[0]          = weapon;
        spriteRenderer.sprite = weapons[0].sprite;
        InventoryWeapon.ChangeInventory(this.inventory);
        foreach (Weapon weapon in inventory)
        {
            if (weapon)
            {
                weapon.UpdateAmmoText();
            }
        }
    }
 void EquipWeapon(InventoryWeapon weapon)
 {
     if (activeUnit)
     {
         activeUnit.weapon = weapon;
         SetActiveUnit(activeUnit);
     }
 }
Ejemplo n.º 9
0
    public void AddWeaponToInventory(WeaponData weaponToAdd)
    {
        InventoryWeapon existingWeaponInInventory = InventoryWeapons.SingleOrDefault(iw => iw.Weapon.Name == weaponToAdd.Name);

        if (existingWeaponInInventory == null)
        {
            InventoryWeapons.Add(new InventoryWeapon(weaponToAdd, false));
        }
    }
Ejemplo n.º 10
0
    public void RemoveWeaponFromInventory(WeaponData weaponToRemove)
    {
        InventoryWeapon weapon = InventoryWeapons.SingleOrDefault(iw => iw.Weapon.Name == weaponToRemove.Name);

        if (weapon != null)
        {
            InventoryWeapons.Remove(weapon);
        }
    }
Ejemplo n.º 11
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.GetComponent <Weapon>() != null)
        {
            if (other.gameObject.GetComponent <Weapon>().GetComponentInParent <WeaponSpot>() == null)
            {
                //if it is a real weapon, existing in the database
                GearDatabaseItem otherGearItemFromDatabase = gearDatabase.weapons.Find(x => other.gameObject.name.Contains(x.gamePref.name));
                if (otherGearItemFromDatabase != null)
                {
                    Transform       weaponSpot = GetComponentInChildren <WeaponSpot>().transform;
                    InventoryWeapon newiw      = new InventoryWeapon();
                    newiw.name = otherGearItemFromDatabase.gamePref.name;

                    // if already have it
                    InventoryWeapon contained = availableWeapons.Find(x => x.name == newiw.name);
                    if (contained != null)
                    {
                        //just add some stuff to the existing
                        contained.bullets += Random.Range(5, 50);
                        //contained.durability = 100f;
                        PlayAmmoSound();
                    }
                    else
                    {
                        //add the new weapon to player gear
                        GameObject instantiatedWeap = Instantiate(otherGearItemFromDatabase.gamePref, weaponSpot) as GameObject;
                        instantiatedWeap.transform.localPosition = Vector3.zero;
                        instantiatedWeap.transform.localRotation = Quaternion.identity;
                        instantiatedWeap.transform.localScale    = Vector3.one;
                        instantiatedWeap.SetActive(false);

                        //do the same for UI gameobjects
                        RectTransform guiWeaponSpot      = GameObject.Find("UI").transform.Find("ActiveWeapon").GetComponent <RectTransform>();
                        GameObject    instantiatedWeapUI = Instantiate(otherGearItemFromDatabase.guiPref, guiWeaponSpot) as GameObject;
                        instantiatedWeapUI.GetComponent <RectTransform>().localPosition = Vector3.zero;
                        instantiatedWeapUI.SetActive(false);

                        newiw.weaponGO   = instantiatedWeap;
                        newiw.weaponUIGO = instantiatedWeapUI;
                        newiw.bullets    = other.gameObject.GetComponent <Weapon>().bullets;
                        availableWeapons.Add(newiw);
                        SetSelectedWeapon(availableWeapons.IndexOf(newiw));

                        //ui weapon slots adjust
                        GameObject weaponSlot = GameObject.Find("UI").transform.Find("Weapons").Find(availableWeapons.IndexOf(newiw).ToString()).gameObject;
                        if (weaponSlot != null)
                        {
                            weaponSlot.transform.Find(otherGearItemFromDatabase.gamePref.name).gameObject.SetActive(true);
                        }
                        PlayChangeWeapSound();
                    }
                    Destroy(other.gameObject);
                }
            }
        }
    }
Ejemplo n.º 12
0
 public void UpdateAmmoText()
 {
     if (reloading)
     {
         InventoryWeapon.GetText(this).text = "Reloading...";
     }
     else
     {
         InventoryWeapon.GetText(this).text = ammoOnStack + "/" + ammoLeft;
     }
 }
Ejemplo n.º 13
0
    public void SetWeaponButton(InventoryWeapon data)
    {
        weaponData = data;

        if (Game.current.Level >= data.Weapon.LevelToUnlocked)
        {
            if (button != null)
            {
                button.interactable = true;
            }

            if (lockImage != null)
            {
                lockImage.SetActive(false);
            }
        }
        else
        {
            if (button != null)
            {
                button.interactable = false;
            }

            if (lockImage != null)
            {
                lockImage.SetActive(true);
            }
        }

        if (data.Unlocked)
        {
            if (costPanel != null)
            {
                costPanel.SetActive(false);
            }
        }
        else
        {
            if (costPanel != null)
            {
                costPanel.SetActive(true);
            }

            if (costText != null)
            {
                costText.text = data.Weapon.Cost.ToString();
            }
        }
    }
Ejemplo n.º 14
0
    public void RefreshWeaponButtons()
    {
        if (WeaponButtons == null)
        {
            return;
        }

        for (int i = 0; i < WeaponButtons.Count; i++)
        {
            InventoryWeapon weaponData = Game.current.InventoryWeapons [i];

            if (weaponData != null)
            {
                WeaponButtons [i].SetWeaponButton(weaponData);
            }
        }
    }
Ejemplo n.º 15
0
    /// <summary>
    /// Executes an Action depending on the CurrentEquipped Item. (Build or use Weapon)
    /// </summary>
    internal void ProcessAction()
    {
        if (Attributes.IsAlive)
        {
            IInventoryItem currentItem = Attributes.CurrentEquippedItem;
            if (currentItem is InventoryTile)
            {
                InventoryTile inventoryTile = (InventoryTile)currentItem;
                PrefabTile    tileToBuild   = inventoryTile.Tile;

                if (resourceManager.ConstructionMaterialAvailable >= tileToBuild.BuildingCosts)
                {
                    if (!tileController.TryAddTile(tileToBuild, transform.position))
                    {
                        var fadeout = Instantiate(fadeoutTextPrefab, transform);
                        fadeout.TextMesh.text  = "#@!&$%";
                        fadeout.TextMesh.color = new Color(1.0f, 0.0f, 0.0f, 1);
                    }
                    // Consume should always work in this case, because we checked for available resources
                    else if (!resourceManager.TryConsume(tileToBuild.BuildingCosts))
                    {
                        Debug.LogError("Could not consume resources for building even though enough resources were available");
                    }
                    else
                    {
                        // Success, create building
                        var fadeout = Instantiate(fadeoutTextPrefab, transform);
                        fadeout.TextMesh.text  = $"-{(float)tileToBuild.BuildingCosts}";
                        fadeout.TextMesh.color = new Color(0.6392157F, 0.5019608F, 0.3892157F, 1.0F);
                    }
                }
                else
                {
                    var fadeout = Instantiate(fadeoutTextPrefab, transform);
                    fadeout.TextMesh.text  = "Not enought Resources!";
                    fadeout.TextMesh.color = new Color(1.0f, 0.0f, 0.0f, 1);
                }
            }
            else if (currentItem is InventoryWeapon)
            {
                InventoryWeapon inventoryWeapon = (InventoryWeapon)currentItem;
                inventoryWeapon.Weapon.GetComponent <IPlayerWeapon>().Fire();
            }
        }
    }
Ejemplo n.º 16
0
    void OnTriggerEnter2D(Collider2D collider2D)
    {
        PlayerAttack player = FindObjectOfType <PlayerAttack>();

        if (collider2D.gameObject.tag.Equals("Player") && collider2D == collider2D.gameObject.GetComponent <PlayerAttack>().body)
        {
            Destroy(gameObject);
            FindWeapon();
            if (weapon.gameObject.GetComponent <PlayerAttack>().GetWeapon() == weapon)
            {
                weapon.SetUpWeapon(true);
            }
            else
            {
                weapon.SetUpWeapon(false);
            }
            AudioSource.PlayClipAtPoint(pickupClip, this.transform.position);
            InventoryWeapon.ChangeInventory(player.inventory);
        }
    }
    void SetActiveWeapon(InventoryWeapon newWeapon)
    {
        // Set all meshes to false
        for (int i = 0; i < inventoryWeapons.Length; i++)
        {
            inventoryWeapons[i].weaponMesh.SetActive(false);
        }
        meleeWeapon.weaponMesh.SetActive(false);
        grenadeLauncher.weaponMesh.SetActive(false);

        // Update weapon prefab
        player.weaponPrefab = newWeapon.weaponPrefab;
        player.UpdateWeaponInstance(player.weaponPrefab);

        // Activate weapon mesh
        newWeapon.weaponMesh.SetActive(true);
        player.characterMesh = newWeapon.weaponMesh;
        player.UpdateAnim();

        // Update flash muzzle location and muzzle light
        player.SetWeaponFlashObjects(newWeapon.weaponFlashMuzzle, newWeapon.weaponFlashLight);
    }
Ejemplo n.º 18
0
    public void CreateWeaponButtons()
    {
        if (weaponButtonPrefab == null || weaponPanelContent == null)
        {
            return;
        }

        for (int i = 0; i < Game.current.InventoryWeapons.Count; i++)
        {
            GameObject weaponButtonClone = Instantiate(weaponButtonPrefab) as GameObject;
            weaponButtonClone.transform.SetParent(weaponPanelContent, false);

            InventoryWeapon weaponData = Game.current.InventoryWeapons [i];
            if (weaponData == null)
            {
                return;
            }

            Sprite sprite = Resources.Load(weaponIconPath + weaponData.Weapon.Name, typeof(Sprite)) as Sprite;
            if (sprite != null)
            {
                Image image = weaponButtonClone.GetComponent <Image> ();
                if (image != null)
                {
                    image.sprite = sprite;
                }
            }

            WeaponButton weaponButton = weaponButtonClone.GetComponent <WeaponButton> ();
            if (weaponButton != null)
            {
                weaponButton.SetWeaponButton(weaponData);

                WeaponButtons.Add(weaponButton);
            }
        }
    }
Ejemplo n.º 19
0
    /// <summary>
    /// Opens the Menu with the Inventory with the available Tiles and Weapons.
    /// </summary>
    internal void OpenInventory()
    {
        if (Attributes.IsAlive)
        {
            this.playerMovement.enabled = false;
            var itemList = new List <IInventoryItem>();

            foreach (GameObject weapon in weapons)
            {
                Sprite         sprite = weapon.GetComponent <SpriteRenderer>().sprite;
                IInventoryItem item   = new InventoryWeapon(Instantiate(weapon, weaponCache.transform), sprite);
                itemList.Add(item);
            }

            foreach (PrefabTile tile in tiles)
            {
                IInventoryItem item = new InventoryTile(tile);
                itemList.Add(item);
            }

            this.inventory.EnableMenuView(itemList);
            this.inventory.EnableItemSelection();
        }
    }
 public OnWeaponRemovedEventArgs(int slotIndex, InventoryWeapon removedWeapon)
 {
     SlotIndex     = slotIndex;
     RemovedWeapon = removedWeapon;
 }
 public OnWeaponAddedEventArgs(int slotIndex, InventoryWeapon addedWeapon)
 {
     SlotIndex   = slotIndex;
     AddedWeapon = addedWeapon;
 }
Ejemplo n.º 22
0
    public void ChangeGeneralDescription(int index)
    {
        if (_weaponInfos.Count > index && _hoverdItemType == ItemType.Weapon)
        {
            if (_weaponInfos[index].weaponMount != null && _weaponInfos[index].weaponMount.item != null)
            {
                _clickedItemType = ItemType.Weapon;

                InventoryWeapon weapon = _weaponInfos[index].weaponMount.item;
                if (_generalDescriptionPanel.descriptionImage != null)
                {
                    _generalDescriptionPanel.descriptionImage.gameObject.SetActive(true);
                    _generalDescriptionPanel.descriptionImage.sprite = weapon.image;
                }

                if (_generalDescriptionPanel.descriptionNameText != null)
                {
                    _generalDescriptionPanel.descriptionNameText.text = weapon.itemName;
                }

                if (_generalDescriptionPanel.decriptionText != null)
                {
                    _generalDescriptionPanel.decriptionText.text = weapon.itemDescription;
                }

                if (_generalDescriptionPanel.actionButton1 != null)
                {
                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(true);
                    _generalDescriptionPanel.actionButton1.GetComponentInChildren <Text>().text = weapon.actionButton1Text;
                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(true);
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.GetComponentInChildren <Text>().text = weapon.actionButton2Text;
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.gameObject.SetActive(weapon.showActionButton2);
                }
            }
        }


        if (_itemInfos.Count > index && _hoverdItemType == ItemType.Ammo)
        {
            if (_itemInfos[index].ammoMount.item != null)
            {
                _clickedItemType = ItemType.Ammo;

                InventoryAmmo ammo = _itemInfos[index].ammoMount.item;

                if (_generalDescriptionPanel.descriptionImage != null)
                {
                    _generalDescriptionPanel.descriptionImage.gameObject.SetActive(true);
                    _generalDescriptionPanel.descriptionImage.sprite = ammo.image;
                }

                if (_generalDescriptionPanel.descriptionNameText != null)
                {
                    _generalDescriptionPanel.descriptionNameText.text = ammo.itemName;
                }

                if (_generalDescriptionPanel.decriptionText != null)
                {
                    _generalDescriptionPanel.decriptionText.text = _itemInfos[index].ammoMount.rounds + "/" + _itemInfos[index].ammoMount.item.capacity;
                }

                if (_generalDescriptionPanel.actionButton1 != null)
                {
                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(true);
                    _generalDescriptionPanel.actionButton1.GetComponentInChildren <Text>().text = ammo.actionButton1Text;
                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(true);
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.GetComponentInChildren <Text>().text = ammo.actionButton2Text;
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.gameObject.SetActive(ammo.showActionButton2);
                }
            }
        }

        if (_itemInfos.Count > index && _hoverdItemType == ItemType.Consumable)
        {
            if (_itemInfos[index].consumableMount.item != null)
            {
                _clickedItemType = ItemType.Consumable;

                InventoryConsumable consumable = _itemInfos[index].consumableMount.item;

                if (_generalDescriptionPanel.descriptionImage != null)
                {
                    _generalDescriptionPanel.descriptionImage.gameObject.SetActive(true);
                    _generalDescriptionPanel.descriptionImage.sprite = consumable.image;
                }

                if (_generalDescriptionPanel.descriptionNameText != null)
                {
                    _generalDescriptionPanel.descriptionNameText.text = consumable.itemName;
                }

                if (_generalDescriptionPanel.decriptionText != null)
                {
                    _generalDescriptionPanel.decriptionText.text = _itemInfos[index].consumableMount.item.itemDescription;
                }

                if (_generalDescriptionPanel.actionButton1 != null)
                {
                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(true);
                    _generalDescriptionPanel.actionButton1.GetComponentInChildren <Text>().text = consumable.actionButton1Text;

                    _generalDescriptionPanel.actionButton1.gameObject.SetActive(consumable.canBeDropped);
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.GetComponentInChildren <Text>().text = consumable.actionButton2Text;
                }

                if (_generalDescriptionPanel.actionButton2 != null)
                {
                    _generalDescriptionPanel.actionButton2.gameObject.SetActive(consumable.showActionButton2);
                }
            }
        }
    }
Ejemplo n.º 23
0
 public OnSelectedWeaponChangedEventArgs(int slotIndex, InventoryWeapon currentWeapon)
 {
     SlotIndex     = slotIndex;
     CurrentWeapon = currentWeapon;
 }