Esempio n. 1
0
        //public void Punch(bool isLeftHand)
        public void Punch(int _left)
        {
            Transform hand = _left == 1 ? leftHand : rightHand;

            //Transform hand = isLeftHand == true ? leftHand : rightHand;

            DebugExtension.DebugWireSphere(hand.position, punchRadius, punchRadius);

            RaycastHit[] hits = Physics.SphereCastAll(hand.position, punchRadius, hand.forward, 0f);
            //Collider[] hitColliders = Physics.OverlapSphere(hand.position, punchRadius);

            List <PlayerController> playersHit = new List <PlayerController>();

            foreach (var hit in hits)
            {
                RootFix playerRoot = hit.transform.GetComponent <RootFix>();
                if (playerRoot != null)
                {
                    PlayerController    player     = playerRoot.playerRoot.GetComponentInChildren <PlayerController>();
                    DamageableBehaviour damageable = playerRoot.playerRoot.GetComponent <DamageableBehaviour>();

                    var myAlignment = myDamageableBehaviour.configuration.AlignmentProvider;

                    if (damageable != null && myAlignment != null)
                    {
                        float knockback = 1f + (damageable.configuration.CurrentDamage / 100f); //EDIT

                        var hitInfo = new HitInfo
                        {
                            damageChangeInfo = new DamageChangeInfo(),
                            damagePoint      = hit.point
                        };

                        bool canKnockBack = (myAlignment != damageable.configuration.AlignmentProvider);

                        if (!playersHit.Contains(player))
                        {
                            if (canKnockBack)
                            {
                                damageable.configuration.AddDamage(damagePerHit, hitInfo);
                                playersHit.Add(player);
                            }
                        }

                        MuscleCollisionBroadcaster broadcaster = hit.transform.GetComponent <MuscleCollisionBroadcaster>();

                        if (broadcaster != null && canKnockBack)
                        {
                            Vector3 heading = hit.point - hand.position;

                            Vector3 direction = hand.transform.forward;

                            broadcaster.Hit(5, direction * (baseKnockback * (knockback * (damageable.configuration.CurrentDamage / 100f))), hit.point);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void SwingHit()
        {
            DebugExtension.DebugWireSphere(swingLocation.position, swingRadius, 0.25f); //Delete this

            RaycastHit[] _hits = Physics.SphereCastAll(swingLocation.position, swingRadius, transform.forward, 0f);

            PickUp weapon = _item.GetComponent <PickUp>();

            List <PlayerController> playersHit = new List <PlayerController>();

            foreach (RaycastHit hit in _hits)
            {
                RootFix playerRoot = hit.transform.GetComponent <RootFix>();
                if (playerRoot != null)
                {
                    PlayerController    player     = playerRoot.playerRoot.GetComponentInChildren <PlayerController>();
                    DamageableBehaviour damageable = playerRoot.playerRoot.GetComponent <DamageableBehaviour>();

                    var myAlignment = myDamageableBehaviour.configuration.AlignmentProvider;

                    if (damageable != null && myAlignment != null)
                    {
                        float knockback = 1f + (damageable.configuration.CurrentDamage / 100f); //EDIT

                        var hitInfo = new HitInfo
                        {
                            damageChangeInfo = new DamageChangeInfo(),
                            damagePoint      = hit.point
                        };

                        bool canKnockBack = (myAlignment != damageable.configuration.AlignmentProvider);

                        //print("Obj: " + player.name + ", Count: " + playersHit.Count + ", Contains: " + playersHit.Contains(player));
                        if (!playersHit.Contains(player))
                        {
                            if (canKnockBack)
                            {
                                damageable.configuration.AddDamage((weapon != null ? weapon.damage : damagePerHit), hitInfo);
                                playersHit.Add(player);
                            }
                        }
                        MuscleCollisionBroadcaster broadcaster = hit.transform.GetComponent <MuscleCollisionBroadcaster>();

                        if (broadcaster != null && canKnockBack)
                        {
                            broadcaster.Hit(5, rightHand.transform.forward * (baseKnockback * (knockback * (damageable.configuration.CurrentDamage / 100f))), hit.point);
                        }
                    }
                }

                /*
                 * if (_hit.transform.root != transform.root)
                 * {
                 *  Debug.Log("RUGHAARINMIJNRIETJE TWEE");
                 *
                 *  //PlayerController _player = null;
                 *  DamageableBehaviour _damageable = null;
                 *  IAlignmentProvider myAlignment = null;
                 *
                 *  if (_hit.transform.root.tag == "Player")
                 *  {
                 *      //_player = _hit.transform.root.GetComponentInChildren<PlayerController>();
                 *      _damageable = _hit.transform.root.GetComponentInChildren<DamageableBehaviour>();
                 *  }
                 *
                 *  float knockback = 1f;
                 *  if (_damageable != null)
                 *  {
                 *      myAlignment = myDamageableBehaviour.configuration.AlignmentProvider;
                 *
                 *      int weaponDamagePerHit = ((_item != null) ? _item.GetComponent<PickUp>().damage : damagePerHit);
                 *
                 *      _damageable.configuration.CheckDamage(weaponDamagePerHit, myAlignment, swingLocation.position);
                 *  }
                 *
                 *  MuscleCollisionBroadcaster broadcaster = _hit.transform.GetComponent<MuscleCollisionBroadcaster>();
                 *
                 *  if (broadcaster != null && _damageable.CanKnockback(myAlignment))
                 *  {
                 *      Vector3 _heading = _hit.point - swingLocation.position;
                 *      float _distance = _heading.magnitude;
                 *      Vector3 _direction = _heading / _distance;
                 *
                 *      broadcaster.Hit(5, _direction * (baseKnockback * knockback), _hit.point); //Edit this
                 *  }
                 * }
                 */
            }
        }