Пример #1
0
 public bool getCards(MWServer server, MWUser user, int num = 1)
 {
     try
     {
         if (btc.getUser(user.userid).Money < server.pool.cost * num)
         {
             outputMessage(server.group, user.userid,
                           $"没{BTCActor.unitName}抽你🐎呢?{(num == 1 ? "单" : $"{num}连")}抽消耗{server.pool.cost * num}枚{BTCActor.unitName}"
                           );
         }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
0
        public void init(sendQQGroupMsgHandler _showScene, getQQNickHandler _getQQNick, BTCActor _btc, string _path)
        {
            outputMessage = _showScene;
            getQQNick     = _getQQNick;
            btc           = _btc;
            path          = _path;

            // init videos;
            var videofiles = Directory.GetFiles(path + videoPath, "*.txt");

            foreach (var vf in videofiles)
            {
                string name = Path.GetFileNameWithoutExtension(vf);
                videos[name] = new MWVideo(vf);
            }

            //LoopThread = new Thread(mainloop);
            //run = true;
            //LoopThread.Start();

            lock (dcardMutex)
            {
                // init cards
                var lines = FileIOActor.readLines(path + dcardPath + cardf, Encoding.UTF8);
                foreach (var line in lines)
                {
                    try
                    {
                        MWItem card = new MWItem();
                        card.parse(line);
                        if (!string.IsNullOrWhiteSpace(card.name))
                        {
                            cards[card.name] = card;
                        }
                    }
                    catch (Exception ex)
                    {
                        FileIOActor.log(ex);
                    }
                }

                // init pools
                lines = FileIOActor.readLines(path + dcardPath + poolf, Encoding.UTF8);
                foreach (var line in lines)
                {
                    try
                    {
                        MWItemPool pool = new MWItemPool(cards);
                        pool.parse(line);
                        if (!string.IsNullOrWhiteSpace(pool.name))
                        {
                            pools[pool.name] = pool;
                        }
                    }
                    catch (Exception ex)
                    {
                        FileIOActor.log(ex);
                    }
                }

                // init users
                lines = FileIOActor.readLines(path + dcardPath + userf, Encoding.UTF8);
                foreach (var line in lines)
                {
                    try
                    {
                        MWUser user = new MWUser(-1, cards);
                        user.parse(line);
                        if (user.userid > 0)
                        {
                            users[user.userid] = user;
                        }
                    }
                    catch (Exception ex)
                    {
                        FileIOActor.log(ex);
                    }
                }

                // init servers
                lines = FileIOActor.readLines(path + dcardPath + dcardserverf, Encoding.UTF8);
                foreach (var line in lines)
                {
                    try
                    {
                        MWServer server = new MWServer(this);
                        server.parse(line);
                        if (server.group > 0)
                        {
                            servers[server.group] = server;
                        }
                    }
                    catch (Exception ex)
                    {
                        FileIOActor.log(ex);
                    }
                }
            }
        }