CShock/CShocker/Shockers/Abstract/Shocker.cs

44 lines
1.6 KiB
C#
Raw Normal View History

2024-01-17 22:16:40 +01:00
using System.Reflection.Metadata;
using CShocker.Ranges;
2024-01-17 04:11:30 +01:00
using Microsoft.Extensions.Logging;
2024-01-17 17:59:10 +01:00
namespace CShocker.Shockers.Abstract;
2024-01-17 04:11:30 +01:00
2024-01-17 04:36:38 +01:00
public abstract class Shocker
2024-01-17 04:11:30 +01:00
{
2024-01-17 19:33:57 +01:00
public readonly List<string> ShockerIds;
public readonly IntensityRange IntensityRange;
public readonly DurationRange DurationRange;
2024-01-17 21:23:08 +01:00
protected ILogger? Logger;
2024-01-17 22:16:40 +01:00
public readonly ShockerApi ApiType;
2024-01-17 04:33:41 +01:00
2024-01-17 04:41:27 +01:00
public void Control(ControlAction action, string? shockerId = null, int? intensity = null, int? duration = null)
2024-01-17 04:11:30 +01:00
{
2024-01-17 17:59:10 +01:00
int i = intensity ?? IntensityRange.GetRandomRangeValue();
int d = duration ?? DurationRange.GetRandomRangeValue();
2024-01-17 04:11:30 +01:00
this.Logger?.Log(LogLevel.Information, $"{action} {(intensity is not null ? $"Overwrite {i}" : $"{i}")} {(duration is not null ? $"Overwrite {d}" : $"{d}")}");
if (action is ControlAction.Nothing)
return;
if(shockerId is null)
2024-01-17 17:59:10 +01:00
foreach (string shocker in ShockerIds)
2024-01-17 04:11:30 +01:00
ControlInternal(action, shocker, i, d);
else
ControlInternal(action, shockerId, i, d);
}
protected abstract void ControlInternal(ControlAction action, string shockerId, int intensity, int duration);
2024-01-17 22:16:40 +01:00
protected Shocker(List<string> shockerIds, IntensityRange intensityRange, DurationRange durationRange, ShockerApi apiType, ILogger? logger = null)
2024-01-17 04:11:30 +01:00
{
2024-01-17 17:59:10 +01:00
this.ShockerIds = shockerIds;
this.IntensityRange = intensityRange;
this.DurationRange = durationRange;
2024-01-17 22:16:40 +01:00
this.ApiType = apiType;
2024-01-17 04:11:30 +01:00
this.Logger = logger;
}
2024-01-17 21:23:08 +01:00
public void SetLogger(ILogger? logger)
{
this.Logger = logger;
}
2024-01-17 04:11:30 +01:00
}