currency levelup rewards wip
This commit is contained in:
parent
aca03cdc01
commit
461dfd553f
@ -241,6 +241,50 @@ namespace NadekoBot.Modules.Xp.Services
|
|||||||
}, token);
|
}, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetCurrencyReward(ulong guildId, int level, int amount)
|
||||||
|
{
|
||||||
|
using (var uow = _db.UnitOfWork)
|
||||||
|
{
|
||||||
|
var settings = uow.GuildConfigs.XpSettingsFor(guildId);
|
||||||
|
|
||||||
|
if (amount <= 0)
|
||||||
|
{
|
||||||
|
var toRemove = settings.CurrencyRewards.FirstOrDefault(x => x.Level == level);
|
||||||
|
if (toRemove != null)
|
||||||
|
{
|
||||||
|
uow._context.Remove(toRemove);
|
||||||
|
settings.CurrencyRewards.Remove(toRemove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
var rew = settings.CurrencyRewards.FirstOrDefault(x => x.Level == level);
|
||||||
|
|
||||||
|
if (rew != null)
|
||||||
|
rew.Amount = amount;
|
||||||
|
else
|
||||||
|
settings.CurrencyRewards.Add(new XpCurrencyReward()
|
||||||
|
{
|
||||||
|
Level = level,
|
||||||
|
Amount = amount,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
uow.Complete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<XpCurrencyReward> GetCurrencyRewards(ulong id)
|
||||||
|
{
|
||||||
|
using (var uow = _db.UnitOfWork)
|
||||||
|
{
|
||||||
|
return uow.GuildConfigs.XpSettingsFor(id)
|
||||||
|
.CurrencyRewards
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<XpRoleReward> GetRoleRewards(ulong id)
|
public IEnumerable<XpRoleReward> GetRoleRewards(ulong id)
|
||||||
{
|
{
|
||||||
using (var uow = _db.UnitOfWork)
|
using (var uow = _db.UnitOfWork)
|
||||||
|
@ -24,33 +24,9 @@ namespace NadekoBot.Modules.Xp
|
|||||||
_db = db;
|
_db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
//[NadekoCommand, Usage, Description, Aliases]
|
|
||||||
//[RequireContext(ContextType.Guild)]
|
|
||||||
//[OwnerOnly]
|
|
||||||
//public async Task Populate()
|
|
||||||
//{
|
|
||||||
// var rng = new NadekoRandom();
|
|
||||||
// using (var uow = _db.UnitOfWork)
|
|
||||||
// {
|
|
||||||
// for (var i = 0ul; i < 1000000; i++)
|
|
||||||
// {
|
|
||||||
// uow.DiscordUsers.Add(new DiscordUser()
|
|
||||||
// {
|
|
||||||
// AvatarId = i.ToString(),
|
|
||||||
// Discriminator = "1234",
|
|
||||||
// UserId = i,
|
|
||||||
// Username = i.ToString(),
|
|
||||||
// Club = null,
|
|
||||||
// });
|
|
||||||
// var xp = uow.Xp.GetOrCreateUser(Context.Guild.Id, i);
|
|
||||||
// xp.Xp = rng.Next(100, 100000);
|
|
||||||
// }
|
|
||||||
// uow.Complete();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
|
//todo add ratelimit attribute
|
||||||
//[Ratelimit(30)]
|
//[Ratelimit(30)]
|
||||||
public async Task Experience([Remainder]IUser user = null)
|
public async Task Experience([Remainder]IUser user = null)
|
||||||
{
|
{
|
||||||
@ -82,7 +58,7 @@ namespace NadekoBot.Modules.Xp
|
|||||||
.Take(9);
|
.Take(9);
|
||||||
|
|
||||||
var embed = new EmbedBuilder()
|
var embed = new EmbedBuilder()
|
||||||
.WithTitle(GetText("role_rewards"))
|
.WithTitle(GetText("level_up_rewards"))
|
||||||
.WithOkColor();
|
.WithOkColor();
|
||||||
|
|
||||||
if (!roles.Any())
|
if (!roles.Any())
|
||||||
@ -116,6 +92,21 @@ namespace NadekoBot.Modules.Xp
|
|||||||
await ReplyConfirmLocalized("role_reward_added", level, Format.Bold(role.ToString())).ConfigureAwait(false);
|
await ReplyConfirmLocalized("role_reward_added", level, Format.Bold(role.ToString())).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task XpCurrencyReward(int level, int amount=0)
|
||||||
|
{
|
||||||
|
if (level < 1 || amount < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_service.SetCurrencyReward(Context.Guild.Id, level, amount);
|
||||||
|
|
||||||
|
if (amount == 0)
|
||||||
|
await ReplyConfirmLocalized("cur_reward_cleared", level).ConfigureAwait(false);
|
||||||
|
else
|
||||||
|
await ReplyConfirmLocalized("cur_reward_added", level, Format.Bold(amount.ToString())).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
public enum NotifyPlace
|
public enum NotifyPlace
|
||||||
{
|
{
|
||||||
Server = 0,
|
Server = 0,
|
||||||
|
@ -8,6 +8,7 @@ namespace NadekoBot.Core.Services.Database.Models
|
|||||||
public GuildConfig GuildConfig { get; set; }
|
public GuildConfig GuildConfig { get; set; }
|
||||||
|
|
||||||
public HashSet<XpRoleReward> RoleRewards { get; set; } = new HashSet<XpRoleReward>();
|
public HashSet<XpRoleReward> RoleRewards { get; set; } = new HashSet<XpRoleReward>();
|
||||||
|
public HashSet<XpCurrencyReward> CurrencyRewards { get; set; } = new HashSet<XpCurrencyReward>();
|
||||||
public bool XpRoleRewardExclusive { get; set; }
|
public bool XpRoleRewardExclusive { get; set; }
|
||||||
public string NotifyMessage { get; set; } = "Congratulations {0}! You have reached level {1}!";
|
public string NotifyMessage { get; set; } = "Congratulations {0}! You have reached level {1}!";
|
||||||
public HashSet<ExcludedItem> ExclusionList { get; set; } = new HashSet<ExcludedItem>();
|
public HashSet<ExcludedItem> ExclusionList { get; set; } = new HashSet<ExcludedItem>();
|
||||||
@ -35,6 +36,25 @@ namespace NadekoBot.Core.Services.Database.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class XpCurrencyReward : DbEntity
|
||||||
|
{
|
||||||
|
public int XpSettingsId { get; set; }
|
||||||
|
public XpSettings XpSettings { get; set; }
|
||||||
|
|
||||||
|
public int Level { get; set; }
|
||||||
|
public int Amount { get; set; }
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Level.GetHashCode() ^ XpSettingsId.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
return obj is XpCurrencyReward xrr && xrr.Level == Level && xrr.XpSettingsId == XpSettingsId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class ExcludedItem : DbEntity
|
public class ExcludedItem : DbEntity
|
||||||
{
|
{
|
||||||
public ulong ItemId { get; set; }
|
public ulong ItemId { get; set; }
|
||||||
|
@ -200,6 +200,8 @@ namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
|||||||
set => set.Include(x => x.XpSettings)
|
set => set.Include(x => x.XpSettings)
|
||||||
.ThenInclude(x => x.RoleRewards)
|
.ThenInclude(x => x.RoleRewards)
|
||||||
.Include(x => x.XpSettings)
|
.Include(x => x.XpSettings)
|
||||||
|
.ThenInclude(x => x.CurrencyRewards)
|
||||||
|
.Include(x => x.XpSettings)
|
||||||
.ThenInclude(x => x.ExclusionList));
|
.ThenInclude(x => x.ExclusionList));
|
||||||
|
|
||||||
if (gc.XpSettings == null)
|
if (gc.XpSettings == null)
|
||||||
|
@ -21,7 +21,7 @@ namespace NadekoBot.Core.Services.Impl
|
|||||||
private readonly IBotCredentials _creds;
|
private readonly IBotCredentials _creds;
|
||||||
private readonly DateTime _started;
|
private readonly DateTime _started;
|
||||||
|
|
||||||
public const string BotVersion = "2.4.4";
|
public const string BotVersion = "2.5.0";
|
||||||
|
|
||||||
public string Author => "Kwoth#2560";
|
public string Author => "Kwoth#2560";
|
||||||
public string Library => "Discord.Net";
|
public string Library => "Discord.Net";
|
||||||
|
Loading…
Reference in New Issue
Block a user