Пример #1
0
    void testBase()
    {
        WeightedBag <int> bag = new WeightedBag <int>(new System.Random());

        bag.add(25, 1);
        bag.add(25, 2);
        bag.add(50, 3);
        Dictionary <int, int> valueRecieve = new Dictionary <int, int>();

        valueRecieve.Add(1, 0);
        valueRecieve.Add(2, 0);
        valueRecieve.Add(3, 0);
        for (int i = 0; i < 1000; i++)
        {
            int value  = bag.next();
            int nbTime = valueRecieve[value] + 1;
            valueRecieve.Remove(value);
            valueRecieve.Add(value, nbTime);
        }

        Debug.Log("Test base");
        foreach (var keyvalue in valueRecieve)
        {
            Debug.Log(keyvalue.Key + " : " + keyvalue.Value);
        }
    }
Пример #2
0
 public void GeneratePoolItems()
 {
     itemPool = new WeightedBag();
     foreach (string itemName in allItems.Keys)
     {
         if (allItems[itemName].unlocked)
         {
             itemPool.AddElement(itemName, 1f / allItems[itemName].goldValue);
         }
     }
 }
Пример #3
0
    void testBase()
    {
        WeightedBag<int> bag = new WeightedBag<int>(new System.Random());
        bag.add(25,1);
        bag.add(25,2);
        bag.add(50,3);
        Dictionary<int,int> valueRecieve = new Dictionary<int, int>();
        valueRecieve.Add(1,0);
        valueRecieve.Add(2,0);
        valueRecieve.Add(3,0);
        for (int i = 0; i < 1000; i++) {
            int value = bag.next();
            int nbTime = valueRecieve[value] + 1 ;
            valueRecieve.Remove(value);
            valueRecieve.Add(value, nbTime);
        }

        Debug.Log("Test base");
        foreach (var keyvalue in valueRecieve) {
            Debug.Log(keyvalue.Key + " : " + keyvalue.Value);
        }
    }
Пример #4
0
    public void NewGame()
    {
        if (currentScene != null)
        {
            currentScene.SetActive(false);
        }
        deathScene.SetActive(false);
        myLootHandler.followerTab.transform.Find("TextBackground").Find("Text").GetComponent <Text>().text = "";
        sceneProb = new WeightedBag();

        thePlayer = new Player();
        initializePlayer();
        myCombatHandler.thePlayer  = thePlayer; myCombatHandler.levelConfront = 0; myCombatHandler.mobPool = new WeightedBag();
        myUpgradeHandler.thePlayer = thePlayer;
        myLootHandler.thePlayer    = thePlayer;

        sceneProb.AddElement("Heal", 0f); sceneProb.AddElement("Upgrade", 0f);

        //currentScene = upgradeScene;
        //upgradeScene.SetActive(true);
        //myUpgradeHandler.InitUpgradeScene();
        nextScene = "Confront";
        CheckSpecialEvent();
    }
Пример #5
0
    public void ResolveEvent(TriggerContent theEvent, GameObject target)
    {
        for (int i = 0; i < theEvent.effectNames.Count; i++)
        {
            string theText;

            switch (theEvent.effectNames[i])
            {
            // COMMENTARY EVENTS
            case "Pool_commentary":
                aBag = new WeightedBag();
                for (int j = 0; j < theEvent.effectData.Count; j++)
                {
                    aBag.AddElement(theEvent.effectData[j], theEvent.effectValues[j] / 100f);
                }

                theText = aBag.Draw(true);
                if (theText != "nothing")
                {
                    target.transform.Find("TextBackground").Find("Text").GetComponent <Text>().text += theText + "\n"; target.SetActive(true);
                }
                else
                {
                    target.SetActive(false);
                }
                break;

            case "Commentary":
                target.transform.Find("TextBackground").Find("Text").GetComponent <Text>().text += theEvent.effectData[i] + "\n";
                target.SetActive(true);
                break;

            case "Commentary_Variable":
                List <string> copyText = new List <string>(); theEvent.effectData.ForEach(x => copyText.Add(x));
                theText = DecodeString(copyText);
                target.transform.Find("TextBackground").Find("Text").GetComponent <Text>().text += theText + "\n";

                target.SetActive(true);
                break;

            case "Increment_counter":
                myData.allCounters[theEvent.effectData[i]].count += (int)theEvent.effectValues[i];
                myData.StoreCounters();

                ExecuteFromTrigger("Incremented_" + theEvent.effectData[i], target);
                break;

            case "Set_counter":
                myData.allCounters[theEvent.effectData[i]].count = (int)theEvent.effectValues[i];
                myData.StoreCounters();
                break;

            // EVENTS
            case "Special_Event":
                eventData = theEvent.effectData;
                GetComponent <GameHandler>().specialEvent = true;
                break;

            case "Force_encounter":
                CharacterContent encounter = new CharacterContent(myData.allMobs[theEvent.effectData[i]]);

                encounter.myName = theEvent.effectData[i + 1];   // dangerous... an encounter can be force-set without name change
                GetComponent <ConfrontationHandler>().forceEncounter = encounter;
                break;

            case "Force_loot":
                GetComponent <LootHandler>().forceLoot = theEvent.effectData[i];
                break;

            case "Pool_triggerEvent":
                aBag = new WeightedBag();
                for (int j = 0; j < theEvent.effectData.Count; j++)
                {
                    aBag.AddElement(theEvent.effectData[j], theEvent.effectValues[j] / 100f);
                }

                theText = aBag.Draw(true);
                ResolveEvent(myData.allEvents[theText], target);
                break;

            // TOOLS
            case "Activate":
                SetEventActive(theEvent.effectData[i], true);
                break;

            case "Deactivate":
                SetEventActive(theEvent.effectData[i], false);
                break;

            case "Deactivate_quest":
                foreach (string elt in myData.allEvents.Keys.ToList())
                {
                    if (elt.Contains(theEvent.effectData[i]))
                    {
                        SetEventActive(elt, false);
                    }
                }
                break;

            case "Unlock_enemy":
                UnlockEnemy(theEvent.effectData[i]);
                break;

            case "Unlock_item":
                UnlockItem(theEvent.effectData[i]);
                break;
            }
        }
    }