Skip to content

Commit

Permalink
Add credit rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
MSWS committed Sep 18, 2024
1 parent e11efa7 commit b546170
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
3 changes: 3 additions & 0 deletions mod/Jailbreak.LastRequest/Jailbreak.LastRequest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
</ItemGroup>

<ItemGroup>
<Reference Include="GangsAPI">
<HintPath>..\..\public\Jailbreak.Public\Mixin\GangsAPI.dll</HintPath>
</Reference>
<Reference Include="MStatsShared">
<HintPath>..\..\public\Jailbreak.Public\Mixin\MStatsShared.dll</HintPath>
</Reference>
Expand Down
49 changes: 38 additions & 11 deletions mod/Jailbreak.LastRequest/LastRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using CounterStrikeSharp.API.Modules.Cvars.Validators;
using CounterStrikeSharp.API.Modules.Menu;
using CounterStrikeSharp.API.Modules.Utils;
using GangsAPI.Data;
using GangsAPI.Services;
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views.LastRequest;
using Jailbreak.Public;
Expand Down Expand Up @@ -105,6 +107,19 @@ public void EnableLR(CCSPlayerController? died = null) {
if (died != null && player.SteamID == died.SteamID) continue;
player.ExecuteClientCommandFromServer("css_lr");
}

if (API.Gangs != null) {
var eco = API.Gangs.Services.GetService<IEcoManager>();
if (eco == null) return;
var survivors = Utilities.GetPlayers()
.Where(p => p is { IsBot: false, PawnIsAlive: true })
.Select(p => new PlayerWrapper(p))
.ToList();
Task.Run(async () => {
foreach (var survivor in survivors)
await eco.Grant(survivor, 100, reason: "LR Reached");
});
}
}

public bool InitiateLastRequest(CCSPlayerController prisoner,
Expand Down Expand Up @@ -137,6 +152,18 @@ public bool EndLastRequest(AbstractLastRequest lr, LRResult result) {
if (result is LRResult.GUARD_WIN or LRResult.PRISONER_WIN) {
RoundUtil.AddTimeRemaining(CV_LR_BONUS_TIME.Value);
messages.LastRequestDecided(lr, result).ToAllChat();

if (API.Gangs != null) {
var eco = API.Gangs.Services.GetService<IEcoManager>();
if (eco == null) return false;
var wrapper =
new PlayerWrapper(result == LRResult.GUARD_WIN ?
lr.Guard :
lr.Prisoner);
Task.Run(async () => {
await eco.Grant(wrapper, 30, reason: "LR Win");
});
}
}

API.Stats?.PushStat(new ServerStat("JB_LASTREQUEST_RESULT",
Expand Down Expand Up @@ -192,14 +219,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) {
if (!IsLREnabledForRound) return HookResult.Continue;

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

if (countAlivePrisoners() - 1 > CV_PRISONER_TO_LR.Value)
return HookResult.Continue;

if (Utilities.GetPlayers().All(p => p.Team != CsTeam.CounterTerrorist))
return HookResult.Continue;

EnableLR(player);
checkLR();
return HookResult.Continue;
}

Expand All @@ -226,13 +246,20 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event,
if (!IsLREnabledForRound) return HookResult.Continue;

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

EnableLR();
checkLR();
return HookResult.Continue;
}

private void checkLR() {
Server.NextFrame(() => {
if (Utilities.GetPlayers().All(p => p.Team != CsTeam.CounterTerrorist))
return;
if (countAlivePrisoners() > CV_PRISONER_TO_LR.Value) return;
EnableLR();
});
}

private int countAlivePrisoners() {
return Utilities.GetPlayers().Count(prisonerCountsToLR);
}
Expand Down
10 changes: 10 additions & 0 deletions mod/Jailbreak.Rebel/C4Bomb/C4Behavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using CounterStrikeSharp.API.Modules.Utils;
using Gangs.BombIconPerk;
using GangsAPI.Data;
using GangsAPI.Services;
using GangsAPI.Services.Gang;
using GangsAPI.Services.Player;
using Jailbreak.Formatting.Extensions;
Expand Down Expand Up @@ -267,6 +268,15 @@ private void detonate(CCSPlayerController player, CC4 bomb) {
}
}

if (API.Gangs != null) {
var eco = API.Gangs.Services.GetService<IEcoManager>();
if (eco != null) {
var wrapper = new PlayerWrapper(player);
Task.Run(async ()
=> await eco.Grant(wrapper, killed * 50, reason: "C4 Kill"));
}
}

API.Stats?.PushStat(new ServerStat("JB_BOMB_EXPLODED", killed.ToString()));

// If they didn't have the C4 make sure to remove it.
Expand Down

0 comments on commit b546170

Please sign in to comment.