Add ShockOnDamage toggle
This commit is contained in:
parent
78b66c5023
commit
0dbb4aa734
|
@ -10,9 +10,13 @@ namespace DalamudShock
|
||||||
|
|
||||||
public string openshockApiKey { get; set; } = string.Empty;
|
public string openshockApiKey { get; set; } = string.Empty;
|
||||||
public string OpenshockShockerID { get; set; } = string.Empty;
|
public string OpenshockShockerID { get; set; } = string.Empty;
|
||||||
|
public string PiShockUser { get; set; } = string.Empty;
|
||||||
|
|
||||||
public int MaxValue { get; set; } = 100;
|
public int MaxValue { get; set; } = 100;
|
||||||
public int MaxDuration { get; set; } = 30;
|
public int MaxDuration { get; set; } = 30;
|
||||||
public bool IsVibrationAllowed { get; set; } = false;
|
public bool IsVibrationAllowed { get; set; } = false;
|
||||||
|
public bool UsePishock { get; set; } = false;
|
||||||
|
public bool ZapOnDamage { get; set; } = false;
|
||||||
|
|
||||||
public bool IsConfigWindowMovable { get; set; } = true;
|
public bool IsConfigWindowMovable { get; set; } = true;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ namespace DalamudShock
|
||||||
public readonly WindowSystem WindowSystem = new("DalamudShock");
|
public readonly WindowSystem WindowSystem = new("DalamudShock");
|
||||||
private ConfigWindow ConfigWindow { get; init; }
|
private ConfigWindow ConfigWindow { get; init; }
|
||||||
private MainWindow MainWindow { get; init; }
|
private MainWindow MainWindow { get; init; }
|
||||||
|
|
||||||
private uint lastHealth;
|
private uint lastHealth;
|
||||||
private DateTime lastShockTime = DateTime.MinValue;
|
private DateTime lastShockTime = DateTime.MinValue;
|
||||||
|
|
||||||
|
@ -82,18 +81,53 @@ namespace DalamudShock
|
||||||
if (currentHealth == lastHealth) return;
|
if (currentHealth == lastHealth) return;
|
||||||
lastHealth = currentHealth;
|
lastHealth = currentHealth;
|
||||||
|
|
||||||
|
if (currentHealth != lastHealth)
|
||||||
|
{
|
||||||
|
lastHealth = currentHealth;
|
||||||
|
|
||||||
|
if (Configuration.ZapOnDamage)
|
||||||
|
{
|
||||||
|
if ((DateTime.Now - lastShockTime).TotalSeconds >= 15)
|
||||||
|
{
|
||||||
|
lastShockTime = DateTime.Now;
|
||||||
|
|
||||||
|
if (Configuration.UsePishock)
|
||||||
|
{
|
||||||
|
SendPiShockApiRequest();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SendOscApiRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (currentHealth < player.MaxHp * 0.5)
|
if (currentHealth < player.MaxHp * 0.5)
|
||||||
{
|
{
|
||||||
if ((DateTime.Now - lastShockTime).TotalSeconds >= 15)
|
if ((DateTime.Now - lastShockTime).TotalSeconds >= 15)
|
||||||
{
|
{
|
||||||
PluginLog.Information($"Player health changed to {currentHealth}, time conditions met. sending API request");
|
PluginLog.Information($"Player health changed to {currentHealth}, time conditions met.");
|
||||||
lastShockTime = DateTime.Now;
|
lastShockTime = DateTime.Now;
|
||||||
SendShockApiRequest();
|
|
||||||
|
if (Configuration.UsePishock)
|
||||||
|
{
|
||||||
|
PluginLog.Information("Using PiShock, triggering PiShock API request.");
|
||||||
|
SendPiShockApiRequest();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PluginLog.Information(
|
||||||
|
"Using default shock API, triggering standard shock API request.");
|
||||||
|
SendOscApiRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void SendShockApiRequest()
|
private async void SendOscApiRequest()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(Configuration.openshockApiKey) || string.IsNullOrEmpty(Configuration.OpenshockShockerID))
|
if (string.IsNullOrEmpty(Configuration.openshockApiKey) || string.IsNullOrEmpty(Configuration.OpenshockShockerID))
|
||||||
{
|
{
|
||||||
|
@ -105,7 +139,7 @@ namespace DalamudShock
|
||||||
|
|
||||||
var random = new Random();
|
var random = new Random();
|
||||||
var intensity = random.Next(0, Configuration.MaxValue);
|
var intensity = random.Next(0, Configuration.MaxValue);
|
||||||
var duration = random.Next(1000, Configuration.MaxDuration);
|
var duration = random.Next(1000, Configuration.MaxDuration * 1000);
|
||||||
|
|
||||||
// Calculate the type based on weighted odds
|
// Calculate the type based on weighted odds
|
||||||
var type = "shock";
|
var type = "shock";
|
||||||
|
@ -159,6 +193,71 @@ namespace DalamudShock
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void SendPiShockApiRequest()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(Configuration.openshockApiKey) || string.IsNullOrEmpty(Configuration.OpenshockShockerID))
|
||||||
|
{
|
||||||
|
PluginLog.Error("Pishock API Key or ShareLink is not configured.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var isVibrationAllowed = Configuration.IsVibrationAllowed;
|
||||||
|
|
||||||
|
var random = new Random();
|
||||||
|
var intensity = random.Next(0, Configuration.MaxValue);
|
||||||
|
var duration = random.Next(1000, Configuration.MaxDuration);
|
||||||
|
|
||||||
|
var type = "0";
|
||||||
|
if (isVibrationAllowed)
|
||||||
|
{
|
||||||
|
var chance = random.Next(1, 11);
|
||||||
|
if (chance > 8)
|
||||||
|
{
|
||||||
|
type = "1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var requestData = new[]
|
||||||
|
{
|
||||||
|
new
|
||||||
|
{
|
||||||
|
Username = Configuration.PiShockUser,
|
||||||
|
Name = "DalamudShock",
|
||||||
|
Code = Configuration.OpenshockShockerID,
|
||||||
|
Intensity = intensity,
|
||||||
|
Duration = duration,
|
||||||
|
Op= type
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var jsonContent = JsonConvert.SerializeObject(requestData);
|
||||||
|
var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
using var client = new HttpClient();
|
||||||
|
client.DefaultRequestHeaders.Add("User-Agent",
|
||||||
|
"Dalamud/0.2 (Windows; U; Windows NT 10.4; x64) AppleWebKit/602.39 (KHTML, like Gecko)");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await client.PostAsync("https://do.pishock.com/api/apioperate", content);
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
PluginLog.Information("{0} sent successfully with intensity {1} and duration {2} ms.", type, intensity, duration);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var responseBody = await response.Content.ReadAsStringAsync();
|
||||||
|
PluginLog.Error($"Shock API request failed: {responseBody}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PluginLog.Error($"Error occurred while sending shock: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,7 @@ namespace DalamudShock.Windows
|
||||||
private Configuration Configuration;
|
private Configuration Configuration;
|
||||||
public ConfigWindow(Plugin plugin) : base("DalamudShock Config###With a constant ID")
|
public ConfigWindow(Plugin plugin) : base("DalamudShock Config###With a constant ID")
|
||||||
{
|
{
|
||||||
Flags = ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoScrollbar |
|
Flags = ImGuiWindowFlags.NoScrollWithMouse;
|
||||||
ImGuiWindowFlags.NoScrollWithMouse;
|
|
||||||
Size = new Vector2(600, 400);
|
Size = new Vector2(600, 400);
|
||||||
SizeCondition = ImGuiCond.Always;
|
SizeCondition = ImGuiCond.Always;
|
||||||
Configuration = plugin.Configuration;
|
Configuration = plugin.Configuration;
|
||||||
|
@ -34,13 +33,13 @@ namespace DalamudShock.Windows
|
||||||
public override void Draw()
|
public override void Draw()
|
||||||
{
|
{
|
||||||
var apiKey = Configuration.openshockApiKey;
|
var apiKey = Configuration.openshockApiKey;
|
||||||
if (ImGui.InputText("OpenShock API Key", ref apiKey, 100))
|
if (ImGui.InputText("API Key", ref apiKey, 100))
|
||||||
{
|
{
|
||||||
Configuration.openshockApiKey = apiKey;
|
Configuration.openshockApiKey = apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
var shockerID = Configuration.OpenshockShockerID;
|
var shockerID = Configuration.OpenshockShockerID;
|
||||||
if (ImGui.InputText("OpenShock Shocker ID", ref shockerID, 100))
|
if (ImGui.InputText("Shocker ID or Share Code", ref shockerID, 100))
|
||||||
{
|
{
|
||||||
Configuration.OpenshockShockerID = shockerID;
|
Configuration.OpenshockShockerID = shockerID;
|
||||||
}
|
}
|
||||||
|
@ -53,17 +52,33 @@ namespace DalamudShock.Windows
|
||||||
if (ImGui.SliderInt("Duration Cap (sec)", ref maxLength, 1, 30))
|
if (ImGui.SliderInt("Duration Cap (sec)", ref maxLength, 1, 30))
|
||||||
{
|
{
|
||||||
// Map the value from [1, 30] to [1000, 30000]
|
// Map the value from [1, 30] to [1000, 30000]
|
||||||
Configuration.MaxDuration = MapValue(maxLength, 1, 30, 1000, 30000);
|
Configuration.MaxDuration = maxLength;
|
||||||
}
|
|
||||||
int MapValue(int value, int fromMin, int fromMax, int toMin, int toMax)
|
|
||||||
{
|
|
||||||
return (int)((float)(value - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin);
|
|
||||||
}
|
}
|
||||||
bool isVibrationAllowed = Configuration.IsVibrationAllowed;
|
bool isVibrationAllowed = Configuration.IsVibrationAllowed;
|
||||||
if (ImGui.Checkbox("Allow Vibration", ref isVibrationAllowed))
|
if (ImGui.Checkbox("Allow Vibration", ref isVibrationAllowed))
|
||||||
{
|
{
|
||||||
Configuration.IsVibrationAllowed = isVibrationAllowed;
|
Configuration.IsVibrationAllowed = isVibrationAllowed;
|
||||||
}
|
}
|
||||||
|
ImGui.SameLine();
|
||||||
|
bool usePsc = Configuration.UsePishock;
|
||||||
|
if (ImGui.Checkbox("Use PiShock API", ref usePsc))
|
||||||
|
{
|
||||||
|
Configuration.UsePishock = usePsc;
|
||||||
|
Configuration.IsVibrationAllowed = usePsc;
|
||||||
|
}
|
||||||
|
ImGui.Spacing();
|
||||||
|
if (usePsc)
|
||||||
|
{
|
||||||
|
string pishockUsername = Configuration.PiShockUser;
|
||||||
|
ImGui.InputText("PiShock Username", ref pishockUsername, 100);
|
||||||
|
Configuration.PiShockUser = pishockUsername;
|
||||||
|
}
|
||||||
|
ImGui.Spacing();
|
||||||
|
bool instantZap = Configuration.ZapOnDamage;
|
||||||
|
if (ImGui.Checkbox("Allow Vibration", ref instantZap))
|
||||||
|
{
|
||||||
|
Configuration.ZapOnDamage = instantZap;
|
||||||
|
}
|
||||||
ImGui.Spacing();
|
ImGui.Spacing();
|
||||||
if (ImGui.Button("Save Configuration"))
|
if (ImGui.Button("Save Configuration"))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue