v1.0.3
This commit is contained in:
parent
68776c3382
commit
576cee8cfb
87 changed files with 4957 additions and 1558 deletions
153
jRandomSkills - SRC Files/src/utils/Config.cs
Normal file
153
jRandomSkills - SRC Files/src/utils/Config.cs
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
using jRandomSkills.src.player;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics.Metrics;
|
||||
using static jRandomSkills.jRandomSkills;
|
||||
|
||||
namespace jRandomSkills
|
||||
{
|
||||
public static class Config
|
||||
{
|
||||
private static readonly string configPath = Path.Combine(Instance.ModuleDirectory, "Config.json");
|
||||
public static ConfigModel config;
|
||||
private static FileSystemWatcher fileWatcher;
|
||||
|
||||
public static ConfigModel LoadedConfig => config;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
config = LoadConfig();
|
||||
SetupFileWatcher();
|
||||
}
|
||||
|
||||
private static ConfigModel LoadConfig()
|
||||
{
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
Instance.Logger.LogInformation("Config file does not exist. Create a new config file...");
|
||||
var defaultConfig = new ConfigModel();
|
||||
SaveConfig(defaultConfig);
|
||||
return defaultConfig;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string json = File.ReadAllText(configPath);
|
||||
return JsonConvert.DeserializeObject<ConfigModel>(json) ?? new ConfigModel();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Instance.Logger.LogError($"Error when loading the config file.");
|
||||
return new ConfigModel();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveConfig(ConfigModel config)
|
||||
{
|
||||
try
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(config, Formatting.Indented);
|
||||
File.WriteAllText(configPath, json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Instance.Logger.LogError($"Error when saving the config file: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetupFileWatcher()
|
||||
{
|
||||
fileWatcher = new FileSystemWatcher(Path.GetDirectoryName(configPath))
|
||||
{
|
||||
Filter = Path.GetFileName(configPath),
|
||||
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size
|
||||
};
|
||||
|
||||
fileWatcher.Changed += (sender, e) => config = LoadConfig();
|
||||
fileWatcher.EnableRaisingEvents = true;
|
||||
}
|
||||
|
||||
public class ConfigModel
|
||||
{
|
||||
public Settings Settings { get; set; } = new Settings();
|
||||
public SkillInfo[] SkillsInfo = {
|
||||
new SkillInfo(Skills.None),
|
||||
new SkillInfo(Skills.Dwarf, chanceFrom : .6f, chanceTo : .95f),
|
||||
new SkillInfo(Skills.SwapPosition, cooldown: 30),
|
||||
new SkillInfo(Skills.FrozenDecoy),
|
||||
new SkillInfo(Skills.Soldier),
|
||||
new SkillInfo(Skills.Armored, chanceFrom : .65f, chanceTo : .85f),
|
||||
new SkillInfo(Skills.Aimbot, only1v1: true),
|
||||
new SkillInfo(Skills.Retreat, cooldown: 15),
|
||||
new SkillInfo(Skills.EnemySpawn, cooldown: 15),
|
||||
new SkillInfo(Skills.Zeus),
|
||||
new SkillInfo(Skills.RadarHack),
|
||||
new SkillInfo(Skills.QuickShot),
|
||||
new SkillInfo(Skills.Planter, team: 2),
|
||||
new SkillInfo(Skills.Silent),
|
||||
new SkillInfo(Skills.KillerFlash),
|
||||
new SkillInfo(Skills.TimeManipulator, cooldown: 30),
|
||||
new SkillInfo(Skills.GodMode, cooldown: 30),
|
||||
new SkillInfo(Skills.RandomWeapon, cooldown: 15),
|
||||
new SkillInfo(Skills.WeaponsSwap, cooldown: 30),
|
||||
new SkillInfo(Skills.Wallhack),
|
||||
new SkillInfo(Skills.Flash, chanceFrom : 1.2f, chanceTo : 3.0f),
|
||||
new SkillInfo(Skills.PawelJumper),
|
||||
new SkillInfo(Skills.BunnyHop),
|
||||
new SkillInfo(Skills.Impostor),
|
||||
new SkillInfo(Skills.OneShot),
|
||||
new SkillInfo(Skills.Muhammed),
|
||||
new SkillInfo(Skills.RichBoy),
|
||||
new SkillInfo(Skills.Rambo),
|
||||
new SkillInfo(Skills.Medic),
|
||||
new SkillInfo(Skills.Ghost),
|
||||
new SkillInfo(Skills.Chicken),
|
||||
new SkillInfo(Skills.Astronaut, chanceFrom : .1f, chanceTo : .7f),
|
||||
new SkillInfo(Skills.Disarmament, chanceFrom: .2f, chanceTo: .4f),
|
||||
new SkillInfo(Skills.AntyFlash),
|
||||
new SkillInfo(Skills.Behind, chanceFrom: .2f, chanceTo: .4f),
|
||||
new SkillInfo(Skills.InfiniteAmmo),
|
||||
new SkillInfo(Skills.Catapult, chanceFrom : .2f, chanceTo : .4f),
|
||||
new SkillInfo(Skills.Dracula),
|
||||
new SkillInfo(Skills.Teleporter),
|
||||
new SkillInfo(Skills.Saper),
|
||||
new SkillInfo(Skills.Phoenix, chanceFrom: .2f, chanceTo: .4f),
|
||||
new SkillInfo(Skills.Pilot),
|
||||
new SkillInfo(Skills.Shade),
|
||||
new SkillInfo(Skills.AntyHead),
|
||||
};
|
||||
}
|
||||
|
||||
public class Settings
|
||||
{
|
||||
public string LangCode { get; set; } = "en";
|
||||
public string Set_Skill { get; set; } = "ustawskill, setskill";
|
||||
public string SkillsList_Menu { get; set; } = "supermoc, skille, listamocy, supermoce, losowemoce";
|
||||
public bool KillerSkillInfo { get; set; } = true;
|
||||
public bool TeamMateSkillInfo { get; set; } = true;
|
||||
public bool SummaryAfterTheRound { get; set; } = true;
|
||||
}
|
||||
|
||||
public class SkillInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public bool Active { get; set; }
|
||||
public float Cooldown { get; set; }
|
||||
public float ChanceFrom { get; set; }
|
||||
public float ChanceTo { get; set; }
|
||||
public int Team { get; set; }
|
||||
public bool Only1v1 { get; set; }
|
||||
|
||||
public SkillInfo(Skills skill, bool active = true, float cooldown = 15f, float chanceFrom = 1, float chanceTo = 1, int team = 1, bool only1v1 = false)
|
||||
{
|
||||
Name = skill.ToString();
|
||||
Active = active;
|
||||
Cooldown = cooldown;
|
||||
ChanceFrom = chanceFrom;
|
||||
ChanceTo = chanceTo;
|
||||
Team = team;
|
||||
Only1v1 = only1v1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
69
jRandomSkills - SRC Files/src/utils/Findtarget.cs
Normal file
69
jRandomSkills - SRC Files/src/utils/Findtarget.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Commands.Targeting;
|
||||
using jRandomSkills.src.utils;
|
||||
using static jRandomSkills.jRandomSkills;
|
||||
|
||||
namespace jRandomSkills;
|
||||
|
||||
public class FindTarget
|
||||
{
|
||||
public static (List<CCSPlayerController> players, string targetname) Find
|
||||
(
|
||||
CommandInfo command,
|
||||
int minArgCount,
|
||||
bool singletarget,
|
||||
bool ignoreMessage = false
|
||||
)
|
||||
{
|
||||
if (command.ArgCount < minArgCount)
|
||||
{
|
||||
return (new List<CCSPlayerController>(), string.Empty);
|
||||
}
|
||||
|
||||
TargetResult targetresult = command.GetArgTargetResult(1);
|
||||
|
||||
if (targetresult.Players.Count == 0)
|
||||
{
|
||||
if (!ignoreMessage)
|
||||
{
|
||||
command.ReplyToCommand(Localization.GetTranslation("no_player"));
|
||||
}
|
||||
|
||||
return (new List<CCSPlayerController>(), string.Empty);
|
||||
}
|
||||
else if (singletarget && targetresult.Players.Count > 1)
|
||||
{
|
||||
command.ReplyToCommand(Localization.GetTranslation("duplicate_player"));
|
||||
return (new List<CCSPlayerController>(), string.Empty);
|
||||
}
|
||||
|
||||
string targetname;
|
||||
|
||||
if (targetresult.Players.Count == 1)
|
||||
{
|
||||
targetname = targetresult.Players.Single().PlayerName;
|
||||
}
|
||||
else
|
||||
{
|
||||
Target.TargetTypeMap.TryGetValue(command.GetArg(1), out TargetType type);
|
||||
|
||||
targetname = type switch
|
||||
{
|
||||
TargetType.GroupAll => Instance.Localizer["all"],
|
||||
TargetType.GroupBots => Instance.Localizer["bots"],
|
||||
TargetType.GroupHumans => Instance.Localizer["humans"],
|
||||
TargetType.GroupAlive => Instance.Localizer["alive"],
|
||||
TargetType.GroupDead => Instance.Localizer["dead"],
|
||||
TargetType.GroupNotMe => Instance.Localizer["notme"],
|
||||
TargetType.PlayerMe => targetresult.Players.First().PlayerName,
|
||||
TargetType.TeamCt => Instance.Localizer["ct"],
|
||||
TargetType.TeamT => Instance.Localizer["t"],
|
||||
TargetType.TeamSpec => Instance.Localizer["spec"],
|
||||
_ => targetresult.Players.First().PlayerName
|
||||
};
|
||||
}
|
||||
|
||||
return (targetresult.Players, targetname);
|
||||
}
|
||||
}
|
||||
57
jRandomSkills - SRC Files/src/utils/Localization.cs
Normal file
57
jRandomSkills - SRC Files/src/utils/Localization.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace jRandomSkills.src.utils
|
||||
{
|
||||
public static class Localization
|
||||
{
|
||||
private static readonly string path = Path.Combine(jRandomSkills.Instance.ModuleDirectory, "lang");
|
||||
private static readonly Dictionary<string, Dictionary<string, string>> _translations = new Dictionary<string, Dictionary<string, string>>();
|
||||
private static string langCode = "pl";
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
_translations.Clear();
|
||||
SetLangCode();
|
||||
LoadAllLanguages();
|
||||
}
|
||||
|
||||
private static void SetLangCode()
|
||||
{
|
||||
langCode = Config.config.Settings.LangCode;
|
||||
}
|
||||
|
||||
private static void LoadAllLanguages()
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
return;
|
||||
|
||||
foreach (var file in Directory.GetFiles(path, "*.json"))
|
||||
LoadLanguage(file);
|
||||
}
|
||||
|
||||
private static void LoadLanguage(string langPath)
|
||||
{
|
||||
if (!File.Exists(langPath))
|
||||
return;
|
||||
|
||||
var code = Path.GetFileNameWithoutExtension(langPath);
|
||||
var jsonText = File.ReadAllText(langPath);
|
||||
var translations = JsonSerializer.Deserialize<Dictionary<string, string>>(jsonText);
|
||||
|
||||
if (translations != null)
|
||||
_translations[code] = translations;
|
||||
}
|
||||
|
||||
public static string GetTranslation(string key, params object[] args)
|
||||
{
|
||||
if (_translations.TryGetValue(langCode, out var langDict) && langDict.TryGetValue(key, out var translation))
|
||||
if (args.Length != 0 && args[0] == "welcome")
|
||||
return translation;
|
||||
else
|
||||
return string.Format(translation, args).Replace("CHATCOLORS.RED", ChatColors.Red.ToString());
|
||||
|
||||
return key;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
jRandomSkills - SRC Files/src/utils/Utils.cs
Normal file
23
jRandomSkills - SRC Files/src/utils/Utils.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using jRandomSkills.src.player;
|
||||
|
||||
namespace jRandomSkills
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
public static void PrintToChat(CCSPlayerController player, string msg, bool isError)
|
||||
{
|
||||
string checkIcon = isError ? $"{ChatColors.DarkRed}✖{ChatColors.LightRed}" : $"{ChatColors.Green}✔{ChatColors.Lime}";
|
||||
player.PrintToChat($" {ChatColors.DarkRed}► {ChatColors.Green}[{ChatColors.DarkRed} jRadnomSkills {ChatColors.Green}] {checkIcon} {msg}");
|
||||
}
|
||||
|
||||
public static void RegisterSkill(Skills skill, string color, bool display = true)
|
||||
{
|
||||
if (!SkillData.Skills.Any(s => s.Skill == skill))
|
||||
{
|
||||
SkillData.Skills.Add(new dSkill_SkillInfo(skill, color, display));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue