示例#1
0
        public void TestMobileStatus(ProtocolChanges changes)
        {
            var beholder = new Mobile(0x1)
            {
                Name = "Random Mobile 1"
            };

            beholder.DefaultMobileInit();
            beholder.Str  = 50;
            beholder.Hits = 100;
            beholder.Int  = 75;
            beholder.Mana = 100;
            beholder.Dex  = 25;
            beholder.Stam = 100;

            var beheld = new Mobile(0x2)
            {
                Name = "Random Mobile 2"
            };

            beheld.DefaultMobileInit();
            beheld.Str  = 50;
            beheld.Hits = 100;
            beheld.Int  = 75;
            beheld.Mana = 100;
            beheld.Dex  = 25;
            beheld.Stam = 100;

            var ns = PacketTestUtilities.CreateTestNetState();

            ns.ProtocolChanges = changes;

            var expected = new MobileStatus(beholder, beheld, ns).Compile();

            ns.SendMobileStatus(beholder, beheld);

            var result = ns.SendPipe.Reader.TryRead();

            AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
        }
示例#2
0
        public void TestMobileStatusExtended(ProtocolChanges changes)
        {
            var beholder = new Mobile(0x1)
            {
                Name = "Random Mobile 1"
            };

            beholder.DefaultMobileInit();

            var beheld = new Mobile(0x2)
            {
                Name = "Random Mobile 2"
            };

            beheld.DefaultMobileInit();

            var ns = new NetState(null)
            {
                ProtocolChanges = changes
            };

            var data = new MobileStatus(beholder, beheld, ns).Compile();

            Span <byte> expectedData = stackalloc byte[121]; // Max Size
            var         pos          = 0;

            expectedData.Write(ref pos, (byte)0x11);
            pos += 2; // Length

            int type;
            var notSelf = beholder != beheld;

            if (notSelf)
            {
                type = 0;
            }
            else if (Core.HS && ns.ExtendedStatus)
            {
                type = 6;
            }
            else if (Core.ML && ns.SupportsExpansion(Expansion.ML))
            {
                type = 5;
            }
            else
            {
                type = Core.AOS ? 4 : 3;
            }

            expectedData.Write(ref pos, beheld.Serial);
            expectedData.WriteAsciiFixed(ref pos, beheld.Name, 30);

            expectedData.WriteReverseAttribute(ref pos, beheld.Hits, beheld.HitsMax, notSelf);

            expectedData.Write(ref pos, beheld.CanBeRenamedBy(beheld));
            expectedData.Write(ref pos, (byte)type);

            if (type > 0)
            {
                expectedData.Write(ref pos, beheld.Female);
                expectedData.Write(ref pos, (ushort)beheld.Str);
                expectedData.Write(ref pos, (ushort)beheld.Dex);
                expectedData.Write(ref pos, (ushort)beheld.Int);

                expectedData.WriteReverseAttribute(ref pos, beheld.Stam, beheld.StamMax, notSelf);
                expectedData.WriteReverseAttribute(ref pos, beheld.Mana, beheld.ManaMax, notSelf);

                expectedData.Write(ref pos, beheld.TotalGold);
                expectedData.Write(
                    ref pos,
                    (ushort)(Core.AOS ? beheld.PhysicalResistance : (int)(beheld.ArmorRating + 0.5))
                    );
                expectedData.Write(ref pos, (ushort)(Mobile.BodyWeight + beheld.TotalWeight));

                if (type >= 5)
                {
                    expectedData.Write(ref pos, (ushort)beheld.MaxWeight);
                    expectedData.Write(ref pos, (byte)(beheld.Race.RaceID + 1)); // 0x00 for a non-ML enabled account
                }

                expectedData.Write(ref pos, (ushort)beheld.StatCap);
                expectedData.Write(ref pos, (byte)beheld.Followers);
                expectedData.Write(ref pos, (byte)beheld.FollowersMax);

                if (type >= 4)
                {
                    expectedData.Write(ref pos, (ushort)beheld.FireResistance);
                    expectedData.Write(ref pos, (ushort)beheld.ColdResistance);
                    expectedData.Write(ref pos, (ushort)beheld.PoisonResistance);
                    expectedData.Write(ref pos, (ushort)beheld.EnergyResistance);
                    expectedData.Write(ref pos, (ushort)beheld.Luck);
                }

                var min = 0;
                var max = 0;
                beheld.Weapon?.GetStatusDamage(beheld, out min, out max);

                expectedData.Write(ref pos, (ushort)min);
                expectedData.Write(ref pos, (ushort)max);

                expectedData.Write(ref pos, beheld.TithingPoints);

                if (type >= 6)
                {
                    for (var i = 0; i < 15; ++i)
                    {
                        expectedData.Write(ref pos, (ushort)beheld.GetAOSStatus(i));
                    }
                }
            }

            expectedData.Slice(1, 2).Write((ushort)pos); // Length

            expectedData = expectedData.Slice(0, pos);
            AssertThat.Equal(data, expectedData);
        }