Fixes code according to modern code style. Fixes a few expression bugs.

This commit is contained in:
Kamron Batman 2018-09-15 09:58:51 -07:00
parent 89eea25e5f
commit 970fd563b2
3324 changed files with 441118 additions and 433755 deletions

View file

@ -1,283 +1,282 @@
using System;
using System.Collections;
using Server.Gumps;
using Server.Network;
using Server.Mobiles;
using Server.Network;
namespace Server.Engines.ConPVP
{
public class AcceptDuelGump : Gump
{
private Mobile m_Challenger, m_Challenged;
private DuelContext m_Context;
private Participant m_Participant;
private int m_Slot;
public class AcceptDuelGump : Gump
{
private const int LabelColor32 = 0xFFFFFF;
private const int BlackColor32 = 0x000008;
public string Center( string text )
{
return $"<CENTER>{text}</CENTER>";
}
private static Hashtable m_IgnoreLists = new Hashtable();
public string Color( string text, int color )
{
return $"<BASEFONT COLOR=#{color:X6}>{text}</BASEFONT>";
}
private bool m_Active = true;
private Mobile m_Challenger, m_Challenged;
private DuelContext m_Context;
private Participant m_Participant;
private int m_Slot;
private const int LabelColor32 = 0xFFFFFF;
private const int BlackColor32 = 0x000008;
public AcceptDuelGump(Mobile challenger, Mobile challenged, DuelContext context, Participant p, int slot) : base(50,
50)
{
m_Challenger = challenger;
m_Challenged = challenged;
m_Context = context;
m_Participant = p;
m_Slot = slot;
private bool m_Active = true;
challenged.CloseGump(typeof(AcceptDuelGump));
public AcceptDuelGump( Mobile challenger, Mobile challenged, DuelContext context, Participant p, int slot ) : base( 50, 50 )
{
m_Challenger = challenger;
m_Challenged = challenged;
m_Context = context;
m_Participant = p;
m_Slot = slot;
Closable = false;
challenged.CloseGump( typeof( AcceptDuelGump ) );
AddPage(0);
Closable = false;
//AddBackground( 0, 0, 400, 220, 9150 );
AddBackground(1, 1, 398, 218, 3600);
//AddBackground( 16, 15, 369, 189, 9100 );
AddPage( 0 );
AddImageTiled(16, 15, 369, 189, 3604);
AddAlphaRegion(16, 15, 369, 189);
//AddBackground( 0, 0, 400, 220, 9150 );
AddBackground( 1, 1, 398, 218, 3600 );
//AddBackground( 16, 15, 369, 189, 9100 );
AddImage(215, -43, 0xEE40);
//AddImage( 330, 141, 0x8BA );
AddImageTiled( 16, 15, 369, 189, 3604 );
AddAlphaRegion( 16, 15, 369, 189 );
AddHtml(22 - 1, 22, 294, 20, Color(Center("Duel Challenge"), BlackColor32), false, false);
AddHtml(22 + 1, 22, 294, 20, Color(Center("Duel Challenge"), BlackColor32), false, false);
AddHtml(22, 22 - 1, 294, 20, Color(Center("Duel Challenge"), BlackColor32), false, false);
AddHtml(22, 22 + 1, 294, 20, Color(Center("Duel Challenge"), BlackColor32), false, false);
AddHtml(22, 22, 294, 20, Color(Center("Duel Challenge"), LabelColor32), false, false);
AddImage( 215, -43, 0xEE40 );
//AddImage( 330, 141, 0x8BA );
string fmt;
AddHtml( 22-1, 22, 294, 20, Color( Center( "Duel Challenge" ), BlackColor32 ), false, false );
AddHtml( 22+1, 22, 294, 20, Color( Center( "Duel Challenge" ), BlackColor32 ), false, false );
AddHtml( 22, 22-1, 294, 20, Color( Center( "Duel Challenge" ), BlackColor32 ), false, false );
AddHtml( 22, 22+1, 294, 20, Color( Center( "Duel Challenge" ), BlackColor32 ), false, false );
AddHtml( 22, 22, 294, 20, Color( Center( "Duel Challenge" ), LabelColor32 ), false, false );
if (p.Contains(challenger))
fmt = "You have been asked to join sides with {0} in a duel. Do you accept?";
else
fmt = "You have been challenged to a duel from {0}. Do you accept?";
string fmt;
AddHtml(22 - 1, 50, 294, 40, Color(string.Format(fmt, challenger.Name), BlackColor32), false, false);
AddHtml(22 + 1, 50, 294, 40, Color(string.Format(fmt, challenger.Name), BlackColor32), false, false);
AddHtml(22, 50 - 1, 294, 40, Color(string.Format(fmt, challenger.Name), BlackColor32), false, false);
AddHtml(22, 50 + 1, 294, 40, Color(string.Format(fmt, challenger.Name), BlackColor32), false, false);
AddHtml(22, 50, 294, 40, Color(string.Format(fmt, challenger.Name), 0xB0C868), false, false);
if ( p.Contains( challenger ) )
fmt = "You have been asked to join sides with {0} in a duel. Do you accept?";
else
fmt = "You have been challenged to a duel from {0}. Do you accept?";
AddImageTiled(32, 88, 264, 1, 9107);
AddImageTiled(42, 90, 264, 1, 9157);
AddHtml( 22-1, 50, 294, 40, Color( string.Format( fmt, challenger.Name ), BlackColor32 ), false, false );
AddHtml( 22+1, 50, 294, 40, Color( string.Format( fmt, challenger.Name ), BlackColor32 ), false, false );
AddHtml( 22, 50-1, 294, 40, Color( string.Format( fmt, challenger.Name ), BlackColor32 ), false, false );
AddHtml( 22, 50+1, 294, 40, Color( string.Format( fmt, challenger.Name ), BlackColor32 ), false, false );
AddHtml( 22, 50, 294, 40, Color( string.Format( fmt, challenger.Name ), 0xB0C868 ), false, false );
AddRadio(24, 100, 9727, 9730, true, 1);
AddHtml(60 - 1, 105, 250, 20, Color("Yes, I will fight this duel.", BlackColor32), false, false);
AddHtml(60 + 1, 105, 250, 20, Color("Yes, I will fight this duel.", BlackColor32), false, false);
AddHtml(60, 105 - 1, 250, 20, Color("Yes, I will fight this duel.", BlackColor32), false, false);
AddHtml(60, 105 + 1, 250, 20, Color("Yes, I will fight this duel.", BlackColor32), false, false);
AddHtml(60, 105, 250, 20, Color("Yes, I will fight this duel.", LabelColor32), false, false);
AddImageTiled( 32, 88, 264, 1, 9107 );
AddImageTiled( 42, 90, 264, 1, 9157 );
AddRadio(24, 135, 9727, 9730, false, 2);
AddHtml(60 - 1, 140, 250, 20, Color("No, I do not wish to fight.", BlackColor32), false, false);
AddHtml(60 + 1, 140, 250, 20, Color("No, I do not wish to fight.", BlackColor32), false, false);
AddHtml(60, 140 - 1, 250, 20, Color("No, I do not wish to fight.", BlackColor32), false, false);
AddHtml(60, 140 + 1, 250, 20, Color("No, I do not wish to fight.", BlackColor32), false, false);
AddHtml(60, 140, 250, 20, Color("No, I do not wish to fight.", LabelColor32), false, false);
AddRadio( 24, 100, 9727, 9730, true, 1 );
AddHtml( 60-1, 105, 250, 20, Color( "Yes, I will fight this duel.", BlackColor32 ), false, false );
AddHtml( 60+1, 105, 250, 20, Color( "Yes, I will fight this duel.", BlackColor32 ), false, false );
AddHtml( 60, 105-1, 250, 20, Color( "Yes, I will fight this duel.", BlackColor32 ), false, false );
AddHtml( 60, 105+1, 250, 20, Color( "Yes, I will fight this duel.", BlackColor32 ), false, false );
AddHtml( 60, 105, 250, 20, Color( "Yes, I will fight this duel.", LabelColor32 ), false, false );
AddRadio(24, 170, 9727, 9730, false, 3);
AddHtml(60 - 1, 175, 250, 20, Color("No, knave. Do not ask again.", BlackColor32), false, false);
AddHtml(60 + 1, 175, 250, 20, Color("No, knave. Do not ask again.", BlackColor32), false, false);
AddHtml(60, 175 - 1, 250, 20, Color("No, knave. Do not ask again.", BlackColor32), false, false);
AddHtml(60, 175 + 1, 250, 20, Color("No, knave. Do not ask again.", BlackColor32), false, false);
AddHtml(60, 175, 250, 20, Color("No, knave. Do not ask again.", LabelColor32), false, false);
AddRadio( 24, 135, 9727, 9730, false, 2 );
AddHtml( 60-1, 140, 250, 20, Color( "No, I do not wish to fight.", BlackColor32 ), false, false );
AddHtml( 60+1, 140, 250, 20, Color( "No, I do not wish to fight.", BlackColor32 ), false, false );
AddHtml( 60, 140-1, 250, 20, Color( "No, I do not wish to fight.", BlackColor32 ), false, false );
AddHtml( 60, 140+1, 250, 20, Color( "No, I do not wish to fight.", BlackColor32 ), false, false );
AddHtml( 60, 140, 250, 20, Color( "No, I do not wish to fight.", LabelColor32 ), false, false );
AddButton(314, 173, 247, 248, 1, GumpButtonType.Reply, 0);
AddRadio( 24, 170, 9727, 9730, false, 3 );
AddHtml( 60-1, 175, 250, 20, Color( "No, knave. Do not ask again.", BlackColor32 ), false, false );
AddHtml( 60+1, 175, 250, 20, Color( "No, knave. Do not ask again.", BlackColor32 ), false, false );
AddHtml( 60, 175-1, 250, 20, Color( "No, knave. Do not ask again.", BlackColor32 ), false, false );
AddHtml( 60, 175+1, 250, 20, Color( "No, knave. Do not ask again.", BlackColor32 ), false, false );
AddHtml( 60, 175, 250, 20, Color( "No, knave. Do not ask again.", LabelColor32 ), false, false );
Timer.DelayCall(TimeSpan.FromSeconds(15.0), AutoReject);
}
AddButton( 314, 173, 247, 248, 1, GumpButtonType.Reply, 0 );
public string Center(string text)
{
return $"<CENTER>{text}</CENTER>";
}
Timer.DelayCall( TimeSpan.FromSeconds( 15.0 ), AutoReject );
}
public string Color(string text, int color)
{
return $"<BASEFONT COLOR=#{color:X6}>{text}</BASEFONT>";
}
public void AutoReject()
{
if ( !m_Active )
return;
public void AutoReject()
{
if (!m_Active)
return;
m_Active = false;
m_Active = false;
m_Challenged.CloseGump( typeof( AcceptDuelGump ) );
m_Challenged.CloseGump(typeof(AcceptDuelGump));
m_Challenger.SendMessage( "{0} seems unresponsive.", m_Challenged.Name );
m_Challenged.SendMessage( "You decline the challenge." );
}
m_Challenger.SendMessage("{0} seems unresponsive.", m_Challenged.Name);
m_Challenged.SendMessage("You decline the challenge.");
}
private static Hashtable m_IgnoreLists = new Hashtable();
public static void BeginIgnore(Mobile source, Mobile toIgnore)
{
ArrayList list = (ArrayList)m_IgnoreLists[source];
private class IgnoreEntry
{
public Mobile m_Ignored;
public DateTime m_Expire;
if (list == null)
m_IgnoreLists[source] = list = new ArrayList();
public Mobile Ignored => m_Ignored;
public bool Expired => ( DateTime.UtcNow >= m_Expire );
for (int i = 0; i < list.Count; ++i)
{
IgnoreEntry ie = (IgnoreEntry)list[i];
private static TimeSpan ExpireDelay = TimeSpan.FromMinutes( 15.0 );
if (ie.Ignored == toIgnore)
{
ie.Refresh();
return;
}
public void Refresh()
{
m_Expire = DateTime.UtcNow + ExpireDelay;
}
if (ie.Expired) list.RemoveAt(i--);
}
public IgnoreEntry( Mobile ignored )
{
m_Ignored = ignored;
Refresh();
}
}
list.Add(new IgnoreEntry(toIgnore));
}
public static void BeginIgnore( Mobile source, Mobile toIgnore )
{
ArrayList list = (ArrayList)m_IgnoreLists[source];
public static bool IsIgnored(Mobile source, Mobile check)
{
ArrayList list = (ArrayList)m_IgnoreLists[source];
if ( list == null )
m_IgnoreLists[source] = list = new ArrayList();
if (list == null)
return false;
for ( int i = 0; i < list.Count; ++i )
{
IgnoreEntry ie = (IgnoreEntry)list[i];
for (int i = 0; i < list.Count; ++i)
{
IgnoreEntry ie = (IgnoreEntry)list[i];
if ( ie.Ignored == toIgnore )
{
ie.Refresh();
return;
}
if (ie.Expired)
list.RemoveAt(i--);
else if (ie.Ignored == check)
return true;
}
if ( ie.Expired )
{
list.RemoveAt( i-- );
}
}
return false;
}
list.Add( new IgnoreEntry( toIgnore ) );
}
public override void OnResponse(NetState sender, RelayInfo info)
{
if (info.ButtonID != 1 || !m_Active || !m_Context.Registered)
return;
public static bool IsIgnored( Mobile source, Mobile check )
{
ArrayList list = (ArrayList)m_IgnoreLists[source];
m_Active = false;
if ( list == null )
return false;
if (!m_Context.Participants.Contains(m_Participant))
return;
for ( int i = 0; i < list.Count; ++i )
{
IgnoreEntry ie = (IgnoreEntry)list[i];
if (info.IsSwitched(1))
{
if (!(m_Challenged is PlayerMobile pm))
return;
if ( ie.Expired )
list.RemoveAt( i-- );
else if ( ie.Ignored == check )
return true;
}
if (pm.DuelContext != null)
{
if (pm.DuelContext.Initiator == pm)
pm.SendMessage(0x22, "You have already started a duel.");
else
pm.SendMessage(0x22, "You have already been challenged in a duel.");
return false;
}
m_Challenger.SendMessage("{0} cannot fight because they are already assigned to another duel.", pm.Name);
}
else if (DuelContext.CheckCombat(pm))
{
pm.SendMessage(0x22,
"You have recently been in combat with another player and must wait before starting a duel.");
m_Challenger.SendMessage(
"{0} cannot fight because they have recently been in combat with another player.", pm.Name);
}
else if (TournamentController.IsActive)
{
pm.SendMessage(0x22, "A tournament is currently active and you may not duel.");
m_Challenger.SendMessage(0x22, "A tournament is currently active and you may not duel.");
}
else
{
bool added = false;
public override void OnResponse( NetState sender, RelayInfo info )
{
if ( info.ButtonID != 1 || !m_Active || !m_Context.Registered )
return;
if (m_Slot >= 0 && m_Slot < m_Participant.Players.Length && m_Participant.Players[m_Slot] == null)
{
added = true;
m_Participant.Players[m_Slot] = new DuelPlayer(m_Challenged, m_Participant);
}
else
{
for (int i = 0; i < m_Participant.Players.Length; ++i)
if (m_Participant.Players[i] == null)
{
added = true;
m_Participant.Players[i] = new DuelPlayer(m_Challenged, m_Participant);
break;
}
}
m_Active = false;
if (added)
{
m_Challenger.SendMessage("{0} has accepted the request.", m_Challenged.Name);
m_Challenged.SendMessage("You have accepted the request from {0}.", m_Challenger.Name);
if ( !m_Context.Participants.Contains( m_Participant ) )
return;
NetState ns = m_Challenger.NetState;
if ( info.IsSwitched( 1 ) )
{
if ( !(m_Challenged is PlayerMobile pm) )
return;
if (ns != null)
foreach (Gump g in ns.Gumps)
{
if (g is ParticipantGump pg && pg.Participant == m_Participant)
{
m_Challenger.SendGump(new ParticipantGump(m_Challenger, m_Context, m_Participant));
break;
}
if ( pm.DuelContext != null )
{
if ( pm.DuelContext.Initiator == pm )
pm.SendMessage( 0x22, "You have already started a duel." );
else
pm.SendMessage( 0x22, "You have already been challenged in a duel." );
if (g is DuelContextGump dcg && dcg.Context == m_Context)
{
m_Challenger.SendGump(new DuelContextGump(m_Challenger, m_Context));
break;
}
}
}
else
{
m_Challenger.SendMessage("The participant list was full and so {0} could not join.",
m_Challenged.Name);
m_Challenged.SendMessage(
"The participant list was full and so you could not join the fight {1} {0}.", m_Challenger.Name,
m_Participant.Contains(m_Challenger) ? "with" : "against");
}
}
}
else
{
if (info.IsSwitched(3))
BeginIgnore(m_Challenged, m_Challenger);
m_Challenger.SendMessage( "{0} cannot fight because they are already assigned to another duel.", pm.Name );
}
else if ( DuelContext.CheckCombat( pm ) )
{
pm.SendMessage( 0x22, "You have recently been in combat with another player and must wait before starting a duel." );
m_Challenger.SendMessage( "{0} cannot fight because they have recently been in combat with another player.", pm.Name );
}
else if ( TournamentController.IsActive )
{
pm.SendMessage( 0x22, "A tournament is currently active and you may not duel." );
m_Challenger.SendMessage( 0x22, "A tournament is currently active and you may not duel." );
}
else
{
bool added = false;
m_Challenger.SendMessage("{0} does not wish to fight.", m_Challenged.Name);
m_Challenged.SendMessage("You chose not to fight {1} {0}.", m_Challenger.Name,
m_Participant.Contains(m_Challenger) ? "with" : "against");
}
}
if ( m_Slot >= 0 && m_Slot < m_Participant.Players.Length && m_Participant.Players[m_Slot] == null )
{
added = true;
m_Participant.Players[m_Slot] = new DuelPlayer( m_Challenged, m_Participant );
}
else
{
for ( int i = 0; i < m_Participant.Players.Length; ++i )
{
if ( m_Participant.Players[i] == null )
{
added = true;
m_Participant.Players[i] = new DuelPlayer( m_Challenged, m_Participant );
break;
}
}
}
private class IgnoreEntry
{
private static TimeSpan ExpireDelay = TimeSpan.FromMinutes(15.0);
public DateTime m_Expire;
public Mobile m_Ignored;
if ( added )
{
m_Challenger.SendMessage( "{0} has accepted the request.", m_Challenged.Name );
m_Challenged.SendMessage( "You have accepted the request from {0}.", m_Challenger.Name );
public IgnoreEntry(Mobile ignored)
{
m_Ignored = ignored;
Refresh();
}
NetState ns = m_Challenger.NetState;
public Mobile Ignored => m_Ignored;
public bool Expired => DateTime.UtcNow >= m_Expire;
if ( ns != null )
{
foreach ( Gump g in ns.Gumps )
{
if ( g is ParticipantGump pg && pg.Participant == m_Participant )
{
m_Challenger.SendGump( new ParticipantGump( m_Challenger, m_Context, m_Participant ) );
break;
}
if ( g is DuelContextGump dcg && dcg.Context == m_Context )
{
m_Challenger.SendGump( new DuelContextGump( m_Challenger, m_Context ) );
break;
}
}
}
}
else
{
m_Challenger.SendMessage( "The participant list was full and so {0} could not join.", m_Challenged.Name );
m_Challenged.SendMessage( "The participant list was full and so you could not join the fight {1} {0}.", m_Challenger.Name, m_Participant.Contains( m_Challenger ) ? "with" : "against" );
}
}
}
else
{
if ( info.IsSwitched( 3 ) )
BeginIgnore( m_Challenged, m_Challenger );
m_Challenger.SendMessage( "{0} does not wish to fight.", m_Challenged.Name );
m_Challenged.SendMessage( "You chose not to fight {1} {0}.", m_Challenger.Name, m_Participant.Contains( m_Challenger ) ? "with" : "against" );
}
}
}
}
public void Refresh()
{
m_Expire = DateTime.UtcNow + ExpireDelay;
}
}
}
}