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
|
|
@ -3,242 +3,247 @@ using System.IO;
|
|||
|
||||
namespace Server.Multis
|
||||
{
|
||||
public class ComponentVerification
|
||||
{
|
||||
private int[] m_ItemTable;
|
||||
private int[] m_MultiTable;
|
||||
public class ComponentVerification
|
||||
{
|
||||
private int[] m_ItemTable;
|
||||
private int[] m_MultiTable;
|
||||
|
||||
public bool IsItemValid( int itemID )
|
||||
{
|
||||
if ( itemID <= 0 || itemID >= m_ItemTable.Length )
|
||||
return false;
|
||||
public ComponentVerification()
|
||||
{
|
||||
m_ItemTable = CreateTable(TileData.MaxItemValue);
|
||||
m_MultiTable = CreateTable(0x4000);
|
||||
|
||||
return CheckValidity( m_ItemTable[itemID] );
|
||||
}
|
||||
LoadItems("Data/Components/walls.txt", "South1", "South2", "South3", "Corner", "East1", "East2", "East3", "Post",
|
||||
"WindowS", "AltWindowS", "WindowE", "AltWindowE", "SecondAltWindowS", "SecondAltWindowE");
|
||||
LoadItems("Data/Components/teleprts.txt", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11",
|
||||
"F12", "F13", "F14", "F15", "F16");
|
||||
LoadItems("Data/Components/stairs.txt", "Block", "North", "East", "South", "West", "Squared1", "Squared2",
|
||||
"Rounded1", "Rounded2");
|
||||
LoadItems("Data/Components/roof.txt", "North", "East", "South", "West", "NSCrosspiece", "EWCrosspiece", "NDent",
|
||||
"EDent", "SDent", "WDent", "NTPiece", "ETPiece", "STPiece", "WTPiece", "XPiece", "Extra Piece");
|
||||
LoadItems("Data/Components/floors.txt", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11",
|
||||
"F12", "F13", "F14", "F15", "F16");
|
||||
LoadItems("Data/Components/misc.txt", "Piece1", "Piece2", "Piece3", "Piece4", "Piece5", "Piece6", "Piece7",
|
||||
"Piece8");
|
||||
LoadItems("Data/Components/doors.txt", "Piece1", "Piece2", "Piece3", "Piece4", "Piece5", "Piece6", "Piece7",
|
||||
"Piece8");
|
||||
|
||||
public bool IsMultiValid( int multiID )
|
||||
{
|
||||
if ( multiID <= 0 || multiID >= m_MultiTable.Length )
|
||||
return false;
|
||||
LoadMultis("Data/Components/stairs.txt", "MultiNorth", "MultiEast", "MultiSouth", "MultiWest");
|
||||
}
|
||||
|
||||
return CheckValidity( m_MultiTable[multiID] );
|
||||
}
|
||||
public bool IsItemValid(int itemID)
|
||||
{
|
||||
if (itemID <= 0 || itemID >= m_ItemTable.Length)
|
||||
return false;
|
||||
|
||||
public bool CheckValidity( int val )
|
||||
{
|
||||
if ( val == -1 )
|
||||
return false;
|
||||
return CheckValidity(m_ItemTable[itemID]);
|
||||
}
|
||||
|
||||
return ( val == 0 || ((int)ExpansionInfo.CoreExpansion.CustomHousingFlag & val) != 0 );
|
||||
}
|
||||
public bool IsMultiValid(int multiID)
|
||||
{
|
||||
if (multiID <= 0 || multiID >= m_MultiTable.Length)
|
||||
return false;
|
||||
|
||||
public ComponentVerification()
|
||||
{
|
||||
m_ItemTable = CreateTable( TileData.MaxItemValue );
|
||||
m_MultiTable = CreateTable( 0x4000 );
|
||||
return CheckValidity(m_MultiTable[multiID]);
|
||||
}
|
||||
|
||||
LoadItems( "Data/Components/walls.txt", "South1", "South2", "South3", "Corner", "East1", "East2", "East3", "Post", "WindowS", "AltWindowS", "WindowE", "AltWindowE", "SecondAltWindowS", "SecondAltWindowE" );
|
||||
LoadItems( "Data/Components/teleprts.txt", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16" );
|
||||
LoadItems( "Data/Components/stairs.txt", "Block", "North", "East", "South", "West", "Squared1", "Squared2", "Rounded1", "Rounded2" );
|
||||
LoadItems( "Data/Components/roof.txt", "North", "East", "South", "West", "NSCrosspiece", "EWCrosspiece", "NDent", "EDent", "SDent", "WDent", "NTPiece", "ETPiece", "STPiece", "WTPiece", "XPiece", "Extra Piece" );
|
||||
LoadItems( "Data/Components/floors.txt", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16" );
|
||||
LoadItems( "Data/Components/misc.txt", "Piece1", "Piece2", "Piece3", "Piece4", "Piece5", "Piece6", "Piece7", "Piece8" );
|
||||
LoadItems( "Data/Components/doors.txt", "Piece1", "Piece2", "Piece3", "Piece4", "Piece5", "Piece6", "Piece7", "Piece8" );
|
||||
public bool CheckValidity(int val)
|
||||
{
|
||||
if (val == -1)
|
||||
return false;
|
||||
|
||||
LoadMultis( "Data/Components/stairs.txt", "MultiNorth", "MultiEast", "MultiSouth", "MultiWest" );
|
||||
}
|
||||
return val == 0 || ((int)ExpansionInfo.CoreExpansion.CustomHousingFlag & val) != 0;
|
||||
}
|
||||
|
||||
private int[] CreateTable( int length )
|
||||
{
|
||||
int[] table = new int[length];
|
||||
private int[] CreateTable(int length)
|
||||
{
|
||||
int[] table = new int[length];
|
||||
|
||||
for ( int i = 0; i < table.Length; ++i )
|
||||
table[i] = -1;
|
||||
for (int i = 0; i < table.Length; ++i)
|
||||
table[i] = -1;
|
||||
|
||||
return table;
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
private void LoadItems( string path, params string[] itemColumns )
|
||||
{
|
||||
LoadSpreadsheet( m_ItemTable, path, itemColumns );
|
||||
}
|
||||
private void LoadItems(string path, params string[] itemColumns)
|
||||
{
|
||||
LoadSpreadsheet(m_ItemTable, path, itemColumns);
|
||||
}
|
||||
|
||||
private void LoadMultis( string path, params string[] multiColumns )
|
||||
{
|
||||
LoadSpreadsheet( m_MultiTable, path, multiColumns );
|
||||
}
|
||||
private void LoadMultis(string path, params string[] multiColumns)
|
||||
{
|
||||
LoadSpreadsheet(m_MultiTable, path, multiColumns);
|
||||
}
|
||||
|
||||
private void LoadSpreadsheet( int[] table, string path, params string[] tileColumns )
|
||||
{
|
||||
Spreadsheet ss = new Spreadsheet( path );
|
||||
private void LoadSpreadsheet(int[] table, string path, params string[] tileColumns)
|
||||
{
|
||||
Spreadsheet ss = new Spreadsheet(path);
|
||||
|
||||
int[] tileCIDs = new int[tileColumns.Length];
|
||||
int[] tileCIDs = new int[tileColumns.Length];
|
||||
|
||||
for ( int i = 0; i < tileColumns.Length; ++i )
|
||||
tileCIDs[i] = ss.GetColumnID( tileColumns[i] );
|
||||
for (int i = 0; i < tileColumns.Length; ++i)
|
||||
tileCIDs[i] = ss.GetColumnID(tileColumns[i]);
|
||||
|
||||
int featureCID = ss.GetColumnID( "FeatureMask" );
|
||||
int featureCID = ss.GetColumnID("FeatureMask");
|
||||
|
||||
for ( int i = 0; i < ss.Records.Length; ++i )
|
||||
{
|
||||
DataRecord record = ss.Records[i];
|
||||
for (int i = 0; i < ss.Records.Length; ++i)
|
||||
{
|
||||
DataRecord record = ss.Records[i];
|
||||
|
||||
int fid = record.GetInt32( featureCID );
|
||||
int fid = record.GetInt32(featureCID);
|
||||
|
||||
for ( int j = 0; j < tileCIDs.Length; ++j )
|
||||
{
|
||||
int itemID = record.GetInt32( tileCIDs[j] );
|
||||
for (int j = 0; j < tileCIDs.Length; ++j)
|
||||
{
|
||||
int itemID = record.GetInt32(tileCIDs[j]);
|
||||
|
||||
if ( itemID <= 0 || itemID >= table.Length )
|
||||
continue;
|
||||
if (itemID <= 0 || itemID >= table.Length)
|
||||
continue;
|
||||
|
||||
table[itemID] = fid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
table[itemID] = fid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Spreadsheet
|
||||
{
|
||||
private class ColumnInfo
|
||||
{
|
||||
public int m_DataIndex;
|
||||
public class Spreadsheet
|
||||
{
|
||||
private ColumnInfo[] m_Columns;
|
||||
|
||||
public string m_Type;
|
||||
public string m_Name;
|
||||
public Spreadsheet(string path)
|
||||
{
|
||||
using (StreamReader ip = new StreamReader(path))
|
||||
{
|
||||
string[] types = ReadLine(ip);
|
||||
string[] names = ReadLine(ip);
|
||||
|
||||
public ColumnInfo( int dataIndex, string type, string name )
|
||||
{
|
||||
m_DataIndex = dataIndex;
|
||||
m_Columns = new ColumnInfo[types.Length];
|
||||
|
||||
m_Type = type;
|
||||
m_Name = name;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < m_Columns.Length; ++i)
|
||||
m_Columns[i] = new ColumnInfo(i, types[i], names[i]);
|
||||
|
||||
private ColumnInfo[] m_Columns;
|
||||
List<DataRecord> records = new List<DataRecord>();
|
||||
|
||||
public DataRecord[] Records { get; }
|
||||
string[] values;
|
||||
|
||||
public int GetColumnID( string name )
|
||||
{
|
||||
for ( int i = 0; i < m_Columns.Length; ++i )
|
||||
{
|
||||
if ( m_Columns[i].m_Name == name )
|
||||
return i;
|
||||
}
|
||||
while ((values = ReadLine(ip)) != null)
|
||||
{
|
||||
object[] data = new object[m_Columns.Length];
|
||||
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < m_Columns.Length; ++i)
|
||||
{
|
||||
ColumnInfo ci = m_Columns[i];
|
||||
|
||||
public Spreadsheet( string path )
|
||||
{
|
||||
using ( StreamReader ip = new StreamReader( path ) )
|
||||
{
|
||||
string[] types = ReadLine( ip );
|
||||
string[] names = ReadLine( ip );
|
||||
switch (ci.m_Type)
|
||||
{
|
||||
case "int":
|
||||
{
|
||||
data[i] = Utility.ToInt32(values[ci.m_DataIndex]);
|
||||
break;
|
||||
}
|
||||
case "string":
|
||||
{
|
||||
data[i] = values[ci.m_DataIndex];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_Columns = new ColumnInfo[types.Length];
|
||||
records.Add(new DataRecord(this, data));
|
||||
}
|
||||
|
||||
for ( int i = 0; i < m_Columns.Length; ++i )
|
||||
m_Columns[i] = new ColumnInfo( i, types[i], names[i] );
|
||||
Records = records.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
List<DataRecord> records = new List<DataRecord>();
|
||||
public DataRecord[] Records{ get; }
|
||||
|
||||
string[] values;
|
||||
public int GetColumnID(string name)
|
||||
{
|
||||
for (int i = 0; i < m_Columns.Length; ++i)
|
||||
if (m_Columns[i].m_Name == name)
|
||||
return i;
|
||||
|
||||
while ( ( values = ReadLine( ip ) ) != null )
|
||||
{
|
||||
object[] data = new object[m_Columns.Length];
|
||||
return -1;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < m_Columns.Length; ++i )
|
||||
{
|
||||
ColumnInfo ci = m_Columns[i];
|
||||
private string[] ReadLine(StreamReader ip)
|
||||
{
|
||||
string line;
|
||||
|
||||
switch ( ci.m_Type )
|
||||
{
|
||||
case "int":
|
||||
{
|
||||
data[i] = Utility.ToInt32( values[ci.m_DataIndex] );
|
||||
break;
|
||||
}
|
||||
case "string":
|
||||
{
|
||||
data[i] = values[ci.m_DataIndex];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
while ((line = ip.ReadLine()) != null)
|
||||
{
|
||||
if (line.Length == 0)
|
||||
continue;
|
||||
|
||||
records.Add( new DataRecord( this, data ) );
|
||||
}
|
||||
return line.Split('\t');
|
||||
}
|
||||
|
||||
Records = records.ToArray();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private string[] ReadLine( StreamReader ip )
|
||||
{
|
||||
string line;
|
||||
private class ColumnInfo
|
||||
{
|
||||
public int m_DataIndex;
|
||||
public string m_Name;
|
||||
|
||||
while ( ( line = ip.ReadLine() ) != null )
|
||||
{
|
||||
if ( line.Length == 0 )
|
||||
continue;
|
||||
public string m_Type;
|
||||
|
||||
return line.Split( '\t' );
|
||||
}
|
||||
public ColumnInfo(int dataIndex, string type, string name)
|
||||
{
|
||||
m_DataIndex = dataIndex;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
m_Type = type;
|
||||
m_Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DataRecord
|
||||
{
|
||||
public Spreadsheet Spreadsheet { get; }
|
||||
public class DataRecord
|
||||
{
|
||||
public DataRecord(Spreadsheet ss, object[] data)
|
||||
{
|
||||
Spreadsheet = ss;
|
||||
Data = data;
|
||||
}
|
||||
|
||||
public object[] Data { get; }
|
||||
public Spreadsheet Spreadsheet{ get; }
|
||||
|
||||
public DataRecord( Spreadsheet ss, object[] data )
|
||||
{
|
||||
Spreadsheet = ss;
|
||||
Data = data;
|
||||
}
|
||||
public object[] Data{ get; }
|
||||
|
||||
public int GetInt32( string name )
|
||||
{
|
||||
return GetInt32( this[name] );
|
||||
}
|
||||
public object this[string name] => this[Spreadsheet.GetColumnID(name)];
|
||||
|
||||
public int GetInt32( int id )
|
||||
{
|
||||
return GetInt32( this[id] );
|
||||
}
|
||||
public object this[int id]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (id < 0)
|
||||
return null;
|
||||
|
||||
public int GetInt32( object obj )
|
||||
{
|
||||
if ( obj is int )
|
||||
return (int) obj;
|
||||
return Data[id];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
public int GetInt32(string name)
|
||||
{
|
||||
return GetInt32(this[name]);
|
||||
}
|
||||
|
||||
public string GetString( string name )
|
||||
{
|
||||
return this[name] as string;
|
||||
}
|
||||
public int GetInt32(int id)
|
||||
{
|
||||
return GetInt32(this[id]);
|
||||
}
|
||||
|
||||
public object this[string name] => this[Spreadsheet.GetColumnID( name )];
|
||||
public int GetInt32(object obj)
|
||||
{
|
||||
if (obj is int)
|
||||
return (int)obj;
|
||||
|
||||
public object this[int id]
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( id < 0 )
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Data[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public string GetString(string name)
|
||||
{
|
||||
return this[name] as string;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue