Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Migrates Guild properties to PlayerMobile #2139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Projects/Server/Mobiles/Mobile.Migrations.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Server.Guilds;

namespace Server;

Expand Down Expand Up @@ -39,4 +40,26 @@ public static void AddToVirtueMigration(Mobile m, int[] values)
VirtueMigrations[m] = values;
}
}

public static List<GuildInfo> GuildMigrations { get; private set; }

public static void AddToGuildMigration(GuildInfo info)
{
if (info != null)
{
GuildMigrations ??= [];
GuildMigrations.Add(info);
}
}

public class GuildInfo
{
public Mobile GuildMember { get; }
public Mobile GuildFealty { get; internal set; }
public string GuildTitle { get; internal set; }
public bool DisplayGuildTitle { get; internal set; }
public BaseGuild Guild { get; internal set; }

public GuildInfo(Mobile member) => GuildMember = member;
}
}
192 changes: 29 additions & 163 deletions Projects/Server/Mobiles/Mobile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,6 @@ public partial class Mobile : IHued, IComparable<Mobile>, ISpawnable, IObjectPro

private static readonly Queue<Mobile> m_DeltaQueue = new();

private static readonly string[] m_GuildTypes =
{
"",
" (Chaos)",
" (Order)"
};

private static bool _disableCastParalyze = true;

public static void Configure()
Expand All @@ -267,7 +260,6 @@ public static void Configure()

private MobileDelta m_DeltaFlags;
private Direction m_Direction;
private bool m_DisplayGuildTitle;

private TimerExecutionToken _expireAggrTimerToken;
private TimerExecutionToken _expireCombatantTimerToken;
Expand All @@ -280,8 +272,6 @@ public static void Configure()
private int m_Followers, m_FollowersMax;
private bool m_Frozen;
private TimerExecutionToken _frozenTimerToken;
private BaseGuild m_Guild;
private string m_GuildTitle;

private VirtualHairInfo _hair;
public VirtualHairInfo Hair => _hair ??= new VirtualHairInfo(HairItemID, HairHue);
Expand Down Expand Up @@ -1340,44 +1330,6 @@ public string Language
[CommandProperty(AccessLevel.GameMaster)]
public int YellHue { get; set; }

[CommandProperty(AccessLevel.GameMaster)]
public string GuildTitle
{
get => m_GuildTitle;
set
{
var old = m_GuildTitle;

if (old != value)
{
m_GuildTitle = value;

if (m_Guild?.Disbanded == false && m_GuildTitle != null)
{
SendLocalizedMessage(1018026, true, m_GuildTitle); // Your guild title has changed :
}

InvalidateProperties();

OnGuildTitleChange(old);
}
}
}

[CommandProperty(AccessLevel.GameMaster)]
public bool DisplayGuildTitle
{
get => m_DisplayGuildTitle;
set
{
m_DisplayGuildTitle = value;
InvalidateProperties();
}
}

[CommandProperty(AccessLevel.GameMaster)]
public Mobile GuildFealty { get; set; }

[CommandProperty(AccessLevel.GameMaster)]
public string NameMod
{
Expand Down Expand Up @@ -1463,30 +1415,6 @@ public DateTime LastStatGain
}
}

public BaseGuild Guild
{
get => m_Guild;
set
{
var old = m_Guild;

if (old != value)
{
if (value == null)
{
GuildTitle = null;
}

m_Guild = value;

Delta(MobileDelta.Noto);
InvalidateProperties();

OnGuildChange(old);
}
}
}

public Region WalkRegion { get; set; }

[CommandProperty(AccessLevel.GameMaster)]
Expand Down Expand Up @@ -1704,8 +1632,6 @@ public IMount Mount

public static bool AsciiClickMessage { get; set; } = true;

public static bool GuildClickMessage { get; set; } = true;

public static bool OldPropertyTitles { get; set; }

public virtual bool ShowFameTitle // (m_Player || m_Body.IsHuman) && m_Fame >= 10000; }
Expand Down Expand Up @@ -2283,7 +2209,7 @@ public virtual void GetProperties(IPropertyList list)

public virtual void Serialize(IGenericWriter writer)
{
writer.Write(36); // version
writer.Write(37); // version

writer.WriteDeltaTime(LastStrGain);
writer.WriteDeltaTime(LastIntGain);
Expand Down Expand Up @@ -2330,12 +2256,6 @@ public virtual void Serialize(IGenericWriter writer)

writer.Write(MagicDamageAbsorb);

writer.Write(GuildFealty);

writer.Write(m_Guild);

writer.Write(m_DisplayGuildTitle);

writer.Write(CanSwim);

writer.Write(Squelched);
Expand All @@ -2358,7 +2278,6 @@ public virtual void Serialize(IGenericWriter writer)
writer.Write(m_Location);
writer.Write(m_Body);
writer.Write(m_Name);
writer.Write(m_GuildTitle);
writer.Write(m_Criminal);
writer.Write(m_Kills);
writer.Write(SpeechHue);
Expand Down Expand Up @@ -2438,8 +2357,6 @@ public virtual void Delete()

SendRemovePacket();

m_Guild?.OnDelete(this);

Deleted = true;

m_Map?.OnLeave(this);
Expand Down Expand Up @@ -3282,42 +3199,11 @@ public virtual void AddNameProperties(IPropertyList list)
prefix = " ";
}

var guild = m_Guild;
var hasTitle = PropertyTitle && !string.IsNullOrEmpty(Title);
var hasGuild = guild != null && (m_Player || m_DisplayGuildTitle);

string suffix = hasTitle switch
{
true when hasGuild => $" {Title} [{guild.Abbreviation.FixHtmlFormattable()}]",
true => $" {Title}",
false when hasGuild => $" [{guild.Abbreviation.FixHtmlFormattable()}]",
_ => " "
};
string suffix = hasTitle ? $"{Title}" : "";

list.Add(1050045, $"{prefix}\t{Name ?? " "}\t{ApplyNameSuffix(suffix)}"); // ~1_PREFIX~~2_NAME~~3_SUFFIX~

if (guild != null && (m_DisplayGuildTitle || m_Player && guild.Type != GuildType.Regular))
{
var type = guild.Type >= 0 && (int)guild.Type < m_GuildTypes.Length ? m_GuildTypes[(int)guild.Type] : "";

var guildTitle = GuildTitle?.Trim() ?? "";

if (guildTitle.Length > 0)
{
if (NewGuildDisplay)
{
list.Add($"{guildTitle.FixHtmlFormattable()}, {guild.Name.FixHtmlFormattable()}");
}
else
{
list.Add($"{guildTitle.FixHtmlFormattable()}, {guild.Name.FixHtmlFormattable()} Guild{type}");
}
}
else
{
list.Add(guild.Name.FixHtml());
}
}
list.Add(1050045, $"{prefix}\t{Name ?? " "}\t{ApplyNameSuffix(suffix).DefaultIfNullOrEmpty(" ")}"); // ~1_PREFIX~~2_NAME~~3_SUFFIX~
}

public virtual void GetChildProperties(IPropertyList list, Item item)
Expand Down Expand Up @@ -6088,8 +5974,11 @@ public virtual void Deserialize(IGenericReader reader)
{
var version = reader.ReadInt();

GuildInfo guildInfo = version <= 36 ? new GuildInfo(this) : null;

switch (version)
{
case 37: // Moved guild to PlayerMobile
case 36: // Moved virtues to VirtueSystem
case 35: // Moved short term murders to PlayerMurderSystem
case 34: // Moved Stabled to PlayerMobile
Expand Down Expand Up @@ -6244,19 +6133,28 @@ public virtual void Deserialize(IGenericReader reader)
}
case 13:
{
GuildFealty = reader.ReadEntity<Mobile>();
if (guildInfo != null)
{
guildInfo.GuildFealty = reader.ReadEntity<Mobile>();
}

goto case 12;
}
case 12:
{
m_Guild = reader.ReadEntity<BaseGuild>();
if (guildInfo != null)
{
guildInfo.Guild = reader.ReadEntity<BaseGuild>();
}

goto case 11;
}
case 11:
{
m_DisplayGuildTitle = reader.ReadBool();
if (guildInfo != null)
{
guildInfo.DisplayGuildTitle = reader.ReadBool();
}

goto case 10;
}
Expand Down Expand Up @@ -6326,11 +6224,6 @@ public virtual void Deserialize(IGenericReader reader)
}
case 0:
{
if (version < 11)
{
m_DisplayGuildTitle = true;
}

if (version < 3)
{
m_StatCap = 225;
Expand All @@ -6345,7 +6238,12 @@ public virtual void Deserialize(IGenericReader reader)
m_Location = reader.ReadPoint3D();
m_Body = new Body(reader.ReadInt());
m_Name = reader.ReadString();
m_GuildTitle = reader.ReadString();

if (guildInfo != null)
{
guildInfo.GuildTitle = reader.ReadString();
}

m_Criminal = reader.ReadBool();
m_Kills = reader.ReadInt();
SpeechHue = reader.ReadInt();
Expand Down Expand Up @@ -6445,6 +6343,11 @@ public virtual void Deserialize(IGenericReader reader)

Utility.Intern(ref m_Title);
Utility.Intern(ref m_Language);

if (guildInfo != null)
{
AddToGuildMigration(guildInfo);
}
}

public void ConvertHair()
Expand Down Expand Up @@ -7152,18 +7055,10 @@ public virtual bool CanSee(Mobile m)
public virtual bool CanBeRenamedBy(Mobile from) =>
from.AccessLevel >= AccessLevel.GameMaster && from.m_AccessLevel > m_AccessLevel;

public virtual void OnGuildTitleChange(string oldTitle)
{
}

public virtual void OnAfterNameChange(string oldName, string newName)
{
}

public virtual void OnGuildChange(BaseGuild oldGuild)
{
}

public virtual int SafeBody(int body)
{
var delta = -1;
Expand Down Expand Up @@ -7869,35 +7764,6 @@ public virtual void OnSingleClick(Mobile from)
return;
}

if (GuildClickMessage)
{
var guild = m_Guild;

if (guild != null && (m_DisplayGuildTitle || m_Player && guild.Type != GuildType.Regular))
{
var title = GuildTitle?.Trim() ?? "";
string type;

if (guild.Type >= 0 && (int)guild.Type < m_GuildTypes.Length)
{
type = m_GuildTypes[(int)guild.Type];
}
else
{
type = "";
}

var text = string.Format(
title.Length <= 0 ? "[{1}]{2}" : "[{0}, {1}]{2}",
title,
guild.Abbreviation,
type
);

PrivateOverheadMessage(MessageType.Regular, SpeechHue, true, text, from.NetState);
}
}

int hue;

if (NameHue != -1)
Expand Down
3 changes: 2 additions & 1 deletion Projects/UOContent/Configuration/ExpansionConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Server.Mobiles;
using Server.Network;

namespace Server
Expand All @@ -10,7 +11,7 @@ public static void Configure()
ObjectPropertyList.Enabled = ServerConfiguration.GetSetting("opl.enable", Core.AOS);
var visibleDamage = ServerConfiguration.GetSetting("visibleDamage", Core.AOS);
Mobile.VisibleDamageType = visibleDamage ? VisibleDamageType.Related : VisibleDamageType.None;
Mobile.GuildClickMessage = ServerConfiguration.GetSetting("guildClickMessage", !Core.AOS);
PlayerMobile.GuildClickMessage = ServerConfiguration.GetSetting("guildClickMessage", !Core.AOS);
Mobile.AsciiClickMessage = ServerConfiguration.GetSetting("asciiClickMessage", !Core.AOS);

Mobile.ActionDelay = ServerConfiguration.GetSetting("actionDelay", Core.AOS ? 1000 : 500);
Expand Down
Loading
Loading