|
|
@ -7,7 +7,7 @@ using static Build_God_Api.DB.BagItem; |
|
|
|
|
|
|
|
|
namespace Build_God_Api.Services |
|
|
namespace Build_God_Api.Services |
|
|
{ |
|
|
{ |
|
|
public interface ICharacterService |
|
|
public interface ICharacterService |
|
|
{ |
|
|
{ |
|
|
public Task<Character?> GetCharacterByAccountId(int accountId); |
|
|
public Task<Character?> GetCharacterByAccountId(int accountId); |
|
|
public Task<List<Character>> GetCharactersByAccountId(int accountId); |
|
|
public Task<List<Character>> GetCharactersByAccountId(int accountId); |
|
|
@ -153,16 +153,16 @@ public interface ICharacterService |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var duration = DateTime.Now - character.TrainingOn.Value; |
|
|
var duration = DateTime.Now - character.TrainingOn.Value; |
|
|
var seconds = (decimal)duration.TotalSeconds; |
|
|
var seconds = duration.TotalSeconds; |
|
|
|
|
|
|
|
|
// exp = 0.1 * seconds * level * level * (1 + buff)
|
|
|
// exp = 0.02 * seconds * level^1.5 * (1 + buff)
|
|
|
var expGained = 0.01m * seconds * character.LevelId * character.LevelId * (1 + 0); |
|
|
var expGained = Convert.ToDecimal(0.02 * seconds * Math.Pow(character.LevelId, 1.5) * (1 + 0)); |
|
|
|
|
|
var result = Math.Round(expGained); |
|
|
character.CurrentExp += Math.Round(expGained); |
|
|
character.CurrentExp += result; |
|
|
character.TrainingOn = null; |
|
|
character.TrainingOn = null; |
|
|
await db.Updateable(character).ExecuteCommandAsync(); |
|
|
await db.Updateable(character).ExecuteCommandAsync(); |
|
|
|
|
|
|
|
|
return expGained; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private readonly RandomNumberGenerator _rng = RandomNumberGenerator.Create(); |
|
|
private readonly RandomNumberGenerator _rng = RandomNumberGenerator.Create(); |
|
|
@ -211,7 +211,7 @@ public interface ICharacterService |
|
|
return await db.Queryable<Character>().AnyAsync(x => x.Name == name); |
|
|
return await db.Queryable<Character>().AnyAsync(x => x.Name == name); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async Task<Character?> GetCharacterByAccountId(int accountId) |
|
|
public async Task<Character?> GetCharacterByAccountId(int accountId) |
|
|
{ |
|
|
{ |
|
|
return await db.Queryable<Character>().FirstAsync(x => x.AccountId == accountId && x.isLocked == false); |
|
|
return await db.Queryable<Character>().FirstAsync(x => x.AccountId == accountId && x.isLocked == false); |
|
|
} |
|
|
} |
|
|
@ -291,7 +291,7 @@ public async Task<Character?> GetCharacterByAccountId(int accountId) |
|
|
NextLevelRequiredPillId = nextLevelRequiredPillId, |
|
|
NextLevelRequiredPillId = nextLevelRequiredPillId, |
|
|
NextLevelRequiredPillName = nextLevelRequiredPillName, |
|
|
NextLevelRequiredPillName = nextLevelRequiredPillName, |
|
|
NextLevelRequiredPillQuantity = nextLevelRequiredPillQuantity, |
|
|
NextLevelRequiredPillQuantity = nextLevelRequiredPillQuantity, |
|
|
TrainingExpRate = 0.01m, |
|
|
TrainingExpRate = 0.02m, |
|
|
LastLogin = c.LastLogin, |
|
|
LastLogin = c.LastLogin, |
|
|
CreatedOn = c.CreatedOn |
|
|
CreatedOn = c.CreatedOn |
|
|
}); |
|
|
}); |
|
|
@ -331,7 +331,7 @@ public async Task<Character?> GetCharacterByAccountId(int accountId) |
|
|
Name = character.Name, |
|
|
Name = character.Name, |
|
|
AccountId = currentUserService.UserId, |
|
|
AccountId = currentUserService.UserId, |
|
|
CurrentExp = 0, |
|
|
CurrentExp = 0, |
|
|
LevelId = 1, |
|
|
LevelId = 10, |
|
|
Money = 0, |
|
|
Money = 0, |
|
|
CurrentHP = 100, |
|
|
CurrentHP = 100, |
|
|
ProfessionId = character.ProfessionId, |
|
|
ProfessionId = character.ProfessionId, |
|
|
|