feat: Moves antimacro to a configuration (#1323)

### Summary

- [X] Moves antimacro to `Distribution/Configuration/antimacro.json`.
- [X] Disables antimacro by default.
This commit is contained in:
Kamron Batman 2023-01-23 21:51:05 -08:00 • committed by GitHub
parent 4f67b1174f
commit 4707666890
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 169 additions and 39 deletions

View file

@ -1,7 +1,10 @@
using System;
using System.IO;
using System.Text.Json.Serialization;
using Server.Collections;
using Server.Factions;
using Server.Json;
using Server.Mobiles;
using Server.Regions;
namespace Server.Misc;
@ -18,18 +21,9 @@ public static class SkillCheck
// Publish 16 changed max stats from 100 to 125
private static int StatMax = Core.LBR ? 125 : 100;
public const int Allowance = 3; // How many times may we use the same location/target for gain
private const int
LocationSize = 5; // The size of eeach location, make this smaller so players dont have to move as far
private static readonly bool AntiMacroCode = !Core.ML; // Change this to false to disable anti-macro code
public static TimeSpan AntiMacroExpire = TimeSpan.FromMinutes(5.0); // How long do we remember targets/locations?
private static readonly bool[] UseAntiMacro =
// *** NOTE ***: Modifying these values will not change an already created antimacro.json file!
private static readonly bool[] _skillThatUseAntiMacro =
{
// true if this skill uses the anti-macro code, false if it does not
false, // Alchemy = 0,
true, // Anatomy = 1,
true, // AnimalLore = 2,
@ -93,6 +87,32 @@ public static class SkillCheck
private static readonly TimeSpan m_StatGainDelay = TimeSpan.FromMinutes(Core.ML ? 0.05 : 15);
private static readonly TimeSpan m_PetStatGainDelay = TimeSpan.FromMinutes(5.0);
private const string _antiMacroPath = "Configuration/antimacro.json";
public static AntiMacroSettings AntiMacro { get; private set; }
public static void Configure()
{
var path = Path.Combine(Core.BaseDirectory, _antiMacroPath);
if (File.Exists(path))
{
AntiMacro = JsonConfig.Deserialize<AntiMacroSettings>(path);
}
else
{
AntiMacro = new AntiMacroSettings
{
Enabled = false,
Allowance = 3,
LocationSize = 5,
Expire = TimeSpan.FromMinutes(5.0),
SkillsThatUseAntiMacro = new BitArray(_skillThatUseAntiMacro)
};
JsonConfig.Serialize(Path.Join(Core.BaseDirectory, _antiMacroPath), AntiMacro);
}
}
public static void Initialize()
{
Mobile.SkillCheckLocationHandler = Mobile_SkillCheckLocation;
@ -125,7 +145,8 @@ public static class SkillCheck
var chance = (value - minSkill) / (maxSkill - minSkill);
var loc = new Point2D(from.Location.X / LocationSize, from.Location.Y / LocationSize);
var size = AntiMacro.LocationSize;
var loc = new Point2D(from.Location.X / size, from.Location.Y / size);
return CheckSkill(from, skill, loc, chance);
}
@ -148,7 +169,8 @@ public static class SkillCheck
return true; // No challenge
}
var loc = new Point2D(from.Location.X / LocationSize, from.Location.Y / LocationSize);
var size = AntiMacro.LocationSize;
var loc = new Point2D(from.Location.X / size, from.Location.Y / size);
return CheckSkill(from, skill, loc, chance);
}
@ -257,7 +279,7 @@ public static class SkillCheck
return false;
}
if (AntiMacroCode && from is PlayerMobile mobile && UseAntiMacro[skill.Info.SkillID])
if (AntiMacro.Enabled && from is PlayerMobile mobile && AntiMacro.UseAntiMacro(skill.Info.SkillID))
{
return mobile.AntiMacroCheck(skill, obj);
}
@ -496,4 +518,24 @@ public static class SkillCheck
IncreaseStat(from, stat, atrophy);
}
public record AntiMacroSettings
{
// How many times may we use the same location/target for gain
public int Allowance { get; init; }
// The size of each location, make this smaller so players dont have to move as far
public int LocationSize { get; init; }
public bool Enabled { get; init; }
// How long do we remember targets/locations?
public TimeSpan Expire { get; init; }
[JsonConverter(typeof(BitArrayEnumIndexConverter<SkillName>))]
public BitArray SkillsThatUseAntiMacro { get; init; }
public bool UseAntiMacro(int skillId) =>
skillId < SkillsThatUseAntiMacro.Length && SkillsThatUseAntiMacro[skillId];
}
}