Skip to content
Draft
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
14 changes: 13 additions & 1 deletion Assets/PinAnimator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CollectionExtensions;
using System;
using UnityEngine;

public class PinAnimator : AugmentAnimator
Expand Down Expand Up @@ -31,6 +31,18 @@ public override void OnReload(GunStats stats) { }

public override void OnFire(GunStats stats)
{
#region Fix for specific bug after weaponswitching
try
{
var test = transform.localPosition;
}
catch (NullReferenceException)
{
Debug.LogWarning($"Ignoring nullref in {nameof(PinAnimator)}:OnFire");
return;
}
#endregion

if (playAudio)
PlayCockingSound();
transform.localPosition = Vector3.zero;
Expand Down
6 changes: 3 additions & 3 deletions Assets/RicochetModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

public class RicochetModifier : MonoBehaviour, ProjectileModifier
{
public void ricochetProjectile(RaycastHit other, ref ProjectileState state)
public void RicochetProjectile(RaycastHit other, ref ProjectileState state)
{
state.direction = Vector3.Reflect(state.direction, other.normal);
}

public void Attach(ProjectileController projectile)
{
projectile.OnColliderHit += ricochetProjectile;
projectile.OnColliderHit += RicochetProjectile;
}
public void Detach(ProjectileController projectile)
{
projectile.OnColliderHit -= ricochetProjectile;
projectile.OnColliderHit -= RicochetProjectile;
}
}
4 changes: 4 additions & 0 deletions Assets/Scripts/Augment/Augment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public abstract class Augment : NetworkBehaviour
// For displaying items with correct alignment
public Transform midpoint;

public abstract void Attach(GunController gunController);

public abstract void Detach(GunController gunController);

public virtual void BuildStats(GunStats gunStats)
{
foreach (var modifier in statModifiers)
Expand Down
18 changes: 9 additions & 9 deletions Assets/Scripts/Augment/AugmentImplementations/AmmoBoxBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ public class AmmoBoxBody : GunBody
[SerializeField]
private PlayerHand playerHandRight;

public override void Start()
public override void Attach(GunController gunController)
{
gunController = transform.parent.GetComponent<GunController>();
if (!gunController)
return;
gunController.onFireStart += Reload;
StartCoroutine(SetClosestAmmoBox());
if (!gunController.Player)
return;
playerHandRight.SetPlayer(gunController.Player);
playerHandRight.Subscribe(gunController.Player);
playerHandRight.gameObject.SetActive(true);
playerHandLeft.SetPlayer(gunController.Player);
playerHandLeft.Subscribe(gunController.Player);
playerHandLeft.gameObject.SetActive(true);
}

private void OnDestroy()
public override void Detach(GunController gunController)
{
if (gunController)
gunController.onFireStart -= Reload;
gunController.onFireStart -= Reload;
if (!gunController.Player)
return;
playerHandRight.Unsubscribe(gunController.Player);
playerHandLeft.Unsubscribe(gunController.Player);
}

private IEnumerator SetClosestAmmoBox()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BoomBardierAnimator : AugmentAnimator
Expand All @@ -25,16 +23,26 @@ public override void OnReload(GunStats stats)

public override void OnFire(GunStats stats)
{
animator.SetTrigger("Fire");
ammo = stats.Ammo;
OnShotFiredAnimation?.Invoke();
OnAnimationEnd?.Invoke();
try
{
animator.SetTrigger("Fire");
ammo = stats.Ammo;
OnShotFiredAnimation?.Invoke();
OnAnimationEnd?.Invoke();
}
catch (System.NullReferenceException)
{
// Avoids specific issue that only appears in build.
Debug.LogWarning($"Ignoring nullref in {nameof(BoomBardierAnimator)}:OnFire");
return;
}
}

// Also called by animator
public void VisualizeAmmoCount()
{
for (int i = 0; i < dynamites.Length; i++)
// TODO nullref here
dynamites[i].enabled = ammo - 1 > i;
}
}
75 changes: 39 additions & 36 deletions Assets/Scripts/Augment/AugmentImplementations/DDRBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,53 +71,65 @@ public class DDRBody : GunBody
private AudioSource audioSource;
private InputManager inputManager;

public override void Start()
private void Start()
{
meshRenderer.materials[screenMaterialIndex] = Instantiate(meshRenderer.materials[screenMaterialIndex]);
ddrMaterial = meshRenderer.materials[screenMaterialIndex];
precisionText.enabled = false;
}

public override void Attach(GunController gunController)
{
musicPace = 60f / MusicTrackManager.Singleton.BeatsPerMinute;
var secondsPerArrow = MusicTrackManager.Singleton.BeatsPerBar * musicPace;
secondsPerUnitHeight = secondsPerArrow / (targetHeight - startHeight);

gunController = transform.parent.GetComponent<GunController>();
if (!gunController)
if (!(gunController.Player && gunController.Player.inputManager))
return;
inputManager = gunController.Player.inputManager;
inputManager.onFirePerformed += Fire;
inputManager.onMovePerformed += ArrowSelect;

if (gunController.Player && gunController.Player.inputManager)
{
inputManager = gunController.Player.inputManager;
inputManager.onFirePerformed += Fire;
inputManager.onMovePerformed += ArrowSelect;
var delay = (float)(MusicTrackManager.Singleton.IsfadingOutPreviousTrack
? MusicTrackManager.Singleton.TrackOffset
: secondsPerArrow - (MusicTrackManager.Singleton.TimeSinceTrackStart % secondsPerArrow));

var delay = (float)(MusicTrackManager.Singleton.IsfadingOutPreviousTrack
? MusicTrackManager.Singleton.TrackOffset
: secondsPerArrow - (MusicTrackManager.Singleton.TimeSinceTrackStart % secondsPerArrow));
PickNewTargetDirection();

arrowMoverTween = LeanTween.value(gameObject, SetArrowHeigth, startHeight, screenHeight, secondsPerUnitHeight * (screenHeight - startHeight))
.setDelay(delay)
.setRepeat(-1).id;

PickNewTargetDirection();
screenPulseAnimatorTween = LeanTween.value(gameObject, SetBackgroundZoom, 0.5f, 1.5f, musicPace)
.setDelay(delay)
.setLoopPingPong()
.setOnComplete(
() => animator.OnFire(gunController.stats)).id;

arrowMoverTween = LeanTween.value(gameObject, SetArrowHeigth, startHeight, screenHeight, secondsPerUnitHeight * (screenHeight - startHeight))
.setDelay(delay)
.setRepeat(-1).id;
animator.OnInitialize(gunController.stats);

screenPulseAnimatorTween = LeanTween.value(gameObject, SetBackgroundZoom, 0.5f, 1.5f, musicPace)
.setDelay(delay)
.setLoopPingPong()
.setOnComplete(
() => animator.OnFire(gunController.stats)).id;
playerHandLeft.Subscribe(gunController.Player);
playerHandLeft.gameObject.SetActive(true);
playerHandRight.Subscribe(gunController.Player);
playerHandRight.gameObject.SetActive(true);

animator.OnInitialize(gunController.stats);
audioSource = GetComponent<AudioSource>();
}

playerHandLeft.SetPlayer(gunController.Player);
playerHandLeft.gameObject.SetActive(true);
playerHandRight.SetPlayer(gunController.Player);
playerHandRight.gameObject.SetActive(true);
public override void Detach(GunController gunController)
{
if (!gunController.Player)
return;
playerHandRight.Unsubscribe(gunController.Player);
playerHandLeft.Unsubscribe(gunController.Player);

audioSource = GetComponent<AudioSource>();
}
if (!inputManager)
return;
inputManager.onFirePerformed -= Fire;
inputManager.onMovePerformed -= ArrowSelect;
}


private void Update()
{
if (!inputManager)
Expand Down Expand Up @@ -326,13 +338,4 @@ private void PickNewTargetDirection()
arrowDirection = (ArrowDirection)Random.Range(0, 4);
AnimateTargetArrowRotation(oldDirection, arrowDirection);
}

private void OnDestroy()
{
if (!inputManager)
return;

inputManager.onFirePerformed -= Fire;
inputManager.onMovePerformed -= ArrowSelect;
}
}
20 changes: 3 additions & 17 deletions Assets/Scripts/Augment/AugmentImplementations/DynamiteBarrel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;

Expand All @@ -22,9 +21,8 @@ public class DynamiteBarrel : GunBarrel
// TODO: allow for even more by instantiating particles with a positionbuffer instead
private const int maxDetonatableInTotal = 10;

void Start()
public override void Attach(GunController gunController)
{
gunController = transform.parent.GetComponent<GunController>();
if (!gunController || !gunController.Player)
return;

Expand Down Expand Up @@ -123,22 +121,10 @@ private void RpcDetonate()

private void OnDeath(PlayerManager killer, PlayerManager victim, DamageInfo info)
{
StopAllCoroutines();
if (!gunController || !gunController.Player)
return;

activeDynamites.ForEach(dynamite => dynamite.gameObject.SetActive(false));

stickyModifer.OnStuckToTarget -= AddDynamite;

if (gunController.Player is not AIManager && gunController.Player.inputManager)
{
gunController.Player.inputManager.onZoomPerformed -= OnZoom;
gunController.Player.GetComponent<PlayerMovement>().ReEnableZoom();
}
Detach(gunController);
}

private void OnDestroy()
public override void Detach(GunController gunController)
{
StopAllCoroutines();
if (!gunController || !gunController.Player || !gunController.Player.IsAlive)
Expand Down
35 changes: 22 additions & 13 deletions Assets/Scripts/Augment/AugmentImplementations/Fire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class Fire : GunExtension
private StuckObject stuckFirePrefab;
[SerializeField]
private LayerMask trailLayers;
private GunController gunController;
private AudioSource audioSource;
[SerializeField]
private AudioGroup lighterSound;
Expand All @@ -39,14 +38,13 @@ public class Fire : GunExtension
[SerializeField]
private StickyProjectileModifier stickyModifier;

private HashSet<ProjectileState> trackedProjectiles = new HashSet<ProjectileState>();
private HashSet<ProjectileState> trackedProjectiles = new();
// Used to keep track of the healthControllers currently burning
public HashSet<HealthController> hitHealthControllers = new HashSet<HealthController>();
public HashSet<HealthController> hitHealthControllers = new();

void Awake()
public override void Attach(GunController gunController)
{
audioSource = GetComponent<AudioSource>();
gunController = transform.parent.GetComponent<GunController>();
if (!gunController)
return;

Expand All @@ -64,18 +62,35 @@ void Awake()
stickyModifier.OnStuckToTarget += InitializeFlame;
projectileType = ProjectileType.Mesh;
}
else if (gunController.projectile is BulletController)
else if (gunController.projectile is BulletController controller)
{
((BulletController)gunController.projectile).SetTrail(fireTrail);
controller.SetTrail(fireTrail);
projectileType = ProjectileType.Hitscan;
}
else if (gunController.projectile is LazurController)
{
projectileType = ProjectileType.Laser;
}
}

public override void Detach(GunController gunController)
{
stuckFirePool?.Flush();
positionActiveBuffer?.Dispose();

if (!gunController)
return;

gunController.onInitializeGun -= AddFireToProjectile;
gunController.onFireEnd -= PlayShotAudio;
gunController.projectile.OnProjectileInit -= TrackProjectile;
gunController.projectile.UpdateProjectileMovement -= ApplyTrails;

if (gunController.projectile is MeshProjectileController)
stickyModifier.OnStuckToTarget -= InitializeFlame;
}


private void TrackProjectile(ref ProjectileState state, GunStats stats)
{
trackedProjectiles.Add(state);
Expand Down Expand Up @@ -206,12 +221,6 @@ private void PlayShotAudio(GunStats stats)
lighterSound.Play(audioSource);
}

private void OnDestroy()
{
stuckFirePool?.Flush();
positionActiveBuffer?.Dispose();
}

#if UNITY_EDITOR
private void OnDrawGizmos()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ public class HackingExtension : GunExtension
private float scrollAmount = 0.10f;
private const int hackingScreenMaterialIndex = 1;

private GunController gunController;

private void Start()
{
meshRenderer.materials[hackingScreenMaterialIndex] = Instantiate(meshRenderer.materials[hackingScreenMaterialIndex]);
hackingScreen = meshRenderer.materials[hackingScreenMaterialIndex];
gunController = transform.parent.GetComponent<GunController>();
if (!gunController)
return;
}

public override void Attach(GunController gunController)
{
gunController.onFireStart += Fire;
}

public override void Detach(GunController gunController)
{
gunController.onFireStart -= Fire;
}

private void Fire(GunStats stats)
{
hackingScreen.SetFloat("_ScrollAmount", hackingScreen.GetFloat("_ScrollAmount") + scrollAmount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ protected override void OnDestroy()
base.OnDestroy();
positionActiveBuffer?.Dispose();
rotationBuffer?.Dispose();
UpdateProjectileMovement -= ProjectileMotions.MoveWithGravity;
if (animator)
animator.OnShotFiredAnimation -= FireProjectile;
}

protected override void OnInitialize(GunStats gunstats)
Expand Down
Loading