private static void HandleChangeAttributes(GameSession session, PacketReader packet) { short lockIndex = -1; long itemUid = packet.ReadLong(); packet.Skip(8); bool useLock = packet.ReadBool(); if (useLock) { packet.Skip(1); lockIndex = packet.ReadShort(); } if (session.Player.Inventory.Items.TryGetValue(itemUid, out Item item)) { item.TimesAttributesChanged++; Item newItem = new Item(item); int attributeCount = newItem.Stats.BonusAttributes.Count; Random rng = new Random(); for (int i = 0; i < attributeCount; i++) { if (i == lockIndex) { continue; } // TODO: Don't RNG the same attribute twice newItem.Stats.BonusAttributes[i] = ItemStat.Of((ItemAttribute)rng.Next(35), 0.01f); } session.StateStorage[NEW_ITEM_KEY] = newItem; session.Send(ChangeAttributesPacket.PreviewNewItem(newItem)); } }
// Example: "item id:20000027" private static void ProcessItemCommand(GameSession session, string command) { Dictionary <string, string> config = command.ToMap(); if (!int.TryParse(config.GetValueOrDefault("id", "20000027"), out int itemId)) { return; } if (!ItemMetadataStorage.IsValid(itemId)) { session.SendNotice("Invalid item: " + itemId); return; } // Add some bonus attributes to equips and pets ItemStats stats = new ItemStats(); if (ItemMetadataStorage.GetTab(itemId) == InventoryTab.Gear || ItemMetadataStorage.GetTab(itemId) == InventoryTab.Pets) { Random rng = new Random(); stats.BonusAttributes.Add(ItemStat.Of((ItemAttribute)rng.Next(35), 0.01f)); stats.BonusAttributes.Add(ItemStat.Of((ItemAttribute)rng.Next(35), 0.01f)); } Item item = new Item(itemId) { CreationTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), TransferFlag = TransferFlag.Splitable | TransferFlag.Tradeable, Stats = stats, PlayCount = itemId.ToString().StartsWith("35") ? 10 : 0 }; if (int.TryParse(config.GetValueOrDefault("rarity", "5"), out int rarity)) { item.Rarity = rarity; } if (int.TryParse(config.GetValueOrDefault("amount", "1"), out int amount)) { item.Amount = amount; } // Simulate looting item InventoryController.Add(session, item, true); /*if (session.Player.Inventory.Add(item)) * { * session.Send(ItemInventoryPacket.Add(item)); * session.Send(ItemInventoryPacket.MarkItemNew(item, item.Amount)); * }*/ }
// Example: "item id:20000027" private static void ProcessItemCommand(GameSession session, string command) { Dictionary <string, string> config = command.ToMap(); int.TryParse(config.GetValueOrDefault("id", "20000027"), out int itemId); if (!ItemMetadataStorage.IsValid(itemId)) { session.SendNotice("Invalid item: " + itemId); return; } // Add some bonus attributes to equips and pets var stats = new ItemStats(); if (ItemMetadataStorage.GetTab(itemId) == InventoryType.Gear || ItemMetadataStorage.GetTab(itemId) == InventoryType.Pets) { var rng = new Random(); stats.BonusAttributes.Add(ItemStat.Of((ItemAttribute)rng.Next(35), 0.01f)); stats.BonusAttributes.Add(ItemStat.Of((ItemAttribute)rng.Next(35), 0.01f)); } var item = new Item(itemId) { Uid = Environment.TickCount64, CreationTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(), Transfer = TransferFlag.Splitable | TransferFlag.Tradeable, Stats = stats }; int.TryParse(config.GetValueOrDefault("rarity", "5"), out item.Rarity); int.TryParse(config.GetValueOrDefault("amount", "1"), out item.Amount); // Simulate looting item if (session.Inventory.Add(item)) { session.Send(ItemInventoryPacket.Add(item)); session.Send(ItemInventoryPacket.MarkItemNew(item)); } }