mirror of
https://github.com/MSWS/TTT.git
synced 2025-12-08 15:27:32 -08:00
Compare commits
5 Commits
0.22.1-dev
...
0.22.3-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acb3be9132 | ||
|
|
bbcc998559 | ||
|
|
56781c6ae8 | ||
|
|
0ca983943d | ||
|
|
8cd8e14e18 |
@@ -7,7 +7,7 @@ public interface IPlayer : IEquatable<IPlayer> {
|
||||
/// </summary>
|
||||
string Id { get; }
|
||||
|
||||
string Name { get; }
|
||||
string Name { get; set; }
|
||||
|
||||
bool IEquatable<IPlayer>.Equals(IPlayer? other) {
|
||||
if (other is null) return false;
|
||||
|
||||
@@ -82,6 +82,7 @@ public static class CS2ServiceCollection {
|
||||
collection.AddModBehavior<TraitorChatHandler>();
|
||||
collection.AddModBehavior<PlayerMuter>();
|
||||
collection.AddModBehavior<MapChangeCausesEndListener>();
|
||||
collection.AddModBehavior<NameUpdater>();
|
||||
// collection.AddModBehavior<EntityTargetHandlers>();
|
||||
|
||||
// Damage Cancelers
|
||||
|
||||
@@ -12,7 +12,7 @@ public class CS2ClusterGrenadeConfig : IStorage<ClusterGrenadeConfig>,
|
||||
IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_clustergrenade_price",
|
||||
"Price of the Cluster Grenade item (Traitor)", 90, ConVarFlags.FCVAR_NONE,
|
||||
"Price of the Cluster Grenade item (Traitor)", 100, ConVarFlags.FCVAR_NONE,
|
||||
new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<int> CV_GRENADE_COUNT = new(
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace TTT.CS2.Configs.ShopItems;
|
||||
public class CS2OneShotDeagleConfig : IStorage<OneShotDeagleConfig>,
|
||||
IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_onedeagle_price", "Price of the One-Shot Deagle item", 125,
|
||||
"css_ttt_shop_onedeagle_price", "Price of the One-Shot Deagle item", 130,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public static readonly FakeConVar<bool> CV_FRIENDLY_FIRE = new(
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace TTT.CS2.Configs.ShopItems;
|
||||
|
||||
public class CS2StickersConfig : IStorage<StickersConfig>, IPluginModule {
|
||||
public static readonly FakeConVar<int> CV_PRICE = new(
|
||||
"css_ttt_shop_stickers_price", "Price of the Stickers item (Detective)", 25,
|
||||
"css_ttt_shop_stickers_price", "Price of the Stickers item (Detective)", 35,
|
||||
ConVarFlags.FCVAR_NONE, new RangeValidator<int>(0, 10000));
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
24
TTT/CS2/GameHandlers/NameUpdater.cs
Normal file
24
TTT/CS2/GameHandlers/NameUpdater.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TTT.API;
|
||||
using TTT.API.Events;
|
||||
using TTT.API.Player;
|
||||
using TTT.Game.Events.Game;
|
||||
using TTT.Game.Listeners;
|
||||
|
||||
namespace TTT.CS2.GameHandlers;
|
||||
|
||||
public class NameUpdater(IServiceProvider provider) : BaseListener(provider) {
|
||||
private readonly IPlayerConverter<CCSPlayerController> converter =
|
||||
provider.GetRequiredService<IPlayerConverter<CCSPlayerController>>();
|
||||
|
||||
[UsedImplicitly]
|
||||
[EventHandler]
|
||||
public void OnGameInit(GameInitEvent ev) {
|
||||
foreach (var player in Utilities.GetPlayers()) {
|
||||
converter.GetPlayer(player).Name = player.PlayerName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using TTT.API.Player;
|
||||
|
||||
namespace TTT.CS2.Player;
|
||||
@@ -53,7 +54,7 @@ public class CS2Player : IOnlinePlayer, IEquatable<CS2Player> {
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Name { get; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public int Health {
|
||||
get => Player?.Pawn.Value != null ? Player.Pawn.Value.Health : 0;
|
||||
@@ -96,7 +97,11 @@ public class CS2Player : IOnlinePlayer, IEquatable<CS2Player> {
|
||||
}
|
||||
|
||||
public bool IsAlive {
|
||||
get => Player != null && Player.Pawn.Value is { Health: > 0 };
|
||||
get
|
||||
=> Player != null && Player is {
|
||||
Team : CsTeam.CounterTerrorist or CsTeam.Terrorist,
|
||||
Pawn.Value.Health: > 0
|
||||
};
|
||||
|
||||
set
|
||||
=> throw new NotSupportedException(
|
||||
|
||||
@@ -8,28 +8,30 @@ using TTT.Game.Events.Player;
|
||||
namespace TTT.Game.Roles;
|
||||
|
||||
public class RoleAssigner(IServiceProvider provider) : IRoleAssigner {
|
||||
private readonly IDictionary<IPlayer, ICollection<IRole>> assignedRoles =
|
||||
new Dictionary<IPlayer, ICollection<IRole>>();
|
||||
private readonly IDictionary<string, ICollection<IRole>> assignedRoles =
|
||||
new Dictionary<string, ICollection<IRole>>();
|
||||
|
||||
private readonly IEventBus bus = provider.GetRequiredService<IEventBus>();
|
||||
|
||||
private readonly IMessenger? onlineMessenger =
|
||||
provider.GetService<IMessenger>();
|
||||
|
||||
private static readonly Random rng = new();
|
||||
|
||||
public void AssignRoles(ISet<IOnlinePlayer> players, IList<IRole> roles) {
|
||||
assignedRoles.Clear();
|
||||
var shuffled = players.OrderBy(_ => Guid.NewGuid()).ToHashSet();
|
||||
var shuffled = players.OrderBy(_ => rng.NextDouble()).ToHashSet();
|
||||
bool roleAssigned;
|
||||
do { roleAssigned = tryAssignRole(shuffled, roles); } while (roleAssigned);
|
||||
}
|
||||
|
||||
public Task<ICollection<IRole>?> Load(IPlayer key) {
|
||||
assignedRoles.TryGetValue(key, out var roles);
|
||||
assignedRoles.TryGetValue(key.Id, out var roles);
|
||||
return Task.FromResult(roles);
|
||||
}
|
||||
|
||||
public Task Write(IPlayer key, ICollection<IRole> newData) {
|
||||
assignedRoles[key] = newData;
|
||||
assignedRoles[key.Id] = newData;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -44,9 +46,9 @@ public class RoleAssigner(IServiceProvider provider) : IRoleAssigner {
|
||||
|
||||
if (ev.IsCanceled) continue;
|
||||
|
||||
if (!assignedRoles.ContainsKey(player))
|
||||
assignedRoles[player] = new List<IRole>();
|
||||
assignedRoles[player].Add(ev.Role);
|
||||
if (!assignedRoles.ContainsKey(player.Id))
|
||||
assignedRoles[player.Id] = new List<IRole>();
|
||||
assignedRoles[player.Id].Add(ev.Role);
|
||||
ev.Role.OnAssign(player);
|
||||
|
||||
onlineMessenger?.Debug(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace ShopAPI.Configs.Traitor;
|
||||
|
||||
public record OneHitKnifeConfig : ShopItemConfig {
|
||||
public override int Price { get; init; } = 70;
|
||||
public override int Price { get; init; } = 80;
|
||||
public bool FriendlyFire { get; init; } = true;
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public class TestPlayer(string id, string name) : IOnlinePlayer {
|
||||
// public ICollection<IRole> Roles { get; } = [];
|
||||
|
||||
public string Id { get; } = id;
|
||||
public string Name { get; } = name;
|
||||
public string Name { get; set; } = name;
|
||||
|
||||
public int Health { get; set; } = 100;
|
||||
public int MaxHealth { get; set; } = 100;
|
||||
|
||||
Reference in New Issue
Block a user