Fixes code according to modern code style. Fixes a few expression bugs.
This commit is contained in:
parent
89eea25e5f
commit
970fd563b2
3324 changed files with 441118 additions and 433755 deletions
|
|
@ -1,143 +1,145 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Server.Commands;
|
||||
using Server.Gumps;
|
||||
using Server.Mobiles;
|
||||
using Server.Targeting;
|
||||
using Server.Gumps;
|
||||
using Server.Commands;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Server.Engines.Help
|
||||
{
|
||||
public class SpeechLog : IEnumerable<SpeechLogEntry>
|
||||
{
|
||||
// Are speech logs enabled?
|
||||
public static readonly bool Enabled = true;
|
||||
public class SpeechLog : IEnumerable<SpeechLogEntry>
|
||||
{
|
||||
// Are speech logs enabled?
|
||||
public static readonly bool Enabled = true;
|
||||
|
||||
// How long should we maintain each speech entry?
|
||||
public static readonly TimeSpan EntryDuration = TimeSpan.FromMinutes( 20.0 );
|
||||
// How long should we maintain each speech entry?
|
||||
public static readonly TimeSpan EntryDuration = TimeSpan.FromMinutes(20.0);
|
||||
|
||||
// What is the maximum number of entries a log can contain? (0 -> no limit)
|
||||
public static readonly int MaxLength = 0;
|
||||
// What is the maximum number of entries a log can contain? (0 -> no limit)
|
||||
public static readonly int MaxLength = 0;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register( "SpeechLog", AccessLevel.Counselor, SpeechLog_OnCommand );
|
||||
}
|
||||
private Queue<SpeechLogEntry> m_Queue;
|
||||
|
||||
[Usage( "SpeechLog" )]
|
||||
[Description( "Opens the speech log of a given target." )]
|
||||
private static void SpeechLog_OnCommand( CommandEventArgs e )
|
||||
{
|
||||
Mobile from = e.Mobile;
|
||||
public SpeechLog()
|
||||
{
|
||||
m_Queue = new Queue<SpeechLogEntry>();
|
||||
}
|
||||
|
||||
from.SendMessage( "Target a player to view his speech log." );
|
||||
e.Mobile.Target = new SpeechLogTarget();
|
||||
}
|
||||
public int Count => m_Queue.Count;
|
||||
|
||||
private class SpeechLogTarget : Target
|
||||
{
|
||||
public SpeechLogTarget() : base( -1, false, TargetFlags.None )
|
||||
{
|
||||
}
|
||||
#region IEnumerable<SpeechLogEntry> Members
|
||||
|
||||
protected override void OnTarget( Mobile from, object targeted )
|
||||
{
|
||||
if ( !(targeted is PlayerMobile pm) )
|
||||
{
|
||||
from.SendMessage( "Speech logs aren't supported on that target." );
|
||||
}
|
||||
else if ( from != targeted && from.AccessLevel <= pm.AccessLevel && from.AccessLevel != AccessLevel.Owner )
|
||||
{
|
||||
from.SendMessage( "You don't have the required access level to view {0} speech log.", pm.Female ? "her" : "his" );
|
||||
}
|
||||
else if ( pm.SpeechLog == null )
|
||||
{
|
||||
from.SendMessage( "{0} has no speech log.", pm.Female ? "She" : "He" );
|
||||
}
|
||||
else
|
||||
{
|
||||
CommandLogging.WriteLine( from, "{0} {1} viewing speech log of {2}", from.AccessLevel, CommandLogging.Format( from ), CommandLogging.Format( targeted ) );
|
||||
IEnumerator<SpeechLogEntry> IEnumerable<SpeechLogEntry>.GetEnumerator()
|
||||
{
|
||||
return m_Queue.GetEnumerator();
|
||||
}
|
||||
|
||||
Gump gump = new SpeechLogGump( pm, pm.SpeechLog );
|
||||
from.SendGump( gump );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private Queue<SpeechLogEntry> m_Queue;
|
||||
#region IEnumerable Members
|
||||
|
||||
public int Count => m_Queue.Count;
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return m_Queue.GetEnumerator();
|
||||
}
|
||||
|
||||
public SpeechLog()
|
||||
{
|
||||
m_Queue = new Queue<SpeechLogEntry>();
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Add( Mobile from, string speech )
|
||||
{
|
||||
Add( new SpeechLogEntry( from, speech ) );
|
||||
}
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register("SpeechLog", AccessLevel.Counselor, SpeechLog_OnCommand);
|
||||
}
|
||||
|
||||
public void Add( SpeechLogEntry entry )
|
||||
{
|
||||
if ( MaxLength > 0 && m_Queue.Count >= MaxLength )
|
||||
m_Queue.Dequeue();
|
||||
[Usage("SpeechLog")]
|
||||
[Description("Opens the speech log of a given target.")]
|
||||
private static void SpeechLog_OnCommand(CommandEventArgs e)
|
||||
{
|
||||
Mobile from = e.Mobile;
|
||||
|
||||
Clean();
|
||||
from.SendMessage("Target a player to view his speech log.");
|
||||
e.Mobile.Target = new SpeechLogTarget();
|
||||
}
|
||||
|
||||
m_Queue.Enqueue( entry );
|
||||
}
|
||||
public void Add(Mobile from, string speech)
|
||||
{
|
||||
Add(new SpeechLogEntry(from, speech));
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
{
|
||||
while ( m_Queue.Count > 0 )
|
||||
{
|
||||
SpeechLogEntry entry = (SpeechLogEntry) m_Queue.Peek();
|
||||
public void Add(SpeechLogEntry entry)
|
||||
{
|
||||
if (MaxLength > 0 && m_Queue.Count >= MaxLength)
|
||||
m_Queue.Dequeue();
|
||||
|
||||
if ( DateTime.UtcNow - entry.Created > EntryDuration )
|
||||
m_Queue.Dequeue();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
Clean();
|
||||
|
||||
public void CopyTo( SpeechLogEntry[] array, int index )
|
||||
{
|
||||
m_Queue.CopyTo( array, index );
|
||||
}
|
||||
m_Queue.Enqueue(entry);
|
||||
}
|
||||
|
||||
#region IEnumerable<SpeechLogEntry> Members
|
||||
public void Clean()
|
||||
{
|
||||
while (m_Queue.Count > 0)
|
||||
{
|
||||
SpeechLogEntry entry = m_Queue.Peek();
|
||||
|
||||
IEnumerator<SpeechLogEntry> IEnumerable<SpeechLogEntry>.GetEnumerator()
|
||||
{
|
||||
return m_Queue.GetEnumerator();
|
||||
}
|
||||
if (DateTime.UtcNow - entry.Created > EntryDuration)
|
||||
m_Queue.Dequeue();
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
public void CopyTo(SpeechLogEntry[] array, int index)
|
||||
{
|
||||
m_Queue.CopyTo(array, index);
|
||||
}
|
||||
|
||||
#region IEnumerable Members
|
||||
private class SpeechLogTarget : Target
|
||||
{
|
||||
public SpeechLogTarget() : base(-1, false, TargetFlags.None)
|
||||
{
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return m_Queue.GetEnumerator();
|
||||
}
|
||||
protected override void OnTarget(Mobile from, object targeted)
|
||||
{
|
||||
if (!(targeted is PlayerMobile pm))
|
||||
{
|
||||
from.SendMessage("Speech logs aren't supported on that target.");
|
||||
}
|
||||
else if (from != targeted && from.AccessLevel <= pm.AccessLevel && from.AccessLevel != AccessLevel.Owner)
|
||||
{
|
||||
from.SendMessage("You don't have the required access level to view {0} speech log.",
|
||||
pm.Female ? "her" : "his");
|
||||
}
|
||||
else if (pm.SpeechLog == null)
|
||||
{
|
||||
from.SendMessage("{0} has no speech log.", pm.Female ? "She" : "He");
|
||||
}
|
||||
else
|
||||
{
|
||||
CommandLogging.WriteLine(from, "{0} {1} viewing speech log of {2}", from.AccessLevel,
|
||||
CommandLogging.Format(from), CommandLogging.Format(targeted));
|
||||
|
||||
#endregion
|
||||
}
|
||||
Gump gump = new SpeechLogGump(pm, pm.SpeechLog);
|
||||
from.SendGump(gump);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SpeechLogEntry
|
||||
{
|
||||
public Mobile From { get; }
|
||||
public class SpeechLogEntry
|
||||
{
|
||||
public SpeechLogEntry(Mobile from, string speech)
|
||||
{
|
||||
From = from;
|
||||
Speech = speech;
|
||||
Created = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
public string Speech { get; }
|
||||
public Mobile From{ get; }
|
||||
|
||||
public DateTime Created { get; }
|
||||
public string Speech{ get; }
|
||||
|
||||
public SpeechLogEntry( Mobile from, string speech )
|
||||
{
|
||||
From = from;
|
||||
Speech = speech;
|
||||
Created = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
}
|
||||
public DateTime Created{ get; }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue