fix(core): Converts corpse packets (#400)

- [X] Converts corpse packets
- [X] Some cleanup
This commit is contained in:
Kamron Batman 2021-01-10 09:53:05 -08:00 • committed by GitHub
parent 764d303543
commit f52e63f320
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 210 additions and 245 deletions

View file

@ -1,152 +0,0 @@
using System;
using Server.Engines.PartySystem;
using Server.Guilds;
using Server.Network;
namespace Server.Misc
{
public static class MapUO
{
public static void Initialize()
{
if (Settings.PartyTrack)
{
ProtocolExtensions.Register(0x00, true, OnPartyTrack);
}
if (Settings.GuildTrack)
{
ProtocolExtensions.Register(0x01, true, OnGuildTrack);
}
}
private static void OnPartyTrack(NetState state, CircularBufferReader reader)
{
var from = state.Mobile;
var party = Party.Get(from);
if (party != null)
{
var packet = new Packets.PartyTrack(from, party);
if (packet.Stream.Length > 8)
{
state.Send(packet);
}
}
}
private static void OnGuildTrack(NetState state, CircularBufferReader reader)
{
var from = state.Mobile;
if (from.Guild is Guild guild)
{
var locations = reader.ReadByte() != 0;
var packet = new Packets.GuildTrack(from, guild, locations);
if (packet.Stream.Length > (locations ? 9 : 5))
{
state.Send(packet);
}
}
else
{
state.Send(new Packets.GuildTrack());
}
}
private static class Settings
{
public const bool PartyTrack = true;
public const bool GuildTrack = true;
public const bool GuildHitsPercent = true;
}
private static class Packets
{
public sealed class PartyTrack : ProtocolExtension
{
public PartyTrack(Mobile from, Party party) : base(0x01, (party.Members.Count - 1) * 9 + 4)
{
for (var i = 0; i < party.Members.Count; ++i)
{
var pmi = party.Members[i];
if (pmi == null || pmi.Mobile == from)
{
continue;
}
var mob = pmi.Mobile;
if (Utility.InUpdateRange(from, mob) && from.CanSee(mob))
{
continue;
}
Stream.Write(mob.Serial);
Stream.Write((short)mob.X);
Stream.Write((short)mob.Y);
Stream.Write((byte)(mob.Map?.MapID ?? 0));
}
Stream.Write(0);
}
}
public sealed class GuildTrack : ProtocolExtension
{
public GuildTrack() : base(0x02, 5)
{
Stream.Write((byte)0);
Stream.Write(0);
}
public GuildTrack(Mobile from, Guild guild, bool locations) : base(
0x02,
(guild.Members.Count - 1) * (locations ? 10 : 4) + 5
)
{
Stream.Write((byte)(locations ? 1 : 0));
for (var i = 0; i < guild.Members.Count; ++i)
{
var mob = guild.Members[i];
if (mob == null || mob == from || mob.NetState == null)
{
continue;
}
if (locations && Utility.InUpdateRange(from, mob) && from.CanSee(mob))
{
continue;
}
Stream.Write(mob.Serial);
if (locations)
{
Stream.Write((short)mob.X);
Stream.Write((short)mob.Y);
Stream.Write((byte)(mob.Map?.MapID ?? 0));
if (Settings.GuildHitsPercent && mob.Alive)
{
Stream.Write((byte)(mob.Hits / Math.Max(mob.HitsMax, 1.0) * 100));
}
else
{
Stream.Write((byte)0);
}
}
}
Stream.Write(0);
}
}
}
}
}

View file

@ -1,59 +0,0 @@
using Server.Network;
namespace Server.Misc
{
public static class ProtocolExtensions
{
private static readonly PacketHandler[] m_Handlers = new PacketHandler[0x100];
public static void Initialize()
{
// IncomingPackets.Register(0xF0, 0, false, DecodeBundledPacket);
}
public static void Register(int packetID, bool ingame, OnPacketReceive onReceive)
{
m_Handlers[packetID] = new PacketHandler(packetID, 0, ingame, onReceive);
}
public static PacketHandler GetHandler(int packetID) =>
packetID >= 0 && packetID < m_Handlers.Length ? m_Handlers[packetID] : null;
public static void DecodeBundledPacket(NetState state, CircularBufferReader reader)
{
int packetID = reader.ReadByte();
var ph = GetHandler(packetID);
if (ph != null)
{
if (ph.Ingame && state.Mobile == null)
{
state.WriteConsole(
"Sent ingame packet (0xF0x{0:X2}) before having been attached to a mobile",
packetID
);
state.Dispose();
}
else if (ph.Ingame && state.Mobile.Deleted)
{
state.Dispose();
}
else
{
ph.OnReceive(state, reader);
}
}
}
}
public abstract class ProtocolExtension : Packet
{
public ProtocolExtension(int packetID, int capacity) : base(0xF0)
{
EnsureCapacity(4 + capacity);
Stream.Write((byte)packetID);
}
}
}