示例#1
0
    // OnTriggerEnter is called when the GameObject collides with another GameObject
    private void OnTriggerEnter(Collider other)
    {
        // If already touched this collider, return
        if (TouchedObjects.Contains(other))
        {
            return;
        }

        // If the collider object should be hit, hit it
        // Check if object has tags
        if ((Owner && (other.gameObject == Owner.gameObject)) || !other.gameObject.HasTag(HittableTags.ObjectTags))
        {
            return;
        }

        TDS_Damageable _target = other.GetComponent <TDS_Damageable>();

        if (!_target)
        {
            return;
        }

        // Deal damages and apply effect
        TouchedObjects.Add(other);
        InflictDamages(_target);
    }
示例#2
0
    /// <summary>
    /// Attacks the target, by inflicting damages and applying effects.
    /// </summary>
    /// <param name="_attacker">The HitBox attacking the target.</param>
    /// <param name="_target">Target to attack.</param>
    /// <returns>Returns -2 if target didn't take any damages, -1 if the target is dead, 0 if no effect could be applied, and 1 if everything went good.</returns>
    public virtual int Attack(TDS_HitBox _attacker, TDS_Damageable _target)
    {
        // Roll the dice to know if the attack effect should be applied
        int  _percent  = Random.Range(1, 100);
        bool _noEffect = (_percent > Effect.PercentageLowest) && ((_percent > Effect.PercentageHighest) || (_percent > Random.Range(Effect.PercentageLowest, Effect.PercentageHighest + 1)));

        // Get attack damages
        int _damages = GetDamages + _attacker.BonusDamages;

        if (!_noEffect)
        {
            _damages += Random.Range(Effect.DamagesMin, Effect.DamagesMax + 1);
        }

        // Inflict damages, and return if target don't get hurt, if no effect or if target is dead
        if ((_damages < 1) || !_target.TakeDamage(_damages, _attacker.Collider.bounds.center))
        {
            return(-2);
        }

        // Increase score
        if ((_attacker.Owner is TDS_Player _player) && (_target is TDS_Enemy _enemyTarget))
        {
            TDS_GameManager.PlayersInfo.First(p => p.PlayerType == _player.PlayerType).PlayerScore.IncreaseInflictedScore(_enemyTarget, _damages);
        }
示例#3
0
 /// <summary>
 /// Attacks the target, by inflicting damages and applying effects.
 /// </summary>
 /// <param name="_attacker">The HitBox attacking the target.</param>
 /// <param name="_target">Target to attack.</param>
 /// <returns>Returns -2 if target didn't take any damages, -1 if the target is dead, 0 if no effect could be applied, and 1 if everything went good.</returns>
 public override int Attack(TDS_HitBox _attacker, TDS_Damageable _target)
 {
     if (canBreakGuard && (_target is TDS_Player _player))
     {
         _player.StopParry();
     }
     return(base.Attack(_attacker, _target));
 }
示例#4
0
    // OnTriggerEnter is called when the GameObject collides with another GameObject
    private void OnTriggerEnter(Collider other)
    {
        // If detected object doesn't have detecting tags, just ignore it
        if (!isActivated || !other.gameObject.HasTag(detectedTags.ObjectTags))
        {
            return;
        }

        TDS_Damageable _damageable = other.GetComponent <TDS_Damageable>();

        if (_damageable)
        {
            _damageable.TakeDamage(Random.Range(damagesMin, damagesMax + 1));
        }

        // Expulse collider
        Vector3 _nearestPoint        = collider.bounds.ClosestPoint(other.bounds.center);
        Vector3 _direction           = _nearestPoint - collider.bounds.center;
        Vector3 _otherColliderCenter = other.bounds.center - other.transform.position;

        other.transform.position = new Vector3(_nearestPoint.x + (other.bounds.extents.x * Mathf.Sign(_direction.x)) + _otherColliderCenter.x, other.transform.position.y, _nearestPoint.z + (other.bounds.extents.z * Mathf.Sign(_direction.z)) + _otherColliderCenter.z);
    }
    /// <summary>
    /// Attacks the target, by inflicting damages and applying effects.
    /// </summary>
    /// <param name="_attacker">The HitBox attacking the target.</param>
    /// <param name="_target">Target to attack.</param>
    /// <returns>Returns -1 if target didn't take any damages, 0 if no effect could be applied, and 1 if everything went good.</returns>
    public override int Attack(TDS_HitBox _attacker, TDS_Damageable _target)
    {
        // If should not apply burn effect, return
        int _result = base.Attack(_attacker, _target);

        if (_result < 0)
        {
            return(_result);
        }

        // Roll the dices to get if burn effect should be applied
        int _percent = Random.Range(1, 101);

        if ((_percent > burnPercentageLowest) && ((_percent > burnPercentageHighest) || (_percent > Random.Range(burnPercentageLowest, burnPercentageHighest + 1))))
        {
            return(0);
        }

        // Burn it
        _target.Burn(burnDamagesMin, burnDamagesMax, burnDuration);
        return(1);
    }
示例#6
0
    /// <summary>
    /// Inflict damages to a specified target.
    /// </summary>
    /// <param name="_target">Target to hit.</param>
    private void InflictDamages(TDS_Damageable _target)
    {
        // Attack the target
        if (CurrentAttack.Attack(this, _target) < -1)
        {
            return;
        }

        // Call local method on the character who hit
        if (Owner)
        {
            if (PhotonNetwork.offlineMode && (Owner is TDS_Player _player))
            {
                _player.HitCallback(_target.Collider.bounds.center.x, _target.Collider.bounds.max.y, _target.transform.position.z);
            }
            else
            {
                TDS_RPCManager.Instance?.RPCPhotonView.RPC("CallMethodOnline", Owner.photonView.owner, TDS_RPCManager.GetInfo(Owner.photonView, Owner.GetType(), "HitCallback"), new object[] { _target.Collider.bounds.center.x, _target.Collider.bounds.max.y, _target.transform.position.z });
            }
        }

        // Triggers event
        OnTouch?.Invoke();
    }