fix: Fixes snooping staff (#900)

* Not allowed to snoop staff
* Staff that snoop won't broadcast messages
* Benchmarks RNG for double vs fixed int
This commit is contained in:
Kamron Batman 2021-12-28 02:09:25 -08:00 committed by GitHub
parent dc6caf5766
commit 79dc9fa0f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 66 deletions

View file

@ -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;
}
}

View file

@ -15,7 +15,8 @@ namespace Benchmarks
// var textEncoding = BenchmarkRunner.Run<BenchmarkTextEncoding>();
// var logging = BenchmarkRunner.Run<BenchmarkConsoleLogging>();
// var gumpPacket = BenchmarkRunner.Run<OutgoingGumpPacketBenchmarks>();
var rngTest = BenchmarkRunner.Run<BenchmarkXoshiro>();
// var rngTest = BenchmarkRunner.Run<BenchmarkXoshiro>();
var doubleRngText = BenchmarkRunner.Run<BenchmarkDoubleVsFixed>();
}
}
}

View file

@ -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<GuardedRegion>();
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<GuardedRegion>();
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();
}
}
}