Example #1
0
        public override bool TakeAction()
        {
            ErrorCode = _ops;
            var sparePart     = ContextUser.SparePartList.Find(m => m.UserSparepartID.Equals(_sparepartID));
            var sparePartInfo = new ConfigCacheSet <SparePartInfo>().FindKey(sparePart.SparePartId);

            var reset = sparePartInfo.GetSparePartReset(_partPropertys.Length);

            if (_ops == 1)
            {
                ErrorInfo = string.Format(LanguageManager.GetLang().St1214_ResetUseLingshi, reset.Lingshi, reset.Coin);
            }
            else if (_ops == 2)
            {
                if (reset.Lingshi > ContextUser.UserExtend.LingshiNum)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St_LingshiNumNotEnough;
                    return(false);
                }
                if (reset.Coin > ContextUser.GameCoin)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St_GameCoinNotEnough;
                    return(false);
                }
                if (reset.Lingshi <= ContextUser.UserExtend.LingshiNum)
                {
                    ResetProperty();
                    ContextUser.UserExtend.UpdateNotify(obj =>
                    {
                        ContextUser.UserExtend.LingshiNum = MathUtils.Subtraction(ContextUser.UserExtend.LingshiNum, reset.Lingshi, 0);
                        return(true);
                    });
                    ContextUser.GameCoin = MathUtils.Subtraction(ContextUser.GameCoin, reset.Coin, 0);
                    //ContextUser.Update();
                }
                UserLogHelper.AppendSparePartLog(ContextUser.UserID, sparePart, 4);
            }
            else if (_ops == 3)
            {
                ErrorInfo = string.Format(LanguageManager.GetLang().St1214_ResetUseGold, reset.Gold, reset.Coin);
            }
            else if (_ops == 4)
            {
                if (reset.Gold > ContextUser.GoldNum)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St_GoldNotEnough;
                    return(false);
                }
                if (reset.Coin > ContextUser.GameCoin)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St_GameCoinNotEnough;
                    return(false);
                }
                if (reset.Gold <= ContextUser.GoldNum && reset.Coin <= ContextUser.GameCoin)
                {
                    ResetProperty();
                    ContextUser.UseGold  = MathUtils.Addition(ContextUser.UseGold, reset.Gold);
                    ContextUser.GameCoin = MathUtils.Subtraction(ContextUser.GameCoin, reset.Coin);
                    //ContextUser.Update();
                }
                UserLogHelper.AppendSparePartLog(ContextUser.UserID, sparePart, 5);
            }
            return(true);
        }
Example #2
0
        public override bool TakeAction()
        {
            ErrorCode = _ops;
            //1:镶嵌 2:卸下 3:出售
            if (_ops == 1)
            {
                if (string.IsNullOrEmpty(_userItemID))
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    return(false);
                }
                UserSparePart[] sparePartsArray = ContextUser.SparePartList.FindAll(m => m.UserItemID.Equals(_userItemID)).ToArray();
                if (sparePartsArray.Length > 0)
                {
                    //原因:装备上镶嵌超出开启位置数量的灵件
                    if (ContextUser.UserExtend != null)
                    {
                        if (_position > ContextUser.UserExtend.MaxLayerNum)
                        {
                            ErrorCode = LanguageManager.GetLang().ErrorCode;
                            ErrorInfo = LanguageManager.GetLang().St1213_GridNumNotEnough;
                            return(false);
                        }
                        if (sparePartsArray.Length >= ContextUser.UserExtend.MaxLayerNum)
                        {
                            ErrorCode = LanguageManager.GetLang().ErrorCode;
                            ErrorInfo = LanguageManager.GetLang().St1213_OpenNumNotEnough;
                            return(false);
                        }
                    }
                    foreach (UserSparePart part in sparePartsArray)
                    {
                        if (part.Position == _position)
                        {
                            ErrorCode = LanguageManager.GetLang().ErrorCode;
                            ErrorInfo = LanguageManager.GetLang().St1213_GridPotionFull;
                            return(false);
                        }
                    }
                }

                var sparePart = ContextUser.SparePartList.Find(m => m.UserSparepartID.Equals(_sparepartID));
                if (sparePart != null && string.IsNullOrEmpty(sparePart.UserItemID))
                {
                    sparePart.UpdateNotify(obj =>
                    {
                        sparePart.UserItemID = _userItemID;
                        sparePart.SetPosition(_position);
                        return(true);
                    });
                    UserLogHelper.AppendSparePartLog(ContextUser.UserID, sparePart, 3);
                    //ContextUser.UpdateSparePart();

                    var          package  = UserItemPackage.Get(Uid);
                    UserItemInfo userItem = package.ItemPackage.Find(m => !m.IsRemove && m.UserItemID.Equals(sparePart.UserItemID));
                    if (userItem != null && userItem.ItemStatus.Equals(ItemStatus.YongBing))
                    {
                        var userGeneral = new GameDataCacheSet <UserGeneral>().FindKey(Uid, userItem.GeneralID);
                        if (userGeneral != null)
                        {
                            userGeneral.RefreshMaxLife();
                        }
                    }
                }
            }
            else if (_ops == 2)
            {
                int currNum = ContextUser.SparePartList.FindAll(m => string.IsNullOrEmpty(m.UserItemID)).Count;
                if (currNum >= ContextUser.UserExtend.SparePartGridNum)
                {
                    ErrorCode = LanguageManager.GetLang().ErrorCode;
                    ErrorInfo = LanguageManager.GetLang().St1213_GridNumFull;
                    return(false);
                }
                var sparePart = ContextUser.SparePartList.Find(m => m.UserSparepartID.Equals(_sparepartID));
                if (sparePart != null && !string.IsNullOrEmpty(sparePart.UserItemID))
                {
                    var          package  = UserItemPackage.Get(Uid);
                    UserItemInfo userItem = package.ItemPackage.Find(m => !m.IsRemove && m.UserItemID.Equals(sparePart.UserItemID));

                    sparePart.UpdateNotify(obj =>
                    {
                        sparePart.SetPosition(0);
                        sparePart.UserItemID = string.Empty;
                        return(true);
                    });
                    UserLogHelper.AppendSparePartLog(ContextUser.UserID, sparePart, 3);
                    if (userItem != null && userItem.ItemStatus.Equals(ItemStatus.YongBing))
                    {
                        var userGeneral = new GameDataCacheSet <UserGeneral>().FindKey(Uid, userItem.GeneralID);
                        if (userGeneral != null)
                        {
                            userGeneral.RefreshMaxLife();
                        }
                    }
                }
            }
            else if (_ops == 3)
            {
                var sparePart = ContextUser.SparePartList.Find(m => m.UserSparepartID.Equals(_sparepartID));
                if (sparePart != null)
                {
                    var sparePartInfo = new ConfigCacheSet <SparePartInfo>().FindKey(sparePart.SparePartId) ?? new SparePartInfo();
                    ContextUser.GameCoin = MathUtils.Addition(ContextUser.GameCoin, sparePartInfo.CoinPrice);
                    ContextUser.UserExtend.UpdateNotify(obj =>
                    {
                        ContextUser.UserExtend.LingshiNum = MathUtils.Addition(ContextUser.UserExtend.LingshiNum, sparePartInfo.LingshiPrice);
                        return(true);
                    });
                    UserLogHelper.AppendSparePartLog(ContextUser.UserID, sparePart, 2);
                    ContextUser.RemoveSparePart(sparePart);
                    //ContextUser.Update();
                }
            }
            return(true);
        }