Ejemplo n.º 1
0
 private void LootOptions_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (LootOptions.SelectedIndex == 0)
     {
         randomizer.weapons = LootOptions.GetItemChecked(0);
     }
     else if (LootOptions.SelectedIndex == 1)
     {
         randomizer.abilities = LootOptions.GetItemChecked(1);
     }
     else if (LootOptions.SelectedIndex == 2)
     {
         randomizer.upgrades = LootOptions.GetItemChecked(2);
     }
     else if (LootOptions.SelectedIndex == 3)
     {
         randomizer.loot = LootOptions.GetItemChecked(3);
     }
 }
Ejemplo n.º 2
0
        public void SpawnLoot(BaseCharacterMono character)
        {
            var positionToSpawn = character.transform.position + (character.transform.up);

            var itemsToLoot = new List <Item>();
            var goldToLoot  = 0;

            //todo: nicer code this, maybe move to function
            var mm = GetObject.PlayerSave.QuestLog.ActiveObjectives;
            //note: we are double checking isDone here as we don't want to spawn loot for already completed itemConditions
            var active             = mm.SelectMany(y => y.ActiveConditions).Where(i => !i.IsDone).ToList();
            var conditions         = active.Select(a => a as ItemCondition);
            var interactConditions = conditions.Where(c => c != null);
            var foundCondition     = interactConditions.FirstOrDefault(i => i.CombatantIDThatDropsItem == (character.Character as CombatCharacter).ID);

            if (foundCondition != null)
            {
                var qItem = Rm_RPGHandler.Instance.Repositories.QuestItems.Get(foundCondition.ItemToCollectID);
                if (qItem != null)
                {
                    itemsToLoot.Add(qItem);
                }
            }

            var enemyInfo = character.Character as CombatCharacter;

            foreach (var loot in enemyInfo.GuaranteedLoot)
            {
                var item = Rm_RPGHandler.Instance.Repositories.Items.Get(loot.ItemID);
                if (item == null)
                {
                    Debug.LogError("Did not find item in guaranteed loot of : " + enemyInfo.Name);
                    continue;
                }

                if (loot.Amount != 0)
                {
                    var stackable = item as IStackable;

                    if (stackable != null)
                    {
                        stackable.CurrentStacks = loot.Amount;
                    }
                }

                itemsToLoot.Add(item);
            }

            var randomGold = Random.Range(0, 100 + 1);

            if (enemyInfo.DropsGold)
            {
                var drops = randomGold <= (enemyInfo.GoldDropChance * 100);
                if (drops)
                {
                    goldToLoot += Random.Range(enemyInfo.MinGoldDrop, enemyInfo.MaxGoldDrop + 1);
                }
            }

            if (enemyInfo.LootTables.Count > 0)
            {
                var random = Random.Range(0, 100 + 1);
                //Debug.Log("LootOption Random: " + random);
                var         currentProbability = random;
                var         prevChance         = 0;
                var         currentIndex       = 0;
                LootOptions lootOptionsToUse   = null;

                while (prevChance < 100)
                {
                    var currentTableChance = enemyInfo.LootTables[currentIndex].Chance + prevChance;
                    prevChance = (int)currentTableChance;


                    //Debug.Log("currentTableChance:" + currentTableChance);
                    if (currentProbability <= currentTableChance)
                    {
                        lootOptionsToUse = enemyInfo.LootTables[currentIndex];
                        break;
                    }
                    else
                    {
                        currentIndex++;
                    }
                }

                if (lootOptionsToUse != null)
                {
                    var lootTableToUse = Rm_RPGHandler.Instance.Repositories.LootTables.AllTables.FirstOrDefault(l => l.ID == enemyInfo.LootTables[currentIndex].LootTableID);
                    for (int x = 0; x < enemyInfo.MaxItemsFromLootTable; x++)
                    {
                        var chanceToGet = lootOptionsToUse.AlwaysGetItem ? 100 : lootTableToUse.ChanceForItem;
                        var randomRoll  = Random.Range(0, 100 + 1);
                        //Debug.Log("LootTableItem Random: " + random);
                        if (randomRoll <= chanceToGet)
                        {
                            randomRoll = Random.Range(0, 100 + 1);
                            var currentProb      = randomRoll;
                            var currentItemIndex = 0;
                            var prevLootChance   = 0;
                            Rm_LootTableItem lootTableItemToLoot = null;
                            while (prevLootChance < 100)
                            {
                                var currentItemChance = lootTableToUse.LootTableItems[currentItemIndex].Chance + prevLootChance;
                                prevLootChance = (int)currentItemChance;

                                //Debug.Log("currentItemChance:" + currentItemChance);
                                if (currentProb <= currentItemChance)
                                {
                                    lootTableItemToLoot = lootTableToUse.LootTableItems[currentItemIndex];
                                    break;
                                }
                                else
                                {
                                    currentItemIndex++;
                                }
                            }
                            if (lootTableItemToLoot != null)
                            {
                                if (!lootTableItemToLoot.IsGold && !lootTableItemToLoot.IsEmpty)
                                {
                                    Item item = null;

                                    if (lootTableItemToLoot.IsNormalItem)
                                    {
                                        item = Rm_RPGHandler.Instance.Repositories.Items.Get(lootTableItemToLoot.ItemID);
                                    }
                                    else if (lootTableItemToLoot.IsQuestItem)
                                    {
                                        item = Rm_RPGHandler.Instance.Repositories.QuestItems.Get(lootTableItemToLoot.ItemID);
                                    }
                                    else if (lootTableItemToLoot.IsCraftableItem)
                                    {
                                        item = Rm_RPGHandler.Instance.Repositories.CraftableItems.Get(lootTableItemToLoot.ItemID);
                                    }


                                    //item = Rm_RPGHandler.Instance.Repositories.Items.AllItems.FirstOrDefault(i => i.ID == lootTableItemToLoot.ItemID);
                                    if (item == null)
                                    {
                                        Debug.LogError("Did not find item in guaranteed loot of : " + enemyInfo.Name);
                                        continue;
                                    }

                                    var itemCopy = GeneralMethods.CopyObject(item);

                                    if (lootTableItemToLoot.MaxQuantity != 1)
                                    {
                                        var stackable = itemCopy as IStackable;
                                        stackable.CurrentStacks = Random.Range(lootTableItemToLoot.MinQuantity, lootTableItemToLoot.MaxQuantity + 1);
                                    }

                                    itemsToLoot.Add(itemCopy);
                                }
                                else if (lootTableItemToLoot.IsGold)
                                {
                                    goldToLoot += Random.Range(lootTableItemToLoot.MinQuantity, lootTableItemToLoot.MaxQuantity + 1);
                                }
                            }
                        }
                    }
                }
            }

            StartCoroutine(SpawnListOfItems(itemsToLoot, positionToSpawn, goldToLoot));
        }