Beispiel #1
0
    public static List <Item> GetItemsFromDropGroup(DropGroupContent dropContent, Gender playerGender, Job job)
    {
        List <Item> items  = new();
        Random      rng    = RandomProvider.Get();
        int         amount = rng.Next((int)dropContent.MinAmount, (int)dropContent.MaxAmount);

        foreach (int id in dropContent.ItemIds)
        {
            if (dropContent.SmartGender)
            {
                Gender itemGender = ItemMetadataStorage.GetGender(id);
                if (itemGender != playerGender && itemGender is not Gender.Neutral)
                {
                    continue;
                }
            }

            List <Job> recommendJobs = ItemMetadataStorage.GetRecommendJobs(id);
            if (recommendJobs.Contains(job) || recommendJobs.Contains(Job.None))
            {
                Item newItem = new(id)
                {
                    Enchants = dropContent.EnchantLevel,
                    Amount   = amount,
                    Rarity   = dropContent.Rarity
                };
                items.Add(newItem);
            }
        }
        return(items);
    }
Beispiel #2
0
    public static void GiveItemFromSelectBox(GameSession session, Item sourceItem, int index)
    {
        SelectItemBox    box      = sourceItem.Function.SelectItemBox;
        ItemDropMetadata metadata = ItemDropMetadataStorage.GetItemDropMetadata(box.BoxId);

        if (metadata == null)
        {
            session.Send(NoticePacket.Notice("No items found", NoticeType.Chat));
            return;
        }

        Inventory inventory = session.Player.Inventory;

        inventory.ConsumeItem(session, sourceItem.Uid, 1);

        // Select boxes disregards group ID. Adding these all to a filtered list
        List <DropGroupContent> dropContentsList = new();

        foreach (DropGroup group in metadata.DropGroups)
        {
            foreach (DropGroupContent dropGroupContent in group.Contents)
            {
                if (dropGroupContent.SmartDropRate == 100)
                {
                    List <Job> recommendJobs = ItemMetadataStorage.GetRecommendJobs(dropGroupContent.ItemIds.First());
                    if (recommendJobs.Contains(session.Player.Job) || recommendJobs.Contains(Job.None))
                    {
                        dropContentsList.Add(dropGroupContent);
                    }
                    continue;
                }
                dropContentsList.Add(dropGroupContent);
            }
        }

        DropGroupContent dropContents = dropContentsList[index];

        Random rng    = RandomProvider.Get();
        int    amount = rng.Next((int)dropContents.MinAmount, (int)dropContents.MaxAmount);

        foreach (int id in dropContents.ItemIds)
        {
            Item newItem = new(id)
            {
                Enchants = dropContents.EnchantLevel,
                Amount   = amount,
                Rarity   = dropContents.Rarity
            };
            inventory.AddItem(session, newItem, true);
        }
    }
    public static List <Item> GetItemsFromDropGroup(DropGroupContent dropContent, Player player, Item sourceItem)
    {
        List <Item> items  = new();
        Random      rng    = Random.Shared;
        int         amount = rng.Next((int)dropContent.MinAmount, (int)dropContent.MaxAmount);

        foreach (int id in dropContent.ItemIds)
        {
            if (dropContent.SmartDropRate == 100)
            {
                List <Job> recommendJobs = ItemMetadataStorage.GetRecommendJobs(id);
                if (!recommendJobs.Contains(player.Job) && !recommendJobs.Contains(Job.None))
                {
                    continue;
                }
            }

            if (dropContent.SmartGender)
            {
                Gender itemGender = ItemMetadataStorage.GetLimitMetadata(id).Gender;
                if (itemGender != player.Gender && itemGender is not Gender.Neutral)
                {
                    continue;
                }
            }


            int rarity   = dropContent.Rarity;
            int constant = ItemMetadataStorage.GetOptionMetadata(sourceItem.Id).Constant;
            if (rarity == 0 && constant is > 0 and < 7)
            {
                rarity = constant;
            }

            Item newItem = new(id, amount, rarity, saveToDatabase : false)
            {
                EnchantLevel = dropContent.EnchantLevel
            };
            newItem.Stats = new(newItem);
            items.Add(newItem);
        }

        return(items);
    }
Beispiel #4
0
        protected override List <ItemDropMetadata> Parse()
        {
            Dictionary <int, List <DropGroup> > itemGroups = new Dictionary <int, List <DropGroup> >();
            List <ItemDropMetadata>             drops      = new List <ItemDropMetadata>();

            foreach (PackFileEntry entry in Resources.XmlReader.Files)
            {
                if (!entry.Name.StartsWith("table/individualitemdrop") && !entry.Name.StartsWith("table/na/individualitemdrop"))
                {
                    continue;
                }

                XmlDocument document           = Resources.XmlReader.GetXmlDocument(entry);
                XmlNodeList individualBoxItems = document.SelectNodes($"/ms2/individualDropBox");
                foreach (XmlNode node in individualBoxItems)
                {
                    string locale = string.IsNullOrEmpty(node.Attributes["locale"]?.Value) ? "" : node.Attributes["locale"].Value;

                    if (locale != "NA" && locale != "")
                    {
                        continue;
                    }

                    int boxId       = int.Parse(node.Attributes["individualDropBoxID"].Value);
                    int dropGroupId = int.Parse(node.Attributes["dropGroup"].Value);

                    DropGroupContent contents = new DropGroupContent();

                    List <int> itemIds = new List <int>
                    {
                        int.Parse(node.Attributes["item"].Value)
                    };
                    if (node.Attributes["item2"] != null)
                    {
                        itemIds.Add(int.Parse(node.Attributes["item2"].Value));
                    }

                    if (node.Attributes["smartDropRate"] != null)
                    {
                        contents.SmartDropRate = int.Parse(node.Attributes["smartDropRate"].Value);
                    }

                    if (node.Attributes["enchantLevel"] != null)
                    {
                        contents.EnchantLevel = byte.Parse(node.Attributes["enchantLevel"].Value);
                    }

                    if (node.Attributes["isApplySmartGenderDrop"] != null)
                    {
                        contents.SmartGender = node.Attributes["isApplySmartGenderDrop"].Value.ToLower() == "true";
                    }

                    contents.MinAmount = float.Parse(node.Attributes["minCount"].Value);
                    contents.MaxAmount = float.Parse(node.Attributes["maxCount"].Value);
                    contents.Rarity    = 1;
                    if (node.Attributes["PackageUIShowGrade"] != null)
                    {
                        contents.Rarity = (byte)(string.IsNullOrEmpty(node.Attributes["PackageUIShowGrade"]?.Value) ? 1 : byte.Parse(node.Attributes["PackageUIShowGrade"].Value));
                    }

                    contents.ItemIds.AddRange(itemIds);

                    if (itemGroups.ContainsKey(boxId))
                    {
                        if (itemGroups[boxId].FirstOrDefault(x => x.Id == dropGroupId) != default)
                        {
                            DropGroup group = itemGroups[boxId].FirstOrDefault(x => x.Id == dropGroupId);
                            group.Contents.Add(contents);
                            continue;
                        }

                        DropGroup newGroup = new DropGroup();
                        newGroup.Id = dropGroupId;
                        newGroup.Contents.Add(contents);
                        itemGroups[boxId].Add(newGroup);
                        continue;
                    }
                    else
                    {
                        itemGroups[boxId] = new List <DropGroup>();
                        DropGroup newGroup = new DropGroup();
                        newGroup.Id = dropGroupId;
                        newGroup.Contents.Add(contents);
                        itemGroups[boxId].Add(newGroup);
                    }
                }

                foreach (KeyValuePair <int, List <DropGroup> > kvp in itemGroups)
                {
                    ItemDropMetadata metadata = new ItemDropMetadata();
                    metadata.Id         = kvp.Key;
                    metadata.DropGroups = kvp.Value;
                    drops.Add(metadata);
                }
            }
            return(drops);
        }
    public static bool GiveItemFromSelectBox(GameSession session, Item sourceItem, int index, out OpenBoxResult result)
    {
        result = OpenBoxResult.Success;

        SelectItemBox    box      = sourceItem.Function.SelectItemBox;
        ItemDropMetadata metadata = ItemDropMetadataStorage.GetItemDropMetadata(box.BoxId);

        if (metadata == null)
        {
            result = OpenBoxResult.UnableToOpen;
            return(false);
        }

        IInventory inventory = session.Player.Inventory;

        // Select boxes disregards group ID. Adding these all to a filtered list
        List <DropGroupContent> dropContentsList = new();

        foreach (DropGroup group in metadata.DropGroups)
        {
            foreach (DropGroupContent dropGroupContent in group.Contents)
            {
                if (dropGroupContent.SmartDropRate == 100)
                {
                    List <Job> recommendJobs = ItemMetadataStorage.GetRecommendJobs(dropGroupContent.ItemIds.First());
                    if (recommendJobs.Contains(session.Player.Job) || recommendJobs.Contains(Job.None))
                    {
                        dropContentsList.Add(dropGroupContent);
                    }

                    continue;
                }

                dropContentsList.Add(dropGroupContent);
            }
        }

        DropGroupContent dropContents = dropContentsList[index];
        int amount = Random.Shared.Next((int)dropContents.MinAmount, (int)dropContents.MaxAmount);

        foreach (int id in dropContents.ItemIds)
        {
            if (inventory.CanHold(id, amount))
            {
                continue;
            }

            result = OpenBoxResult.InventoryFull;
            return(false);
        }

        inventory.ConsumeItem(session, sourceItem.Uid, 1);

        foreach (int id in dropContents.ItemIds)
        {
            Item newItem = new(id, amount, dropContents.Rarity)
            {
                EnchantLevel = dropContents.EnchantLevel
            };
            newItem.Stats = new(newItem);
            if (inventory.CanHold(newItem))
            {
                inventory.AddItem(session, newItem, true);
                continue;
            }

            result = OpenBoxResult.InventoryFull;
            MailHelper.InventoryWasFull(newItem, session.Player.CharacterId);
        }

        return(true);
    }