Beispiel #1
0
        public async Task SetActionRepeat(CommandContext c,
                                          [Description("If set to on, the current action will be repeated when it ends (if allowed")] string repeatString)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session.LoadAsync <Player>(c.User.Id.ToString());

                if (repeatString.ToLower() == "on" || repeatString.ToLower() == "true")
                {
                    player.CurrentActionRepeat = true;
                    await c.ConfirmMessage();
                }
                else if (repeatString.ToLower() == "off" || repeatString.ToLower() == "true")
                {
                    player.CurrentActionRepeat = false;
                    await c.ConfirmMessage();
                }
                else
                {
                    await c.RejectMessage();
                }

                if (session.Advanced.HasChanges)
                {
                    await session.SaveChangesAsync();
                }
            }
        }
Beispiel #2
0
        public async Task RegisterNewCharacter(CommandContext c, string raceName)
        {
            c.LogDebug($"Character registration received from {c.User.GetFullUsername()} (race: {raceName})");

            if (await c.RpgChannelGuard() == false)
            {
                return;
            }

            if (ContentManager.Races.ContainsKey(raceName) == false)
            {
                var validRaces = string.Join(", ", ContentManager.Races.Select(r => r.Value.RaceName));
                await c.RespondAsync(
                    $":warning: {c.User.Mention}: \"{raceName}\" is not a valid race. Valid races are: {validRaces}");

                await c.Message.DeleteAsync();
            }

            using (var db = ContentManager.GetDb())
            {
                var players = db.GetPlayerTable();
                var player  = new Player(c.User.Id, raceName, ContentManager.Config.StartingClass);
                players.Insert(player.DiscordId, player);
                c.LogDebug($"Added player character for {c.User.GetFullUsername()} ({c.User.Id})");
            }

            await c.RespondAsync($"{ContentManager.Config.StartingClass} {c.User.Mention} has joined the adventure!");

            await c.ConfirmMessage();

            c.LogDebug($"Character registration completed for {c.User.GetFullUsername()}");
        }
Beispiel #3
0
        public async Task DeleteCharacter(CommandContext c)
        {
            c.LogDebug($"{c.User.GetFullUsername()} -> {nameof(DeleteCharacter)}");

            if (await c.RpgChannelGuard() == false)
            {
                return;
            }

            using (var db = ContentManager.GetDb())
            {
                var players = db.GetPlayerTable();

                if (players.Exists(p => p.DiscordId == c.User.Id) == false)
                {
                    await c.RejectMessage();

                    return;
                }

                players.Delete(p => p.DiscordId == c.User.Id);
            }

            await c.ConfirmMessage();

            await c.RespondAsync($"{c.User.Mention} has left the adventure! {ContentManager.EMOJI_FACE_SAD}");
        }
Beispiel #4
0
        public async Task DoEventEncounter(IAsyncDocumentSession session, CommandContext cmdCtx, Player player)
        {
            var events = (await session.LoadAsync <Event>(Events)).Values.ToList();

            if (events.Count == 0)
            {
                await cmdCtx.ConfirmMessage("Nothing to see here");

                return;
            }

            var evt = events.GetRandomEntry();

            evt.Stages.ForEach(async stage =>
            {
                var stageScript = await Db.DocStore.Operations.SendAsync(new GetAttachmentOperation(evt.Id, stage.Script, AttachmentType.Document, null));

                if (stageScript == null)
                {
                    Serilog.Log.ForContext <Encounter>().Error($"{evt.Id}-{stage.StageName} is missing an action script.");
                    await cmdCtx.RejectMessage($"{evt.Id}-{stage.StageName} is missing an action script. Contact one of the admins (Error_EventStageScriptNotFound)");
                    return;
                }

                string script = await new System.IO.StreamReader(stageScript.Stream).ReadToEndAsync();
                await Script.ScriptManager.RunDiscordScriptAsync($"{evt.Id}-{stage.StageName}", script, cmdCtx, player, null);
            });
        }
Beispiel #5
0
        public async Task AddLevels(CommandContext c,
                                    [Description("")] DiscordUser mention,
                                    [Description("")] int levels)
        {
            if (levels > 10)
            {
                await c.RejectMessage("Cannot add more then 10 levels at the same time");

                return;
            }

            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session.LoadAsync <Player>(mention.Id.ToString());

                if (player == null)
                {
                    await c.RejectMessage(Realm.GetMessage("user_not_registered"));

                    return;
                }

                for (int i = 0; i < levels; i++)
                {
                    var xpNeeded = player.XpNext - player.XpCurrent;
                    await player.AddXpAsync(xpNeeded, c);
                }

                await session.SaveChangesAsync();
            }

            await c.ConfirmMessage();
        }
Beispiel #6
0
        public async Task LookLocation(CommandContext c)
        {
            if (await c.RpgChannelGuard() == false)
            {
                return;
            }
            c.LogDebug($"{c.User.GetFullUsername()} -> {nameof(LookLocation)}");

            using (var db = ContentManager.GetDb())
            {
                var players = db.GetPlayerTable();
                var player  = players.FindOne(p => p.DiscordId == c.User.Id);

                if (player == null)
                {
                    c.LogDebug($"Player {c.User.GetFullUsername()} not found");
                    await c.RejectMessage();

                    return;
                }

                var locEmbed = ContentManager.Locations[player.CurrentLocation].GetLocationEmbed();

                await c.RespondAsync(c.User.Mention, embed : locEmbed);

                await c.ConfirmMessage();
            }
        }
Beispiel #7
0
        public async Task ShowCombatLog(CommandContext c)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var log = await session.LoadAsync <Models.CombatLog>("combatlogs/" + c.User.Id);

                if (log == null)
                {
                    await c.RespondAsync("No combat log available");

                    await c.ConfirmMessage();

                    return;
                }

                var body = new System.Text.StringBuilder();
                body.AppendLine($"**Victor: ** {log.Winner}");
                body.AppendLine($"**Lose: ** {log.Loser}");
                body.AppendLine();
                body.AppendLine("**Log**");
                log.Lines.ForEach(l => body.AppendLine(l));

                var embed = new DiscordEmbedBuilder()
                            .WithTitle("Combat Log")
                            .WithDescription(body.ToString())
                            .WithTimestamp(log.Timestamp);

                await c.Member.SendMessageAsync(embed : embed.Build());
            }
        }
Beispiel #8
0
        public async Task GetSkillInfo(CommandContext c,
                                       [Description("The name of the skill you want info on"), RemainingText] string skillName)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var skill = await session.Query <Skill>("Skills/All")
                            .FirstOrDefaultAsync(s => s.DisplayName.Equals(skillName));

                if (skill == null)
                {
                    await c.RespondAsync($"Skill *{skillName}* couldn't be found");

                    await c.RejectMessage();

                    return;
                }

                var embed = new DiscordEmbedBuilder()
                            .WithTitle(skill.DisplayName)
                            .WithDescription(skill.Description);

                if (skill.ImageUrl != null)
                {
                    embed.WithThumbnailUrl("https://i.redd.it/frqc24q7u96z.jpg");
                }

                await c.RespondAsync(c.User.Mention, embed : embed);
            }

            await c.ConfirmMessage();
        }
Beispiel #9
0
        public async Task EnterBuilding(CommandContext c,
                                        [Description("Name of the building"), RemainingText]
                                        string buildingName)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Location>(loc => loc.Id)
                             .LoadAsync <Player>(c.User.Id.ToString());

                if (player == null)
                {
                    await c.RespondAsync($"{c.User.Mention}, {Realm.GetMessage("not_registered")}");

                    await c.RejectMessage();

                    return;
                }

                if (player.IsIdle == false)
                {
                    await c.RespondAsync(string.Format(Realm.GetMessage("player_not_idle"), c.User.Mention, player.CurrentActionDisplay));

                    await c.RejectMessage();

                    return;
                }

                var location = await session.LoadAsync <Location>(player.CurrentLocation);

                var building =
                    location.Buildings.FirstOrDefault(b => b.Name.Equals(buildingName, System.StringComparison.OrdinalIgnoreCase));

                if (building == null)
                {
                    await c.RespondAsync($"{c.User.Mention}. No building called {buildingName} is located in {location.DisplayName}");

                    await c.RejectMessage();

                    return;
                }

                var bType = Realm.GetBuildingImplementation(building.BuildingImpl);
                if (bType == null)
                {
                    await c.RespondAsync("An error occured. Contact one of the admins and (Error_BuildingImplNotFound)");

                    await c.RejectMessage();

                    return;
                }

                var bImpl = (Buildings.IBuilding)System.Activator.CreateInstance(bType);
                await bImpl.EnterBuilding(c, building);

                await c.ConfirmMessage();
            }
        }
Beispiel #10
0
        public async Task EnterLocation(CommandContext c, Place loc)
        {
            var desc = new System.Text.StringBuilder();

            foreach (var act in loc.Actions)
            {
                var sla = ContentManager.PlaceActions[act];
                desc.AppendLine(sla.Description);
            }

            var embed = new DiscordEmbedBuilder()
                        .WithColor(DiscordColor.Blurple)
                        .WithTitle(loc.Name)
                        .WithDescription(desc.ToString());
            var msg = await c.RespondAsync(embed : embed);

            foreach (var act in loc.Actions)
            {
                var sla = ContentManager.PlaceActions[act];
                await msg.CreateReactionAsync(DiscordEmoji.FromName(c.Client, sla.ReactionIcon));
            }

            await c.ConfirmMessage();

            var inter    = c.Client.GetInteractivity();
            var response = await inter.WaitForMessageReactionAsync(msg, c.User, TimeSpan.FromSeconds(10));

            // If no response, remove request + Action dialog
            if (response == null)
            {
                Serilog.Log.ForContext <InnService>()
                .Debug("Action timeout, removing all messages concerning this service (user: {usr})", c.User.GetFullUsername());
                await c.Message.DeleteAsync();

                await msg.DeleteAsync();

                return;
            }

            await msg.DeleteAllReactionsAsync();

            var responseName = response.Emoji.GetDiscordName().ToLower();

            var actionsToPerform = new List <string>();

            foreach (var act in loc.Actions)
            {
                var sla = ContentManager.PlaceActions[act];

                if (sla.ReactionIcon == responseName)
                {
                    actionsToPerform.AddRange(sla.ActionCommands);
                }
            }

            await new ActionProcessor(c, msg).ProcessActionList(actionsToPerform);
        }
Beispiel #11
0
        public async Task ExecuteSkill(CommandContext c, Skill skill, TrainedSkill trainedSkill, Player source, object target)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var location = await session
                               .Include <Skill>(i => i.Id)
                               .LoadAsync <Location>(source.CurrentLocation);

                if (location.Resources?.Count == 0)
                {
                    await c.ConfirmMessage("No resources available for this skill");

                    return;
                }

                if (skill.Parameters.ContainsKey("ResourceType") == false)
                {
                    await c.RejectMessage("An error occured. Contact one of the admins and (Error_NoResourceTypeForGatherSkill)");

                    return;
                }

                string resourceType = skill.GetParameter <string>("ResourceType");

                // Check if there is a resource type like this on the location
                if (location.Resources.Contains(resourceType))
                {
                    source.BusyUntil            = DateTime.Now.AddSeconds(skill.CooldownRanks[0]);
                    source.CurrentAction        = $"gathering:{skill.Id}";
                    source.CurrentActionDisplay = skill.GetParameter <string>("ActionDisplayText");

                    DoCooldown = true;
                }

                if (session.Advanced.HasChanges)
                {
                    await session.SaveChangesAsync();
                }
            }

            await c.ConfirmMessage();
        }
Beispiel #12
0
        public async Task DiscardItem(CommandContext c,
                                      [Description("The amount to discard. If set to 0, everything will be discarded")] int amount,
                                      [Description("The name of the item to discard"), RemainingText] string itemName)
        {
            if (amount < 0)
            {
                await c.RejectMessage($"{c.User.Mention}, Discard amount should be positive");

                return;
            }

            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Item>(itm => itm.DisplayName)
                             .LoadAsync <Player>(c.User.Id.ToString());

                var itemDef = await session.Query <Item>()
                              .FirstOrDefaultAsync(i => i.DisplayName.Equals(itemName, System.StringComparison.OrdinalIgnoreCase));

                if (itemDef == null)
                {
                    await c.RejectMessage($"{c.User.Mention}, Incorrect item");

                    return;
                }

                if (amount != 0)
                {
                    var entry = player.Inventory.FirstOrDefault(pi => pi.ItemId == itemDef.Id);

                    if (entry.Amount - amount <= 0)
                    {
                        amount = 0;
                    }
                    else
                    {
                        entry.Amount -= amount;
                    }
                }

                if (amount == 0)
                {
                    player.Inventory.RemoveAll(pi => pi.ItemId == itemDef.Id);
                }

                if (session.Advanced.HasChanges)
                {
                    await session.SaveChangesAsync();
                }
            }

            await c.ConfirmMessage("Item(s) have been discarded");
        }
Beispiel #13
0
        //[Cooldown(1, 30, CooldownBucketType.User)]
        public async Task ExploreLocation(CommandContext c)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Location>(loc => loc.Id)
                             .Include <Encounter>(enc => enc.Id)
                             .LoadAsync <Player>(c.User.Id.ToString());

                var location = await session.LoadAsync <Location>(player.CurrentLocation);

                if (location.Encounters == null || location.Encounters?.Count == 0)
                {
                    var fluffEvents = new List <string>();
                    fluffEvents.AddRange(location.FluffEvents);
                    fluffEvents.AddRange(Realm.GetSetting <string[]>("generic_fluff_events"));
                    await c.RespondAsync(fluffEvents.GetRandomEntry());
                }
                else
                {
                    var encounterId = location.Encounters?.GetRandomEntry();
                    var encounter   = await session.LoadAsync <Encounter>(encounterId);

                    await encounter.DoEncounter(session, c, player);

                    //if (encounter?.EncounterType == Encounter.EncounterTypes.Battle)
                    //{
                    //	await encounter.DoBattleEncounter(session, c, player);
                    //}
                }

                if (player.LocationExploreCounts.ContainsKey(player.CurrentLocation) == false)
                {
                    player.LocationExploreCounts.Add(player.CurrentLocation, 0);
                }

                player.LocationExploreCounts[player.CurrentLocation] += 1;

                if (location.ExploresNeeded == player.LocationExploreCounts[player.CurrentLocation])
                {
                    int xp = Realm.GetSetting <int>("settings/complete_explore_xp_award");
                    await player.AddXpAsync(xp);

                    await c.RespondAsync($"{c.User.Mention} has discovered routes to new locations and received {xp}xp.");
                }

                if (session.Advanced.HasChanges)
                {
                    await session.SaveChangesAsync();
                }

                await c.ConfirmMessage();
            }
        }
Beispiel #14
0
        public async Task RegisterPlayer(CommandContext c, string race)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                // Check if player Exists
                if (await session.Advanced.ExistsAsync(c.User.Id.ToString()))
                {
                    await c.RespondAsync($"{c.Member.Mention} You are already registered.");

                    await c.RejectMessage();

                    return;
                }

                var raceInfo = await session.Query <Race>().FirstOrDefaultAsync(r => r.Id == $"races/{race}");

                if (raceInfo == null)
                {
                    await c.RejectMessage($"{c.Member.Mention} Race \"{race}\" is not valid. You can use *.info races* to get a list of races");

                    return;
                }

                var charClass = await session.Query <CharacterClass>().FirstOrDefaultAsync(cls => cls.Id == Realm.GetSetting <string>("startingclass"));

                if (charClass == null)
                {
                    await c.RespondAsync($"Something went wrong while getting the startingclass (Error_StartingClassNull {Realm.GetSetting<string>("startingclass")})");

                    return;
                }

                var player = Realm.GetPlayerRegistration(c.Member, raceInfo, charClass);

                await session.StoreAsync(player);

                await session.SaveChangesAsync();
            }

            var role = c.Guild.Roles.FirstOrDefault(r => r.Name == "Realm Player");

            if (role == null)
            {
                await c.RejectMessage(Realm.GetMessage("missing_player_role"));

                return;
            }

            await c.Member.GrantRoleAsync(role, "Registered for Realm");

            await c.RespondAsync($"{c.User.Mention} has joined the Realm");

            await c.ConfirmMessage();
        }
Beispiel #15
0
        public async Task ListInventory(CommandContext c)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Item>(i => i.Id)
                             .LoadAsync <Player>(c.User.Id.ToString());

                if (player == null)
                {
                    await c.RespondAsync(Realm.GetMessage("user_not_registered"));

                    await c.RejectMessage();

                    return;
                }

                var items = await session.LoadAsync <Item>(player.Inventory.Select(inv => inv.ItemId));

                var itemDict = new SortedDictionary <Item.ItemTypes, List <string> >();

                foreach (var item in player.Inventory)
                {
                    var itemDef = items[item.ItemId];
                    if (itemDict.ContainsKey(itemDef.Type) == false)
                    {
                        itemDict.Add(itemDef.Type, new List <string>());
                    }

                    itemDict[itemDef.Type].Add(itemDef.Type == Item.ItemTypes.Equipment
                                                ? $"{itemDef.DisplayName} (*{itemDef.EquipmentSlot} - x{item.Amount}*)"
                                                : $"{itemDef.DisplayName} *x{item.Amount}*");
                }

                var desc = new System.Text.StringBuilder();
                foreach (var e in itemDict)
                {
                    desc.AppendLine($"*{e.Key}*");
                    e.Value.ForEach(v => desc.AppendLine(v));
                    desc.AppendLine();
                }

                var embed = new DiscordEmbedBuilder()
                            .WithTitle("Inventory")
                            .WithDescription(desc.ToString())
                            .WithTimestamp(System.DateTime.Now);

                await c.Member.SendMessageAsync(embed : embed.Build());

                await c.ConfirmMessage();
            }
        }
Beispiel #16
0
        public async Task UseItem(CommandContext c,
                                  [Description("")] int amount,
                                  [Description(""), RemainingText] string itemName)
        {
            if (amount < 1)
            {
                await c.RejectMessage($"{c.User.Mention}, Amount to use should be positive");

                return;
            }

            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Item>(itm => itm.DisplayName)
                             .LoadAsync <Player>(c.User.Id.ToString());

                var itemDef = await session.Query <Item>()
                              .FirstOrDefaultAsync(i => i.DisplayName.Equals(itemName, System.StringComparison.OrdinalIgnoreCase));

                if (itemDef == null)
                {
                    await c.RejectMessage($"{c.User.Mention}, Incorrect item");

                    return;
                }

                session.Advanced.IgnoreChangesFor(itemDef);

                var invEntry = player.Inventory.FirstOrDefault(pi => pi.ItemId == itemDef.Id);
                if (invEntry.Amount < amount)
                {
                    await c.RejectMessage($"{c.User.Mention}, you don't have that many of that item");

                    return;
                }

                for (int i = 0; i < amount; i++)
                {
                    itemDef.UseOnSelf(player);
                }

                invEntry.Amount -= amount;

                if (session.Advanced.HasChanges)
                {
                    await session.SaveChangesAsync();
                }

                await c.ConfirmMessage($"{c.User.Mention}, {itemDef.UsedResponse}");
            }
        }
Beispiel #17
0
        public async Task RemovePlayer(CommandContext c)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session.LoadAsync <Player>(c.User.Id.ToString());

                if (player == null)
                {
                    await c.RespondAsync(Realm.GetMessage("not_registered"));

                    await c.ConfirmMessage();

                    return;
                }

                session.Delete(player);
                await session.SaveChangesAsync();
            }

            var role = c.Guild.Roles.FirstOrDefault(r => r.Name == "Realm Player");

            if (role == null)
            {
                await c.RespondAsync("No Realm Player role exists");

                await c.RejectMessage();

                return;
            }

            await c.Member.RevokeRoleAsync(role, "Deleted player registration");

            await c.RespondAsync($"{c.User.Mention} has left the Realm");

            await c.ConfirmMessage();
        }
Beispiel #18
0
        public async Task Look(CommandContext c)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Location>(loc => loc.Id)
                             .LoadAsync <Player>(c.User.Id.ToString());

                if (player == null)
                {
                    await c.RespondAsync($"{c.User.Mention}, {Realm.GetMessage("not_registered")}");

                    await c.RejectMessage();

                    return;
                }

                int exploreCounts = -1;
                if (player.LocationExploreCounts.ContainsKey(player.CurrentLocation))
                {
                    exploreCounts = player.LocationExploreCounts[player.CurrentLocation];
                }

                var location = await session.LoadAsync <Location>(player.CurrentLocation);

                var playersOnLoc = await session.Query <Player>()
                                   .Where(pl => pl.CurrentLocation == location.Id && pl.Id != c.User.Id.ToString())
                                   .Select(pl => pl.Id)
                                   .ToListAsync();

                var locEmbed = new DiscordEmbedBuilder(location.GetLocationEmbed(player.FoundHiddenLocations, player.PreviousLocation, exploreCounts));

                if (playersOnLoc.Count > 0)
                {
                    var names = new List <string>();
                    foreach (var pl in playersOnLoc)
                    {
                        names.Add((await c.Guild.GetMemberAsync(ulong.Parse(pl))).DisplayName);
                    }

                    locEmbed.AddField("Also Here", string.Join(", ", names));
                }

                await c.RespondAsync(c.User.Mention, embed : locEmbed.Build());

                await c.ConfirmMessage();
            }
        }
Beispiel #19
0
        public async Task GetCharacterStatus(CommandContext c)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Race>(r => r.Id)
                             .Include <CharacterClass>(cc => cc.Id)
                             .LoadAsync <Player>(c.User.Id.ToString());

                var race = await session.LoadAsync <Race>(player.Race);

                var cls = await session.LoadAsync <CharacterClass>(player.Class);

                var hpPerc = (int)System.Math.Round(((double)player.HpCurrent / player.HpMax) * 100);
                var xpPerc = (int)System.Math.Round(((double)player.XpCurrent / player.XpNext) * 100);

                var hpBar = new System.Text.StringBuilder();
                hpBar.Append(string.Concat(Enumerable.Repeat("|", hpPerc / 10)));
                hpBar.Append(string.Concat(Enumerable.Repeat("-", 10 - (hpPerc / 10))));

                var xpBar = new System.Text.StringBuilder();
                xpBar.Append(string.Concat(Enumerable.Repeat("|", xpPerc / 10)));
                xpBar.Append(string.Concat(Enumerable.Repeat("-", 10 - (xpPerc / 10))));

                var description = new System.Text.StringBuilder();
                description.AppendLine("**Stats:**");
                description.AppendLine($"STR: {player.Attributes.Strength}");
                description.AppendLine($"AGI: {player.Attributes.Agility}");
                description.AppendLine($"STA: {player.Attributes.Stamina}");
                description.AppendLine($"INT: {player.Attributes.Intelligence}");
                description.AppendLine($"WIS: {player.Attributes.Wisdom}");

                var embed = new DiscordEmbedBuilder()
                            .WithTitle($"{player.Name} the {race.DisplayName} {cls.DisplayName}")
                            .AddField("Hp", $"{hpBar} ({player.HpCurrent}/{player.HpMax})")
                            .AddField("Xp", $"{xpBar} ({player.XpCurrent}/{player.XpNext})")
                            .AddField("Skill pts", player.SkillPoints.ToString(), true)
                            .AddField("Attrib pts", player.AttributePoints.ToString(), true)
                            .WithDescription(description.ToString());

                await c.Member.SendMessageAsync(embed : embed.Build());
            }

            await c.ConfirmMessage();
        }
Beispiel #20
0
        public async Task TakeItemFromLocation(CommandContext c,
                                               [Description("The name of the item you want to take"), RemainingText]
                                               string itemName)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Location>(l => l.Id)
                             .LoadAsync <Player>(c.User.Id.ToString());

                var location = await session.LoadAsync <Location>(player.CurrentLocation);

                var inv = location.LocationInventory.FirstOrDefault(i =>
                                                                    i.DisplayName.Equals(itemName, System.StringComparison.OrdinalIgnoreCase));

                if (inv == null)
                {
                    await c.RespondAsync($"Could not find item {itemName} on this location");

                    await c.RejectMessage();

                    return;
                }

                if (inv.Amount == 0)
                {
                    location.LocationInventory.Remove(inv);
                    await c.RespondAsync($"Could not find item {itemName} on this location");

                    await c.RejectMessage();

                    return;
                }

                // Add item to player
                player.AddItemToInventory(inv.DocId, inv.Amount);

                // Remove item/amount from location
                location.LocationInventory.Remove(inv);

                await session.SaveChangesAsync();
            }

            await c.ConfirmMessage();
        }
Beispiel #21
0
        public async Task Teleport(CommandContext c,
                                   [Description("User to teleport")] DiscordUser mention,
                                   [Description("Location to teleport to"), RemainingText] string locationName)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Location>(loc => loc.DisplayName)
                             .LoadAsync <Player>(mention.Id.ToString());

                if (player == null)
                {
                    await c.RespondAsync(Realm.GetMessage("user_not_registered"));

                    await c.RejectMessage();

                    return;
                }

                var location = await session.Query <Location>().FirstOrDefaultAsync(l =>
                                                                                    l.DisplayName.Equals(locationName, System.StringComparison.OrdinalIgnoreCase));

                if (location == null)
                {
                    await c.RespondAsync("Invalid location");

                    await c.RejectMessage();

                    return;
                }

                player.CurrentLocation = location.Id;
                await session.SaveChangesAsync();

                var user = await c.Guild.GetMemberAsync(mention.Id);

                await user.SendMessageAsync($"[REALM] You have been teleported to {location.DisplayName}");
            }

            await c.ConfirmMessage();
        }
Beispiel #22
0
        public async Task StopCurrentAction(CommandContext c)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session.LoadAsync <Player>(c.User.Id.ToString());

                if (player == null)
                {
                    await c.RespondAsync(Realm.GetMessage("not_registered"));

                    await c.RejectMessage();

                    return;
                }

                player.SetIdleAction();
                await session.SaveChangesAsync();

                await c.ConfirmMessage();
            }
        }
Beispiel #23
0
        public async Task LevelUp(CommandContext c,
                                  [Description("User mention who should get the levelup")] DiscordUser mention)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session.LoadAsync <Player>(mention.Id.ToString());

                if (player == null)
                {
                    await c.RejectMessage(Realm.GetMessage("user_not_registered"));

                    return;
                }

                var xpNeeded = player.XpNext - player.XpCurrent;
                await player.AddXpAsync(xpNeeded, c);

                await session.SaveChangesAsync();
            }

            await c.ConfirmMessage();
        }
Beispiel #24
0
        public async Task ListRaces(CommandContext c,
                                    [Description("")] string raceName)
        {
            using (var s = Db.DocStore.OpenAsyncSession())
            {
                var race = await s.Query <Race>().FirstOrDefaultAsync(rn => rn.DisplayName == raceName);

                if (race == null)
                {
                    await c.RejectMessage("This is not a valid race");

                    return;
                }

                var raceInfo = new DiscordEmbedBuilder()
                               .WithTitle($"Race Information - {race.DisplayName}");

                if (string.IsNullOrWhiteSpace(race.ImageUrl) == false)
                {
                    raceInfo.WithImageUrl(race.ImageUrl);
                }

                var descr = new System.Text.StringBuilder(race.Description)
                            .AppendLine()
                            .AppendLine("**Stat Bonusses**")
                            .AppendLine($"{nameof(race.BonusStats.Strength)}: +{race.BonusStats.Strength}")
                            .AppendLine($"{nameof(race.BonusStats.Agility)}: +{race.BonusStats.Agility}")
                            .AppendLine($"{nameof(race.BonusStats.Stamina)}: +{race.BonusStats.Stamina}")
                            .AppendLine($"{nameof(race.BonusStats.Wisdom)}: +{race.BonusStats.Wisdom}")
                            .AppendLine($"{nameof(race.BonusStats.Intelligence)}: +{race.BonusStats.Intelligence}");

                raceInfo.WithDescription(descr.ToString());

                await c.RespondAsync(embed : raceInfo.Build());

                await c.ConfirmMessage();
            }
        }
Beispiel #25
0
        public async Task ListRaces(CommandContext c)
        {
            using (var s = Db.DocStore.OpenAsyncSession())
            {
                var raceList = await s.Query <Race>().ToListAsync();

                var sb = new System.Text.StringBuilder();
                foreach (var r in raceList)
                {
                    sb.AppendLine($"- {r.DisplayName}");
                }

                var embed = new DiscordEmbedBuilder()
                            .WithTitle("Available races:")
                            .WithDescription(sb.ToString())
                            .WithFooter("TODO: .info race human")
                            .Build();

                await c.RespondAsync(embed : embed);
            }

            await c.ConfirmMessage();
        }
Beispiel #26
0
        public async Task HurtOwnCharacter(CommandContext c, int dmgValue)
        {
            c.LogDebug($"{c.User.GetFullUsername()} -> {nameof(HurtOwnCharacter)} ({nameof(dmgValue)}: {dmgValue})");
            using (var db = ContentManager.GetDb())
            {
                var player = db.GetPlayer(c.User.Id);

                player.HpCurrent -= dmgValue;

                if (player.HpCurrent < 0)
                {
                    player.HpCurrent = 0;
                }
                if (player.HpCurrent > player.HpMax)
                {
                    player.HpCurrent = player.HpMax;
                }

                db.GetPlayerTable().Update(player.DiscordId, player);
            }

            await c.ConfirmMessage();
        }
Beispiel #27
0
        public async Task GiveItem(CommandContext c,
                                   [Description("User who will receive the item")] DiscordUser mention,
                                   [Description("The itemid as it's referenced in the database")] string itemId,
                                   [Description("Amount of the item to give. If ommited, defaults to 1")] int amount = 1)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session
                             .Include <Item>(itm => itm.Id)
                             .LoadAsync <Player>(mention.Id.ToString());

                if (player == null)
                {
                    await c.RejectMessage(Realm.GetMessage("user_not_registered"));

                    return;
                }

                var item = await session.LoadAsync <Item>(itemId);

                if (item == null)
                {
                    await c.RejectMessage("No item with that ID exists");

                    return;
                }

                player.AddItemToInventory(item.Id, amount);

                if (session.Advanced.HasChanges)
                {
                    await session.SaveChangesAsync();
                }
            }

            await c.ConfirmMessage();
        }
Beispiel #28
0
        public async Task CharacterStatus(CommandContext c)
        {
            if (await c.RpgChannelGuard() == false)
            {
                return;
            }
            c.LogDebug($"{c.User.GetFullUsername()} -> {nameof(CharacterStatus)}");

            using (var db = ContentManager.GetDb())
            {
                var players = db.GetPlayerTable();
                var player  = players.FindOne(p => p.DiscordId == c.User.Id);

                if (player == null)
                {
                    c.LogDebug($"Player {c.User.GetFullUsername()} not found");
                    await c.RejectMessage();

                    return;
                }

                var embedBuilder = new DiscordEmbedBuilder()
                                   .WithTitle($"**{c.User.Username} the {player.Class}**")
                                   .WithColor(DiscordColor.DarkGray);

                var status = new System.Text.StringBuilder();
                status.AppendLine("**Status**");
                status.AppendLine("**Level:**");
                status.AppendLine($"**- Hp:** {player.HpCurrent}/{player.HpMax}");

                embedBuilder.WithDescription(status.ToString());

                await c.RespondAsync(embed : embedBuilder);

                await c.ConfirmMessage();
            }
        }
Beispiel #29
0
        public async Task TravelToLocation(CommandContext c, string destination)
        {
            if (await c.RpgChannelGuard() == false)
            {
                return;
            }
            c.LogDebug($"{c.User.GetFullUsername()} -> {nameof(TravelToLocation)} (destination: {destination})");

            using (var db = ContentManager.GetDb())
            {
                var players = db.GetPlayerTable();
                var player  = players.FindOne(p => p.DiscordId == c.User.Id);

                if (player == null)
                {
                    c.LogDebug($"Player {c.User.GetFullUsername()} not found");
                    await c.RejectMessage();

                    return;
                }

                var currLoc = ContentManager.Locations[player.CurrentLocation];

                if (currLoc.LocationConnections.Contains(destination, StringComparer.OrdinalIgnoreCase))
                {
                    var nextLoc = ContentManager.Locations[destination];

                    player.CurrentLocation = nextLoc.LocationId;

                    players.Update(player.DiscordId, player);

                    await c.ConfirmMessage();

                    await c.RespondAsync($"{c.User.Mention} arrived in {nextLoc.DisplayName}", embed : nextLoc.GetLocationEmbed());
                }
            }
        }
Beispiel #30
0
        public async Task GiveXp(CommandContext c,
                                 [Description("User mention who should receive the xp")] DiscordUser mention,
                                 [Description("The amount of xp the user will receive")] int xpAmount)
        {
            using (var session = Db.DocStore.OpenAsyncSession())
            {
                var player = await session.LoadAsync <Player>(mention.Id.ToString());

                if (player == null)
                {
                    await c.RespondAsync(Realm.GetMessage("user_not_registered"));

                    await c.RejectMessage();

                    return;
                }

                await player.AddXpAsync(xpAmount, c);

                await session.SaveChangesAsync();

                await c.ConfirmMessage();
            }
        }