Merge branch 'dev' into SES-136

This commit is contained in:
Natalia Gawron 2021-01-08 20:39:04 +01:00
commit d542652a8b
13 changed files with 239 additions and 21 deletions

View File

@ -14,5 +14,6 @@ namespace SessionCompanion.Services.Interfaces
Task<IEnumerable<CharacterBasicStatsViewModel>> GetBasicCharactersData(List<int> charactersId);
Task<IEnumerable<CharacterForLoginViewModel>> GetUserLoginCharacters(int userId);
Task<List<UniversalStatisticViewModel>> GetCharacterStatistics(int characterId);
Task<CharacterBasicInfoViewModel> GetBasicCharacterbasicInfo(int characterId);
}
}

View File

@ -10,5 +10,6 @@ namespace SessionCompanion.Services.Interfaces
{
public interface IStatisticsService : IServiceBase<StatisticsViewModel, Statistics>
{
Task SubtractHp(int characterId, int hpToSubtract);
}
}

View File

@ -25,7 +25,15 @@ namespace SessionCompanion.Services.Profiles
.ForMember(vm => vm.Level, conf => conf.MapFrom(charact => charact.Statistics.Level))
.ForMember(vm => vm.CurrentHealthPoints, conf => conf.MapFrom(charact => charact.Statistics.CurrentHealthPoints))
.ForMember(vm => vm.Class, conf => conf.MapFrom(charact => charact.Biography.Class.Name)).ReverseMap();
CreateMap<Character, CharacterBasicInfoViewModel>()
.ForMember(vm => vm.Name, conf => conf.MapFrom(charact => charact.Biography.Name))
.ForMember(vm => vm.Level, conf => conf.MapFrom(charact => charact.Statistics.Level))
.ForMember(vm => vm.CurrentHealthPoints, conf => conf.MapFrom(charact => charact.Statistics.CurrentHealthPoints))
.ForMember(vm => vm.MaxHealthPoints, conf => conf.MapFrom(charact => charact.Statistics.HealthPoints))
.ForMember(vm => vm.Race, conf => conf.MapFrom(charact => charact.Biography.Race.Name))
.ForMember(vm => vm.Class, conf => conf.MapFrom(charact => charact.Biography.Class.Name)).ReverseMap();
CreateMap<Character, CharacterEveryStatViewModel>()
.ForMember(vm => vm.CanDeception, conf => conf.MapFrom(charact => charact.Charisma.CanDeception))
.ForMember(vm => vm.CanIntimidation, conf => conf.MapFrom(charact => charact.Charisma.CanIntimidation))

View File

@ -96,5 +96,20 @@ namespace SessionCompanion.Services.Services
return statistics;
}
/// <summary>
/// Funkcja zwraca podstawowy widok postaci na podstawie ich id
/// </summary>
/// <param name="characterId">Lista identyfikatorów postaci</param>
/// <returns>Podstawowy widok podanych postaci</returns>
public async Task<CharacterBasicInfoViewModel> GetBasicCharacterbasicInfo(int characterId)
{
var character = await Repository.Get(c => c.Id.Equals(characterId))
.Include(x => x.Biography).ThenInclude(x => x.Class)
.Include(x => x.Biography).ThenInclude(x => x.Race)
.Include(x => x.Statistics).SingleAsync();
var result = Mapper.Map<CharacterBasicInfoViewModel>(character);
return result;
}
}
}

View File

@ -17,5 +17,18 @@ namespace SessionCompanion.Services.Services
{
public StatisticsService(IMapper mapper, IRepository<Statistics> repository) : base(mapper, repository)
{ }
/// <summary>
/// Method subtract hp from given character
/// </summary>
/// <param name="characterId"></param>
/// <param name="hpToSubtract"></param>
/// <returns></returns>
public async Task SubtractHp(int characterId, int hpToSubtract)
{
var result = await Repository.Get(c => c.Id.Equals(characterId)).SingleAsync();
result.CurrentHealthPoints -= hpToSubtract;
await Repository.Update(result);
await Repository.Save();
}
}
}

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SessionCompanion.ViewModels.CharacterViewModels
{
public class CharacterBasicInfoViewModel
{
/// <summary>
/// Identyfikator postaci
/// </summary>
public int Id { get; set; }
/// <summary>
/// Nazwa postaci
/// </summary>
public string Name { get; set; }
/// <summary>
/// Poziom postaci
/// </summary>
public int Level { get; set; }
/// <summary>
/// Aktualna ilość życia postaci
/// </summary>
public int CurrentHealthPoints { get; set; }
/// <summary>
/// Maksymalna ilość życia psotaci
/// </summary>
public int MaxHealthPoints { get; set; }
/// <summary>
/// Klasa postaci
/// </summary>
public string Class { get; set; }
/// <summary>
/// Rasa postaci
/// </summary>
public string Race{ get; set; }
}
}

View File

@ -80,6 +80,41 @@
Płeć postaci
</summary>
</member>
<member name="P:SessionCompanion.ViewModels.CharacterViewModels.CharacterBasicInfoViewModel.Id">
<summary>
Identyfikator postaci
</summary>
</member>
<member name="P:SessionCompanion.ViewModels.CharacterViewModels.CharacterBasicInfoViewModel.Name">
<summary>
Nazwa postaci
</summary>
</member>
<member name="P:SessionCompanion.ViewModels.CharacterViewModels.CharacterBasicInfoViewModel.Level">
<summary>
Poziom postaci
</summary>
</member>
<member name="P:SessionCompanion.ViewModels.CharacterViewModels.CharacterBasicInfoViewModel.CurrentHealthPoints">
<summary>
Aktualna ilość życia postaci
</summary>
</member>
<member name="P:SessionCompanion.ViewModels.CharacterViewModels.CharacterBasicInfoViewModel.MaxHealthPoints">
<summary>
Maksymalna ilość życia psotaci
</summary>
</member>
<member name="P:SessionCompanion.ViewModels.CharacterViewModels.CharacterBasicInfoViewModel.Class">
<summary>
Klasa postaci
</summary>
</member>
<member name="P:SessionCompanion.ViewModels.CharacterViewModels.CharacterBasicInfoViewModel.Race">
<summary>
Rasa postaci
</summary>
</member>
<member name="P:SessionCompanion.ViewModels.CharacterViewModels.CharacterBasicStatsViewModel.Id">
<summary>
Identyfikator postaci

View File

@ -66,14 +66,14 @@ namespace SessionCompanion.Controllers
};
}
/// <summary>
/// Metoda zwraca listę postaci przypisanych do danego użytkownika
/// Metoda zwraca listę zalogowanych postaci
/// </summary>
/// <returns> Lista zalogowanych postaci lub wiadomość błędu </returns>
[HttpGet("loggedCharacters")]
public async Task<Either<List<CharacterBasicStatsViewModel>, ErrorResponse>> GetLoggedUsersCharacters()
{
var connectedCharacters = _sessionHubData.ConnectedCharacters_Prop;
var characters = await _service.GetBasicCharactersData(connectedCharacters.Values.ToList());
var characters = await _service.GetBasicCharactersData(connectedCharacters.Keys.ToList());
return characters.ToList();
}
@ -88,5 +88,22 @@ namespace SessionCompanion.Controllers
var statistics = await _service.GetCharacterStatistics(characterId);
return statistics;
}
/// <summary>
/// Metoda zwraca podstawowe informacje dla danej postaci
/// </summary>
/// <param name="characterId"></param>
/// <returns>Podstawowe informacje dla danej postaci</returns>
[HttpGet("characterBasicInfo")]
public async Task<Either<CharacterBasicInfoViewModel, ErrorResponse>> GetCharacterBasicInfo([Required] int characterId)
{
var info = await _service.GetBasicCharacterbasicInfo(characterId);
if (info is null)
return new ErrorResponse() {
Message = "No characters with given id",
StatusCode = 204
};
return info;
}
}
}

View File

@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Mvc;
using SessionCompanion.Extensions.EitherType;
using SessionCompanion.Services.Interfaces;
using SessionCompanion.ViewModels.ApiResponses;
using SessionCompanion.ViewModels.OtherEquipmentViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SessionCompanion.Controllers
{
[Route("api/otherEquipment")]
[ApiController]
public class OtherEquipmentController : Controller
{
private readonly IOtherEquipmentService _service;
public OtherEquipmentController(IOtherEquipmentService service) => _service = service;
/// <summary>
/// Metoda zwraca wszystkie dostępne inne przedmioty
/// </summary>
/// <returns>Lista wszystkich innych przedmiotów w bazie danych</returns>
[HttpGet("getAllOtherEquipment")]
public async Task<Either<List<OtherEquipmentViewModel>, ErrorResponse>> GetOtherEquipment()
{
try
{
var otherEq = _service.Get().ToList();
return otherEq;
}
catch (Exception e)
{
return new ErrorResponse()
{
StatusCode = 204,
Message = e.Message
};
}
}
}
}

View File

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.SignalR;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace SessionCompanion.Hubs
@ -25,10 +26,11 @@ namespace SessionCompanion.Hubs
public override Task OnDisconnectedAsync(Exception exception)
{
// if true then it is character, if false it is GM
if (this.sessionHubData.ConnectedCharacters_Prop.ContainsKey(Context.ConnectionId))
if (this.sessionHubData.ConnectedCharacters_Prop.ContainsValue(Context.ConnectionId))
{
Groups.RemoveFromGroupAsync(Context.ConnectionId, "Players");
this.sessionHubData.ConnectedCharacters_Prop.Remove(Context.ConnectionId);
int charactedId = this.sessionHubData.ConnectedCharacters_Prop.Where(e => e.Value.Equals(Context.ConnectionId)).First().Key;
this.sessionHubData.ConnectedCharacters_Prop.Remove(charactedId);
}
else
{
@ -61,6 +63,29 @@ namespace SessionCompanion.Hubs
return false;
}
}
/// <summary>
/// Metoda wysyła wiadomość do konkretnego gracza [MessageFromGameMaster]
/// </summary>
/// <param name="characterId"> Id postaci któa ma otrzymać wiadomość </param>
/// <param name="message"> Wiadomość do wysłania </param>
public void SendMessageToPlayer(int characterId, string message)
{
string playerConnectionId = "";
if (this.sessionHubData.ConnectedCharacters_Prop.TryGetValue(characterId, out playerConnectionId))
{
Clients.Client(playerConnectionId).SendAsync("MessageFromGameMaster", message);
}
}
/// <summary>
/// Metoda wysyła wiadomość do wszystkich graczy [MessageFromGameMaster]
/// </summary>
/// <param name="message"> Wiadomość do wysłania </param>
public void SendMessageToAllPlayers(string message)
{
Clients.Group("Players").SendAsync("MessageFromGameMaster", message);
}
#endregion
#region Player
@ -72,7 +97,7 @@ namespace SessionCompanion.Hubs
/// <returns>Wysyła wiadomość "Welcome" do wszystkich zalogowanych użytkoników</returns>
public Task PlayerCharacterLogin(int characterId)
{
this.sessionHubData.ConnectedCharacters_Prop.Add(Context.ConnectionId, characterId);
this.sessionHubData.ConnectedCharacters_Prop.Add(characterId, Context.ConnectionId);
Groups.AddToGroupAsync(Context.ConnectionId, "Players");
return Clients.All.SendAsync("Welcome", "Welcome new Player");

View File

@ -10,7 +10,7 @@ namespace SessionCompanion.Hubs
/// <summary>
/// Lista zalogowanych graczy i identyfikator wybranej postaci
/// </summary>
public static Dictionary<string, int> ConnectedCharacters = new Dictionary<string, int>();
public static Dictionary<int, string> ConnectedCharacters = new Dictionary<int, string>();
/// <summary>
/// Status, czy GM został już zalogowany
@ -36,7 +36,7 @@ namespace SessionCompanion.Hubs
/// <summary>
/// Zwraca lub ustawia listę zalogowanych postaci
/// </summary>
public Dictionary<string, int> ConnectedCharacters_Prop
public Dictionary<int, string> ConnectedCharacters_Prop
{
get
{

View File

@ -36,10 +36,6 @@
<None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SessionCompanion.Database\SessionCompanion.Database.csproj" />
<ProjectReference Include="..\SessionCompanion.Extensions\SessionCompanion.Extensions.csproj" />

View File

@ -20,23 +20,29 @@
</member>
<member name="M:SessionCompanion.Controllers.CharacterController.GetLoggedUsersCharacters">
<summary>
Metoda zwraca listę postaci przypisanych do danego użytkownika
Metoda zwraca listę zalogowanych postaci
</summary>
<returns> Lista zalogowanych postaci lub wiadomość błędu </returns>
</member>
<member name="M:SessionCompanion.Controllers.CharacterController.GetCharacterEveryStat(System.Int32)">
<summary>
Metoda zwraca wszystkie statystyki dla danej postaci
Zwracane statystyki dla:
Charisma
Constitution
Dexterity
Intelligence
Strength
Wisdom
</summary>
<param name="characterId"> Id postaci </param>
<returns> Listę wszystkich statystyk </returns>
</member>
<member name="M:SessionCompanion.Controllers.OtherEquipmentController.GetOtherEquipment">
<summary>
Metoda zwraca wszystkie dostępne inne przedmioty
</summary>
<returns>Lista wszystkich innych przedmiotów w bazie danych</returns>
</member>
<member name="M:SessionCompanion.Controllers.CharacterController.GetCharacterBasicInfo(System.Int32)">
<summary>
Metoda zwraca podstawowe informacje dla danej postaci
</summary>
<param name="characterId"></param>
<returns></returns>
<returns>Podstawowe informacje dla danej postaci</returns>
</member>
<member name="M:SessionCompanion.Controllers.UserController.Login(System.String,System.String)">
<summary>
@ -79,6 +85,19 @@
</summary>
<returns>Zwraca true - jeśli udało się zalogować, false - jesli ktoś zalogował się już jako GM</returns>
</member>
<member name="M:SessionCompanion.Hubs.SessionHub.SendMessageToPlayer(System.Int32,System.String)">
<summary>
Metoda wysyła wiadomość do konkretnego gracza [MessageFromGameMaster]
</summary>
<param name="characterId"> Id postaci któa ma otrzymać wiadomość </param>
<param name="message"> Wiadomość do wysłania </param>
</member>
<member name="M:SessionCompanion.Hubs.SessionHub.SendMessageToAllPlayers(System.String)">
<summary>
Metoda wysyła wiadomość do wszystkich graczy [MessageFromGameMaster]
</summary>
<param name="message"> Wiadomość do wysłania </param>
</member>
<member name="M:SessionCompanion.Hubs.SessionHub.PlayerCharacterLogin(System.Int32)">
<summary>
Logowanie do Huba dla Gracza