Ejemplo n.º 1
0
        public void LoadConfig()
        {
            Dictionary <int, SevenDayChargeAct._DayAward> tmpDict = new Dictionary <int, SevenDayChargeAct._DayAward>();

            try
            {
                XElement xml = XElement.Load(Global.GameResPath("Config/SevenDay/SevenDayChongZhi.xml")).Element("GiftList");
                foreach (XElement xmlItem in xml.Elements())
                {
                    int day = (int)Global.GetSafeAttributeLong(xmlItem, "ID");
                    SevenDayChargeAct._DayAward award = new SevenDayChargeAct._DayAward();
                    award.NeedCharge = (int)Global.GetSafeAttributeLong(xmlItem, "MinZhuanShi");
                    string goodsIDs = Global.GetSafeAttributeStr(xmlItem, "GoodsOne");
                    if (!string.IsNullOrEmpty(goodsIDs))
                    {
                        string[] fields = goodsIDs.Split(new char[]
                        {
                            '|'
                        });
                        if (fields.Length <= 0)
                        {
                            LogManager.WriteLog(LogTypes.Warning, string.Format("读取{0}活动配置文件中的物品配置项失败", "Config/SevenDay/SevenDayChongZhi.xml"), null, true);
                        }
                        else
                        {
                            award.AllAward.GoodsDataList = HuodongCachingMgr.ParseGoodsDataList(fields, "Config/SevenDay/SevenDayChongZhi.xml");
                        }
                    }
                    goodsIDs = Global.GetSafeAttributeStr(xmlItem, "GoodsTwo");
                    if (!string.IsNullOrEmpty(goodsIDs))
                    {
                        string[] fields = goodsIDs.Split(new char[]
                        {
                            '|'
                        });
                        if (fields.Length <= 0)
                        {
                            LogManager.WriteLog(LogTypes.Warning, "Config/SevenDay/SevenDayChongZhi.xml", null, true);
                        }
                        else
                        {
                            award.OccAward.GoodsDataList = HuodongCachingMgr.ParseGoodsDataList(fields, "Config/SevenDay/SevenDayChongZhi.xml");
                        }
                    }
                    tmpDict[day] = award;
                }
                lock (this.ConfigMutex)
                {
                    this.DayAwardDict = tmpDict;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("七日登录活动加载配置失败{0}", "Config/SevenDay/SevenDayChongZhi.xml"), ex, true);
            }
        }
Ejemplo n.º 2
0
        public bool HasAnyAwardCanGet(GameClient client)
        {
            bool result;

            if (client == null)
            {
                result = false;
            }
            else if (!SingletonTemplate <SevenDayActivityMgr> .Instance().IsInActivityTime(client))
            {
                result = false;
            }
            else
            {
                Dictionary <int, SevenDayChargeAct._DayAward> tmpDayAwardDict = null;
                lock (this.ConfigMutex)
                {
                    tmpDayAwardDict = this.DayAwardDict;
                }
                if (tmpDayAwardDict == null)
                {
                    result = false;
                }
                else
                {
                    Dictionary <int, SevenDayItemData> itemDict = SingletonTemplate <SevenDayActivityMgr> .Instance().GetActivityData(client, ESevenDayActType.Charge);

                    if (itemDict == null)
                    {
                        result = false;
                    }
                    else
                    {
                        lock (itemDict)
                        {
                            foreach (KeyValuePair <int, SevenDayItemData> kvp in itemDict)
                            {
                                int day = kvp.Key;
                                SevenDayItemData            itemData = kvp.Value;
                                SevenDayChargeAct._DayAward award    = null;
                                if (tmpDayAwardDict.TryGetValue(day, out award) && itemData.Params1 * GameManager.GameConfigMgr.GetGameConfigItemInt("money-to-yuanbao", 10) >= award.NeedCharge && itemData.AwardFlag != 1)
                                {
                                    return(true);
                                }
                            }
                        }
                        result = false;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public ESevenDayActErrorCode HandleGetAward(GameClient client, int day)
        {
            int currDay;
            ESevenDayActErrorCode result;

            if (!SingletonTemplate <SevenDayActivityMgr> .Instance().IsInActivityTime(client, out currDay))
            {
                result = ESevenDayActErrorCode.NotInActivityTime;
            }
            else if (day < 0 || day > currDay)
            {
                result = ESevenDayActErrorCode.VisitParamsWrong;
            }
            else
            {
                SevenDayChargeAct._DayAward dayAward = null;
                lock (this.ConfigMutex)
                {
                    if (this.DayAwardDict == null || !this.DayAwardDict.TryGetValue(day, out dayAward))
                    {
                        return(ESevenDayActErrorCode.ServerConfigError);
                    }
                }
                Dictionary <int, SevenDayItemData> itemDict = SingletonTemplate <SevenDayActivityMgr> .Instance().GetActivityData(client, ESevenDayActType.Charge);

                if (itemDict == null)
                {
                    result = ESevenDayActErrorCode.NotReachCondition;
                }
                else
                {
                    lock (itemDict)
                    {
                        SevenDayItemData itemData = null;
                        if (!itemDict.TryGetValue(day, out itemData))
                        {
                            result = ESevenDayActErrorCode.ServerConfigError;
                        }
                        else if (itemData.Params1 * GameManager.GameConfigMgr.GetGameConfigItemInt("money-to-yuanbao", 10) < dayAward.NeedCharge || itemData.AwardFlag != 0)
                        {
                            result = ESevenDayActErrorCode.NotReachCondition;
                        }
                        else
                        {
                            int awardGoodsCnt = 0;
                            if (dayAward.AllAward != null && dayAward.AllAward.GoodsDataList != null)
                            {
                                awardGoodsCnt += dayAward.AllAward.GoodsDataList.Count;
                            }
                            if (dayAward.OccAward != null && dayAward.OccAward.GoodsDataList != null)
                            {
                                awardGoodsCnt += dayAward.OccAward.GoodsDataList.Count((GoodsData _goods) => Global.IsRoleOccupationMatchGoods(client, _goods.GoodsID));
                            }
                            if (awardGoodsCnt <= 0 || !Global.CanAddGoodsNum(client, awardGoodsCnt))
                            {
                                result = ESevenDayActErrorCode.NoBagSpace;
                            }
                            else
                            {
                                itemData.AwardFlag = 1;
                                if (!SingletonTemplate <SevenDayActivityMgr> .Instance().UpdateDb(client.ClientData.RoleID, ESevenDayActType.Charge, day, itemData, client.ServerId))
                                {
                                    itemData.AwardFlag = 0;
                                    result             = ESevenDayActErrorCode.DBFailed;
                                }
                                else
                                {
                                    if (!SingletonTemplate <SevenDayActivityMgr> .Instance().GiveAward(client, dayAward.AllAward, ESevenDayActType.Charge) || !SingletonTemplate <SevenDayActivityMgr> .Instance().GiveAward(client, dayAward.OccAward, ESevenDayActType.Charge))
                                    {
                                        LogManager.WriteLog(LogTypes.Error, string.Format("玩家领取七日充值奖励,设置领奖了但是发奖失败 roleid={0}, day={1}", client.ClientData.RoleID, day), null, true);
                                    }
                                    result = ESevenDayActErrorCode.Success;
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }