forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterService.cs
More file actions
106 lines (89 loc) · 3.5 KB
/
Copy pathCharacterService.cs
File metadata and controls
106 lines (89 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using L2dotNET.Repositories.Contracts;
using L2dotNET.Services.Contracts;
using L2dotNET.DataContracts;
using L2dotNET.DataContracts.Shared.Enums;
using L2dotNET.Models.Inventory;
using L2dotNET.Models.Player;
using L2dotNET.Models.Player.General;
using L2dotNET.Tables;
using L2dotNET.Utility;
namespace L2dotNET.Services
{
public class CharacterService : ICharacterService
{
private readonly ICrudService<CharacterContract> _characterCrudService;
private readonly ICharacterRepository _characterRepository;
private readonly ICrudService<ItemContract> _itemCrudService;
private readonly IItemService _itemService;
private readonly Config.Config _config;
private readonly IdFactory _idFactory;
private readonly ItemTable _itemTable;
public CharacterService(ICrudService<ItemContract> itemCrudService,
ICrudService<CharacterContract> characterCrudService,
ICharacterRepository characterRepository,
IItemService itemService,
IdFactory idFactory,
ItemTable itemTable,
Config.Config config)
{
_itemCrudService = itemCrudService;
_itemService = itemService;
_idFactory = idFactory;
_itemTable = itemTable;
_config = config;
_characterCrudService = characterCrudService;
_characterRepository = characterRepository;
}
public async Task<L2Player> GetById(int characterId)
{
var characterContract = await _characterCrudService.GetById(characterId);
return characterContract.ToPlayer();
}
public async Task<bool> CheckIfPlayerNameExists(string name)
{
return await _characterRepository.CheckIfPlayerNameExists(name);
}
public void CreatePlayer(L2Player player)
{
_characterCrudService.Add(player.ToContract());
}
public async Task UpdatePlayer(L2Player player)
{
player.LastAccess = DateTime.UtcNow;
await _characterCrudService.Update(player.ToContract());
}
public async Task<L2Player> GetPlayerBySlotId(int accountId, int slotId)
{
CharacterContract playerContract = await _characterRepository.GetCharacterBySlot(accountId, slotId);
return await RestorePlayer(playerContract);
}
public async Task<IEnumerable<L2Player>> GetPlayersOnAccount(int accountId)
{
IEnumerable<CharacterContract> playersOnAccount = await _characterRepository.GetCharactersOnAccount(accountId);
return await Task.WhenAll(playersOnAccount.Select(playerContract => RestorePlayer(playerContract)));
}
public bool DeleteCharById(int characterId)
{
_characterCrudService.Delete(new CharacterContract
{
CharacterId = characterId
});
return true;
}
public async Task<L2Player> RestorePlayer(CharacterContract characterContract)
{
L2Player player = characterContract.ToPlayer();
await player.Inventory.Restore(player);
player.SessionData = new PlayerBag();
return player;
}
public int GetDaysRequiredToDeletePlayer()
{
return _config.GameplayConfig.Server.Client.DeleteCharAfterDays;
}
}
}