Skip to content

Commit 6010af8

Browse files
add Chance method
1 parent e43a389 commit 6010af8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Code/Examples/ChaosCoinScript.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ IsAllowed false
2828
end
2929
3030
# 50% chance to lose the coin
31-
if {RandomNum 1 2 int} == 1
31+
if {Chance 50%}
3232
Hint @evPlayer 3s "{$hintInfo}Your coin has turned into dust..."
3333
AdvDestroyItem {@evPlayer heldItemRef}
3434
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using JetBrains.Annotations;
2+
using SER.Code.ArgumentSystem.Arguments;
3+
using SER.Code.ArgumentSystem.BaseArguments;
4+
using SER.Code.MethodSystem.BaseMethods.Synchronous;
5+
using SER.Code.MethodSystem.MethodDescriptors;
6+
using SER.Code.ValueSystem;
7+
8+
namespace SER.Code.MethodSystem.Methods.NumberMethods;
9+
10+
[UsedImplicitly]
11+
public class ChanceMethod : ReturningMethod<BoolValue>, IAdditionalDescription
12+
{
13+
public override string Description =>
14+
"Generates a random number; returns true if it is less than your specified percentage threshold.";
15+
16+
public override Argument[] ExpectedArguments { get; } =
17+
[
18+
new FloatArgument("chance", 0, 1)
19+
];
20+
21+
public override void Execute()
22+
{
23+
ReturnValue = Args.GetFloat("chance") < UnityEngine.Random.Range(0f, 1f);
24+
}
25+
26+
public string AdditionalDescription =>
27+
"In simple terms, when you use {Chance 20%}, it will return true 20% of the time.";
28+
}

0 commit comments

Comments
 (0)