bool IsInLethalRange(AttackCondition info)
        {
            for (int i = 0; i < control.RAGDOLL_DATA.ArrBodyParts.Length; i++)
            {
                float dist = Vector3.SqrMagnitude(
                    control.RAGDOLL_DATA.ArrBodyParts[i].transform.position - info.Attacker.transform.position);

                if (dist <= info.LethalRange)
                {
                    int             index           = Random.Range(0, control.RAGDOLL_DATA.ArrBodyParts.Length);
                    TriggerDetector triggerDetector = control.RAGDOLL_DATA.ArrBodyParts[index].GetComponent <TriggerDetector>();

                    damageData.damageTaken = new DamageTaken(
                        info.Attacker,
                        info.AttackAbility,
                        triggerDetector,
                        null,
                        Vector3.zero);

                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        public void RemoveWeaponFromDictionary(CharacterControl c)
        {
            foreach (Collider col in c.RagdollParts)
            {
                TriggerDetector t = col.GetComponent <TriggerDetector>();

                if (t != null)
                {
                    ProcRemove(c.animationProgress.CollidingWeapons, t);
                    ProcRemove(c.animationProgress.CollidingBodyParts, t);
                }

                //if (t != null)
                //{
                //    if (c.animationProgress.CollidingWeapons.ContainsKey(t))
                //    {
                //        if (c.animationProgress.CollidingWeapons[t].Contains(PickUpCollider))
                //        {
                //            c.animationProgress.CollidingWeapons[t].Remove(PickUpCollider);
                //        }
                //
                //        if (c.animationProgress.CollidingWeapons[t].Contains(AttackCollider))
                //        {
                //            c.animationProgress.CollidingWeapons[t].Remove(AttackCollider);
                //        }
                //
                //        if (c.animationProgress.CollidingWeapons[t].Count == 0)
                //        {
                //            c.animationProgress.CollidingWeapons.Remove(t);
                //        }
                //    }
                //}
            }
        }
Beispiel #3
0
 public DamageTaken(CharacterControl attacker,
                    Attack attack,
                    TriggerDetector damagee,
                    GameObject damager,
                    Vector3 incomingVelocity)
 {
     mAttacker         = attacker;
     mAttack           = attack;
     mDamagee          = damagee;
     mDamager          = damager;
     mIncomingVelocity = incomingVelocity;
 }
        public void TurnOnRagdoll()
        {
            //change layers
            Transform[] arr = GetComponentsInChildren <Transform>();
            foreach (Transform t in arr)
            {
                t.gameObject.layer = LayerMask.NameToLayer(RB_Layers.DEADBODY.ToString());
            }

            //save bodypart positions
            foreach (Collider c in RagdollParts)
            {
                TriggerDetector det = c.GetComponent <TriggerDetector>();
                det.LastPosition = c.gameObject.transform.localPosition;
                det.LastRotation = c.gameObject.transform.localRotation;
            }

            //turn off animator/avatar/etc
            RIGID_BODY.useGravity = false;
            RIGID_BODY.velocity   = Vector3.zero;
            this.gameObject.GetComponent <BoxCollider>().enabled = false;
            SkinnedMeshAnimator.enabled = false;
            SkinnedMeshAnimator.avatar  = null;

            //turn on ragdoll
            foreach (Collider c in RagdollParts)
            {
                c.isTrigger = false;

                TriggerDetector det = c.GetComponent <TriggerDetector>();
                c.transform.localPosition = det.LastPosition;
                c.transform.localRotation = det.LastRotation;

                c.attachedRigidbody.velocity = Vector3.zero;
            }

            //add force
            if (animationProgress.DamagedTrigger != null)
            {
                animationProgress.DamagedTrigger.GetComponent <Rigidbody>().
                AddForce(animationProgress.Attacker.transform.forward * animationProgress.Attack.ForwardForce +
                         animationProgress.Attacker.transform.right * animationProgress.Attack.RightForce +
                         animationProgress.Attacker.transform.up * animationProgress.Attack.UpForce);
            }
        }
        void ProcRemove(Dictionary <TriggerDetector, List <Collider> > d, TriggerDetector t)
        {
            if (d.ContainsKey(t))
            {
                if (d[t].Contains(PickUpCollider))
                {
                    d[t].Remove(PickUpCollider);
                }

                if (d[t].Contains(AttackCollider))
                {
                    d[t].Remove(AttackCollider);
                }

                if (d[t].Count == 0)
                {
                    d.Remove(t);
                }
            }
        }
        bool IsInLethalRange(AttackInfo info)
        {
            foreach (Collider c in control.RAGDOLL_DATA.BodyParts)
            {
                float dist = Vector3.SqrMagnitude(c.transform.position - info.Attacker.transform.position);

                if (dist <= info.LethalRange)
                {
                    int             index           = Random.Range(0, control.RAGDOLL_DATA.BodyParts.Count);
                    TriggerDetector triggerDetector = control.RAGDOLL_DATA.BodyParts[index].GetComponent <TriggerDetector>();

                    damageData.SetData(
                        info.Attacker,
                        info.AttackAbility,
                        triggerDetector,
                        null);

                    return(true);
                }
            }

            return(false);
        }
        public void RemoveWeaponFromDictionary(CharacterControl c)
        {
            for (int i = 0; i < c.RAGDOLL_DATA.ArrBodyParts.Length; i++)
            {
                TriggerDetector t = c.RAGDOLL_DATA.ArrBodyParts[i].GetComponent <TriggerDetector>();

                if (t != null)
                {
                    ProcRemove(c.animationProgress.CollidingWeapons, t);
                    ProcRemove(c.animationProgress.CollidingBodyParts, t);
                }
            }

            //foreach(Collider col in c.RAGDOLL_DATA.BodyParts)
            //{
            //    TriggerDetector t = col.GetComponent<TriggerDetector>();
            //
            //    if (t != null)
            //    {
            //        ProcRemove(c.animationProgress.CollidingWeapons, t);
            //        ProcRemove(c.animationProgress.CollidingBodyParts, t);
            //    }
            //}
        }
Beispiel #8
0
        void ProcRagdoll()
        {
            ragdollData.RagdollTriggered = false;

            if (control.SkinnedMeshAnimator.avatar == null)
            {
                return;
            }

            //change layers
            Transform[] arr = control.gameObject.GetComponentsInChildren <Transform>();
            foreach (Transform t in arr)
            {
                t.gameObject.layer = LayerMask.NameToLayer(RB_Layers.DEADBODY.ToString());
            }

            //save bodypart positions
            for (int i = 0; i < ragdollData.ArrBodyParts.Length; i++)
            {
                TriggerDetector det = ragdollData.ArrBodyParts[i].GetComponent <TriggerDetector>();
                det.LastPosition = ragdollData.ArrBodyParts[i].gameObject.transform.position;
                det.LastRotation = ragdollData.ArrBodyParts[i].gameObject.transform.rotation;
            }

            //turn off animator/avatar
            control.RIGID_BODY.useGravity = false;
            control.RIGID_BODY.velocity   = Vector3.zero;
            control.gameObject.GetComponent <BoxCollider>().enabled = false;
            control.SkinnedMeshAnimator.enabled = false;
            control.SkinnedMeshAnimator.avatar  = null;

            //turn off ledge colliders
            control.LEDGE_GRAB_DATA.LedgeCollidersOff();

            //turn off ai
            if (control.aiController != null)
            {
                control.aiController.gameObject.SetActive(false);
                control.navMeshObstacle.enabled = false;
            }

            //turn on ragdoll
            for (int i = 0; i < ragdollData.ArrBodyParts.Length; i++)
            {
                ragdollData.ArrBodyParts[i].isTrigger = false;
                ragdollData.ArrBodyParts[i].attachedRigidbody.isKinematic = true;
            }

            for (int i = 0; i < ragdollData.ArrBodyParts.Length; i++)
            {
                TriggerDetector det = ragdollData.ArrBodyParts[i].GetComponent <TriggerDetector>();
                ragdollData.ArrBodyParts[i].attachedRigidbody.MovePosition(det.LastPosition);
                ragdollData.ArrBodyParts[i].attachedRigidbody.MoveRotation(det.LastRotation);
                ragdollData.ArrBodyParts[i].attachedRigidbody.velocity = Vector3.zero;
            }

            for (int i = 0; i < ragdollData.ArrBodyParts.Length; i++)
            {
                ragdollData.ArrBodyParts[i].attachedRigidbody.isKinematic = false;
            }

            ragdollData.ClearExistingVelocity();

            if (control.DAMAGE_DATA.damageTaken != null)
            {
                //take damage from ragdoll
                Vector3         incomingVelocity = control.DAMAGE_DATA.damageTaken.INCOMING_VELOCITY;
                TriggerDetector damagedPart      = control.DAMAGE_DATA.damageTaken.DAMAGEE;

                if (Vector3.SqrMagnitude(incomingVelocity) > 0.0001f)
                {
                    Debug.Log(control.gameObject.name + ": taking damage from ragdoll");
                    damagedPart.body.AddForce(incomingVelocity * 0.7f);
                }

                //take damage from attack
                else
                {
                    ragdollData.AddForceToDamagedPart(RagdollPushType.NORMAL);
                }
            }
        }
        void CheckMarioStomp()
        {
            if (control.RIGID_BODY.velocity.y >= 0f)
            {
                MarioStompTargets.Clear();
                DownBlockingObjs.Clear();
                return;
            }

            if (MarioStompTargets.Count > 0)
            {
                control.RIGID_BODY.velocity = Vector3.zero;
                control.RIGID_BODY.AddForce(Vector3.up * 250f);

                foreach (CharacterControl c in MarioStompTargets)
                {
                    AttackCondition info = new AttackCondition();
                    info.CopyInfo(c.DAMAGE_DATA.MarioStompAttack, control);

                    int             index      = Random.Range(0, c.RAGDOLL_DATA.ArrBodyParts.Length);
                    TriggerDetector randomPart = c.RAGDOLL_DATA.ArrBodyParts[index].GetComponent <TriggerDetector>();

                    c.DAMAGE_DATA.damageTaken = new DamageTaken(
                        control,
                        c.DAMAGE_DATA.MarioStompAttack,
                        randomPart,
                        control.RightFoot_Attack,
                        Vector3.zero);

                    c.DAMAGE_DATA.TakeDamage(info);
                }

                MarioStompTargets.Clear();
                return;
            }

            CheckDownBlocking();

            if (DownBlockingObjs.Count > 0)
            {
                foreach (KeyValuePair <GameObject, GameObject> data in DownBlockingObjs)
                {
                    CharacterControl c = CharacterManager.Instance.
                                         GetCharacter(data.Value.transform.root.gameObject);

                    if (c != null)
                    {
                        if (c.boxCollider.center.y + c.transform.position.y < control.transform.position.y)
                        {
                            if (c != control)
                            {
                                if (!MarioStompTargets.Contains(c))
                                {
                                    MarioStompTargets.Add(c);
                                }
                            }
                        }
                    }
                }
            }
        }