Skip to content

Commit

Permalink
fix: Fixes issue with duping items and serialization, and sector list…
Browse files Browse the repository at this point in the history
…s. (#1662)
  • Loading branch information
kamronbatman authored Jan 24, 2024
1 parent 497ea87 commit 3812a78
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 53 deletions.
23 changes: 2 additions & 21 deletions Projects/Server/Items/BaseMulti.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ public override int ItemID
{
if (base.ItemID != value)
{
var facet = Parent == null ? Map : null;

facet?.OnLeave(this);

Map?.OnLeave(this);
base.ItemID = value;

facet?.OnEnter(this);
Map?.OnEnter(this);
}
}
}
Expand Down Expand Up @@ -69,21 +65,6 @@ public override int LabelNumber

public virtual MultiComponentList Components => MultiData.GetComponents(ItemID);

[Obsolete("Replace with calls to OnLeave and OnEnter surrounding component invalidation.", true)]
public virtual void RefreshComponents()
{
if (Parent == null)
{
var facet = Map;

if (facet != null)
{
facet.OnLeave(this);
facet.OnEnter(this);
}
}
}

public override int GetMaxUpdateRange() => 22;

public override int GetUpdateRange(Mobile m) => 22;
Expand Down
31 changes: 17 additions & 14 deletions Projects/Server/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,18 +599,16 @@ public IEntity Parent

var oldParent = m_Parent;

if (m_Map != null && oldParent == null && value != null)
{
m_Map.OnLeave(this);
}

m_Parent = value;

if (m_Map != null)
if (m_Map != null && oldParent != null && value == null)
{
if (oldParent != null && m_Parent == null)
{
m_Map.OnEnter(this);
}
else if (m_Parent != null)
{
m_Map.OnLeave(this);
}
m_Map.OnEnter(this);
}
}
}
Expand Down Expand Up @@ -1207,9 +1205,13 @@ public Map Map
{
var old = m_Map;

if (m_Map != null && m_Parent == null)
if (m_Map != null)
{
m_Map.OnLeave(this);
if (m_Parent == null)
{
m_Map.OnLeave(this);
}

SendRemovePacket();
}

Expand Down Expand Up @@ -3328,13 +3330,14 @@ public virtual void RemoveItem(Item item)
}
}

private static readonly HashSet<string> _excludedProperties = new()
{
private static readonly HashSet<string> _excludedProperties =
[
"SaveBuffer",
"Parent",
"Next",
"Previous",
"OnLinkList"
};
];

public virtual bool DupeExcludedProperty(string propertyName) => _excludedProperties.Contains(propertyName);

Expand Down
20 changes: 10 additions & 10 deletions Projects/Server/Maps/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,27 +568,27 @@ public void OnClientChange(NetState oldState, NetState newState, Mobile m)
}
}

public void OnEnter(Mobile m)
internal void OnEnter(Mobile m)
{
OnEnter(m.Location, m);
}

public void OnEnter(Point3D p, Mobile m)
internal void OnEnter(Point3D p, Mobile m)
{
if (this != Internal)
{
GetSector(p).OnEnter(m);
}
}

public void OnEnter(Item item)
internal void OnEnter(Item item)
{
OnEnter(item.Location, item);
}

public void OnEnter(Point3D p, Item item)
internal void OnEnter(Point3D p, Item item)
{
if (this == Internal)
if (this == Internal || item.Parent != null)
{
return;
}
Expand All @@ -606,27 +606,27 @@ public void OnEnter(Point3D p, Item item)
}
}

public void OnLeave(Mobile m)
internal void OnLeave(Mobile m)
{
OnLeave(m.Location, m);
}

public void OnLeave(Point3D p, Mobile m)
internal void OnLeave(Point3D p, Mobile m)
{
if (this != Internal)
{
GetSector(p).OnLeave(m);
}
}

public void OnLeave(Item item)
internal void OnLeave(Item item)
{
OnLeave(item.Location, item);
}

public void OnLeave(Point3D p, Item item)
internal void OnLeave(Point3D p, Item item)
{
if (this == Internal)
if (this == Internal || item.Parent != null)
{
return;
}
Expand Down
3 changes: 1 addition & 2 deletions Projects/Server/Mobiles/Mobile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7272,6 +7272,7 @@ public virtual void SetLocation(Point3D newLocation, bool isTeleport)
}

m_Location = newLocation;
m_Map?.OnMove(oldLocation, this);
UpdateRegion();

var box = FindBankNoCreate();
Expand All @@ -7283,8 +7284,6 @@ public virtual void SetLocation(Point3D newLocation, bool isTeleport)

m_NetState?.ValidateAllTrades();

m_Map?.OnMove(oldLocation, this);

if (isTeleport && m_NetState != null && (!m_NetState.HighSeas || !NoMoveHS))
{
m_NetState.Sequence = 0;
Expand Down
2 changes: 1 addition & 1 deletion Projects/Server/World/EntityPersistence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ List<EntitySpan<T>> entities
}
else
{
Console.WriteLine($"***** Bad deserialize of {t.GetType()} *****");
Console.WriteLine($"***** Bad deserialize of {t.GetType()} ({t.Serial}) *****");
Console.WriteLine(error);

ConsoleKey pressedKey;
Expand Down
6 changes: 1 addition & 5 deletions Projects/UOContent/World Saves/AutoSave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ public static bool SavesEnabled

public static void Configure()
{
SavesEnabled = ServerConfiguration.GetOrUpdateSetting("autosave.enabled", true);
Delay = ServerConfiguration.GetOrUpdateSetting("autosave.saveDelay", TimeSpan.FromMinutes(5.0));
Warning = ServerConfiguration.GetOrUpdateSetting("autosave.warningDelay", TimeSpan.Zero);
}

public static void Initialize()
{
SavesEnabled = true;
}

public static void ResetAutoSave(TimeSpan saveDelay, TimeSpan warningDelay)
{
if (saveDelay != Delay || warningDelay != Warning)
Expand Down

0 comments on commit 3812a78

Please sign in to comment.