Changes damage packets (#299)
- [X] Changes damage packets Bumps release version
This commit is contained in:
parent
6f5cb00cdd
commit
c3289a20ab
19 changed files with 89 additions and 170 deletions
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,3 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: CombatPackets.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 sealed class Swing : Packet
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using Server.Network;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -8,49 +7,40 @@ namespace Server.Tests.Network
|
|||
public class DamagePacketTests : IClassFixture<ServerFixture>
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(10, 10)]
|
||||
[InlineData(-5, 0)]
|
||||
[InlineData(1024, 0xFF)]
|
||||
public void TestDamagePacketOld(int inputAmount, byte expectedAmount)
|
||||
[InlineData(10)]
|
||||
[InlineData(-5)]
|
||||
[InlineData(1024)]
|
||||
public void TestDamagePacketOld(int inputAmount)
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
Serial serial = 0x1024;
|
||||
|
||||
var data = new DamagePacketOld(m.Serial, inputAmount).Compile();
|
||||
var expected = new DamagePacketOld(serial, inputAmount).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[11];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.SendDamage(serial, inputAmount);
|
||||
|
||||
expectedData.Write(ref pos, (byte)0xBF); // Packet ID
|
||||
expectedData.Write(ref pos, (ushort)11); // Length
|
||||
expectedData.Write(ref pos, (ushort)0x22); // Sub-packet
|
||||
expectedData.Write(ref pos, (byte)0x01); // Command
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, expectedAmount);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(10, 10)]
|
||||
[InlineData(-5, 0)]
|
||||
[InlineData(1024, 1024)]
|
||||
[InlineData(100000, 0xFFFF)]
|
||||
public void TestDamage(int inputAmount, ushort expectedAmount)
|
||||
[InlineData(10)]
|
||||
[InlineData(-5)]
|
||||
[InlineData(1024)]
|
||||
[InlineData(100000)]
|
||||
public void TestDamage(int inputAmount)
|
||||
{
|
||||
var m = new Mobile(0x1);
|
||||
m.DefaultMobileInit();
|
||||
Serial serial = 0x1024;
|
||||
|
||||
var data = new DamagePacket(m.Serial, inputAmount).Compile();
|
||||
var expected = new DamagePacket(serial, inputAmount).Compile();
|
||||
|
||||
Span<byte> expectedData = stackalloc byte[7];
|
||||
var pos = 0;
|
||||
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||
ns.ProtocolChanges = ProtocolChanges.DamagePacket;
|
||||
|
||||
expectedData.Write(ref pos, (byte)0x0B); // Packet ID
|
||||
expectedData.Write(ref pos, m.Serial);
|
||||
expectedData.Write(ref pos, expectedAmount);
|
||||
ns.SendDamage(serial, inputAmount);
|
||||
|
||||
AssertThat.Equal(data, expectedData);
|
||||
var result = ns.SendPipe.Reader.TryRead();
|
||||
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public sealed class DamagePacketOld : Packet
|
||||
{
|
||||
public DamagePacketOld(Serial mobile, int amount) : base(0xBF)
|
||||
{
|
||||
EnsureCapacity(11);
|
||||
|
||||
Stream.Write((short)0x22);
|
||||
Stream.Write((byte)1);
|
||||
Stream.Write(mobile);
|
||||
|
||||
Stream.Write((byte)Math.Clamp(amount, 0, 255));
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DamagePacket : Packet
|
||||
{
|
||||
public DamagePacket(Serial mobile, int amount) : base(0x0B, 7)
|
||||
{
|
||||
Stream.Write(mobile);
|
||||
|
||||
Stream.Write((ushort)Math.Clamp(amount, 0, 0xFFFF));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace Server.Tests
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public interface IEntity : IPoint3D, ISerializable
|
||||
|
|
|
|||
|
|
@ -6485,60 +6485,17 @@ namespace Server
|
|||
|
||||
public void SendVisibleDamageRelated(Mobile from, int amount)
|
||||
{
|
||||
NetState ourState = m_NetState, theirState = from?.m_NetState;
|
||||
var ourState = m_NetState ?? GetDamageMaster(from)?.m_NetState;
|
||||
var theirState = from?.m_NetState ?? from?.GetDamageMaster(this)?.m_NetState;
|
||||
|
||||
if (ourState == null)
|
||||
if (amount > 0)
|
||||
{
|
||||
var master = GetDamageMaster(from);
|
||||
|
||||
if (master != null)
|
||||
{
|
||||
ourState = master.m_NetState;
|
||||
}
|
||||
}
|
||||
|
||||
if (theirState == null && from != null)
|
||||
{
|
||||
var master = from.GetDamageMaster(this);
|
||||
|
||||
if (master != null)
|
||||
{
|
||||
theirState = master.m_NetState;
|
||||
}
|
||||
}
|
||||
|
||||
if (amount > 0 && (ourState != null || theirState != null))
|
||||
{
|
||||
Packet p = null; // = new DamagePacket( this, amount );
|
||||
|
||||
if (ourState != null)
|
||||
{
|
||||
p = ourState.DamagePacket
|
||||
? Packet.Acquire(new DamagePacket(Serial, amount))
|
||||
: Packet.Acquire(new DamagePacketOld(Serial, amount));
|
||||
|
||||
ourState.Send(p);
|
||||
}
|
||||
ourState?.SendDamage(Serial, amount);
|
||||
|
||||
if (theirState != null && theirState != ourState)
|
||||
{
|
||||
var newPacket = theirState.DamagePacket;
|
||||
|
||||
if (newPacket && !(p is DamagePacket))
|
||||
{
|
||||
Packet.Release(p);
|
||||
p = Packet.Acquire(new DamagePacket(Serial, amount));
|
||||
}
|
||||
else if (!newPacket && !(p is DamagePacketOld))
|
||||
{
|
||||
Packet.Release(p);
|
||||
p = Packet.Acquire(new DamagePacketOld(Serial, amount));
|
||||
}
|
||||
|
||||
theirState.Send(p);
|
||||
theirState.SendDamage(Serial, amount);
|
||||
}
|
||||
|
||||
Packet.Release(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -6558,37 +6515,21 @@ namespace Server
|
|||
|
||||
var eable = map.GetClientsInRange(m_Location);
|
||||
|
||||
Packet pNew = null;
|
||||
Packet pOld = null;
|
||||
|
||||
foreach (var ns in eable)
|
||||
{
|
||||
if (ns.Mobile.CanSee(this))
|
||||
{
|
||||
if (ns.DamagePacket)
|
||||
{
|
||||
pNew ??= Packet.Acquire(new DamagePacket(Serial, amount));
|
||||
|
||||
ns.Send(pNew);
|
||||
}
|
||||
else
|
||||
{
|
||||
pOld ??= Packet.Acquire(new DamagePacketOld(Serial, amount));
|
||||
|
||||
ns.Send(pOld);
|
||||
}
|
||||
ns.SendDamage(Serial, amount);
|
||||
}
|
||||
}
|
||||
|
||||
Packet.Release(pNew);
|
||||
Packet.Release(pOld);
|
||||
|
||||
eable.Free();
|
||||
}
|
||||
|
||||
public void SendVisibleDamageSelective(Mobile from, int amount)
|
||||
{
|
||||
NetState ourState = m_NetState, theirState = from?.m_NetState;
|
||||
var ourState = m_NetState;
|
||||
var theirState = from?.m_NetState;
|
||||
|
||||
var damager = from;
|
||||
var damaged = this;
|
||||
|
|
@ -6620,39 +6561,23 @@ namespace Server
|
|||
}
|
||||
}
|
||||
|
||||
if (amount > 0 && (ourState != null || theirState != null))
|
||||
if (amount > 0)
|
||||
{
|
||||
if (damaged.CanSeeVisibleDamage && ourState != null)
|
||||
if (damaged.CanSeeVisibleDamage)
|
||||
{
|
||||
if (ourState.DamagePacket)
|
||||
{
|
||||
ourState.Send(new DamagePacket(Serial, amount));
|
||||
}
|
||||
else
|
||||
{
|
||||
ourState.Send(new DamagePacketOld(Serial, amount));
|
||||
}
|
||||
ourState?.SendDamage(Serial, amount);
|
||||
}
|
||||
|
||||
if (theirState != null && theirState != ourState && damager.CanSeeVisibleDamage)
|
||||
{
|
||||
if (theirState.DamagePacket)
|
||||
{
|
||||
theirState.Send(new DamagePacket(Serial, amount));
|
||||
}
|
||||
else
|
||||
{
|
||||
theirState.Send(new DamagePacketOld(Serial, amount));
|
||||
}
|
||||
theirState.SendDamage(Serial, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal(int amount) => Heal(amount, this, true);
|
||||
public void Heal(int amount) => Heal(amount, this);
|
||||
|
||||
public void Heal(int amount, Mobile from) => Heal(amount, from, true);
|
||||
|
||||
public void Heal(int amount, Mobile from, bool message)
|
||||
public void Heal(int amount, Mobile from, bool message = true)
|
||||
{
|
||||
if (!Alive || IsDeadBondedPet)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: DamagePackets.cs *
|
||||
* File: OutgoingDamagePackets.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 *
|
||||
|
|
@ -14,30 +14,38 @@
|
|||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Buffers;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
public sealed class DamagePacketOld : Packet
|
||||
public static class OutgoingDamagePackets
|
||||
{
|
||||
public DamagePacketOld(Serial mobile, int amount) : base(0xBF)
|
||||
public static void SendDamage(this NetState ns, Serial serial, int amount)
|
||||
{
|
||||
EnsureCapacity(11);
|
||||
if (ns == null || !ns.GetSendBuffer(out var buffer))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Stream.Write((short)0x22);
|
||||
Stream.Write((byte)1);
|
||||
Stream.Write(mobile);
|
||||
var writer = new CircularBufferWriter(buffer);
|
||||
|
||||
Stream.Write((byte)Math.Clamp(amount, 0, 255));
|
||||
}
|
||||
}
|
||||
if (ns.DamagePacket)
|
||||
{
|
||||
writer.Write((byte)0x0B); // Packet ID
|
||||
writer.Write(serial);
|
||||
writer.Write((ushort)Math.Clamp(amount, 0, 0xFFFF));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write((byte)0xBF); // Packet ID
|
||||
writer.Write((ushort)11); // Length
|
||||
writer.Write((ushort)0x22);
|
||||
writer.Write((byte)1);
|
||||
writer.Write(serial);
|
||||
writer.Write((byte)Math.Clamp(amount, 0, 0xFF));
|
||||
}
|
||||
|
||||
public sealed class DamagePacket : Packet
|
||||
{
|
||||
public DamagePacket(Serial mobile, int amount) : base(0x0B, 7)
|
||||
{
|
||||
Stream.Write(mobile);
|
||||
|
||||
Stream.Write((ushort)Math.Clamp(amount, 0, 0xFFFF));
|
||||
ns.Send(ref buffer, writer.Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using Server.Misc;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests.Accounting
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Server.Misc;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.Security.Cryptography;
|
||||
using Server.Misc;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Server.Misc;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Server.Misc;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
using System;
|
||||
|
||||
namespace Server.Engines.Chat
|
||||
{
|
||||
public class ChatActionHandlers
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using Server.Accounting;
|
||||
|
||||
namespace Server.Engines.Chat
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
using System;
|
||||
|
||||
namespace Server.Misc
|
||||
{
|
||||
// This fastwalk detection is no longer required
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Server.ContextMenus;
|
||||
using Server.Engines.ConPVP;
|
||||
using Server.Engines.MLQuests;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ using System.Linq;
|
|||
using Server.Accounting;
|
||||
using Server.ContextMenus;
|
||||
using Server.Engines.BulkOrders;
|
||||
using Server.Engines.CannedEvil;
|
||||
using Server.Engines.ConPVP;
|
||||
using Server.Engines.Craft;
|
||||
using Server.Engines.Help;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue