From 79dc9fa0f713b339c1011f4bc4dd1371b6ff0785 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Tue, 28 Dec 2021 02:09:25 -0800 Subject: [PATCH] fix: Fixes snooping staff (#900) * Not allowed to snoop staff * Staff that snoop won't broadcast messages * Benchmarks RNG for double vs fixed int --- .../Benchmarks/Rng/BenchmarkDoubleVsFixed.cs | 28 ++++ Projects/Benchmarks/Program.cs | 3 +- Projects/UOContent/Skills/Snooping.cs | 123 +++++++++--------- 3 files changed, 88 insertions(+), 66 deletions(-) create mode 100644 Projects/Benchmarks/Benchmarks/Rng/BenchmarkDoubleVsFixed.cs diff --git a/Projects/Benchmarks/Benchmarks/Rng/BenchmarkDoubleVsFixed.cs b/Projects/Benchmarks/Benchmarks/Rng/BenchmarkDoubleVsFixed.cs new file mode 100644 index 000000000..53b079cb5 --- /dev/null +++ b/Projects/Benchmarks/Benchmarks/Rng/BenchmarkDoubleVsFixed.cs @@ -0,0 +1,28 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Jobs; +using Server.Random; + +namespace Benchmarks.Benchmarks.Rng +{ + [MemoryDiagnoser] + [SimpleJob(RuntimeMoniker.Net60)] + public class BenchmarkDoubleVsFixed + { + private Xoshiro256PlusPlus _xoshiro256PlusPlus; + + [GlobalSetup] + public void Setup() + { + _xoshiro256PlusPlus = new Xoshiro256PlusPlus(); + } + + [Benchmark] + public bool NextDouble() => 50.1 < _xoshiro256PlusPlus.NextDouble() * 100; + + [Benchmark] + public bool NextFixedInt() => 501 < _xoshiro256PlusPlus.Next(1000); + + [Benchmark] + public bool NextHighResDouble() => 50.1 < _xoshiro256PlusPlus.NextDoubleHighRes() * 100; + } +} diff --git a/Projects/Benchmarks/Program.cs b/Projects/Benchmarks/Program.cs index 845354d56..4b5671c0f 100644 --- a/Projects/Benchmarks/Program.cs +++ b/Projects/Benchmarks/Program.cs @@ -15,7 +15,8 @@ namespace Benchmarks // var textEncoding = BenchmarkRunner.Run(); // var logging = BenchmarkRunner.Run(); // var gumpPacket = BenchmarkRunner.Run(); - var rngTest = BenchmarkRunner.Run(); + // var rngTest = BenchmarkRunner.Run(); + var doubleRngText = BenchmarkRunner.Run(); } } } diff --git a/Projects/UOContent/Skills/Snooping.cs b/Projects/UOContent/Skills/Snooping.cs index 73b03bffc..58b28ee24 100644 --- a/Projects/UOContent/Skills/Snooping.cs +++ b/Projects/UOContent/Skills/Snooping.cs @@ -3,68 +3,64 @@ using Server.Misc; using Server.Mobiles; using Server.Regions; -namespace Server.SkillHandlers +namespace Server.SkillHandlers; + +public static class Snooping { - public static class Snooping + public static void Configure() { - public static void Configure() + Container.SnoopHandler = Container_Snoop; + } + + public static bool CheckSnoopAllowed(Mobile from, Mobile to) + { + var map = from.Map; + + if (to.Player) { - Container.SnoopHandler = Container_Snoop; + return from.CanBeHarmful(to, false, true); // normal restrictions } - public static bool CheckSnoopAllowed(Mobile from, Mobile to) + if ((map?.Rules & MapRules.HarmfulRestrictions) == 0) { - var map = from.Map; - - if (to.Player) - { - return from.CanBeHarmful(to, false, true); // normal restrictions - } - - if ((map?.Rules & MapRules.HarmfulRestrictions) == 0) - { - return true; // felucca you can snoop anybody - } - - var reg = to.Region.GetRegion(); - - if (reg?.IsDisabled() != true) - { - return true; // not in town? we can snoop any npc - } - - return !to.Body.IsHuman || to is BaseCreature cret && (cret.AlwaysAttackable || cret.AlwaysMurderer); + return true; // felucca you can snoop anybody } - public static void Container_Snoop(Container cont, Mobile from) + var reg = to.Region.GetRegion(); + + if (reg?.IsDisabled() != true) { - if (from.AccessLevel <= AccessLevel.Player && !from.InRange(cont.GetWorldLocation(), 1)) - { - from.SendLocalizedMessage(500446); // That is too far away. - return; - } + return true; // not in town? we can snoop any npc + } - var root = cont.RootParent as Mobile; + return !to.Body.IsHuman || to is BaseCreature cret && (cret.AlwaysAttackable || cret.AlwaysMurderer); + } - if (root?.Alive == false) - { - return; - } + public static void Container_Snoop(Container cont, Mobile from) + { + if (from.AccessLevel <= AccessLevel.Player && !from.InRange(cont.GetWorldLocation(), 1)) + { + from.SendLocalizedMessage(500446); // That is too far away. + return; + } - if (root?.AccessLevel > AccessLevel.Player && from.AccessLevel == AccessLevel.Player) - { - from.SendLocalizedMessage(500209); // You can not peek into the container. - return; - } + var root = cont.RootParent as Mobile; - if (root?.AccessLevel == AccessLevel.Player && !CheckSnoopAllowed(from, root)) - { - from.SendLocalizedMessage(1001018); // You cannot perform negative acts on your target. - return; - } + if (root?.Alive == false) + { + return; + } - if (root?.AccessLevel == AccessLevel.Player && - from.Skills.Snooping.Value < Utility.Random(100)) + if (root?.AccessLevel > AccessLevel.Player || !CheckSnoopAllowed(from, root)) + { + from.SendLocalizedMessage(1001018); // You cannot perform negative acts on your target. + return; + } + + if (from.AccessLevel == AccessLevel.Player) + { + var snooping = from.Skills.Snooping.Value; + if (root != null && snooping < 100.0 && snooping < Utility.RandomDouble() * 100) { var map = from.Map; @@ -86,28 +82,25 @@ namespace Server.SkillHandlers } } - if (from.AccessLevel == AccessLevel.Player) + Titles.AwardKarma(from, -4, true); + } + + if (from.AccessLevel > AccessLevel.Player || from.CheckTargetSkill(SkillName.Snooping, cont, 0.0, 100.0)) + { + if ((cont as TrappableContainer)?.ExecuteTrap(from) == true) { - Titles.AwardKarma(from, -4, true); + return; } - if (from.AccessLevel > AccessLevel.Player || from.CheckTargetSkill(SkillName.Snooping, cont, 0.0, 100.0)) - { - if (cont is TrappableContainer container && container.ExecuteTrap(from)) - { - return; - } + cont.DisplayTo(from); + } + else + { + from.SendLocalizedMessage(500210); // You failed to peek into the container. - cont.DisplayTo(from); - } - else + if (from.Skills.Hiding.Value / 2 < Utility.RandomDouble() * 100) { - from.SendLocalizedMessage(500210); // You failed to peek into the container. - - if (from.Skills.Hiding.Value / 2 < Utility.Random(100)) - { - from.RevealingAction(); - } + from.RevealingAction(); } } }