Ejemplo n.º 1
0
    private void OnTriggerEnter(Collider other)
    {
        // EARLY OUT! //
        // If the trigger isn't on an impact layer, ignore it.
        if (_isCollided || !CombatUtils.IsProjectileCollider(other.gameObject.layer))
        {
            return;
        }

        // EARLY OUT! //
        // If the collider is a friendly entity, early out.
        if (CombatUtils.IsEntity(other.gameObject.layer) && !CombatUtils.IsEnemy(_creator.Owner, other))
        {
            return;
        }

        _isCollided = true;

        var card = SL.Get <Config>().GetCardByName(_entityToSpawn);

        if (card != null)
        {
            card.SpawnChargeSeconds = 0;
            var unit = Entity.SpawnFromDefinition(_creator.Owner, card, transform.position.ZeroY(), isFromPlayersHand: false);
            _creator.Owner.RotateForPlayer(unit.gameObject);
        }
        else
        {
            Debug.LogWarning("Can't find card: " + card.Name);
        }

        // Destroy the shell.
        Destroy(gameObject);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Should this unit be affected by this spell?
 /// </summary>
 private bool isAffectedEntity(PlayerModel friendly, Entity target)
 {
     if (_isAffectingFriendlies)
     {
         return(!CombatUtils.IsEnemy(friendly, target));
     }
     else
     {
         return(CombatUtils.IsEnemy(friendly, target));
     }
 }
Ejemplo n.º 3
0
    private void OnTriggerEnter(Collider other)
    {
        // EARLY OUT! //
        // If the trigger isn't on an impact layer, ignore it.
        if (!CombatUtils.IsProjectileCollider(other.gameObject.layer))
        {
            return;
        }

        // EARLY OUT! //
        // If the collider is a friendly entity, early out.
        if (CombatUtils.IsEntity(other.gameObject.layer) && !CombatUtils.IsEnemy(_owner, other))
        {
            return;
        }

        // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
        Collider[] colliders = Physics.OverlapSphere(transform.position, _explosionRadius, CombatUtils.EntityMask);

        for (int i = 0; i < colliders.Length; i++)
        {
            Entity targetEntity = colliders[i].GetComponent <Entity> ();

            // If it's an enemy unit, do damage to it.
            if (CombatUtils.IsEnemy(_owner, targetEntity))
            {
                targetEntity.TakeDamage(_areaDamage);
            }
        }

        if (_explosionParticlePrefab != null)
        {
            var explosion = Utils.Instantiate(_explosionParticlePrefab, transform.position, transform.rotation);

            // Play the particle system.
            explosion.Play();

            // Once the particles have finished, destroy the gameobject they are on.
            Destroy(explosion.gameObject, explosion.main.duration);
        }

        if (_explosionAudio != null)
        {
            // Play the explosion sound effect.
            _explosionAudio.Play();
        }


        // Destroy the shell.
        Destroy(gameObject);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Attempt attacks when we detect a rigidbody collision.
    /// </summary>
    private void OnTriggerStay(Collider other)
    {
        // EARLY OUT! //
        // If on cooldown don't attack.
        if (!this.enabled || _cooldownSeconds > 0f)
        {
            return;
        }

        // EARLY OUT! //
        // If the trigger isn't an entity, ignore it.
        if (!CombatUtils.IsEntity(other.gameObject.layer))
        {
            return;
        }

        // EARLY OUT! //
        // If the collider isn't an enemy, ignore it.
        var target = other.GetComponent <Entity>();

        if (!CombatUtils.IsEnemy(_entity.Owner, target))
        {
            return;
        }

        bool didAttack = false;

        // Only attack if the entity is a type that this unit attacks.
        if (_entity.AttacksGroundUnits || target.IsBuilding)
        {
            didAttack  = attemptDirectAttack(target);
            didAttack |= attemptAreaAttack(target);
        }

        if (didAttack)
        {
            // Reset cooldown.
            _cooldownSeconds = _entity.AttackSpeed;

            // Play attack audio if we have any.
            if (_animator != null)
            {
                _animator.Attack();
            }
        }
    }
Ejemplo n.º 5
0
    private bool attemptAreaAttack(Entity target)
    {
        bool didAttack = true;

        // Trigger enter only applies to area attacks.
        if (target != null && _entity.AreaAttackDamage > 0)
        {
            Collider[] colliders = Physics.OverlapSphere(transform.position, _attackRadius, CombatUtils.EntityMask);

            for (int i = 0; i < colliders.Length; i++)
            {
                var areaTarget = colliders[i].GetComponent <Entity>();
                if (CombatUtils.IsEnemy(_entity.Owner, areaTarget))
                {
                    attack(areaTarget, _entity.AreaAttackDamage);
                    didAttack = true;
                }
            }
        }
        return(didAttack);
    }
Ejemplo n.º 6
0
    private void triggerBomb()
    {
        // Collect all the colliders in a sphere from the shell's current position to a radius of the explosion radius.
        Collider[] colliders = Physics.OverlapSphere(transform.position, _explosionRadius, CombatUtils.EntityMask);

        for (int i = 0; i < colliders.Length; i++)
        {
            Entity targetEntity = colliders[i].GetComponent <Entity> ();

            // If it's an enemy unit, do damage to it.
            if (CombatUtils.IsEnemy(_owner, targetEntity))
            {
                targetEntity.TakeDamage(_areaDamage);
            }
        }

        if (_explosionParticles != null)
        {
            // Unparent the particles from the shell.
            _explosionParticles.transform.parent = null;

            // Play the particle system.
            _explosionParticles.Play();

            // Once the particles have finished, destroy the gameobject they are on.
            Destroy(_explosionParticles.gameObject, _explosionParticles.main.duration);
        }

        if (_explosionAudio != null)
        {
            // Play the explosion sound effect.
            _explosionAudio.Play();
        }

        // Destroy the shell.
        Destroy(gameObject);
    }