Skip to content

Commit

Permalink
Update v1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
NockyCZ committed Jun 4, 2024
1 parent 6142525 commit ea86df8
Show file tree
Hide file tree
Showing 19 changed files with 485 additions and 251 deletions.
24 changes: 24 additions & 0 deletions source/DeathmachAPI/DeathmatchAPI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using DeathmatchAPI.Events;
using DeathmatchAPI.Helpers;

namespace DeathmatchAPI;

public interface IDeathmatchAPI
{
public void StartCustomMode(int modeId);
public void ChangeNextMode(int modeId);
public void AddCustomMode(int modeId, ModeData mode);
public void ChangeCheckDistance(int distance);

/*
Team String - Available values: ct | t
Spawns Dictionary - Vector & QAngle to string
*/
public void SetupCustomSpawns(string team, Dictionary<string, string> spawns);
public void SwapHudMessageVisibility(bool visible);
public int GetActiveModeId();
public int GetActiveModeRemainingTime();
public Dictionary<string, ModeData> GetCustomModes();
public event EventHandler<IDeathmatchEventsAPI> DeathmatchEventHandlers;
public void TriggerEvent(IDeathmatchEventsAPI @event);
}
9 changes: 9 additions & 0 deletions source/DeathmachAPI/DeathmatchAPI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions source/DeathmachAPI/Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace DeathmatchAPI.Events;
public interface IDeathmatchEventsAPI
{
public record OnCustomModeStarted(int modeId) : IDeathmatchEventsAPI;
}
16 changes: 16 additions & 0 deletions source/DeathmachAPI/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace DeathmatchAPI.Helpers;

public class ModeData
{
public required string Name { get; set; }
public required int Interval { get; set; }
public required int Armor { get; set; }
public required bool OnlyHS { get; set; }
public required bool KnifeDamage { get; set; }
public required bool RandomWeapons { get; set; }
public required string CenterMessageText { get; set; }
public List<string>? PrimaryWeapons { get; set; }
public List<string>? SecondaryWeapons { get; set; }
public List<string>? Utilities { get; set; }
public List<string>? ExecuteCommands { get; set; }
}
87 changes: 87 additions & 0 deletions source/Deathmatch/API.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using DeathmatchAPI;
using DeathmatchAPI.Events;
using DeathmatchAPI.Helpers;

namespace Deathmatch;

public partial class Deathmatch : IDeathmatchAPI
{
public event EventHandler<IDeathmatchEventsAPI>? DeathmatchEventHandlers;
public void TriggerEvent(IDeathmatchEventsAPI @event)
{
DeathmatchEventHandlers?.Invoke(this, @event);
}

public void StartCustomMode(int modeId)
{
if (!CustomModes.ContainsKey(modeId.ToString()))
throw new Exception($"A Custom mode with ID '{modeId}' cannot be started, because this mode does not exist!");

SetupCustomMode(modeId.ToString());
}

public void ChangeNextMode(int modeId)
{
if (!CustomModes.ContainsKey(modeId.ToString()))
throw new Exception($"A Custom mode with ID '{modeId}' cannot be set as next mode, because this mode does not exist!");

NextMode = modeId;
}

public void AddCustomMode(int modeId, ModeData mode)
{
if (CustomModes.ContainsKey(modeId.ToString()))
throw new Exception($"A Custom mode with ID '{modeId}' cannot be added, because this mode already exists!");

CustomModes.Add(modeId.ToString(), mode);
}

public void ChangeCheckDistance(int distance)
{
CheckedEnemiesDistance = distance;
}

public void SetupCustomSpawns(string team, Dictionary<string, string> spawns)
{
if (team.Equals("ct"))
{
spawnPositionsCT.Clear();
foreach (var spawn in spawns)
{
spawnPositionsCT.Add(ParseVector(spawn.Key), ParseQAngle(spawn.Value));
}
}
else if (team.Equals("t"))
{
spawnPositionsT.Clear();
foreach (var spawn in spawns)
{
spawnPositionsT.Add(ParseVector(spawn.Key), ParseQAngle(spawn.Value));
}
}
else
{
throw new Exception($"Invalid team name '{team}'! Allowed options: ct , t");
}
}

public void SwapHudMessageVisibility(bool visible)
{
VisibleHud = visible;
}

public int GetActiveModeId()
{
return ActiveCustomMode;
}

public int GetActiveModeRemainingTime()
{
return RemainingTime;
}

public Dictionary<string, ModeData> GetCustomModes()
{
return CustomModes;
}
}
15 changes: 0 additions & 15 deletions source/Common/Classes.cs → source/Deathmatch/Common/Classes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@ namespace Deathmatch
{
public partial class Deathmatch
{
public class ModeData
{
public required string Name { get; set; }
public required int Interval { get; set; }
public required int Armor { get; set; }
public required bool OnlyHS { get; set; }
public required bool KnifeDamage { get; set; }
public required bool RandomWeapons { get; set; }
public required string CenterMessageText { get; set; }
public List<string>? PrimaryWeapons { get; set; }
public List<string>? SecondaryWeapons { get; set; }
public List<string>? Utilities { get; set; }
public List<string>? ExecuteCommands { get; set; }
}

public class DeathmatchPlayerData
{
public required string PrimaryWeapon { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using DeathmatchAPI.Helpers;
using Vector = CounterStrikeSharp.API.Modules.Utils.Vector;

namespace Deathmatch
{
public partial class Deathmatch
{
public Dictionary<string, ModeData> CustomModes = new();
public Dictionary<string, Dictionary<string, Dictionary<RestrictType, RestrictData>>> RestrictedWeapons = new();
public static Dictionary<string, ModeData> CustomModes = new();
public static Dictionary<string, Dictionary<string, Dictionary<RestrictType, RestrictData>>> RestrictedWeapons = new();
public static Dictionary<Vector, QAngle> spawnPositionsCT = new();
public static Dictionary<Vector, QAngle> spawnPositionsT = new();
internal static PlayerCache<DeathmatchPlayerData> playerData = new PlayerCache<DeathmatchPlayerData>();
public List<(string, bool, int)> PrefsMenuSounds = new();
public List<(string, bool, int)> PrefsMenuFunctions = new();
public List<string> AllowedPrimaryWeaponsList = new List<string>();
public List<string> AllowedSecondaryWeaponsList = new List<string>();
public List<CCSPlayerController> blockRandomWeaponsIntegeration = new List<CCSPlayerController>();
public static List<(string, bool, int)> PrefsMenuSounds = new();
public static List<(string, bool, int)> PrefsMenuFunctions = new();
public static List<string> AllowedPrimaryWeaponsList = new List<string>();
public static List<string> AllowedSecondaryWeaponsList = new List<string>();
public static List<CCSPlayerController> blockRandomWeaponsIntegeration = new List<CCSPlayerController>();

readonly Dictionary<string, string> weaponSelectMapping = new Dictionary<string, string>
{
Expand All @@ -25,14 +26,14 @@ public partial class Deathmatch
{ "m4a1", "weapon_m4a1_silencer" }
};

readonly HashSet<string> SecondaryWeaponsList = new HashSet<string>
readonly HashSet<string> SecondaryWeaponsList = new()
{
"weapon_hkp2000", "weapon_cz75a", "weapon_deagle", "weapon_elite",
"weapon_fiveseven", "weapon_glock", "weapon_p250",
"weapon_revolver", "weapon_tec9", "weapon_usp_silencer"
};

readonly HashSet<string> PrimaryWeaponsList = new HashSet<string>
readonly HashSet<string> PrimaryWeaponsList = new()
{
"weapon_mag7", "weapon_nova", "weapon_sawedoff", "weapon_xm1014",
"weapon_m249", "weapon_negev", "weapon_mac10", "weapon_mp5sd",
Expand All @@ -42,7 +43,7 @@ public partial class Deathmatch
"weapon_awp", "weapon_g3sg1", "weapon_scar20", "weapon_ssg08"
};

readonly HashSet<string> RadioMessagesList = new HashSet<string>
readonly HashSet<string> RadioMessagesList = new()
{
"coverme", "takepoint", "holdpos", "followme",
"regroup", "takingfire", "go", "fallback",
Expand Down
File renamed without changes.
12 changes: 10 additions & 2 deletions source/Common/Globals.cs → source/Deathmatch/Common/Globals.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Capabilities;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using DeathmatchAPI;
using DeathmatchAPI.Helpers;

namespace Deathmatch
{
public partial class Deathmatch
{
public DeathmatchConfig Config { get; set; } = null!;
private static readonly Random Random = new Random();
public static PluginCapability<IDeathmatchAPI> DeathmatchAPI { get; } = new("deathmatch");
public DeathmatchConfig Config { get; set; } = new();
public static int NextMode;
public static string ModeCenterMessage = "";
public static int ActiveCustomMode = 0;
public static int ModeTimer = 0;
public static int RemainingTime = 500;
public static bool IsActiveEditor = false;
public static bool VisibleHud = true;
public static int CheckedEnemiesDistance = 500;
public static bool IsCasualGamemode;
public static bool DefaultMapSpawnDisabled = false;
public ModeData? ActiveMode;
public static bool IsLinuxServer;
public static ModeData? ActiveMode;
public MemoryFunctionWithReturn<CCSPlayer_ItemServices, CEconItemView, AcquireMethod, NativeObject, AcquireResult>? CCSPlayer_CanAcquireFunc;
public MemoryFunctionWithReturn<int, string, CCSWeaponBaseVData>? GetCSWeaponDataFromKeyFunc;
}
Expand Down
4 changes: 3 additions & 1 deletion source/Configs.cs → source/Deathmatch/Configs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CounterStrikeSharp.API.Core;
using DeathmatchAPI.Helpers;
using System.Text.Json.Serialization;
using static Deathmatch.Deathmatch;

Expand Down Expand Up @@ -30,10 +31,11 @@ public class Gameplay
[JsonPropertyName("Random Selection Of Modes")] public bool RandomSelectionOfModes { get; set; } = true;
[JsonPropertyName("Map Start Custom Mode")] public int MapStartMode { get; set; } = 0;
[JsonPropertyName("New Mode Countdown")] public int NewModeCountdown { get; set; } = 10;
[JsonPropertyName("Hud Type")] public int HudType { get; set; } = 1;
[JsonPropertyName("Check Enemies Distance")] public bool CheckDistance { get; set; } = true;
[JsonPropertyName("Distance From Enemies for Respawn")] public int DistanceRespawn { get; set; } = 500;
[JsonPropertyName("Default Weapons")] public int DefaultModeWeapons { get; set; } = 2;
[JsonPropertyName("Contains Restricted Weapons As Default Weapons")] public bool RemoveRestrictedWeapons { get; set; } = true;
[JsonPropertyName("Include Restricted Weapons As Defaults")] public bool RemoveRestrictedWeapons { get; set; } = true;
[JsonPropertyName("Switch Weapons")] public bool SwitchWeapons { get; set; } = true;
[JsonPropertyName("Allow Buymenu")] public bool AllowBuyMenu { get; set; } = true;
[JsonPropertyName("Use Default Spawns")] public bool DefaultSpawns { get; set; } = false;
Expand Down
Loading

0 comments on commit ea86df8

Please sign in to comment.