Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
C9Glax committed Nov 2, 2024
1 parent c6bd342 commit 2d429fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion OpenCS2hock/OpenCS2hock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<ItemGroup>
<PackageReference Include="CS2GSI" Version="1.0.7" />
<PackageReference Include="CShocker" Version="2.3.1" />
<PackageReference Include="CShocker" Version="2.4.0" />
<PackageReference Include="GlaxLogger" Version="1.0.6" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
Expand Down
21 changes: 8 additions & 13 deletions OpenCS2hock/ShockerAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace OpenCS2hock;
public struct ShockerAction
{
public CS2Event TriggerEvent;
// ReSharper disable thrice FieldCanBeMadeReadOnly.Global JsonDeserializer will throw a fit
public int ShockerId;
public ControlAction Action;
public bool ValueFromInput;
public IntegerRange IntensityRange, DurationRange;
// ReSharper disable MemberCanBePrivate.Global -> exposed
public readonly int ShockerId;
public readonly ControlAction Action;
public readonly bool ValueFromInput;
public readonly IntegerRange IntensityRange, DurationRange;

public ShockerAction(CS2Event trigger, int shockerId, ControlAction action, bool valueFromInput, IntegerRange intensityRange, IntegerRange durationRange)
{
Expand All @@ -28,23 +28,18 @@ public void Execute(Dictionary<int, Shocker> shockers, CS2EventArgs cs2EventArgs
{
if (!shockers.ContainsKey(ShockerId))
return;
int intensity = ValueFromInput ? IntensityFromCS2Event(cs2EventArgs) : RandomValueFromRange(IntensityRange);
int duration = RandomValueFromRange(DurationRange);
int intensity = ValueFromInput ? IntensityFromCS2Event(cs2EventArgs) : IntensityRange.RandomValueWithinLimits();
int duration = DurationRange.RandomValueWithinLimits();
shockers[ShockerId].Control(Action, intensity, duration);
}

private static int RandomValueFromRange(IntegerRange range)
{
return Random.Shared.Next(range.Min, range.Max);
}

private int IntensityFromCS2Event(CS2EventArgs cs2EventArgs)
{
return TriggerEvent switch
{
CS2Event.OnDamageTaken => MapInt(cs2EventArgs.ValueAsOrDefault<int>(), 0, 100, IntensityRange.Min, IntensityRange.Max),
CS2Event.OnArmorChange => MapInt(cs2EventArgs.ValueAsOrDefault<int>(), 0, 100, IntensityRange.Min, IntensityRange.Max),
_ => RandomValueFromRange(IntensityRange)
_ => IntensityRange.RandomValueWithinLimits()
};
}

Expand Down

0 comments on commit 2d429fc

Please sign in to comment.