Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix gungame not teleporting #273

Merged
merged 2 commits into from
Aug 7, 2024
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
11 changes: 6 additions & 5 deletions lang/Jailbreak.English/SpecialDay/GunDayLocale.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Objects;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Views.SpecialDay;

namespace Jailbreak.English.SpecialDay;

Expand All @@ -21,27 +21,28 @@ public IView PromotedTo(string weapon, int weaponsLeft) {
if (weaponsLeft == 1)
return new SimpleView {
PREFIX,
$"You were promoted to",
"You were promoted to",
weapon + ".",
ChatColors.Green + "LAST WEAPON!"
};

return new SimpleView {
PREFIX,
$"You were promoted to",
"You were promoted to",
weapon + ".",
weaponsLeft,
"weapons left."
};
}

public IView PlayerOnLastPromotion(CCSPlayerController player)
=> new SimpleView {
public IView PlayerOnLastPromotion(CCSPlayerController player) {
return new SimpleView {
PREFIX,
player,
"is on their last weapon!",
ChatColors.LightRed + "Watch out!"
};
}

public IView PlayerWon(CCSPlayerController player) {
var view = new SimpleView { PREFIX, player, "won the game!" };
Expand Down
1 change: 1 addition & 0 deletions lang/Jailbreak.English/SpecialDay/SDLocale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Jailbreak.Formatting.Logistics;
using Jailbreak.Formatting.Objects;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Views.SpecialDay;

namespace Jailbreak.English.SpecialDay;

Expand Down
1 change: 1 addition & 0 deletions lang/Jailbreak.English/SpecialDay/SoloDayLocale.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Views.SpecialDay;
using Jailbreak.Public.Utils;

namespace Jailbreak.English.SpecialDay;
Expand Down
1 change: 1 addition & 0 deletions lang/Jailbreak.English/SpecialDay/SpeedrunDayLocale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Views.SpecialDay;

namespace Jailbreak.English.SpecialDay;

Expand Down
1 change: 1 addition & 0 deletions lang/Jailbreak.English/SpecialDay/TeamDayLocale.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Views.SpecialDay;
using Jailbreak.Public.Utils;

namespace Jailbreak.English.SpecialDay;
Expand Down
12 changes: 8 additions & 4 deletions mod/Jailbreak.Debug/Subcommands/DebugCenterHud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ public class DebugCenterHud(IServiceProvider services)
: AbstractCommand(services) {
public override void OnCommand(CCSPlayerController? executor,
WrappedInfo info) {
ServerExtensions.GetGameRules().GameRestart =
!ServerExtensions.GetGameRules().GameRestart;
var rules = ServerExtensions.GetGameRules();
if (rules == null) {
info.ReplyToCommand("Failed to get GameRules.");
return;
}

rules.GameRestart = !rules.GameRestart;

if (info.ArgCount == 1)
info.ReplyToCommand(
$"Set Center HUD to {ServerExtensions.GetGameRules().GameRestart}");
info.ReplyToCommand($"Set Center HUD to {rules.GameRestart}");

executor?.PrintToCenterHtml("This is a test message", 100);
}
Expand Down
6 changes: 2 additions & 4 deletions mod/Jailbreak.Debug/Subcommands/DebugZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,10 @@ await zoneManager.PushZoneWithID(innerZone, innerPair.Value.Item2,
.GetResult();

var toRemove = new List<IZone>();
foreach (var spawn in spawns) {
foreach (var spawn in spawns)
if (doNotTeleport.Any(d
=> d.IsInsideZone(spawn.CalculateCenterPoint()))) {
=> d.IsInsideZone(spawn.CalculateCenterPoint())))
toRemove.Add(spawn);
}
}

info.ReplyToCommand("Removing " + toRemove.Count
+ " auto-generated zones");
Expand Down
24 changes: 12 additions & 12 deletions mod/Jailbreak.LastGuard/LastGuard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,6 @@ public class LastGuard(ILGLocale notifications, ILastRequestManager lrManager)
private bool isLastGuard;
private List<CCSPlayerController> lastGuardPrisoners = [];

public int CalculateHealth() {
var aliveTerrorists = Utilities.GetPlayers()
.Where(plr => plr is { PawnIsAlive: true, Team: CsTeam.Terrorist })
.ToList();

return (int)Math.Floor(aliveTerrorists
.Select(player => player.PlayerPawn.Value?.Health ?? 0)
.Select(playerHealth
=> Math.Min(playerHealth, CvMaxTHealthContribution.Value))
.Sum() * CvGuardHealthRatio.Value);
}

public void StartLastGuard(CCSPlayerController lastGuard) {
var guardPlayerPawn = lastGuard.PlayerPawn.Value;

Expand Down Expand Up @@ -121,6 +109,18 @@ public void StartLastGuard(CCSPlayerController lastGuard) {

public void DisableLastGuardForRound() { canStart = false; }

public int CalculateHealth() {
var aliveTerrorists = Utilities.GetPlayers()
.Where(plr => plr is { PawnIsAlive: true, Team: CsTeam.Terrorist })
.ToList();

return (int)Math.Floor(aliveTerrorists
.Select(player => player.PlayerPawn.Value?.Health ?? 0)
.Select(playerHealth
=> Math.Min(playerHealth, CvMaxTHealthContribution.Value))
.Sum() * CvGuardHealthRatio.Value);
}

[GameEventHandler]
public HookResult OnPlayerDeathEvent(EventPlayerDeath @event,
GameEventInfo info) {
Expand Down
6 changes: 3 additions & 3 deletions mod/Jailbreak.LastRequest/LastRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) {

if (!IsLREnabledForRound) return HookResult.Continue;

if (player.GetTeam() != CsTeam.Terrorist) return HookResult.Continue;
if (player.Team != CsTeam.Terrorist) return HookResult.Continue;

if (countAlivePrisoners() - 1 > CvPrisonerToLR.Value)
return HookResult.Continue;
Expand Down Expand Up @@ -221,7 +221,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event,

if (!IsLREnabledForRound) return HookResult.Continue;

if (player.GetTeam() != CsTeam.Terrorist) return HookResult.Continue;
if (player.Team != CsTeam.Terrorist) return HookResult.Continue;
if (countAlivePrisoners() > CvPrisonerToLR.Value)
return HookResult.Continue;

Expand All @@ -236,6 +236,6 @@ private int countAlivePrisoners() {
private bool prisonerCountsToLR(CCSPlayerController player) {
if (!player.IsReal()) return false;
if (!player.PawnIsAlive) return false;
return player.GetTeam() == CsTeam.Terrorist;
return player.Team == CsTeam.Terrorist;
}
}
6 changes: 1 addition & 5 deletions mod/Jailbreak.LastRequest/LastRequests/BulletForBullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public class BulletForBullet : TeleportingRequest {
"weapon_nova"
];

private static readonly string[] GUN_NAMES = [
"Desert Eagle", "USPS", "Tec9", "Scout", "Nova"
];

private readonly ChatMenu chatMenu;
private readonly bool magForMag;
private readonly ILRB4BLocale msg;
Expand All @@ -43,7 +39,7 @@ public BulletForBullet(BasePlugin plugin, IServiceProvider provider,
public override LRType Type
=> magForMag ? LRType.MAG_FOR_MAG : LRType.SHOT_FOR_SHOT;

private void OnSelect(CCSPlayerController player, ChatMenuOption option,
private void OnSelect(CCSPlayerController player, ChatMenuOption _,
string designer) {
if (player.Slot != Prisoner.Slot) return;
designerName = designer;
Expand Down
3 changes: 1 addition & 2 deletions mod/Jailbreak.Logs/Tags/PlayerTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Objects;
using Jailbreak.Formatting.Views.Logging;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.Rebel;
using Jailbreak.Public.Mod.Warden;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -25,7 +24,7 @@ public class PlayerTagHelper(IServiceProvider provider) : IRichPlayerTag {
public FormatObject Rich(CCSPlayerController player) {
if (wardenService.Value != null && wardenService.Value.IsWarden(player))
return new StringFormatObject("(WARDEN)", ChatColors.DarkBlue);
if (player.GetTeam() == CsTeam.CounterTerrorist)
if (player.Team == CsTeam.CounterTerrorist)
return new StringFormatObject("(CT)", ChatColors.BlueGrey);
if (rebelService.Value != null && rebelService.Value.IsRebel(player))
return new StringFormatObject("(REBEL)", ChatColors.DarkRed);
Expand Down
4 changes: 2 additions & 2 deletions mod/Jailbreak.Rebel/RebelListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public class RebelListener(IRebelService rebelService,
public HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) {
var player = @event.Userid;
if (player == null || !player.IsReal()) return HookResult.Continue;
if (player.GetTeam() != CsTeam.CounterTerrorist) return HookResult.Continue;
if (player.Team != CsTeam.CounterTerrorist) return HookResult.Continue;

var attacker = @event.Attacker;
if (attacker == null || !attacker.IsReal()) return HookResult.Continue;

if (attacker.GetTeam() != CsTeam.Terrorist) return HookResult.Continue;
if (attacker.Team != CsTeam.Terrorist) return HookResult.Continue;

if (lastRequestManager.IsInLR(attacker)) return HookResult.Continue;

Expand Down
1 change: 1 addition & 0 deletions mod/Jailbreak.SpecialDay/SpecialDayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using CounterStrikeSharp.API.Modules.Menu;
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Views.SpecialDay;
using Jailbreak.Formatting.Views.Warden;
using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Mod.SpecialDay;
Expand Down
1 change: 1 addition & 0 deletions mod/Jailbreak.SpecialDay/SpecialDays/CustomDay.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CounterStrikeSharp.API.Core;
using Jailbreak.English.SpecialDay;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Views.SpecialDay;
using Jailbreak.Public.Mod.SpecialDay;
using Jailbreak.Public.Mod.SpecialDay.Enums;

Expand Down
1 change: 1 addition & 0 deletions mod/Jailbreak.SpecialDay/SpecialDays/FFADay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Jailbreak.English.SpecialDay;
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Views.SpecialDay;
using Jailbreak.Public.Mod.SpecialDay;
using Jailbreak.Public.Mod.SpecialDay.Enums;

Expand Down
63 changes: 32 additions & 31 deletions mod/Jailbreak.SpecialDay/SpecialDays/GunGameDay.cs
Original file line number Diff line number Diff line change
@@ -1,59 +1,58 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.English.SpecialDay;
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views;
using Jailbreak.Formatting.Views.SpecialDay;
using Jailbreak.Public.Extensions;
using Jailbreak.Public.Mod.SpecialDay;
using Jailbreak.Public.Mod.SpecialDay.Enums;
using Jailbreak.Public.Utils;
using Microsoft.VisualBasic.CompilerServices;

namespace Jailbreak.SpecialDay.SpecialDays;

public class GunGameDay(BasePlugin plugin, IServiceProvider provider)
: AbstractSpecialDay(plugin, provider), ISpecialDayMessageProvider {
private readonly IList<string> weaponProgression = [];
private readonly IList<string> BAD = [
"weapon_deagle", "weapon_elite", "weapon_fiveseven", "weapon_glock",
"weapon_hkp2000", "weapon_p250", "weapon_usp_silencer", "weapon_tec9",
"weapon_cz75a", "weapon_revolver"
];

private readonly IList<string> BEST = [
"weapon_awp", "weapon_scar20", "weapon_g3sg1"
];

private readonly IList<string> GREAT = [
"weapon_ak47", "weapon_m4a1", "weapon_m4a1_silencer",
];

private readonly IList<string> GOOD = [
"weapon_bizon", "weapon_mac10", "weapon_mp5sd", "weapon_mp7", "weapon_mp9",
"weapon_p90", "weapon_ump45", "weapon_negev"
];

private readonly IList<string> GREAT = [
"weapon_ak47", "weapon_m4a1", "weapon_m4a1_silencer"
];

private readonly IList<string> LAST = ["weapon_knife", "weapon_taser"];

private readonly IList<string> OKAY = [
"weapon_mag7", "weapon_nova", "weapon_sawedoff", "weapon_xm1014",
"weapon_ssg08"
];

private readonly IList<string> BAD = [
"weapon_deagle", "weapon_elite", "weapon_fiveseven", "weapon_glock",
"weapon_hkp2000", "weapon_p250", "weapon_usp_silencer", "weapon_tec9",
"weapon_cz75a", "weapon_revolver"
];

private readonly IList<string> LAST = ["weapon_knife", "weapon_taser"];

private readonly IDictionary<int, int> progressions =
new Dictionary<int, int>();

private ShuffleBag<Vector>? spawns;
private readonly IList<string> weaponProgression = [];

public ISDInstanceLocale Locale => new GunDayLocale();
private ShuffleBag<Vector>? spawns;

public override SDType Type => SDType.GUNGAME;
public override SpecialDaySettings Settings => new GunGameSettings();
private IGunDayLocale msg => (IGunDayLocale)Locale;

public ISDInstanceLocale Locale => new GunDayLocale();

public override void Setup() {
Timers[5] += () => Locale.BeginsIn(5).ToAllChat();
Timers[10] += Execute;
Expand Down Expand Up @@ -100,8 +99,10 @@ private HookResult OnRespawn(EventPlayerSpawn @event, GameEventInfo info) {
if (player == null || !player.IsValid) return HookResult.Continue;
if (!progressions.TryGetValue(player.Slot, out var index)) index = 0;
Plugin.AddTimer(0.1f, () => {
if (!player.IsValid || player.Pawn.Value == null || !player.Pawn.IsValid)
return;
player.GiveNamedItem(weaponProgression[index]);
if (spawns != null) player.Teleport(spawns.GetNext());
if (spawns != null) player.Pawn.Value.Teleport(spawns.GetNext());
});
return HookResult.Continue;
}
Expand All @@ -115,11 +116,10 @@ private HookResult OnDeath(EventPlayerDeath @event, GameEventInfo info) {
if (!progressions.TryGetValue(player.Slot, out playerIndex))
playerIndex = 0;
if (attacker == null || !attacker.IsValid) {
if (playerIndex > 0) {
playerIndex--;
msg.DemotedDueToSuicide.ToChat(player);
progressions[player.Slot] = playerIndex;
}
if (playerIndex <= 0) return HookResult.Continue;
playerIndex--;
msg.DemotedDueToSuicide.ToChat(player);
progressions[player.Slot] = playerIndex;

return HookResult.Continue;
}
Expand All @@ -137,6 +137,7 @@ private HookResult OnDeath(EventPlayerDeath @event, GameEventInfo info) {
p.RemoveWeapons();
}

attacker.SetSpeed(2f);
attacker.RemoveWeapons();
attacker.GiveNamedItem("weapon_negev");
attacker.GiveNamedItem("weapon_knife");
Expand All @@ -145,22 +146,22 @@ private HookResult OnDeath(EventPlayerDeath @event, GameEventInfo info) {
Server.ExecuteCommand("mp_respawn_on_death_t 0");
Server.ExecuteCommand("mp_respawn_on_death_ct 0");

RoundUtil.SetTimeRemaining(Math.Min(RoundUtil.GetTimeRemaining(), 30));

Plugin.DeregisterEventHandler<EventPlayerDeath>(OnDeath, HookMode.Pre);
return HookResult.Continue;
}


attackerProgress += 1;
if (@event.Weapon.Contains("knife")) {
progressions[attacker.Slot] = Math.Min(attackerProgress + 2,
weaponProgression.Count - 1);
msg.DemotedDueToSuicide.ToChat(player);
attackerProgress += 1;
msg.DemotedDueToKnife.ToChat(player);
progressions[player.Slot] = Math.Max(playerIndex - 1, 0);
} else {
progressions[attacker.Slot] = Math.Min(attackerProgress + 1,
weaponProgression.Count - 1);
}

attackerProgress = attackerProgress + 1;
attackerProgress = Math.Min(attackerProgress, weaponProgression.Count - 1);

progressions[attacker.Slot] = attackerProgress;

if (attackerProgress == weaponProgression.Count - 1)
msg.PlayerOnLastPromotion(attacker).ToAllChat();
Expand Down
Loading
Loading