public async Task AddXpAsync(int amount, DSharpPlus.CommandsNext.CommandContext c = null) { bool hasLeveled = false; XpCurrent += amount; if (XpCurrent >= XpNext) { hasLeveled = true; while (XpCurrent >= XpNext) { XpCurrent = XpCurrent - XpNext; Level++; XpNext = Rpg.GetNextXp(Level); SkillPoints += Realm.GetSetting <int>("skill_points_per_levelup"); AttributePoints += Realm.GetSetting <int>("attribute_points_per_levelup"); } } if (hasLeveled == false || c == null) { return; } HpMax = Rpg.GetBaseHpForLevel(Level); HpCurrent = HpMax; var g = await Bot.RpgBot.Client.GetGuildAsync(GuildId); var m = await g.GetMemberAsync(ulong.Parse(Id)); await c.Channel.SendMessageAsync($"{m.Mention} is now level {Level}!"); }
//[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(); } }
/// <summary> /// Player is resting, healing 10% hp/tick /// </summary> /// <param name="p"></param> void Resting(Player p) { int heal = (p.HpMax / 100) * Realm.GetSetting <int>("rest_heal_perc"); p.HealHpAsync(heal).ConfigureAwait(false); if (p.HpCurrent == p.HpMax) { p.SetIdleAction(); return; } if (p.CurrentActionRepeat) { _log.Debug("Repeating rest action for {pname} ({pid})", p.Name, p.Id); p.SetActionAsync(p.CurrentAction, p.CurrentActionDisplay, TimeSpan.FromMinutes(1)).GetAwaiter(); } }
public async Task <int> SetFaintedAsync() { return(await Task.Run(() => { CurrentLocation = Realm.GetSetting <string>("startinglocation"); HpCurrent = HpMax; var percentage = Realm.GetSetting <int>("faint_xp_penalty"); var xpLoss = (XpCurrent / 100) * percentage; XpCurrent = XpCurrent - xpLoss; if (XpCurrent < 0) { XpCurrent = 0; } return xpLoss; })); }
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(); }
public DiscordEmbed GetLocationEmbed( List <string> foundHiddenLocations = null, string entranceId = null, int exploreCount = -1) { var builder = new DiscordEmbedBuilder() .WithTitle(DisplayName); var desc = new System.Text.StringBuilder(Description); // Hostility Colors switch (SafetyRating.ToLower()) { case "sanctuary": builder.WithColor(DiscordColor.Gold); break; case "friendly": builder.WithColor(DiscordColor.SpringGreen); break; case "neutral": builder.WithColor(DiscordColor.CornflowerBlue); break; case "caution": builder.WithColor(DiscordColor.Orange); break; case "dangerous": builder.WithColor(DiscordColor.IndianRed); break; case "hostile": builder.WithColor(DiscordColor.Red); break; default: builder.WithColor(DiscordColor.White); break; } // Buildings if (Buildings?.Count > 0) { builder.AddField("Buildings", string.Join(", ", Buildings.Select(b => b.Name))); } // Exits var exits = new List <string>(); if (LocationConnections.Keys.Count > 0) { // Always show all exits for the starting location if (exploreCount >= ExploresNeeded || Id == Realm.GetSetting <string>("startinglocation")) { exits.AddRange(LocationConnections.Keys); } else { exits.Add(LocationConnections.FirstOrDefault(l => l.Value.Equals(entranceId, System.StringComparison.OrdinalIgnoreCase)).Key); } } // Include hidden exits (if found) if (HiddenLocationConnections.Keys.Count > 0 && foundHiddenLocations != null) { var toInclude = HiddenLocationConnections .Where(l => foundHiddenLocations.Contains(l.Value)) .Select(l => l.Key); exits.AddRange(toInclude); } builder.AddField("Exits", string.Join(", ", exits)); // Location Inventory if (LocationInventory?.Count > 0) { var items = LocationInventory.Select(inv => $"{inv.DisplayName} (x{inv.Amount})"); builder.AddField("Items", string.Join(", ", items)); } builder.WithDescription(desc.ToString()); return(builder.Build()); }
public async Task ExecuteSkill(CommandContext c, Skill skill, TrainedSkill trainedSkill, Player source, object target) { using (var session = Db.DocStore.OpenAsyncSession()) { // Get locations var location = await session .Include <Item>(i => i.Id) .LoadAsync <Location>(source.CurrentLocation); if (location.Perceptables?.Count == 0 && location.HiddenLocationConnections?.Count == 0) { await c.ConfirmMessage("Nothing to see here"); DoCooldown = true; return; } var roll = Dice.Roll($"1d20+{trainedSkill.Rank}"); var foundPerceptables = location.Perceptables?.Where(p => p.Difficulty <= roll).ToList(); // Select a random one var perceptable = foundPerceptables.GetRandomEntry(); bool perceptablePerformed = false; if (perceptable.Type == Perceptable.PerceptableType.HiddenExit) { // Check if the player hasn't found the exit yet if (source.FoundHiddenLocations.Contains(perceptable.DocId) == false) { source.FoundHiddenLocations.Add(perceptable.DocId); await c.RespondAsync($"{c.User.Mention} found a hidden exit"); perceptablePerformed = true; } } if (perceptable.Type == Perceptable.PerceptableType.Item && perceptablePerformed == false) { var item = await session.LoadAsync <Item>(perceptable.DocId); var existingInventory = location.LocationInventory.FirstOrDefault(li => li.DocId == perceptable.DocId); if (existingInventory == null) { var inv = new LocationInventoryItem { DocId = item.Id, DisplayName = item.DisplayName, Amount = perceptable.Count == 0 ? 1 : perceptable.Count, DecaysOn = DateTime.Now.AddMilliseconds((trainedSkill.Rank * 2.5) * 10000) }; location.LocationInventory.Add(inv); var uncoverVariation = Realm.GetSetting <List <string> >("perception_uncover_variations").GetRandomEntry(); await c.RespondAsync($"{c.User.Mention} uncovered {item.DisplayName} {uncoverVariation} (Roll {roll})"); } else { if (existingInventory.Amount < perceptable.MaxPerceptable) { existingInventory.Amount += perceptable.Count; var percDecaySkillFactor = Realm.GetSetting <double>("skill_perception_decay_factor"); existingInventory.DecaysOn = existingInventory.DecaysOn + TimeSpan.FromMilliseconds(trainedSkill.Rank * percDecaySkillFactor * 10000); var uncoverVariation = Realm.GetSetting <List <string> >("perception_uncover_variations").GetRandomEntry(); await c.RespondAsync($"{c.User.Mention} found some more {item.DisplayName} {uncoverVariation} (Roll {roll})"); } else { await c.RespondAsync($"{c.User.Mention} looked for hours, but couldn't find anything"); } } } // else if (perceptable.Type == Perceptable.PerceptableType.Event) await ProcessPerceptableEvent(perceptable); if (perceptablePerformed == false) { await c.RespondAsync($"{c.User.Mention} couldn't find anything at this place..this time"); } if (session.Advanced.HasChanges) { await session.SaveChangesAsync(); } DoCooldown = true; } await c.ConfirmMessage(); }