Example #1
0
 /// <summary>
 /// 药剂数量
 /// </summary>
 /// <param name="medicine"></param>
 /// <returns></returns>
 public static int GetGeneralMedicine(GeneralMedicine medicine)
 {
     var medicineArray = new PersonalCacheStruct<GeneralMedicine>().FindAll(medicine.UserID, u => u.MedicineID.Equals(medicine.MedicineID) && u.GeneralID == medicine.GeneralID);
     return medicineArray.Count;
 }
Example #2
0
        public override bool TakeAction()
        {
            ItemBaseInfo itemInfo = new ShareCacheStruct<ItemBaseInfo>().FindKey(medicineID);
            var userItemArray = UserItemHelper.GetItems(Uid).FindAll(u => (u.ItemStatus == ItemStatus.BeiBao || u.ItemStatus == ItemStatus.CangKu));
            if (userItemArray.Count == 0)
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St1407_MedicineNum;
                return false;
            }
            UserGeneral general = new PersonalCacheStruct<UserGeneral>().FindKey(ContextUser.UserID, generalID);
            if (general == null)
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St10006_DoesNotExistTheGeneral;
                return false;
            }
            if (itemInfo.DemandLv > general.GeneralLv)
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().St_LevelNotEnough;
                return false;
            }

            int sum = 0;
            short baseNum = 0;
            //佣兵服用ID为medicineID的丹药
            var generalMedicineArray = new PersonalCacheStruct<GeneralMedicine>().FindAll(ContextUser.UserID, g => g.MedicineID.Equals(medicineID) && g.GeneralID == generalID);
            if (generalMedicineArray.Count > 0)
            {
                int mLv = itemInfo.MedicineLv;
                int mNum = generalMedicineArray.Count;
                if (mLv == 1 && mNum >= 2 || mLv == 2 && mNum >= 3 || mLv == 3 && mNum >= 4 || mLv == 4 && mNum >= 5 || mLv == 5 && mNum >= 6 || mLv == 6 && mNum >= 7)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St1407_MedicineNumFull;
                    return false;
                }

                sum = mNum * 5; //
                baseNum = MathUtils.Subtraction(itemInfo.MedicineNum, (short)sum, (short)0);
            }
            else
            {
                baseNum = itemInfo.MedicineNum;
            }

            //vip
            int useGold = 0;
            int[] vipMeArray = { 30, 150, 300, 600, 1200, 2400 };
            for (int i = 1; i <= vipMeArray.Length; i++)
            {
                if (itemInfo.MedicineLv == i)
                {
                    useGold = vipMeArray[i - 1];
                }
            }

            if (ops == 0)
            {

                GeneralMedicine generalMedicine = new GeneralMedicine()
                {
                    GeneralMedicineID = Guid.NewGuid().ToString(),
                    UserID = ContextUser.UserID,
                    GeneralID = generalID,
                    MedicineID = medicineID,
                    BaseNum = (int)baseNum
                };
                var cacheSet = new PersonalCacheStruct<GeneralMedicine>();
                cacheSet.Add(generalMedicine);

                UserItemHelper.UseUserItem(ContextUser.UserID, itemInfo.ItemID, 1);

                if (itemInfo.MedicineType == 1)
                {
                    general.PowerNum = MathUtils.Addition(general.PowerNum, baseNum, short.MaxValue);
                }
                else if (itemInfo.MedicineType == 2)
                {
                    general.SoulNum = MathUtils.Addition(general.SoulNum, baseNum, short.MaxValue);
                }
                else if (itemInfo.MedicineType == 3)
                {
                    general.IntellectNum = MathUtils.Addition(general.IntellectNum, baseNum, short.MaxValue);
                }
                //general.Update();
            }
            else if (ops == 1)
            {
                ErrorCode = 1;
                ErrorInfo = string.Format(LanguageManager.GetLang().St1407_MedicineUseGold, useGold);
                return false;
            }
            else if (ops == 2)
            {
                if (ContextUser.GoldNum < useGold)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough;
                    return false;
                }

                GeneralMedicine generalMedicine = new GeneralMedicine()
                {
                    GeneralMedicineID = Guid.NewGuid().ToString(),
                    UserID = ContextUser.UserID,
                    GeneralID = generalID,
                    MedicineID = medicineID,
                    BaseNum = (int)baseNum
                };
                var cacheSet = new PersonalCacheStruct<GeneralMedicine>();
                cacheSet.Add(generalMedicine);

                ContextUser.UseGold = MathUtils.Addition(ContextUser.UseGold, useGold, int.MaxValue);
                //ContextUser.Update();

                if (itemInfo.MedicineType == 1)
                {
                    general.PowerNum = MathUtils.Addition(general.PowerNum, baseNum, short.MaxValue);
                }
                else if (itemInfo.MedicineType == 2)
                {
                    general.SoulNum = MathUtils.Addition(general.SoulNum, baseNum, short.MaxValue);
                }
                else if (itemInfo.MedicineType == 3)
                {
                    general.IntellectNum = MathUtils.Addition(general.IntellectNum, baseNum, short.MaxValue);
                }
                //general.Update();
            }
            else
            {
                ErrorCode = LanguageManager.GetLang().ErrorCode;
                ErrorInfo = LanguageManager.GetLang().UrlElement;
                return false;
            }
            return true;
        }