ModernUO/Projects/UOContent/Mobiles/Monsters/Mammal/Melee/VorpalBunny.cs
Kamron Batman ee2cd1d18d
feat: Adds new decay system and SkipSerialization (#2311)
## Summary

- Replaces scan-based decay checking during world saves with an event-driven timer wheel scheduler
- Removes virtual property checks from serialization hot path, achieving 6-8x faster world saves

## Changes

### DecayScheduler (new):
- Timer wheel with 12 HashSet buckets (5-min intervals) + PriorityQueue for active processing
- O(1) register/unregister vs O(n) scan of all items
- Auto start/stop when items exist/empty
- Configurable tick interval with jitter to prevent system synchronization

### Item.cs:
- Added ScheduledDecayTime computed property
- Added UpdateDecayRegistration() called from SetLastMoved(), property setters, AddItem()/RemoveItem()
- Hooks in Visible, Movable, Spawner setters and Delete()

### World.cs:
- Removed _decayQueue, EnqueueForDecay(), ProcessDecay()
- ItemPersistence.Serialize() now tight loop without virtual calls

## Performance

| Metric        | Before     | After     | Improvement |
|---------------|------------|-----------|-------------|
| Items (230K)  | 245K ticks | 34K ticks | 8x faster   |
| Mobiles (43K) | 56K ticks  | 6K ticks  | 9x faster   |
| Total         | 302K ticks | 40K ticks | 7.5x faster |

## Configuration

decay.maxItemsPerTick = 250       # Items processed per tick
decay.tickInterval = 256ms        # Base processing interval
decay.bucketInterval = 5min       # Timer wheel bucket size
decay.jitterMaxMs = 25            # ±25ms tick jitter
2026-01-08 11:43:51 -08:00

108 lines
2.7 KiB
C#

using ModernUO.Serialization;
using System;
using Server.Items;
namespace Server.Mobiles
{
[SerializationGenerator(0, false)]
public partial class VorpalBunny : BaseCreature
{
[Constructible]
public VorpalBunny() : base(AIType.AI_Melee)
{
Body = 205;
Hue = 0x480;
SetStr(15);
SetDex(2000);
SetInt(1000);
SetHits(2000);
SetStam(500);
SetMana(0);
SetDamage(1);
SetDamageType(ResistanceType.Physical, 100);
SetSkill(SkillName.MagicResist, 200.0);
SetSkill(SkillName.Tactics, 5.0);
SetSkill(SkillName.Wrestling, 5.0);
Fame = 1000;
Karma = 0;
VirtualArmor = 4;
var carrots = Utility.RandomMinMax(5, 10);
PackItem(new Carrot(carrots));
if (Utility.Random(5) == 0)
{
PackItem(new BrightlyColoredEggs());
}
PackStatue();
DelayBeginTunnel();
}
public override string CorpseName => "a vorpal bunny corpse";
public override string DefaultName => "a vorpal bunny";
public override int Meat => 1;
public override int Hides => 1;
public override bool BardImmune => !Core.AOS;
public override void GenerateLoot()
{
AddLoot(LootPack.FilthyRich);
AddLoot(LootPack.Rich, 2);
}
public virtual void DelayBeginTunnel()
{
Timer.StartTimer(TimeSpan.FromMinutes(3.0), BeginTunnel);
}
public virtual void BeginTunnel()
{
if (Deleted)
{
return;
}
// TODO: Add splashing in the water - cliloc 1114451
new BunnyHole().MoveToWorld(Location, Map);
Frozen = true;
// * The bunny begins to dig a tunnel back to its underground lair *
Say(1114450);
PlaySound(0x247);
Timer.StartTimer(TimeSpan.FromSeconds(5.0), Delete);
}
public override int GetAttackSound() => 0xC9;
public override int GetHurtSound() => 0xCA;
public override int GetDeathSound() => 0xCB;
[SerializationGenerator(0, false)]
public partial class BunnyHole : Item
{
public BunnyHole() : base(0x913)
{
Movable = false;
Hue = 1;
Timer.StartTimer(TimeSpan.FromSeconds(40.0), Delete);
}
public override string DefaultName => "a mysterious rabbit hole";
public override bool SkipSerialization => true;
}
}
}