fix(core): Converts mobile stats packets (#360)
- [X] Converts mobile stats packets - [X] Removes human racial from non-players
This commit is contained in:
parent
d73afdba8e
commit
5b69f1d389
10 changed files with 413 additions and 423 deletions
|
|
@ -25,6 +25,9 @@ namespace Server.Network
|
|||
public const int DeathAnimationPacketLength = 13;
|
||||
public const int MobileMovingPacketLength = 17;
|
||||
public const int MobileMovingPacketCacheLength = MobileMovingPacketLength * 8 * 2; // 8 notoriety, 2 client versions
|
||||
public const int AttributeMaximum = 100;
|
||||
public const int MobileAttributePacketLength = 9;
|
||||
public const int MobileAttributesPacketLength = 17;
|
||||
|
||||
public static void CreateBondedStatus(Span<byte> buffer, Serial serial, bool bonded)
|
||||
{
|
||||
|
|
@ -135,5 +138,119 @@ namespace Server.Network
|
|||
|
||||
ns.Send(buffer);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void WriteAttribute(this ref SpanWriter writer, int max, int cur, bool normalize = false, bool reverse = false)
|
||||
{
|
||||
if (normalize && max != 0)
|
||||
{
|
||||
if (reverse)
|
||||
{
|
||||
writer.Write((short)(cur * AttributeMaximum / max));
|
||||
writer.Write((short)AttributeMaximum);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write((short)AttributeMaximum);
|
||||
writer.Write((short)(cur * AttributeMaximum / max));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (reverse)
|
||||
{
|
||||
writer.Write((short)cur);
|
||||
writer.Write((short)max);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write((short)max);
|
||||
writer.Write((short)cur);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendMobileHits(this NetState ns, Mobile m, bool normalize = false)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Span<byte> span = stackalloc byte[MobileAttributePacketLength];
|
||||
CreateMobileHits(ref span, m, normalize);
|
||||
ns.Send(span);
|
||||
}
|
||||
|
||||
public static void CreateMobileHits(ref Span<byte> buffer, Mobile m, bool normalize = false)
|
||||
{
|
||||
var writer = new SpanWriter(buffer);
|
||||
writer.Write((byte)0xA1); // Packet ID
|
||||
writer.Write(m.Serial);
|
||||
writer.WriteAttribute(m.HitsMax, m.Hits, normalize);
|
||||
}
|
||||
|
||||
public static void SendMobileMana(this NetState ns, Mobile m, bool normalize = false)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Span<byte> span = stackalloc byte[MobileAttributePacketLength];
|
||||
CreateMobileMana(ref span, m, normalize);
|
||||
ns.Send(span);
|
||||
}
|
||||
|
||||
public static void CreateMobileMana(ref Span<byte> buffer, Mobile m, bool normalize = false)
|
||||
{
|
||||
var writer = new SpanWriter(buffer);
|
||||
writer.Write((byte)0xA2); // Packet ID
|
||||
writer.Write(m.Serial);
|
||||
writer.WriteAttribute(m.ManaMax, m.Mana, normalize);
|
||||
}
|
||||
|
||||
public static void SendMobileStam(this NetState ns, Mobile m, bool normalize = false)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Span<byte> span = stackalloc byte[MobileAttributePacketLength];
|
||||
CreateMobileStam(ref span, m, normalize);
|
||||
ns.Send(span);
|
||||
}
|
||||
|
||||
public static void CreateMobileStam(ref Span<byte> buffer, Mobile m, bool normalize = false)
|
||||
{
|
||||
var writer = new SpanWriter(buffer);
|
||||
writer.Write((byte)0xA3); // Packet ID
|
||||
writer.Write(m.Serial);
|
||||
writer.WriteAttribute(m.StamMax, m.Stam, normalize);
|
||||
}
|
||||
|
||||
public static void SendMobileAttributes(this NetState ns, Mobile m, bool normalize = false)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Span<byte> span = stackalloc byte[MobileAttributesPacketLength];
|
||||
CreateMobileAttributes(ref span, m, normalize);
|
||||
ns.Send(span);
|
||||
}
|
||||
|
||||
public static void CreateMobileAttributes(ref Span<byte> buffer, Mobile m, bool normalize = false)
|
||||
{
|
||||
var writer = new SpanWriter(buffer);
|
||||
writer.Write((byte)0x2D); // Packet ID
|
||||
writer.Write(m.Serial);
|
||||
|
||||
writer.WriteAttribute(m.HitsMax, m.Hits, normalize);
|
||||
writer.WriteAttribute(m.ManaMax, m.Mana, normalize);
|
||||
writer.WriteAttribute(m.StamMax, m.Stam, normalize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue