2024-01-17 04:11:30 +01:00
using CShocker.Shockers.ShockerSettings.Abstract ;
using Microsoft.Extensions.Logging ;
namespace CShocker.Shockers.Abstract
;
2024-01-17 04:36:38 +01:00
public abstract class Shocker
2024-01-17 04:11:30 +01:00
{
protected readonly AShockerSettings ShockerSettings ;
protected readonly ILogger ? Logger ;
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
{
int i = intensity ? ? ShockerSettings . Intensity . GetRandomRangeValue ( ) ;
int d = duration ? ? ShockerSettings . Duration . GetRandomRangeValue ( ) ;
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 )
foreach ( string shocker in ShockerSettings . ShockerIds )
ControlInternal ( action , shocker , i , d ) ;
else
ControlInternal ( action , shockerId , i , d ) ;
}
protected abstract void ControlInternal ( ControlAction action , string shockerId , int intensity , int duration ) ;
protected Shocker ( AShockerSettings shockerSettings , ILogger ? logger = null )
{
this . ShockerSettings = shockerSettings ;
this . Logger = logger ;
}
}