コード例 #1
0
ファイル: Backpack.cs プロジェクト: quill18/LD42-PathOfExcess
    public void SellOffLoot(Text itemNameTxt, Text statGainTxt)
    {
        Dictionary <Stats, float> statGains = new Dictionary <Stats, float>();

        itemNameTxt.text = "Sold Items:\n\n";

        for (int x = 0; x < BagWidth; x++)
        {
            for (int y = 0; y < BagHeight; y++)
            {
                Loot l = bagSlots[x, y].MyLoot;
                if (l == null)
                {
                    continue;
                }

                LootStats ls = l.GetComponent <LootStats>();

                itemNameTxt.text += ls.name + "\n";

                float perc = 0.1f;
                if (ls.itemType == ItemTypes.Potion)
                {
                    perc = 0.01f * (ls.PotionDuration / 10f);
                }


                l.RemoveFromSlot();
                foreach (ItemMod im in ls.itemMods)
                {
                    float gain = im.Value * perc * (100f + StatManager.Instance.GetValueF(Stats.Charisma)) / 100f;

                    if (statGains.ContainsKey(im.Stat))
                    {
                        statGains[im.Stat] += gain;
                    }
                    else
                    {
                        statGains[im.Stat] = gain;
                    }

                    StatManager.Instance.ChangeValue(im.Stat, gain);
                }

                Destroy(ls.gameObject);
            }
        }

        statGainTxt.text = "Total Stats Gained:\n\n";

        foreach (Stats s in statGains.Keys)
        {
            if (statGains[s] == 0)
            {
                continue;
            }

            statGainTxt.text += s.ToString() + (statGains[s] >= 0 ? " +" : " ") + statGains[s].ToString("0.#") + "\n";
        }
    }
コード例 #2
0
    void ShowToolTip(LootStats ls)
    {
        Text nameTxt  = transform.Find("Item Name").GetComponent <Text>();
        Text statsTxt = transform.Find("Stats").GetComponent <Text>();

        nameTxt.color = rarityColor.RarityColors[ls.Rarity];

        if (ls.IsIdentified())
        {
            nameTxt.text = ls.name;

            statsTxt.text = "";

            foreach (ItemMod im in ls.itemMods)
            {
                if (statsTxt.text != "")
                {
                    statsTxt.text += "\n";
                }

                statsTxt.text += im.Stat.ToString() + (im.Value >= 0 ? " +" : " ") + im.Value;
            }
        }
        else
        {
            // NOT IDENTIFIED
            nameTxt.text = "UNIDENTIFIED";

            statsTxt.text = ls.IdentTimeLeft().ToString("#.##");
        }

        this.transform.SetAsLastSibling();
        Tooltip.Show();
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (PauseManager.isPaused)
        {
            return;
        }


        PointerEventData pointerData = new PointerEventData(EventSystem.current)
        {
            pointerId = -1,
        };

        pointerData.position = Input.mousePosition;

        List <RaycastResult> results = new List <RaycastResult>();

        EventSystem.current.RaycastAll(pointerData, results);

        foreach (RaycastResult rr in results)
        {
            LootStats ls = rr.gameObject.GetComponentInParent <LootStats>();

            if (ls != null)
            {
                ShowToolTip(ls);
                return;
            }
        }

        Tooltip.Hide();
    }
コード例 #4
0
ファイル: ItemMod.cs プロジェクト: quill18/LD42-PathOfExcess
    static public void MakeItem(LootStats ls, int iLvl, int rarity)
    {
        System.Array values = System.Enum.GetValues(typeof(ItemTypes));

        ItemTypes randomBar = (ItemTypes)values.GetValue(random.Next(values.Length));

        MakeItem(ls, randomBar, iLvl, rarity);
    }
コード例 #5
0
ファイル: BagSlot.cs プロジェクト: quill18/LD42-PathOfExcess
    /// <summary>
    /// Return the "true" bag slot that this item will get placed in,
    /// or null if there's no space here
    /// </summary>
    /// <param name="l"></param>
    /// <returns></returns>
    public BagSlot CanDropHere(Loot l)
    {
        if (Backpack == null)
        {
            // This is char inventory
            LootStats ls = l.GetComponent <LootStats>();
            if (ls.IsIdentified() == false || ls.itemType.ToString() != this.gameObject.name)
            {
                return(null);
            }

            return(this);
        }

        int x = PosX;
        int y = PosY;

        // First, correct if we're too close to the edge

        if (x + l.GridWidth > Backpack.BagWidth)
        {
            x = Backpack.BagWidth - l.GridWidth;
        }
        if (y + l.GridHeight > Backpack.BagHeight)
        {
            y = Backpack.BagHeight - l.GridHeight;
        }

        if (x != PosX || y != PosY)
        {
            // position was corrected, so send job to new tile
            return(Backpack.GetSlotAt(x, y));
        }

        // Correct bag slot, so check that all slots that will be used for this item
        // have at most one other item
        if (Backpack.GetLootsInArea(x, y, l.GridWidth, l.GridHeight).Length > 1)
        {
            // Not a valid tile for placement
            return(null);
        }

        return(this);
    }
コード例 #6
0
ファイル: LootArea.cs プロジェクト: quill18/LD42-PathOfExcess
    public void SpawnLoot(Vector2 pos, int iLevel, int dropRate)
    {
        //Debug.Log("SpawnLoot");
        int luck     = statManager.GetValue(Stats.Luck);
        int numItems = Mathf.CeilToInt((Random.Range(0, dropRate + luck)) / 100f);

        for (int i = 0; i < numItems; i++)
        {
            GameObject lootGO = Instantiate(LootPrefab);
            LootStats  ls     = lootGO.GetComponent <LootStats>();
            ls.iLvl = iLevel;

            int rarityRoll = Random.Range(Mathf.Min(luck, 50), 101 + (luck / 5));

            if (rarityRoll < 70)
            {
                ls.Rarity = 1;
            }
            else if (rarityRoll < 80)
            {
                ls.Rarity = 2;
            }
            else if (rarityRoll < 95)
            {
                ls.Rarity = 3;
            }
            else if (rarityRoll < 97)
            {
                ls.Rarity = 4;
            }
            else if (rarityRoll < 99)
            {
                ls.Rarity = 5;
            }
            else
            {
                ls.Rarity = 6;
            }

            lootGO.transform.SetParent(this.transform);
            lootGO.transform.position = (Vector3)pos;
        }
    }
コード例 #7
0
ファイル: ItemMod.cs プロジェクト: quill18/LD42-PathOfExcess
    static public void MakeItem(LootStats ls, ItemTypes slot, int iLvl, int rarity)
    {
        string         name     = slot.ToString();
        List <ItemMod> itemMods = new List <ItemMod>();

        string image_name = name;
        int    width      = 1;
        int    height     = 1;

        ItemSizeByType(slot, ref width, ref height);

        if (ItemSubTypesBySlot.ContainsKey(slot))
        {
            ItemSubType sub = ItemSubTypesBySlot[slot][Random.Range(0, ItemSubTypesBySlot[slot].Length)];
            name       = sub.Name;
            width      = sub.Width;
            height     = sub.Height;
            image_name = sub.Image;
        }

        int numPrefixes = Random.Range(0, rarity + 1);

        if (slot == ItemTypes.Weapon && numPrefixes == 0)
        {
            numPrefixes = 1;
        }

        int numSuffixes = rarity - numPrefixes;

        if (numPrefixes > 3)
        {
            numSuffixes += numPrefixes - 3;
            numPrefixes  = 3;
        }
        else if (numSuffixes > 3)
        {
            numPrefixes += numSuffixes - 3;
            numSuffixes  = 3;
        }

        List <ItemModChart> legalPrefs = ModsOfLevel(prefixes, iLvl);

        if (slot == ItemTypes.Potion)
        {
            rarity      = 2;
            numPrefixes = 1;
            numSuffixes = 0;

            legalPrefs = ModsOfLevel(PotionPrefixes, iLvl);
        }

        if (slot == ItemTypes.Weapon)
        {
            numPrefixes--;
        }

        for (int i = 0; i < numPrefixes; i++)
        {
            int r     = Random.Range(0, legalPrefs.Count);
            int value = Mathf.CeilToInt(legalPrefs[r].Value * Random.Range(0.5f, 1.0f));

            if (value == 0)
            {
                value = -1;
            }

            itemMods.Add(
                new ItemMod(
                    legalPrefs[r].Stat,
                    value
                    )
                );

            name = legalPrefs[r].Name + " " + name;
            legalPrefs.RemoveAt(r);
        }

        if (slot == ItemTypes.Weapon)
        {
            List <ItemModChart> legalWeaponPrefs = ModsOfLevel(WeaponPrefixes, iLvl);
            int r = Random.Range(0, legalWeaponPrefs.Count);

            itemMods.Add(
                new ItemMod(
                    legalWeaponPrefs[r].Stat,
                    Mathf.CeilToInt(legalWeaponPrefs[r].Value * Random.Range(0.5f, 1.0f))
                    )
                );

            name = legalWeaponPrefs[r].Name + " " + name;
            legalWeaponPrefs.RemoveAt(r);
        }


        List <ItemModChart> legalSuffs = ModsOfLevel(suffixes, iLvl);

        for (int i = 0; i < numSuffixes; i++)
        {
            int r = Random.Range(0, legalSuffs.Count);

            itemMods.Add(
                new ItemMod(
                    legalSuffs[r].Stat,
                    Mathf.CeilToInt(legalSuffs[r].Value * Random.Range(0.5f, 1.0f))
                    )
                );

            if (i == 0)
            {
                name += " of ";
            }
            else
            {
                name += " and ";
            }

            name += legalSuffs[r].Name;

            legalSuffs.RemoveAt(r);
        }


        // Copy all the data into the gameobject
        ls.gameObject.name = name;


        Image img = ls.transform.Find("Image").GetComponent <Image>();

        img.sprite = Resources.Load <Sprite>("ItemGFX/" + image_name);

        if (img.sprite == null)
        {
            Debug.Log("No sprite for: " + "ItemGFX/" + image_name);
        }

        img.color = Random.ColorHSV(0f, 1f, 0f, 0.5f, 0.8f, 1.0f);

        //if(img.sprite!= null)
        //    img.SetNativeSize();
        img.GetComponent <RectTransform>().sizeDelta = new Vector2(50 * width, 50 * height);

        ls.itemType = slot;
        ls.itemMods = itemMods.ToArray();
        ls.Rarity   = rarity;

        Loot loot = ls.GetComponent <Loot>();

        loot.GridWidth  = width;
        loot.GridHeight = height;

        RectTransform rt = ls.GetComponent <RectTransform>();

        rt.sizeDelta = new Vector2(50 * width, 50 * height);
    }