Esempio n. 1
0
        public override bool TakeAction()
        {
            string publicUserID = string.Empty;
            if (string.IsNullOrEmpty(toUserID))
            {
                publicUserID = ContextUser.UserID;
            }
            else
            {
                publicUserID = toUserID;
            }
            short crystalLv = 0;
            var package = UserCrystalPackage.Get(publicUserID);
            _userCrystal = package.CrystalPackage.Find(m => m.UserCrystalID.Equals(_userCrystalID));
            //_userCrystal = UserCrystal.FindKey(_userCrystalID);)
            if (_userCrystal != null)
            {
                _crystalInfo = new ConfigCacheSet<CrystalInfo>().FindKey(_userCrystal.CrystalID);
                crystalLv = _userCrystal.CrystalLv;
            }
            else
            {
                var grayCrystal = ContextUser.GrayCrystalList.Find(m => m.UserCrystalID == _userCrystalID);
                if (grayCrystal != null)
                    _crystalInfo = new ConfigCacheSet<CrystalInfo>().FindKey(grayCrystal.CrystalID);
                else
                    return false;
            }
            if (_crystalInfo == null)
            {
                return false;
            }
            CrystalLvInfo currCrystal = new ConfigCacheSet<CrystalLvInfo>().FindKey(_crystalInfo.CrystalID, crystalLv);
            short upLv = MathUtils.Addition(crystalLv, (short)1, short.MaxValue);
            if (upLv >= 10)
            {
                upLv = 10;
            }
            _crystalLvInfo = new ConfigCacheSet<CrystalLvInfo>().FindKey(_crystalInfo.CrystalID, upLv);//下级经验
            if (currCrystal != null && currCrystal.AbilityNum > 1)
            {
                _attrNum = currCrystal.AbilityNum.ToString().Replace(".0000", "");
            }
            else if (currCrystal != null)
            {
                _attrNum = Math.Round((currCrystal.AbilityNum * 100), 1, MidpointRounding.AwayFromZero).ToString();
                _attrNum = _attrNum.Replace(".0", "") + "%";
            }

            return true;
        }
Esempio n. 2
0
        public override bool TakeAction()
        {
            UserHelper.GetUserLightOpen(ContextUser.UserID);
            short opType = 0;
            int huntingID2 = 0;
            if (huntingID < 1005)
            {
                huntingID2 = MathUtils.Addition(huntingID, 1, int.MaxValue);
            }
            else
            {
                huntingID2 = 1001; //huntingID;
            }
            UserHelper.ChechDailyRestrain(ContextUser.UserID);

            if (!CrystalHelper.CheckAllowCrystall(ContextUser))
            {
                ErrorCode = 1000;
                ErrorInfo = LanguageManager.GetLang().St1305_FateBackpackFull;
                return false;
            }
            else
            {
                if (!CrystalHelper.CheckAllowCrystall(ContextUser))
                {
                    ErrorCode = errorNum;
                    ErrorInfo = LanguageManager.GetLang().St1305_FateBackpackFull;
                    return false;
                }
            }

            ProbabilityInfo probabilityInfo = null;
            if (ops == 1)
            {
                #region
                opType = 1;
                UserDailyRestrain userRestrain = new GameDataCacheSet<UserDailyRestrain>().FindKey(ContextUser.UserID);
                probabilityInfo = new ConfigCacheSet<ProbabilityInfo>().FindKey(huntingID); //当前猎命人物的概率
                if (probabilityInfo == null)
                {
                    return false;
                }
                ProbabilityInfo probability1 = new ConfigCacheSet<ProbabilityInfo>().FindKey(huntingID2);
                if (userRestrain != null && userRestrain.Funtion2 >= VipHelper.GetVipUseNum(ContextUser.VipLv, RestrainType.MianFeiLieMing) && DateTime.Now.Date == userRestrain.RefreshDate.Date)
                {
                    if (probabilityInfo.Price > ContextUser.GameCoin)
                    {
                        ErrorCode = errorNum;
                        ErrorInfo = LanguageManager.GetLang().St_GameCoinNotEnough;
                        return false;
                    }
                }
                //暑期第三弹
                if (huntingID2 == 1001 && !NoviceHelper.IsGianCrystalPack(ContextUser))
                {
                    ErrorCode = errorNum;
                    ErrorInfo = LanguageManager.GetLang().St1305_BeiBaoBackpackFull;
                    return false;
                }
                var lightCacheSet = new GameDataCacheSet<UserLight>();
                if (huntingID != 1001)
                {
                    UserLight userLight1 = lightCacheSet.FindKey(ContextUser.UserID, huntingID);
                    if (userLight1.IsLight == 2)
                    {
                        ErrorCode = LanguageManager.GetLang().ErrorCode;
                        return false;
                    }

                    if (userLight1.IsLight == 1)
                    {
                        userLight1.IsLight = 2;
                        //userLight1.Update();
                    }
                }
                UserLight userLight = new GameDataCacheSet<UserLight>().FindKey(ContextUser.UserID, huntingID2);
                if (RandomUtils.IsHit(probability1.Light))
                {
                    ErrorCode = ErrorCode;
                    ErrorInfo = probability1.HuntingName;

                    if (userLight != null)
                    {
                        userLight.IsLight = 1;
                        //userLight.Update();
                    }
                    else
                    {
                        userLight = new UserLight()
                        {
                            UserID = ContextUser.UserID,
                            HuntingID = huntingID2,
                            IsLight = 1
                        };
                        lightCacheSet.Add(userLight);
                    }
                }

                if (userRestrain != null)
                {
                    if (userRestrain.Funtion2 >= VipHelper.GetVipUseNum(ContextUser.VipLv, RestrainType.MianFeiLieMing) && DateTime.Now.Date == userRestrain.RefreshDate.Date)
                    {
                        ContextUser.GameCoin = MathUtils.Subtraction(ContextUser.GameCoin, probabilityInfo.Price, 0);
                        //ContextUser.Update();
                    }
                    else
                    {
                        userRestrain.Funtion2 = MathUtils.Addition(userRestrain.Funtion2, 1, int.MaxValue);
                        //userRestrain.Update();
                    }
                }
                else
                {
                    ContextUser.GameCoin = MathUtils.Subtraction(ContextUser.GameCoin, probabilityInfo.Price, 0);
                    //ContextUser.Update();
                }

                lightArray = new GameDataCacheSet<UserLight>().FindAll(ContextUser.UserID);
                #endregion
            }
            else if (ops == 2)
            {
                #region
                opType = 2;
                if (ContextUser.VipLv < 5)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St_VipNotEnough;
                    return false;
                }

                probabilityInfo = new ConfigCacheSet<ProbabilityInfo>().FindKey(huntingID); //当前猎命人物的概率
                if (probabilityInfo == null)
                {
                    return false;
                }

                if (ContextUser.GoldNum < probabilityInfo.Price)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough;
                    return false;
                }
                UserLight uLightInfo = new GameDataCacheSet<UserLight>().FindKey(ContextUser.UserID, probabilityInfo.GoldHunting);
                if (uLightInfo != null && uLightInfo.IsLight == 1)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St1305_HuntingIDLight;
                    return false;
                }
                else if (uLightInfo != null && (uLightInfo.IsLight == 2 || uLightInfo.IsLight == 0))
                {
                    uLightInfo.IsLight = 1;
                }
                else
                {
                    uLightInfo = new UserLight()
                    {
                        UserID = ContextUser.UserID,
                        HuntingID = probabilityInfo.GoldHunting,
                        IsLight = 1
                    };
                    new GameDataCacheSet<UserLight>().Add(uLightInfo);
                }

                ContextUser.UseGold = MathUtils.Addition(ContextUser.UseGold, probabilityInfo.Price, int.MaxValue);
                lightArray = new GameDataCacheSet<UserLight>().FindAll(ContextUser.UserID);
                #endregion
            }

            //每种品质的概率
            double[] probabilityArray2 = { (double)probabilityInfo.Gray, (double)probabilityInfo.Green, (double)probabilityInfo.Blue, (double)probabilityInfo.Purple, (double)probabilityInfo.Yellow, (double)probabilityInfo.Red };
            int index2 = RandomUtils.GetHitIndex(probabilityArray2);
            CrystalQualityType qualityType = (CrystalQualityType)Enum.Parse(typeof(CrystalQualityType), (index2 + 1).ToString());
            List<CrystalInfo> crystalArray2 = new ConfigCacheSet<CrystalInfo>().FindAll(u => u.CrystalQuality == qualityType && u.DemandLv <= ContextUser.UserLv);
            if (crystalArray2.Count > 0)
            {
                int randomNum = RandomUtils.GetRandom(0, crystalArray2.Count);
                crystal = new ConfigCacheSet<CrystalInfo>().FindKey(crystalArray2[randomNum].CrystalID);
                if (crystal != null && crystal.CrystalQuality == CrystalQualityType.Gray)
                {
                    //wuzf修改 8-15 灰色放在临时背包不存DB
                    CrystalHelper.AppendGrayCrystal(ContextUser, crystal.CrystalID);
                }
                else if (crystal != null)
                {
                    var package = UserCrystalPackage.Get(Uid);

                    UserCrystalInfo userCrystal = new UserCrystalInfo()
                    {
                        UserCrystalID = Guid.NewGuid().ToString(),
                        CrystalID = crystal.CrystalID,
                        CrystalLv = 1,
                        CurrExprience = 0,
                        GeneralID = 0,
                        IsSale = 1,
                        CreateDate = DateTime.Now
                    };
                    package.SaveCrystal(userCrystal);
                    UserLogHelper.AppenCtystalLog(ContextUser.UserID, opType, crystal.CrystalID, probabilityInfo.Price, probabilityInfo.Price, null, 1, 0);
                    //高品质聊天通知);
                    if (crystal.CrystalQuality >= CrystalQualityType.Yellow)
                    {
                        var cacheChat = new TjxChatService();
                        string content = string.Format(LanguageManager.GetLang().St1305_HighQualityNotice,
                            ContextUser.NickName,
                           CrystalHelper.GetQualityName(crystal.CrystalQuality),
                            crystal.CrystalName
                            );
                        cacheChat.SystemSend(ChatType.World, content);
                    }
                }
            }

            //日常任务-猎命
            TaskHelper.TriggerDailyTask(Uid, 4009);
            return true;
        }
Esempio n. 3
0
 /// <summary>
 /// 获得物品
 /// </summary>
 /// <param name="userInfo"></param>
 /// <param name="prize"></param>
 /// <returns></returns>
 public bool DoPrize(GameUser userInfo, List<PrizeInfo> prizeList)
 {
     try
     {
         bool isDeduct = false;
         int crystalNum = 0;
         CrystalInfo crystal = new CrystalInfo();
         content = LanguageManager.GetLang().St_SummerThreeGameCoinNotice.Substring(0, 5);
         foreach (PrizeInfo prize in prizeList)
         {
             int num = prize.Num;
             switch (prize.Type)
             {
                 case RewardType.GameGoin:
                     userInfo.GameCoin = MathUtils.Addition(userInfo.GameCoin, num);
                     if (content.Length == 0)
                         content = string.Format(LanguageManager.GetLang().St_SummerThreeGameCoinNotice, num);
                     else
                         content += string.Format(LanguageManager.GetLang().St_GameCoin, num) + ",";
                     break;
                 case RewardType.Obtion:
                     userInfo.ObtainNum = MathUtils.Addition(userInfo.ObtainNum, num);
                     if (content.Length == 0)
                         content = string.Format(LanguageManager.GetLang().St_SummerThreeObtionNotice, num);
                     else
                         content += string.Format(LanguageManager.GetLang().St_ObtionNum, num) + ",";
                     break;
                 case RewardType.ExpNum:
                     userInfo.ExpNum = MathUtils.Addition(userInfo.ExpNum, num);
                     if (content.Length == 0)
                         content = string.Format(LanguageManager.GetLang().St_SummerThreeExpNumNotice, num);
                     else
                         content += string.Format(LanguageManager.GetLang().St_ExpNum, num) + ",";
                     break;
                 case RewardType.EnergyNum:
                     userInfo.EnergyNum = MathUtils.Addition(userInfo.EnergyNum, (short)num, short.MaxValue);
                     if (content.Length == 0)
                         content = string.Format(LanguageManager.GetLang().St_SummerThreeEnergyNotice, num);
                     else
                         content += string.Format(LanguageManager.GetLang().St_EnergyNum, num) + ",";
                     break;
                 case RewardType.Experience:
                     UserHelper.UserGeneralExp(userInfo.UserID, num);
                     if (content.Length == 0)
                         content = string.Format(LanguageManager.GetLang().St_SummerThreeExperienceNotice, num);
                     else
                         content += string.Format(LanguageManager.GetLang().St_Experience, num) + ",";
                     break;
                 case RewardType.Gold:
                     userInfo.ItemGold = MathUtils.Addition(userInfo.ItemGold, num);
                     if (content.Length == 0)
                         content = string.Format(LanguageManager.GetLang().St_SummerThreeGoldNotice, num);
                     else
                         content += string.Format(LanguageManager.GetLang().St_GiftGoldNum, num) + ",";
                     break;
                 case RewardType.Item:
                     if (UserHelper.IsBeiBaoFull(userInfo))
                     {
                         content = LanguageManager.GetLang().St1107_GridNumFull;
                         return false;
                     }
                     UserItemHelper.AddUserItem(userInfo.UserID, prize.ItemID, num);
                     ItemBaseInfo itemInfo = new ConfigCacheSet<ItemBaseInfo>().FindKey(prize.ItemID);
                     if (itemInfo != null)
                     {
                         if (content.Length == 0)
                             content = string.Format(LanguageManager.GetLang().St_SummerThreeItemNotice, num);
                         else
                             content += string.Format("{0}*{1}", itemInfo.ItemName, num) + ",";
                     }
                     break;
                 case RewardType.CrystalType:
                     if (!UserCrystalInfo.CheckFull(userInfo.UserID, 0))
                     {
                         content = LanguageManager.GetLang().St1307_FateBackpackFull;
                         return false;
                     }
                     List<CrystalInfo> crystalArray2 = new ConfigCacheSet<CrystalInfo>().FindAll(m => m.CrystalQuality == prize.CrystalType);
                     if (crystalArray2.Count > 0)
                     {
                         int randomNum = RandomUtils.GetRandom(0, crystalArray2.Count);
                         int crystalID = crystalArray2[randomNum].CrystalID;
                         UserHelper.CrystalAppend(userInfo.UserID, crystalID, 2);
                         CrystalHelper.SendChat(crystalArray2[randomNum].CrystalID, userInfo);
                         crystal = new ConfigCacheSet<CrystalInfo>().FindKey(crystalID);
                         if (crystal != null)
                         {
                             content += string.Format(LanguageManager.GetLang().St_Crystal, CrystalHelper.GetQualityName(crystal.CrystalQuality), crystal.CrystalName) + ",";
                         }
                     }
                     else
                     {
                         TraceLog.WriteError("配置出错");
                         return false;
                     }
                     break;
                 case RewardType.CrystalId:
                     if (!UserCrystalInfo.CheckFull(userInfo.UserID, 0))
                     {
                         content = LanguageManager.GetLang().St1307_FateBackpackFull;
                         return false;
                     }
                     UserHelper.CrystalAppend(userInfo.UserID, prize.ItemID, 2);
                     CrystalHelper.SendChat(prize.ItemID, userInfo);
                     crystal = new ConfigCacheSet<CrystalInfo>().FindKey(prize.ItemID);
                     if (crystal != null)
                     {
                         content += string.Format(LanguageManager.GetLang().St_Crystal, CrystalHelper.GetQualityName(crystal.CrystalQuality), crystal.CrystalName) + ",";
                     }
                     break;
                 case RewardType.Spare:
                     int currNum = userInfo.SparePartList.FindAll(m => string.IsNullOrEmpty(m.UserItemID)).Count;
                     if (currNum >= userInfo.UserExtend.SparePartGridNum)
                     {
                         content = LanguageManager.GetLang().St1213_GridNumFull;
                         return false;
                     }
                     UserSparePart sparePart = UserSparePart.GetRandom(prize.ItemID);
                     SparePartInfo partInfo = new ConfigCacheSet<SparePartInfo>().FindKey(prize.ItemID);
                     if (partInfo != null && sparePart != null && UserHelper.AddSparePart(userInfo, sparePart))
                     {
                         SendChat(prize, userInfo.NickName, partInfo.Name);
                     }
                     content = string.Empty;
                     break;
                 default:
                     break;
             }
             if (prize.Reward == 3 && !string.IsNullOrEmpty(prize.Desc))
             {
                 content = prize.Desc;
             }
             //原因:开启礼包消耗的物品
             if (prize.DemandItem > 0 && !isDeduct)
             {
                 UserItemHelper.UseUserItem(userInfo.UserID, prize.DemandItem, prize.DemandNum);
                 isDeduct = true;
             }
         }
         return true;
     }
     catch (Exception ex)
     {
         content = "使用礼包出错!";
         TraceLog.WriteError("使用礼包出错!", ex);
     }
     return false;
 }