diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2023-07-30 19:50:07 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2023-07-30 19:50:07 +0100 |
| commit | fcca74deba166218deaf1e906acc0c206d96d27e (patch) | |
| tree | ba3980ae24949e007c271c5a4ffa023b2da24ceb /code/pawn/component/camera/SpectatorCameraComponent.cs | |
| parent | 4ae38adb208c435ff6a021cdd0517768c5314fe6 (diff) | |
Add spectator target switching
Diffstat (limited to 'code/pawn/component/camera/SpectatorCameraComponent.cs')
| -rw-r--r-- | code/pawn/component/camera/SpectatorCameraComponent.cs | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/code/pawn/component/camera/SpectatorCameraComponent.cs b/code/pawn/component/camera/SpectatorCameraComponent.cs index bba92f6..fba33a5 100644 --- a/code/pawn/component/camera/SpectatorCameraComponent.cs +++ b/code/pawn/component/camera/SpectatorCameraComponent.cs @@ -4,25 +4,36 @@ using System.Linq; namespace MurderGame;
-public class SpectatorCameraComponent : BaseCameraComponent
+public partial class SpectatorCameraComponent : BaseCameraComponent
{
- public Player Target { get; set; }
+ [Net] public Player Target { get; set; }
+ [Net] public int TargetIndex { get; set; }
public override void Simulate( IClient cl )
{
+ var targets = GetTargets();
+ if ( targets.Count == 0 )
+ {
+ Target = null;
+ return;
+ }
if (Target == null || !Target.IsValid() || Target.LifeState == LifeState.Dead)
{
- var targets = GetTargets();
- if ( targets.Count == 0 )
- {
- Target = null;
- return;
- }
- var nextTarget = targets.First();
- Target = (Player)nextTarget.Pawn;
+ FindNextTarget( targets, false );
+ return;
+ }
+
+ if ( Input.Released( "attack1" ) )
+ {
+ FindNextTarget( targets, false );
+ }
+ else if ( Input.Released( "attack2" ) )
+ {
+ FindNextTarget( targets, true );
}
}
+
public override void FrameSimulate( IClient cl )
{
if ( Target == null || !Target.IsValid() || Target.LifeState == LifeState.Dead ) return;
@@ -38,7 +49,20 @@ public class SpectatorCameraComponent : BaseCameraComponent {
return Game.Clients.Where(c => c.Pawn is Player player && player.CurrentTeam != Team.Spectator && player.LifeState == LifeState.Alive).ToList();
}
-
+
+ private void FindNextTarget(List<IClient> targets, bool backwards)
+ {
+ if ( !backwards )
+ {
+ if ( ++TargetIndex >= targets.Count ) TargetIndex = 0;
+ }
+ else {
+ if ( --TargetIndex < 0 ) TargetIndex = targets.Count - 1;
+ }
+ var nextTarget = targets[TargetIndex];
+ Target = (Player)nextTarget.Pawn;
+ }
+
public override InventoryComponent GetObservedInventory()
{
return Target?.Inventory;
|
