private static GachaContent HandleSmartGender(GachaMetadata gacha, byte playerGender) { Random random = RandomProvider.Get(); int index = random.Next(gacha.Contents.Count); GachaContent contents = gacha.Contents[index]; if (!contents.SmartGender) { return(contents); } byte itemGender = ItemMetadataStorage.GetGender(contents.ItemId); if (playerGender != itemGender || itemGender != 2) // if it's not the same gender or unisex, roll again { bool sameGender = false; do { int indexReroll = random.Next(gacha.Contents.Count); GachaContent rerollContents = gacha.Contents[indexReroll]; byte rerollContentsGender = ItemMetadataStorage.GetGender(rerollContents.ItemId); if (rerollContentsGender == playerGender || rerollContentsGender == 2) { return(rerollContents); } } while (!sameGender); } return(contents); }
private static GachaContent HandleSmartGender(GachaMetadata gacha, Gender playerGender) { Random random = Random.Shared; int index = random.Next(gacha.Contents.Count); GachaContent contents = gacha.Contents[index]; if (!contents.SmartGender) { return(contents); } Gender itemGender = ItemMetadataStorage.GetLimitMetadata(contents.ItemId).Gender; if (playerGender != itemGender || itemGender != Gender.Neutral) // if it's not the same gender or unisex, roll again { bool sameGender = false; do { int indexReroll = random.Next(gacha.Contents.Count); GachaContent rerollContents = gacha.Contents[indexReroll]; Gender rerollContentsGender = ItemMetadataStorage.GetLimitMetadata(rerollContents.ItemId).Gender; if (rerollContentsGender == playerGender || rerollContentsGender == Gender.Neutral) { return(rerollContents); } } while (!sameGender); } return(contents); }
private static void HandleOpenGachaBox(GameSession session, PacketReader packet, Item capsule) { string amount = packet.ReadUnicodeString(); int rollCount = 0; GachaMetadata gacha = GachaMetadataStorage.GetMetadata(capsule.Function.Id); Random random = new Random(); List <Item> items = new List <Item>() { }; if (amount == "single") { rollCount = 1; } else if (amount == "multi") { rollCount = 10; } for (int i = 0; i < rollCount; i++) { GachaContent contents = HandleSmartGender(gacha, session.Player.Gender); int itemAmount = random.Next(contents.MinAmount, contents.MaxAmount); Item gachaItem = new Item(contents.ItemId) { Rarity = contents.Rarity, Amount = itemAmount, GachaDismantleId = gacha.GachaId }; items.Add(gachaItem); InventoryController.Consume(session, capsule.Uid, 1); } session.Send(FireWorksPacket.Gacha(items)); foreach (Item item in items) { InventoryController.Add(session, item, true); } }
protected override List <GachaMetadata> Parse() { Dictionary <int, List <GachaContent> > gachaContent = new Dictionary <int, List <GachaContent> >(); foreach (PackFileEntry entry in Resources.XmlReader.Files) { if (!entry.Name.StartsWith("table/individualitemdrop_newgacha")) // Capsules { continue; } XmlDocument document = Resources.XmlReader.GetXmlDocument(entry); foreach (XmlNode node in document.DocumentElement.ChildNodes) { if (node.Name == "individualDropBox") { int id = int.Parse(node.Attributes["individualDropBoxID"].Value); int itemId = int.Parse(node.Attributes["item"].Value); byte smartDrop = byte.Parse(node.Attributes["smartDropRate"].Value); bool smartGender = false; if (node.Attributes["isApplySmartGenderDrop"] != null) { smartGender = bool.Parse(node.Attributes["isApplySmartGenderDrop"].Value); } short minAmount = short.Parse(node.Attributes["minCount"].Value); short maxAmount = short.Parse(node.Attributes["maxCount"].Value); byte rarity = byte.Parse(node.Attributes["PackageUIShowGrade"].Value); GachaContent metadata = new GachaContent() { ItemId = itemId, SmartDrop = smartDrop, SmartGender = smartGender, MinAmount = minAmount, MaxAmount = maxAmount, Rarity = rarity, }; if (gachaContent.ContainsKey(id)) { gachaContent[id].Add(metadata); } else { gachaContent[id] = new List <GachaContent>() { metadata }; } } } } List <GachaMetadata> gacha = new List <GachaMetadata>(); foreach (PackFileEntry entry in Resources.XmlReader.Files) { if (!entry.Name.StartsWith("table/gacha_info")) { continue; } XmlDocument document = Resources.XmlReader.GetXmlDocument(entry); foreach (XmlNode node in document.DocumentElement.ChildNodes) { if (node.Name == "randomBox") { int gachaId = int.Parse(node.Attributes["randomBoxID"].Value); byte boxGroup = byte.Parse(node.Attributes["randomBoxGroup"].Value); int dropBoxId = int.Parse(node.Attributes["individualDropBoxID"].Value); int shopId = string.IsNullOrEmpty(node.Attributes["shopID"].Value) ? 0 : int.Parse(node.Attributes["shopID"].Value); int coinItemId = string.IsNullOrEmpty(node.Attributes["coinItemID"].Value) ? 0 : int.Parse(node.Attributes["coinItemID"].Value); byte coinAmount = (byte)(string.IsNullOrEmpty(node.Attributes["coinItemAmount"].Value) ? 0 : byte.Parse(node.Attributes["coinItemAmount"].Value)); GachaMetadata metadata = new GachaMetadata() { GachaId = gachaId, BoxGroup = boxGroup, DropBoxId = dropBoxId, ShopId = shopId, CoinId = coinItemId, CoinAmount = coinAmount }; if (gachaContent.ContainsKey(dropBoxId)) { metadata.Contents = gachaContent[dropBoxId]; } gacha.Add(metadata); } } } return(gacha); }
protected override List <GachaMetadata> Parse() { Dictionary <int, List <GachaContent> > gachaContent = new Dictionary <int, List <GachaContent> >(); foreach (PackFileEntry entry in Resources.XmlReader.Files) { if (!entry.Name.StartsWith("table/individualitemdrop_newgacha")) // Capsules { continue; } XmlDocument document = Resources.XmlReader.GetXmlDocument(entry); XmlNodeList nodes = document.SelectNodes("/ms2/individualDropBox"); foreach (XmlNode node in nodes) { GachaContent metadata = new GachaContent() { ItemId = int.Parse(node.Attributes["item"].Value), SmartDrop = byte.Parse(node.Attributes["smartDropRate"].Value), SmartGender = bool.Parse(node.Attributes["isApplySmartGenderDrop"]?.Value ?? "false"), MinAmount = short.Parse(node.Attributes["minCount"].Value), MaxAmount = short.Parse(node.Attributes["maxCount"].Value), Rarity = byte.Parse(node.Attributes["PackageUIShowGrade"].Value), }; string individualDropBoxId = node.Attributes["individualDropBoxID"].Value; if (gachaContent.ContainsKey(int.Parse(individualDropBoxId))) { gachaContent[int.Parse(individualDropBoxId)].Add(metadata); } else { gachaContent[int.Parse(individualDropBoxId)] = new List <GachaContent>() { metadata }; } } } List <GachaMetadata> gacha = new List <GachaMetadata>(); foreach (PackFileEntry entry in Resources.XmlReader.Files) { if (!entry.Name.StartsWith("table/gacha_info")) { continue; } XmlDocument document = Resources.XmlReader.GetXmlDocument(entry); foreach (XmlNode node in document.DocumentElement.ChildNodes) { if (node.Name != "randomBox") { continue; } int dropBoxId = int.Parse(node.Attributes["individualDropBoxID"].Value); _ = int.TryParse(node.Attributes["shopID"]?.Value ?? "0", out int shopId); _ = int.TryParse(node.Attributes["coinItemID"]?.Value ?? "0", out int coinItemId); _ = byte.TryParse(node.Attributes["coinItemAmount"]?.Value ?? "0", out byte coinAmount); GachaMetadata metadata = new GachaMetadata() { GachaId = int.Parse(node.Attributes["randomBoxID"].Value), BoxGroup = byte.Parse(node.Attributes["randomBoxGroup"].Value), DropBoxId = dropBoxId, ShopId = shopId, CoinId = coinItemId, CoinAmount = coinAmount }; if (gachaContent.ContainsKey(dropBoxId)) { metadata.Contents = gachaContent[dropBoxId]; } gacha.Add(metadata); } } return(gacha); }