fix: Source generates map item serialization (#1166)

This commit is contained in:
Kamron Batman 2022-09-07 01:13:20 -07:00 committed by GitHub
parent b5a06d0545
commit b44c69bcee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 1517 additions and 1636 deletions

View file

@ -15,133 +15,140 @@
using System;
namespace Server
namespace Server;
[NoSort]
[Parsable]
[PropertyObject]
public struct Rectangle2D
{
[NoSort]
[Parsable]
[PropertyObject]
public struct Rectangle2D
public bool Equals(Rectangle2D other) => m_Start == other.m_Start && m_End == other.m_End;
public static bool operator ==(Rectangle2D l, Rectangle2D r) => l.m_Start == r.m_Start && l.m_End == r.m_End;
public static bool operator !=(Rectangle2D l, Rectangle2D r) => l.m_Start != r.m_Start || l.m_End != r.m_End;
public override int GetHashCode() => HashCode.Combine(m_Start, m_End);
private Point2D m_Start;
private Point2D m_End;
public Rectangle2D(Point2D start, Point2D end)
{
private Point2D m_Start;
private Point2D m_End;
public Rectangle2D(Point2D start, Point2D end)
{
m_Start = start;
m_End = end;
}
public Rectangle2D(int x, int y, int width, int height)
{
m_Start = new Point2D(x, y);
m_End = new Point2D(x + width, y + height);
}
public void Set(int x, int y, int width, int height)
{
m_Start = new Point2D(x, y);
m_End = new Point2D(x + width, y + height);
}
public static Rectangle2D Parse(string value)
{
var start = value.IndexOfOrdinal('(');
var end = value.IndexOf(',', start + 1);
Utility.ToInt32(value.AsSpan(start + 1, end - (start + 1)).Trim(), out var x);
start = end;
end = value.IndexOf(',', start + 1);
Utility.ToInt32(value.AsSpan(start + 1, end - (start + 1)).Trim(), out var y);
start = end;
end = value.IndexOf(',', start + 1);
Utility.ToInt32(value.AsSpan(start + 1, end - (start + 1)).Trim(), out var w);
start = end;
end = value.IndexOf(')', start + 1);
Utility.ToInt32(value.AsSpan(start + 1, end - (start + 1)).Trim(), out var h);
return new Rectangle2D(x, y, w, h);
}
[CommandProperty(AccessLevel.Counselor)]
public Point2D Start
{
get => m_Start;
set => m_Start = value;
}
[CommandProperty(AccessLevel.Counselor)]
public Point2D End
{
get => m_End;
set => m_End = value;
}
[CommandProperty(AccessLevel.Counselor)]
public int X
{
get => m_Start.m_X;
set => m_Start.m_X = value;
}
[CommandProperty(AccessLevel.Counselor)]
public int Y
{
get => m_Start.m_Y;
set => m_Start.m_Y = value;
}
[CommandProperty(AccessLevel.Counselor)]
public int Width
{
get => m_End.m_X - m_Start.m_X;
set => m_End.m_X = m_Start.m_X + value;
}
[CommandProperty(AccessLevel.Counselor)]
public int Height
{
get => m_End.m_Y - m_Start.m_Y;
set => m_End.m_Y = m_Start.m_Y + value;
}
public void MakeHold(Rectangle2D r)
{
if (r.m_Start.m_X < m_Start.m_X)
{
m_Start.m_X = r.m_Start.m_X;
}
if (r.m_Start.m_Y < m_Start.m_Y)
{
m_Start.m_Y = r.m_Start.m_Y;
}
if (r.m_End.m_X > m_End.m_X)
{
m_End.m_X = r.m_End.m_X;
}
if (r.m_End.m_Y > m_End.m_Y)
{
m_End.m_Y = r.m_End.m_Y;
}
}
public readonly bool Contains(Point3D p) =>
m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
public readonly bool Contains(Point2D p) =>
m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
public readonly bool Contains(int x, int y) =>
m_Start.m_X <= x && m_Start.m_Y <= y && m_End.m_X > x && m_End.m_Y > y;
public override string ToString() => $"({X}, {Y})+({Width}, {Height})";
m_Start = start;
m_End = end;
}
public Rectangle2D(int x, int y, int width, int height)
{
m_Start = new Point2D(x, y);
m_End = new Point2D(x + width, y + height);
}
public void Set(int x, int y, int width, int height)
{
m_Start = new Point2D(x, y);
m_End = new Point2D(x + width, y + height);
}
public static Rectangle2D Parse(string value)
{
var start = value.IndexOfOrdinal('(');
var end = value.IndexOf(',', start + 1);
Utility.ToInt32(value.AsSpan(start + 1, end - (start + 1)).Trim(), out var x);
start = end;
end = value.IndexOf(',', start + 1);
Utility.ToInt32(value.AsSpan(start + 1, end - (start + 1)).Trim(), out var y);
start = end;
end = value.IndexOf(',', start + 1);
Utility.ToInt32(value.AsSpan(start + 1, end - (start + 1)).Trim(), out var w);
start = end;
end = value.IndexOf(')', start + 1);
Utility.ToInt32(value.AsSpan(start + 1, end - (start + 1)).Trim(), out var h);
return new Rectangle2D(x, y, w, h);
}
[CommandProperty(AccessLevel.Counselor)]
public Point2D Start
{
get => m_Start;
set => m_Start = value;
}
[CommandProperty(AccessLevel.Counselor)]
public Point2D End
{
get => m_End;
set => m_End = value;
}
[CommandProperty(AccessLevel.Counselor)]
public int X
{
get => m_Start.m_X;
set => m_Start.m_X = value;
}
[CommandProperty(AccessLevel.Counselor)]
public int Y
{
get => m_Start.m_Y;
set => m_Start.m_Y = value;
}
[CommandProperty(AccessLevel.Counselor)]
public int Width
{
get => m_End.m_X - m_Start.m_X;
set => m_End.m_X = m_Start.m_X + value;
}
[CommandProperty(AccessLevel.Counselor)]
public int Height
{
get => m_End.m_Y - m_Start.m_Y;
set => m_End.m_Y = m_Start.m_Y + value;
}
public void MakeHold(Rectangle2D r)
{
if (r.m_Start.m_X < m_Start.m_X)
{
m_Start.m_X = r.m_Start.m_X;
}
if (r.m_Start.m_Y < m_Start.m_Y)
{
m_Start.m_Y = r.m_Start.m_Y;
}
if (r.m_End.m_X > m_End.m_X)
{
m_End.m_X = r.m_End.m_X;
}
if (r.m_End.m_Y > m_End.m_Y)
{
m_End.m_Y = r.m_End.m_Y;
}
}
public readonly bool Contains(Point3D p) =>
m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
public readonly bool Contains(Point2D p) =>
m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
public readonly bool Contains(int x, int y) =>
m_Start.m_X <= x && m_Start.m_Y <= y && m_End.m_X > x && m_End.m_Y > y;
public override string ToString() => $"({X}, {Y})+({Width}, {Height})";
}

View file

@ -1,33 +1,17 @@
namespace Server.Items
using ModernUO.Serialization;
namespace Server.Items;
[SerializationGenerator(0, false)]
public partial class BlankMap : MapItem
{
public class BlankMap : MapItem
[Constructible]
public BlankMap()
{
[Constructible]
public BlankMap()
{
}
}
public BlankMap(Serial serial) : base(serial)
{
}
public override void OnDoubleClick(Mobile from)
{
SendLocalizedMessageTo(from, 500208); // It appears to be blank.
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
}
public override void OnDoubleClick(Mobile from)
{
SendLocalizedMessageTo(from, 500208); // It appears to be blank.
}
}

View file

@ -1,55 +1,25 @@
namespace Server.Items
using System;
using ModernUO.Serialization;
namespace Server.Items;
[SerializationGenerator(0, false)]
public partial class CityMap : MapItem
{
public class CityMap : MapItem
[Constructible]
public CityMap()
{
[Constructible]
public CityMap()
{
SetDisplay(0, 0, 5119, 4095, 400, 400);
}
SetDisplay(0, 0, 5119, 4095, 400, 400);
}
public CityMap(Serial serial) : base(serial)
{
}
public override int LabelNumber => 1015231; // city map
public override int LabelNumber => 1015231; // city map
public override void CraftInit(Mobile from)
{
var skillValue = from.Skills.Cartography.Value;
var dist = Math.Max(64 + (int)(skillValue * 4), 200);
var size = Math.Clamp(32 + (int)(skillValue * 2), 200, 400);
public override void CraftInit(Mobile from)
{
var skillValue = from.Skills.Cartography.Value;
var dist = 64 + (int)(skillValue * 4);
if (dist < 200)
{
dist = 200;
}
var size = 32 + (int)(skillValue * 2);
if (size < 200)
{
size = 200;
}
else if (size > 400)
{
size = 400;
}
SetDisplay(from.X - dist, from.Y - dist, from.X + dist, from.Y + dist, size, size);
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
}
SetDisplay(from.X - dist, from.Y - dist, from.X + dist, from.Y + dist, size, size);
}
}

View file

@ -1,43 +1,17 @@
namespace Server.Items
using ModernUO.Serialization;
namespace Server.Items;
[SerializationGenerator(0)]
public partial class IndecipherableMap : MapItem
{
public class IndecipherableMap : MapItem
[Constructible]
public IndecipherableMap() => Hue = Utility.RandomDouble() < 0.2 ? 0x965 : 0x961;
public override int LabelNumber => 1070799; // indecipherable map
public override void OnDoubleClick(Mobile from)
{
[Constructible]
public IndecipherableMap()
{
if (Utility.RandomDouble() < 0.2)
{
Hue = 0x965;
}
else
{
Hue = 0x961;
}
}
public IndecipherableMap(Serial serial) : base(serial)
{
}
public override int LabelNumber => 1070799; // indecipherable map
public override void OnDoubleClick(Mobile from)
{
from.SendLocalizedMessage(1070801); // You cannot decipher this ruined map.
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.WriteEncodedInt(0); // version
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadEncodedInt();
}
from.SendLocalizedMessage(1070801); // You cannot decipher this ruined map.
}
}

View file

@ -1,39 +1,23 @@
namespace Server.Items
using ModernUO.Serialization;
namespace Server.Items;
[SerializationGenerator(0, false)]
public partial class LocalMap : MapItem
{
public class LocalMap : MapItem
[Constructible]
public LocalMap()
{
[Constructible]
public LocalMap()
{
SetDisplay(0, 0, 5119, 4095, 400, 400);
}
SetDisplay(0, 0, 5119, 4095, 400, 400);
}
public LocalMap(Serial serial) : base(serial)
{
}
public override int LabelNumber => 1015230; // local map
public override int LabelNumber => 1015230; // local map
public override void CraftInit(Mobile from)
{
var skillValue = from.Skills.Cartography.Value;
var dist = 64 + (int)(skillValue * 2);
public override void CraftInit(Mobile from)
{
var skillValue = from.Skills.Cartography.Value;
var dist = 64 + (int)(skillValue * 2);
SetDisplay(from.X - dist, from.Y - dist, from.X + dist, from.Y + dist, 200, 200);
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
}
SetDisplay(from.X - dist, from.Y - dist, from.X + dist, from.Y + dist, 200, 200);
}
}

View file

@ -1,324 +1,300 @@
using System;
using System.Collections.Generic;
using ModernUO.Serialization;
using Server.Engines.Craft;
using Server.Network;
namespace Server.Items
namespace Server.Items;
[Flippable(0x14EB, 0x14EC)]
[SerializationGenerator(1, false)]
public partial class MapItem : Item, ICraftable
{
[Flippable(0x14EB, 0x14EC)]
public class MapItem : Item, ICraftable
private const int MaxUserPins = 50;
[SerializableField(0)]
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
private Rectangle2D _bounds;
[SerializableField(1)]
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
private int _width;
[SerializableField(2)]
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
private int _height;
[SerializableField(3)]
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
private bool _protected;
[SerializableField(4, setter: "private")]
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
private List<Point2D> _pins;
[SerializableField(5)]
[SerializableFieldAttr("[CommandProperty(AccessLevel.GameMaster)]")]
private Map _facet;
[SerializableField(6)]
private bool _editable;
[Constructible]
public MapItem(Map facet = null) : base(0x14EC)
{
private const int MaxUserPins = 50;
private bool m_Editable;
Weight = 1.0;
_width = 200;
_height = 200;
_facet = facet;
_pins = new List<Point2D>();
}
[Constructible]
public MapItem(Map facet = null) : base(0x14EC)
public int OnCraft(
int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool,
CraftItem craftItem, int resHue
)
{
CraftInit(from);
return 1;
}
public virtual void CraftInit(Mobile from)
{
}
public void SetDisplay(int x1, int y1, int x2, int y2, int w, int h)
{
Width = w;
Height = h;
if (x1 < 0)
{
Weight = 1.0;
Width = 200;
Height = 200;
Facet = facet;
x1 = 0;
}
public MapItem(Serial serial) : base(serial)
if (y1 < 0)
{
y1 = 0;
}
[CommandProperty(AccessLevel.GameMaster)]
public bool Protected { get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public Rectangle2D Bounds { get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public int Width { get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public int Height { get; set; }
[CommandProperty(AccessLevel.GameMaster)]
public Map Facet { get; set; }
public List<Point2D> Pins { get; } = new();
public int OnCraft(
int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool,
CraftItem craftItem, int resHue
)
if (x2 > 5119)
{
CraftInit(from);
return 1;
x2 = 5119;
}
public virtual void CraftInit(Mobile from)
if (y2 > 4095)
{
y2 = 4095;
}
public void SetDisplay(int x1, int y1, int x2, int y2, int w, int h)
Bounds = new Rectangle2D(x1, y1, x2 - x1, y2 - y1);
}
public override void OnDoubleClick(Mobile from)
{
if (from.InRange(GetWorldLocation(), 2))
{
Width = w;
Height = h;
DisplayTo(from);
}
else
{
from.SendLocalizedMessage(500446); // That is too far away.
}
}
if (x1 < 0)
{
x1 = 0;
}
public virtual void DisplayTo(Mobile from)
{
var ns = from.NetState;
if (y1 < 0)
{
y1 = 0;
}
if (x2 >= 5120)
{
x2 = 5119;
}
if (y2 >= 4096)
{
y2 = 4095;
}
Bounds = new Rectangle2D(x1, y1, x2 - x1, y2 - y1);
if (!ns.NewCharacterList && _facet != null && _facet != Map.Felucca && _facet != Map.Trammel)
{
from.SendMessage("You must have client 7.0.13.0 or higher to display this map.");
return;
}
public override void OnDoubleClick(Mobile from)
ns.SendMapDetails(this);
ns.SendMapDisplay(this);
for (var i = 0; i < Pins.Count; ++i)
{
if (from.InRange(GetWorldLocation(), 2))
{
DisplayTo(from);
}
else
{
from.SendLocalizedMessage(500446); // That is too far away.
}
ns.SendMapAddPin(this, Pins[i]);
}
public virtual void DisplayTo(Mobile from)
ns.SendMapSetEditable(this, ValidateEdit(from));
}
public virtual void OnAddPin(Mobile from, int x, int y)
{
if (!ValidateEdit(from))
{
var ns = from.NetState;
if (!ns.NewCharacterList && Facet != null && Facet != Map.Felucca && Facet != Map.Trammel)
{
from.SendMessage("You must have client 7.0.13.0 or higher to display this map.");
return;
}
ns.SendMapDetails(this);
ns.SendMapDisplay(this);
for (var i = 0; i < Pins.Count; ++i)
{
ns.SendMapAddPin(this, Pins[i]);
}
ns.SendMapSetEditable(this, ValidateEdit(from));
return;
}
public virtual void OnAddPin(Mobile from, int x, int y)
if (Pins.Count >= MaxUserPins)
{
if (!ValidateEdit(from))
{
return;
}
if (Pins.Count >= MaxUserPins)
{
return;
}
Validate(ref x, ref y);
AddPin(x, y);
return;
}
public virtual void OnRemovePin(Mobile from, int number)
{
if (!ValidateEdit(from))
{
return;
}
Validate(ref x, ref y);
AddPin(x, y);
}
RemovePin(number);
public virtual void OnRemovePin(Mobile from, int number)
{
if (!ValidateEdit(from))
{
return;
}
public virtual void OnChangePin(Mobile from, int number, int x, int y)
{
if (!ValidateEdit(from))
{
return;
}
RemovePin(number);
}
Validate(ref x, ref y);
ChangePin(number, x, y);
public virtual void OnChangePin(Mobile from, int number, int x, int y)
{
if (!ValidateEdit(from))
{
return;
}
public virtual void OnInsertPin(Mobile from, int number, int x, int y)
Validate(ref x, ref y);
ChangePin(number, x, y);
}
public virtual void OnInsertPin(Mobile from, int number, int x, int y)
{
if (!ValidateEdit(from))
{
if (!ValidateEdit(from))
{
return;
}
if (Pins.Count >= MaxUserPins)
{
return;
}
Validate(ref x, ref y);
InsertPin(number, x, y);
return;
}
public virtual void OnClearPins(Mobile from)
if (Pins.Count >= MaxUserPins)
{
if (!ValidateEdit(from))
{
return;
}
ClearPins();
return;
}
public virtual void OnToggleEditable(Mobile from)
{
if (Validate(from))
{
m_Editable = !m_Editable;
}
Validate(ref x, ref y);
InsertPin(number, x, y);
}
from.NetState.SendMapSetEditable(this, m_Editable && Validate(from));
public virtual void OnClearPins(Mobile from)
{
if (!ValidateEdit(from))
{
return;
}
public virtual void Validate(ref int x, ref int y)
ClearPins();
}
public virtual void OnToggleEditable(Mobile from)
{
if (Validate(from))
{
x = Math.Clamp(x, 0, Width - 1);
y = Math.Clamp(y, 0, Height - 1);
_editable = !_editable;
}
public virtual bool ValidateEdit(Mobile from) => m_Editable && Validate(from);
from.NetState.SendMapSetEditable(this, _editable && Validate(from));
}
public virtual bool Validate(Mobile from)
public virtual void Validate(ref int x, ref int y)
{
x = Math.Clamp(x, 0, Width - 1);
y = Math.Clamp(y, 0, Height - 1);
}
public virtual bool ValidateEdit(Mobile from) => _editable && Validate(from);
public virtual bool Validate(Mobile from)
{
if (!from.CanSee(this) || from.Map != Map || !from.Alive || InSecureTrade)
{
if (!from.CanSee(this) || from.Map != Map || !from.Alive || InSecureTrade)
{
return false;
}
if (from.AccessLevel >= AccessLevel.GameMaster)
{
return true;
}
if (!Movable || Protected || !from.InRange(GetWorldLocation(), 2))
{
return false;
}
return !(RootParent is Mobile && RootParent != from);
return false;
}
public void ConvertToWorld(int x, int y, out int worldX, out int worldY)
if (from.AccessLevel >= AccessLevel.GameMaster)
{
worldX = Bounds.Width * x / Width + Bounds.X;
worldY = Bounds.Height * y / Height + Bounds.Y;
return true;
}
public void ConvertToMap(int x, int y, out int mapX, out int mapY)
if (!Movable || Protected || !from.InRange(GetWorldLocation(), 2))
{
mapX = (x - Bounds.X) * Width / Bounds.Width;
mapY = (y - Bounds.Y) * Width / Bounds.Height;
return false;
}
public virtual void AddWorldPin(int x, int y)
{
ConvertToMap(x, y, out var mapX, out var mapY);
AddPin(mapX, mapY);
}
return !(RootParent is Mobile && RootParent != from);
}
public virtual void AddPin(int x, int y)
public void ConvertToWorld(int x, int y, out int worldX, out int worldY)
{
worldX = Bounds.Width * x / Width + Bounds.X;
worldY = Bounds.Height * y / Height + Bounds.Y;
}
public void ConvertToMap(int x, int y, out int mapX, out int mapY)
{
mapX = (x - Bounds.X) * Width / Bounds.Width;
mapY = (y - Bounds.Y) * Width / Bounds.Height;
}
public virtual void AddWorldPin(int x, int y)
{
ConvertToMap(x, y, out var mapX, out var mapY);
AddPin(mapX, mapY);
}
public virtual void AddPin(int x, int y)
{
Pins.Add(new Point2D(x, y));
}
public virtual void RemovePin(int index)
{
if (index > 0 && index < Pins.Count)
{
Pins.RemoveAt(index);
}
}
public virtual void InsertPin(int index, int x, int y)
{
if (index < 0 || index >= Pins.Count)
{
Pins.Add(new Point2D(x, y));
}
public virtual void RemovePin(int index)
else
{
if (index > 0 && index < Pins.Count)
{
Pins.RemoveAt(index);
}
Pins.Insert(index, new Point2D(x, y));
}
}
public virtual void InsertPin(int index, int x, int y)
public virtual void ChangePin(int index, int x, int y)
{
if (index >= 0 && index < Pins.Count)
{
if (index < 0 || index >= Pins.Count)
{
Pins.Add(new Point2D(x, y));
}
else
{
Pins.Insert(index, new Point2D(x, y));
}
Pins[index] = new Point2D(x, y);
}
}
public virtual void ChangePin(int index, int x, int y)
public virtual void ClearPins()
{
Pins.Clear();
}
private void Deserialize(IGenericReader reader, int version)
{
// Version 0 doesn't serialize Facet/Editable, and count is not encoded
Bounds = reader.ReadRect2D();
Width = reader.ReadInt();
Height = reader.ReadInt();
Protected = reader.ReadBool();
var count = reader.ReadInt();
for (var i = 0; i < count; i++)
{
if (index >= 0 && index < Pins.Count)
{
Pins[index] = new Point2D(x, y);
}
}
public virtual void ClearPins()
{
Pins.Clear();
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
writer.Write(Bounds);
writer.Write(Width);
writer.Write(Height);
writer.Write(Protected);
writer.Write(Pins.Count);
for (var i = 0; i < Pins.Count; ++i)
{
writer.Write(Pins[i]);
}
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
switch (version)
{
case 0:
{
Bounds = reader.ReadRect2D();
Width = reader.ReadInt();
Height = reader.ReadInt();
Protected = reader.ReadBool();
var count = reader.ReadInt();
for (var i = 0; i < count; i++)
{
Pins.Add(reader.ReadPoint2D());
}
break;
}
}
Pins.Add(reader.ReadPoint2D());
}
}
}

View file

@ -43,23 +43,35 @@ namespace Server.Network
switch (command)
{
case 1:
map.OnAddPin(from, x, y);
break;
{
map.OnAddPin(from, x, y);
break;
}
case 2:
map.OnInsertPin(from, number, x, y);
break;
{
map.OnInsertPin(from, number, x, y);
break;
}
case 3:
map.OnChangePin(from, number, x, y);
break;
{
map.OnChangePin(from, number, x, y);
break;
}
case 4:
map.OnRemovePin(from, number);
break;
{
map.OnRemovePin(from, number);
break;
}
case 5:
map.OnClearPins(from);
break;
{
map.OnClearPins(from);
break;
}
case 6:
map.OnToggleEditable(from);
break;
{
map.OnToggleEditable(from);
break;
}
}
}

View file

@ -1,147 +1,121 @@
namespace Server.Items
using ModernUO.Serialization;
namespace Server.Items;
[SerializationGenerator(0, false)]
public partial class PresetMap : MapItem
{
public class PresetMap : MapItem
private int _labelNumber;
[Constructible]
public PresetMap(PresetMapType type)
{
private int m_LabelNumber;
var v = (int)type;
[Constructible]
public PresetMap(PresetMapType type)
if (v >= 0 && v < PresetMapEntry.Table.Length)
{
var v = (int)type;
if (v >= 0 && v < PresetMapEntry.Table.Length)
{
InitEntry(PresetMapEntry.Table[v]);
}
}
public PresetMap(PresetMapEntry entry)
{
InitEntry(entry);
}
public PresetMap(Serial serial) : base(serial)
{
}
public override int LabelNumber => m_LabelNumber == 0 ? base.LabelNumber : m_LabelNumber;
public void InitEntry(PresetMapEntry entry)
{
m_LabelNumber = entry.Name;
Width = entry.Width;
Height = entry.Height;
Bounds = entry.Bounds;
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
writer.Write(m_LabelNumber);
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
switch (version)
{
case 0:
{
m_LabelNumber = reader.ReadInt();
break;
}
}
InitEntry(PresetMapEntry.Table[v]);
}
}
public class PresetMapEntry
public PresetMap(PresetMapEntry entry)
{
public PresetMapEntry(int name, int width, int height, int xLeft, int yTop, int xRight, int yBottom)
{
Name = name;
Width = width;
Height = height;
Bounds = new Rectangle2D(xLeft, yTop, xRight - xLeft, yBottom - yTop);
}
public int Name { get; }
public int Width { get; }
public int Height { get; }
public Rectangle2D Bounds { get; }
public static PresetMapEntry[] Table { get; } =
{
new(1041189, 200, 200, 1092, 1396, 1736, 1924), // map of Britain
new(1041203, 200, 200, 0256, 1792, 1736, 2560), // map of Britain to Skara Brae
new(1041192, 200, 200, 1024, 1280, 2304, 3072), // map of Britain to Trinsic
new(1041183, 200, 200, 2500, 1900, 3000, 2400), // map of Buccaneer's Den
new(1041198, 200, 200, 2560, 1792, 3840, 2560), // map of Buccaneer's Den to Magincia
new(1041194, 200, 200, 2560, 1792, 3840, 3072), // map of Buccaneer's Den to Ocllo
new(1041181, 200, 200, 1088, 3572, 1528, 4056), // map of Jhelom
new(1041186, 200, 200, 3530, 2022, 3818, 2298), // map of Magincia
new(1041199, 200, 200, 3328, 1792, 3840, 2304), // map of Magincia to Ocllo
new(1041182, 200, 200, 2360, 0356, 2706, 0702), // map of Minoc
new(1041190, 200, 200, 0000, 0256, 2304, 3072), // map of Minoc to Yew
new(1041191, 200, 200, 2467, 0572, 2878, 0746), // map of Minoc to Vesper
new(1041188, 200, 200, 4156, 0808, 4732, 1528), // map of Moonglow
new(1041201, 200, 200, 3328, 0768, 4864, 1536), // map of Moonglow to Nujelm
new(1041185, 200, 200, 3446, 1030, 3832, 1424), // map of Nujelm
new(1041197, 200, 200, 3328, 1024, 3840, 2304), // map of Nujelm to Magincia
new(1041187, 200, 200, 3582, 2456, 3770, 2742), // map of Ocllo
new(1041184, 200, 200, 2714, 3329, 3100, 3639), // map of Serpent's Hold
new(1041200, 200, 200, 2560, 2560, 3840, 3840), // map of Serpent's Hold to Ocllo
new(1041180, 200, 200, 0524, 2064, 0960, 2452), // map of Skara Brae
new(1041204, 200, 200, 0000, 0000, 5199, 4095), // map of The World
new(1041177, 200, 200, 1792, 2630, 2118, 2952), // map of Trinsic
new(1041193, 200, 200, 1792, 1792, 3072, 3072), // map of Trinsic to Buccaneer's Den
new(1041195, 200, 200, 0256, 1792, 2304, 4095), // map of Trinsic to Jhelom
new(1041178, 200, 200, 2636, 0592, 3064, 1012), // map of Vesper
new(1041196, 200, 200, 2636, 0592, 3840, 1536), // map of Vesper to Nujelm
new(1041179, 200, 200, 0236, 0741, 0766, 1269), // map of Yew
new(1041202, 200, 200, 0000, 0512, 1792, 2048) // map of Yew to Britain
};
InitEntry(entry);
}
public enum PresetMapType
[SerializableProperty(0, useField: nameof(_labelNumber))]
public override int LabelNumber => _labelNumber == 0 ? base.LabelNumber : _labelNumber;
public void InitEntry(PresetMapEntry entry)
{
Britain,
BritainToSkaraBrae,
BritainToTrinsic,
BucsDen,
BucsDenToMagincia,
BucsDenToOcllo,
Jhelom,
Magincia,
MaginciaToOcllo,
Minoc,
MinocToYew,
MinocToVesper,
Moonglow,
MoonglowToNujelm,
Nujelm,
NujelmToMagincia,
Ocllo,
SerpentsHold,
SerpentsHoldToOcllo,
SkaraBrae,
TheWorld,
Trinsic,
TrinsicToBucsDen,
TrinsicToJhelom,
Vesper,
VesperToNujelm,
Yew,
YewToBritain
_labelNumber = entry.Name;
Width = entry.Width;
Height = entry.Height;
Bounds = entry.Bounds;
}
}
public class PresetMapEntry
{
public PresetMapEntry(int name, int width, int height, int xLeft, int yTop, int xRight, int yBottom)
{
Name = name;
Width = width;
Height = height;
Bounds = new Rectangle2D(xLeft, yTop, xRight - xLeft, yBottom - yTop);
}
public int Name { get; }
public int Width { get; }
public int Height { get; }
public Rectangle2D Bounds { get; }
public static PresetMapEntry[] Table { get; } =
{
new(1041189, 200, 200, 1092, 1396, 1736, 1924), // map of Britain
new(1041203, 200, 200, 0256, 1792, 1736, 2560), // map of Britain to Skara Brae
new(1041192, 200, 200, 1024, 1280, 2304, 3072), // map of Britain to Trinsic
new(1041183, 200, 200, 2500, 1900, 3000, 2400), // map of Buccaneer's Den
new(1041198, 200, 200, 2560, 1792, 3840, 2560), // map of Buccaneer's Den to Magincia
new(1041194, 200, 200, 2560, 1792, 3840, 3072), // map of Buccaneer's Den to Ocllo
new(1041181, 200, 200, 1088, 3572, 1528, 4056), // map of Jhelom
new(1041186, 200, 200, 3530, 2022, 3818, 2298), // map of Magincia
new(1041199, 200, 200, 3328, 1792, 3840, 2304), // map of Magincia to Ocllo
new(1041182, 200, 200, 2360, 0356, 2706, 0702), // map of Minoc
new(1041190, 200, 200, 0000, 0256, 2304, 3072), // map of Minoc to Yew
new(1041191, 200, 200, 2467, 0572, 2878, 0746), // map of Minoc to Vesper
new(1041188, 200, 200, 4156, 0808, 4732, 1528), // map of Moonglow
new(1041201, 200, 200, 3328, 0768, 4864, 1536), // map of Moonglow to Nujelm
new(1041185, 200, 200, 3446, 1030, 3832, 1424), // map of Nujelm
new(1041197, 200, 200, 3328, 1024, 3840, 2304), // map of Nujelm to Magincia
new(1041187, 200, 200, 3582, 2456, 3770, 2742), // map of Ocllo
new(1041184, 200, 200, 2714, 3329, 3100, 3639), // map of Serpent's Hold
new(1041200, 200, 200, 2560, 2560, 3840, 3840), // map of Serpent's Hold to Ocllo
new(1041180, 200, 200, 0524, 2064, 0960, 2452), // map of Skara Brae
new(1041204, 200, 200, 0000, 0000, 5199, 4095), // map of The World
new(1041177, 200, 200, 1792, 2630, 2118, 2952), // map of Trinsic
new(1041193, 200, 200, 1792, 1792, 3072, 3072), // map of Trinsic to Buccaneer's Den
new(1041195, 200, 200, 0256, 1792, 2304, 4095), // map of Trinsic to Jhelom
new(1041178, 200, 200, 2636, 0592, 3064, 1012), // map of Vesper
new(1041196, 200, 200, 2636, 0592, 3840, 1536), // map of Vesper to Nujelm
new(1041179, 200, 200, 0236, 0741, 0766, 1269), // map of Yew
new(1041202, 200, 200, 0000, 0512, 1792, 2048) // map of Yew to Britain
};
}
public enum PresetMapType
{
Britain,
BritainToSkaraBrae,
BritainToTrinsic,
BucsDen,
BucsDenToMagincia,
BucsDenToOcllo,
Jhelom,
Magincia,
MaginciaToOcllo,
Minoc,
MinocToYew,
MinocToVesper,
Moonglow,
MoonglowToNujelm,
Nujelm,
NujelmToMagincia,
Ocllo,
SerpentsHold,
SerpentsHoldToOcllo,
SkaraBrae,
TheWorld,
Trinsic,
TrinsicToBucsDen,
TrinsicToJhelom,
Vesper,
VesperToNujelm,
Yew,
YewToBritain
}

View file

@ -1,55 +1,25 @@
namespace Server.Items
using System;
using ModernUO.Serialization;
namespace Server.Items;
[SerializationGenerator(0, false)]
public partial class SeaChart : MapItem
{
public class SeaChart : MapItem
[Constructible]
public SeaChart()
{
[Constructible]
public SeaChart()
{
SetDisplay(0, 0, 5119, 4095, 400, 400);
}
SetDisplay(0, 0, 5119, 4095, 400, 400);
}
public SeaChart(Serial serial) : base(serial)
{
}
public override int LabelNumber => 1015232; // sea chart
public override int LabelNumber => 1015232; // sea chart
public override void CraftInit(Mobile from)
{
var skillValue = from.Skills.Cartography.Value;
var dist = Math.Max(64 + (int)(skillValue * 10), 200);
var size = Math.Clamp(24 + (int)(skillValue * 3.3), 200, 400);
public override void CraftInit(Mobile from)
{
var skillValue = from.Skills.Cartography.Value;
var dist = 64 + (int)(skillValue * 10);
if (dist < 200)
{
dist = 200;
}
var size = 24 + (int)(skillValue * 3.3);
if (size < 200)
{
size = 200;
}
else if (size > 400)
{
size = 400;
}
SetDisplay(from.X - dist, from.Y - dist, from.X + dist, from.Y + dist, size, size);
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
}
SetDisplay(from.X - dist, from.Y - dist, from.X + dist, from.Y + dist, size, size);
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,51 +1,27 @@
namespace Server.Items
using System;
using ModernUO.Serialization;
namespace Server.Items;
[SerializationGenerator(0)]
public partial class WorldMap : MapItem
{
public class WorldMap : MapItem
[Constructible]
public WorldMap()
{
[Constructible]
public WorldMap()
{
SetDisplay(0, 0, 5119, 4095, 400, 400);
}
SetDisplay(0, 0, 5119, 4095, 400, 400);
}
public WorldMap(Serial serial) : base(serial)
{
}
public override int LabelNumber => 1015233; // world map
public override int LabelNumber => 1015233; // world map
public override void CraftInit(Mobile from)
{
// Unlike the others, world map is not based on crafted location
public override void CraftInit(Mobile from)
{
// Unlike the others, world map is not based on crafted location
var skillValue = from.Skills.Cartography.Value;
var x20 = (int)(skillValue * 20);
var size = Math.Clamp(25 + (int)(skillValue * 6.6), 200, 400);
var skillValue = from.Skills.Cartography.Value;
var x20 = (int)(skillValue * 20);
var size = 25 + (int)(skillValue * 6.6);
if (size < 200)
{
size = 200;
}
else if (size > 400)
{
size = 400;
}
SetDisplay(1344 - x20, 1600 - x20, 1472 + x20, 1728 + x20, size, size);
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
}
SetDisplay(1344 - x20, 1600 - x20, 1472 + x20, 1728 + x20, size, size);
}
}

View file

@ -0,0 +1,4 @@
{
"version": 0,
"type": "Server.Items.BlankMap"
}

View file

@ -0,0 +1,4 @@
{
"version": 0,
"type": "Server.Items.CityMap"
}

View file

@ -0,0 +1,4 @@
{
"version": 0,
"type": "Server.Items.IndecipherableMap"
}

View file

@ -0,0 +1,4 @@
{
"version": 0,
"type": "Server.Items.LocalMap"
}

View file

@ -0,0 +1,65 @@
{
"version": 1,
"type": "Server.Items.MapItem",
"properties": [
{
"name": "Bounds",
"type": "Server.Rectangle2D",
"rule": "PrimitiveUOTypeMigrationRule",
"ruleArguments": [
"Rect2D"
]
},
{
"name": "Width",
"type": "int",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": [
""
]
},
{
"name": "Height",
"type": "int",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": [
""
]
},
{
"name": "Protected",
"type": "bool",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": [
""
]
},
{
"name": "Pins",
"type": "System.Collections.Generic.List\u003CServer.Point2D\u003E",
"rule": "ListMigrationRule",
"ruleArguments": [
"",
"Server.Point2D",
"PrimitiveUOTypeMigrationRule",
"Point2D"
]
},
{
"name": "Facet",
"type": "Server.Map",
"rule": "PrimitiveUOTypeMigrationRule",
"ruleArguments": [
"Map"
]
},
{
"name": "Editable",
"type": "bool",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": [
""
]
}
]
}

View file

@ -0,0 +1,14 @@
{
"version": 0,
"type": "Server.Items.PresetMap",
"properties": [
{
"name": "LabelNumber",
"type": "int",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": [
""
]
}
]
}

View file

@ -0,0 +1,4 @@
{
"version": 0,
"type": "Server.Items.SeaChart"
}

View file

@ -0,0 +1,4 @@
{
"version": 0,
"type": "Server.Items.TreasureChestDirt"
}

View file

@ -0,0 +1,48 @@
{
"version": 0,
"type": "Server.Items.TreasureMap",
"properties": [
{
"name": "CompletedBy",
"type": "Server.Mobile",
"rule": "SerializableInterfaceMigrationRule"
},
{
"name": "Level",
"type": "int",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": [
""
]
},
{
"name": "Completed",
"type": "bool",
"rule": "PrimitiveTypeMigrationRule",
"ruleArguments": [
""
]
},
{
"name": "Decoder",
"type": "Server.Mobile",
"rule": "SerializableInterfaceMigrationRule"
},
{
"name": "ChestMap",
"type": "Server.Map",
"rule": "PrimitiveUOTypeMigrationRule",
"ruleArguments": [
"Map"
]
},
{
"name": "ChestLocation",
"type": "Server.Point2D",
"rule": "PrimitiveUOTypeMigrationRule",
"ruleArguments": [
"Point2D"
]
}
]
}

View file

@ -0,0 +1,4 @@
{
"version": 0,
"type": "Server.Items.WorldMap"
}