fix(core): Converts mobile moving packet (#357)

- [X] Converts mobile moving packet
This commit is contained in:
Kamron Batman 2020-12-24 17:13:55 -08:00 • committed by GitHub
parent c2143584bc
commit 10a6e17640
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 147 additions and 170 deletions

View file

@ -435,12 +435,6 @@ namespace Server
private static readonly TimeSpan ExpireCombatantDelay = TimeSpan.FromMinutes(1.0);
private static readonly TimeSpan ExpireAggressorsDelay = TimeSpan.FromSeconds(5.0);
private static readonly Packet[][] m_MovingPacketCache =
{
new Packet[8],
new Packet[8]
};
private static readonly List<IEntity> m_MoveList = new();
private static readonly List<Mobile> m_MoveClientList = new();
@ -3055,7 +3049,8 @@ namespace Server
sendFacialHair = true;
}
var cache = new[] { new Packet[8], new Packet[8] };
Span<byte> mobileMovingPackets = stackalloc byte[OutgoingMobilePackets.MobileMovingPacketCacheLength];
mobileMovingPackets.InitializePackets(OutgoingMobilePackets.MobileMovingPacketLength);
var ourState = m.m_NetState;
@ -3072,14 +3067,13 @@ namespace Server
ourState.Send(new MobileIncoming(ourState, m, m));
}
if (sendMoving || !ourState.StygianAbyss && (sendHealthbarPoison || sendHealthbarYellow))
{
ourState.SendMobileMovingUsingCache(mobileMovingPackets, m, m);
}
if (ourState.StygianAbyss)
{
if (sendMoving)
{
var noto = Notoriety.Compute(m, m);
ourState.Send(cache[0][noto] = Packet.Acquire(new MobileMoving(m, noto, true)));
}
if (sendHealthbarPoison)
{
ourState.Send(new HealthbarPoison(m));
@ -3090,14 +3084,6 @@ namespace Server
ourState.Send(new HealthbarYellow(m));
}
}
else
{
if (sendMoving || sendHealthbarPoison || sendHealthbarYellow)
{
var noto = Notoriety.Compute(m, m);
ourState.Send(cache[1][noto] = Packet.Acquire(new MobileMoving(m, noto, false)));
}
}
if (sendPublicStats || sendPrivateStats)
{
@ -3218,22 +3204,13 @@ namespace Server
}
}
if (sendMoving || !state.StygianAbyss && (sendHealthbarPoison || sendHealthbarYellow))
{
state.SendMobileMovingUsingCache(mobileMovingPackets, beholder, m);
}
if (state.StygianAbyss)
{
if (sendMoving)
{
var noto = Notoriety.Compute(beholder, m);
var p = cache[0][noto];
if (p == null)
{
cache[0][noto] = p = Packet.Acquire(new MobileMoving(m, noto, true));
}
state.Send(p);
}
if (sendHealthbarPoison)
{
hbpPacket ??= Packet.Acquire(new HealthbarPoison(m));
@ -3248,22 +3225,6 @@ namespace Server
state.Send(hbyPacket);
}
}
else
{
if (sendMoving || sendHealthbarPoison || sendHealthbarYellow)
{
var noto = Notoriety.Compute(beholder, m);
var p = cache[1][noto];
if (p == null)
{
cache[1][noto] = p = Packet.Acquire(new MobileMoving(m, noto, false));
}
state.Send(p);
}
}
if (sendPublicStats)
{
@ -3319,17 +3280,6 @@ namespace Server
eable.Free();
}
if (sendMoving || sendNonlocalMoving || sendHealthbarPoison || sendHealthbarYellow)
{
for (var i = 0; i < cache.Length; ++i)
{
for (var j = 0; j < cache[i].Length; ++j)
{
Packet.Release(ref cache[i][j]);
}
}
}
}
public ISpawner Spawner { get; set; }
@ -4580,11 +4530,8 @@ namespace Server
eable.Free();
var cache = m_MovingPacketCache;
/*for( int i = 0; i < cache.Length; ++i )
for( int j = 0; j < cache[i].Length; ++j )
Packet.Release( ref cache[i][j] );*/
Span<byte> mobileMovingPackets = stackalloc byte[OutgoingMobilePackets.MobileMovingPacketCacheLength];
mobileMovingPackets.InitializePackets(OutgoingMobilePackets.MobileMovingPacketLength);
foreach (var m in m_MoveClientList)
{
@ -4592,38 +4539,7 @@ namespace Server
if (ns != null && Utility.InUpdateRange(m_Location, m.m_Location) && m.CanSee(this))
{
if (ns.StygianAbyss)
{
var noto = Notoriety.Compute(m, this);
var p = cache[0][noto];
if (p == null)
{
cache[0][noto] = p = Packet.Acquire(new MobileMoving(this, noto, true));
}
ns.Send(p);
}
else
{
var noto = Notoriety.Compute(m, this);
var p = cache[1][noto];
if (p == null)
{
cache[1][noto] = p = Packet.Acquire(new MobileMoving(this, noto, false));
}
ns.Send(p);
}
}
}
for (var i = 0; i < cache.Length; ++i)
{
for (var j = 0; j < cache[i].Length; ++j)
{
Packet.Release(ref cache[i][j]);
ns.SendMobileMovingUsingCache(mobileMovingPackets, m, this);
}
}