Example #1
0
        public static bool CheckItemOut(GameUser user, ItemStatus itemStatus, int gridNum)
        {
            if (user == null)
            {
                return(false);
            }
            int gridMaxNum = 0;

            if (itemStatus == ItemStatus.BeiBao)
            {
                gridMaxNum = user.GridNum;
            }
            else if (itemStatus == ItemStatus.CangKu)
            {
                gridMaxNum = user.WarehouseNum;
            }

            var package     = UserItemPackage.Get(user.UserID);
            var itemList    = package.ItemPackage.FindAll(m => !m.IsRemove && m.ItemStatus.Equals(itemStatus));
            int currGridNum = gridMaxNum - itemList.Count;

            //原因:物品数量等于开启格子时提示背包已满
            if (gridNum > 0)
            {
                return(currGridNum < gridNum);
            }
            return(currGridNum <= gridNum);
        }
Example #2
0
        /// <summary>
        /// 检查物品
        /// </summary>
        /// <returns></returns>
        public static int CheckItemNum(string userID, int itemID)
        {
            int result    = 0;
            var package   = UserItemPackage.Get(userID);
            var userItems = package.ItemPackage.FindAll(m => !m.IsRemove && m.ItemID == itemID);

            foreach (var userItem in userItems)
            {
                result += userItem.Num;
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// 以玩家物品ID取出物品ID
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="userItemID"></param>
        /// <returns></returns>
        public static int GetUserItemInfoID(string userID, string userItemID)
        {
            var package = UserItemPackage.Get(userID);

            if (package != null)
            {
                var useritem = package.ItemPackage.Find(s => !s.IsRemove && s.UserItemID == userItemID);
                if (useritem != null)
                {
                    return(useritem.ItemID);
                }
            }
            return(0);
        }
Example #4
0
        /// <summary>
        /// 当前物品的数量
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="itemID"></param>
        /// <returns></returns>
        public static int UserItemNum(string userID, int itemID)
        {
            int itemNum = 0;
            var package = UserItemPackage.Get(userID);

            if (package != null)
            {
                var useritem = package.ItemPackage.FindAll(s => !s.IsRemove && s.ItemID == itemID);
                foreach (var item in useritem)
                {
                    itemNum += item.Num;
                }
            }
            return(itemNum);
        }
Example #5
0
        /// <summary>
        /// 传入仓库或取出物品后合并物品
        /// </summary>
        public static void MergerUserItem(string userID, string userItemID, ItemStatus itemStatus)
        {
            var          package  = UserItemPackage.Get(userID);
            UserItemInfo userItem = package.ItemPackage.Find(m => !m.IsRemove && string.Equals(m.UserItemID, userItemID));

            if (userItem != null)
            {
                ItemBaseInfo itemInfo = new ConfigCacheSet <ItemBaseInfo>().FindKey(userItem.ItemID);
                if (itemInfo == null)
                {
                    return;
                }
                if (userItem.Num == itemInfo.PackMaxNum)
                {
                    userItem.ItemStatus = itemStatus;
                    package.SaveItem(userItem);
                }
                else
                {
                    int itemNum   = userItem.Num;
                    var itemArray = package.ItemPackage.FindAll(u => !u.IsRemove && u.ItemID == userItem.ItemID && u.ItemStatus.Equals(itemStatus));
                    foreach (var item in itemArray)
                    {
                        if (item.Num < itemInfo.PackMaxNum)
                        {
                            int subNum = MathUtils.Subtraction(itemInfo.PackMaxNum, item.Num, 0);
                            item.Num = MathUtils.Addition(item.Num, itemNum, itemInfo.PackMaxNum);
                            itemNum  = MathUtils.Subtraction(itemNum, subNum, 0);
                            package.SaveItem(item);
                            //item.Update();
                        }
                    }
                    if (itemNum > 0)
                    {
                        userItem.Num        = itemNum;
                        userItem.ItemStatus = itemStatus;
                        package.SaveItem(userItem);
                    }
                    else
                    {
                        AddItemLog(userID, userItem.ItemID, itemNum, userItem.ItemLv, 7, userItemID);

                        package.RemoveItem(userItem);
                    }
                }
            }
        }
Example #6
0
        public static bool IsEnoughBeiBaoItem(string userID, int itemID, int itemNum)
        {
            int maxNum   = 0;
            var package  = UserItemPackage.Get(userID);
            var itemList = package.ItemPackage.FindAll(
                m => !m.IsRemove && m.ItemStatus.Equals(ItemStatus.BeiBao) &&
                m.ItemID == itemID && m.IsNotUsed);

            foreach (var userItem in itemList)
            {
                maxNum = MathUtils.Addition(maxNum, userItem.Num, int.MaxValue);
            }
            if (maxNum >= itemNum)
            {
                return(true);
            }
            return(false);
        }
Example #7
0
        private int GetMaxLife()
        {
            int      genLv     = 0;
            int      currMaxLv = 0;
            GameUser userinfo  = new GameDataCacheSet <GameUser>().FindKey(UserID);

            if (userinfo != null)
            {
                currMaxLv = userinfo.UserLv;
            }
            if (currMaxLv > 0 && GeneralLv > currMaxLv)
            {
                genLv = userinfo.UserLv;
            }
            else
            {
                genLv = GeneralLv;
            }
            //��ʼ����+(�ȼ�-1)*ְҵ�ӳ� + װ������+����ˮ������+ħ����������+������+��ħ����
            int        lifeNum    = 0;
            CareerInfo careerInfo = new ConfigCacheSet <CareerInfo>().FindKey(CareerID);

            if (careerInfo == null)
            {
                return(lifeNum);
            }
            var tempLv = MathUtils.Subtraction(genLv, 1, 0);

            if (IsUserGeneral)
            {
                lifeNum = MathUtils.Addition(careerInfo.LifeNum, careerInfo.LifeIncreaseNum * tempLv, int.MaxValue);
            }
            else
            {
                GeneralInfo generalInfo = new ConfigCacheSet <GeneralInfo>().FindKey(GeneralID);
                if (generalInfo != null)
                {
                    lifeNum = MathUtils.Addition(generalInfo.LifeNum, careerInfo.LifeIncreaseNum * tempLv, int.MaxValue);
                }
            }
            //����ˮ������
            var packageCrystal = UserCrystalPackage.Get(UserID);

            if (packageCrystal != null && packageCrystal.CrystalPackage != null)
            {
                UserCrystalInfo[] crystalList = packageCrystal.CrystalPackage.FindAll(m => m.GeneralID.Equals(GeneralID)).ToArray();
                foreach (UserCrystalInfo item in crystalList)
                {
                    short upLv = 0;
                    if (item.CrystalLv < 10)
                    {
                        upLv = item.CrystalLv; //item.CrystalLv.Addition(1, short.MaxValue);
                    }
                    else
                    {
                        upLv = 10;
                    }
                    //AbilityType abilityType = new ConfigCacheSet<CrystalInfo>().FindKey(item.CrystalID).AbilityID;
                    var           cacheSetCrystal = new ConfigCacheSet <CrystalInfo>();
                    var           crystalInfo     = cacheSetCrystal.FindKey(item.CrystalID);
                    AbilityType   abilityType     = crystalInfo != null ? crystalInfo.AbilityID : AbilityType.AttackLife;
                    decimal       effectNum       = 0;
                    CrystalLvInfo lvInfo          = new ConfigCacheSet <CrystalLvInfo>().FindKey(item.CrystalID, upLv);
                    if (lvInfo != null)
                    {
                        effectNum = lvInfo.AbilityNum;
                    }
                    if (abilityType == AbilityType.ShengMing)
                    {
                        lifeNum = MathUtils.Addition(lifeNum, effectNum.ToInt(), int.MaxValue);
                    }
                }
            }
            //װ������
            var package = UserItemPackage.Get(UserID);

            if (package != null && package.ItemPackage != null)
            {
                var equList = package.ItemPackage.FindAll(m => !m.IsRemove && m.GeneralID.Equals(GeneralID) && m.ItemStatus.Equals(ItemStatus.YongBing));
                foreach (var item in equList)
                {
                    ItemEquAttrInfo equAttr = new ConfigCacheSet <ItemEquAttrInfo>().FindKey(item.ItemID, AbilityType.ShengMing);
                    if (equAttr != null)
                    {
                        lifeNum = MathUtils.Addition(lifeNum, equAttr.GetEffectNum(item.ItemLv), int.MaxValue);
                    }
                    //���������
                    var user = new GameDataCacheSet <GameUser>().FindKey(UserID);
                    if (user != null && user.SparePartList != null && user.SparePartList.Count > 0)
                    {
                        var sparepartList = user.SparePartList.FindAll(m => string.Equals(m.UserItemID, item.UserItemID));
                        foreach (var sparepart in sparepartList)
                        {
                            foreach (var property in sparepart.Propertys)
                            {
                                if (property.AbilityType == AbilityType.ShengMing)
                                {
                                    lifeNum = MathUtils.Addition(lifeNum, property.Num.ToInt());
                                }
                            }
                        }
                    }
                }
            }
            //ħ������������������
            var userMagicList = new GameDataCacheSet <UserMagic>().FindAll(UserID, u => u.MagicID != 1);

            foreach (UserMagic item in userMagicList)
            {
                //�����󷨵ȼ�Ϊ10��
                int mlv = 0;
                if (item.MagicType == MagicType.MoFaZhen && item.MagicLv > 10)
                {
                    mlv = 10;
                }
                else if (item.MagicType == MagicType.JiNeng && item.MagicLv > currMaxLv)
                {
                    mlv = currMaxLv;
                }
                else
                {
                    mlv = item.MagicLv;
                }
                MagicLvInfo magicLvItem = new ConfigCacheSet <MagicLvInfo>().FindKey(item.MagicID, mlv);

                if (magicLvItem != null && magicLvItem.AbilityType == AbilityType.ShengMing)
                {
                    int errNum = magicLvItem.EffectNum.ToInt();
                    lifeNum = MathUtils.Addition(lifeNum, errNum, int.MaxValue);
                }
            }
            // Ӷ���øжȵȼ��ӳ�����
            FeelLvInfo fellLvInfo = new ConfigCacheSet <FeelLvInfo>().FindKey(FeelLv);

            if (fellLvInfo != null && fellLvInfo.Property != null)
            {
                GeneralProperty property = fellLvInfo.Property.Find(m => m.AbilityType.Equals(AbilityType.ShengMing));
                if (property != null)
                {
                    int effectNum = property.AbilityValue.ToInt();
                    lifeNum = MathUtils.Addition(lifeNum, effectNum, int.MaxValue);
                }
            }

            //���������ӳ�
            UserTrump userTrump = new GameDataCacheSet <UserTrump>().FindKey(UserID, TrumpInfo.CurrTrumpID);

            if (userTrump != null && userTrump.LiftNum > 0 && GeneralID == LanguageManager.GetLang().GameUserGeneralID)
            {
                TrumpInfo trumpInfo = new ConfigCacheSet <TrumpInfo>().FindKey(TrumpInfo.CurrTrumpID, userTrump.TrumpLv);
                if (trumpInfo != null && trumpInfo.Property != null && trumpInfo.Property.Count > 0)
                {
                    int             maxMatureNum = ConfigEnvSet.GetInt("Trump.MaxMatrueNum");
                    decimal         mature       = (decimal)userTrump.MatureNum / maxMatureNum;
                    GeneralProperty property     = trumpInfo.Property.Find(m => m.AbilityType == AbilityType.ShengMing);
                    if (property != null)
                    {
                        lifeNum = MathUtils.Addition(lifeNum, (int)Math.Floor(mature * property.AbilityValue));
                    }
                }

                if (userTrump.PropertyInfo.Count > 0)
                {
                    GeneralProperty property = userTrump.PropertyInfo.Find(m => m.AbilityType == AbilityType.ShengMing);
                    if (property != null)
                    {
                        lifeNum = MathUtils.Addition(lifeNum, (int)property.AbilityValue);
                    }
                }
            }

            //��ħ����
            var itempackage    = UserItemPackage.Get(UserID);
            var enchantPackage = UserEnchant.Get(UserID);

            if (itempackage != null && itempackage.ItemPackage != null && enchantPackage != null && enchantPackage.EnchantPackage != null)
            {
                var useritem = itempackage.ItemPackage.Find(m => !m.IsRemove && m.GeneralID == GeneralID && m.Equparts == EquParts.WuQi);
                if (useritem != null)
                {
                    var enchantList = enchantPackage.EnchantPackage.FindAll(m => m.UserItemID == useritem.UserItemID && m.AbilityType == AbilityType.ShengMing);
                    foreach (var info in enchantList)
                    {
                        EnchantLvInfo enchantLvInfo = new ConfigCacheSet <EnchantLvInfo>().FindKey(info.EnchantID, info.EnchantLv);
                        if (enchantLvInfo != null)
                        {
                            int     maxEnchantMature = ConfigEnvSet.GetInt("Enchant.MaxEnchantMature");
                            decimal growthrate       = enchantLvInfo.Num * info.MaxMature / maxEnchantMature * info.EnchantLv;
                            lifeNum = MathUtils.Addition(lifeNum, (int)growthrate);
                        }
                    }
                }
            }
            //Ӷ����������
            if (Attribute.Count > 0)
            {
                var generalPro = Attribute.Find(s => s.AbilityType == AbilityType.ShengMing);
                if (generalPro != null)
                {
                    lifeNum = MathUtils.Addition(lifeNum, generalPro.AbilityValue.ToInt());
                }
            }

            return(lifeNum);
        }
Example #8
0
        /// <summary>
        /// 使用物品
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="itemID"></param>
        /// <param name="itemNum"></param>
        /// <returns>false:物品不够</returns>
        public static bool UseUserItem(string userID, int itemID, int itemNum)
        {
            var          loger    = new BaseLog();
            bool         result   = false;
            ItemBaseInfo itemInfo = new ConfigCacheSet <ItemBaseInfo>().FindKey(itemID);

            if (itemInfo == null)
            {
                return(result);
            }
            var package = UserItemPackage.Get(userID);

            AddItemLog(userID, itemID, itemNum, 1, 2, itemID.ToString());

            int packNum = itemNum / itemInfo.PackMaxNum;
            int num     = itemNum % itemInfo.PackMaxNum;

            var itemList = new List <UserItemInfo>();

            if (IsEnoughBeiBaoItem(userID, itemID, itemNum))
            {
                itemList = package.ItemPackage.FindAll(m => !m.IsRemove && m.ItemID == itemID && m.IsNotUsed && m.ItemStatus == ItemStatus.BeiBao);
            }
            else
            {
                itemList = package.ItemPackage.FindAll(m => !m.IsRemove && m.ItemID == itemID && m.IsNotUsed && m.ItemStatus != ItemStatus.Sell);
            }

            List <UserItemInfo> removeItem = new List <UserItemInfo>();
            List <UserItemInfo> updateItem = new List <UserItemInfo>();
            UserItemInfo        packItem   = null;

            foreach (UserItemInfo item in itemList)
            {
                if (packNum > 0 && item.Num == itemInfo.PackMaxNum)
                {
                    //删除整包的
                    item.Num = 0;
                    package.SaveItem(item);
                    removeItem.Add(item);
                    //package.ItemPackage.UpdateChildren(item, obj =>
                    //{
                    //    obj.Num = 0;
                    //    removeItem.Add(obj);
                    //});
                    packNum--;
                }
                else if (num > 0 && item.Num < itemInfo.PackMaxNum)
                {
                    //删除散的
                    if (item.Num > num)
                    {
                        item.Num = MathUtils.Subtraction(item.Num, num, 0);
                        num      = 0;
                        updateItem.Add(item);
                        package.SaveItem(item);
                    }
                    else
                    {
                        num      = MathUtils.Subtraction(num, item.Num, 0);
                        item.Num = 0;
                        removeItem.Add(item);
                        package.SaveItem(item);
                    }
                }
                else if (item.Num == itemInfo.PackMaxNum)
                {
                    //取剩余第一个整包
                    if (packItem == null)
                    {
                        packItem = item;
                    }
                }
            }
            //若散的不足再从整包中扣除
            if (num > 0 && packItem != null)
            {
                packItem.Num = MathUtils.Subtraction(packItem.Num, num, 0);
                num          = 0;
                package.SaveItem(packItem);
                updateItem.Add(packItem);
            }

            if (packNum == 0 && num == 0)
            {
                foreach (UserItemInfo item in removeItem)
                {
                    package.RemoveItem(item);
                }

                //foreach (UserItemInfo item in updateItem)
                //{
                //    package.DelayChange();
                //}
                result = true;
            }

            return(result);
        }
Example #9
0
        /// <summary>
        /// 增加物品
        /// </summary>
        public static void AddUserItem(string userID, int itemID, int itemNum, ItemStatus itemStatus, short itemLv, List <UniversalInfo> universalInfoList = null)
        {
            // 增加玩家集邮册
            AddUserAlbum(userID, itemID);

            var      chatService = new TjxChatService();
            GameUser user        = new GameDataCacheSet <GameUser>().FindKey(userID);

            ItemBaseInfo itemInfo = new ConfigCacheSet <ItemBaseInfo>().FindKey(itemID);

            if (user == null || itemInfo == null)
            {
                return;
            }
            AddUniversalInfo(universalInfoList, itemInfo, itemNum);

            if (itemInfo.ItemType == ItemType.DaoJu && itemInfo.PropType == 17)
            {
                for (int i = 0; i < itemNum; i++)
                {
                    if (!PackIsFull(userID, BackpackType.HunJi, 1))
                    {
                        AddUserAbility(itemInfo.EffectNum, userID.ToInt(), 0, 0);
                    }
                }
            }
            else
            {
                if (itemInfo.ItemType == ItemType.DaoJu && itemInfo.PropType == 20)
                {
                    AddGeneralSoul(userID, itemInfo.ItemID, itemNum);
                }
                else
                {
                    int gridMaxNum = 0;
                    if (itemInfo.ItemType == ItemType.ZhuangBei)
                    {
                        gridMaxNum = GetPackTypePositionNum(BackpackType.ZhuangBei, userID);
                    }
                    else
                    {
                        gridMaxNum = GetPackTypePositionNum(BackpackType.BeiBao, userID);
                    }
                    int packNum = itemNum / itemInfo.PackMaxNum;
                    int num     = itemNum % itemInfo.PackMaxNum;
                    ////判断背包是否有空位
                    //bool isOut = false;
                    //if (itemStatus == ItemStatus.BeiBao)
                    //{
                    //    isOut = CheckItemOut(user, itemStatus);
                    //}

                    var package  = UserItemPackage.Get(userID);
                    var itemList = package.ItemPackage.FindAll(m => !m.IsRemove && m.ItemStatus.Equals(ItemStatus.BeiBao));
                    //背包中是否有余
                    var packItemList = package.ItemPackage.FindAll(
                        m => !m.IsRemove && m.ItemStatus.Equals(itemStatus) &&
                        m.ItemID == itemID &&
                        m.Num < itemInfo.PackMaxNum);

                    //当前空位
                    int currGridNum = gridMaxNum - itemList.Count;
                    // if ((isOut && packItemList.Count == 0) || currGridNum < packNum)
                    if (packItemList.Count == 0 && currGridNum <= 0)
                    {
                        AddItemLog(userID, itemID, itemNum, 1, 0, null);
                        chatService.SystemSendWhisper(user, string.Format("掉落物品{0}*{1}", itemInfo.ItemName, itemNum));
                        return;
                    }
                    currGridNum = MathUtils.Subtraction(currGridNum, packNum, 0);

                    for (int i = 0; i < packNum; i++)
                    {
                        //增加整包
                        UserItemInfo userItem = new UserItemInfo();
                        string       uitemID  = SetUserItem(userItem, userID, itemInfo, itemStatus, itemLv);
                        userItem.Num = itemInfo.PackMaxNum;

                        package.SaveItem(userItem);
                        AddItemLog(userID, itemID, userItem.Num, userItem.ItemLv, 1, uitemID);
                    }
                    //背包中是否有余
                    foreach (var item in packItemList)
                    {
                        if (num == 0)
                        {
                            break;
                        }

                        int gridNum = itemInfo.PackMaxNum - item.Num;
                        int tempNum = gridNum > num ? num : gridNum;

                        item.Num = MathUtils.Addition(item.Num, tempNum, itemInfo.PackMaxNum);

                        package.SaveItem(item);
                        num = num > tempNum ? num - tempNum : 0;
                    }
                    //数据是否有余
                    if (num > 0)
                    {
                        if (currGridNum <= 0)
                        {
                            AddItemLog(userID, itemInfo.ItemID, num, 1, 0, null);
                            chatService.SystemSendWhisper(user, string.Format("掉落物品{0}*{1}", itemInfo.ItemName, num));
                        }
                        else
                        {
                            var    userItem = new UserItemInfo();
                            string uitemID  = SetUserItem(userItem, userID, itemInfo, itemStatus, itemLv);
                            userItem.Num = num;
                            package.SaveItem(userItem);

                            AddItemLog(userID, itemID, userItem.Num, userItem.ItemLv, 1, uitemID);
                        }
                    }
                }
            }
        }
Example #10
0
        public static List <UserItemInfo> GetItems(string userId)
        {
            var package = UserItemPackage.Get(userId);

            return(package.ItemPackage.FindAll(m => !m.IsRemove));
        }