Skip to content

Commit

Permalink
Fixes more edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman committed Jun 2, 2024
1 parent 6fe2011 commit 76b8ed9
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Projects/UOContent.Tests/Tests/Items/Books/BookPacketTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TestBook : BaseBook
{
public TestBook(int itemID, int pageCount = 20, bool writable = true) : base(itemID, pageCount, writable)
{
}
}

public TestBook(int itemID, string title, string author, int pageCount, bool writable) : base(itemID, title, author, pageCount, writable)
{
Expand Down Expand Up @@ -89,4 +89,4 @@ public void TestBookContent()
var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
}
}
51 changes: 44 additions & 7 deletions Projects/UOContent/Engines/Bulk Orders/Books/BulkOrderBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using ModernUO.Serialization;
using Server.ContextMenus;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
using Server.Multis;
using Server.Prompts;
Expand All @@ -16,6 +15,7 @@ public partial class BulkOrderBook : Item, ISecurable
[SerializableField(0)]
private int _itemCount;

[SerializedIgnoreDupe]
[InvalidateProperties]
[SerializableField(1)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
Expand All @@ -26,10 +26,12 @@ public partial class BulkOrderBook : Item, ISecurable
[SerializedCommandProperty(AccessLevel.GameMaster)]
private string _bookName;

[SerializedIgnoreDupe]
[SerializableField(3)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private BOBFilter _filter;

[SerializedIgnoreDupe]
[SerializableField(4)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private List<IBOBEntry> _entries;
Expand All @@ -40,12 +42,39 @@ public BulkOrderBook() : base(0x2259)
Weight = 1.0;
LootType = LootType.Blessed;

_entries = new List<IBOBEntry>();
_entries = [];
_filter = new BOBFilter();

_level = SecureLevel.CoOwners;
}

public override void OnAfterDuped(Item newItem)
{
if (newItem is not BulkOrderBook book)
{
return;
}

var filter = book._filter;
filter.Material = Filter.Material;
filter.Quality = Filter.Quality;
filter.Quantity = Filter.Quantity;
filter.Type = Filter.Type;

for (var i = 0; i < Entries.Count; i++)
{
// Recreate the BOD
var bod = Entries[i].Reconstruct();

// Recreate the entry
IBOBEntry newEntry = bod is LargeBOD largeBod ? new BOBLargeEntry(largeBod) : new BOBSmallEntry((SmallBOD)bod);
book.AddToEntries(newEntry);

// Delete the new BOD
bod.Delete();
}
}

public override void OnDoubleClick(Mobile from)
{
if (!from.InRange(GetWorldLocation(), 2))
Expand Down Expand Up @@ -169,13 +198,21 @@ public void InvalidateItems()
}
}

public void InvalidateContainers(IEntity parent)
public static void InvalidateContainers(IEntity parent)
{
if (parent is Container c)
do
{
c.InvalidateProperties();
InvalidateContainers(c.Parent);
}
if (parent is Item item)
{
item.InvalidateProperties();
parent = item.Parent;
}
else if (parent is Mobile m)
{
m.InvalidateProperties();
return;
}
} while (parent != null);
}

private void Deserialize(IGenericReader reader, int version)
Expand Down
2 changes: 1 addition & 1 deletion Projects/UOContent/Engines/Spawners/BaseSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public override void OnAfterDuped(Item newItem)
)
{
var entry = new SpawnerEntry(this, creaturename, probability, amount, properties, parameters);
Entries.Add(entry);
AddToEntries(entry);
if (dotimer)
{
DoTimer(TimeSpan.FromSeconds(1));
Expand Down
27 changes: 26 additions & 1 deletion Projects/UOContent/Items/Books/BaseBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Server.Items
[SerializationGenerator(5, false)]
public partial class BaseBook : Item, ISecurable
{
[SerializedIgnoreDupe]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;
Expand Down Expand Up @@ -45,14 +46,15 @@ public partial class BaseBook : Item, ISecurable
[SerializableFieldSaveFlag(3)]
private bool ShouldSerializeWritable() => _writable;

[SerializedIgnoreDupe]
[SerializableField(4, setter: "protected")]
private BookPageInfo[] _pages;

[SerializableFieldSaveFlag(4)]
private bool ShouldSerializePages() => DefaultContent?.IsMatch(_pages) != true;

[SerializableFieldDefault(4)]
private BookPageInfo[] PagesDefaultvalue() => DefaultContent?.Copy() ?? Array.Empty<BookPageInfo>();
private BookPageInfo[] PagesDefaultValue() => DefaultContent?.Copy() ?? Array.Empty<BookPageInfo>();

[Constructible]
public BaseBook(int itemID, int pageCount = 20, bool writable = true) : this(itemID, null, null, pageCount, writable)
Expand Down Expand Up @@ -91,6 +93,29 @@ public BaseBook(int itemID, bool writable) : this(itemID, 0, writable)
[CommandProperty(AccessLevel.GameMaster)]
public int PagesCount => _pages.Length;

public override void OnAfterDuped(Item newItem)
{
if (newItem is not BaseBook book)
{
return;
}

book.Pages = new BookPageInfo[book.PagesCount];

for (var i = 0; i < _pages.Length; ++i)
{
var oldPage = _pages[i];
var oldLines = _pages[i].Lines;
var lines = new string[oldPage.Lines.Length];
for (var j = 0; j < oldLines.Length; j++)
{
lines[j] = oldLines[j];
}

book._pages[i] = new BookPageInfo(lines);
}
}

public virtual BookContent DefaultContent => null;

public string ContentAsString
Expand Down
41 changes: 19 additions & 22 deletions Projects/UOContent/Items/Books/BookPageInfo.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
using System;
namespace Server.Items;

namespace Server.Items
public class BookPageInfo
{
public class BookPageInfo
{
public BookPageInfo() => Lines = Array.Empty<string>();
public BookPageInfo() => Lines = [];

public BookPageInfo(params string[] lines) => Lines = lines;
public BookPageInfo(params string[] lines) => Lines = lines;

public BookPageInfo(IGenericReader reader)
{
var length = reader.ReadInt();
public BookPageInfo(IGenericReader reader)
{
var length = reader.ReadInt();

Lines = new string[length];
Lines = new string[length];

for (var i = 0; i < Lines.Length; ++i)
{
Lines[i] = reader.ReadString().Intern();
}
for (var i = 0; i < Lines.Length; ++i)
{
Lines[i] = reader.ReadString().Intern();
}
}

public string[] Lines { get; set; }
public string[] Lines { get; set; }

public void Serialize(IGenericWriter writer)
{
writer.Write(Lines.Length);
public void Serialize(IGenericWriter writer)
{
writer.Write(Lines.Length);

for (var i = 0; i < Lines.Length; ++i)
{
writer.Write(Lines[i]);
}
for (var i = 0; i < Lines.Length; ++i)
{
writer.Write(Lines[i]);
}
}
}
1 change: 1 addition & 0 deletions Projects/UOContent/Items/Construction/Doors/HouseDoors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public GenericHouseDoor(DoorFacing facing, int baseItemID, int openedSound, int
[SerializationGenerator(2, false)]
public abstract partial class BaseHouseDoor : BaseDoor, ISecurable
{
[SerializedIgnoreDupe]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;
Expand Down
1 change: 1 addition & 0 deletions Projects/UOContent/Items/Games/BaseBoard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Server.Items;
[SerializationGenerator(2, false)]
public abstract partial class BaseBoard : Container, ISecurable
{
[SerializedIgnoreDupe]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;
Expand Down
6 changes: 6 additions & 0 deletions Projects/UOContent/Items/Games/Mahjong/MahjongGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,28 @@ public partial class MahjongGame : Item, ISecurable
public const int MaxPlayers = 4;
public const int BaseScore = 30000;

[SerializedIgnoreDupe]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;

[SerializedIgnoreDupe]
[SerializableField(1, setter: "private")]
private MahjongTile[] _tiles;

[SerializedIgnoreDupe]
[SerializableField(2, setter: "private")]
private MahjongDealerIndicator _dealerIndicator;

[SerializedIgnoreDupe]
[SerializableField(3, setter: "private")]
private MahjongWallBreakIndicator _wallBreakIndicator;

[SerializedIgnoreDupe]
[SerializableField(4, setter: "private")]
private MahjongDices _dices;

[SerializedIgnoreDupe]
[SerializableField(5, setter: "private")]
private MahjongPlayers _players;

Expand Down
22 changes: 22 additions & 0 deletions Projects/UOContent/Items/Misc/PlayerBulletinBoards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public partial class PlayerBBEast : BasePlayerBB
[SerializationGenerator(0, false)]
public abstract partial class BasePlayerBB : Item, ISecurable
{
[SerializedIgnoreDupe]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;
Expand All @@ -40,10 +41,12 @@ public abstract partial class BasePlayerBB : Item, ISecurable
private string _title;

[CanBeNull]
[SerializedIgnoreDupe]
[SerializableField(2)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private PlayerBBMessage _greeting;

[SerializedIgnoreDupe]
[SerializableField(3)]
private List<PlayerBBMessage> _messages;

Expand All @@ -53,6 +56,25 @@ public BasePlayerBB(int itemID) : base(itemID)
_level = SecureLevel.Anyone;
}

public override void OnAfterDuped(Item newItem)
{
if (newItem is not BasePlayerBB board)
{
return;
}

if (_greeting != null)
{
board.Greeting = new PlayerBBMessage(_greeting.Time, _greeting.Poster, _greeting.Message);
}

for (var i = 0; i < _messages.Count; i++)
{
var message = _messages[i];
board.AddToMessages(new PlayerBBMessage(message.Time, message.Poster, message.Message));
}
}

public override void GetContextMenuEntries(Mobile from, List<ContextMenuEntry> list)
{
base.GetContextMenuEntries(from, list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface IDyable
[SerializationGenerator(2, false)]
public partial class DyeTub : Item, ISecurable
{
[SerializedIgnoreDupe]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public partial class DawnsMusicBox : Item, ISecurable
[SerializableField(0, setter: "private")]
private List<MusicName> _tracks;

[SerializedIgnoreDupe]
[SerializableField(1)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;
Expand Down
11 changes: 11 additions & 0 deletions Projects/UOContent/Items/Special/Gifts/RoseOfTrinsic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class RoseOfTrinsic : Item, ISecurable
[SerializableField(1, setter: "private")]
private DateTime _nextSpawnTime;

[SerializedIgnoreDupe]
[SerializableField(2)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;
Expand All @@ -34,6 +35,16 @@ public RoseOfTrinsic() : base(0x234D)

public override int LabelNumber => 1062913; // Rose of Trinsic

public override void OnAfterDuped(Item newItem)
{
if (newItem is not RoseOfTrinsic rose)
{
return;
}

rose.NextSpawnTime = NextSpawnTime;
}

[SerializableProperty(0)]
[CommandProperty(AccessLevel.GameMaster)]
public int Petals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Server.Items;
[SerializationGenerator(1)]
public partial class TapestryOfSosaria : Item, ISecurable
{
[SerializedIgnoreDupe]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;
Expand Down
1 change: 1 addition & 0 deletions Projects/UOContent/Items/Special/SoulStone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class SoulStone : Item, ISecurable
[SerializedCommandProperty(AccessLevel.GameMaster)]
private string _lastUserName;

[SerializedIgnoreDupe]
[SerializableField(1)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;
Expand Down
1 change: 1 addition & 0 deletions Projects/UOContent/Multis/Houses/HouseTeleporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Server.Items;
[SerializationGenerator(2, false)]
public partial class HouseTeleporter : Item, ISecurable
{
[SerializedIgnoreDupe]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SecureLevel _level;
Expand Down

0 comments on commit 76b8ed9

Please sign in to comment.