### Summary
Moves inventory insurance out of `Mobile`/`PlayerMobile` into its own system at `Projects/UOContent/Engines/Insurance/`, wires it into the feature flag system, and makes disabling it actually disable it everywhere.
### Changes
**New `Server.Engines.Insurance.Insurance` system**
* Owns its own `Configure()`, seeding from the existing `insurance.enable` setting (default `Core.AOS`), so no config migration is needed. `Mobile.InsuranceEnabled` is gone, along with its line in `ExpansionConfiguration`.
* `CanInsure`, `GetInsuranceCost`, `ToggleItemInsurance`, `AutoRenewInventoryInsurance`, `CancelRenewInventoryInsurance` and `OpenItemInsuranceMenu` move here from `PlayerMobile`, which keeps four one-line shims for the context-menu callbacks.
* Every entry point is gated on `Insurance.Enabled`, and the death-time state is only allocated when insurance is on — a shard without insurance pays nothing for it.
**Feature flag integration**
Insurance is now a first-class feature flag: `ServerFeatureFlags.InsuranceEnabled`, registered under the `insurance` key in `FeatureFlagManager.SyncStaticFlag`, so it can be inspected and toggled through the normal flag command/gump rather than only at boot. `Insurance.Enabled` reads through to the flag, so there is one source of truth for every consumer.
**Fixes a memory leak from PvP**
`PlayerMobile.m_InsuranceAward` was a `Mobile` field assigned on every death and never cleared, so every player permanently pinned a strong reference to the last player who killed them. Killers were kept alive by their victims indefinitely.
Death-time insurance state now lives in a `Dictionary<Mobile, InsuranceContext>` owned by the insurance system: the entry is created in `OnBeforeDeath` and removed in `OnDeath`, so nothing outlives the death that created it.
**Removes insurance fields from every PlayerMobile**
`m_InsuranceAward`, `m_InsuranceBonus` and `m_NonAutoreinsuredItems` were carried by every `PlayerMobile` whether or not the shard ran insurance. All three are gone; the equivalent state is allocated per-death, only for players who actually die with insured items, only when insurance is enabled.
**Stale `Insured` flags are inert when insurance is off**
`Item.Insured` is a persisted flag, so items stay marked after a shard turns insurance off. Every read path now checks the flag first, so those items behave exactly as if they were never insured:
* `Item.CheckBlessed` / `Item.IsStandardLoot` — they drop again instead of acting blessed
* `Item.AddLootTypeProperty` — no more phantom "insured" tooltip
* `PlayerMobile.FindItems_Callback` — not yanked out of nested bags on death
* `DestroyEquipment` — no longer immune
* `ClothingBlessDeed` — no longer reports "that item is already blessed"
**Gumps promoted out of `PlayerMobile`**
`ItemInsuranceMenuGump`, `ItemInsuranceMenuConfirmGump` and `CancelRenewInventoryInsuranceGump` were private nested classes reaching into `PlayerMobile` privates. They are now public types in `Engines/Insurance/Gumps/`, talking to the insurance system through its public API. `ItemInsuranceMenuGump.ToggleSelected()` replaces the confirm gump's reach-in to the parent's `_items`/`_insure` arrays.
### Behavior changes
* The per-item "You lack the funds to purchase the insurance" message on failed auto-renewal is no longer sent during death; players get the single 1061115 summary instead. Marked with a TODO pending a decision on whether the per-item message should spam.
* The killer's insurance bonus is deposited once at the end of death processing rather than 300 gold at a time per insured item, and the "gold has been deposited" message is now conditional on the deposit succeeding. Same total.
### Drive-by cleanups
`PoisonImpl.IncreaseLevel` -> `Poison.IncreaseLevel`, a redundant `is NetState { } ns` pattern, `new List<Item>(Items)` -> collection expression, alignment of the `SyncStaticFlag` switch arms, and some comment/formatting fixes in `PlayerMobile`.
67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using Server.Collections;
|
|
using Server.Engines.Insurance;
|
|
using Server.Items;
|
|
|
|
namespace Server.Mobiles;
|
|
|
|
public class DestroyEquipment : MonsterAbilitySingleTarget
|
|
{
|
|
public override MonsterAbilityType AbilityType => MonsterAbilityType.DestroyEquipment;
|
|
public override MonsterAbilityTrigger AbilityTrigger => MonsterAbilityTrigger.GiveMeleeDamage;
|
|
public override double ChanceToTrigger => 0.05;
|
|
|
|
public virtual int AttackRange => 1;
|
|
|
|
protected override void OnTarget(MonsterAbilityTrigger trigger, BaseCreature source, Mobile defender)
|
|
{
|
|
using var queue = PooledRefQueue<Item>.Create();
|
|
|
|
for (var i = 0; i < defender.Items.Count; i++)
|
|
{
|
|
var item = defender.Items[i];
|
|
if (item.Deleted || item.LootType is LootType.Blessed or LootType.Newbied || item.BlessedFor != null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (Insurance.Enabled && item.Insured)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Late publish AOS, do not destroy equipment that mages use
|
|
if (item is IAosItem { Attributes.SpellChanneling: > 0 })
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (item is IDurability { MaxHitPoints: > 0 })
|
|
{
|
|
queue.Enqueue(item);
|
|
}
|
|
}
|
|
|
|
if (queue.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
source.DoHarmful(defender);
|
|
|
|
var toDestroy = queue.PeekRandom();
|
|
var name = toDestroy.Name?.Trim().DefaultIfNullOrEmpty(toDestroy.ItemData.Name);
|
|
|
|
// TODO: Is there supposed to be a special effect?
|
|
// TODO: Is there supposed to be a special sound?
|
|
toDestroy.Delete();
|
|
|
|
// Their ~1_NAME~ is destroyed by the attack.
|
|
defender.NonlocalOverheadMessage(MessageType.Regular, 0x3B2, 1080034, name);
|
|
|
|
// Your ~1_NAME~ is destroyed by the attack.
|
|
defender.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1080035, name);
|
|
}
|
|
|
|
protected override bool CanEffectTarget(MonsterAbilityTrigger trigger, BaseCreature source, Mobile defender) =>
|
|
defender.Player && defender.AccessLevel == AccessLevel.Player && source.InRange(defender, AttackRange);
|
|
}
|