fix: Updates disguises and codegens tinkering items (#1353)

This commit is contained in:
Kamron Batman 2023-02-25 12:01:06 -08:00 • committed by GitHub
parent f2fdc0321c
commit d14e864c85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 1012 additions and 1454 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using ModernUO.Serialization;
using Server.Factions;
using Server.Gumps;
using Server.Mobiles;
@ -9,347 +10,257 @@ using Server.Spells;
using Server.Spells.Fifth;
using Server.Spells.Seventh;
namespace Server.Items
namespace Server.Items;
[SerializationGenerator(0, false)]
public partial class DisguiseKit : Item
{
public class DisguiseKit : Item
[Constructible]
public DisguiseKit() : base(0xE05) => Weight = 1.0;
public bool ValidateUse(Mobile from)
{
[Constructible]
public DisguiseKit() : base(0xE05) => Weight = 1.0;
var pm = from as PlayerMobile;
public DisguiseKit(Serial serial) : base(serial)
if (!IsChildOf(from.Backpack))
{
from.SendLocalizedMessage(1042001);
}
else if (pm?.NpcGuild != NpcGuild.ThievesGuild)
{
from.SendLocalizedMessage(501702);
}
else if (Stealing.SuspendOnMurder && pm.Kills > 0)
{
from.SendLocalizedMessage(501703);
}
else if (!from.CanBeginAction<IncognitoSpell>())
{
from.SendLocalizedMessage(501704);
}
else if (Sigil.ExistsOn(from))
{
from.SendLocalizedMessage(1010465); // You cannot disguise yourself while holding a sigil
}
else if (TransformationSpellHelper.UnderTransformation(from))
{
from.SendLocalizedMessage(1061634);
}
else if (from.BodyMod == 183 || from.BodyMod == 184)
{
from.SendLocalizedMessage(1040002);
}
else if (!from.CanBeginAction<PolymorphSpell>() || from.IsBodyMod)
{
from.SendLocalizedMessage(501705);
}
else
{
return true;
}
public override int LabelNumber => 1041078; // a disguise kit
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 bool ValidateUse(Mobile from)
{
var pm = from as PlayerMobile;
if (!IsChildOf(from.Backpack))
{
from.SendLocalizedMessage(1042001);
}
else if (pm?.NpcGuild != NpcGuild.ThievesGuild)
{
from.SendLocalizedMessage(501702);
}
else if (Stealing.SuspendOnMurder && pm.Kills > 0)
{
from.SendLocalizedMessage(501703);
}
else if (!from.CanBeginAction<IncognitoSpell>())
{
from.SendLocalizedMessage(501704);
}
else if (Sigil.ExistsOn(from))
{
from.SendLocalizedMessage(1010465); // You cannot disguise yourself while holding a sigil
}
else if (TransformationSpellHelper.UnderTransformation(from))
{
from.SendLocalizedMessage(1061634);
}
else if (from.BodyMod == 183 || from.BodyMod == 184)
{
from.SendLocalizedMessage(1040002);
}
else if (!from.CanBeginAction<PolymorphSpell>() || from.IsBodyMod)
{
from.SendLocalizedMessage(501705);
}
else
{
return true;
}
return false;
}
public override void OnDoubleClick(Mobile from)
{
if (ValidateUse(from))
{
from.SendGump(new DisguiseGump(from, this, true, false));
}
}
return false;
}
public class DisguiseGump : Gump
public override void OnDoubleClick(Mobile from)
{
private static readonly DisguiseEntry[] m_HairEntries =
if (ValidateUse(from))
{
new(8251, 50700, 0, 5, 1011052), // Short
new(8261, 60710, 0, 3, 1011047), // Pageboy
new(8252, 60708, 0, -5, 1011053), // Long
new(8264, 60901, 0, 5, 1011048), // Receding
new(8253, 60702, 0, -5, 1011054), // Ponytail
new(8265, 60707, 0, -5, 1011049), // 2-tails
new(8260, 50703, 0, 5, 1011055), // Mohawk
new(8266, 60713, 0, 10, 1011050), // Topknot
null,
new(0, 0, 0, 0, 1011051) // None
};
private static readonly DisguiseEntry[] m_BeardEntries =
{
new(8269, 50906, 0, 0, 1011401), // Vandyke
new(8257, 50808, 0, -2, 1011062), // Mustache
new(8255, 50802, 0, 0, 1011060), // Short beard
new(8268, 50905, 0, -10, 1011061), // Long beard
new(8267, 50904, 0, 0, 1011060), // Short beard
new(8254, 50801, 0, -10, 1011061), // Long beard
null,
new(0, 0, 0, 0, 1011051) // None
};
private readonly Mobile m_From;
private readonly DisguiseKit m_Kit;
private readonly bool m_Used;
public DisguiseGump(Mobile from, DisguiseKit kit, bool startAtHair, bool used) : base(50, 50)
{
m_From = from;
m_Kit = kit;
m_Used = used;
from.CloseGump<DisguiseGump>();
AddPage(0);
AddBackground(100, 10, 400, 385, 2600);
// <center>THIEF DISGUISE KIT</center>
AddHtmlLocalized(100, 25, 400, 35, 1011045);
AddButton(140, 353, 4005, 4007, 0);
AddHtmlLocalized(172, 355, 90, 35, 1011036); // OKAY
AddButton(257, 353, 4005, 4007, 1);
AddHtmlLocalized(289, 355, 90, 35, 1011046); // APPLY
if (from.Female || from.Body.IsFemale)
{
DrawEntries(0, 1, -1, m_HairEntries, -1);
}
else if (startAtHair)
{
DrawEntries(0, 1, 2, m_HairEntries, 1011056);
DrawEntries(1, 2, 1, m_BeardEntries, 1011059);
}
else
{
DrawEntries(1, 1, 2, m_BeardEntries, 1011059);
DrawEntries(0, 2, 1, m_HairEntries, 1011056);
}
}
private void DrawEntries(int index, int page, int nextPage, DisguiseEntry[] entries, int nextNumber)
{
AddPage(page);
if (nextPage != -1)
{
AddButton(155, 320, 250 + index * 2, 251 + index * 2, 0, GumpButtonType.Page, nextPage);
AddHtmlLocalized(180, 320, 150, 35, nextNumber);
}
for (var i = 0; i < entries.Length; ++i)
{
var entry = entries[i];
if (entry == null)
{
continue;
}
var x = i % 2 * 205;
var y = i / 2 * 55;
if (entry.m_GumpID != 0)
{
AddBackground(220 + x, 60 + y, 50, 50, 2620);
AddImage(153 + x + entry.m_OffsetX, 15 + y + entry.m_OffsetY, entry.m_GumpID);
}
AddHtmlLocalized(140 + x, 72 + y, 80, 35, entry.m_Number);
AddRadio(118 + x, 73 + y, 208, 209, false, i * 2 + index);
}
}
public override void OnResponse(NetState sender, RelayInfo info)
{
if (info.ButtonID == 0)
{
if (m_Used)
{
m_From.SendLocalizedMessage(501706); // Disguises wear off after 2 hours.
}
else
{
m_From.SendLocalizedMessage(501707); // You're looking good.
}
return;
}
var switches = info.Switches;
if (switches.Length == 0)
{
return;
}
var switched = switches[0];
var type = switched % 2;
var index = switched / 2;
var hair = type == 0;
var entries = hair ? m_HairEntries : m_BeardEntries;
if (index >= 0 && index < entries.Length)
{
var entry = entries[index];
if (entry == null)
{
return;
}
if (!m_Kit.ValidateUse(m_From))
{
return;
}
if (!hair && (m_From.Female || m_From.Body.IsFemale))
{
return;
}
m_From.NameMod = NameList.RandomName(m_From.Female ? "female" : "male");
if (m_From is PlayerMobile pm)
{
if (hair)
{
pm.SetHairMods(entry.m_ItemID, -2);
}
else
{
pm.SetHairMods(-2, entry.m_ItemID);
}
}
m_From.SendGump(new DisguiseGump(m_From, m_Kit, hair, true));
DisguiseTimers.RemoveTimer(m_From);
DisguiseTimers.CreateTimer(m_From, TimeSpan.FromHours(2.0));
DisguiseTimers.StartTimer(m_From);
}
}
private class DisguiseEntry
{
public readonly int m_GumpID;
public readonly int m_ItemID;
public readonly int m_Number;
public readonly int m_OffsetX;
public readonly int m_OffsetY;
public DisguiseEntry(int itemID, int gumpID, int ox, int oy, int name)
{
m_ItemID = itemID;
m_GumpID = gumpID;
m_OffsetX = ox;
m_OffsetY = oy;
m_Number = name;
}
}
}
public static class DisguiseTimers
{
public static Dictionary<Mobile, Timer> Timers { get; } = new();
public static void Initialize()
{
new DisguisePersistance();
}
public static void CreateTimer(Mobile m, TimeSpan delay)
{
if (m != null && !IsDisguised(m))
{
Timers[m] = new InternalTimer(m, delay);
}
}
public static void StartTimer(Mobile m)
{
Timers.TryGetValue(m, out var t);
t?.Start();
}
public static bool IsDisguised(Mobile m) => Timers.ContainsKey(m);
public static void StopTimer(Mobile m)
{
if (!Timers.TryGetValue(m, out var t))
{
return;
}
t.Delay = Utility.Max(t.Next - Core.Now, TimeSpan.Zero);
t.Stop();
}
public static void RemoveTimer(Mobile m)
{
if (Timers.Remove(m, out var t))
{
t.Stop();
}
}
public static TimeSpan TimeRemaining(Mobile m) =>
Timers.TryGetValue(m, out var t) ? t.Next - Core.Now : TimeSpan.Zero;
private class InternalTimer : Timer
{
private readonly Mobile m_Player;
public InternalTimer(Mobile m, TimeSpan delay) : base(delay)
{
m_Player = m;
}
protected override void OnTick()
{
m_Player.NameMod = null;
if (m_Player is PlayerMobile mobile)
{
mobile.SetHairMods(-1, -1);
}
RemoveTimer(m_Player);
}
from.SendGump(new DisguiseGump(from, this, true, false));
}
}
}
public class DisguiseGump : Gump
{
private static readonly DisguiseEntry[] m_HairEntries =
{
new(8251, 50700, 0, 5, 1011052), // Short
new(8261, 60710, 0, 3, 1011047), // Pageboy
new(8252, 60708, 0, -5, 1011053), // Long
new(8264, 60901, 0, 5, 1011048), // Receding
new(8253, 60702, 0, -5, 1011054), // Ponytail
new(8265, 60707, 0, -5, 1011049), // 2-tails
new(8260, 50703, 0, 5, 1011055), // Mohawk
new(8266, 60713, 0, 10, 1011050), // Topknot
null,
new(0, 0, 0, 0, 1011051) // None
};
private static readonly DisguiseEntry[] m_BeardEntries =
{
new(8269, 50906, 0, 0, 1011401), // Vandyke
new(8257, 50808, 0, -2, 1011062), // Mustache
new(8255, 50802, 0, 0, 1011060), // Short beard
new(8268, 50905, 0, -10, 1011061), // Long beard
new(8267, 50904, 0, 0, 1011060), // Short beard
new(8254, 50801, 0, -10, 1011061), // Long beard
null,
new(0, 0, 0, 0, 1011051) // None
};
private readonly Mobile m_From;
private readonly DisguiseKit m_Kit;
private readonly bool m_Used;
public DisguiseGump(Mobile from, DisguiseKit kit, bool startAtHair, bool used) : base(50, 50)
{
m_From = from;
m_Kit = kit;
m_Used = used;
from.CloseGump<DisguiseGump>();
AddPage(0);
AddBackground(100, 10, 400, 385, 2600);
// <center>THIEF DISGUISE KIT</center>
AddHtmlLocalized(100, 25, 400, 35, 1011045);
AddButton(140, 353, 4005, 4007, 0);
AddHtmlLocalized(172, 355, 90, 35, 1011036); // OKAY
AddButton(257, 353, 4005, 4007, 1);
AddHtmlLocalized(289, 355, 90, 35, 1011046); // APPLY
if (from.Female || from.Body.IsFemale)
{
DrawEntries(0, 1, -1, m_HairEntries, -1);
}
else if (startAtHair)
{
DrawEntries(0, 1, 2, m_HairEntries, 1011056);
DrawEntries(1, 2, 1, m_BeardEntries, 1011059);
}
else
{
DrawEntries(1, 1, 2, m_BeardEntries, 1011059);
DrawEntries(0, 2, 1, m_HairEntries, 1011056);
}
}
private void DrawEntries(int index, int page, int nextPage, DisguiseEntry[] entries, int nextNumber)
{
AddPage(page);
if (nextPage != -1)
{
AddButton(155, 320, 250 + index * 2, 251 + index * 2, 0, GumpButtonType.Page, nextPage);
AddHtmlLocalized(180, 320, 150, 35, nextNumber);
}
for (var i = 0; i < entries.Length; ++i)
{
var entry = entries[i];
if (entry == null)
{
continue;
}
var x = i % 2 * 205;
var y = i / 2 * 55;
if (entry.m_GumpID != 0)
{
AddBackground(220 + x, 60 + y, 50, 50, 2620);
AddImage(153 + x + entry.m_OffsetX, 15 + y + entry.m_OffsetY, entry.m_GumpID);
}
AddHtmlLocalized(140 + x, 72 + y, 80, 35, entry.m_Number);
AddRadio(118 + x, 73 + y, 208, 209, false, i * 2 + index);
}
}
public override void OnResponse(NetState sender, RelayInfo info)
{
if (info.ButtonID == 0)
{
if (m_Used)
{
m_From.SendLocalizedMessage(501706); // Disguises wear off after 2 hours.
}
else
{
m_From.SendLocalizedMessage(501707); // You're looking good.
}
return;
}
var switches = info.Switches;
if (switches.Length == 0)
{
return;
}
var switched = switches[0];
var type = switched % 2;
var index = switched / 2;
var hair = type == 0;
var entries = hair ? m_HairEntries : m_BeardEntries;
if (index >= 0 && index < entries.Length)
{
var entry = entries[index];
if (entry == null)
{
return;
}
if (!m_Kit.ValidateUse(m_From))
{
return;
}
if (!hair && (m_From.Female || m_From.Body.IsFemale))
{
return;
}
m_From.NameMod = NameList.RandomName(m_From.Female ? "female" : "male");
if (m_From is PlayerMobile pm)
{
if (hair)
{
pm.SetHairMods(entry.m_ItemID, -2);
}
else
{
pm.SetHairMods(-2, entry.m_ItemID);
}
}
m_From.SendGump(new DisguiseGump(m_From, m_Kit, hair, true));
DisguisePersistence.RemoveTimer(m_From);
DisguisePersistence.CreateTimer(m_From, TimeSpan.FromHours(2.0));
DisguisePersistence.StartTimer(m_From);
}
}
private class DisguiseEntry
{
public readonly int m_GumpID;
public readonly int m_ItemID;
public readonly int m_Number;
public readonly int m_OffsetX;
public readonly int m_OffsetY;
public DisguiseEntry(int itemID, int gumpID, int ox, int oy, int name)
{
m_ItemID = itemID;
m_GumpID = gumpID;
m_OffsetX = ox;
m_OffsetY = oy;
m_Number = name;
}
}
}

View file

@ -1,73 +0,0 @@
namespace Server.Items
{
public class DisguisePersistance : Item
{
public DisguisePersistance() : base(1)
{
Movable = false;
if (Instance?.Deleted != false)
{
Instance = this;
}
else
{
base.Delete();
}
}
public DisguisePersistance(Serial serial) : base(serial) => Instance = this;
public static DisguisePersistance Instance { get; private set; }
public override string DefaultName => "Disguise Persistance - Internal";
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
var timerCount = DisguiseTimers.Timers.Count;
writer.Write(timerCount);
foreach (var entry in DisguiseTimers.Timers)
{
var m = entry.Key;
writer.Write(m);
writer.Write(entry.Value.Next - Core.Now);
writer.Write(m.NameMod);
}
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
switch (version)
{
case 0:
{
var count = reader.ReadInt();
for (var i = 0; i < count; ++i)
{
var m = reader.ReadEntity<Mobile>();
DisguiseTimers.CreateTimer(m, reader.ReadTimeSpan());
m.NameMod = reader.ReadString();
}
break;
}
}
}
public override void Delete()
{
}
}
}

View file

@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using Server.Mobiles;
namespace Server.Items;
public static class DisguisePersistence
{
public static Dictionary<Mobile, Timer> Timers { get; } = new();
public static void Configure()
{
GenericPersistence.Register("Disguises", Serialize, Deserialize);
}
private static void Deserialize(IGenericReader reader)
{
var count = reader.ReadEncodedInt();
for (var i = 0; i < count; ++i)
{
var m = reader.ReadEntity<Mobile>();
CreateTimer(m, reader.ReadTimeSpan());
m.NameMod = reader.ReadString();
}
}
private static void Serialize(IGenericWriter writer)
{
writer.WriteEncodedInt(Timers.Count);
foreach (var (m, timer) in Timers)
{
writer.Write(m);
writer.Write(timer.Next - Core.Now);
}
}
public static void CreateTimer(Mobile m, TimeSpan delay)
{
if (m != null && !IsDisguised(m))
{
Timers[m] = new InternalTimer(m, delay);
}
}
public static void StartTimer(Mobile m)
{
if (Timers.TryGetValue(m, out var t))
{
t.Start();
}
}
public static bool IsDisguised(Mobile m) => Timers.ContainsKey(m);
public static void StopTimer(Mobile m)
{
if (!Timers.TryGetValue(m, out var t))
{
return;
}
t.Delay = Utility.Max(t.Next - Core.Now, TimeSpan.Zero);
t.Stop();
}
public static void RemoveTimer(Mobile m)
{
if (Timers.Remove(m, out var t))
{
t.Stop();
}
}
public static TimeSpan TimeRemaining(Mobile m) =>
Timers.TryGetValue(m, out var t) ? t.Next - Core.Now : TimeSpan.Zero;
private class InternalTimer : Timer
{
private readonly Mobile _player;
public InternalTimer(Mobile m, TimeSpan delay) : base(delay) => _player = m;
protected override void OnTick()
{
_player.NameMod = null;
if (_player is PlayerMobile mobile)
{
mobile.SetHairMods(-1, -1);
}
RemoveTimer(_player);
}
}
}
[ManualDirtyChecking]
[TypeAlias("Server.Items.DisguisePersistance")]
[Obsolete("Deprecated in favor of the static system. Only used for legacy deserialization")]
public class DisguisePersistenceTimers : Item
{
public DisguisePersistenceTimers() : base(1)
{
Movable = false;
}
public DisguisePersistenceTimers(Serial serial) : base(serial)
{
}
public override string DefaultName => "Disguise Persistence - Internal";
public override void Serialize(IGenericWriter writer)
{
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
var count = reader.ReadInt();
for (var i = 0; i < count; ++i)
{
var m = reader.ReadEntity<Mobile>();
DisguisePersistence.CreateTimer(m, reader.ReadTimeSpan());
m.NameMod = reader.ReadString();
}
Timer.DelayCall(Delete);
}
}

View file

@ -1,4 +1,5 @@
using System;
using ModernUO.Serialization;
using Server.Targeting;
namespace Server.Items;
@ -18,7 +19,8 @@ public interface ILockpickable : IPoint2D
}
[Flippable(0x14fc, 0x14fb)]
public class Lockpick : Item
[SerializationGenerator(0, false)]
public partial class Lockpick : Item
{
[Constructible]
public Lockpick(int amount = 1) : base(0x14FC)
@ -27,29 +29,6 @@ public class Lockpick : Item
Amount = amount;
}
public Lockpick(Serial serial) : base(serial)
{
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(1); // version
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
if (version == 0 && Weight == 0.1)
{
Weight = -1;
}
}
public override void OnDoubleClick(Mobile from)
{
from.SendLocalizedMessage(502068); // What do you want to pick?
@ -96,15 +75,15 @@ public class Lockpick : Item
private class InternalTimer : Timer
{
private readonly Mobile m_From;
private readonly ILockpickable m_Item;
private readonly Lockpick m_Lockpick;
private readonly Mobile _from;
private readonly ILockpickable _item;
private readonly Lockpick _lockpick;
public InternalTimer(Mobile from, ILockpickable item, Lockpick lockpick) : base(TimeSpan.FromSeconds(3.0))
{
m_From = from;
m_Item = item;
m_Lockpick = lockpick;
_from = from;
_item = item;
_lockpick = lockpick;
}
protected void BrokeLockPickTest()
@ -112,56 +91,52 @@ public class Lockpick : Item
// When failed, a 25% chance to break the lockpick
if (Utility.Random(4) == 0)
{
var item = (Item)m_Item;
var item = (Item)_item;
// You broke the lockpick.
item.SendLocalizedMessageTo(m_From, 502074);
item.SendLocalizedMessageTo(_from, 502074);
m_From.PlaySound(0x3A4);
m_Lockpick.Consume();
_from.PlaySound(0x3A4);
_lockpick.Consume();
}
}
protected override void OnTick()
{
var item = (Item)m_Item;
var item = (Item)_item;
if (!m_From.InRange(item.GetWorldLocation(), 1))
if (!_from.InRange(item.GetWorldLocation(), 1))
{
return;
}
if (m_Item.LockLevel is ILockpickable.CannotPick or ILockpickable.MagicLock)
if (_item.LockLevel is ILockpickable.CannotPick or ILockpickable.MagicLock)
{
// LockLevel of 0 means that the door can't be picklocked
// LockLevel of -255 means it's magic locked
item.SendLocalizedMessageTo(m_From, 502073); // This lock cannot be picked by normal means
item.SendLocalizedMessageTo(_from, 502073); // This lock cannot be picked by normal means
return;
}
if (m_From.Skills.Lockpicking.Value < m_Item.RequiredSkill)
if (_from.Skills.Lockpicking.Value < _item.RequiredSkill)
{
/*
// Do some training to gain skills
m_From.CheckSkill( SkillName.Lockpicking, 0, m_Item.LockLevel );*/
// The LockLevel is higher thant the LockPicking of the player
item.SendLocalizedMessageTo(m_From, 502072); // You don't see how that lock can be manipulated.
item.SendLocalizedMessageTo(_from, 502072); // You don't see how that lock can be manipulated.
return;
}
if (m_From.CheckTargetSkill(SkillName.Lockpicking, m_Item, m_Item.LockLevel, m_Item.MaxLockLevel))
if (_from.CheckTargetSkill(SkillName.Lockpicking, _item, _item.LockLevel, _item.MaxLockLevel))
{
// Success! Pick the lock!
item.SendLocalizedMessageTo(m_From, 502076); // The lock quickly yields to your skill.
m_From.PlaySound(0x4A);
m_Item.LockPick(m_From);
item.SendLocalizedMessageTo(_from, 502076); // The lock quickly yields to your skill.
_from.PlaySound(0x4A);
_item.LockPick(_from);
}
else
{
// The player failed to pick the lock
BrokeLockPickTest();
item.SendLocalizedMessageTo(m_From, 502075); // You are unable to pick the lock.
item.SendLocalizedMessageTo(_from, 502075); // You are unable to pick the lock.
}
}
}