fix: Codegens corpses (#1287)

This commit is contained in:
Kamron Batman 2022-11-28 23:08:38 -08:00 • committed by GitHub
parent c8a804d0b1
commit 0b4cd460de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 1250 additions and 1339 deletions

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using ModernUO.Serialization;
using Server.ContextMenus; using Server.ContextMenus;
using Server.Engines.PartySystem; using Server.Engines.PartySystem;
using Server.Engines.Quests.Doom; using Server.Engines.Quests.Doom;
@ -9,16 +10,16 @@ using Server.Misc;
using Server.Mobiles; using Server.Mobiles;
using Server.Network; using Server.Network;
namespace Server.Items namespace Server.Items;
{
public interface IDevourer
{
bool Devour(Corpse corpse);
}
[Flags] public interface IDevourer
public enum CorpseFlag {
{ bool Devour(Corpse corpse);
}
[Flags]
public enum CorpseFlag
{
None = 0x00000000, None = 0x00000000,
/// <summary> /// <summary>
@ -60,34 +61,75 @@ namespace Server.Items
/// Has this corpse been self looted? /// Has this corpse been self looted?
/// </summary> /// </summary>
SelfLooted = 0x00000080 SelfLooted = 0x00000080
} }
public class Corpse : Container, ICarvable [SerializationGenerator(13, false)]
{ public partial class Corpse : Container, ICarvable
{
public static readonly TimeSpan MonsterLootRightSacrifice = TimeSpan.FromMinutes(2.0); public static readonly TimeSpan MonsterLootRightSacrifice = TimeSpan.FromMinutes(2.0);
public static readonly TimeSpan InstancedCorpseTime = TimeSpan.FromMinutes(3.0); private static TimeSpan InstancedCorpseTime = TimeSpan.FromMinutes(3.0);
private static readonly TimeSpan m_DefaultDecayTime = TimeSpan.FromMinutes(7.0); private static TimeSpan _defaultDecayTime = TimeSpan.FromMinutes(7.0);
private static readonly TimeSpan m_BoneDecayTime = TimeSpan.FromMinutes(7.0); private static TimeSpan _boneDecayTime = TimeSpan.FromMinutes(7.0);
private string private IDevourer _devourer; // The creature that devoured this corpse
m_CorpseName; // Value of the CorpseNameAttribute attached to the owner when he died -or- null if the owner had no CorpseNameAttribute; use "the remains of ~name~"
private DateTime m_DecayTime; private Dictionary<Item, InstancedItemInfo> _instancedItems;
private Timer m_DecayTimer; [SerializableField(0)]
private IDevourer m_Devourer; // The creature that devoured this corpse private List<Item> _restoreEquip;
private CorpseFlag m_Flags; // @see CorpseFlag
// For notoriety: [SerializableField(1)]
private CorpseFlag _flags;
// For Forensics Evaluation [DeltaDateTime]
public string m_Forensicist; // Name of the first PlayerMobile who used Forensic Evaluation on the corpse [SerializableField(2)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private DateTime _timeOfDeath;
private Dictionary<Item, InstancedItemInfo> m_InstancedItems; [SerializableField(3, getter: "private", setter: "private")]
private Dictionary<Item, Point3D> _restoreTable;
private Dictionary<Item, Point3D> m_RestoreTable; [TimerDrift]
[SerializableField(4, getter: "private", setter: "private")]
private Timer _decayTimer;
[DeserializeTimerField(4)]
private void DeserializeDecayTimer(TimeSpan delay) => BeginDecay(delay);
[SerializableField(5, setter: "private")]
private HashSet<Mobile> _looters;
[SerializableField(6, setter: "private")]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private Mobile _killer;
[SerializableField(7, setter: "private")]
private List<Mobile> _aggressors;
[SerializableField(8, setter: "private")]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private Mobile _owner;
// Value of the CorpseNameAttribute attached to the owner when he died -or- null if the owner had no CorpseNameAttribute; use "the remains of ~name~"
[SerializableField(9, getter: "private", setter: "private")]
private string _corpseName;
[SerializableField(10, setter: "private")]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private AccessLevel _accessLevel;
[SerializableField(11, setter: "private")]
private Guild _guild;
[SerializableField(12)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private int _kills;
[SerializableField(13, setter: "private")]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private List<Item> _equipItems;
// Why was this public? // Why was this public?
// public override bool IsPublicContainer => true; // public override bool IsPublicContainer => true;
@ -109,15 +151,15 @@ namespace Server.Items
Direction = owner.Direction; Direction = owner.Direction;
Name = owner.Name; Name = owner.Name;
Owner = owner; _owner = owner;
m_CorpseName = GetCorpseName(owner); _corpseName = GetCorpseName(owner);
TimeOfDeath = Core.Now; _timeOfDeath = Core.Now;
AccessLevel = owner.AccessLevel; _accessLevel = owner.AccessLevel;
Guild = owner.Guild as Guild; _guild = owner.Guild as Guild;
Kills = owner.Kills; _kills = owner.Kills;
SetFlag(CorpseFlag.Criminal, owner.Criminal); SetFlag(CorpseFlag.Criminal, owner.Criminal);
Hair = hair; Hair = hair;
@ -126,11 +168,10 @@ namespace Server.Items
// This corpse does not turn to bones if: the owner is not a player // This corpse does not turn to bones if: the owner is not a player
SetFlag(CorpseFlag.NoBones, !owner.Player); SetFlag(CorpseFlag.NoBones, !owner.Player);
Looters = new List<Mobile>(); _looters = new HashSet<Mobile>();
EquipItems = equipItems; _equipItems = equipItems;
Aggressors = new List<Mobile>(owner.Aggressors.Count + owner.Aggressed.Count); _aggressors = new List<Mobile>(owner.Aggressors.Count + owner.Aggressed.Count);
// bool addToAggressors = !( owner is BaseCreature );
var isBaseCreature = owner is BaseCreature; var isBaseCreature = owner is BaseCreature;
@ -142,13 +183,13 @@ namespace Server.Items
if (Core.Now - info.LastCombatTime < lastTime) if (Core.Now - info.LastCombatTime < lastTime)
{ {
Killer = info.Attacker; _killer = info.Attacker;
lastTime = Core.Now - info.LastCombatTime; lastTime = Core.Now - info.LastCombatTime;
} }
if (!isBaseCreature && !info.CriminalAggression) if (!isBaseCreature && !info.CriminalAggression)
{ {
Aggressors.Add(info.Attacker); _aggressors.Add(info.Attacker);
} }
} }
@ -158,13 +199,13 @@ namespace Server.Items
if (Core.Now - info.LastCombatTime < lastTime) if (Core.Now - info.LastCombatTime < lastTime)
{ {
Killer = info.Defender; _killer = info.Defender;
lastTime = Core.Now - info.LastCombatTime; lastTime = Core.Now - info.LastCombatTime;
} }
if (!isBaseCreature) if (!isBaseCreature)
{ {
Aggressors.Add(info.Defender); _aggressors.Add(info.Defender);
} }
} }
@ -175,7 +216,7 @@ namespace Server.Items
var master = bc.GetMaster(); var master = bc.GetMaster();
if (master != null) if (master != null)
{ {
Aggressors.Add(master); _aggressors.Add(master);
} }
var rights = BaseCreature.GetLootingRights(bc.DamageEntries, bc.HitsMax); var rights = BaseCreature.GetLootingRights(bc.DamageEntries, bc.HitsMax);
@ -185,30 +226,27 @@ namespace Server.Items
if (ds.m_HasRight) if (ds.m_HasRight)
{ {
Aggressors.Add(ds.m_Mobile); _aggressors.Add(ds.m_Mobile);
} }
} }
} }
BeginDecay(m_DefaultDecayTime); BeginDecay(_defaultDecayTime);
DevourCorpse(); DevourCorpse();
} }
public Corpse(Serial serial) : base(serial)
{
}
[CommandProperty(AccessLevel.GameMaster)] [CommandProperty(AccessLevel.GameMaster)]
public virtual bool InstancedCorpse => Core.SE && Core.Now < TimeOfDeath + InstancedCorpseTime; public virtual bool InstancedCorpse => Core.SE && Core.Now < TimeOfDeath + InstancedCorpseTime;
public override bool IsDecoContainer => false; public override bool IsDecoContainer => false;
[CommandProperty(AccessLevel.GameMaster)]
public DateTime TimeOfDeath { get; set; }
public override bool DisplayWeight => false; public override bool DisplayWeight => false;
// Name of the first PlayerMobile who used Forensic Evaluation on the corpse
[CommandProperty(AccessLevel.GameMaster)]
public string Forensicist { get; set; }
public HairInfo Hair { get; } public HairInfo Hair { get; }
public FacialHairInfo FacialHair { get; } public FacialHairInfo FacialHair { get; }
@ -217,7 +255,7 @@ namespace Server.Items
public bool IsBones => GetFlag(CorpseFlag.IsBones); public bool IsBones => GetFlag(CorpseFlag.IsBones);
[CommandProperty(AccessLevel.GameMaster)] [CommandProperty(AccessLevel.GameMaster)]
public bool Devoured => m_Devourer != null; public bool Devoured => _devourer != null;
[CommandProperty(AccessLevel.GameMaster)] [CommandProperty(AccessLevel.GameMaster)]
public bool Carved public bool Carved
@ -254,25 +292,6 @@ namespace Server.Items
set => SetFlag(CorpseFlag.SelfLooted, value); set => SetFlag(CorpseFlag.SelfLooted, value);
} }
[CommandProperty(AccessLevel.GameMaster)]
public AccessLevel AccessLevel { get; private set; }
public List<Mobile> Aggressors { get; private set; }
public List<Mobile> Looters { get; private set; }
[CommandProperty(AccessLevel.GameMaster)]
public Mobile Killer { get; private set; }
public List<Item> EquipItems { get; private set; }
public List<Item> RestoreEquip { get; set; }
public Guild Guild { get; }
[CommandProperty(AccessLevel.GameMaster)]
public int Kills { get; set; }
[CommandProperty(AccessLevel.GameMaster)] [CommandProperty(AccessLevel.GameMaster)]
public bool Criminal public bool Criminal
{ {
@ -280,9 +299,6 @@ namespace Server.Items
set => SetFlag(CorpseFlag.Criminal, value); set => SetFlag(CorpseFlag.Criminal, value);
} }
[CommandProperty(AccessLevel.GameMaster)]
public Mobile Owner { get; private set; }
public override bool DisplaysContent => false; public override bool DisplaysContent => false;
public void Carve(Mobile from, Item item) public void Carve(Mobile from, Item item)
@ -342,18 +358,18 @@ namespace Server.Items
} }
public override bool IsChildVisibleTo(Mobile m, Item child) => public override bool IsChildVisibleTo(Mobile m, Item child) =>
!m.Player || m.AccessLevel > AccessLevel.Player || m_InstancedItems == null || !m.Player || m.AccessLevel > AccessLevel.Player || _instancedItems == null ||
!m_InstancedItems.TryGetValue(child, out var info) || !InstancedCorpse && !info.Perpetual !_instancedItems.TryGetValue(child, out var info) || !InstancedCorpse && !info.Perpetual
|| info.IsOwner(m); || info.IsOwner(m);
private void AssignInstancedLoot() private void AssignInstancedLoot()
{ {
if (Aggressors.Count == 0 || Items.Count == 0) if (_aggressors.Count == 0 || Items.Count == 0)
{ {
return; return;
} }
m_InstancedItems ??= new Dictionary<Item, InstancedItemInfo>(); _instancedItems ??= new Dictionary<Item, InstancedItemInfo>();
var m_Stackables = new List<Item>(); var m_Stackables = new List<Item>();
var m_Unstackables = new List<Item>(); var m_Unstackables = new List<Item>();
@ -375,7 +391,7 @@ namespace Server.Items
} }
} }
var attackers = new List<Mobile>(Aggressors); var attackers = new List<Mobile>(_aggressors);
for (var i = 1; i < attackers.Count - 1; i++) // randomize for (var i = 1; i < attackers.Count - 1; i++) // randomize
{ {
@ -397,17 +413,16 @@ namespace Server.Items
for (var j = 0; j < (remainder == 0 ? attackers.Count - 1 : attackers.Count); j++) for (var j = 0; j < (remainder == 0 ? attackers.Count - 1 : attackers.Count); j++)
{ {
// LiftItemDupe automagically adds it as a child item to the corpse // LiftItemDupe automagically adds it as a child item to the corpse
var splitItem = var splitItem = Mobile.LiftItemDupe(item, item.Amount - amountPerAttacker);
Mobile.LiftItemDupe(item, item.Amount - amountPerAttacker);
m_InstancedItems.Add(splitItem, new InstancedItemInfo(splitItem, attackers[j])); _instancedItems.Add(splitItem, new InstancedItemInfo(splitItem, attackers[j]));
// What happens to the remaining portion? TEMP FOR NOW UNTIL OSI VERIFICATION: Treat as Single Item. // What happens to the remaining portion? TEMP FOR NOW UNTIL OSI VERIFICATION: Treat as Single Item.
} }
if (remainder == 0) if (remainder == 0)
{ {
m_InstancedItems.Add(item, new InstancedItemInfo(item, attackers[^1])); _instancedItems.Add(item, new InstancedItemInfo(item, attackers[^1]));
} }
else else
{ {
@ -426,7 +441,7 @@ namespace Server.Items
var m = attackers[i % attackers.Count]; var m = attackers[i % attackers.Count];
var item = m_Unstackables[i]; var item = m_Unstackables[i];
m_InstancedItems.Add(item, new InstancedItemInfo(item, m)); _instancedItems.Add(item, new InstancedItemInfo(item, m));
} }
} }
@ -436,9 +451,9 @@ namespace Server.Items
if (InstancedCorpse) if (InstancedCorpse)
{ {
m_InstancedItems ??= new Dictionary<Item, InstancedItemInfo>(); _instancedItems ??= new Dictionary<Item, InstancedItemInfo>();
m_InstancedItems.Add(carved, new InstancedItemInfo(carved, carver)); _instancedItems.Add(carved, new InstancedItemInfo(carved, carver));
} }
} }
@ -458,24 +473,20 @@ namespace Server.Items
SetFlag(CorpseFlag.NoBones, true); SetFlag(CorpseFlag.NoBones, true);
SetFlag(CorpseFlag.IsBones, true); SetFlag(CorpseFlag.IsBones, true);
BeginDecay(m_BoneDecayTime); BeginDecay(_boneDecayTime);
} }
public void BeginDecay(TimeSpan delay) public void BeginDecay(TimeSpan delay)
{ {
m_DecayTimer?.Stop(); _decayTimer?.Stop();
_decayTimer = new InternalTimer(this, delay);
m_DecayTime = Core.Now + delay; _decayTimer.Start();
m_DecayTimer = new InternalTimer(this, delay);
m_DecayTimer.Start();
} }
public override void OnAfterDelete() public override void OnAfterDelete()
{ {
m_DecayTimer?.Stop(); _decayTimer?.Stop();
_decayTimer = null;
m_DecayTimer = null;
} }
public static string GetCorpseName(Mobile m) => m is BaseCreature bc ? bc.CorpseNameOverride ?? bc.CorpseName : null; public static string GetCorpseName(Mobile m) => m is BaseCreature bc ? bc.CorpseNameOverride ?? bc.CorpseName : null;
@ -538,100 +549,30 @@ namespace Server.Items
return c; return c;
} }
protected bool GetFlag(CorpseFlag flag) => (m_Flags & flag) != 0; protected bool GetFlag(CorpseFlag flag) => (_flags & flag) != 0;
protected void SetFlag(CorpseFlag flag, bool on) protected void SetFlag(CorpseFlag flag, bool value)
{ {
m_Flags = on ? m_Flags | flag : m_Flags & ~flag; if (value)
}
public override void Serialize(IGenericWriter writer)
{ {
base.Serialize(writer); Flags |= flag;
writer.Write(12); // version
if (RestoreEquip == null)
{
writer.Write(false);
} }
else else
{ {
writer.Write(true); Flags &= ~flag;
writer.Write(RestoreEquip);
}
writer.Write((int)m_Flags);
writer.WriteDeltaTime(TimeOfDeath);
var count = m_RestoreTable?.Count ?? 0;
writer.Write(count);
if (m_RestoreTable != null)
{
foreach (var (item, loc) in m_RestoreTable)
{
writer.Write(item);
if (item.Location == loc)
{
writer.Write(false);
}
else
{
writer.Write(true);
writer.Write(loc);
}
} }
} }
writer.Write(m_DecayTimer != null); private void Deserialize(IGenericReader reader, int version)
if (m_DecayTimer != null)
{
writer.WriteDeltaTime(m_DecayTime);
}
writer.Write(Looters);
writer.Write(Killer);
writer.Write(Aggressors);
writer.Write(Owner);
writer.Write(m_CorpseName);
writer.Write((int)AccessLevel);
writer.Write(Guild);
writer.Write(Kills);
writer.Write(EquipItems);
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
switch (version)
{
case 12:
{ {
if (reader.ReadBool()) if (reader.ReadBool())
{ {
RestoreEquip = reader.ReadEntityList<Item>(); _restoreEquip = reader.ReadEntityList<Item>();
} }
goto case 11; _flags = (CorpseFlag)reader.ReadInt();
}
case 11:
{
// Version 11, we move all bools to a CorpseFlag
m_Flags = (CorpseFlag)reader.ReadInt();
TimeOfDeath = reader.ReadDeltaTime(); _timeOfDeath = reader.ReadDeltaTime();
var count = reader.ReadInt(); var count = reader.ReadInt();
@ -654,131 +595,19 @@ namespace Server.Items
BeginDecay(reader.ReadDeltaTime() - Core.Now); BeginDecay(reader.ReadDeltaTime() - Core.Now);
} }
Looters = reader.ReadEntityList<Mobile>(); _looters = reader.ReadEntitySet<Mobile>();
Killer = reader.ReadEntity<Mobile>(); _killer = reader.ReadEntity<Mobile>();
Aggressors = reader.ReadEntityList<Mobile>(); _aggressors = reader.ReadEntityList<Mobile>();
Owner = reader.ReadEntity<Mobile>(); _owner = reader.ReadEntity<Mobile>();
m_CorpseName = reader.ReadString(); _corpseName = reader.ReadString();
AccessLevel = (AccessLevel)reader.ReadInt(); _accessLevel = (AccessLevel)reader.ReadInt();
reader.ReadInt(); // guild reserve reader.ReadInt(); // guild reserve
Kills = reader.ReadInt(); _kills = reader.ReadInt();
EquipItems = reader.ReadEntityList<Item>(); _equipItems = reader.ReadEntityList<Item>();
break;
}
case 10:
{
TimeOfDeath = reader.ReadDeltaTime();
goto case 9;
}
case 9:
{
var count = reader.ReadInt();
for (var i = 0; i < count; ++i)
{
var item = reader.ReadEntity<Item>();
if (reader.ReadBool())
{
SetRestoreInfo(item, reader.ReadPoint3D());
}
else if (item != null)
{
SetRestoreInfo(item, item.Location);
}
}
goto case 8;
}
case 8:
{
SetFlag(CorpseFlag.VisitedByTaxidermist, reader.ReadBool());
goto case 7;
}
case 7:
{
if (reader.ReadBool())
{
BeginDecay(reader.ReadDeltaTime() - Core.Now);
}
goto case 6;
}
case 6:
{
Looters = reader.ReadEntityList<Mobile>();
Killer = reader.ReadEntity<Mobile>();
goto case 5;
}
case 5:
{
SetFlag(CorpseFlag.Carved, reader.ReadBool());
goto case 4;
}
case 4:
{
Aggressors = reader.ReadEntityList<Mobile>();
goto case 3;
}
case 3:
{
Owner = reader.ReadEntity<Mobile>();
goto case 2;
}
case 2:
{
SetFlag(CorpseFlag.NoBones, reader.ReadBool());
goto case 1;
}
case 1:
{
m_CorpseName = reader.ReadString();
goto case 0;
}
case 0:
{
if (version < 10)
{
TimeOfDeath = Core.Now;
}
if (version < 7)
{
BeginDecay(m_DefaultDecayTime);
}
if (version < 6)
{
Looters = new List<Mobile>();
}
if (version < 4)
{
Aggressors = new List<Mobile>();
}
AccessLevel = (AccessLevel)reader.ReadInt();
reader.ReadInt(); // guild reserve
Kills = reader.ReadInt();
SetFlag(CorpseFlag.Criminal, reader.ReadBool());
EquipItems = reader.ReadEntityList<Item>();
break;
}
}
} }
public bool DevourCorpse() public bool DevourCorpse()
@ -789,8 +618,8 @@ namespace Server.Items
return false; return false;
} }
m_Devourer = devourer; // Set the devourer the killer _devourer = devourer; // Set the devourer the killer
return m_Devourer.Devour(this); // Devour the corpse if it hasn't return _devourer.Devour(this); // Devour the corpse if it hasn't
} }
public override void SendInfoTo(NetState ns, ReadOnlySpan<byte> world = default) public override void SendInfoTo(NetState ns, ReadOnlySpan<byte> world = default)
@ -846,12 +675,9 @@ namespace Server.Items
from.CriminalAction(true); from.CriminalAction(true);
} }
if (!Looters.Contains(from)) this.Add(_looters, from);
{
Looters.Add(from);
}
m_InstancedItems?.Remove(item); _instancedItems?.Remove(item);
} }
@ -869,26 +695,23 @@ namespace Server.Items
from.CriminalAction(true); from.CriminalAction(true);
} }
if (!Looters.Contains(from)) this.Add(_looters, from);
{
Looters.Add(from);
}
m_InstancedItems?.Remove(item); _instancedItems?.Remove(item);
} }
public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list) public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
{ {
base.GetContextMenuEntries(from, list); base.GetContextMenuEntries(from, list);
if (Core.AOS && Owner == from && from.Alive) if (Core.AOS && _owner == from && from.Alive)
{ {
list.Add(new OpenCorpseEntry()); list.Add(new OpenCorpseEntry());
} }
} }
public bool GetRestoreInfo(Item item, ref Point3D loc) => public bool GetRestoreInfo(Item item, ref Point3D loc) =>
item != null && m_RestoreTable?.TryGetValue(item, out loc) == true; item != null && _restoreTable?.TryGetValue(item, out loc) == true;
public void SetRestoreInfo(Item item, Point3D loc) public void SetRestoreInfo(Item item, Point3D loc)
{ {
@ -897,23 +720,26 @@ namespace Server.Items
return; return;
} }
m_RestoreTable ??= new Dictionary<Item, Point3D>(); _restoreTable ??= new Dictionary<Item, Point3D>();
_restoreTable[item] = loc;
m_RestoreTable[item] = loc; this.MarkDirty();
} }
public void ClearRestoreInfo(Item item) public void ClearRestoreInfo(Item item)
{ {
if (m_RestoreTable == null || item == null) if (_restoreTable == null || item == null)
{ {
return; return;
} }
m_RestoreTable.Remove(item); _restoreTable.Remove(item);
if (_restoreTable.Count == 0)
if (m_RestoreTable.Count == 0)
{ {
m_RestoreTable = null; RestoreTable = null;
}
else
{
this.MarkDirty();
} }
} }
@ -1065,11 +891,8 @@ namespace Server.Items
if (player.PlaceInBackpack(bone)) if (player.PlaceInBackpack(bone))
{ {
obj.CorpseWithBone = null; obj.CorpseWithBone = null;
player.SendLocalizedMessage( // You rummage through the bones and find a Daemon Bone! You quickly place the item in your pack.
1049341, player.SendLocalizedMessage(1049341, "", 0x22);
"",
0x22
); // You rummage through the bones and find a Daemon Bone! You quickly place the item in your pack.
if (!obj.Completed) if (!obj.Completed)
{ {
@ -1079,11 +902,8 @@ namespace Server.Items
else else
{ {
bone.Delete(); bone.Delete();
player.SendLocalizedMessage( // Rummaging through the bones you find a Daemon Bone, but can't pick it up because your pack is too full. Come back when you have more room in your pack.
1049342, player.SendLocalizedMessage(1049342, "", 0x22);
"",
0x22
); // Rummaging through the bones you find a Daemon Bone, but can't pick it up because your pack is too full. Come back when you have more room in your pack.
} }
return; return;
@ -1099,17 +919,15 @@ namespace Server.Items
if (player.PlaceInBackpack(sk)) if (player.PlaceInBackpack(sk))
{ {
obj.CorpseWithSkull = null; obj.CorpseWithSkull = null;
player.SendLocalizedMessage( // For your valor in combating the devourer, you have been awarded a golden skull.
1050022 player.SendLocalizedMessage(1050022);
); // For your valor in combating the devourer, you have been awarded a golden skull.
qs.Complete(); qs.Complete();
} }
else else
{ {
sk.Delete(); sk.Delete();
player.SendLocalizedMessage( // You find a golden skull, but your backpack is too full to carry it.
1050023 player.SendLocalizedMessage(1050023);
); // You find a golden skull, but your backpack is too full to carry it.
} }
} }
} }
@ -1128,9 +946,9 @@ namespace Server.Items
{ {
if (ItemID == 0x2006) // Corpse form if (ItemID == 0x2006) // Corpse form
{ {
if (m_CorpseName != null) if (_corpseName != null)
{ {
list.Add(m_CorpseName); list.Add(_corpseName);
} }
else else
{ {
@ -1160,9 +978,9 @@ namespace Server.Items
if (ItemID == 0x2006) // Corpse form if (ItemID == 0x2006) // Corpse form
{ {
if (m_CorpseName != null) if (_corpseName != null)
{ {
from.NetState.SendMessage(Serial, ItemID, MessageType.Label, hue, 3, true, null, "", m_CorpseName); from.NetState.SendMessage(Serial, ItemID, MessageType.Label, hue, 3, true, null, "", _corpseName);
} }
else else
{ {
@ -1177,20 +995,20 @@ namespace Server.Items
private class InstancedItemInfo private class InstancedItemInfo
{ {
private readonly Item m_Item; private Item _item;
private readonly Mobile m_Mobile; private Mobile _mobile;
public InstancedItemInfo(Item i, Mobile m) public InstancedItemInfo(Item i, Mobile m)
{ {
m_Item = i; _item = i;
m_Mobile = m; _mobile = m;
} }
public bool Perpetual { get; set; } public bool Perpetual { get; set; }
public bool IsOwner(Mobile m) public bool IsOwner(Mobile m)
{ {
if (m_Item.LootType == LootType.Cursed) // Cursed Items are part of everyone's instanced corpse... (?) if (_item.LootType == LootType.Cursed) // Cursed Items are part of everyone's instanced corpse... (?)
{ {
return true; return true;
} }
@ -1200,12 +1018,12 @@ namespace Server.Items
return false; // sanity return false; // sanity
} }
if (m_Mobile == m) if (_mobile == m)
{ {
return true; return true;
} }
var myParty = Party.Get(m_Mobile); var myParty = Party.Get(_mobile);
return myParty != null && myParty == Party.Get(m); return myParty != null && myParty == Party.Get(m);
} }
@ -1213,19 +1031,19 @@ namespace Server.Items
private class InternalTimer : Timer private class InternalTimer : Timer
{ {
private readonly Corpse m_Corpse; private Corpse _corpse;
public InternalTimer(Corpse c, TimeSpan delay) : base(delay) => m_Corpse = c; public InternalTimer(Corpse c, TimeSpan delay) : base(delay) => _corpse = c;
protected override void OnTick() protected override void OnTick()
{ {
if (!m_Corpse.GetFlag(CorpseFlag.NoBones)) if (!_corpse.GetFlag(CorpseFlag.NoBones))
{ {
m_Corpse.TurnToBones(); _corpse.TurnToBones();
} }
else else
{ {
m_Corpse.Delete(); _corpse.Delete();
} }
} }
} }
@ -1244,5 +1062,4 @@ namespace Server.Items
} }
} }
} }
}
} }

View file

@ -1,12 +1,11 @@
using System; using System;
namespace Server namespace Server;
[AttributeUsage(AttributeTargets.Class)]
public class CorpseNameAttribute : Attribute
{ {
[AttributeUsage(AttributeTargets.Class)]
public class CorpseNameAttribute : Attribute
{
public CorpseNameAttribute(string name) => Name = name; public CorpseNameAttribute(string name) => Name = name;
public string Name { get; } public string Name { get; }
}
} }

View file

@ -17,10 +17,10 @@ using System.Buffers;
using System.IO; using System.IO;
using Server.Items; using Server.Items;
namespace Server.Network namespace Server.Network;
public static class CorpsePackets
{ {
public static class CorpsePackets
{
public static void SendCorpseEquip(this NetState ns, Mobile beholder, Corpse beheld) public static void SendCorpseEquip(this NetState ns, Mobile beholder, Corpse beheld)
{ {
if (ns.CannotSendPackets()) if (ns.CannotSendPackets())
@ -155,5 +155,4 @@ namespace Server.Network
writer.Seek(0, SeekOrigin.End); writer.Seek(0, SeekOrigin.End);
ns.Send(writer.Span); ns.Send(writer.Span);
} }
}
} }

View file

@ -1,23 +1,26 @@
using System; using System;
using ModernUO.Serialization;
namespace Server.Items namespace Server.Items;
[SerializationGenerator(2, false)]
public partial class DecayedCorpse : Container
{ {
public class DecayedCorpse : Container private static TimeSpan _defaultDecayTime = TimeSpan.FromMinutes(7.0);
{
private static readonly TimeSpan m_DefaultDecayTime = TimeSpan.FromMinutes(7.0); [TimerDrift]
private DateTime m_DecayTime; [SerializableField(0, getter: "private", setter: "private")]
private Timer m_DecayTimer; private Timer _decayTimer;
[DeserializeTimerField(0)]
private void DeserializeDecayTimer(TimeSpan delay) => BeginDecay(delay);
public DecayedCorpse(string name) : base(Utility.Random(0xECA, 9)) public DecayedCorpse(string name) : base(Utility.Random(0xECA, 9))
{ {
Movable = false; Movable = false;
Name = name; Name = name;
BeginDecay(m_DefaultDecayTime); BeginDecay(_defaultDecayTime);
}
public DecayedCorpse(Serial serial) : base(serial)
{
} }
// Do not display (x items, y stones) // Do not display (x items, y stones)
@ -25,19 +28,15 @@ namespace Server.Items
public void BeginDecay(TimeSpan delay) public void BeginDecay(TimeSpan delay)
{ {
m_DecayTimer?.Stop(); _decayTimer?.Stop();
DecayTimer = new InternalTimer(this, delay);
m_DecayTime = Core.Now + delay; DecayTimer.Start();
m_DecayTimer = new InternalTimer(this, delay);
m_DecayTimer.Start();
} }
public override void OnAfterDelete() public override void OnAfterDelete()
{ {
m_DecayTimer?.Stop(); _decayTimer?.Stop();
_decayTimer = null;
m_DecayTimer = null;
} }
// Do not display (x items, y stones) // Do not display (x items, y stones)
@ -53,56 +52,23 @@ namespace Server.Items
LabelTo(from, 1046414, Name); // the remains of ~1_NAME~ LabelTo(from, 1046414, Name); // the remains of ~1_NAME~
} }
public override void Serialize(IGenericWriter writer) private void Deserialize(IGenericReader reader, int version)
{
base.Serialize(writer);
writer.Write(1); // version
writer.Write(m_DecayTimer != null);
if (m_DecayTimer != null)
{
writer.WriteDeltaTime(m_DecayTime);
}
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
switch (version)
{
case 0:
{
BeginDecay(m_DefaultDecayTime);
break;
}
case 1:
{ {
if (reader.ReadBool()) if (reader.ReadBool())
{ {
BeginDecay(reader.ReadDeltaTime() - Core.Now); BeginDecay(reader.ReadDeltaTime() - Core.Now);
} }
break;
}
}
} }
private class InternalTimer : Timer private class InternalTimer : Timer
{ {
private readonly DecayedCorpse m_Corpse; private DecayedCorpse _corpse;
public InternalTimer(DecayedCorpse c, TimeSpan delay) : base(delay) => m_Corpse = c; public InternalTimer(DecayedCorpse c, TimeSpan delay) : base(delay) => _corpse = c;
protected override void OnTick() protected override void OnTick()
{ {
m_Corpse.Delete(); _corpse.Delete();
}
} }
} }
} }

View file

@ -0,0 +1,113 @@
{
"version": 13,
"type": "Server.Items.Corpse",
"properties": [
{
"name": "RestoreEquip",
"type": "System.Collections.Generic.List\u003CServer.Item\u003E",
"rule": "ListMigrationRule",
"ruleArguments": [
"Server.Item",
"SerializableInterfaceMigrationRule"
]
},
{
"name": "Flags",
"type": "Server.Items.CorpseFlag",
"rule": "EnumMigrationRule"
},
{
"name": "TimeOfDeath",
"type": "System.DateTime",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": [
"DeltaTime"
]
},
{
"name": "RestoreTable",
"type": "System.Collections.Generic.Dictionary\u003CServer.Item, Server.Point3D\u003E",
"rule": "DictionaryMigrationRule",
"ruleArguments": [
"Server.Item",
"SerializableInterfaceMigrationRule",
"0",
"Server.Point3D",
"PrimitiveUOTypeMigrationRule",
"1",
"Point3D"
]
},
{
"name": "DecayTimer",
"type": "Server.Timer",
"rule": "TimerMigrationRule",
"ruleArguments": [
"@TimerDrift"
]
},
{
"name": "Looters",
"type": "System.Collections.Generic.HashSet\u003CServer.Mobile\u003E",
"rule": "HashSetMigrationRule",
"ruleArguments": [
"Server.Mobile",
"SerializableInterfaceMigrationRule"
]
},
{
"name": "Killer",
"type": "Server.Mobile",
"rule": "SerializableInterfaceMigrationRule"
},
{
"name": "Aggressors",
"type": "System.Collections.Generic.List\u003CServer.Mobile\u003E",
"rule": "ListMigrationRule",
"ruleArguments": [
"Server.Mobile",
"SerializableInterfaceMigrationRule"
]
},
{
"name": "Owner",
"type": "Server.Mobile",
"rule": "SerializableInterfaceMigrationRule"
},
{
"name": "CorpseName",
"type": "string",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": [
""
]
},
{
"name": "AccessLevel",
"type": "Server.AccessLevel",
"rule": "EnumMigrationRule"
},
{
"name": "Guild",
"type": "Server.Guilds.Guild",
"rule": "SerializableInterfaceMigrationRule"
},
{
"name": "Kills",
"type": "int",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": [
""
]
},
{
"name": "EquipItems",
"type": "System.Collections.Generic.List\u003CServer.Item\u003E",
"rule": "ListMigrationRule",
"ruleArguments": [
"Server.Item",
"SerializableInterfaceMigrationRule"
]
}
]
}

View file

@ -0,0 +1,14 @@
{
"version": 2,
"type": "Server.Items.DecayedCorpse",
"properties": [
{
"name": "DecayTimer",
"type": "Server.Timer",
"rule": "TimerMigrationRule",
"ruleArguments": [
"@TimerDrift"
]
}
]
}

View file

@ -46,50 +46,53 @@ namespace Server.SkillHandlers
} }
else else
{ {
from.SendLocalizedMessage(501001); // You cannot determain anything useful. from.SendLocalizedMessage(501001); // You cannot determine anything useful.
} }
} }
else if (target is Corpse c) else if (target is Corpse c)
{ {
if (from.CheckTargetSkill(SkillName.Forensics, c, 0.0, 100.0)) if (from.CheckTargetSkill(SkillName.Forensics, c, 0.0, 100.0))
{ {
if (c.m_Forensicist != null) if (c.Forensicist != null)
{ {
from.SendLocalizedMessage( // The forensicist ~1_NAME~ has already discovered that:
1042750, from.SendLocalizedMessage(1042750, c.Forensicist);
c.m_Forensicist
); // The forensicist ~1_NAME~ has already discovered that:
} }
else else
{ {
c.m_Forensicist = from.Name; c.Forensicist = from.Name;
} }
if (((Body)c.Amount).IsHuman) if (((Body)c.Amount).IsHuman)
{ {
from.SendLocalizedMessage( // This person was killed by ~1_KILLER_NAME~
1042751, from.SendLocalizedMessage(1042751, c.Killer == null ? "no one" : c.Killer.Name);
c.Killer == null ? "no one" : c.Killer.Name
); // This person was killed by ~1_KILLER_NAME~
} }
if (c.Looters.Count > 0) if (c.Looters.Count > 0)
{ {
using var sb = new ValueStringBuilder(stackalloc char[128]); using var sb = new ValueStringBuilder(stackalloc char[128]);
for (var i = 0; i < c.Looters.Count; i++) int i = 0;
foreach (var looter in c.Looters)
{ {
if (i > 0) if (i == c.Looters.Count - 1)
{ {
sb.Append(i == c.Looters.Count - 1 ? ", and " : ", "); sb.Append($", and {looter.Name}");
}
else if (i > 0)
{
sb.Append($", {looter.Name}");
}
else
{
sb.Append(looter.Name);
} }
sb.Append(c.Looters[i].Name); i++;
} }
from.SendLocalizedMessage( // This body has been disturbed by ~1_PLAYER_NAMES~
1042752, from.SendLocalizedMessage(1042752, sb.ToString());
sb.ToString()
); // This body has been disturbed by ~1_PLAYER_NAMES~
} }
else else
{ {
@ -98,7 +101,7 @@ namespace Server.SkillHandlers
} }
else else
{ {
from.SendLocalizedMessage(501001); // You cannot determain anything useful. from.SendLocalizedMessage(501001); // You cannot determine anything useful.
} }
} }
else if (target is ILockpickable p) else if (target is ILockpickable p)