示例#1
0
        public void TestPotion()
        {
            IHealthModifier badPotion  = new SimplePotion("Bad potion", -20);
            IHealthModifier goodPotion = new SimplePotion("GoodPotion", 15);

            badPotion.UseOn(PLAYER);
            goodPotion.UseOn(PLAYER);
            Assert.AreEqual(PLAYER.Health, 95);
        }
示例#2
0
        public void TestHealthOverflow()
        {
            IHealthModifier goodPotion = new SimplePotion("GoodPotion", 20);

            for (int i = 0; i < 6; i++)
            {
                goodPotion.UseOn(PLAYER);
            }
            Assert.AreEqual(PLAYER.Health, 100);
        }
示例#3
0
        public void TestHealthUnderflow()
        {
            IHealthModifier badPotion = new SimplePotion("Bad potion", -20);

            for (int i = 0; i < 6; i++)
            {
                badPotion.UseOn(PLAYER);
            }
            Assert.AreEqual(PLAYER.Health, 0);
            Assert.IsFalse(PLAYER.IsAlive());
        }
示例#4
0
    public void UseOnSlot()
    {
        if (!invMarker.HasMarkedSlot)
        {
            if (invMarker.CurrentSlot.StoredItem != null)
            {
                string slotItemType = GetItemType(invMarker.CurrentSlot.StoredItem);

                switch (slotItemType)
                {
                case "ArmorGem":

                    if (invMarker.CurrentInv == backpack)
                    {
                        Slot possibleSlot = SearchForSlot(armorGemEquipment);

                        if (possibleSlot != null)
                        {
                            MoveAndEquipItem(possibleSlot);
                            GenerateTooltip(true);
                        }
                    }
                    else
                    {
                        Slot possibleSlot = SearchForSlot(backpack);

                        if (possibleSlot != null)
                        {
                            MoveAndUnequipItem(possibleSlot);
                            GenerateTooltip(true);
                        }
                    }

                    break;

                case "WeaponGem":

                    if (invMarker.CurrentInv == backpack)
                    {
                        Slot possibleSlot = SearchForSlot(weaponGemEquipment);

                        if (possibleSlot != null)
                        {
                            MoveAndEquipItem(possibleSlot);
                            GenerateTooltip(true);
                        }
                    }
                    else
                    {
                        Slot possibleSlot = SearchForSlot(backpack);

                        if (possibleSlot != null)
                        {
                            MoveAndUnequipItem(possibleSlot);
                            GenerateTooltip(true);
                        }
                    }

                    break;

                case "SimplePotion":

                    SimplePotion sp = (SimplePotion)invMarker.CurrentSlot.StoredItem;
                    sp.Consume(player.GetComponent <Player>());
                    GenerateTooltip(true);

                    break;
                }
            }
        }
        else
        {
            invMarker.UnmarkSlot();
        }
    }
示例#5
0
    private void GenerateTooltip(bool isEmpty)
    {
        Text  itemName     = itemInfo.transform.GetChild(0).GetComponent <Text>();
        Text  itemTier     = itemInfo.transform.GetChild(1).GetComponent <Text>();
        Text  itemHeader   = itemInfo.transform.GetChild(2).GetComponent <Text>();
        Text  itemDesc     = itemInfo.transform.GetChild(3).GetComponent <Text>();
        Image windowBorder = itemInfo.transform.GetChild(6).GetComponent <Image>();

        List <Text> statList = new List <Text>();
        Dictionary <string, float> foundStats = new Dictionary <string, float>();

        for (int i = 0; i < 5; i++)
        {
            statList.Add(itemInfo.transform.GetChild(4).transform.GetChild(i).GetComponent <Text>());
        }

        for (int i = 0; i < 5; i++)
        {
            statList.Add(itemInfo.transform.GetChild(5).transform.GetChild(i).GetComponent <Text>());
        }

        Color propertyColor;

        if (!isEmpty)
        {
            I_item currentItem = invMarker.CurrentSlot.StoredItem;
            itemName.text   = currentItem.Name;
            itemDesc.text   = currentItem.Description;
            itemTier.text   = "Tier " + currentItem.Tier;
            itemHeader.text = "[" + currentItem.HeaderDescription + "]";

            switch (currentItem.Tier)
            {
            case 1:

                propertyColor      = new Color(0, 255, 0);
                itemTier.color     = propertyColor;
                windowBorder.color = propertyColor;

                break;

            case 2:

                propertyColor      = new Color(0, 255, 255);
                itemTier.color     = propertyColor;
                windowBorder.color = propertyColor;

                break;
            }

            switch (GetItemType(currentItem))
            {
            case "ArmorGem":

                propertyColor    = new Color(0, 0.3656104f, 1);
                itemHeader.color = propertyColor;

                for (int i = 0; i < statList.Count; i++)
                {
                    statList[i].text = null;
                }

                ArmorGem ag = (ArmorGem)currentItem;
                foundStats = ag.GetStats();
                int statIndex = 0;

                foreach (KeyValuePair <string, float> stat in foundStats)
                {
                    if (stat.Value > 0)
                    {
                        statList[statIndex].text = "+ " + stat.Value + " " + stat.Key;
                        statIndex++;
                    }
                    else if (stat.Value < 0)
                    {
                        statList[statIndex].text = "- " + Mathf.Abs(stat.Value) + " " + stat.Key;
                        statIndex++;
                    }
                    else
                    {
                        statList[statIndex].text = null;
                    }
                }

                break;

            case "WeaponGem":

                propertyColor    = new Color(1, 0, 0.2169275f);
                itemHeader.color = propertyColor;

                for (int i = 0; i < statList.Count; i++)
                {
                    statList[i].text = null;
                }

                WeaponGem wg = (WeaponGem)currentItem;
                foundStats = wg.GetStats();
                statIndex  = 0;

                foreach (KeyValuePair <string, float> stat in foundStats)
                {
                    if (stat.Value > 0)
                    {
                        statList[statIndex].text = "+ " + stat.Value + " " + stat.Key;
                        statIndex++;
                    }
                    else if (stat.Value < 0)
                    {
                        statList[statIndex].text = "- " + Mathf.Abs(stat.Value) + " " + stat.Key;
                        statIndex++;
                    }
                    else
                    {
                        statList[statIndex].text = null;
                    }
                }

                break;

            case "SimplePotion":

                propertyColor    = new Color(1, 0, 1);
                itemHeader.color = propertyColor;

                for (int i = 0; i < statList.Count; i++)
                {
                    statList[i].text = null;
                }

                SimplePotion sp = (SimplePotion)currentItem;
                foundStats = sp.GetStats();
                statIndex  = 0;

                foreach (KeyValuePair <string, float> stat in foundStats)
                {
                    if (stat.Key == "Recovery time")
                    {
                        statList[statIndex].text = stat.Value + "s " + stat.Key;
                    }
                    else
                    {
                        if (stat.Value > 0)
                        {
                            statList[statIndex].text = "+ " + stat.Value + " " + stat.Key;
                            statIndex++;
                        }
                        else if (stat.Value < 0)
                        {
                            statList[statIndex].text = "- " + Mathf.Abs(stat.Value) + " " + stat.Key;
                            statIndex++;
                        }
                        else
                        {
                            statList[statIndex].text = null;
                        }
                    }
                }

                break;
            }
        }
        else
        {
            itemName.text      = null;
            itemTier.text      = null;
            itemHeader.text    = null;
            itemDesc.text      = null;
            windowBorder.color = Color.white;

            for (int i = 0; i < statList.Count; i++)
            {
                statList[i].text = null;
            }
        }
    }