Converts equipment packets (#314)
### Change to how DisplayEquipInfo works * Fixes a bug where raw name wasn't used * Fixes another bug where an empty, blank, or null string was still sending an empty crafted by property. Bumps release version
This commit is contained in:
parent
b0d8dd42c0
commit
1fb7ac5cda
14 changed files with 177 additions and 132 deletions
|
|
@ -1,133 +0,0 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: EquipmentPackets.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public class EquipInfoAttribute
|
||||
{
|
||||
public EquipInfoAttribute(int number, int charges = -1)
|
||||
{
|
||||
Number = number;
|
||||
Charges = charges;
|
||||
}
|
||||
|
||||
public int Number { get; }
|
||||
|
||||
public int Charges { get; }
|
||||
}
|
||||
|
||||
public class EquipmentInfo
|
||||
{
|
||||
public EquipmentInfo(int number, Mobile crafter, bool unidentified, EquipInfoAttribute[] attributes)
|
||||
{
|
||||
Number = number;
|
||||
Crafter = crafter;
|
||||
Unidentified = unidentified;
|
||||
Attributes = attributes;
|
||||
}
|
||||
|
||||
public int Number { get; }
|
||||
|
||||
public Mobile Crafter { get; }
|
||||
|
||||
public bool Unidentified { get; }
|
||||
|
||||
public EquipInfoAttribute[] Attributes { get; }
|
||||
}
|
||||
|
||||
public sealed class DisplayEquipmentInfo : Packet
|
||||
{
|
||||
public DisplayEquipmentInfo(Item item, EquipmentInfo info) : base(0xBF)
|
||||
{
|
||||
var attrs = info.Attributes;
|
||||
|
||||
EnsureCapacity(
|
||||
17 + (info.Crafter?.Name?.Length ?? 0) +
|
||||
(info.Unidentified ? 4 : 0) + attrs.Length * 6
|
||||
);
|
||||
|
||||
Stream.Write((short)0x10);
|
||||
Stream.Write(item.Serial);
|
||||
|
||||
Stream.Write(info.Number);
|
||||
|
||||
if (info.Crafter != null)
|
||||
{
|
||||
var name = info.Crafter.Name;
|
||||
|
||||
Stream.Write(-3);
|
||||
|
||||
if (name == null)
|
||||
{
|
||||
Stream.Write((ushort)0);
|
||||
}
|
||||
else
|
||||
{
|
||||
var length = name.Length;
|
||||
Stream.Write((ushort)length);
|
||||
Stream.WriteAsciiFixed(name, length);
|
||||
}
|
||||
}
|
||||
|
||||
if (info.Unidentified)
|
||||
{
|
||||
Stream.Write(-4);
|
||||
}
|
||||
|
||||
for (var i = 0; i < attrs.Length; ++i)
|
||||
{
|
||||
Stream.Write(attrs[i].Number);
|
||||
Stream.Write((short)attrs[i].Charges);
|
||||
}
|
||||
|
||||
Stream.Write(-1);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class EquipUpdate : Packet
|
||||
{
|
||||
public EquipUpdate(Item item) : base(0x2E, 15)
|
||||
{
|
||||
Serial parentSerial;
|
||||
|
||||
var parent = item.Parent as Mobile;
|
||||
var hue = item.Hue;
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
parentSerial = parent.Serial;
|
||||
|
||||
if (parent.SolidHueOverride >= 0)
|
||||
{
|
||||
hue = parent.SolidHueOverride;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: EquipUpdate on item with !(parent is Mobile)");
|
||||
parentSerial = Serial.Zero;
|
||||
}
|
||||
|
||||
Stream.Write(item.Serial);
|
||||
Stream.Write((short)item.ItemID);
|
||||
Stream.Write((byte)0);
|
||||
Stream.Write((byte)item.Layer);
|
||||
Stream.Write(parentSerial);
|
||||
Stream.Write((short)hue);
|
||||
}
|
||||
}
|
||||
}
|
||||
129
Projects/Server/Network/Packets/OutgoingEquipmentPackets.cs
Normal file
129
Projects/Server/Network/Packets/OutgoingEquipmentPackets.cs
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: OutgoingEquipmentPackets.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public class EquipInfoAttribute
|
||||
{
|
||||
public EquipInfoAttribute(int number, int charges = -1)
|
||||
{
|
||||
Number = number;
|
||||
Charges = charges;
|
||||
}
|
||||
|
||||
public int Number { get; }
|
||||
|
||||
public int Charges { get; }
|
||||
}
|
||||
|
||||
public static class OutgoingEquipmentPackets
|
||||
{
|
||||
public static void SendDisplayEquipmentInfo(
|
||||
this NetState ns,
|
||||
Serial serial,
|
||||
int number,
|
||||
string crafterName,
|
||||
bool unidentified,
|
||||
List<EquipInfoAttribute> attrs
|
||||
)
|
||||
{
|
||||
if (ns == null || !ns.GetSendBuffer(out var buffer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
crafterName = crafterName.DefaultIfNullOrEmpty("");
|
||||
|
||||
var length = 17 +
|
||||
(crafterName.Length > 0 ? 6 + crafterName.Length : 0) +
|
||||
(unidentified ? 4 : 0) +
|
||||
attrs.Count * 6;
|
||||
|
||||
var writer = new CircularBufferWriter(buffer);
|
||||
writer.Write((byte)0xBF); // Packet ID
|
||||
writer.Write((ushort)length);
|
||||
writer.Write((ushort)0x10); // Subpacket
|
||||
writer.Write(serial);
|
||||
writer.Write(number);
|
||||
|
||||
if (crafterName.Length > 0)
|
||||
{
|
||||
writer.Write(-3); // crafted by
|
||||
|
||||
writer.Write((ushort)crafterName.Length);
|
||||
writer.WriteAscii(crafterName);
|
||||
}
|
||||
|
||||
if (unidentified)
|
||||
{
|
||||
writer.Write(-4);
|
||||
}
|
||||
|
||||
for (var i = 0; i < attrs.Count; ++i)
|
||||
{
|
||||
var attr = attrs[i];
|
||||
writer.Write(attr.Number);
|
||||
writer.Write((short)attr.Charges);
|
||||
}
|
||||
|
||||
writer.Write(-1);
|
||||
|
||||
ns.Send(ref buffer, writer.Position);
|
||||
}
|
||||
|
||||
public static void SendEquipUpdate(this NetState ns, Item item)
|
||||
{
|
||||
if (ns == null || !ns.GetSendBuffer(out var buffer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Serial parentSerial;
|
||||
|
||||
var parent = item.Parent as Mobile;
|
||||
var hue = item.Hue;
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
parentSerial = parent.Serial;
|
||||
|
||||
if (parent.SolidHueOverride >= 0)
|
||||
{
|
||||
hue = parent.SolidHueOverride;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: EquipUpdate on item with !(parent is Mobile)");
|
||||
parentSerial = Serial.Zero;
|
||||
}
|
||||
|
||||
|
||||
var writer = new CircularBufferWriter(buffer);
|
||||
writer.Write((byte)0x2E); // Packet ID
|
||||
writer.Write(item.Serial);
|
||||
writer.Write((short)item.ItemID);
|
||||
writer.Write((ushort)item.Layer);
|
||||
writer.Write(parentSerial);
|
||||
writer.Write((short)hue);
|
||||
|
||||
ns.Send(ref buffer, writer.Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue