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(); }
/// <summary> /// Saves the skill. /// </summary> /// <returns>Skill object</returns> public Skill SaveSkill() { SqlDataReader result; DatabaseConnection dbconn = new DatabaseConnection(); SqlCommand command = new SqlCommand(); SqlConnection connection = new SqlConnection(dbconn.SQLSEVERConnString); try { connection.Open(); command.Connection = connection; command.CommandType = CommandType.StoredProcedure; command.CommandText = "InsertUpdate_Skill"; command.Parameters.Add(dbconn.GenerateParameterObj("@SkillID", SqlDbType.Int, SkillID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@SkillName", SqlDbType.VarChar, SkillName.ToString(), 100)); command.Parameters.Add(dbconn.GenerateParameterObj("@SkillDescription", SqlDbType.VarChar, SkillDescription.ToString(), 1000)); command.Parameters.Add(dbconn.GenerateParameterObj("@AbilityID", SqlDbType.Int, AbilityID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@TrainedSkill", SqlDbType.Bit, TrainedSkill.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@SkillTrainingFeatID", SqlDbType.Int, SkillTrainingFeatID.ToString(), 0)); command.Parameters.Add(dbconn.GenerateParameterObj("@AmorProfAffected", SqlDbType.Bit, AmorProfAffected.ToString(), 0)); result = command.ExecuteReader(); result.Read(); SetReaderToObject(ref result); } catch { Exception e = new Exception(); this._insertUpdateOK = false; this._insertUpdateMessage.Append(e.Message + " Inner Exception= " + e.InnerException); throw e; } finally { command.Dispose(); connection.Close(); } return(this); }
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(); }