TigerEmu/Game/Navigator/Views/MyWorldView.cs

69 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.ObjectModel;
using Tiger.Communication.Messages.Types;
using Tiger.Game.Habbos;
using Tiger.Game.Rooms;
using Tiger.Storage;
namespace Tiger.Game.Navigator.Views;
public class MyWorldView : INavigatorView
{
private readonly IRepository<Room> _roomRepository;
private const int OwnRoomsType = 0;
private const int FavoriteRoomsType = 1;
private const int GroupRoomsType = 2;
private const int VisitedRoomsType = 3;
private const int FriendRoomsType = 4;
private const int RightsRoomType = 5;
public string Code => "myworld_view";
private readonly IDictionary<string, int> _categories = new Dictionary<string, int>
{
{"My Rooms", OwnRoomsType},
{"My Favorite Rooms", FavoriteRoomsType},
{"My Groups", GroupRoomsType},
{"My Room Visit History", VisitedRoomsType},
{"My Friends' Rooms", FriendRoomsType},
{"Rooms Where I Have Rights", RightsRoomType}
};
public MyWorldView(IRepository<Room> roomRepository)
{
_roomRepository = roomRepository;
}
public async Task Compose(ServerMessage message, Habbo habbo, string query)
{
message.AppendInt32(_categories.Count);
foreach (var (category, type) in _categories)
{
message.AppendString(category);
message.AppendString(category);
message.AppendInt32(0); // action?
message.AppendBoolean(false); // closed?
message.AppendInt32(0); // mode?
var rooms = await GetRoomsByType(habbo, type);
message.AppendInt32(rooms.Count);
foreach (var room in rooms)
{
room.Serialize(message);
}
}
}
private async Task<ICollection<Room>> GetRoomsByType(Habbo habbo, int type)
{
return type switch
{
OwnRoomsType => (await _roomRepository.FindByAsync(r => r.Owner == habbo)).ToList(),
_ => new Collection<Room>()
};
}
}