using System; using Oddworm.Framework; using RebootKit.Engine.Foundation; using RebootKit.Engine.Main; using RebootKit.Engine.Simulation; using Unity.Mathematics; using UnityEngine; using Logger = RebootKit.Engine.Foundation.Logger; namespace RebootReality.jelycho { public class HitboxManagerActor : Actor { static readonly Logger s_Logger = new Logger(nameof(HitboxManagerActor)); static readonly Collider[] s_CollidersBuffer = new Collider[512]; [ConfigVar("debug.hitbox", 0, "Shows hitboxes")] static ConfigVar s_ShowHitboxesDebug; static bool ShouldShowHitboxes() { return s_ShowHitboxesDebug.IndexValue > 0; } [SerializeField] Color m_HitboxDebugColor = Color.red; [SerializeField] float m_HitboxDebugDuration = 3.0f; [SerializeField] LayerMask m_HurtboxesLayerMask; // // @MARK: HitboxManager // public void HitSphere(float3 origin, float radius, Actor attacker, ulong damage) { if (RR.IsServer()) { HitSphereLocal(origin, radius, attacker, damage); } else { throw new NotImplementedException("Hitting on client not implemented yet!"); } } void HitSphereLocal(float3 origin, float radius, Actor attacker, ulong damage) { if (ShouldShowHitboxes()) { DbgDraw.Sphere(origin, Quaternion.identity, Vector3.one * radius, m_HitboxDebugColor, m_HitboxDebugDuration); } int count = Physics.OverlapSphereNonAlloc(origin, radius, s_CollidersBuffer, m_HurtboxesLayerMask); for (int i = 0; i < count; ++i) { if (s_CollidersBuffer[i].TryGetComponent(out IHurtbox hurtbox)) { float3 p = s_CollidersBuffer[i].ClosestPoint(origin); if (ShouldShowHitboxes()) { DbgDraw.Sphere(p, Quaternion.identity, Vector3.one * 0.1f, Color.magenta, m_HitboxDebugDuration); } hurtbox.ReceiveDamage(attacker, damage, p); } // if (s_CollidersBuffer[i].TryGetComponent(out IKillable killable)) { // Actor killableActor = killable as Actor; // if (killableActor == attacker) { // continue; // } // // if (killable is IHasHitFeedback hitFeedback) { // float3 p = s_CollidersBuffer[i].ClosestPoint(origin); // if (ShouldShowHitboxes()) { // DbgDraw.Sphere(p, Quaternion.identity, Vector3.one * 0.1f, Color.magenta, m_HitboxDebugDuration); // } // // hitFeedback.HitFeedback(p); // } // // // @TODO: send command to server to hit an killable // killable.OnHit(attacker, damage); // } } } // // @MARK: Actor // protected override IActorData CreateActorData() { return new NoActorData(); } } }