Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: /clock command #7

Merged
merged 60 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0f08f1f
Merge branch 'main' of https://github.com/rsek/TheOracle2
rsek Jan 3, 2022
44be5dd
Merge branch 'XenotropicDev:main' into main
rsek Jan 4, 2022
2862b69
Feature: search command for Oracles, Moves, and Assets
XenotropicDev Jan 4, 2022
f3d83d9
ignore local config that isn't in bin, idk why
rsek Jan 2, 2022
12081c7
refactor: standard formatting
XenotropicDev Jan 3, 2022
27a4701
fix: formatting
XenotropicDev Jan 4, 2022
4c79d7a
rename: MomentumBurnOutcome, IsActionDieCanceled
rsek Jan 3, 2022
9e1bdc8
documenting IronswornRoll + some props
rsek Jan 3, 2022
034fb35
summary annotations
rsek Jan 3, 2022
5ff153f
AuthorText => RollTypeLabel
rsek Jan 3, 2022
cbf58b5
fix: removes double interaction response
XenotropicDev Jan 4, 2022
89f1d23
initial commit: clocks!
rsek Jan 5, 2022
b49b821
basic `/clock` implementation
rsek Jan 5, 2022
930d254
additional annotation/errors
rsek Jan 5, 2022
e649660
separate Ask the Oracle enum for use by other cmds
rsek Jan 5, 2022
cce1662
first pass at OracleAnswer class
rsek Jan 5, 2022
994f821
rm default value for segments
rsek Jan 5, 2022
f478071
add ToEmbedField method
rsek Jan 5, 2022
b90c644
dummy TensionClock for later
rsek Jan 5, 2022
909a6c8
CampaignClock button methods
rsek Jan 5, 2022
1e20d18
clock imgs, tweaks to AtO output
rsek Jan 7, 2022
7c3432a
fixed missing images
rsek Jan 7, 2022
7226fec
reorganizing directories
rsek Jan 8, 2022
6d16d05
clock subcommands
rsek Jan 8, 2022
c629909
fixing interactions + component names
rsek Jan 8, 2022
013984a
Merge branch 'main' into clocks
rsek Jan 8, 2022
cac3fbe
simplified reference to Method
rsek Jan 8, 2022
168c08d
adding random to Die and OracleAnswer
rsek Jan 8, 2022
3bd59e6
adding default value of null
rsek Jan 8, 2022
f961cce
fix clock increment; "text" param => "title"
rsek Jan 8, 2022
47eea63
add'l dbs to gitignore
rsek Jan 8, 2022
7f0988e
string tweaks
rsek Jan 8, 2022
4521df1
embed color change (blue => red) as clock fills :D
rsek Jan 9, 2022
bdc7e9d
Scene challenges + progress track changes (#8)
rsek Jan 11, 2022
ec4d474
progress overhaul, move reference menus, string DB keys, methods for …
rsek Jan 17, 2022
bee87b7
Merge branch 'XenotropicDev:main' into clocks
rsek Jan 17, 2022
ee98460
Squashed commit of the following:
rsek Jan 18, 2022
c6179ec
meta: code format cleanup
XenotropicDev Jan 18, 2022
955f2bf
fix: breaking change for existing burn-roll buttons.
XenotropicDev Jan 18, 2022
5e084f0
cleanup: remove commented file
XenotropicDev Jan 18, 2022
10f4014
cleanup: remove enum move file
XenotropicDev Jan 18, 2022
841c2d2
refactor: move isMatch check into MatchMessage
XenotropicDev Jan 18, 2022
3713ab0
meta: Don't register the oracle dump command
XenotropicDev Jan 18, 2022
bbdace5
refactor: renamed methods, and added some null handling
XenotropicDev Jan 18, 2022
8eabbe9
refactor: moved extension method
XenotropicDev Jan 18, 2022
978f3da
refactor: use modulus for match detection
XenotropicDev Jan 18, 2022
905171b
fix compiler gripe about missing extensions
rsek Jan 18, 2022
42aaae8
additional extensions for working with customids
rsek Jan 18, 2022
47f3028
cleanup extraneous file
rsek Jan 18, 2022
ef7b265
simplified to AskOption-only version
rsek Jan 18, 2022
a245e4e
simplified to single command with presets
rsek Jan 18, 2022
2f727cc
removing unneeded params from clock menu custom id
rsek Jan 18, 2022
25f08df
methods for parsing whether alerts should be sent
rsek Jan 18, 2022
92e3fc5
add alert toggle button
rsek Jan 18, 2022
9cea351
menu methods forward to button methods
rsek Jan 18, 2022
c7cc608
simplify counter customIds
rsek Jan 18, 2022
af349b5
fixed missing param
rsek Jan 18, 2022
e9d22ef
substitute nicer strings til enum param available
rsek Jan 18, 2022
9a3e5bc
prevent empty tring from being parsed
rsek Jan 18, 2022
195e22e
cleanup
rsek Jan 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,8 @@ omnisharp.json

# local configuration
debugGuilds.json
token.json

# gamecontent db
GameContent.db
token.json
GameContent.db*
33 changes: 33 additions & 0 deletions TheOracle2/AskTheOracle/AskOption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.ComponentModel.DataAnnotations;
namespace TheOracle2;
public enum AskOption
{
[Display(Name = "Sure thing")]
SureThing = 90,
Likely = 75,
[Display(Name = "Fifty-fifty")]
FiftyFifty = 50,
Unlikely = 25,
[Display(Name = "Small chance")]
SmallChance = 10
}

public class AskDefs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't being used as far as I can tell, and I don't really understand the intent of this code. I'm assuming this is something that got left over from some testing or something. I plan on removing it before I merge it in, but let me know if this is for something.

{
public Dictionary<int, string> ByNumber { get; set; }
public Dictionary<string, int> ByString { get; set; }

public AskDefs()
{
ByNumber = new()
{
{ 10, "small chance" },
{ 25, "unlikely" },
{ 50, "fifty-fifty" },
{ 75, "likely" },
{ 90, "sure thing" }
};
ByString = new();
}
}

63 changes: 63 additions & 0 deletions TheOracle2/AskTheOracle/OracleAnswer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace TheOracle2.GameObjects;

public class OracleAnswer : Die, IMatchable
{
public OracleAnswer(Random random, int odds, string question) : base(random, 100)
{
if (odds is < 1 or > 99) { throw new ArgumentOutOfRangeException(nameof(odds), "Chance must be from 1 to 99, inclusive."); }
Question = question;
Odds = odds;
}
public string Question { get; set; }
public int Odds { get; }
public bool IsYes => Value <= Odds;
public bool IsMatch => MatchResults.Contains(Value);
private static readonly List<int> MatchResults = new() { 11, 22, 33, 44, 55, 66, 77, 88, 99, 100 };

public override string ToString()
{
return $"Rolled {Value} vs. {Odds}: **{AnswerString}**";
}
public Color OutcomeColor()
{
return IsYes switch
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style only: Overall I'm not a fan of doing this for something that could be handled very cleanly by a ternary operator. If the rest of the code in this class was using switches I'd be way more okay with it. If I'm in this file later on I reserve the right to change it to a ternary, but I'm really not too worried about it.

{
true => new Color(0x47AEDD),
false => new Color(0xC50933)
};
}
private static string MatchMessage => "You rolled a match! Envision an extreme result or twist.";
private string AnswerString
{
get
{
string str = IsYes ? "Yes" : "No";
if (IsMatch)
{
str = $"hell {str}!".ToUpperInvariant();
XenotropicDev marked this conversation as resolved.
Show resolved Hide resolved
}
return str;
}
}
public static Dictionary<int, string> OddsString => new()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a dictionary<int, string> solely to allow for spaces in the name? Because overall for both code, and possible future localization I think enum with a [DisplayAttribute] is a better way to go, even if it's annoying to get the string value out of the DissplayAttribute

{
{ 10, "Small chance" },
{ 25, "Unlikely" },
{ 50, "50/50" },
{ 75, "Likely" },
{ 90, "Sure thing" }
};

public EmbedBuilder ToEmbed()
{
string authorString = $"Ask the Oracle: {OddsString[Odds]}";
string footerString = IsMatch ? MatchMessage : "";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the MatchMessage should handle the IsMatch value, and either return null or String.Empty. That way the code is at the point of responsibility.

return new EmbedBuilder()
.WithAuthor(authorString)
.WithDescription(ToString())
.WithTitle(Question.Length > 0 ? Question : "Ask the Oracle")
.WithFooter(footerString)
.WithColor(OutcomeColor())
;
}
}
39 changes: 39 additions & 0 deletions TheOracle2/Clock/CampaignClock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace TheOracle2.GameObjects;
public class CampaignClock : Clock
{
public CampaignClock(Embed embed) : base(embed) { }

public CampaignClock(ClockSize segments, int filledSegments, string title, string description = "") : base(segments, filledSegments, title, description) { }
public override string EmbedCategory => "Campaign Clock";
public override string LogMessage => "The event is triggered or the project is complete. Envision the outcome and the impact on your setting.";

public SelectMenuBuilder MakeSelectMenu()
{
SelectMenuBuilder selectMenu = new SelectMenuBuilder()
.WithPlaceholder("Advance clock...")
.WithCustomId($"clock-menu:{Filled}/{Segments}")
.WithMinValues(0)
.WithMaxValues(1)
.AddOption("test", "test");
return selectMenu;
}
public override ComponentBuilder MakeComponents()
{
SelectMenuBuilder menu = new SelectMenuBuilder()
.WithCustomId($"clock-menu:{Filled}/{Segments}")
.WithMinValues(0);
if (!IsFull)
{
menu.AddOption(IClock.AdvanceOption());
foreach (AskOption odds in Enum.GetValues(typeof(AskOption)))
{
menu.AddOption(IClock.AdvanceAskOption(odds));
}
}
if (Filled != 0)
{
menu.AddOption(IClock.ResetOption());
}
return new ComponentBuilder().WithSelectMenu(menu);
}
}
57 changes: 57 additions & 0 deletions TheOracle2/Clock/Clock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace TheOracle2.GameObjects;

public abstract class Clock : IClock
{
protected Clock(Embed embed)
{
var values = IClock.ParseClock(embed);
Title = embed.Title;
Description = embed.Description;
Filled = values.Item1;
Segments = values.Item2;
}
protected Clock(ClockSize segments = (ClockSize)6, int filledSegments = 0, string title = "", string description = "")
{
if (filledSegments < 0 || filledSegments > ((int)segments))
{
throw new ArgumentOutOfRangeException(nameof(filledSegments), "filledSegments can't exceed segments");
}
Title = title;
Segments = (int)segments;
Filled = filledSegments;
Description = description;
}
public int Segments { get; }
public int Filled { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Footer { get; set; }
public abstract string EmbedCategory { get; }
public string AlertFooter { get; }
public bool AlertOnIncrement { get; } = true;
public bool AlertOnDecrement { get; }
public bool LogOnIncrement { get; } = true;
public bool LogOnDecrement { get; } = true;
public bool IsFull => Filled >= Segments;

public virtual EmbedBuilder ToEmbed()
{
var embed = new EmbedBuilder()
.WithAuthor(EmbedCategory)
.WithTitle(Title)
.WithDescription(Description)
;
return IClock.AddClockTemplate(embed, this);
}
public EmbedBuilder AlertEmbed()
{
return IClock.AlertStub(this);
}
public virtual string LogMessage => Filled == Segments ? "The clock fills!" : $"The clock advances to {Filled}/{Segments}";
public virtual ComponentBuilder MakeComponents()
{
return new ComponentBuilder()
.WithButton(IClock.AdvanceButton().WithDisabled(IsFull))
.WithButton(IClock.ResetButton().WithDisabled(Filled == 0));
}
}
31 changes: 31 additions & 0 deletions TheOracle2/Clock/ClockSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.ComponentModel.DataAnnotations;
using Discord.Interactions;
namespace TheOracle2.GameObjects;

// TODO: add display names once ChoiceDisplayAttribute is available
public enum ClockSize
{
[Display(Name = "4 segments")]
Four = 4,

[Display(Name = "6 segments")]
Six = 6,

[Display(Name = "8 segments")]
Eight = 8,

[Display(Name = "10 segments")]
Ten = 10
}

public enum SceneChallengeClockSize
{
[Display(Name = "4 segments")]
Four = 4,

[Display(Name = "6 segments")]
Six = 6,

[Display(Name = "8 segments")]
Eight = 8,
}
Loading