public static void ShowRewardedAd(System.Action <RemakeShowResult> showResultHandler)
 {
     ShowAd(Singleton.rewardVideoPlacement, (result) =>
     {
         if (result == RemakeShowResult.Finished)
         {
             var randomizer = WeightedRandomizer.From(AdsRewards);
             var reward     = randomizer.TakeOne();
             if (OverrideSaveAdsReward != null)
             {
                 // Custom save ads reward function
                 OverrideSaveAdsReward.Invoke(reward);
             }
             else
             {
                 // Default save ads reward function
                 DefaultSaveAdsReward(reward);
             }
         }
         if (showResultHandler != null)
         {
             showResultHandler.Invoke(result);
         }
     });
 }
Beispiel #2
0
 public static void ShowRewardedAd(System.Action <RemakeShowResult> showResultHandler)
 {
     ShowAd(Singleton.rewardVideoPlacement, (result) =>
     {
         if (result == RemakeShowResult.Finished)
         {
             var randomizer = WeightedRandomizer.From(AdsRewards);
             var reward     = randomizer.TakeOne();
             var currencies = reward.currencies;
             foreach (var currency in currencies)
             {
                 Save.AddCurrency(currency.id, currency.amount);
             }
             var items = reward.items;
             foreach (var item in items)
             {
                 Save.AddPurchasedItem(item.name);
             }
         }
         if (showResultHandler != null)
         {
             showResultHandler(result);
         }
     });
 }
Beispiel #3
0
    private void SpawnCustomer()
    {
        GameObject selected;

        // Select a random customer is list by chance
        if (customersToSpawn.Length == 1)
        {
            selected = customersToSpawn[0].customerPrefab;
        }
        else if (customersToSpawn.Length > 1)
        {
            Dictionary <GameObject, int> weights = new Dictionary <GameObject, int>();

            for (int i = 1; i < customersToSpawn.Length; i++)
            {
                weights.Add(customersToSpawn[i].customerPrefab, customersToSpawn[i].chancesOfSpawning);
            }

            selected = WeightedRandomizer.From(weights).TakeOne();
        }
        else
        {
            Debug.LogError("There are no customers to spawn in the GameManager!", gameObject);
            return;
        }

        // Spawn selected customer
        _mapManager.GetRandomCustomerSpawner().SpawnCustomer(selected);
    }
Beispiel #4
0
    // Start is called before the first frame update
    void Start()
    {
        myDictionary = new Dictionary <GameObject, int>();
        foreach (var entry in toSpawn)
        {
            myDictionary.Add(entry.key, entry.value);
        }

        GameObject objectToSpawn = WeightedRandomizer.From(myDictionary).TakeOne();

        GameObject actualObject = null;

        if (whereToSpawn != null)
        {
            actualObject = Instantiate(objectToSpawn, whereToSpawn.position, Quaternion.identity);
        }
        else
        {
            actualObject = Instantiate(objectToSpawn, transform.position, Quaternion.identity);
        }

        if (createAsChild)
        {
            actualObject.transform.parent = transform;
        }
    }
    public IEnumerator Spawn(int amount)
    {
        EnemyTracker.InitializeNewWave(amount);
//        Game.Hud.remainingEnemies.text = "Remaining enemies: " + amount;


        for (var i = 0; i < amount; i++)
        {
            var spawnIndex = Random.Range(0, _spawnPositions.Length);

            yield return(new WaitForSeconds(1 / Game.Controller.currentWave));

            var enemy = Instantiate
                        (
                WeightedRandomizer.From(_enemies).TakeOne(),
                _spawnPositions[spawnIndex].position,
                Quaternion.identity,
                enemyContainer
                        );

            enemy.name             = enemy.enemyName;
            enemy.currentWaveIndex = i;

            EnemyTracker.Enemies[i] = enemy;

            yield return(new WaitForSeconds(spawnRate));
        }
    }
Beispiel #6
0
    private GameObject GetDrop(List <ItemDropWeight> item_weights)
    {
        Dictionary <GameObject, int> weights = new Dictionary <GameObject, int>();

        item_weights.ForEach(x => weights.Add(x.prefab, x.weight));
        return(WeightedRandomizer.From(weights).TakeOne());
    }
Beispiel #7
0
        //public List<BlockModel> generateThisRow = new List<BlockModel>();
        #endregion

        #region Private Fields
        #endregion

        #region Getters/Setters/Constructors
        #endregion

        #region My Methods
        public void GenerateBlockZone(BlockZone blockZone, int offset)
        {
            // Adding +1 to the offset so that the next blockzone doesn't overlap with the last row of the last blockzone.
            for (int yPosition = offset + 1; yPosition <= offset + blockZone.LowYPosition; yPosition++)
            {
                for (int xPosition = blockZone.LowXPosition; xPosition <= blockZone.HighXPosition; xPosition++)
                {
                    BlockModel model =
                        BlockModelFactory
                        .Start()
                        .WithBlockType(WeightedRandomizer.From(blockZone.BlockProbability).TakeOne())
                        .WithPosition(xPosition, yPosition)
                        .WithBlockLevelFromBlockType()
                        .WithBlockExperienceFromBlockType()
                        .WithBlockHPFromBlockType()
                        .WithBlockDefenseFromBlockType()
                        .Finish();

                    //Debug.Log($"{model.BlockType.BlockName}");
                    if (model.BlockType.BlockName != "BLANK")
                    {
                        blockModels.Add(model);
                    }
                }
            }
        }
Beispiel #8
0
 private void InitCaches()
 {
     if (cacheHarvestEffectivenesses == null || cacheHarvestItems == null)
     {
         cacheHarvestEffectivenesses = new Dictionary <WeaponType, HarvestEffectiveness>();
         cacheHarvestItems           = new Dictionary <WeaponType, WeightedRandomizer <ItemDropByWeight> >();
         foreach (var harvestEffectiveness in harvestEffectivenesses)
         {
             if (harvestEffectiveness.weaponType != null && harvestEffectiveness.damageEffectiveness > 0)
             {
                 cacheHarvestEffectivenesses[harvestEffectiveness.weaponType] = harvestEffectiveness;
                 var harvestItems = new Dictionary <ItemDropByWeight, int>();
                 foreach (var item in harvestEffectiveness.items)
                 {
                     if (item.item == null || item.amountPerDamage <= 0 || item.randomWeight <= 0)
                     {
                         continue;
                     }
                     harvestItems[item] = item.randomWeight;
                 }
                 cacheHarvestItems[harvestEffectiveness.weaponType] = WeightedRandomizer.From(harvestItems);
             }
         }
     }
 }
        private void DrawDayPriorityGenericConversations()
        {
            //        print(AllConversations.Count);
            DayPriorityGenericConversations = new List <Conversation>();
            Dictionary <Conversation, int> priority1 = new Dictionary <Conversation, int>();

            foreach (Conversation conversation in AllConversations)
            {
                if (CheckIfGeneric(conversation) == false)
                {
                    //               print("Not generic");
                    continue;
                }
                if (conversation.LookupInt("Priority") == 0)
                {
                    //               print("Priority<1");
                    continue;
                }

                if (conversation.LookupInt("Priority") == 2)
                {
                    //               print("Priority 2. Adding.");
                    DayPriorityGenericConversations.Add(conversation);
                    continue;
                }
                else if (conversation.LookupInt("Priority") == 1)
                {
                    //              print("Adding to priority 1 list");
                    priority1.Add(conversation, conversation.LookupInt("Weight"));
                    continue;
                }
            }

            int amt = MaxGenPrioConvos - DayPriorityGenericConversations.Count;

            if (amt < 0)
            {
                amt = 0;
            }
            //      print("Getting priority 1: " + amt);
            for (int i = 0; i < amt; i++)
            {
                if (priority1.Count > 0)
                {
                    Conversation conversation = WeightedRandomizer.From(priority1).TakeOne();
                    DayPriorityGenericConversations.Add(conversation);
                    priority1.Remove(conversation);
                    //               print("Adding conversation to priority generic list.");
                }
                else
                {
                    //               print("No more eligible conversations");
                    break;
                }
            }
            //        print("Generic priority conversations: " + DayPriorityGenericConversations.Count);
        }
Beispiel #10
0
    public LootBoxReward RandomReward()
    {
        var weight = new Dictionary <LootBoxReward, int>();

        foreach (var lootboxReward in lootboxRewards)
        {
            weight.Add(lootboxReward, lootboxReward.randomWeight);
        }
        return(WeightedRandomizer.From(weight).TakeOne());
    }
Beispiel #11
0
    public StageRandomFoe RandomFoes()
    {
        var weight = new Dictionary <StageRandomFoe, int>();

        foreach (var randomFoe in randomFoes)
        {
            weight.Add(randomFoe, randomFoe.randomWeight);
        }
        return(WeightedRandomizer.From(weight).TakeOne());
    }
        public string CreateCompetitor(string pName, BlossomData.BlossomGrowth pGrowth, float pMinStrength, float pMaxStrength, float pMinAgility,
                                       float pMaxAgility, float pMinIntellect, float pMaxIntellect, float pMinCharm, float pMaxCharm, int pMinAffection = -1, int pMaxAffection = 1)
        {
            //CREATE BLOSSOM
            BlossomData newBlossom = Instantiate(BlossomPrefab, transform);

            newBlossom.ID = "Blossom" + CurrentBlossomID.ToString();
            string ID = newBlossom.ID;

            CurrentBlossomID += 1;
            //newBlossom.Age = pAge;
            newBlossom.Name    = pName;
            newBlossom.Parent1 = string.Empty;
            newBlossom.Parent2 = string.Empty;
            newBlossom.Growth  = pGrowth;
            newBlossom.Energy  = 2;

            //STATS
            //Agility
            newBlossom.Agility.Value = Random.Range(pMinAgility, pMaxAgility);

            //Strength
            newBlossom.Strength.Value = Random.Range(pMinStrength, pMaxStrength);

            //Intellect
            newBlossom.Intellect.Value = Random.Range(pMinIntellect, pMaxIntellect);

            //Charm
            newBlossom.Charm.Value = Random.Range(pMinCharm, pMaxCharm);

            newBlossom.CurrentLevel = string.Empty;

            newBlossom.transform.position = Vector2.zero;

            //ExistingBlossoms.Add(newBlossom.ID);

            BlossomColor[]           allColors = Resources.LoadAll <BlossomColor>("BlossomColors");
            Dictionary <string, int> colorPool = new Dictionary <string, int>();

            foreach (BlossomColor color in allColors)
            {
                colorPool.Add(color.Name, color.Probability);
            }
            newBlossom.Color = WeightedRandomizer.From(colorPool).TakeOne();


            if (pMinAffection != -1 && pMaxAffection != -1 && pMaxAffection >= pMinAffection)
            {
                int affection = Random.Range(pMinAffection, pMaxAffection);
                newBlossom.Affection = affection;
            }
            //DESTROY OBJECT, THIS WILL SAVE DATA
            Destroy(newBlossom.gameObject);
            return(ID);
        }
//	void GetEligibleConversations(Character character){
//
//		EligibleConversations.Clear ();
//		List<Conversation> conversations = new List<Conversation>();
//
//		if (conversations.Count>0) {
//			foreach(Conversation conversation in conversations){
//				if (conversation.CheckConditions () == true) {
//					if (!character.SaidToday.Contains (conversation)) {
//						EligibleConversations.Add (conversation);
//					}
//				}
//			}
//			if (EligibleConversations.Count < 1) {
//				character.SaidToday.Clear ();
//				foreach(Conversation conversation in conversations){
//					if (conversation.CheckConditions () == true) {
//						EligibleConversations.Add (conversation);
//					}
//				}
//			}
//		}
//
//	}
//
//	void GetEligibleConversations(Character character, ConversationTypes pType){
//		EligibleConversations.Clear ();
//		List<Conversation> conversations = new List<Conversation>();
//		switch (pType) {
//		case ConversationTypes.Greeting:
//			conversations = character.Greetings;
//			break;
//		case ConversationTypes.Meeting:
//			conversations = character.Meetings;
//			break;
//		case ConversationTypes.Normal:
//			conversations = character.Conversations;
//			break;
//		default:
//			break;
//		}
//		if (conversations.Count>0) {
//			foreach(Conversation conversation in conversations){
//				if (conversation.CheckConditions () == true) {
//					if (!character.SaidToday.Contains (conversation)) {
//						EligibleConversations.Add (conversation);
//					}
//				}
//			}
//			if (EligibleConversations.Count < 1) {
//				character.SaidToday.Clear ();
//				foreach(Conversation conversation in conversations){
//					if (conversation.CheckConditions () == true) {
//							EligibleConversations.Add (conversation);
//					}
//				}
//			}
//		}
//
//	}


    Conversation GetSingleConversation()
    {
        var weights = new Dictionary <Conversation, int> ();

        foreach (Conversation conversation in EligibleConversations)
        {
//			weights.Add (conversation, conversation.Weight);
        }

        return(WeightedRandomizer.From(weights).TakeOne());
    }
    void Start()
    {
        myDictionary = new Dictionary <GameObject, int>();
        foreach (var entry in toSpawn)
        {
            myDictionary.Add(entry.key, entry.value);
        }

        GameObject objectToSpawn = WeightedRandomizer.From(myDictionary).TakeOne();

        Instantiate(objectToSpawn, transform.position, Quaternion.identity);
    }
Beispiel #15
0
    public AdsReward RandomReward()
    {
        var cacheRewards = new Dictionary <AdsReward, int>();

        foreach (var reward in rewards)
        {
            cacheRewards[reward] = reward.randomWeight;
        }
        var randomizer = WeightedRandomizer.From(cacheRewards);

        return(randomizer.TakeOne());
    }
Beispiel #16
0
    private IEnumerator RepeatSummoning()
    {
        while (GlobalValues.gameIsActive)
        {
            yield return(new WaitForSeconds(respawnTime));

            var weights = new Dictionary <AvailableMonsters, int>();
            weights.Add(AvailableMonsters.Skeleton, 80);
            weights.Add(AvailableMonsters.Werewolf, 15);
            weights.Add(AvailableMonsters.Ogre, 5);

            AvailableMonsters selectedMonster = WeightedRandomizer.From(weights).TakeOne(); d
            StartCoroutine(SummonMonster(monsterList[(int)selectedMonster], respawnPoints[Random.Range(0, respawnPoints.Count)]));
        }
    }
Beispiel #17
0
    int SetUnitIVs()
    {
        var boonBaneChances = new Dictionary <int, int>();

        boonBaneChances.Add(0, 60);    // 60% chance to return a buff of 0
        boonBaneChances.Add(3, 16);    // 16% chance to return a buff of positive 3
        boonBaneChances.Add(-3, 16);   // 16% chance to return a buff of negative 3
        boonBaneChances.Add(4, 3);     // 3% chance etc
        boonBaneChances.Add(-4, 3);    // 3% chance etc
        boonBaneChances.Add(5, 1);     // 1% chance etc
        boonBaneChances.Add(-5, 1);    // 1% chance etc

        // This will go through the boonBanes and pick one. The percentages mean that something 50% is 50% more like to be picked than something with 4%
        return(WeightedRandomizer.From(boonBaneChances).TakeOne());
    }
Beispiel #18
0
    //custom skill logic


    public void RandomAction()
    {
        // Random Action
        // Dictionary of actionId, weight
        Dictionary <string, int> actions = new Dictionary <string, int>();

        actions.Add(Const.NormalAttack, 5);
        foreach (string key in self.Item.GetCustomSkills().Keys)
        {
            var skill = self.Item.GetCustomSkills()[key];
            if (skill == null || !skill.CanUse())
            {
                continue;
            }
            actions.Add(key, 5);
        }
        self.Action = WeightedRandomizer.From(actions).TakeOne();
        // Random Target
        if (self.Action == Const.NormalAttack)
        {
            var foes = self.Manager.GetFoes(self);
            Random.InitState(System.DateTime.Now.Millisecond);
            self.ActionTarget = foes[Random.Range(0, foes.Count - 1)] as CharacterEntity;
        }
        else
        {
            switch (self.SelectedCustomSkill.usageScope)
            {
            case CustomSkill.SkillUsageScope.Enemy:
                var foes = self.Manager.GetFoes(self);
                Random.InitState(System.DateTime.Now.Millisecond);
                self.ActionTarget = foes[Random.Range(0, foes.Count)] as CharacterEntity;
                break;

            case CustomSkill.SkillUsageScope.Ally:
                var allies = self.Manager.GetAllies(self);
                Random.InitState(System.DateTime.Now.Millisecond);
                self.ActionTarget = allies[Random.Range(0, allies.Count)] as CharacterEntity;
                break;

            default:
                self.ActionTarget = null;
                break;
            }
        }
        DoAction();
    }
Beispiel #19
0
    private IEnumerator SimulateEvent()
    {
        yield return(new WaitForSeconds(5));

        while (true)
        {
            RemoveDeadEvents();
            if (events.Count > 0)
            {
                Event ev = WeightedRandomizer.From(events).TakeOne();
                events.Remove(ev);
                PerformEvent(ev);
            }

            yield return(new WaitForSeconds(EventFrequency));
        }
    }
Beispiel #20
0
    public void PerformCombatAction()
    {
        TakeDotDamage();
        EnemyAbility ab = WeightedRandomizer.From(enemyData.EnemyAbilities).TakeOne();

        abName = ab.Name;
        Invoke(nameof(UpdateText), 1);

        if (ab.MinHeal > 0)
        {
            EnemyBehavior enemyToHeal = Game.CurrentCombatSystem.Enemies.First(e => e.health == Game.CurrentCombatSystem.Enemies.Max(b => b.health));
            enemyToHeal.ReceiveHealing(Random.Range(ab.MinHeal, ab.MaxHeal));
        }

        if (ab.MinDamage > 0)
        {
            this.ApplyDamage(Random.Range(ab.MinDamage, ab.MaxDamage + 1), Game.Player, ab.ArmorPiercing);
        }

        if (ab.MinBlock > 0)
        {
            this.IncreaseShield(Random.Range(ab.MinBlock, ab.MaxBlock));
        }

        if (ab.Stun)
        {
            Game.Player.stunned = true;
        }

        if (ab.DamageReduction > 0)
        {
            this.ApplyDamageDebuff(-ab.DamageReduction, Game.Player);
        }

        if (ab.SelfDamage > 0)
        {
            this.ReceiveDamage(ab.SelfDamage);
        }

        if (ab.Dot)
        {
            this.ReceiveDot(ab.DotDamage, ab.Time);
        }

        UpdateBars();
    }
Beispiel #21
0
    public void Generate()
    {
        transform.DestroyChildren(true);
        foreach (var _prefabCollection in prefabs)
        {
            if (!weights.ContainsKey(_prefabCollection.prefab))
            {
                weights.Add(_prefabCollection.prefab, _prefabCollection.weight);
            }
        }

        GameObject selected = WeightedRandomizer.From(weights).TakeOne();

        foreach (var _prefabCollection in prefabs)
        {
            if (_prefabCollection.prefab.name.Equals(selected.name))
            {
                if (_prefabCollection.childPrefabs == null)
                {
                    break;
                }

                foreach (var _childPrefabs in _prefabCollection.childPrefabs)
                {
                    Dictionary <GameObject, int> childWeights = new Dictionary <GameObject, int>();
                    foreach (var _childPrefabCollection in _childPrefabs.childPrefabCollection)
                    {
                        if (!childWeights.ContainsKey(_childPrefabCollection.prefab))
                        {
                            childWeights.Add(_childPrefabCollection.prefab, _childPrefabCollection.weight);
                        }
                    }
                    this.childWeights.Add(childWeights);
                }
            }
        }
        GameObject PrefabCollec = (GameObject)Instantiate(selected, transform.position, transform.rotation, transform);

        foreach (var _childPrefabCollection in childWeights)
        {
            GameObject selectedChild     = WeightedRandomizer.From(_childPrefabCollection).TakeOne();
            GameObject PrefabCollecChild = (GameObject)Instantiate(selectedChild, transform.position, transform.rotation, PrefabCollec.transform);
        }
        childWeights.Clear();
    }
        private void DrawDayGenericConversations()
        {
            DayGenericConversations = new List <Conversation>();
            Dictionary <Conversation, int> generic = new Dictionary <Conversation, int>();

            foreach (Conversation conversation in AllConversations)
            {
                //            print(conversation.Title);
                if (CheckIfGeneric(conversation) == false)
                {
                    //                print("Not generic");
                    continue;
                }
                if (conversation.LookupInt("Priority") != 0)
                {
                    //                print("Priority>0");
                    continue;
                }
                generic.Add(conversation, conversation.LookupInt("Weight"));
                //           print("Add to generic: " + conversation.Title);
            }

            int amt = maxGenConvos - DayGenericConversations.Count;

            if (amt < 0)
            {
                amt = 0;
            }
            //       print("Adding conversations: " + amt);
            for (int i = 0; i < amt; i++)
            {
                if (generic.Count < 1)
                {
                    //               print("No more eligible conversations");
                    break;
                }
                Conversation conversation = WeightedRandomizer.From(generic).TakeOne();
                DayGenericConversations.Add(conversation);
                // AllConversations.Remove(conversation);
                generic.Remove(conversation);
                //            print("Adding to list");
            }
            //       print("Generated generic conversations for the day: " + DayGenericConversations.Count);
        }
Beispiel #23
0
    public void DropLoot(Vector3 position)
    {
        // 1 in 5 chance of winning a prize!
        if (Random.Range(0, 1f) > _chanceOfDrop)
        {
            return;
        }

        position.y = 0; // HACKY :D
        var copy    = Instantiate(_lootBoxPrefab, position, Quaternion.identity);
        var lootBox = copy.GetComponent <LootBox>();

        lootBox._loot = Instantiate(WeightedRandomizer.From(_weighted).TakeOne());

        var visual     = lootBox._loot.GetComponent <LootDropMonoBehaviour>()._containerPrefab;
        var visualCopy = Instantiate(visual, lootBox.transform);

        visualCopy.transform.localPosition = Vector3.zero;
    }
Beispiel #24
0
    public void SetupRoom(RoomSetupProperties properties)
    {
        var player = PlayerCharacter.GetPlayerCharacter();
        var desired_spawn_location = GetOppositeDirection(properties.enter_from);
        var player_spawn_points    = GetComponentsInChildren <PlayerSpawn>().ToList();
        var player_spawn           = player_spawn_points.Find((x) => x.spawn_direction == desired_spawn_location);

        if (player_spawn == null)
        {
            player_spawn = player_spawn_points[0];
        }
        player.transform.position = player_spawn.transform.position;

        if (enemy_types.Count == 0)
        {
            Debug.LogError("NEED TO SET ENEMY WEIGHTS IN ROOM!");
            return;
        }
        Dictionary <GameObject, int> enemy_spawn_dict = new Dictionary <GameObject, int>();

        enemy_types.ForEach((enemy) => { enemy_spawn_dict.Add(enemy.enemy_prefab, enemy.weight); });
        var enemy_weighted_random = WeightedRandomizer.From(enemy_spawn_dict);
        var enemy_spawn_points    = GetComponentsInChildren <EnemySpawn>().ToList();

        enemy_spawn_points.ForEach((EnemySpawn spawn) => {
            var enemy_type     = enemy_weighted_random.TakeOne();
            var enemy_instance = Instantiate <GameObject>(enemy_type, spawn.transform);
            // make new spawns objectives in order to exit room
            enemy_instance.AddComponent <ObjectiveEnemy>();
            var ai_brain = enemy_instance.GetComponent <AIBrain>();
            // disable AI at start
            ai_brain.EnableBrain(false);
            var distance_to_player = Vector3.Distance(enemy_instance.transform.position, player.gameObject.transform.position);
            if (distance_to_player >= 10f)
            {
                ai_brain.SetEnableOnDistanceOrDamage();
            }
        });
        // @TODO: iterate over AI and set "wake nearby" on wake...

        room_setup_complete = true;
    }
Beispiel #25
0
        public static Worker GenerateRandomWorker()
        {
            Random     rand    = new Random();
            RandomName nameGen = new RandomName(rand);
            var        worker  = new Worker()
            {
                Name = nameGen.Generate((Sex)rand.Next(0, 2), rand.Next(0, 2)), Cost = 2000
            };
            var weights = new Dictionary <int, int>()
            {
                { 1, 40 },
                { 2, 40 },
                { 3, 15 },
                { 4, 4 },
                { 5, 1 },
            };

            worker.Efficiency = WeightedRandomizer.From(weights).TakeOne();
            return(worker);
        }
 public static void ShowAd(string placement, System.Action <RemakeShowResult> showResultHandler)
 {
     ShowResultCallbacks[placement] = showResultHandler;
     if (Singleton.adsOverrideActions != null && Singleton.adsOverrideActions.Count > 0)
     {
         Dictionary <ShowAdOverrideAction, int> randomActions = new Dictionary <ShowAdOverrideAction, int>();
         foreach (var overrideAction in Singleton.adsOverrideActions)
         {
             if (overrideAction.placement.Equals(placement))
             {
                 randomActions[overrideAction] = overrideAction.weight;
             }
         }
         if (randomActions.Count > 0)
         {
             var randomizer = WeightedRandomizer.From(randomActions);
             randomizer.TakeOne().action.Invoke(placement);
             return;
         }
     }
     Singleton.DefaultShowAdFunction(placement);
 }
    public void Random()
    {
        var gameplay = GameplayManager.Singleton;
        var dict     = new Dictionary <CharacterAttributes, int>();
        var list     = gameplay.attributes.Values.ToList();

        foreach (var entry in list)
        {
            dict.Add(entry, entry.randomWeight);
        }

        for (var i = 0; i < randomAttributes.Length; ++i)
        {
            var randomAttribute = randomAttributes[i];
            if (randomAttribute != null)
            {
                var randomedAttribute = WeightedRandomizer.From(dict).TakeOne();
                randomAttribute.SetAttribute(randomedAttribute);
                dict.Remove(randomedAttribute);
            }
        }
    }
Beispiel #28
0
    public void Hit()
    {
        if (TriesToday >= TriesPerDay)
        {
            DialogueManager.ShowAlert("Enough for today");
            return;
        }
        ItemTool tool = ToolManager.Instance.CurrentTool;

        if (RequiredToolLevel > tool.Level)
        {
            DialogueManager.ShowAlert("My tool needs to be stronger");

            return;
        }
        Vector3 position = transform.position;

        position.z -= 0.0001f;
        ParticleSpawner.Instance.SpawnOneShot(Particle, position);

        TriesToday += 1;
        var weights = new Dictionary <ItemBase, int>();


        foreach (VeinItem item in ItemOutputs)
        {
            weights.Add(item.ContainedItem, item.Probability);
        }

        ItemBase pickedItem = WeightedRandomizer.From(weights).TakeOne();

        if (pickedItem != null)
        {
            ItemSpawner.Instance.SpawnItems(pickedItem, SpawnPoint.position);
        }
    }
        public string CreateStarterBlossom()
        {
            string name       = GetRandomBlossomName();
            string newBlossom = CreateRandomBlossom(name, BlossomData.BlossomGrowth.Baby, 20, 20, 0.5f, 0.5f, 0, 1, 2, string.Empty, new Vector2(0, 0), false);

            Dictionary <string, int> colorPool = new Dictionary <string, int>();
            BlossomColor             blue      = Resources.Load <BlossomColor>("BlossomColors/Blue");

            colorPool.Add(blue.Name, blue.Probability);
            BlossomColor red = Resources.Load <BlossomColor>("BlossomColors/Red");

            colorPool.Add(red.Name, red.Probability);
            BlossomColor yellow = Resources.Load <BlossomColor>("BlossomColors/Yellow");

            colorPool.Add(yellow.Name, yellow.Probability);
            BlossomColor green = Resources.Load <BlossomColor>("BlossomColors/Green");

            colorPool.Add(green.Name, green.Probability);

            string color = WeightedRandomizer.From(colorPool).TakeOne();

            DialogueLua.SetVariable(newBlossom + "Color", color);
            //STAT POTENTIAL BONUS DISTRIBUTION
            for (int potentialBonus = 30; potentialBonus > 0; potentialBonus--)
            {
                List <string> availableStats = new List <string>();
                if (DialogueLua.GetVariable(newBlossom + "AgilityPotential").asFloat < 40)
                {
                    availableStats.Add("AgilityPotential");
                }
                if (DialogueLua.GetVariable(newBlossom + "StrengthPotential").asFloat < 40)
                {
                    availableStats.Add("StrengthPotential");
                }
                if (DialogueLua.GetVariable(newBlossom + "IntellectPotential").asFloat < 40)
                {
                    availableStats.Add("IntellectPotential");
                }
                if (DialogueLua.GetVariable(newBlossom + "CharmPotential").asFloat < 40)
                {
                    availableStats.Add("CharmPotential");
                }
                if (availableStats.Count > 0)
                {
                    int   rand       = Random.Range(0, availableStats.Count);
                    float currentVal = DialogueLua.GetVariable(newBlossom + availableStats[rand]).asFloat;
                    DialogueLua.SetVariable(newBlossom + availableStats[rand], currentVal + 1);
                }
                else
                {
                    break;
                }
            }

            //STAT LEARNING SPEED BONUS DISTRIBUTION
            for (int learningSpeedBonus = 5; learningSpeedBonus > 0; learningSpeedBonus--)
            {
                List <string> availableStats = new List <string>();

                availableStats.Add("AgilityLearningSpeed");
                availableStats.Add("StrengthLearningSpeed");
                availableStats.Add("IntellectLearningSpeed");
                availableStats.Add("CharmLearningSpeed");

                if (availableStats.Count > 0)
                {
                    int   rand       = Random.Range(0, availableStats.Count);
                    float currentVal = DialogueLua.GetVariable(newBlossom + availableStats[rand]).asFloat;
                    DialogueLua.SetVariable(newBlossom + availableStats[rand], currentVal + 0.1f);
                }
                else
                {
                    break;
                }
            }


            return(newBlossom);
        }
        public string CreateRandomBlossom(string pName, BlossomData.BlossomGrowth pGrowth, float pPotentialMin, float pPotentialMax, float pSpeedMin, float pSpeedMax, int pAge, int pTraitMinAmount, int pTraitMaxAmount, string pCurrentLevel, Vector2 pCurrentPosition, bool pOwned = false)
        {
            //CREATE BLOSSOM
            BlossomData newBlossom = Instantiate(BlossomPrefab, transform);

            newBlossom.ID = "Blossom" + CurrentBlossomID.ToString();
            string ID = newBlossom.ID;

            CurrentBlossomID += 1;
            //newBlossom.Age = pAge;
            newBlossom.Name    = pName;
            newBlossom.Parent1 = string.Empty;
            newBlossom.Parent2 = string.Empty;
            newBlossom.Growth  = pGrowth;
            newBlossom.Energy  = 2;

            //STATS
            //Agility
            newBlossom.Agility.Value         = 0;
            newBlossom.Agility.Potential     = Random.Range(pPotentialMin, pPotentialMax);
            newBlossom.Agility.LearningSpeed = Random.Range(pSpeedMin, pSpeedMax);
            //Strength
            newBlossom.Strength.Value         = 0;
            newBlossom.Strength.Potential     = Random.Range(pPotentialMin, pPotentialMax);
            newBlossom.Strength.LearningSpeed = Random.Range(pSpeedMin, pSpeedMax);
            //Intellect
            newBlossom.Intellect.Value         = 0;
            newBlossom.Intellect.Potential     = Random.Range(pPotentialMin, pPotentialMax);
            newBlossom.Intellect.LearningSpeed = Random.Range(pSpeedMin, pSpeedMax);
            //Charm
            newBlossom.Charm.Value         = 0;
            newBlossom.Charm.Potential     = Random.Range(pPotentialMin, pPotentialMax);
            newBlossom.Charm.LearningSpeed = Random.Range(pSpeedMin, pSpeedMax);


            //TRAITS
            Trait[] allTraits = Resources.LoadAll <Trait>("BlossomTraits");
            Dictionary <Trait, int> traitPool = new Dictionary <Trait, int>();

            foreach (Trait trait in allTraits)
            {
                traitPool.Add(trait, trait.Probabilty);
            }
            int rand = Random.Range(pTraitMinAmount, pTraitMinAmount);

            for (int i = 0; i < rand; i++)
            {
                Trait trait = WeightedRandomizer.From(traitPool).TakeOne();
                if (!newBlossom.Traits.Contains(trait))
                {
                    newBlossom.Traits.Add(trait);
                }
            }

            newBlossom.CurrentLevel       = pCurrentLevel;
            newBlossom.transform.position = pCurrentPosition;

            if (pOwned == true)
            {
                OwnedBlossoms.Add(newBlossom.ID);
            }
            ExistingBlossoms.Add(newBlossom.ID);


            BlossomColor[]           allColors = Resources.LoadAll <BlossomColor>("BlossomColors");
            Dictionary <string, int> colorPool = new Dictionary <string, int>();

            foreach (BlossomColor color in allColors)
            {
                colorPool.Add(color.Name, color.Probability);
            }
            newBlossom.Color = WeightedRandomizer.From(colorPool).TakeOne();

            //DESTROY OBJECT
            Destroy(newBlossom.gameObject);
            return(ID);
        }