Modernization Fixes & Updates to Default Values (#3)

This commit is contained in:
Kamron Batman 2018-10-28 00:33:16 -07:00 • committed by GitHub
parent 445eddff68
commit dcf64091b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
768 changed files with 10507 additions and 14196 deletions

View file

@ -1,6 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Server.Diagnostics;
namespace Server.Commands
@ -52,6 +54,7 @@ namespace Server.Commands
}
catch
{
// ignored
}
}
@ -80,6 +83,7 @@ namespace Server.Commands
}
catch
{
// ignored
}
}
@ -89,37 +93,32 @@ namespace Server.Commands
{
using (StreamWriter op = new StreamWriter("objects.log"))
{
Hashtable table = new Hashtable();
Dictionary<Type, int> table = new Dictionary<Type, int>();
foreach (Item item in World.Items.Values)
{
Type type = item.GetType();
object o = table[type];
if (o == null)
table[type] = 1;
if (table.ContainsKey(type))
table[type] = 1 + table[type];
else
table[type] = 1 + (int)o;
table[type] = 1;
}
ArrayList items = new ArrayList(table);
List<KeyValuePair<Type, int>> items = table.ToList();
table.Clear();
foreach (Mobile m in World.Mobiles.Values)
{
Type type = m.GetType();
object o = table[type];
if (o == null)
table[type] = 1;
if (table.ContainsKey(type))
table[type] = 1 + table[type];
else
table[type] = 1 + (int)o;
table[type] = 1;
}
ArrayList mobiles = new ArrayList(table);
List<KeyValuePair<Type, int>> mobiles = table.ToList();
items.Sort(new CountSorter());
mobiles.Sort(new CountSorter());
@ -130,16 +129,16 @@ namespace Server.Commands
op.WriteLine("# Items:");
foreach (DictionaryEntry de in items)
op.WriteLine("{0}\t{1:F2}%\t{2}", de.Value, 100 * (int)de.Value / (double)World.Items.Count, de.Key);
items.ForEach(kvp =>
op.WriteLine("{0}\t{1:F2}%\t{2}", kvp.Value, 100.0 * kvp.Value / World.Items.Count, kvp.Key));
op.WriteLine();
op.WriteLine();
op.WriteLine("#Mobiles:");
foreach (DictionaryEntry de in mobiles)
op.WriteLine("{0}\t{1:F2}%\t{2}", de.Value, 100 * (int)de.Value / (double)World.Mobiles.Count, de.Key);
mobiles.ForEach(kvp =>
op.WriteLine("{0}\t{1:F2}%\t{2}", kvp.Value, 100.0 * kvp.Value / World.Mobiles.Count, kvp.Key));
}
e.Mobile.SendMessage("Object table has been generated. See the file : <runuo root>/objects.log");
@ -149,7 +148,7 @@ namespace Server.Commands
[Description("Generates a log file describing all items using expanded memory.")]
public static void TraceExpanded_OnCommand(CommandEventArgs e)
{
Hashtable typeTable = new Hashtable();
Dictionary<Type, int[]> typeTable = new Dictionary<Type, int[]>();
foreach (Item item in World.Items.Values)
{
@ -162,8 +161,10 @@ namespace Server.Commands
do
{
if (!(typeTable[itemType] is int[] countTable))
typeTable[itemType] = countTable = new int[9];
typeTable.TryGetValue(itemType, out int[] countTable);
if (countTable == null)
countTable = new int[9];
if ((flags & ExpandFlag.Name) != 0)
++countTable[0];
@ -213,16 +214,15 @@ namespace Server.Commands
"Spawner"
};
ArrayList list = new ArrayList(typeTable);
List<KeyValuePair<Type, int[]>> list = typeTable.ToList();
list.Sort(new CountSorter());
list.Sort(new CountsSorter());
foreach (DictionaryEntry de in list)
foreach (KeyValuePair<Type, int[]> kvp in list)
{
Type itemType = de.Key as Type;
int[] countTable = de.Value as int[];
int[] countTable = kvp.Value;
op.WriteLine("# {0}", itemType.FullName);
op.WriteLine("# {0}", kvp.Key.FullName);
for (int i = 0; i < countTable.Length; ++i)
if (countTable[i] > 0)
@ -234,6 +234,7 @@ namespace Server.Commands
}
catch
{
// ignored
}
}
@ -242,7 +243,7 @@ namespace Server.Commands
public static void TraceInternal_OnCommand(CommandEventArgs e)
{
int totalCount = 0;
Hashtable table = new Hashtable();
Dictionary<Type, int[]> table = new Dictionary<Type, int[]>();
foreach (Item item in World.Items.Values)
{
@ -252,7 +253,7 @@ namespace Server.Commands
++totalCount;
Type type = item.GetType();
int[] parms = (int[])table[type];
int[] parms = table[type];
if (parms == null)
table[type] = parms = new[] { 0, 0 };
@ -269,12 +270,11 @@ namespace Server.Commands
op.WriteLine();
op.WriteLine("Type\t\tCount\t\tAmount\t\tAvg. Amount");
foreach (DictionaryEntry de in table)
foreach (KeyValuePair<Type, int[]> de in table)
{
Type type = (Type)de.Key;
int[] parms = (int[])de.Value;
int[] parms = de.Value;
op.WriteLine("{0}\t\t{1}\t\t{2}\t\t{3:F2}", type.Name, parms[0], parms[1], (double)parms[1] / parms[0]);
op.WriteLine("{0}\t\t{1}\t\t{2}\t\t{3:F2}", de.Key.Name, parms[0], parms[1], (double)parms[1] / parms[0]);
}
}
}
@ -291,7 +291,7 @@ namespace Server.Commands
{
try
{
ArrayList types = new ArrayList();
List<Type> types = new List<Type>();
using (BinaryReader bin = new BinaryReader(new FileStream(string.Format("Saves/{0}/{0}.tdb", type),
FileMode.Open, FileAccess.Read, FileShare.Read)))
@ -304,7 +304,7 @@ namespace Server.Commands
long total = 0;
Hashtable table = new Hashtable();
Dictionary<Type, int> table = new Dictionary<Type, int>();
using (BinaryReader bin = new BinaryReader(new FileStream(string.Format("Saves/{0}/{0}.idx", type),
FileMode.Open, FileAccess.Read, FileShare.Read)))
@ -317,16 +317,14 @@ namespace Server.Commands
int serial = bin.ReadInt32();
long pos = bin.ReadInt64();
int length = bin.ReadInt32();
Type objType = (Type)types[typeID];
Type objType = types[typeID];
while (objType != null && objType != typeof(object))
while (objType != typeof(object))
{
object obj = table[objType];
if (obj == null)
table[objType] = length;
if (table.ContainsKey(objType))
table[objType] = length + table[objType];
else
table[objType] = length + (int)obj;
table[objType] = length;
objType = objType.BaseType;
total += length;
@ -334,7 +332,7 @@ namespace Server.Commands
}
}
ArrayList list = new ArrayList(table);
List<KeyValuePair<Type, int>> list = table.ToList();
list.Sort(new CountSorter());
@ -345,55 +343,46 @@ namespace Server.Commands
op.WriteLine();
op.WriteLine();
foreach (DictionaryEntry de in list)
op.WriteLine("{0}\t{1:F2}%\t{2}", de.Value, 100 * (int)de.Value / (double)total, de.Key);
list.ForEach(kvp =>
op.WriteLine("{0}\t{1:F2}%\t{2}", kvp.Value, 100.0 * kvp.Value / total, kvp.Key));
}
}
catch
{
// ignored
}
}
private class CountSorter : IComparer
private class CountSorter : IComparer<KeyValuePair<Type, int>>
{
public int Compare(object x, object y)
public int Compare(KeyValuePair<Type, int> x, KeyValuePair<Type, int> y)
{
DictionaryEntry a = (DictionaryEntry)x;
DictionaryEntry b = (DictionaryEntry)y;
int aCount = GetCount(a.Value);
int bCount = GetCount(b.Value);
int aCount = x.Value;
int bCount = y.Value;
int v = -aCount.CompareTo(bCount);
if (v == 0)
{
Type aType = (Type)a.Key;
Type bType = (Type)b.Key;
if (v != 0)
return v;
v = aType.FullName.CompareTo(bType.FullName);
}
return v;
return x.Key.FullName.CompareTo(y.Key.FullName);
}
}
private int GetCount(object obj)
private class CountsSorter : IComparer<KeyValuePair<Type, int[]>>
{
public int Compare(KeyValuePair<Type, int[]> x, KeyValuePair<Type, int[]> y)
{
if (obj is int intObj)
return intObj;
int aCount = x.Value.Aggregate(0, (t, val) => t + val);
int bCount = y.Value.Aggregate(0, (t, val) => t + val);
if (obj is int[] list)
{
int total = 0;
int v = -aCount.CompareTo(bCount);
for (int i = 0; i < list.Length; ++i)
total += list[i];
if (v != 0)
return v;
return total;
}
return 0;
return x.Key.FullName.CompareTo(y.Key.FullName);
}
}
}
}
}