Ejemplo n.º 1
0
        /// <summary>
        /// 加载物品数据
        /// </summary>
        /// <returns></returns>
        internal unsafe int LoadItemsDB()
        {
            int          result = -1;
            int          Idx;
            TStdItem *   StdItem;
            IDataReader  dr         = null;
            const string sSQLString = "SELECT IDX,NAME,STDMODE,SHAPE,WEIGHT,ANICOUNT,SOURCE,RESERVED,LOOKS,DURAMAX,AC,AC2,MAC,MAC2,DC,DC2,MC,MC2,SC,SC2,NEED,NEEDLEVEL,PRICE,STOCK FROM TBL_STDITEMS";

            HUtil32.EnterCriticalSection(M2Share.ProcessHumanCriticalSection);
            try
            {
                try
                {
                    foreach (var item in UserEngine.StdItemList)
                    {
                        if (item != null)
                        {
                            Dispose(item);
                        }
                    }
                    UserEngine.StdItemList.Clear();
                    try
                    {
                        dr = DBsession.ExecuteReader(sSQLString);
                    }
                    catch
                    {
                        MainOutMessage("链接数据库发生异常...");
                    }
                    finally
                    {
                        result = -2;
                    }
                    if (dr == null) //2013.04.16 Fixed dr为空时Read报错
                    {
                        return(result);
                    }
                    while (dr.Read())
                    {
                        Idx     = dr.GetInt32("Idx");// 序号
                        StdItem = (TStdItem *)Marshal.AllocHGlobal(sizeof(TStdItem));
                        HUtil32.ZeroMemory(StdItem, sizeof(TStdItem));
                        HUtil32.StrToSByteArry(dr.GetString("Name"), StdItem->Name, 14, ref StdItem->NameLen);
                        StdItem->StdMode      = dr.GetByte("StdMode");                                                                   // 分类号
                        StdItem->Shape        = dr.GetByte("Shape");                                                                     // 装备外观
                        StdItem->Weight       = dr.GetByte("Weight");                                                                    // 重量
                        StdItem->AniCount     = HUtil32.IntToByte(dr.GetInt32("AniCount"));                                              // 保留
                        StdItem->Source       = dr.GetSByte("Source");
                        StdItem->Reserved     = HUtil32.IntToByte(dr.GetInt32("Reserved"));                                              // 保留
                        StdItem->Looks        = dr.GetUInt16("Looks");                                                                   // 物品外观
                        StdItem->DuraMax      = dr.GetUInt16("DuraMax");                                                                 // 持久力
                        StdItem->Reserved1    = 0;
                        StdItem->AC           = TStdItem.MakeAC(dr.GetInt32("Ac"), dr.GetInt32("Ac2"), GameConfig.nItemsACPowerRate);    //物理防御
                        StdItem->MAC          = TStdItem.MakeMAC(dr.GetInt32("Mac"), dr.GetInt32("Mac2"), GameConfig.nItemsACPowerRate); //魔法防御
                        StdItem->DC           = TStdItem.MakeDC(dr.GetInt32("Dc"), dr.GetInt32("Dc2"), GameConfig.nItemsPowerRate);      //物理攻击
                        StdItem->MC           = TStdItem.MakeMC(dr.GetInt32("Mc"), dr.GetInt32("Mc2"), GameConfig.nItemsPowerRate);      //魔法攻击
                        StdItem->SC           = TStdItem.MakeSC(dr.GetInt32("Sc"), dr.GetInt32("Sc2"), GameConfig.nItemsPowerRate);      //道术
                        StdItem->Need         = dr.GetInt32("Need");                                                                     // 附加条件
                        StdItem->NeedLevel    = dr.GetInt32("NeedLevel");                                                                // 需要等级
                        StdItem->Price        = dr.GetInt32("Price");                                                                    // 价格
                        StdItem->Stock        = dr.GetInt32("Stock");                                                                    // 库存
                        StdItem->NeedIdentify = M2Share.GetGameLogItemNameList(dr.GetString("Name"));
                        if (UserEngine.StdItemList.Count == Idx)
                        {
                            UserEngine.StdItemList.Add((IntPtr)StdItem);
                            result = 1;
                        }
                        else
                        {
                            MainOutMessage(string.Format("加载物品[Idx:{0} Name:{1}]数据失败!!!", Idx, dr.GetString("Name")));
                            result = -100;
                            return(result);
                        }
                    }
                    M2Share.g_boGameLogGold        = M2Share.GetGameLogItemNameList(M2Share.sSTRING_GOLDNAME) == 1;
                    M2Share.g_boGameLogHumanDie    = M2Share.GetGameLogItemNameList(GameMsgDef.g_sHumanDieEvent) == 1;
                    M2Share.g_boGameLogGameGold    = M2Share.GetGameLogItemNameList(M2Share.g_Config.sGameGoldName) == 1;
                    M2Share.g_boGameLogGameDiaMond = M2Share.GetGameLogItemNameList(M2Share.g_Config.sGameDiaMond) == 1; // 是否写入日志(调整金刚石)
                    M2Share.g_boGameLogGameGird    = M2Share.GetGameLogItemNameList(M2Share.g_Config.sGameGird) == 1;    // 是否写入日志(调整灵符)
                    M2Share.g_boGameLogGameGlory   = M2Share.GetGameLogItemNameList(M2Share.g_Config.sGameGlory) == 1;   // 是否写入日志(调整荣誉值)
                    M2Share.g_boGameLogGamePoint   = M2Share.GetGameLogItemNameList(M2Share.g_Config.sGamePointName) == 1;
                }
                finally
                {
                    if (dr != null)
                    {
                        dr.Close();
                        dr.Dispose();
                    }
                }
            }
            finally
            {
                HUtil32.LeaveCriticalSection(M2Share.ProcessHumanCriticalSection);
            }

            return(result);
        }