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
|
|
@ -1,23 +1,8 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: AttributeNormalizer.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/>. *
|
||||
*************************************************************************/
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public static class AttributeNormalizer
|
||||
{
|
||||
public static int Maximum { get; set; } = 25;
|
||||
public static int Maximum { get; set; } = 100;
|
||||
|
||||
public static bool Enabled { get; set; } = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,92 +17,6 @@ using System.Threading;
|
|||
|
||||
namespace Server.Network
|
||||
{
|
||||
public sealed class MobileHits : Packet
|
||||
{
|
||||
public MobileHits(Mobile m) : base(0xA1, 9)
|
||||
{
|
||||
Stream.Write(m.Serial);
|
||||
Stream.Write((short)m.HitsMax);
|
||||
Stream.Write((short)m.Hits);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MobileHitsN : Packet
|
||||
{
|
||||
public MobileHitsN(Mobile m) : base(0xA1, 9)
|
||||
{
|
||||
Stream.Write(m.Serial);
|
||||
AttributeNormalizer.Write(Stream, m.Hits, m.HitsMax);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MobileMana : Packet
|
||||
{
|
||||
public MobileMana(Mobile m) : base(0xA2, 9)
|
||||
{
|
||||
Stream.Write(m.Serial);
|
||||
Stream.Write((short)m.ManaMax);
|
||||
Stream.Write((short)m.Mana);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MobileManaN : Packet
|
||||
{
|
||||
public MobileManaN(Mobile m) : base(0xA2, 9)
|
||||
{
|
||||
Stream.Write(m.Serial);
|
||||
AttributeNormalizer.Write(Stream, m.Mana, m.ManaMax);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MobileStam : Packet
|
||||
{
|
||||
public MobileStam(Mobile m) : base(0xA3, 9)
|
||||
{
|
||||
Stream.Write(m.Serial);
|
||||
Stream.Write((short)m.StamMax);
|
||||
Stream.Write((short)m.Stam);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MobileStamN : Packet
|
||||
{
|
||||
public MobileStamN(Mobile m) : base(0xA3, 9)
|
||||
{
|
||||
Stream.Write(m.Serial);
|
||||
AttributeNormalizer.Write(Stream, m.Stam, m.StamMax);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MobileAttributes : Packet
|
||||
{
|
||||
public MobileAttributes(Mobile m) : base(0x2D, 17)
|
||||
{
|
||||
Stream.Write(m.Serial);
|
||||
|
||||
Stream.Write((short)m.HitsMax);
|
||||
Stream.Write((short)m.Hits);
|
||||
|
||||
Stream.Write((short)m.ManaMax);
|
||||
Stream.Write((short)m.Mana);
|
||||
|
||||
Stream.Write((short)m.StamMax);
|
||||
Stream.Write((short)m.Stam);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MobileAttributesN : Packet
|
||||
{
|
||||
public MobileAttributesN(Mobile m) : base(0x2D, 17)
|
||||
{
|
||||
Stream.Write(m.Serial);
|
||||
|
||||
AttributeNormalizer.Write(Stream, m.Hits, m.HitsMax);
|
||||
AttributeNormalizer.Write(Stream, m.Mana, m.ManaMax);
|
||||
AttributeNormalizer.Write(Stream, m.Stam, m.StamMax);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MobileName : Packet
|
||||
{
|
||||
public MobileName(Mobile m) : base(0x98)
|
||||
|
|
|
|||
|
|
@ -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