fix(core): Converts healthbar packets (#367)
- [X] Converts healthbar packets
This commit is contained in:
parent
26243a72a7
commit
8f8b650ab5
22 changed files with 174 additions and 166 deletions
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Server.Buffers;
|
||||
|
||||
namespace Server
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
[NoSort, Parsable, PropertyObject]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Server.Guilds
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using Server.Accounting;
|
||||
using Server.Buffers;
|
||||
using Server.ContextMenus;
|
||||
|
|
@ -345,6 +344,13 @@ namespace Server
|
|||
Attributes = 0x0000001C
|
||||
}
|
||||
|
||||
public enum Healthbar
|
||||
{
|
||||
Normal,
|
||||
Poison,
|
||||
Yellow
|
||||
}
|
||||
|
||||
public enum AccessLevel
|
||||
{
|
||||
Player,
|
||||
|
|
@ -2978,17 +2984,6 @@ namespace Server
|
|||
sendIncoming = true;
|
||||
}
|
||||
|
||||
/*if ((delta & MobileDelta.Hue) != 0)
|
||||
{
|
||||
sendNonlocalIncoming = true;
|
||||
sendUpdate = true;
|
||||
}
|
||||
else if ((delta & (MobileDelta.Direction | MobileDelta.Body)) != 0)
|
||||
{
|
||||
sendNonlocalMoving = true;
|
||||
sendUpdate = true;
|
||||
}
|
||||
else*/
|
||||
if ((delta & (MobileDelta.Flags | MobileDelta.Noto)) != 0)
|
||||
{
|
||||
sendMoving = true;
|
||||
|
|
@ -3066,12 +3061,12 @@ namespace Server
|
|||
{
|
||||
if (sendHealthbarPoison)
|
||||
{
|
||||
ourState.Send(new HealthbarPoison(m));
|
||||
ourState.SendMobileHealthbar(m, Healthbar.Poison);
|
||||
}
|
||||
|
||||
if (sendHealthbarYellow)
|
||||
{
|
||||
ourState.Send(new HealthbarYellow(m));
|
||||
ourState.SendMobileHealthbar(m, Healthbar.Yellow);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3164,6 +3159,12 @@ namespace Server
|
|||
|
||||
var eable = m.Map.GetClientsInRange(m.m_Location);
|
||||
|
||||
Span<byte> hbpBuffer = stackalloc byte[OutgoingMobilePackets.MobileHealthbarPacketLength];
|
||||
hbpBuffer.InitializePacket();
|
||||
|
||||
Span<byte> hbyBuffer = stackalloc byte[OutgoingMobilePackets.MobileHealthbarPacketLength];
|
||||
hbyBuffer.InitializePacket();
|
||||
|
||||
Span<byte> deadBuffer = stackalloc byte[OutgoingMobilePackets.BondedStatusPacketLength];
|
||||
deadBuffer.InitializePacket();
|
||||
|
||||
|
|
@ -3216,14 +3217,20 @@ namespace Server
|
|||
{
|
||||
if (sendHealthbarPoison)
|
||||
{
|
||||
hbpPacket ??= Packet.Acquire(new HealthbarPoison(m));
|
||||
if (hbpBuffer[0] == 0)
|
||||
{
|
||||
OutgoingMobilePackets.CreateMobileHealthbar(hbpBuffer, m, Healthbar.Poison);
|
||||
}
|
||||
|
||||
state.Send(hbpPacket);
|
||||
}
|
||||
|
||||
if (sendHealthbarYellow)
|
||||
{
|
||||
hbyPacket ??= Packet.Acquire(new HealthbarYellow(m));
|
||||
if (hbyBuffer[0] == 0)
|
||||
{
|
||||
OutgoingMobilePackets.CreateMobileHealthbar(hbyBuffer, m, Healthbar.Yellow);
|
||||
}
|
||||
|
||||
state.Send(hbyPacket);
|
||||
}
|
||||
|
|
@ -7150,15 +7157,8 @@ namespace Server
|
|||
|
||||
if (ns.StygianAbyss)
|
||||
{
|
||||
if (m.Poisoned)
|
||||
{
|
||||
ns.Send(new HealthbarPoison(m));
|
||||
}
|
||||
|
||||
if (m.Blessed || m.YellowHealthbar)
|
||||
{
|
||||
ns.Send(new HealthbarYellow(m));
|
||||
}
|
||||
ns.SendMobileHealthbar(m, Healthbar.Poison);
|
||||
ns.SendMobileHealthbar(m, Healthbar.Yellow);
|
||||
}
|
||||
|
||||
if (m.IsDeadBondedPet)
|
||||
|
|
@ -7562,27 +7562,25 @@ namespace Server
|
|||
}
|
||||
|
||||
var inOldRange = Utility.InUpdateRange(oldLocation, m.m_Location);
|
||||
var ns = m.m_NetState;
|
||||
|
||||
if (m.m_NetState != null &&
|
||||
(isTeleport && (!m.m_NetState.HighSeas || !NoMoveHS) || !inOldRange) && m.CanSee(this))
|
||||
if (ns != null &&
|
||||
(isTeleport && (!ns.HighSeas || !NoMoveHS) || !inOldRange) && m.CanSee(this))
|
||||
{
|
||||
m.m_NetState.Send(new MobileIncoming(m.m_NetState, m, this));
|
||||
ns.Send(new MobileIncoming(m.m_NetState, m, this));
|
||||
|
||||
if (m.m_NetState.StygianAbyss)
|
||||
if (ns.StygianAbyss)
|
||||
{
|
||||
// if (m_Poison != null)
|
||||
m.m_NetState.Send(new HealthbarPoison(this));
|
||||
|
||||
// if (m_Blessed || m_YellowHealthbar)
|
||||
m.m_NetState.Send(new HealthbarYellow(this));
|
||||
ns.SendMobileHealthbar(this, Healthbar.Poison);
|
||||
ns.SendMobileHealthbar(this, Healthbar.Yellow);
|
||||
}
|
||||
|
||||
if (IsDeadBondedPet)
|
||||
{
|
||||
m.m_NetState.SendBondedStatus(Serial, true);
|
||||
ns.SendBondedStatus(Serial, true);
|
||||
}
|
||||
|
||||
SendOPLPacketTo(m.m_NetState);
|
||||
SendOPLPacketTo(ns);
|
||||
}
|
||||
|
||||
if (inOldRange || !CanSee(m))
|
||||
|
|
@ -7594,11 +7592,8 @@ namespace Server
|
|||
|
||||
if (ourState.StygianAbyss)
|
||||
{
|
||||
// if (m.Poisoned)
|
||||
ourState.Send(new HealthbarPoison(m));
|
||||
|
||||
// if (m.Blessed || m.YellowHealthbar)
|
||||
ourState.Send(new HealthbarYellow(m));
|
||||
ourState.SendMobileHealthbar(m, Healthbar.Poison);
|
||||
ourState.SendMobileHealthbar(m, Healthbar.Yellow);
|
||||
}
|
||||
|
||||
if (m.IsDeadBondedPet)
|
||||
|
|
@ -7626,11 +7621,8 @@ namespace Server
|
|||
|
||||
if (ns.StygianAbyss)
|
||||
{
|
||||
// if (m_Poison != null)
|
||||
ns.Send(new HealthbarPoison(this));
|
||||
|
||||
// if (m_Blessed || m_YellowHealthbar)
|
||||
ns.Send(new HealthbarYellow(this));
|
||||
ns.SendMobileHealthbar(this, Healthbar.Poison);
|
||||
ns.SendMobileHealthbar(this, Healthbar.Yellow);
|
||||
}
|
||||
|
||||
if (IsDeadBondedPet)
|
||||
|
|
@ -7707,15 +7699,8 @@ namespace Server
|
|||
|
||||
if (state.StygianAbyss)
|
||||
{
|
||||
if (m_Poison != null)
|
||||
{
|
||||
state.Send(new HealthbarPoison(this));
|
||||
}
|
||||
|
||||
if (m_Blessed || m_YellowHealthbar)
|
||||
{
|
||||
state.Send(new HealthbarYellow(this));
|
||||
}
|
||||
state.SendMobileHealthbar(this, Healthbar.Poison);
|
||||
state.SendMobileHealthbar(this, Healthbar.Yellow);
|
||||
}
|
||||
|
||||
if (IsDeadBondedPet)
|
||||
|
|
|
|||
|
|
@ -259,52 +259,6 @@ namespace Server.Network
|
|||
}
|
||||
}
|
||||
|
||||
public sealed class HealthbarPoison : Packet
|
||||
{
|
||||
public HealthbarPoison(Mobile m) : base(0x17)
|
||||
{
|
||||
EnsureCapacity(12);
|
||||
|
||||
Stream.Write(m.Serial);
|
||||
Stream.Write((short)1); // Show Bar?
|
||||
|
||||
Stream.Write((short)1); // Poison Bar
|
||||
|
||||
var p = m.Poison;
|
||||
|
||||
if (p != null)
|
||||
{
|
||||
Stream.Write((byte)(p.Level + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HealthbarYellow : Packet
|
||||
{
|
||||
public HealthbarYellow(Mobile m) : base(0x17)
|
||||
{
|
||||
EnsureCapacity(12);
|
||||
|
||||
Stream.Write(m.Serial);
|
||||
Stream.Write((short)1);
|
||||
|
||||
Stream.Write((short)2);
|
||||
|
||||
if (m.Blessed || m.YellowHealthbar)
|
||||
{
|
||||
Stream.Write((byte)1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Stream.Write((byte)0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class MobileUpdate : Packet
|
||||
{
|
||||
public MobileUpdate(Mobile m, bool stygianAbyss) : base(0x20, 19)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ namespace Server.Network
|
|||
public const int MobileAttributesPacketLength = 17;
|
||||
public const int MobileAnimationPacketLength = 14;
|
||||
public const int NewMobileAnimationPacketLength = 10;
|
||||
public const int MobileHealthbarPacketLength = 12;
|
||||
|
||||
public static void CreateBondedStatus(Span<byte> buffer, Serial serial, bool bonded)
|
||||
{
|
||||
|
|
@ -327,5 +328,51 @@ namespace Server.Network
|
|||
CreateNewMobileAnimation(span, mobile, action, frameCount, delay);
|
||||
ns.Send(span);
|
||||
}
|
||||
|
||||
public static void SendMobileHealthbar(this NetState ns, Mobile m, Healthbar healthbar)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Span<byte> span = stackalloc byte[MobileHealthbarPacketLength];
|
||||
CreateMobileHealthbar(span, m, healthbar);
|
||||
ns.Send(span);
|
||||
}
|
||||
|
||||
public static void CreateMobileHealthbar(Span<byte> buffer, Mobile m, Healthbar healthbar)
|
||||
{
|
||||
switch (healthbar)
|
||||
{
|
||||
case Healthbar.Poison:
|
||||
{
|
||||
CreateMobileHealthbar(buffer, m.Serial, Healthbar.Poison, m.Poison?.Level + 1 ?? 0);
|
||||
break;
|
||||
}
|
||||
case Healthbar.Yellow:
|
||||
{
|
||||
CreateMobileHealthbar(buffer, m.Serial, Healthbar.Yellow, m.Blessed || m.YellowHealthbar ? 1 : 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Console.WriteLine("Packets: Invalid Healthbar {0} in {1}", healthbar, nameof(CreateMobileHealthbar));
|
||||
CreateMobileHealthbar(buffer, m.Serial, Healthbar.Normal, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateMobileHealthbar(Span<byte> buffer, Serial serial, Healthbar healthbar, int level)
|
||||
{
|
||||
var writer = new SpanWriter(buffer);
|
||||
writer.Write((byte)0x17); // Packet ID
|
||||
writer.Write((ushort)12);
|
||||
writer.Write(serial);
|
||||
writer.Write((short)1); // Show bar
|
||||
writer.Write((short)healthbar);
|
||||
writer.Write((byte)level); // 0 is off for that bar type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue