Skip to content

Commit

Permalink
refactor: return PlayerControllerB instead of Result
Browse files Browse the repository at this point in the history
  • Loading branch information
winstxnhdw committed Feb 15, 2024
1 parent 017f7d7 commit baabcef
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions lc-hax/Scripts/Commands/HealCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

[Command("heal")]
internal class HealCommand : IStun, ICommand {
void StunAtPlayerPosition(PlayerControllerB player) => this.Stun(player.transform.position, 5.0f, 1.0f);

void RespawnLocalPlayer(PlayerControllerB localPlayer, StartOfRound startOfRound, HUDManager hudManager) {
if (Helper.SoundManager is not SoundManager soundManager) return;

Expand Down Expand Up @@ -85,7 +83,7 @@ void RespawnLocalPlayer(PlayerControllerB localPlayer, StartOfRound startOfRound
occludeAudio.overridingLowPass = false;
}

Result HealLocalPlayer(HUDManager hudManager) {
PlayerControllerB HealLocalPlayer(HUDManager hudManager) {
if (hudManager.localPlayer.health <= 0) {
this.RespawnLocalPlayer(hudManager.localPlayer, hudManager.localPlayer.playersManager, hudManager);

Expand All @@ -103,31 +101,28 @@ Result HealLocalPlayer(HUDManager hudManager) {
hudManager.HUDAnimator.SetTrigger("HealFromCritical");
hudManager.UpdateHealthUI(hudManager.localPlayer.health, false);

this.StunAtPlayerPosition(hudManager.localPlayer);
return new Result(true);
return hudManager.localPlayer;
}

Result HealPlayer(StringArray args) {
if (Helper.GetActivePlayer(args[0]) is not PlayerControllerB targetPlayer) {
return new Result(message: "Target player is not alive or found!");
}

targetPlayer.HealPlayer();
this.StunAtPlayerPosition(targetPlayer);
PlayerControllerB? HealPlayer(string? playerNameOrId) {
PlayerControllerB? targetPlayer = Helper.GetActivePlayer(playerNameOrId);
targetPlayer?.HealPlayer();

return new Result(true);
return targetPlayer;
}

public void Execute(StringArray args) {
if (Helper.HUDManager is not HUDManager hudManager) return;

Result result = args.Length switch {
PlayerControllerB? healedPlayer = args.Length switch {
0 => this.HealLocalPlayer(hudManager),
_ => this.HealPlayer(args)
_ => this.HealPlayer(args[0])
};

if (!result.Success) {
Chat.Print(result.Message);
if (healedPlayer is null) {
Chat.Print("Target player is not alive or found!");
}

this.Stun(healedPlayer.transform.position, 5.0f, 1.0f);

Check warning on line 126 in lc-hax/Scripts/Commands/HealCommand.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.

Check warning on line 126 in lc-hax/Scripts/Commands/HealCommand.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.

Check warning on line 126 in lc-hax/Scripts/Commands/HealCommand.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 126 in lc-hax/Scripts/Commands/HealCommand.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
}
}

0 comments on commit baabcef

Please sign in to comment.