Exemplo n.º 1
0
    void CreateLevel()
    {
        List <int> costs = new List <int>();

        for (int i = 0; i < Bazaar.childCount; i++)
        {
            List <int> thisCosts    = new List <int>();
            NPC        npc          = Bazaar.GetChild(i).GetComponent <NPC>();
            int        invetorySize = Random.Range(4, 9);

            if (i != 4)
            {
                int price     = i == 0 || i == 5 ? 15 : 5;
                int minRange  = i == 1 ? 1 : 0;
                int maxrange  = i == 3 ? 2 : 3;
                int extraSize = Random.Range(minRange, maxrange);
                for (int j = 0; j < extraSize; j++)
                {
                    string s;
                    int    c;
                    int    trial = 0;
                    do
                    {
                        int index = Random.Range(0, 18);
                        s = npc.Data.ItemList[index];
                        c = npc.Data.ItemValues[index];
                    } while ((npc.Contains(s) || c >= price) && trial++ < 197);
                    if (!npc.Contains(s) && s != "" && c < price)
                    {
                        npc.AddItem(s, c, true);
                    }
                }
            }

            for (int j = 0; j < invetorySize; j++)
            {
                int    randomCost;
                bool   flag = false;
                string s    = "";
                int    c    = 0;
                if (costs.Count > 0 && Random.value < 0.5f)
                {
                    randomCost = costs[Random.Range(0, costs.Count - 1)];
                    for (int k = 0; k < 19; k++)
                    {
                        if (npc.Data.ItemValues[k] - randomCost < 3 && npc.Data.ItemValues[k] - randomCost > 0 && !npc.Contains(npc.Data.ItemList[k]))
                        {
                            flag = true;
                            s    = npc.Data.ItemList[k];
                            c    = npc.Data.ItemValues[k];
                            costs.Remove(randomCost);
                            break;
                        }
                    }
                }
                if (!flag)
                {
                    do
                    {
                        int index = Random.Range(0, 18);
                        s = npc.Data.ItemList[index];
                        c = npc.Data.ItemValues[index];
                    } while (npc.Contains(s));
                }

                if (!npc.Contains(s))
                {
                    npc.AddItem(s, c);
                    thisCosts.Add(c);
                }
            }
            costs.AddRange(thisCosts);
            thisCosts.Clear();
        }

        List <string> needs = new List <string>();

        for (int i = 0; i < Bazaar.childCount; i++)
        {
            if (i == 4)
            {
                continue;
            }
            NPC npc       = Bazaar.GetChild(i).GetComponent <NPC>();
            int minRange  = i == 2 ? 2 : 1;
            int maxrange  = i == 3 ? 3 : 2;
            int needCount = Random.Range(minRange, maxrange);
            for (int j = 0; j < needCount; j++)
            {
                int bazaarElement;
                do
                {
                    bazaarElement = Random.Range(0, Bazaar.childCount - 1);
                } while (bazaarElement == i);
                string s;
                do
                {
                    s = Bazaar.GetChild(bazaarElement).GetComponent <NPC>().RandomItem();
                } while (npc.IsNeeded(s) || needs.Contains(s));
                if (!npc.IsNeeded(s) && s != "" && !needs.Contains(s))
                {
                    npc.AddNeed(s);
                    needs.Add(s);
                }
            }
        }
    }