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

@ -4,83 +4,81 @@ using Server.Accounting;
namespace Server.Misc
{
public enum GiftResult
{
Backpack,
BankBox
}
public enum GiftResult
{
Backpack,
BankBox
}
public class GiftGiving
{
private static List<GiftGiver> m_Givers = new List<GiftGiver>();
public class GiftGiving
{
private static List<GiftGiver> m_Givers = new List<GiftGiver>();
public static void Register( GiftGiver giver )
{
m_Givers.Add( giver );
}
public static void Register(GiftGiver giver)
{
m_Givers.Add(giver);
}
public static void Initialize()
{
EventSink.Login += EventSink_Login;
}
public static void Initialize()
{
EventSink.Login += EventSink_Login;
}
private static void EventSink_Login( LoginEventArgs e )
{
Account acct = e.Mobile.Account as Account;
private static void EventSink_Login(LoginEventArgs e)
{
Account acct = e.Mobile.Account as Account;
if ( acct == null )
return;
if (acct == null)
return;
DateTime now = DateTime.UtcNow;
DateTime now = DateTime.UtcNow;
for ( int i = 0; i < m_Givers.Count; ++i )
{
GiftGiver giver = m_Givers[i];
for (int i = 0; i < m_Givers.Count; ++i)
{
GiftGiver giver = m_Givers[i];
if ( now < giver.Start || now >= giver.Finish )
continue; // not in the correct timefream
if (now < giver.Start || now >= giver.Finish)
continue; // not in the correct timefream
if ( acct.Created > (giver.Start - giver.MinimumAge) )
continue; // newly created account
if (acct.Created > giver.Start - giver.MinimumAge)
continue; // newly created account
if ( acct.LastLogin >= giver.Start )
continue; // already got one
if (acct.LastLogin >= giver.Start)
continue; // already got one
giver.DelayGiveGift( TimeSpan.FromSeconds( 5.0 ), e.Mobile );
}
giver.DelayGiveGift(TimeSpan.FromSeconds(5.0), e.Mobile);
}
acct.LastLogin = now;
}
}
acct.LastLogin = now;
}
}
public abstract class GiftGiver
{
public virtual TimeSpan MinimumAge => TimeSpan.FromDays( 30.0 );
public abstract class GiftGiver
{
public virtual TimeSpan MinimumAge => TimeSpan.FromDays(30.0);
public abstract DateTime Start{ get; }
public abstract DateTime Finish{ get; }
public abstract void GiveGift( Mobile mob );
public abstract DateTime Start{ get; }
public abstract DateTime Finish{ get; }
public abstract void GiveGift(Mobile mob);
public virtual void DelayGiveGift( TimeSpan delay, Mobile mob )
{
Timer.DelayCall( delay, new TimerStateCallback( DelayGiveGift_Callback ), mob );
}
public virtual void DelayGiveGift(TimeSpan delay, Mobile mob)
{
Timer.DelayCall(delay, new TimerStateCallback(DelayGiveGift_Callback), mob);
}
protected virtual void DelayGiveGift_Callback( object state )
{
GiveGift( (Mobile) state );
}
protected virtual void DelayGiveGift_Callback(object state)
{
GiveGift((Mobile)state);
}
public virtual GiftResult GiveGift( Mobile mob, Item item )
{
if ( mob.PlaceInBackpack( item ) )
{
if ( !WeightOverloading.IsOverloaded( mob ) )
return GiftResult.Backpack;
}
public virtual GiftResult GiveGift(Mobile mob, Item item)
{
if (mob.PlaceInBackpack(item))
if (!WeightOverloading.IsOverloaded(mob))
return GiftResult.Backpack;
mob.BankBox.DropItem( item );
return GiftResult.BankBox;
}
}
mob.BankBox.DropItem(item);
return GiftResult.BankBox;
}
}
}

View file

@ -1,16 +1,16 @@
namespace Server.Misc
{
public static class ItemFixes
{
public static void Initialize()
{
// Missing NoShoot flags
TileData.ItemTable[0x2A0].Flags |= TileFlag.NoShoot;
TileData.ItemTable[0x3E0].Flags |= TileFlag.NoShoot;
TileData.ItemTable[0x3E1].Flags |= TileFlag.NoShoot;
public static class ItemFixes
{
public static void Initialize()
{
// Missing NoShoot flags
TileData.ItemTable[0x2A0].Flags |= TileFlag.NoShoot;
TileData.ItemTable[0x3E0].Flags |= TileFlag.NoShoot;
TileData.ItemTable[0x3E1].Flags |= TileFlag.NoShoot;
// Incorrect height
TileData.ItemTable[0x34D2].Height = 0;
}
}
}
// Incorrect height
TileData.ItemTable[0x34D2].Height = 0;
}
}
}

View file

@ -2,87 +2,89 @@ using System.Collections.Generic;
namespace Server.Misc
{
/*
* This system prevents the inability for server staff to
* access their server due to data overflows during login.
*
* Whenever a staff character's NetState is disposed right after
* the login process, the character is moved to and logged out
* at a "safe" alternative.
*
* The location the character was moved from will be reported
* to the player upon the next successful login.
*
* This system does not affect non-staff players.
*/
public static class PreventInaccess
{
public static readonly bool Enabled = true;
/*
* This system prevents the inability for server staff to
* access their server due to data overflows during login.
*
* Whenever a staff character's NetState is disposed right after
* the login process, the character is moved to and logged out
* at a "safe" alternative.
*
* The location the character was moved from will be reported
* to the player upon the next successful login.
*
* This system does not affect non-staff players.
*/
public static class PreventInaccess
{
public static readonly bool Enabled = true;
private static readonly LocationInfo[] m_Destinations = {
new LocationInfo( new Point3D( 5275, 1163, 0 ), Map.Felucca ), // Jail
new LocationInfo( new Point3D( 5275, 1163, 0 ), Map.Trammel ),
new LocationInfo( new Point3D( 5445, 1153, 0 ), Map.Felucca ), // Green acres
new LocationInfo( new Point3D( 5445, 1153, 0 ), Map.Trammel )
};
private static readonly LocationInfo[] m_Destinations =
{
new LocationInfo(new Point3D(5275, 1163, 0), Map.Felucca), // Jail
new LocationInfo(new Point3D(5275, 1163, 0), Map.Trammel),
new LocationInfo(new Point3D(5445, 1153, 0), Map.Felucca), // Green acres
new LocationInfo(new Point3D(5445, 1153, 0), Map.Trammel)
};
private static Dictionary<Mobile, LocationInfo> m_MoveHistory;
private static Dictionary<Mobile, LocationInfo> m_MoveHistory;
public static void Initialize()
{
m_MoveHistory = new Dictionary<Mobile, LocationInfo>();
public static void Initialize()
{
m_MoveHistory = new Dictionary<Mobile, LocationInfo>();
if ( Enabled )
EventSink.Login += OnLogin;
}
if (Enabled)
EventSink.Login += OnLogin;
}
public static void OnLogin( LoginEventArgs e )
{
Mobile from = e.Mobile;
public static void OnLogin(LoginEventArgs e)
{
Mobile from = e.Mobile;
if ( from == null || from.AccessLevel < AccessLevel.Counselor )
return;
if (from == null || from.AccessLevel < AccessLevel.Counselor)
return;
if ( HasDisconnected( from ) )
{
if ( !m_MoveHistory.ContainsKey( from ) )
m_MoveHistory[from] = new LocationInfo( from.Location, from.Map );
if (HasDisconnected(from))
{
if (!m_MoveHistory.ContainsKey(from))
m_MoveHistory[from] = new LocationInfo(from.Location, from.Map);
LocationInfo dest = GetRandomDestination();
LocationInfo dest = GetRandomDestination();
from.Location = dest.Location;
from.Map = dest.Map;
}
else if ( m_MoveHistory.ContainsKey( from ) )
{
LocationInfo orig = m_MoveHistory[from];
from.SendMessage( "Your character was moved from {0} ({1}) due to a detected client crash.", orig.Location, orig.Map );
from.Location = dest.Location;
from.Map = dest.Map;
}
else if (m_MoveHistory.ContainsKey(from))
{
LocationInfo orig = m_MoveHistory[from];
from.SendMessage("Your character was moved from {0} ({1}) due to a detected client crash.", orig.Location,
orig.Map);
m_MoveHistory.Remove( from );
}
}
m_MoveHistory.Remove(from);
}
}
private static bool HasDisconnected( Mobile m )
{
return ( m.NetState?.Socket == null );
}
private static bool HasDisconnected(Mobile m)
{
return m.NetState?.Socket == null;
}
private static LocationInfo GetRandomDestination()
{
return m_Destinations[Utility.Random( m_Destinations.Length )];
}
private static LocationInfo GetRandomDestination()
{
return m_Destinations[Utility.Random(m_Destinations.Length)];
}
private class LocationInfo
{
public Point3D Location { get; }
private class LocationInfo
{
public LocationInfo(Point3D loc, Map map)
{
Location = loc;
Map = map;
}
public Map Map { get; }
public Point3D Location{ get; }
public LocationInfo( Point3D loc, Map map )
{
Location = loc;
Map = map;
}
}
}
}
public Map Map{ get; }
}
}
}

View file

@ -1,236 +1,233 @@
using System;
using System.Text;
using Server.Commands;
using Server.Gumps;
using Server.Network;
using Server.Commands;
namespace Server.Misc
{
public class TestCenter
{
private const bool m_Enabled = false;
public static bool Enabled => m_Enabled;
public class TestCenter
{
private const bool m_Enabled = false;
public static bool Enabled => m_Enabled;
public static void Initialize()
{
// Register our speech handler
if ( Enabled )
EventSink.Speech += EventSink_Speech;
}
public static void Initialize()
{
// Register our speech handler
if (Enabled)
EventSink.Speech += EventSink_Speech;
}
private static void EventSink_Speech( SpeechEventArgs args )
{
if ( !args.Handled )
{
if ( Insensitive.StartsWith( args.Speech, "set" ) )
{
Mobile from = args.Mobile;
private static void EventSink_Speech(SpeechEventArgs args)
{
if (!args.Handled)
{
if (Insensitive.StartsWith(args.Speech, "set"))
{
Mobile from = args.Mobile;
string[] split = args.Speech.Split( ' ' );
string[] split = args.Speech.Split(' ');
if ( split.Length == 3 )
{
try
{
string name = split[1];
double value = Convert.ToDouble( split[2] );
if (split.Length == 3)
try
{
string name = split[1];
double value = Convert.ToDouble(split[2]);
if ( Insensitive.Equals( name, "str" ) )
ChangeStrength( from, (int)value );
else if ( Insensitive.Equals( name, "dex" ) )
ChangeDexterity( from, (int)value );
else if ( Insensitive.Equals( name, "int" ) )
ChangeIntelligence( from, (int)value );
else
ChangeSkill( from, name, value );
}
catch
{
}
}
}
else if ( Insensitive.Equals( args.Speech, "help" ) )
{
args.Mobile.SendGump( new TCHelpGump() );
if (Insensitive.Equals(name, "str"))
ChangeStrength(from, (int)value);
else if (Insensitive.Equals(name, "dex"))
ChangeDexterity(from, (int)value);
else if (Insensitive.Equals(name, "int"))
ChangeIntelligence(from, (int)value);
else
ChangeSkill(from, name, value);
}
catch
{
}
}
else if (Insensitive.Equals(args.Speech, "help"))
{
args.Mobile.SendGump(new TCHelpGump());
args.Handled = true;
}
}
}
args.Handled = true;
}
}
}
private static void ChangeStrength( Mobile from, int value )
{
if ( value < 10 || value > 125 )
{
from.SendLocalizedMessage( 1005628 ); // Stats range between 10 and 125.
}
else
{
if ( (value + from.RawDex + from.RawInt) > from.StatCap )
{
from.SendLocalizedMessage( 1005629 ); // You can not exceed the stat cap. Try setting another stat lower first.
}
else
{
from.RawStr = value;
from.SendLocalizedMessage( 1005630 ); // Your stats have been adjusted.
}
}
}
private static void ChangeStrength(Mobile from, int value)
{
if (value < 10 || value > 125)
{
from.SendLocalizedMessage(1005628); // Stats range between 10 and 125.
}
else
{
if (value + from.RawDex + from.RawInt > from.StatCap)
{
from.SendLocalizedMessage(
1005629); // You can not exceed the stat cap. Try setting another stat lower first.
}
else
{
from.RawStr = value;
from.SendLocalizedMessage(1005630); // Your stats have been adjusted.
}
}
}
private static void ChangeDexterity( Mobile from, int value )
{
if ( value < 10 || value > 125 )
{
from.SendLocalizedMessage( 1005628 ); // Stats range between 10 and 125.
}
else
{
if ( (from.RawStr + value + from.RawInt) > from.StatCap )
{
from.SendLocalizedMessage( 1005629 ); // You can not exceed the stat cap. Try setting another stat lower first.
}
else
{
from.RawDex = value;
from.SendLocalizedMessage( 1005630 ); // Your stats have been adjusted.
}
}
}
private static void ChangeDexterity(Mobile from, int value)
{
if (value < 10 || value > 125)
{
from.SendLocalizedMessage(1005628); // Stats range between 10 and 125.
}
else
{
if (from.RawStr + value + from.RawInt > from.StatCap)
{
from.SendLocalizedMessage(
1005629); // You can not exceed the stat cap. Try setting another stat lower first.
}
else
{
from.RawDex = value;
from.SendLocalizedMessage(1005630); // Your stats have been adjusted.
}
}
}
private static void ChangeIntelligence( Mobile from, int value )
{
if ( value < 10 || value > 125 )
{
from.SendLocalizedMessage( 1005628 ); // Stats range between 10 and 125.
}
else
{
if ( (from.RawStr + from.RawDex + value) > from.StatCap )
{
from.SendLocalizedMessage( 1005629 ); // You can not exceed the stat cap. Try setting another stat lower first.
}
else
{
from.RawInt = value;
from.SendLocalizedMessage( 1005630 ); // Your stats have been adjusted.
}
}
}
private static void ChangeIntelligence(Mobile from, int value)
{
if (value < 10 || value > 125)
{
from.SendLocalizedMessage(1005628); // Stats range between 10 and 125.
}
else
{
if (from.RawStr + from.RawDex + value > from.StatCap)
{
from.SendLocalizedMessage(
1005629); // You can not exceed the stat cap. Try setting another stat lower first.
}
else
{
from.RawInt = value;
from.SendLocalizedMessage(1005630); // Your stats have been adjusted.
}
}
}
private static void ChangeSkill( Mobile from, string name, double value )
{
SkillName index;
private static void ChangeSkill(Mobile from, string name, double value)
{
SkillName index;
if ( !Enum.TryParse( name, true, out index ) || (!Core.SE && (int)index > 51) || (!Core.AOS && (int)index > 48) )
{
from.SendLocalizedMessage( 1005631 ); // You have specified an invalid skill to set.
return;
}
if (!Enum.TryParse(name, true, out index) || !Core.SE && (int)index > 51 || !Core.AOS && (int)index > 48)
{
from.SendLocalizedMessage(1005631); // You have specified an invalid skill to set.
return;
}
Skill skill = from.Skills[index];
Skill skill = from.Skills[index];
if ( skill != null )
{
if ( value < 0 || value > skill.Cap )
{
from.SendMessage($"Your skill in {skill.Info.Name} is capped at {skill.Cap:F1}.");
}
else
{
int newFixedPoint = (int)(value * 10.0);
int oldFixedPoint = skill.BaseFixedPoint;
if (skill != null)
{
if (value < 0 || value > skill.Cap)
{
from.SendMessage($"Your skill in {skill.Info.Name} is capped at {skill.Cap:F1}.");
}
else
{
int newFixedPoint = (int)(value * 10.0);
int oldFixedPoint = skill.BaseFixedPoint;
if ( ((skill.Owner.Total - oldFixedPoint) + newFixedPoint) > skill.Owner.Cap )
{
from.SendMessage( "You can not exceed the skill cap. Try setting another skill lower first." );
}
else
{
skill.BaseFixedPoint = newFixedPoint;
}
}
}
else
{
from.SendLocalizedMessage( 1005631 ); // You have specified an invalid skill to set.
}
}
if (skill.Owner.Total - oldFixedPoint + newFixedPoint > skill.Owner.Cap)
from.SendMessage("You can not exceed the skill cap. Try setting another skill lower first.");
else
skill.BaseFixedPoint = newFixedPoint;
}
}
else
{
from.SendLocalizedMessage(1005631); // You have specified an invalid skill to set.
}
}
public class TCHelpGump : Gump
{
public TCHelpGump() : base( 40, 40 )
{
AddPage( 0 );
AddBackground( 0, 0, 160, 120, 5054 );
public class TCHelpGump : Gump
{
public TCHelpGump() : base(40, 40)
{
AddPage(0);
AddBackground(0, 0, 160, 120, 5054);
AddButton( 10, 10, 0xFB7, 0xFB9, 1, GumpButtonType.Reply, 0 );
AddLabel( 45, 10, 0x34, "RunUO" );
AddButton(10, 10, 0xFB7, 0xFB9, 1, GumpButtonType.Reply, 0);
AddLabel(45, 10, 0x34, "RunUO");
AddButton( 10, 35, 0xFB7, 0xFB9, 2, GumpButtonType.Reply, 0 );
AddLabel( 45, 35, 0x34, "List of skills" );
AddButton(10, 35, 0xFB7, 0xFB9, 2, GumpButtonType.Reply, 0);
AddLabel(45, 35, 0x34, "List of skills");
AddButton( 10, 60, 0xFB7, 0xFB9, 3, GumpButtonType.Reply, 0 );
AddLabel( 45, 60, 0x34, "Command list" );
AddButton(10, 60, 0xFB7, 0xFB9, 3, GumpButtonType.Reply, 0);
AddLabel(45, 60, 0x34, "Command list");
AddButton( 10, 85, 0xFB1, 0xFB3, 0, GumpButtonType.Reply, 0 );
AddLabel( 45, 85, 0x34, "Close" );
}
AddButton(10, 85, 0xFB1, 0xFB3, 0, GumpButtonType.Reply, 0);
AddLabel(45, 85, 0x34, "Close");
}
public override void OnResponse( NetState sender, RelayInfo info )
{
switch ( info.ButtonID )
{
case 1: // RunUO
{
sender.LaunchBrowser("https://github.com/runuo/");
break;
}
case 2: // List of skills
{
string[] strings = Enum.GetNames( typeof( SkillName ) );
public override void OnResponse(NetState sender, RelayInfo info)
{
switch (info.ButtonID)
{
case 1: // RunUO
{
sender.LaunchBrowser("https://github.com/runuo/");
break;
}
case 2: // List of skills
{
string[] strings = Enum.GetNames(typeof(SkillName));
Array.Sort( strings );
Array.Sort(strings);
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder();
if ( strings.Length > 0 )
sb.Append( strings[0] );
if (strings.Length > 0)
sb.Append(strings[0]);
for ( int i = 1; i < strings.Length; ++i )
{
string v = strings[i];
for (int i = 1; i < strings.Length; ++i)
{
string v = strings[i];
if ( (sb.Length + 1 + v.Length) >= 256 )
{
sender.Send( new AsciiMessage( Server.Serial.MinusOne, -1, MessageType.Label, 0x35, 3, "System", sb.ToString() ) );
sb = new StringBuilder();
sb.Append( v );
}
else
{
sb.Append( ' ' );
sb.Append( v );
}
}
if (sb.Length + 1 + v.Length >= 256)
{
sender.Send(new AsciiMessage(Server.Serial.MinusOne, -1, MessageType.Label, 0x35, 3,
"System", sb.ToString()));
sb = new StringBuilder();
sb.Append(v);
}
else
{
sb.Append(' ');
sb.Append(v);
}
}
if ( sb.Length > 0 )
{
sender.Send( new AsciiMessage( Server.Serial.MinusOne, -1, MessageType.Label, 0x35, 3, "System", sb.ToString() ) );
}
if (sb.Length > 0)
sender.Send(new AsciiMessage(Server.Serial.MinusOne, -1, MessageType.Label, 0x35, 3, "System",
sb.ToString()));
break;
}
case 3: // Command list
{
sender.Mobile.SendAsciiMessage( 0x482, "The command prefix is \"{0}\"", CommandSystem.Prefix );
CommandHandlers.Help_OnCommand( new CommandEventArgs( sender.Mobile, "help", "", new string[0] ) );
break;
}
case 3: // Command list
{
sender.Mobile.SendAsciiMessage(0x482, "The command prefix is \"{0}\"", CommandSystem.Prefix);
CommandHandlers.Help_OnCommand(new CommandEventArgs(sender.Mobile, "help", "", new string[0]));
break;
}
}
}
}
}
}
break;
}
}
}
}
}
}