Esempio n. 1
0
        private static void AddGuaranteedDrop(DM_DropTable dropTableHolder, int item_ID, string item_Name, int min_Qty, int max_Qty)
        {
            // check if we already have this guaranteed drop, if so add to quantity
            bool newDrop = true;

            foreach (DropTableEntry gDropHolder in dropTableHolder.Guaranteed_Drops)
            {
                if (item_ID == gDropHolder.Item_ID)
                {
                    newDrop = false;
                    gDropHolder.Min_Quantity += min_Qty;
                    gDropHolder.Max_Quantity += max_Qty;
                }
            }
            if (newDrop)
            {
                if (IsUnidentified(item_ID, out string identified))
                {
                    item_Name += " (" + identified + ")";
                }

                dropTableHolder.Guaranteed_Drops.Add(new DropTableEntry
                {
                    Item_Name    = item_Name,
                    Item_ID      = item_ID,
                    Min_Quantity = min_Qty,
                    Max_Quantity = max_Qty
                });
            }
        }
Esempio n. 2
0
        public static DM_LootContainer ParseLootContainer(TreasureChest loot)
        {
            var lootHolder = new DM_LootContainer
            {
                Name   = loot.Name?.Trim(),
                ItemID = loot.ItemID,
                UID    = loot.UID
            };

            if (lootHolder.Name == "Pocket")
            {
                lootHolder.Name = "Corpse";
            }

            if (At.GetField(loot as SelfFilledItemContainer, "m_drops") is List <Dropable> droppers)
            {
                foreach (Dropable dropper in droppers)
                {
                    var dropableHolder = DM_DropTable.ParseDropable(dropper, null, lootHolder.Name);
                    lootHolder.DropTables.Add(dropableHolder.Name);
                }
            }

            string dir      = Serializer.Folders.Scenes + "/" + SceneManager.Instance.GetCurrentRegion() + "/" + SceneManager.Instance.GetCurrentLocation(loot.transform.position);
            string saveName = lootHolder.Name + "_" + lootHolder.UID;

            Serializer.SaveToXml(dir + "/LootContainers", saveName, lootHolder);

            return(lootHolder);
        }
        public static DM_Gatherable ParseGatherable(Gatherable gatherable)
        {
            var gatherableHolder = new DM_Gatherable
            {
                Name   = gatherable.Name?.Trim(),
                ItemID = gatherable.ItemID
            };

            if (At.GetField(gatherable as SelfFilledItemContainer, "m_drops") is List <Dropable> droppers)
            {
                if (droppers == null || droppers.Count < 1)
                {
                    //SL.LogWarning("droppers is null or list count is 0!");
                }
                else
                {
                    foreach (Dropable dropper in droppers)
                    {
                        var dropableHolder = DM_DropTable.ParseDropable(dropper);
                        gatherableHolder.DropTables.Add(dropableHolder.Name);
                    }
                }
            }

            if (gatherableHolder.Name == "Fish")
            {
                gatherableHolder.Name = "Fishing Spot (" + gatherableHolder.DropTables[0] + ")";
            }

            if (gatherableHolder.Name.Contains("vein"))
            {
                gatherableHolder.Name.Replace("vein", "Vein");

                if (gatherableHolder.Name.Contains("Iron") || gatherableHolder.Name == "Palladium")
                {
                    foreach (var table in gatherableHolder.DropTables)
                    {
                        if (table.Contains("Tourmaline"))
                        {
                            gatherableHolder.Name += " (Tourmaline)";
                            break;
                        }
                    }
                }
            }

            return(gatherableHolder);
        }
Esempio n. 4
0
        public static DM_Merchant ParseMerchant(Merchant merchant)
        {
            var merchantHolder = new DM_Merchant
            {
                Name = merchant.ShopName?.Trim(),
                UID  = merchant.HolderUID
            };

            if (At.GetField(merchant, "m_dropableInventory") is Dropable dropper)
            {
                merchantHolder.DropTable = DM_DropTable.ParseDropable(dropper, merchant);
            }

            foreach (var priceMod in merchant.GetComponentsInChildren <PriceModifier>())
            {
                if (priceMod.BuyMultiplierAdded != 0f || priceMod.SellMultiplierAdded != 0f)
                {
                    //SL.Log("Merchant " + merchantHolder.Name + " has buy or sell mods! Buy: " + priceMod.BuyMultiplierAdded + ", Sell: " + priceMod.SellMultiplierAdded);
                    merchantHolder.BuyModifiers.Add(priceMod.BuyMultiplierAdded);
                    merchantHolder.SellModifiers.Add(priceMod.SellMultiplierAdded);
                }
            }

            string dir      = Serializer.Folders.Merchants;
            string saveName = SceneManager.Instance.GetCurrentLocation(merchant.transform.position) + " - " + merchantHolder.Name + " (" + merchantHolder.UID + ")";

            if (ListManager.Merchants.ContainsKey(saveName))
            {
                return(null);
            }

            Serializer.SaveToXml(dir, saveName, merchantHolder);

            ListManager.Merchants.Add(saveName, merchantHolder);

            return(merchantHolder);
        }
Esempio n. 5
0
        public static DM_DropTable ParseDropable(Dropable dropable, Merchant merchant = null, string containerName = "")
        {
            if (!dropable)
            {
                return(null);
            }

            var dropTableHolder = new DM_DropTable
            {
                Name = dropable.name
            };

            if (dropTableHolder.Name == "InventoryTable" && merchant)
            {
                dropTableHolder.Name = SceneManager.Instance.GetCurrentLocation(merchant.transform.position) + " - " + merchant.ShopName;
            }

            dropTableHolder.Name = dropTableHolder.Name.Trim();

            if (At.GetField(dropable, "m_allGuaranteedDrops") is List <GuaranteedDrop> guaranteedDrops)
            {
                foreach (GuaranteedDrop gDropper in guaranteedDrops)
                {
                    if (At.GetField(gDropper, "m_itemDrops") is List <BasicItemDrop> gItemDrops && gItemDrops.Count > 0)
                    {
                        foreach (BasicItemDrop gItemDrop in gItemDrops)
                        {
                            if (!gItemDrop.DroppedItem)
                            {
                                continue;
                            }

                            //var pos = dropable.transform.position;
                            AddGuaranteedDrop(dropTableHolder,
                                              gItemDrop.DroppedItem.ItemID,
                                              gItemDrop.DroppedItem.Name,
                                              gItemDrop.MinDropCount,
                                              gItemDrop.MaxDropCount);
                        }
                    }
                }
            }

            if (At.GetField(dropable, "m_conditionalGuaranteedDrops") is List <ConditionalGuaranteedDrop> conditionalGuaranteed)
            {
                foreach (var guaConditional in conditionalGuaranteed)
                {
                    if (!guaConditional.Dropper)
                    {
                        continue;
                    }

                    var drops = At.GetField(guaConditional.Dropper, "m_itemDrops") as List <BasicItemDrop>;
                    foreach (var gItemDrop in drops)
                    {
                        if (!gItemDrop.DroppedItem)
                        {
                            continue;
                        }

                        //var pos = dropable.transform.position;
                        AddGuaranteedDrop(dropTableHolder,
                                          gItemDrop.DroppedItem.ItemID,
                                          gItemDrop.DroppedItem.Name,
                                          gItemDrop.MinDropCount,
                                          gItemDrop.MaxDropCount);
                    }
                }
            }

            if (At.GetField(dropable, "m_mainDropTables") is List <DropTable> dropTables)
            {
                foreach (DropTable table in dropTables)
                {
                    if (ParseDropTable(dropTableHolder, containerName, dropable, table) is DropGeneratorHolder generatorHolder)
                    {
                        dropTableHolder.Random_Tables.Add(generatorHolder);
                    }
                }
            }

            if (At.GetField(dropable, "m_conditionalDropTables") is List <ConditionalDropTable> conditionals)
            {
                foreach (var conTable in conditionals)
                {
                    if (ParseDropTable(dropTableHolder, containerName, dropable, conTable.Dropper) is DropGeneratorHolder generatorHolder)
                    {
                        generatorHolder.DropConditionType = conTable.DropCondition.GetType().FullName;

                        dropTableHolder.Random_Tables.Add(generatorHolder);
                    }
                }
            }

            if (merchant == null)
            {
                string dir = Serializer.Folders.DropTables;
                if (!File.Exists(dir + "/" + dropTableHolder.Name + ".xml"))
                {
                    ListManager.DropTables.Add(dropTableHolder.Name, dropTableHolder);
                    Serializer.SaveToXml(dir, dropTableHolder.Name, dropTableHolder);
                }
            }

            return(dropTableHolder);
        }
Esempio n. 6
0
        public static DropGeneratorHolder ParseDropTable(DM_DropTable dropTableHolder, string containerName, Dropable dropper, DropTable table)
        {
            var generatorHolder = new DropGeneratorHolder
            {
                MinNumberOfDrops = table.MinNumberOfDrops,
                MaxNumberOfDrops = table.MaxNumberOfDrops,
                MaxDiceValue     = (int)At.GetField(table, "m_maxDiceValue"),
            };

            //if (generatorHolder.MaxDiceValue <= 0)
            //{
            //    SL.LogWarning("This random table's MaxDiceValue is 0, skipping...");
            //    return null;
            //}

            if (At.GetField(table, "m_dropAmount") is SimpleRandomChance dropAmount)
            {
                generatorHolder.ChanceReduction = dropAmount.ChanceReduction;
                generatorHolder.ChanceRegenQty  = dropAmount.ChanceRegenQty;

                if (dropAmount.CanRegen)
                {
                    generatorHolder.RegenTime = dropAmount.ChanceRegenDelay;
                }
                else
                {
                    generatorHolder.RegenTime = -1;
                }
            }
            else
            {
                generatorHolder.RegenTime = -1;
            }

            if (At.GetField(table, "m_emptyDropChance") is int i && generatorHolder.MaxDiceValue > 0)
            {
                try
                {
                    decimal emptyChance = (decimal)i / generatorHolder.MaxDiceValue;
                    generatorHolder.EmptyDrop = (float)emptyChance * 100;
                }
                catch
                {
                    generatorHolder.EmptyDrop = 0;
                }
            }

            if (At.GetField(table, "m_itemDrops") is List <ItemDropChance> itemDrops)
            {
                foreach (ItemDropChance drop in itemDrops)
                {
                    if (!drop.DroppedItem)
                    {
                        continue;
                    }

                    float percentage;
                    try
                    {
                        percentage = (float)((decimal)drop.DropChance / generatorHolder.MaxDiceValue) * 100f;
                    }
                    catch
                    {
                        percentage = 100f;
                    }

                    percentage = (float)Math.Round(percentage, 2);

                    string name = drop.DroppedItem.Name;

                    if (IsUnidentified(drop.DroppedItem.ItemID, out string identified))
                    {
                        name += " (" + identified + ")";
                    }

                    if (percentage >= 100)
                    {
                        AddGuaranteedDrop(dropTableHolder, drop.DroppedItem.ItemID, name, drop.MaxDropCount, drop.MinDropCount);
                    }
                    else
                    {
                        generatorHolder.Item_Drops.Add(new DropTableChanceEntry
                        {
                            Item_ID          = drop.DroppedItem.ItemID,
                            Item_Name        = name,
                            Min_Quantity     = drop.MinDropCount,
                            Max_Quantity     = drop.MaxDropCount,
                            Drop_Chance      = percentage,
                            Dice_Range       = drop.MaxDiceRollValue - drop.MinDiceRollValue,
                            ChanceReduction  = drop.ChanceReduction,
                            ChanceRegenDelay = drop.ChanceRegenDelay,
                            ChanceRegenQty   = drop.ChanceRegenQty
                        });
                    }
                }
            }

            return(generatorHolder);
        }