Beispiel #1
0
 public HitInfo(BaseController controller, IHitboxComponent hitbox, Vector3 hitPoint, int hitLocation, int hitMaterial)
 {
     Controller  = controller;
     Hitbox      = hitbox;
     HitPoint    = hitPoint;
     HitLocation = hitLocation;
     HitMaterial = hitMaterial;
 }
Beispiel #2
0
        void IDamageOnHit.HandleCollision(BaseController otherController, IHitboxComponent hitbox, int hitLocation, int hitmaterial, Vector3?positionOverride, float damageMultiplier, bool allDamageIsPierce)
        {
            //Debug.Log($"{name} hit {otherController?.name}");

            if (!EnableCollision || DeferredHitBegan)
            {
                return;
            }

            HandleHit(otherController, hitbox, hitLocation, hitmaterial, positionOverride, damageMultiplier, allDamageIsPierce);
        }
Beispiel #3
0
        private void HandleInteraction()
        {
            //get thing, probe and display tooltip, check use

            bool haveTarget = false;

            int layerMask = LayerMask.GetMask("Default", "ActorHitbox", "Actor");

            Debug.DrawRay(CameraRoot.position, CameraRoot.transform.forward * MaxProbeDist);

            //raycast all, go through the hits ignoring hits to self
            RaycastHit[] hits = Physics.RaycastAll(CameraRoot.transform.position, CameraRoot.transform.forward, MaxProbeDist * 2, layerMask, QueryTriggerInteraction.Collide);
            if (hits != null && hits.Length > 0)
            {
                //GameObject nearestObject = null;
                InteractableComponent nearestInteractable = null;
                float nearestDist = float.MaxValue;
                foreach (RaycastHit hit in hits)
                {
                    //skip if it's further than nearestDist (occluded) or flatdist is further than MaxProbeDist (too far away)
                    if (hit.distance > nearestDist)
                    {
                        continue;
                    }

                    float fDist = VectorUtils.GetFlatVectorToTarget(transform.position, hit.point).magnitude;
                    if (fDist > MaxProbeDist)
                    {
                        continue;
                    }

                    //nearestObject = hit.collider.gameObject;

                    //if there's a PlayerController attached, we've hit ourselves
                    if (hit.collider.GetComponent <PlayerController>() != null)
                    {
                        continue;
                    }

                    //TODO pull a similar trick to see if we're pointing at an Actor?

                    //get the interactable component and hitbox component; if it doesn't have either then it's an obstacle
                    InteractableComponent ic  = hit.collider.GetComponent <InteractableComponent>();
                    IHitboxComponent      ahc = hit.collider.GetComponent <IHitboxComponent>();
                    if (ic == null && ahc == null)
                    {
                        //we null out our hit first since it's occluded by this one
                        nearestInteractable = null;
                        nearestDist         = hit.distance;
                        continue;
                    }

                    //it's just us lol
                    if (ahc != null && ahc.ParentController is PlayerController)
                    {
                        continue;
                    }

                    //we have an interactablecomponent and we're not occluded
                    if (ic != null)
                    {
                        nearestInteractable = ic;
                        nearestDist         = hit.distance;
                        continue;
                    }

                    //if it doesn't meet any of those criteria then it's an occluder
                    nearestInteractable = null;
                    nearestDist         = hit.distance;
                }

                //if(nearestObject != null)
                //    Debug.Log("Nearest: " + nearestObject.name);

                if (nearestInteractable != null && nearestInteractable.enabled)
                {
                    //Debug.Log("Detected: " + nearestInteractable.Tooltip);

                    //HUDScript.SetTargetMessage(nearestInteractable.Tooltip);
                    nearestInteractable.OnLook(this.gameObject);
                    if (!string.IsNullOrEmpty(nearestInteractable.Tooltip))
                    {
                        MessageInterface.PushToBus(new QdmsKeyValueMessage("PlayerHasTarget", "Target", nearestInteractable.Tooltip));
                        HadTargetLastFrame = true;
                        haveTarget         = true;
                    }

                    //actual use
                    if (MappedInput.GetButtonDown(DefaultControls.Use) && !GameState.Instance.PlayerFlags.Contains(PlayerFlags.NoInteract))
                    {
                        nearestInteractable.OnActivate(this.gameObject);
                    }
                }
            }

            if (!haveTarget && HadTargetLastFrame)
            {
                MessageInterface.PushToBus(new QdmsFlagMessage("PlayerClearTarget")); //should probably not do this constantly
            }

            HadTargetLastFrame = haveTarget;
        }
Beispiel #4
0
        private void HandleHit(BaseController otherController, IHitboxComponent hitbox, int hitLocation, int hitmaterial, Vector3?positionOverride, float damageMultiplier, bool allDamageIsPierce)
        {
            //Debug.Log($"HandleHit called ({otherController})");

            if (gameObject == null)
            {
                return; //don't double it up
            }
            if (HitInfo.HitFlags.HasFlag(BuiltinHitFlags.IgnoreHitLocation))
            {
                if (!(hitbox != null && hitbox.AlwaysApplyMultiplier))
                {
                    damageMultiplier = 1;
                }
            }

            if (otherController != null)
            {
                if (otherController == HitInfo.Originator) //no friendly fire for now
                {
                    return;
                }

                if (positionOverride == null)
                {
                    HitInfo.HitCoords = transform.position;
                }
                else
                {
                    HitInfo.HitCoords = positionOverride;
                }

                HitInfo.Damage       *= damageMultiplier;
                HitInfo.DamagePierce *= damageMultiplier;

                if (allDamageIsPierce)
                {
                    HitInfo.DamagePierce += HitInfo.Damage;
                    HitInfo.Damage        = 0;
                }

                if (hitLocation > 0)
                {
                    HitInfo.HitLocation = hitLocation;
                }

                if (otherController is ITakeDamage itd)
                {
                    itd.TakeDamage(HitInfo);

                    if (FiredByPlayer)
                    {
                        QdmsMessageBus.Instance.PushBroadcast(new QdmsFlagMessage("PlayerHitTarget"));
                    }
                }
            }

            if (HitInfo.HitCoords == null)
            {
                if (positionOverride == null)
                {
                    HitInfo.HitCoords = transform.position;
                }
                else
                {
                    HitInfo.HitCoords = positionOverride;
                }
                //Debug.Log($"HitCoords set to {HitInfo.HitCoords}");
            }

            if (hitmaterial > 0)
            {
                HitInfo.HitMaterial = hitmaterial;
            }

            if (!string.IsNullOrEmpty(HitPuffOverride))
            {
                HitPuffScript.SpawnHitPuff(HitPuffOverride, HitInfo.HitCoords.Value, HitInfo.HitMaterial);
            }
            else
            {
                HitPuffScript.SpawnHitPuff(HitInfo);
            }

            if (HitSpecial != null)
            {
                HitSpecial.Invoke(new ActionInvokerData()
                {
                    Activator = HitInfo.Originator
                });
            }

            Destroy(this.gameObject);
        }