public void TestContainerContentUpdate() { Serial serial = 0x1; var item = new Item(serial); var data = new ContainerContentUpdate(item).Compile(); Span <byte> expectedData = stackalloc byte[20]; var pos = 0; expectedData.Write(ref pos, (byte)0x25); // Packet ID expectedData.Write(ref pos, item.Serial); expectedData.Write(ref pos, (ushort)item.ItemID); #if NO_LOCAL_INIT expectedData.Write(ref pos, (byte)0); // ItemID offset #else pos++; #endif expectedData.Write(ref pos, (ushort)Math.Min(item.Amount, ushort.MaxValue)); expectedData.Write(ref pos, (ushort)item.X); expectedData.Write(ref pos, (ushort)item.Y); expectedData.Write(ref pos, item.Parent?.Serial ?? Serial.Zero); expectedData.Write(ref pos, (ushort)(item.QuestItem ? Item.QuestItemHue : item.Hue)); AssertThat.Equal(data, expectedData); }
public void TestContainerContentUpdate() { Serial serial = 0x1; var item = new Item(serial); var expected = new ContainerContentUpdate(item).Compile(); using var ns = PacketTestUtilities.CreateTestNetState(); ns.SendContainerContentUpdate(item); var result = ns.SendPipe.Reader.TryRead(); AssertThat.Equal(result.Buffer[0].AsSpan(0), expected); }
/// <summary> /// Analyzes packet and saves it, if its part of the loot. /// </summary> /// <param name="packet">Packet</param> public void AnalyzePacket(Packet packet) { if (packet is MobileIncoming) { MobileIncoming p = (MobileIncoming)packet; if (!m_Mobiles.ContainsKey(p.Serial)) { Mobile m = new Mobile(p.Serial); m.Body = p.ModelId; m.Hue = (int)p.Hue; m.Notoriety = (Notoriety)p.Notoriety; m.Female = (p.Flag & 0x2) == 1 ? true : false; m.Blessed = (p.Flag & 0x8) == 1 ? true : false; m_Mobiles.Add(p.Serial, m); } else { Mobile m = m_Mobiles[p.Serial]; m.Body = p.ModelId; m.Hue = (int)p.Hue; m.Notoriety = (Notoriety)p.Notoriety; m.Female = (p.Flag & 0x2) == 1 ? true : false; m.Blessed = (p.Flag & 0x8) == 1 ? true : false; } } /*else if ( packet is MobileStat ) * { * MobileStat p = (MobileStat) packet; * * if ( m_Mobiles.ContainsKey( p.Serial ) ) * { * Mobile m = m_Mobiles[ p.Serial ]; * * if ( m.Name == null ) * m.Name = p.Name; * } * }*/ else if (packet is DeathAnimation) { DeathAnimation p = (DeathAnimation)packet; if (m_Mobiles.ContainsKey(p.Serial)) { Mobile m = m_Mobiles[p.Serial]; if (m.Corpse == 0) { m.Corpse = p.Corpse; if (!m_Corpses.ContainsKey(p.Corpse)) { m_Corpses.Add(p.Corpse, m); } } } } else if (packet is ContainerContentUpdate) { ContainerContentUpdate p = (ContainerContentUpdate)packet; if (m_Corpses.ContainsKey(p.ContSerial)) { Mobile m = m_Corpses[p.ContSerial]; if (m.CorpseContainer == 0) { m.CorpseContainer = p.Serial; m_Filter.AddMobile(m.Name); if (!m_CorpseContainers.ContainsKey(p.Serial)) { m_CorpseContainers.Add(p.Serial, m); } } } } else if (packet is ContainerContent) { ContainerContent p = (ContainerContent)packet; foreach (ContainerContent.ContainedItem i in p.Items) { if (m_CorpseContainers.ContainsKey(i.ContSerial)) { Mobile m = m_CorpseContainers[i.ContSerial]; if (!m.Loot.ContainsKey(i.Serial)) { Item item; if (!m_Items.ContainsKey(i.Serial)) { item = new Item(i.Serial); m_Items.Add(i.Serial, item); } else { item = m_Items[i.Serial]; } item.ItemID = i.ItemId; item.Hue = i.Hue; item.Amount = i.Amount; m.Loot.Add(i.Serial, item); } } } } else if (packet is ObjectProperties) { ObjectProperties p = (ObjectProperties)packet; if (m_Corpses.ContainsKey(p.Serial)) { Mobile m = m_Corpses[p.Serial]; if (m.CorpseName == null && p.Properties.Length > 0) { ObjectProperties.Property prop = p.Properties[0]; m.CorpseName = LocalizedList.Construct(prop.Number, prop.Arguments); } } else if (m_Mobiles.ContainsKey(p.Serial)) { Mobile m = m_Mobiles[p.Serial]; if (p.Properties.Length > 0) { m.Name = LocalizedList.Construct(p.Properties[0].Number, p.Properties[0].Arguments); } } else { Item item; if (!m_Items.ContainsKey(p.Serial)) { item = new Item(p.Serial); m_Items.Add(p.Serial, item); } else { item = m_Items[p.Serial]; } if (item.Name != null) { return; } for (int i = 0; i < p.Properties.Length; i++) { ObjectProperties.Property prop = p.Properties[i]; item.ParseProperty(i, prop.Number, prop.Arguments); } } } }