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

@ -2,193 +2,191 @@ using System;
namespace Server.Engines.Quests
{
public class QuestSerializer
{
public static object Construct( Type type )
{
try
{
return Activator.CreateInstance( type );
}
catch
{
return null;
}
}
public class QuestSerializer
{
public static object Construct(Type type)
{
try
{
return Activator.CreateInstance(type);
}
catch
{
return null;
}
}
public static void Write( Type type, Type[] referenceTable, GenericWriter writer )
{
if ( type == null )
{
writer.WriteEncodedInt( (int) 0x00 );
}
else
{
for ( int i = 0; i < referenceTable.Length; ++i )
{
if ( referenceTable[i] == type )
{
writer.WriteEncodedInt( (int) 0x01 );
writer.WriteEncodedInt( (int) i );
return;
}
}
public static void Write(Type type, Type[] referenceTable, GenericWriter writer)
{
if (type == null)
{
writer.WriteEncodedInt(0x00);
}
else
{
for (int i = 0; i < referenceTable.Length; ++i)
if (referenceTable[i] == type)
{
writer.WriteEncodedInt(0x01);
writer.WriteEncodedInt(i);
return;
}
writer.WriteEncodedInt( (int) 0x02 );
writer.Write( type.FullName );
}
}
writer.WriteEncodedInt(0x02);
writer.Write(type.FullName);
}
}
public static Type ReadType( Type[] referenceTable, GenericReader reader )
{
int encoding = reader.ReadEncodedInt();
public static Type ReadType(Type[] referenceTable, GenericReader reader)
{
int encoding = reader.ReadEncodedInt();
switch ( encoding )
{
default:
case 0x00: // null
{
return null;
}
case 0x01: // indexed
{
int index = reader.ReadEncodedInt();
switch (encoding)
{
default:
case 0x00: // null
{
return null;
}
case 0x01: // indexed
{
int index = reader.ReadEncodedInt();
if ( index >= 0 && index < referenceTable.Length )
return referenceTable[index];
if (index >= 0 && index < referenceTable.Length)
return referenceTable[index];
return null;
}
case 0x02: // by name
{
string fullName = reader.ReadString();
return null;
}
case 0x02: // by name
{
string fullName = reader.ReadString();
if ( fullName == null )
return null;
if (fullName == null)
return null;
return ScriptCompiler.FindTypeByFullName( fullName, false );
}
}
}
return ScriptCompiler.FindTypeByFullName(fullName, false);
}
}
}
public static QuestSystem DeserializeQuest( GenericReader reader )
{
int encoding = reader.ReadEncodedInt();
public static QuestSystem DeserializeQuest(GenericReader reader)
{
int encoding = reader.ReadEncodedInt();
switch ( encoding )
{
default:
case 0x00: // null
{
return null;
}
case 0x01:
{
Type type = ReadType( QuestSystem.QuestTypes, reader );
switch (encoding)
{
default:
case 0x00: // null
{
return null;
}
case 0x01:
{
Type type = ReadType(QuestSystem.QuestTypes, reader);
QuestSystem qs = Construct( type ) as QuestSystem;
QuestSystem qs = Construct(type) as QuestSystem;
qs?.BaseDeserialize( reader );
qs?.BaseDeserialize(reader);
return qs;
}
}
}
return qs;
}
}
}
public static void Serialize( QuestSystem qs, GenericWriter writer )
{
if ( qs == null )
{
writer.WriteEncodedInt( 0x00 );
}
else
{
writer.WriteEncodedInt( 0x01 );
public static void Serialize(QuestSystem qs, GenericWriter writer)
{
if (qs == null)
{
writer.WriteEncodedInt(0x00);
}
else
{
writer.WriteEncodedInt(0x01);
Write( qs.GetType(), QuestSystem.QuestTypes, writer );
Write(qs.GetType(), QuestSystem.QuestTypes, writer);
qs.BaseSerialize( writer );
}
}
qs.BaseSerialize(writer);
}
}
public static QuestObjective DeserializeObjective( Type[] referenceTable, GenericReader reader )
{
int encoding = reader.ReadEncodedInt();
public static QuestObjective DeserializeObjective(Type[] referenceTable, GenericReader reader)
{
int encoding = reader.ReadEncodedInt();
switch ( encoding )
{
default:
case 0x00: // null
{
return null;
}
case 0x01:
{
Type type = ReadType( referenceTable, reader );
switch (encoding)
{
default:
case 0x00: // null
{
return null;
}
case 0x01:
{
Type type = ReadType(referenceTable, reader);
QuestObjective obj = Construct( type ) as QuestObjective;
QuestObjective obj = Construct(type) as QuestObjective;
obj?.BaseDeserialize( reader );
obj?.BaseDeserialize(reader);
return obj;
}
}
}
return obj;
}
}
}
public static void Serialize( Type[] referenceTable, QuestObjective obj, GenericWriter writer )
{
if ( obj == null )
{
writer.WriteEncodedInt( 0x00 );
}
else
{
writer.WriteEncodedInt( 0x01 );
public static void Serialize(Type[] referenceTable, QuestObjective obj, GenericWriter writer)
{
if (obj == null)
{
writer.WriteEncodedInt(0x00);
}
else
{
writer.WriteEncodedInt(0x01);
Write( obj.GetType(), referenceTable, writer );
Write(obj.GetType(), referenceTable, writer);
obj.BaseSerialize( writer );
}
}
obj.BaseSerialize(writer);
}
}
public static QuestConversation DeserializeConversation( Type[] referenceTable, GenericReader reader )
{
int encoding = reader.ReadEncodedInt();
public static QuestConversation DeserializeConversation(Type[] referenceTable, GenericReader reader)
{
int encoding = reader.ReadEncodedInt();
switch ( encoding )
{
default:
case 0x00: // null
{
return null;
}
case 0x01:
{
Type type = ReadType( referenceTable, reader );
switch (encoding)
{
default:
case 0x00: // null
{
return null;
}
case 0x01:
{
Type type = ReadType(referenceTable, reader);
QuestConversation conv = Construct( type ) as QuestConversation;
QuestConversation conv = Construct(type) as QuestConversation;
conv?.BaseDeserialize( reader );
conv?.BaseDeserialize(reader);
return conv;
}
}
}
return conv;
}
}
}
public static void Serialize( Type[] referenceTable, QuestConversation conv, GenericWriter writer )
{
if ( conv == null )
{
writer.WriteEncodedInt( 0x00 );
}
else
{
writer.WriteEncodedInt( 0x01 );
public static void Serialize(Type[] referenceTable, QuestConversation conv, GenericWriter writer)
{
if (conv == null)
{
writer.WriteEncodedInt(0x00);
}
else
{
writer.WriteEncodedInt(0x01);
Write( conv.GetType(), referenceTable, writer );
Write(conv.GetType(), referenceTable, writer);
conv.BaseSerialize( writer );
}
}
}
conv.BaseSerialize(writer);
}
}
}
}