Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ The config file is located in the plugin folder under `config/config.json`.
- `RoundTypePercentages`: The frequency of each type of round. The values must add up to `100`.
- `UsableWeapons`: The weapons that can be allocated. Any weapon removed from this list cannot be used.
- `EnableNextRoundTypeVoting`: Whether to allow voting for the next round type via `!nextround`. `false` by default.
- `NumberOfExtraVipChancesForPreferredWeapon`: When randomly selecting preferred weapons per team (ie. "AWP queue"), how
many extra chances should VIPs get.
- The default is 1, meaning VIPs will get 1 extra chance. For example, lets say
there are 3 players on the team and this config is set to 1. Normally each person would have a 33% chance of getting
the AWP, but in this case, since one of the players is a VIP, the VIP will get a 50% chance of getting the AWP, and
the other two players will each have 25% chance of getting the AWP.
- If you set this to 0, there will be no preference for VIPs.
- `AllowedWeaponSelectionTypes`: The types of weapon allocation that are allowed.
- Choices:
- `PlayerChoice` - Allow players to choose their preferences for the round type
Expand All @@ -101,7 +108,8 @@ The config file is located in the plugin folder under `config/config.json`.
- The connection string for `Sqlite` probably doesnt need to be changed from the default, but you can change it if
you want the db file to be in a different location.
- More info on formatting the string here: https://www.connectionstrings.com/sqlite/
- The connection string for `MySql` should be configured per instructions here: https://www.connectionstrings.com/mysql/
- The connection string for `MySql` should be configured per instructions
here: https://www.connectionstrings.com/mysql/

- `MigrateOnStartup`: Whether or not to migrate the database on startup. This defaults to yes for now, but production
servers may want to change this to false so they can control when database migrations are applied.
Expand All @@ -119,7 +127,8 @@ You can use the following commands to select specific weapon preferences per-use
provided
- For example, if you previously did `!gun galil` while a terrorist, and you do `!removegun galil` while a
terrorist, you will no longer prefer the galil, and will instead get a random weapon
- `!nextround` - Vote for the next round type. Can be enabled with the `EnableNextRoundTypeVoting` config, which is `false` by default.
- `!nextround` - Vote for the next round type. Can be enabled with the `EnableNextRoundTypeVoting` config, which
is `false` by default.
- `!setnextround <P|H|F>` - For admins only. Force the next round to be the selected type.
- `!reload_allocator_config` - For admins only. Reload the JSON config in-place.

Expand Down
3 changes: 3 additions & 0 deletions RetakesAllocator/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;
Expand Down Expand Up @@ -189,4 +190,6 @@ public static int GetNumPlayersOnTeam()
.Where(player => player.Team is CsTeam.Terrorist or CsTeam.CounterTerrorist).ToList()
.Count;
}

public static bool IsVip(CCSPlayerController player) => AdminManager.PlayerHasPermissions(player, "@css/vip");
}
2 changes: 1 addition & 1 deletion RetakesAllocator/RetakesAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;
using RetakesAllocator.Managers;
using RetakesAllocator.Menus;
using RetakesAllocatorCore;
Expand Down Expand Up @@ -437,6 +436,7 @@ public HookResult OnRoundPostStart(EventRoundPoststart @event, GameEventInfo inf
Helpers.GetTeam,
GiveDefuseKit,
AllocateItemsForPlayer,
Helpers.IsVip,
out var currentRoundType
);
RoundTypeManager.GetInstance().SetCurrentRoundType(currentRoundType);
Expand Down
1 change: 1 addition & 0 deletions RetakesAllocatorCore/Config/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public record ConfigData
public bool AllowAllocationAfterFreezeTime { get; set; } = false;
public bool EnableRoundTypeAnnouncement { get; set; } = true;
public bool EnableNextRoundTypeVoting { get; set; } = false;
public int NumberOfExtraVipChancesForPreferredWeapon = 1;

public DatabaseProvider DatabaseProvider { get; set; } = DatabaseProvider.Sqlite;
public string DatabaseConnectionString { get; set; } = "Data Source=data.db";
Expand Down
15 changes: 8 additions & 7 deletions RetakesAllocatorCore/OnRoundPostStartHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;
using RetakesAllocatorCore.Config;
using RetakesAllocatorCore.Db;

namespace RetakesAllocatorCore;
Expand All @@ -15,6 +13,7 @@ public static void Handle<T>(
Func<T, CsTeam> getTeam,
Action<T> giveDefuseKit,
Action<T, ICollection<CsItem>, string?> allocateItemsForPlayer,
Func<T, bool> isVip,
out RoundType currentRoundType
)
{
Expand Down Expand Up @@ -56,12 +55,14 @@ HashSet<T> FilterByPreferredWeaponPreference(IEnumerable<T> ps) =>
userSetting.GetWeaponPreference(getTeam(p), WeaponAllocationType.Preferred) is not null)
.ToHashSet();

ICollection<T> tPreferredPlayers = new HashSet<T>();
ICollection<T> ctPreferredPlayers = new HashSet<T>();
ICollection<T> tPreferredPlayers = new List<T>();
ICollection<T> ctPreferredPlayers = new List<T>();
if (roundType == RoundType.FullBuy)
{
tPreferredPlayers = WeaponHelpers.SelectPreferredPlayers(FilterByPreferredWeaponPreference(tPlayers));
ctPreferredPlayers = WeaponHelpers.SelectPreferredPlayers(FilterByPreferredWeaponPreference(ctPlayers));
tPreferredPlayers =
WeaponHelpers.SelectPreferredPlayers(FilterByPreferredWeaponPreference(tPlayers), isVip);
ctPreferredPlayers =
WeaponHelpers.SelectPreferredPlayers(FilterByPreferredWeaponPreference(ctPlayers), isVip);
}

foreach (var player in allPlayers)
Expand Down
2 changes: 1 addition & 1 deletion RetakesAllocatorCore/PluginInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace RetakesAllocatorCore;

public static class PluginInfo
{
public const string Version = "1.2.7";
public const string Version = "1.2.8";

public static readonly string LogPrefix = $"[RetakesAllocator {Version}] ";
public static readonly string MessagePrefix = $"[{ChatColors.Green}Retakes{ChatColors.White}] ";
Expand Down
36 changes: 28 additions & 8 deletions RetakesAllocatorCore/WeaponHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CounterStrikeSharp.API.Modules.Utils;
using RetakesAllocatorCore.Config;
Expand All @@ -12,6 +13,7 @@ public enum WeaponAllocationType
HalfBuyPrimary,
Secondary,
PistolRound,

// eg. AWP is a preferred gun - you cant always get it even if its your preference
// Right now its only snipers, but if we make this configurable, we need to change:
// - CoercePreferredTeam
Expand Down Expand Up @@ -62,7 +64,7 @@ public static class WeaponHelpers
// Shotgun
CsItem.XM1014,
CsItem.Nova,

// Sniper
CsItem.Scout,
};
Expand Down Expand Up @@ -163,7 +165,9 @@ private static readonly Dictionary<RoundType, ICollection<WeaponAllocationType>>
{
RoundType.FullBuy,
new HashSet<WeaponAllocationType>
{WeaponAllocationType.Secondary, WeaponAllocationType.FullBuyPrimary, WeaponAllocationType.Preferred}
{
WeaponAllocationType.Secondary, WeaponAllocationType.FullBuyPrimary, WeaponAllocationType.Preferred
}
},
};

Expand Down Expand Up @@ -249,6 +253,7 @@ public static bool IsAllocationTypeValidForRound(WeaponAllocationType? allocatio
{
return false;
}

return _validAllocationTypesForRound[roundType.Value].Contains(allocationType.Value);
}

Expand All @@ -262,16 +267,29 @@ public static bool IsPreferred(CsTeam team, CsItem weapon)
};
}

// TODO In the future this will be more complex based on sniper/preferred config and VIP status
public static ICollection<T> SelectPreferredPlayers<T>(ICollection<T> players)
public static IList<T> SelectPreferredPlayers<T>(IEnumerable<T> players, Func<T, bool> isVip)
{
var player = Utils.Choice(players);
var choicePlayers = new List<T>();
foreach (var p in players)
{
choicePlayers.Add(p);
// VIPs get extra chances to be selected
if (isVip(p))
{
for (var i = 0; i < Configs.GetConfigData().NumberOfExtraVipChancesForPreferredWeapon; i++)
{
choicePlayers.Add(p);
}
}
}

var player = Utils.Choice(choicePlayers);
if (player is null)
{
return new HashSet<T>();
return new List<T>();
}

return new HashSet<T> {player};
return new List<T> {player};
}

public static bool IsUsableWeapon(CsItem weapon)
Expand Down Expand Up @@ -327,7 +345,7 @@ public static ICollection<CsItem> FindValidWeaponsByName(string needle)
.Where(item => _allWeapons.Contains(item))
.ToList();
}

public static WeaponAllocationType? GetWeaponAllocationTypeForWeaponAndRound(RoundType? roundType, CsTeam team,
CsItem weapon)
{
Expand All @@ -352,6 +370,7 @@ public static ICollection<CsItem> FindValidWeaponsByName(string needle)
{
return potentialAllocationTypes.First();
}

if (potentialAllocationTypes.Count == 0)
{
return null;
Expand Down Expand Up @@ -449,6 +468,7 @@ private static ICollection<CsItem> FindItemsByName(string needle)
{
return null;
}

return _defaultWeaponsByTeamAndAllocationType[team][allocationType];
}

Expand Down