Greetings all! I have implemented the original NpcGuilds on my RunUO shard, and expanded on them a bit. Previously, joining and quitting the guild was activated via OnSpeech; speaking the name of the Npc Guildmaster followed by "join" or "quit." This worked well, but was a bit tedious. I recently added some new clilocs to enable the use of context menus for this purpose, though I also left in the code for OnSpeech. The code I added for Context Menus works, though I am not sure if the way I did it is the best or most efficient way, or if it might lead to issues of which I am not aware. I would be grateful if someone could maybe take a look at it. The code below is what I added. I have included the full Guildmaster.cs script as well. Thanks in advance for any help!
Code:
public override void AddCustomContextEntries( Mobile from, List<ContextMenuEntry> list )
{
PlayerMobile pm = from as PlayerMobile;
if ( pm != null )
{
if ( pm.NpcGuild == NpcGuild.None )
list.Add( new JoinGuildEntry( this, from ) );
if ( pm.NpcGuild == this.NpcGuild )
list.Add( new ResignGuildEntry( this, from ) );
}
base.AddCustomContextEntries( from, list );
}
private class JoinGuildEntry : ContextMenuEntry
{
private BaseGuildmaster m_Mobile;
private Mobile m_From;
public JoinGuildEntry( BaseGuildmaster m, Mobile from ) : base( 6084, 3 )
{
m_Mobile = m;
m_From = from;
}
public override void OnClick()
{
if( !( m_From is PlayerMobile ) )
return;
PlayerMobile mobile = (PlayerMobile) m_From;
BaseGuildmaster reg = ( BaseGuildmaster ) m_Mobile;
if ( mobile != null )
{
if ( mobile.NpcGuild == reg.NpcGuild )
reg.SayTo( mobile, 501047 ); // Thou art already a member of our guild.
else if ( mobile.NpcGuild != NpcGuild.None )
reg.SayTo( mobile, 501046 ); // Thou must resign from thy other guild first.
else if ( reg.CheckCustomReqs( mobile ) )
reg.SayPriceTo( mobile );
}
}
}
private class ResignGuildEntry : ContextMenuEntry
{
private BaseGuildmaster m_Mobile;
private Mobile m_From;
public ResignGuildEntry( BaseGuildmaster m, Mobile from ) : base( 6085, 3 )
{
m_Mobile = m;
m_From = from;
}
public override void OnClick()
{
PlayerMobile mobile = (PlayerMobile) m_From;
BaseGuildmaster reg = ( BaseGuildmaster ) m_Mobile;
if ( mobile != null )
{
if ( mobile.NpcGuild != reg.NpcGuild )
{
reg.SayTo( mobile, 501052 ); // Thou dost not belong to my guild!
}
else if ( (mobile.NpcGuildJoinTime + reg.QuitAge) > DateTime.Now ) // || (pm.NpcGuildGameTime + QuitGameAge) > pm.GameTime )
{
reg.SayTo( mobile, "You just joined my guild! You must wait a week to resign." ); // You just joined my guild! You must wait a week to resign.
}
else
{
reg.SayTo( mobile, 501054 ); // I accept thy resignation.
mobile.NpcGuild = NpcGuild.None;
mobile.GuildTitle = null;
}
}
}
}