예제 #1
0
 public static void LoadCallPetType()
 {
     try
     {
         lock (CallPetManager._CallPetMutex)
         {
             CallPetManager.CallPetTypeDict.Clear();
             string fileName = "Config/CallPetType.xml";
             GeneralCachingXmlMgr.RemoveCachingXml(Global.GameResPath(fileName));
             XElement xml = GeneralCachingXmlMgr.GetXElement(Global.GameResPath(fileName));
             if (null == xml)
             {
                 LogManager.WriteLog(LogTypes.Fatal, "加载Config/CallPetType.xml时出错!!!文件不存在", null, true);
             }
             else
             {
                 IEnumerable <XElement> xmlItems = xml.Elements();
                 foreach (XElement xmlItem in xmlItems)
                 {
                     CallPetType CfgData = new CallPetType();
                     CfgData.ID            = (int)Global.GetSafeAttributeLong(xmlItem, "ID");
                     CfgData.MinZhuanSheng = (int)Global.GetSafeAttributeLong(xmlItem, "MinZhuanSheng");
                     CfgData.MinLevel      = (int)Global.GetSafeAttributeLong(xmlItem, "MinLevel");
                     CfgData.MaxZhuanSheng = (int)Global.GetSafeAttributeLong(xmlItem, "MaxZhuanSheng");
                     CfgData.MaxLevel      = (int)Global.GetSafeAttributeLong(xmlItem, "MaxLevel");
                     CallPetManager.CallPetTypeDict[CfgData.ID] = CfgData;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LogManager.WriteLog(LogTypes.Fatal, "加载Config/CallPetType.xml时文件出错", ex, true);
     }
 }
예제 #2
0
        public static CallPetType GetCallPetType(int type = 1)
        {
            CallPetType config = null;

            lock (CallPetManager._CallPetMutex)
            {
                if (CallPetManager.CallPetTypeDict.ContainsKey(type))
                {
                    config = CallPetManager.CallPetTypeDict[type];
                }
            }
            return(config);
        }
예제 #3
0
        public static CallSpriteResult CallPet(GameClient client, int times, out string strGetGoods)
        {
            strGetGoods = "";
            CallSpriteResult result;

            if (times != 1 && times != 10)
            {
                result = CallSpriteResult.ErrorParams;
            }
            else
            {
                CallPetType TypeData = CallPetManager.GetCallPetType(1);
                if (null == TypeData)
                {
                    result = CallSpriteResult.ErrorConfig;
                }
                else if (client.ClientData.Level < TypeData.MinLevel)
                {
                    result = CallSpriteResult.ErrorLevel;
                }
                else if (client.ClientData.Level > TypeData.MaxLevel)
                {
                    result = CallSpriteResult.ErrorLevel;
                }
                else if (client.ClientData.ChangeLifeCount < TypeData.MinZhuanSheng)
                {
                    result = CallSpriteResult.ErrorLevel;
                }
                else if (client.ClientData.ChangeLifeCount > TypeData.MaxZhuanSheng)
                {
                    result = CallSpriteResult.ErrorLevel;
                }
                else
                {
                    bool bFreeCall = false;
                    bool bUseGoods = false;
                    int  bind      = 0;
                    if (1 == times)
                    {
                        if (CallPetManager.getFreeSec(client) <= 0L)
                        {
                            bFreeCall = true;
                            bind      = 1;
                        }
                    }
                    if (!bFreeCall && CallPetManager.CallPetGoodsID > 0)
                    {
                        if (1 == times)
                        {
                            if (null != Global.GetGoodsByID(client, CallPetManager.CallPetGoodsID))
                            {
                                bUseGoods = true;
                                bind      = 1;
                            }
                        }
                    }
                    int nNeedLuckStar = CallPetManager.GetCallPetPrice(times);
                    if (nNeedLuckStar < 0)
                    {
                        result = CallSpriteResult.ErrorConfig;
                    }
                    else
                    {
                        if (!bFreeCall && !bUseGoods)
                        {
                            if (Global.IsRoleHasEnoughMoney(client, nNeedLuckStar, 163) < 0 && !HuanLeDaiBiManager.GetInstance().HuanledaibiReplaceEnough(client, nNeedLuckStar, DaiBiSySType.JingLingLieQu))
                            {
                                return(CallSpriteResult.ZuanShiNotEnough);
                            }
                        }
                        if (CallPetManager.GetMaxPetCount() - CallPetManager.GetPetListCount(client) < times)
                        {
                            result = CallSpriteResult.SpriteBagIsFull;
                        }
                        else
                        {
                            if (!bFreeCall)
                            {
                                if (bUseGoods)
                                {
                                    bool usedBinding     = false;
                                    bool usedTimeLimited = false;
                                    if (!GameManager.ClientMgr.NotifyUseGoods(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, CallPetManager.CallPetGoodsID, 1, false, out usedBinding, out usedTimeLimited, false))
                                    {
                                        bUseGoods = false;
                                    }
                                }
                            }
                            if (!bFreeCall && !bUseGoods)
                            {
                                if (!GameManager.ClientMgr.ModifyLuckStarValue(client, -nNeedLuckStar, "精灵召唤", false, DaiBiSySType.JingLingLieQu))
                                {
                                    return(CallSpriteResult.ZuanShiNotEnough);
                                }
                                bind = 0;
                            }
                            for (int i = 0; i < times; i++)
                            {
                                CallPetConfig        CfgData = null;
                                List <CallPetConfig> CfgList = CallPetManager.GetCallPetConfigList(bFreeCall || bUseGoods);
                                if (CfgList == null || CfgList.Count <= 0)
                                {
                                    return(CallSpriteResult.ErrorConfig);
                                }
                                int random = Global.GetRandomNumber(1, 100001);
                                foreach (CallPetConfig item in CfgList)
                                {
                                    if (random >= item.StartValues && random <= item.EndValues)
                                    {
                                        CfgData = item;
                                        break;
                                    }
                                }
                                LogManager.WriteLog(LogTypes.Info, string.Format("获取精灵随机数: random = {0}, GoodsID = {1}", random, CfgData.GoodsID), null, true);
                                if (null != CfgData)
                                {
                                    int nExcellenceProp = 0;
                                    if (CfgData.ZhuoYueFallID != -1)
                                    {
                                        nExcellenceProp = GameManager.GoodsPackMgr.GetExcellencePropertysID(CfgData.GoodsID, CfgData.ZhuoYueFallID);
                                    }
                                    Global.AddGoodsDBCommand(Global._TCPManager.TcpOutPacketPool, client, CfgData.GoodsID, CfgData.Num, 0, "", 0, bind, 4000, "", false, 1, "精灵召唤", "1900-01-01 12:00:00", 0, 0, 0, 0, nExcellenceProp, 0, 0, null, null, 0, true);
                                    strGetGoods += string.Format("{0},{1},{2},{3},{4},{5},{6}|", new object[]
                                    {
                                        CfgData.GoodsID,
                                        CfgData.Num,
                                        bind,
                                        0,
                                        0,
                                        0,
                                        nExcellenceProp
                                    });
                                }
                            }
                            if (bFreeCall)
                            {
                                Global.UpdateRoleParamByName(client, "CallPetFreeTime", Global.GetOffsetSecond(TimeUtil.NowDateTime()).ToString(), true);
                                if (client._IconStateMgr.CheckPetIcon(client))
                                {
                                    client._IconStateMgr.SendIconStateToClient(client);
                                }
                            }
                            else if (!bUseGoods)
                            {
                                int nPetJiFen = (int)((double)nNeedLuckStar * CallPetManager.ConsumeCallPetJiFen);
                                GameManager.ClientMgr.ModifyPetJiFenValue(client, nPetJiFen, "精灵召唤", false, true);
                            }
                            result = CallSpriteResult.Success;
                        }
                    }
                }
            }
            return(result);
        }
예제 #4
0
        /// <summary>
        /// 召唤精灵
        /// </summary>
        public static CallSpriteResult CallPet(GameClient client, int times, out string strGetGoods)
        {
            strGetGoods = "";

            if (times != 1 && times != 10)
            {
                return(CallSpriteResult.ErrorParams);
            }

            // 检查等级
            CallPetType TypeData = GetCallPetType();

            if (null == TypeData)
            {
                return(CallSpriteResult.ErrorConfig);
            }

            // 判断条件
            if (client.ClientData.Level < TypeData.MinLevel)
            {
                return(CallSpriteResult.ErrorLevel);
            }

            if (client.ClientData.Level > TypeData.MaxLevel)
            {
                return(CallSpriteResult.ErrorLevel);
            }

            if (client.ClientData.ChangeLifeCount < TypeData.MinZhuanSheng)
            {
                return(CallSpriteResult.ErrorLevel);
            }

            if (client.ClientData.ChangeLifeCount > TypeData.MaxZhuanSheng)
            {
                return(CallSpriteResult.ErrorLevel);
            }

            // 抽取一次 是不是到达免费次数了
            // 免费抽取的精灵为绑定状态,钻石抽取的精灵为不绑定状态
            bool bFreeCall = false;
            bool bUseGoods = false;
            int  bind      = 0;

            if (1 == times)
            {
                if (getFreeSec(client) <= 0)
                {
                    bFreeCall = true;
                    bind      = 1;
                }
            }

            // 不是免费 看看有没有道具
            if (bFreeCall == false && CallPetGoodsID > 0)
            {
                if (1 == times)
                {
                    if (null != Global.GetGoodsByID(client, CallPetGoodsID))
                    {
                        bUseGoods = true;
                        bind      = 1;
                    }
                }
            }

            // 检查金钱是否足够
            int nNeedZuanShi = GetCallPetPrice(times);

            if (nNeedZuanShi < 0)
            {
                return(CallSpriteResult.ErrorConfig);
            }

            if (false == bFreeCall && false == bUseGoods)
            {
                if (client.ClientData.UserMoney < nNeedZuanShi)
                {
                    return(CallSpriteResult.ZuanShiNotEnough);
                }
            }

            // 检查精灵背包是否足够
            if (GetMaxPetCount() - GetPetListCount(client) < times)
            {
                return(CallSpriteResult.SpriteBagIsFull);
            }

            if (bFreeCall)
            {
                //do nothing;
            }
            // 扣道具
            else if (bUseGoods)
            {
                bool usedBinding     = false;
                bool usedTimeLimited = false;
                // 消耗物品
                if (!GameManager.ClientMgr.NotifyUseGoods(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool,
                                                          Global._TCPManager.TcpOutPacketPool, client, CallPetGoodsID, 1, false, out usedBinding, out usedTimeLimited))
                {
                    bUseGoods = false;
                }
            }

            // 再扣钱
            if (false == bFreeCall && false == bUseGoods)
            {
                if (!GameManager.ClientMgr.SubUserMoney(Global._TCPManager.MySocketListener, Global._TCPManager.tcpClientPool, Global._TCPManager.TcpOutPacketPool, client, nNeedZuanShi, "精灵召唤"))
                {
                    return(CallSpriteResult.ZuanShiNotEnough);
                }
                bind = 0;
            }

            // 生成道具
            for (int i = 0; i < times; ++i)
            {
                CallPetConfig        CfgData = null;
                List <CallPetConfig> CfgList = GetCallPetConfigList(bFreeCall || bUseGoods);
                if (null == CfgList || CfgList.Count <= 0)
                {
                    return(CallSpriteResult.ErrorConfig);
                }

                int random = Global.GetRandomNumber(1, 100001);
                foreach (var item in CfgList)
                {
                    if (random >= item.StartValues && random <= item.EndValues)
                    {
                        CfgData = item;
                        break;
                    }
                }

                LogManager.WriteLog(LogTypes.Info, string.Format("获取精灵随机数: random = {0}, GoodsID = {1}", random, CfgData.GoodsID));

                if (null == CfgData)
                {
                    continue;
                }

                // 生成卓越属性
                int nExcellenceProp = 0;

                if (CfgData.ZhuoYueFallID != -1)
                {
                    nExcellenceProp = GameManager.GoodsPackMgr.GetExcellencePropertysID(CfgData.ZhuoYueFallID);
                }

                // 加道具
                Global.AddGoodsDBCommand(Global._TCPManager.TcpOutPacketPool, client,
                                         CfgData.GoodsID, CfgData.Num /*GCount*/,
                                         0, "" /*props*/, 0 /*forgelevel*/,
                                         bind /*binding*/, (int)SaleGoodsConsts.PetBagGoodsID, "" /*jewelList*/, false, 1,
                                         /**/ "精灵召唤", Global.ConstGoodsEndTime, 0, 0, 0, 0 /*Strong*/, nExcellenceProp /*ExcellenceProperty*/, 0, 0);

                // 返回4个参数 1.返回值 2.抽奖类型 3.抽中的物品列表(物品ID, 物品ID|物品数量|是否绑定|强化等级|追加等级|是否有幸运|卓越属性,...) 4.免费祈福的剩余时间
                strGetGoods += String.Format("{0},{1},{2},{3},{4},{5},{6}|", CfgData.GoodsID, CfgData.Num, bind, 0, 0, 0, nExcellenceProp);
            }

            // 如果是免费的 更新下上次召唤的时间
            if (true == bFreeCall)
            {
                double currSec = Global.GetOffsetSecond(TimeUtil.NowDateTime());
                Global.UpdateRoleParamByName(client, RoleParamName.CallPetFreeTime, currSec.ToString(), true);

                if (client._IconStateMgr.CheckPetIcon(client))
                {
                    client._IconStateMgr.SendIconStateToClient(client);
                }
            }
            else if (true == bUseGoods)
            {
                // do nothing
            }
            else
            {
                int nPetJiFen = (int)(nNeedZuanShi * ConsumeCallPetJiFen);
                GameManager.ClientMgr.ModifyPetJiFenValue(client, nPetJiFen, "精灵召唤");
            }

            return(CallSpriteResult.Success);
        }