Commit 057183c6 authored by NukeKitty's avatar NukeKitty
Browse files

Merged main and push

parent e1e8f328
Subproject commit 39ceacc91fd41d1013185a350d84726f5aaa668f
Subproject commit 9d398abec5807f8646eb036bc0e6a243ceea9c8d
using Microsoft.Extensions.Logging;
using MomentaryMeeting.Game.Interactions;
using MomentaryMeeting.Game.Interactions;
using MomentaryMeeting.Models;
using MomentaryMeeting.Services;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MomentaryMeeting.Game
{
public interface IEndMeetings
{
Task EndMeeting(Meeting meeting);
}
public class InteractionManager : IEndMeetings
{
private const string _entryText = "A stranger appears in front of you.";
private readonly IDatabaseApi _databaseApi;
private readonly Database _database;
private readonly ILogger<InteractionManager> _logger;
private readonly ArrangementGenerator _arrangementGenerator;
private List<Meeting> _meetings;
private GameInstance _gameInstance;
public InteractionManager(IDatabaseApi databaseApi, ILogger<InteractionManager> logger, ArrangementGenerator arrangementGenerator)
{
_databaseApi = databaseApi;
_database = _databaseApi.Current;
_logger = logger;
_arrangementGenerator = arrangementGenerator;
_meetings = new List<Meeting>();
}
public async Task<string> CheckForInteraction(GameInstance gameInstance, UserModel player)
{
if (_gameInstance == null)
_gameInstance = gameInstance;
foreach(UserModel otherUser in gameInstance.GetPlayers())
{
_logger.LogInformation($"ID: {player.DiscordId} {otherUser.DiscordId} {player.DiscordId != otherUser.DiscordId} object: {player != otherUser}");
// if someone else is in the room, and they are not me and they are not in meeting
if (otherUser.LocationName == player.LocationName && player.DiscordId != otherUser.DiscordId && otherUser.InMeeting == false)
{
player.InMeeting = true;
otherUser.InMeeting = true;
Meeting meeting = new Meeting(this);
meeting._users.Add(player);
meeting._users.Add(otherUser);
_meetings.Add(meeting);
// let them know someone has entered their room
await _gameInstance.SendPromptToPlayer(otherUser, "<" + _entryText);
await _gameInstance.SyncPlayerMusic(_gameInstance.GetConnection(otherUser.DiscordId));
_logger.LogInformation("User(" + player.DiscordId + ":" + player.Username +
") has entered a room occupied by " + "User(" + otherUser.DiscordId + ":" + otherUser.Username + "). Beginning meeting!");
return _entryText;
}
}
return null;
}
public async Task EndMeeting(Meeting meeting)
{
_logger.LogInformation("Ending meeting between " + meeting._users[0] + " and " + meeting._users[1]);
foreach (UserModel player in meeting._users)
{
player.InMeeting = false;
_meetings.Remove(meeting);
// send them two rooms away
ArrangementGenerator.Neighbours neighbours;
string newRoom = player.LocationName;
int roomDistance = 3;
for (int i = 0; i < roomDistance; i++)
{
neighbours = _arrangementGenerator.GetNeighbours(newRoom);
List<string> rooms = new List<string>();
string northNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.North);
if (northNeighbour != "")
rooms.Add(northNeighbour);
string southNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.South);
if (southNeighbour != "")
rooms.Add(southNeighbour);
string eastNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.East);
if (eastNeighbour != "")
rooms.Add(eastNeighbour);
string westNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.West);
if (westNeighbour != "")
rooms.Add(westNeighbour);
newRoom = rooms[new Random().Next(rooms.Count)];
}
player.LocationName = newRoom;
await _gameInstance.NotifyPlayerOfMeetingEnd(player.DiscordId);
}
_gameInstance.GenerateAndNotify();
}
public Meeting FindMeeting(UserModel aUser)
{
foreach(Meeting meeting in _meetings)
{
if (meeting._users.Contains(aUser))
return meeting;
}
_logger.LogError($"Couldn't find meeting for userid: {aUser.DiscordId}");
return null;
}
}
}
<<<<<<< Updated upstream
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MomentaryMeeting.Game
{
public interface IEndMeetings
{
Task EndMeeting(Meeting meeting);
}
public class InteractionManager : IEndMeetings
{
private const string _entryText = "A stranger appears in front of you.";
private readonly IDatabaseApi _databaseApi;
private readonly Database _database;
private readonly ILogger<InteractionManager> _logger;
private readonly ArrangementGenerator _arrangementGenerator;
private List<Meeting> _meetings;
private GameInstance _gameInstance;
public InteractionManager(IDatabaseApi databaseApi, ILogger<InteractionManager> logger, ArrangementGenerator arrangementGenerator)
{
_databaseApi = databaseApi;
_database = _databaseApi.Current;
_logger = logger;
_arrangementGenerator = arrangementGenerator;
_meetings = new List<Meeting>();
}
public async Task<string> CheckForInteraction(GameInstance gameInstance, UserModel player)
{
if (_gameInstance == null)
_gameInstance = gameInstance;
foreach(UserModel otherUser in gameInstance.GetPlayers())
{
_logger.LogInformation($"ID: {player.DiscordId} {otherUser.DiscordId} {player.DiscordId != otherUser.DiscordId} object: {player != otherUser}");
// if someone else is in the room, and they are not me and they are not in meeting
if (otherUser.LocationName == player.LocationName && player.DiscordId != otherUser.DiscordId && otherUser.InMeeting == false)
{
player.InMeeting = true;
otherUser.InMeeting = true;
Meeting meeting = new Meeting(this);
meeting._users.Add(player);
meeting._users.Add(otherUser);
_meetings.Add(meeting);
// let them know someone has entered their room
await _gameInstance.SendPromptToPlayer(otherUser, "<" + _entryText);
await _gameInstance.SyncPlayerMusic(_gameInstance.GetConnection(otherUser.DiscordId));
_logger.LogInformation("User(" + player.DiscordId + ":" + player.Username +
") has entered a room occupied by " + "User(" + otherUser.DiscordId + ":" + otherUser.Username + "). Beginning meeting!");
return _entryText;
}
}
return null;
}
public async Task EndMeeting(Meeting meeting)
{
_logger.LogInformation("Ending meeting between " + meeting._users[0] + " and " + meeting._users[1]);
foreach (UserModel player in meeting._users)
{
player.InMeeting = false;
_meetings.Remove(meeting);
// send them two rooms away
ArrangementGenerator.Neighbours neighbours;
string newRoom = player.LocationName;
int roomDistance = 3;
for (int i = 0; i < roomDistance; i++)
{
neighbours = _arrangementGenerator.GetNeighbours(newRoom);
List<string> rooms = new List<string>();
string northNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.North);
if (northNeighbour != "")
rooms.Add(northNeighbour);
string southNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.South);
if (southNeighbour != "")
rooms.Add(southNeighbour);
string eastNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.East);
if (eastNeighbour != "")
rooms.Add(eastNeighbour);
string westNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.West);
if (westNeighbour != "")
rooms.Add(westNeighbour);
newRoom = rooms[new Random().Next(rooms.Count)];
}
player.LocationName = newRoom;
await _gameInstance.NotifyPlayerOfMeetingEnd(player.DiscordId);
}
_gameInstance.GenerateAndNotify();
}
public Meeting FindMeeting(UserModel aUser)
{
foreach(Meeting meeting in _meetings)
{
if (meeting._users.Contains(aUser))
return meeting;
}
_logger.LogError($"Couldn't find meeting for userid: {aUser.DiscordId}");
return null;
}
}
}
=======
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MomentaryMeeting.Game
{
public interface IEndMeetings
{
Task EndMeeting(Meeting meeting);
}
public class InteractionManager : IEndMeetings
{
private const string _entryText = "A stranger appears in front of you.";
private readonly IDatabaseApi _databaseApi;
private readonly Database _database;
private readonly ILogger<InteractionManager> _logger;
private readonly ArrangementGenerator _arrangementGenerator;
private List<Meeting> _meetings;
private GameInstance _gameInstance;
public InteractionManager(IDatabaseApi databaseApi, ILogger<InteractionManager> logger, ArrangementGenerator arrangementGenerator)
{
_databaseApi = databaseApi;
_database = _databaseApi.Current;
_logger = logger;
_arrangementGenerator = arrangementGenerator;
_meetings = new List<Meeting>();
}
public async Task<string> CheckForInteraction(GameInstance gameInstance, UserModel player)
{
if (_gameInstance == null)
_gameInstance = gameInstance;
foreach(UserModel otherUser in gameInstance.GetPlayers())
{
_logger.LogInformation($"ID: {player.DiscordId} {otherUser.DiscordId} {player.DiscordId != otherUser.DiscordId} object: {player != otherUser}");
// if someone else is in the room, and they are not me and they are not in meeting
if (otherUser.LocationName == player.LocationName && player.DiscordId != otherUser.DiscordId && otherUser.InMeeting == false)
{
player.InMeeting = true;
otherUser.InMeeting = true;
Meeting meeting = new Meeting(this);
meeting._users.Add(player);
meeting._users.Add(otherUser);
_meetings.Add(meeting);
// let them know someone has entered their room
await _gameInstance.SendPromptToPlayer(otherUser, ">" + _entryText);
await _gameInstance.SyncPlayerMusic(_gameInstance.GetConnection(otherUser.DiscordId));
_logger.LogInformation("User(" + player.DiscordId + ":" + player.Username +
") has entered a room occupied by " + "User(" + otherUser.DiscordId + ":" + otherUser.Username + "). Beginning meeting!");
return _entryText;
}
}
return null;
}
public async Task EndMeeting(Meeting meeting)
{
_logger.LogInformation("Ending meeting between " + meeting._users[0] + " and " + meeting._users[1]);
foreach (UserModel player in meeting._users)
{
player.InMeeting = false;
_meetings.Remove(meeting);
// send them two rooms away
ArrangementGenerator.Neighbours neighbours;
string newRoom = player.LocationName;
int roomDistance = 3;
for (int i = 0; i < roomDistance; i++)
{
neighbours = _arrangementGenerator.GetNeighbours(newRoom);
List<string> rooms = new List<string>();
string northNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.North);
if (northNeighbour != "")
rooms.Add(northNeighbour);
string southNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.South);
if (southNeighbour != "")
rooms.Add(southNeighbour);
string eastNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.East);
if (eastNeighbour != "")
rooms.Add(eastNeighbour);
string westNeighbour = neighbours.GetNeighbour(UserModel.CardinalDirection.West);
if (westNeighbour != "")
rooms.Add(westNeighbour);
newRoom = rooms[new Random().Next(rooms.Count)];
}
player.LocationName = newRoom;
await _gameInstance.NotifyPlayerOfMeetingEnd(player.DiscordId);
}
_gameInstance.GenerateAndNotify();
}
public Meeting FindMeeting(UserModel aUser)
{
foreach(Meeting meeting in _meetings)
{
if (meeting._users.Contains(aUser))
return meeting;
}
_logger.LogError($"Couldn't find meeting for userid: {aUser.DiscordId}");
return null;
}
}
}
>>>>>>> Stashed changes
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment