示例#1
0
        public override bool TakeAction()
        {
            UserTrump userTrump = new GameDataCacheSet <UserTrump>().FindKey(ContextUser.UserID, TrumpInfo.CurrTrumpID);

            if (userTrump != null && userTrump.PropertyInfo.Count > 0)
            {
                GeneralProperty property = userTrump.PropertyInfo.Find(m => m.AbilityType == propertyID);
                if (property != null)
                {
                    if (property.AbilityLv >= TrumpPropertyInfo.MaxTrumpPropertyLv)
                    {
                        ErrorCode = LanguageManager.GetLang().ErrorCode;
                        ErrorInfo = LanguageManager.GetLang().St1466_OutPropertyMaxLv;
                        return(false);
                    }
                    TrumpPropertyInfo trumpProperty = new ConfigCacheSet <TrumpPropertyInfo>().FindKey(property.AbilityType, property.AbilityLv);
                    if (trumpProperty != null)
                    {
                        int upItemNum = TrumpHelper.GetUserItemNum(ContextUser.UserID, trumpProperty.ItemID);
                        if (upItemNum < trumpProperty.ItemNum)
                        {
                            ErrorCode = LanguageManager.GetLang().ErrorCode;
                            ErrorInfo = LanguageManager.GetLang().St1462_ItemNumNotEnough;
                            return(false);
                        }
                        if (ContextUser.GameCoin < trumpProperty.GameCoin)
                        {
                            ErrorCode = LanguageManager.GetLang().ErrorCode;
                            ErrorInfo = LanguageManager.GetLang().St_GameCoinNotEnough;
                            return(false);
                        }
                        if (ContextUser.ObtainNum < trumpProperty.ObtainNum)
                        {
                            ErrorCode = LanguageManager.GetLang().ErrorCode;
                            ErrorInfo = LanguageManager.GetLang().St_ObtainNumNotEnough;
                            return(false);
                        }
                        ContextUser.ObtainNum = MathUtils.Subtraction(ContextUser.ObtainNum, trumpProperty.ObtainNum);
                        ContextUser.GameCoin  = MathUtils.Subtraction(ContextUser.GameCoin, trumpProperty.GameCoin);
                        UserItemHelper.UseUserItem(ContextUser.UserID, trumpProperty.ItemID, trumpProperty.ItemNum);
                        short             upLv            = MathUtils.Addition(property.AbilityLv, (short)1, (short)TrumpPropertyInfo.MaxTrumpPropertyLv);
                        TrumpPropertyInfo uptrumpProperty = new ConfigCacheSet <TrumpPropertyInfo>().FindKey(property.AbilityType, upLv);
                        property.UpdateNotify(obj =>
                        {
                            property.AbilityLv    = MathUtils.Addition(property.AbilityLv, (short)1, TrumpPropertyInfo.MaxTrumpPropertyLv);
                            property.AbilityValue = uptrumpProperty.PropertyNum;
                            return(true);
                        });
                        var usergeneral = UserGeneral.GetMainGeneral(ContextUser.UserID);
                        if (usergeneral != null)
                        {
                            usergeneral.RefreshMaxLife();
                        }
                        ErrorCode = 0;
                        ErrorInfo = LanguageManager.GetLang().St1464_UpgradeWasSsuccessful;
                    }
                }
            }
            return(true);
        }