-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from 37 commits
0f08f1f
44be5dd
2862b69
f3d83d9
12081c7
27a4701
4c79d7a
9e1bdc8
034fb35
5ff153f
cbf58b5
89f1d23
b49b821
930d254
e649660
cce1662
994f821
f478071
b90c644
909a6c8
1e20d18
7c3432a
7226fec
6d16d05
c629909
013984a
cac3fbe
168c08d
3bd59e6
f961cce
47eea63
7f0988e
4521df1
bdc7e9d
ec4d474
bee87b7
ee98460
c6179ec
955f2bf
5e084f0
10f4014
841c2d2
3713ab0
bbdace5
8eabbe9
978f3da
905171b
42aaae8
47f3028
ef7b265
a245e4e
2f727cc
25f08df
92e3fc5
9cea351
c7cc608
af349b5
e9d22ef
9a3e5bc
195e22e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
{ | ||
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(); | ||
} | ||
} | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 : ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
; | ||
} | ||
} |
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); | ||
} | ||
} |
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)); | ||
} | ||
} |
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, | ||
} |
There was a problem hiding this comment.
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.