refactor: power-up effects applied centrally in GameBootstrap

This commit is contained in:
2026-05-14 01:21:22 +02:00
parent 8edb5cfbb5
commit 1b8c7f730d
2 changed files with 17 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections;
using Core.Domain;
using Core.Domain.Status.Effects;
using Core.Ports;
using TMPro;
using UnityEngine;
@@ -370,14 +371,22 @@ namespace Infrastructure.Unity
instance.Configure(type);
instance.OnCollected += (t) =>
instance.OnCollected += (t, dur) =>
{
cameraController?.Shake(0.2f, 0.15f);
rumbleManager?.PulseMedium();
if (t == PowerUpType.TimeSlow)
switch (t)
{
_gameSession.ActivateTimeSlow(10f);
case PowerUpType.TimeSlow:
_gameSession.ActivateTimeSlow(dur);
break;
case PowerUpType.LightFooted:
_playerInstance?.Status.AddEffect(new LightFootedEffect(dur));
break;
case PowerUpType.SpeedBoost:
_playerInstance?.Status.AddEffect(new SpeedBoostEffect(dur));
break;
}
};
}

View File

@@ -1,6 +1,5 @@
using System;
using Core.Domain;
using Core.Domain.Status.Effects;
using KBCore.Refs;
using UnityEngine;
@@ -17,7 +16,7 @@ namespace Infrastructure.Unity
private MaterialPropertyBlock _propBlock;
private static readonly int ColorProperty = Shader.PropertyToID("_BaseColor");
public event Action<PowerUpType> OnCollected;
public event Action<PowerUpType, float> OnCollected;
private void Awake()
{
@@ -45,20 +44,16 @@ namespace Infrastructure.Unity
private void OnTriggerEnter(Collider other)
{
if (other.TryGetComponent<PlayerController>(out var player))
if (other.TryGetComponent<PlayerController>(out _))
{
ApplyEffect(player);
OnCollected?.Invoke(type);
OnCollected?.Invoke(type, duration);
if (pickupVfx)
{
var vfx = Instantiate(pickupVfx, transform.position, Quaternion.identity);
var main = vfx.main;
meshRenderer.GetPropertyBlock(_propBlock);
var currentColor = _propBlock.GetColor(ColorProperty);
main.startColor = currentColor;
main.startColor = _propBlock.GetColor(ColorProperty);
Destroy(vfx.gameObject, 2f);
}
@@ -66,24 +61,6 @@ namespace Infrastructure.Unity
}
}
private void ApplyEffect(PlayerController player)
{
switch (type)
{
case PowerUpType.LightFooted:
player.Status.AddEffect(new LightFootedEffect(duration));
break;
case PowerUpType.SpeedBoost:
player.Status.AddEffect(new SpeedBoostEffect(duration, 1.5f));
break;
case PowerUpType.TimeSlow:
// Handled globally
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public void Configure(PowerUpType newType)
{
type = newType;