コード例 #1
0
ファイル: MarshRuler.cs プロジェクト: cenpengzhu/SuperMarsh
        //从数据库中读取
        private bool LoadFromDB()
        {
            var tempGiftValueList = SingleInstanceHelper.Instance.DBHelper.FindAll(SingleInstanceHelper.Instance.DBHelper.GiftValueCoName);

            if (tempGiftValueList == null || tempGiftValueList.Count == 0)
            {
            }
            else
            {
                foreach (var eachGiftValueBson in tempGiftValueList)
                {
                    var temp = new GiftValueModel();
                    temp.FromBson(eachGiftValueBson);
                    GiftValueList.Add(temp);
                }
            }

            var tempMarshList = SingleInstanceHelper.Instance.DBHelper.FindAll(SingleInstanceHelper.Instance.DBHelper.MarshRecordCoName);

            if (tempMarshList == null || tempMarshList.Count == 0)
            {
                MarshModel temp = new MarshModel();
                temp.TotalTime     = 3600;
                temp.StartTime     = TimeHelper.CurrentUnixTime();
                temp.TotalWeight   = 10;
                temp.CurrentRunner = "无";
                AllMarshs.Add(temp);
            }
            else
            {
                foreach (var eachMarsh in tempMarshList)
                {
                    var temp = new MarshModel();
                    temp.FromBson(eachMarsh);
                    AllMarshs.Add(temp);
                }
            }
            return(true);
        }
コード例 #2
0
ファイル: MarshRuler.cs プロジェクト: cenpengzhu/SuperMarsh
        //接受到弹幕
        public void ReceiveDanmu(object sender, ReceivedDanmakuArgs e)
        {
            if (e.Danmaku != null && (e.Danmaku.MsgType == MsgTypeEnum.GiftSend || e.Danmaku.MsgType == MsgTypeEnum.GuardBuy))
            {
                if (e.Danmaku.GiftCount > 0)
                {
                    //记录礼物价值
                    var            obj           = JObject.Parse(e.Danmaku.RawData);
                    GiftValueModel tempGiftValue = null;
                    if (GiftValueList.Count > 0)
                    {
                        tempGiftValue = GiftValueList.Find(r => r.GiftName.Equals(e.Danmaku.GiftName));
                    }
                    if (tempGiftValue == null)
                    {
                        tempGiftValue = new GiftValueModel()
                        {
                            GiftName  = e.Danmaku.GiftName,
                            Giftid    = obj["data"]["giftId"].ToObject <int>(),
                            GiftPrice = obj["data"]["price"].ToObject <double>(),
                        };
                        GiftValueList.Add(tempGiftValue);
                    }
                    //记录到数据库
                    var temp = BsonSerializer.Deserialize <BsonDocument>(e.Danmaku.RawData);
                    SingleInstanceHelper.Instance.DBHelper.Insert(SingleInstanceHelper.Instance.DBHelper.GiftRecordCoName, temp);
                    double Power = tempGiftValue.GiftPrice * e.Danmaku.GiftCount;

                    //增加用户的power数据到数据库顺便更新用户状态
                    var Collection = SingleInstanceHelper.Instance.DBHelper.DataBase.GetCollection <BsonDocument>(SingleInstanceHelper.Instance.DBHelper.UserRecordCoName);
                    FilterDefinition <BsonDocument> filter = Builders <BsonDocument> .Filter.Eq(x => x["UserId"], e.Danmaku.UserID);

                    List <BsonDocument> result = Collection.Find(filter).ToList();
                    var tempUserRecord         = new UserRecordModel();
                    int addFollow = obj["data"]["addFollow"].ToObject <int>();
                    if (result != null && result.Count > 0)
                    {
                        tempUserRecord.FromBson(result[0]);
                        tempUserRecord.UserTotalPower += Power;
                        tempUserRecord.UserName        = e.Danmaku.UserName;
                        if (addFollow == 0)
                        {
                            tempUserRecord.IsFan = false;
                        }
                        else
                        {
                            tempUserRecord.IsFan = true;
                        }
                    }
                    else
                    {
                        tempUserRecord.UserId         = e.Danmaku.UserID;
                        tempUserRecord.UserName       = e.Danmaku.UserName;
                        tempUserRecord.UserTotalPower = Power;
                        tempUserRecord.UserGetWeight  = 0;
                        if (addFollow == 0)
                        {
                            tempUserRecord.IsFan = false;
                        }
                        else
                        {
                            tempUserRecord.IsFan = true;
                        }
                    }
                    var TempBson = BsonSerializer.Deserialize <BsonDocument>(JsonHelper.getJsonByObject(tempUserRecord));
                    SingleInstanceHelper.Instance.DBHelper.Save(SingleInstanceHelper.Instance.DBHelper.UserRecordCoName, TempBson, "UserId");

                    if (Stop)
                    {
                        return;
                    }

                    //记录消息
                    Random rd       = new Random();
                    int    rdResult = rd.Next(1, 100);
                    if (rdResult < 50)
                    {
                        String NewRunnerMessage = NewRunnerMessages[rdResult % 11].Replace("挑战者", e.Danmaku.UserName);
                        WriteToFile(NewRunnerMessage);
                    }
                    //沼泽处理
                    if (CurrentMarsh.GetOneRunner(e.Danmaku.UserName, Power, e.Danmaku.UserID, addFollow) == 2)
                    {
                        String RealBoomMessage = BoomMessage.Replace("挑战者", e.Danmaku.UserName);
                        WriteToFile(RealBoomMessage);
                    }
                    //竞猜处理
                    if (CurrentBet != null)
                    {
                        if (CurrentBet.Status == BetStatus.betting)
                        {
                            CurrentBet.Bet(e.Danmaku.UserName, e.Danmaku.UserID, e.Danmaku.GiftCount, tempGiftValue.GiftPrice);
                        }
                    }
                }
            }
        }