当前位置: 首页>>代码示例>>C#>>正文


C# IGameObject.Serialize方法代码示例

本文整理汇总了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;
                }
//.........这里部分代码省略.........
开发者ID:kamilion,项目名称:WISP,代码行数:101,代码来源:DBExtensionItems.cs


注:本文中的IGameObject.Serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。