Skip to content

Commit 8723266

Browse files
committed
2 parents 6fc8771 + 82e3f32 commit 8723266

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
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+
}

Code/MethodSystem/Methods/RespawnMethods/RespawnWaveInfoMethod.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using JetBrains.Annotations;
22
using LabApi.Features.Wrappers;
33
using PlayerRoles;
4+
using Respawning;
5+
using Respawning.Waves;
6+
using Respawning.Waves.Generic;
47
using SER.Code.ArgumentSystem.Arguments;
58
using SER.Code.ArgumentSystem.BaseArguments;
69
using SER.Code.ArgumentSystem.Structures;
@@ -14,36 +17,39 @@ namespace SER.Code.MethodSystem.Methods.RespawnMethods;
1417
[UsedImplicitly]
1518
public class RespawnWaveInfoMethod : LiteralValueReturningMethod, IReferenceResolvingMethod
1619
{
17-
public Type ReferenceType => typeof(RespawnWave);
20+
public Type ReferenceType => typeof(TimeBasedWave);
1821

1922
public override TypeOfValue LiteralReturnTypes => new TypesOfValue([
2023
typeof(NumberValue),
21-
typeof(TextValue)
24+
typeof(TextValue),
25+
typeof(DurationValue)
2226
]);
2327

2428
public override string Description => IReferenceResolvingMethod.Desc.Get(this);
2529

2630
public override Argument[] ExpectedArguments { get; } =
2731
[
28-
new ReferenceArgument<RespawnWave>("respawnWave"),
32+
new ReferenceArgument<TimeBasedWave>("respawnWave"),
2933
new OptionsArgument("property",
3034
Option.Enum<Faction>(),
3135
"maxWaveSize",
3236
"respawnTokens",
3337
"influence",
34-
"secondsLeft")
38+
"timeleft"
39+
)
3540
];
3641

3742
public override void Execute()
3843
{
39-
var wave = Args.GetReference<RespawnWave>("respawnWave");
44+
var wave = Args.GetReference<TimeBasedWave>("respawnWave");
45+
4046
ReturnValue = Args.GetOption("property") switch
4147
{
42-
"faction" => new TextValue(wave.Faction.ToString()),
48+
"faction" => new TextValue(wave.TargetFaction.ToString()),
4349
"maxwavesize" => new NumberValue(wave.MaxWaveSize),
44-
"respawntokens" => new NumberValue(wave.RespawnTokens),
45-
"influence" => new NumberValue((decimal)wave.Influence),
46-
"secondsleft" => new NumberValue((decimal)wave.TimeLeft),
50+
"respawntokens" => new NumberValue(wave is ILimitedWave limitedWave ? limitedWave.RespawnTokens : 0),
51+
"influence" => new NumberValue((decimal)FactionInfluenceManager.Get(wave.TargetFaction)),
52+
"timeleft" => new DurationValue(TimeSpan.FromSeconds(wave.Timer.TimeLeft)),
4753
_ => throw new AndrzejFuckedUpException()
4854
};
4955
}

0 commit comments

Comments
 (0)