fix: Finishes code gen for misc items (#1248)

This commit is contained in:
Kamron Batman 2022-11-13 23:10:13 -08:00 • committed by GitHub
parent 6d00b2caa9
commit 5660f4636e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 2797 additions and 3156 deletions

View file

@ -1,86 +1,63 @@
using ModernUO.Serialization;
using Server.Targeting;
namespace Server.Items
namespace Server.Items;
[SerializationGenerator(0, false)]
public partial class Scales : Item
{
public class Scales : Item
[Constructible]
public Scales() : base(0x1852) => Weight = 4.0;
public override void OnDoubleClick(Mobile from)
{
[Constructible]
public Scales() : base(0x1852) => Weight = 4.0;
from.SendLocalizedMessage(502431); // What would you like to weigh?
from.Target = new InternalTarget(this);
}
public Scales(Serial serial) : base(serial)
private class InternalTarget : Target
{
private Scales _scales;
public InternalTarget(Scales item) : base(1, false, TargetFlags.None) => _scales = item;
protected override void OnTarget(Mobile from, object targeted)
{
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
}
public override void OnDoubleClick(Mobile from)
{
from.SendLocalizedMessage(502431); // What would you like to weigh?
from.Target = new InternalTarget(this);
}
private class InternalTarget : Target
{
private readonly Scales m_Item;
public InternalTarget(Scales item) : base(1, false, TargetFlags.None) => m_Item = item;
protected override void OnTarget(Mobile from, object targeted)
if (targeted == _scales)
{
string message;
from.SendMessage("It cannot weigh itself.");
return;
}
if (targeted == m_Item)
{
message = "It cannot weight itself.";
}
else if (targeted is Item item)
{
var root = item.RootParent;
if (targeted is Mobile m)
{
from.SendLocalizedMessage(502432); // That is too heavy for these scales!
}
if (root != null && root != from || item.Parent == from)
{
message = "You decide that item's current location is too awkward to get an accurate result.";
}
else if (item.Movable)
{
message = item.Amount > 1
? "You place one item on the scale. "
: "You place that item on the scale. ";
if (targeted is not Item { Movable: true } item)
{
from.SendMessage("You cannot weigh that.");
return;
}
var weight = item.Weight;
var root = item.RootParent;
if (weight <= 0.0)
{
message += "It is lighter than a feather.";
}
else
{
message += $"It weighs {weight} stones.";
}
}
else
{
message = "You cannot weigh that object.";
}
}
else
{
message = "You cannot weigh that object.";
}
if (root != null && root != from || item.Parent == from)
{
from.SendMessage("You decide that item's current location is too awkward to get an accurate result.");
return;
}
from.SendMessage(message);
var amount = item.Amount > 1 ? "one" : "that";
var weight = item.Weight;
if (weight <= 0.0)
{
from.SendMessage($"You place {amount} item on the scale. It is lighter than a feather.");
}
else
{
from.SendMessage($"You place {amount} item on the scale. It weighs {weight} stones.");
}
}
}