示例#1
0
        public async Task EditEvent(EventList eventList)
        {
            using var context = new RPGContext(_options);

            context.Update(eventList);

            await context.SaveChangesAsync().ConfigureAwait(false);
        }
示例#2
0
        public bool Equip(Item item)
        {
            bool success = false;

            using (RPGContext context = new RPGContext())
            {
                if (this.PlayerItem.Item.Type != ItemType.None)
                {
                    Unequip();
                }
                context.PlayerItems.Remove(this.PlayerItem);
                context.Items.Remove(this.PlayerItem.Item);


                bool inRoom            = this.Room.Inventory.Items.Exists(x => x.ItemId == item.ItemId);
                bool inPlayerInventory = this.Inventory.Items.Exists(x => x.ItemId == item.ItemId);

                if (inRoom || inPlayerInventory)
                {
                    Inventory inventory;

                    if (inRoom)
                    {
                        inventory = this.Room.Inventory;
                    }
                    else
                    {
                        inventory = this.Inventory;
                    }
                    InventoryItem inventoryItem = inventory.Items.Find(x => x.ItemId == item.ItemId);

                    inventory.Items.Remove(inventoryItem);
                    context.Remove(inventoryItem);
                    context.Update(inventory);
                }
                else
                {
                    //the item is not somewhere that can be picked up and/or equipped
                }

                PlayerItem playerItem = new PlayerItem
                {
                    PlayerItemId = Guid.NewGuid(),
                    Player       = this,
                    Item         = item
                };

                context.PlayerItems.Add(playerItem);

                context.SaveChanges();
            }

            return(success);
        }
示例#3
0
        public DomainPlayer Update(DomainPlayerUpdateModel player)
        {
            var existingPlayer = GetPlayer(player.Id);

            var result = mapper.Map(player, existingPlayer);

            db.Update(result);
            db.SaveChanges();

            return(mapper.Map <DomainPlayer>(result));
        }
示例#4
0
        public DomainItem Update(DomainItemUpdateModel item)
        {
            var existingItem = GetItem(item.ID);

            var result = mapper.Map(item, existingItem);

            db.Update(result);
            db.SaveChanges();

            return(mapper.Map <DomainItem>(result));
        }
示例#5
0
                public async Task UpdateChannelStats(CommandContext ctx, bool force = false)
                {
                    if (!updateNeeded.ContainsKey(ctx.Guild.Id))
                    {
                        ctx.Client.DebugLogger.LogMessage(LogLevel.Debug, ctx.Client.CurrentApplication.Name, $"{ctx.Guild.Name} not found in updateNeeded dictionary creating new instance.", DateTime.Now);
                        updateNeeded.Add(ctx.Guild.Id, true);
                    }

                    if (!updateNeeded[ctx.Guild.Id] && !force)
                    {
                        ctx.Client.DebugLogger.LogMessage(LogLevel.Debug, ctx.Client.CurrentApplication.Name, $"{ctx.Guild.Name} Does not need to update stats.", DateTime.Now);
                        return;
                    }

                    ctx.Client.DebugLogger.LogMessage(LogLevel.Debug, ctx.Client.CurrentApplication.Name, $"{ctx.Guild.Name} needs stats to be updating, updating now...", DateTime.Now);

                    updateNeeded[ctx.Guild.Id] = false;


                    using var context = new RPGContext(_options);

                    var guildPrefs = await _guildPreferences.GetOrCreateGuildPreferences(ctx.Guild.Id);

                    guildPrefs.TotalCommandsExecuted++;
                    context.Update(guildPrefs);
                    await context.SaveChangesAsync();

                    if (guildPrefs.StatChannels.Count == 0)
                    {
                        ctx.Client.DebugLogger.LogMessage(DSharpPlus.LogLevel.Debug, ctx.Client.CurrentApplication.Name, "This guild is not configured to update a stat channel, updating other stats and returning.", DateTime.Now);
                        return;
                    }

                    foreach (var statChannel in guildPrefs.StatChannels)
                    {
                        DiscordChannel channel = null;

                        channel = ctx.Guild.GetChannel(statChannel.ChannelId);

                        if (channel == null)
                        {
                            ctx.Client.DebugLogger.LogMessage(LogLevel.Warning, ctx.Client.CurrentApplication.Name, $"The stat channel for stat option {statChannel.StatOption} in the guild '{ctx.Guild.Name}' no longer exists and the data base entry will be removed.", DateTime.Now);
                            await _statChannelService.DeleteStatChannel(ctx.Guild.Id, statChannel.StatOption);

                            break;
                        }

                        await channel.ModifyAsync(x => x.Name = $"{statChannel.StatMessage}: { GetStat(ctx, statChannel.StatOption) }").ConfigureAwait(false);
                    }
                }
示例#6
0
        private GameState Continue()
        {
            GameState gameState = new GameState();

            using (RPGContext context = new RPGContext())
            {
                Player player = context.Players.OrderBy(x => x.LastPlayed).First();
                player.LastPlayed = DateTime.Now;
                context.Update(player);
                context.SaveChanges();
                gameState = context.GameStates.FirstOrDefault(x => x.Player == player);
            }

            return(gameState);
        }
示例#7
0
        public bool Unequip()
        {
            bool success = false;

            using (RPGContext context = new RPGContext())
            {
                if (this.PlayerItem.Item.Type == ItemType.None)
                {
                    //you cannot unequip your hand
                }
                else
                {
                    context.PlayerItems.Remove(PlayerItem);
                    Inventory.AddItem(PlayerItem.Item);
                    context.Update(Inventory);
                }
                context.SaveChanges();
            }

            return(success);
        }
示例#8
0
        public async Task CreateOrModifyStatChannel(ulong guildId, ulong channelId, StatOption stat, string message)
        {
            using var context = new RPGContext(_options);

            GuildPreferences guildPrefs = await _guildPreferences.GetOrCreateGuildPreferences(guildId);

            CheckForGuildsStatCatergoryChannel(guildPrefs);

            var channelStat = guildPrefs.StatChannels.Where(x => x.StatOption == stat).FirstOrDefault();

            if (channelStat == null)
            {
                if (guildPrefs.StatChannels.Count >= 3)
                {
                    throw new Exception("You can only have 3 stats at a time, to create a new one, you must delete one of the channels and type `w@guild stats update true`, then try to create your stat channel again.");
                }

                channelStat = new StatChannel()
                {
                    StatMessage        = message,
                    StatOption         = stat,
                    ChannelId          = channelId,
                    GuildPreferencesId = guildPrefs.Id
                };
                context.Add(channelStat);
            }
            else
            {
                channelStat.StatMessage = message;
                channelStat.ChannelId   = channelId;
                channelStat.StatOption  = stat;
                context.Update(channelStat);
            }

            await context.SaveChangesAsync();
        }