public static IEnumerable <(UserId, DatabaseVariables)> GetTop(TopParam param, int count) { var order = new List <(DbColumnAttribute, bool)>(); switch (param) { case TopParam.Rooms: order.Add((DatabaseVariables.GetColumn(x => x.Rooms), false)); break; case TopParam.Monsters: order.Add((DatabaseVariables.GetColumn(x => x.Monsters), false)); break; case TopParam.Gold: order.Add((DatabaseVariables.GetColumn(x => x.Gold), false)); break; case TopParam.Level: order.Add((DatabaseVariables.GetColumn(x => x.Level), false)); order.Add((DatabaseVariables.GetColumn(x => x.Experience), false)); break; default: throw new ArgumentOutOfRangeException(nameof(param), param, null); } var users = DatabaseConnection.QueryUsers(order, null, count); foreach (var userData in users) { yield return(userData.Id, userData.Variables); } }
public UserData(UserId id, byte[] data, DatabaseVariables variables, int version) { Data = data; Id = id; Variables = variables; Version = version; }
private void OnMessage(User user, ReceivedMessage message) { if (user.ItemManager.Get(Id) == null) { return; } var filter = new List <(DbColumnAttribute, string, object)> { (DatabaseVariables.GetColumn(v => v.Level), ">=", user.Info.Level.Level - 1), (DatabaseVariables.GetColumn(v => v.Level), "<=", user.Info.Level.Level + 1), (DatabaseVariables.GetColumn(v => v.LastMessageReceived), ">", DateTime.Now - TimeSpan.FromMinutes(1.5)) }; var users = DatabaseConnection.QueryUsers(null, filter, null); ImmutableHashSet <UserId> gladiators; lock (GlobalVariables.Variables) { gladiators = GetGladiators() .Cast <UserId>() .ToImmutableHashSet(); } if (!gladiators.Contains(user.Info.UserId)) { user.MessageManager.SendMessage(new SentMessage { Text = "<b>Отныне вы не гладиатор!</b>" }); user.ItemManager.Remove(new ItemInfo(Id, 1)); return; } gladiators = gladiators.Remove(user.Info.UserId); var filtered = users .Where(u => gladiators.Contains(u.Id)) .Where(u => { using (var ctx = new UserContext(u.Id)) { return(ctx.User.RoomManager.GetRoom()?.Identifier != Battle.Id); } }) .ToList(); if (filtered.Count == 0) { return; } var enemy = filtered[user.Random.Next(filtered.Count)]; using (var ctx = new UserContext(enemy.Id)) { Battle.BeginBattle(ctx.User, user, true); // Force send message after enetring battle to show OnEnter() to user ctx.User.MessageManager.Finish(); // Force send message before enetring battle to clean queue. // OnEnter message will be handled by MessengerManager user.MessageManager.Finish(); Battle.BeginBattle(user, ctx, false); } }