コード例 #1
0
        public bool deleteCards(MWServer server, MWUser user, string cname, int maxnum)
        {
            try
            {
                if (maxnum <= 0)
                {
                    return(false);
                }
                List <MWItem> deleteItems = new List <MWItem>();
                foreach (var card in user.cards)
                {
                    if (card.name == cname)
                    {
                        deleteItems.Add(card);
                        if (deleteItems.Count >= maxnum)
                        {
                            break;
                        }
                    }
                }
                int  dnum   = deleteItems.Count;
                uint dmoney = 0;
                foreach (var item in deleteItems)
                {
                    dmoney += user.deleteCard(item);
                }

                string res = "";
                if (dnum <= 0)
                {
                    // no cards
                    res = $"你手里没有 {cname} 卡";
                }
                else
                {
                    btc.getUser(user.userid).addMoney(dmoney);
                    if (dnum < maxnum)
                    {
                        res = $"你卖掉了全部{dnum}张 {cname} 卡,获得{dmoney}{BTCActor.unitName}";
                    }
                    else
                    {
                        res = $"你卖掉了{dnum}张 {cname} 卡,获得{dmoney}{BTCActor.unitName}";
                    }
                }
                outputMessage(server.group, user.userid, res.Trim());
                savePlayData();
            }
            catch (Exception ex)
            {
                FileIOActor.log(ex);
                return(false);
            }
            return(true);
        }
コード例 #2
0
        public bool deleteCardsByQuality(MWServer server, MWUser user, ulong maxquality)
        {
            try
            {
                if (maxquality <= 0)
                {
                    return(false);
                }
                Dictionary <string, List <MWItem> > deleteItems = new Dictionary <string, List <MWItem> >();
                foreach (var card in user.cards)
                {
                    if (card.quality <= maxquality)
                    {
                        if (!deleteItems.ContainsKey(card.name))
                        {
                            deleteItems[card.name] = new List <MWItem>();
                        }
                        deleteItems[card.name].Add(card);
                    }
                }
                uint   dmoney = 0;
                string res    = "";
                if (deleteItems.Count <= 0)
                {
                    // no cards
                    res = $"你手里没有 {maxquality}星或以下卡片";
                }
                else
                {
                    res = $"你卖掉了";
                    foreach (var itemp in deleteItems)
                    {
                        foreach (var item in itemp.Value)
                        {
                            dmoney += user.deleteCard(item);
                        }
                        res += $"{itemp.Value.Count}张{itemp.Key},";
                    }

                    btc.getUser(user.userid).addMoney(dmoney);
                    res += $"获得{dmoney}{BTCActor.unitName}";
                }
                outputMessage(server.group, user.userid, res.Trim());
                savePlayData();
            }
            catch (Exception ex)
            {
                FileIOActor.log(ex);
                return(false);
            }
            return(true);
        }