本文整理汇总了C#中IGameObject.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# IGameObject.Serialize方法的具体用法?C# IGameObject.Serialize怎么用?C# IGameObject.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGameObject
的用法示例。
在下文中一共展示了IGameObject.Serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Item_Save
public static bool Item_Save(this DB db, IGameObject item, string owner, out string msg, out SqlTransaction tran, out SqlConnection con)
{
/*
WHEN NOT MATCHED [BY TARGET] -- row exists in source but not in target
WHEN NOT MATCHED BY SOURCE -- row exists in target but not in source
*/
if(((ServerGameObject)item).IsTransient)
{
tran = null;
con = null;
msg = "Transient objects can't be saved.";
return false;
}
tran = null;
bool result = true;
msg = "";
con = DB.GameDataConnection;
SqlCommand cmd = DB.GetCommand(con, "Items_Save", true);
SqlParameter pout = new SqlParameter("@resultCode", 0);
pout.Direction = ParameterDirection.Output;
cmd.Parameters.Add(pout);
cmd.Parameters.Add(new SqlParameter("@itemID", item.UID));
cmd.Parameters.Add(new SqlParameter("@owner", owner));
cmd.Parameters.Add(new SqlParameter("@context", item.Context));
cmd.Parameters.Add(new SqlParameter("@typeHash", item.TypeHash));
cmd.Parameters.Add(new SqlParameter("@typeHash", item.TypeHash));
cmd.Parameters.Add(new SqlParameter("@stackCount", item.StackCount));
cmd.Parameters.Add(new SqlParameter("@template", item.ItemTemplate));
cmd.Parameters.Add(new SqlParameter("@objectOwner", item.Owner));
cmd.Parameters.Add(new SqlParameter("@typeHash", (long)item.TypeHash));
cmd.Parameters.Add(new SqlParameter("@createdOn", item.CreatedOn));
cmd.Parameters.Add(new SqlParameter("@got", (int)item.GameObjectType));
if (!((ServerGameObject)item).IsStatic)
{
Pointer dataPointer = new Pointer();
byte[] bindata = new byte[1024];
item.Serialize(ref bindata, dataPointer);
// Combine envelope and body into final data gram
byte[] trimData = new byte[dataPointer.Position];
Util.Copy(bindata, 0, trimData, trimData.Length, dataPointer.Position);
cmd.Parameters.Add(new SqlParameter("@binData", trimData));
SqlParameter ints = new SqlParameter("@intProperties", ItemIntPropertiesToTable(item.Properties.GetAllPropertiesOfKind(PropertyKind.Int32), item.UID));
ints.SqlDbType = SqlDbType.Structured;
cmd.Parameters.Add(ints);
SqlParameter floats = new SqlParameter("@floatProperties", ItemFloatPropertiesToTable(item.Properties.GetAllPropertiesOfKind(PropertyKind.Single), item.UID));
floats.SqlDbType = SqlDbType.Structured;
cmd.Parameters.Add(floats);
SqlParameter longs = new SqlParameter("@longProperties", ItemLongPropertiesToTable(item.Properties.GetAllPropertiesOfKind(PropertyKind.Int64), item.UID));
longs.SqlDbType = SqlDbType.Structured;
cmd.Parameters.Add(longs);
SqlParameter strings = new SqlParameter("@stringProperties", ItemStringPropertiesToTable(item.Properties.GetAllPropertiesOfKind(PropertyKind.String), item.UID));
strings.SqlDbType = SqlDbType.Structured;
cmd.Parameters.Add(strings);
SqlParameter statsParm = new SqlParameter("@stats", ItemStatsToTable(item.Stats.AllStats, item.UID));
statsParm.SqlDbType = SqlDbType.Structured;
cmd.Parameters.Add(statsParm);
}
try
{
con.Open();
tran = con.BeginTransaction(IsolationLevel.ReadCommitted);
cmd.Connection = con;
cmd.Transaction = tran;
cmd.ExecuteNonQuery();
long val = (long)cmd.Parameters[0].Value;
result = val > 0;
// -1 = unknown error creating Item
// 0 = unknown error crating Item starting stats
// 1 = Item created successfully
}
catch (Exception e)
{
Log1.Logger("Server").Error("[DATABASE ERROR] : " + e.Message);
result = false;
}
finally
{
/*
if (con != null)
{
con.Close();
con.Dispose();
con = null;
}
//.........这里部分代码省略.........