Esempio n. 1
0
        private void Attack(GameObject warriorObject)
        {
            var lifeController = warriorObject.GetComponent <LifeController>();
            var warrior        = warriorObject.GetComponent <Warrior>();

            if (!lifeController || !warrior)
            {
                return;
            }
            if (_warrior.Team == warrior.Team)
            {
                return;
            }

            _animator.SetTrigger("Attack");
            lifeController.Attack(.35f);

            if (lifeController.Life <= 0f)
            {
                _lifeController.AddLife(.3f);
                OnKill?.Invoke();
            }

            OnAttack?.Invoke();
        }
Esempio n. 2
0
        private void OnArrowCollision(GameObject obj)
        {
            var lifeController = obj.GetComponent <LifeController>();
            var warrior        = obj.GetComponent <Warrior>();

            if (!lifeController || !warrior || _warrior.Team == warrior.Team)
            {
                _missed++;

                if (_missed > 4)
                {
                    _missed = 0;
                    //OnMissed?.Invoke();
                }

                return;
            }

            lifeController.Attack(.35f);
            if (lifeController.Life <= 0f)
            {
                _lifeController.Attack(-1f);
                OnKill?.Invoke();
            }

            OnAttack?.Invoke();
        }
Esempio n. 3
0
 public void BasicAttackOnPosition(Vector3Int position)
 {
     CanAttack        = false;
     movement.CanMove = false;
     world.UnitManager.GetUnitAt <UnitEntity>(position).Combat.DealDamage(attack, this, true);
     OnAttack?.Invoke();
 }
Esempio n. 4
0
 public void Activate()
 {
     collider.enabled = false;
     waitCountdown    = waitDuration;
     attackCountdown  = attackDuration;
     OnAttack?.Invoke(direction);
 }
Esempio n. 5
0
 /// <summary>
 /// Get if the animal is currently attacking. This called form the animator when an attack animation started
 /// </summary>
 /// <param name="attack"></param>
 public void Attacking(bool attack)
 {
     isAttacking = attack;
     if (attack)
     {
         OnAttack.Invoke();
     }
 }
Esempio n. 6
0
 public void Attack()
 {
     if (OnAttack != null)
     {
         OnAttack.Invoke();
     }
     animator.SetTrigger("attack");
 }
Esempio n. 7
0
 public void CastAbility(Ability ability, Vector3Int target)
 {
     ability.Cast(Unit, target, world);
     UseMana(ability.ManaCost);
     movement.CanMove = false;
     CanAttack        = false;
     OnAttack?.Invoke();
 }
Esempio n. 8
0
 public void Attack()
 {
     if (selected != null)
     {
         selected.Attack(_characterController);
         OnAttack?.Invoke();
     }
 }
Esempio n. 9
0
    ///<summary>
    /// Changing enemyacter state by detecting what kind of layer it touches
    ///</summary>
    protected virtual void ChangeState(EnemyState state)
    {
        if (enemyState == state || IsDead())
        {
            return;
        }

        if (IsAttacking())
        {
            OnAttackEnd.Invoke();
        }

        if (IsPatrolling())
        {
            OnPatrolEnd.Invoke();
        }

        if (IsChasing())
        {
            OnChaseEnd.Invoke();
        }

        if (IsIdling())
        {
            OnIdleEnd.Invoke();
        }
        // set new state
        var prevState = enemyState;

        enemyState = state;

        if (!IsAttacking())
        {
            m_General.canFlip = true;
        }

        if (IsAttacking())
        {
            OnAttack.Invoke();
        }

        if (IsPatrolling())
        {
            OnPatrol.Invoke();
        }

        if (IsChasing())
        {
            OnChase.Invoke();
        }

        if (IsIdling())
        {
            OnIdle.Invoke();
        }

        OnMotorStateChanged.Invoke(prevState, enemyState);
    }
Esempio n. 10
0
        public bool CallBack(EventType type, object[] args)
        {
            switch (type)
            {
            case EventType.OnAttack:
                if (OnAttack != null)
                {
                    return(OnAttack.Invoke(args));
                }
                else
                {
                    return(false);
                }

            case EventType.OnAttackDefault:
                if (OnAttackDefault != null)
                {
                    return(OnAttackDefault.Invoke(args));
                }
                else
                {
                    return(false);
                }

            case EventType.TryAttack:
                if (TryAttack != null)
                {
                    return(TryAttack.Invoke(args));
                }
                else
                {
                    return(false);
                }

            case EventType.OnActiveCursor:
                if (OnActiveCursor != null)
                {
                    return(OnActiveCursor.Invoke(args));
                }
                else
                {
                    return(false);
                }

            case EventType.OnCrystalize:
                if (OnCrystalize != null)
                {
                    return(OnCrystalize.Invoke(args));
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
Esempio n. 11
0
 /// <summary>
 /// Activate an Attack by his Animation State Name
 /// </summary>
 public virtual void SetAttack(string animation)
 {
     attack1 = true;
     if (!isAttacking)
     {
         Anim.Play(animation);
     }
     OnAttack.Invoke();
 }
Esempio n. 12
0
    private void ProcessAttack()
    {
        if (_timeToNextAttack >= _attackRate && !_isThrowingBack)
        {
            OnAttack?.Invoke();

            _timeToNextAttack = 0;
        }
    }
 protected virtual void TryAttack()
 {
     if (attackTimer <= 0)
     {
         attackTimer = stats.attackSpeed;
         Attack();
         OnAttack?.Invoke();
     }
 }
Esempio n. 14
0
        protected virtual void Attacked(AttackArgs.HitByAttack attackHit, Fighter target, int damage)
        {
            AttackArgs attackArgs = new AttackArgs()
            {
                AttackHit = attackHit, Target = target, Attacker = this, Damage = damage
            };

            OnAttack?.Invoke(this, attackArgs);
            FighterEffectManager.GetDamageFromAttack(attackArgs);
        }
Esempio n. 15
0
    public void Attack(PlayerStat target)
    {
        if (attackCountdown <= 0f)
        {
            attackCountdown = 1f / attackRate;

            target.TakeDamage(myStats.damage.GetValue());
            OnAttack?.Invoke();
        }
    }
Esempio n. 16
0
        private void Attack()
        {
            if (isAnimating)
            {
                return;
            }

            OnAttack?.Invoke();
            isAnimating    = true;
            animationTimer = 0f;
        }
Esempio n. 17
0
        public void Attack(AttackType type)
        {
            ActivateCoolDown(type);
            var hit = _castHandler.Cast();

            if (hit)
            {
                DoAttack(hit.collider, type);
            }

            OnAttack?.Invoke(type);
        }
Esempio n. 18
0
    public void Attack(CharacterStats targetStats)
    {
        if (attackCooldown <= 0)
        {
            enemyStats = targetStats;
            OnAttack?.Invoke();

            attackCooldown = 1 / attackSpeed;
            InCombat       = true;
            lastAttackTime = Time.time;
        }
    }
Esempio n. 19
0
        public IEnumerator AttackCoroutine()
        {
            if (GameManager.Instance.CharacterBases.Count > 0)
            {
                _mrDudesModel.Target = GameManager.Instance.CharacterBases[0].gameObject;
            }

            OnAttack?.Invoke();

            yield return(new WaitForSeconds(2));

            _mrDudesModel.EndState();
        }
Esempio n. 20
0
        protected virtual void Attack(bool triggering = true)
        {
            if (LockedTarget == null)
            {
                return;
            }

            if (triggering)
            {
                OnAttack?.Invoke(LockedTarget);
            }

            InitializeAttack();
        }
    protected override IEnumerator Attack()
    {
        WaitForSeconds Wait = new WaitForSeconds(AttackDelay);

        yield return(Wait);

        while (Damageables.Count > 0)
        {
            for (int i = 0; i < Damageables.Count; i++)
            {
                if (HasLineOfSightTo(Damageables[i].GetTransform()))
                {
                    targetDamageable = Damageables[i];
                    OnAttack?.Invoke(Damageables[i]);
                    Agent.enabled = false;
                    break;
                }
            }

            if (targetDamageable != null)
            {
                PoolableObject poolableObject = BulletPool.GetObject();
                if (poolableObject != null)
                {
                    bullet = poolableObject.GetComponent <Bullet>();

                    bullet.Damage             = Damage;
                    bullet.transform.position = transform.position + BulletSpawnOffset;
                    bullet.transform.rotation = Agent.transform.rotation;
                    bullet.Rigidbody.AddForce(Agent.transform.forward * BulletPrefab.MoveSpeed, ForceMode.VelocityChange);
                }
            }
            else
            {
                Agent.enabled = true; // no target in line of sight, keep trying to get closer
            }

            yield return(Wait);

            if (targetDamageable == null || !HasLineOfSightTo(targetDamageable.GetTransform()))
            {
                Agent.enabled = true;
            }

            Damageables.RemoveAll(DisabledDamageables);
        }

        Agent.enabled   = true;
        AttackCoroutine = null;
    }
Esempio n. 22
0
    public void Attack(CharacterStats targetStats)
    {
        if (attackCooldown <= 0f)
        {
            StartCoroutine(DoDamage(targetStats, attackDelay));

            if (onAttack != null)
            {
                onAttack.Invoke();
            }

            attackCooldown = 1f / attackSpeed;
        }
    }
Esempio n. 23
0
        public void Attack(Characters.Character targetStats)
        {
            if (targetStats.CanAttack && _attackCooldown <= 0f)
            {
                Attacked = true;

                enemyCurrentlyFightingWith = targetStats.GetComponent <GameObject>();

                StartCoroutine(DealBasicAttackDamage(targetStats, attackDelay));

                OnAttack?.Invoke();

                _attackCooldown = 1f / _myStats.stats[5].GetValue();
            }
        }
Esempio n. 24
0
    protected override void Attacking()
    {
        if (!PlayerOnAttackRange())
        {
            actualTime = 0;
            OnEnemyOutOfAttackRange();
            return;
        }

        if (actualTime <= 0)
        {
            OnAttack.Invoke();
            actualTime = fireRate;
            nav.speed  = 0;
            attackFSM.Attack();
        }
        actualTime -= Time.deltaTime;
    }
Esempio n. 25
0
    public bool attack(Entity entity)
    {
        if (entity != null)
        {
            OnAttack?.Invoke(entity);
            entity.TakeDamage(TotalDamage);
            _grid.EnqueueEvent(new GameEvent(GameEvent.EventType.DAMAGE_DEALT, this));

            if (FreeAttacks > 0)
            {
                FreeAttacks -= 1;
                return(false);
            }

            return(true);
        }
        return(false);
    }
Esempio n. 26
0
    public void Attack(CharacterStatsBin targetStats)
    {
        // if it's time to attack then attack
        if (attackCooldown <= 0f)
        {
            // delaying the animation
            StartCoroutine(DoDamage(targetStats, attackDelay));

            // start the attack animation
            OnAttack?.Invoke();

            // bigger is the attackspeed, smaller the cooldown is
            attackCooldown = 1f / attackSpeed;

            // still in combat
            InCombat       = true;
            lastAttackTime = Time.time;
        }
    }
Esempio n. 27
0
        public void UseCard(Guid targetId, CardData card, Action callBack)
        {
            if (UnitState == UnitState.Exhausted)
            {
                UnitState = UnitState.Normal;
                OnExhausted?.Invoke(this, callBack);
                return;
            }

            // Temp
            if (card.Name == "Tail Attack")
            {
                Debug.LogWarning("Tail attack!!!!!");
                UnitState = UnitState.Exhausted;
            }

            // var cf = new CardFactory();
            // var act = cf.GetAction(card.CardClass);
            isInAction = true;
            var target = GameObject.Find(targetId.ToString()).GetComponent <UnitManager>();
            var args   = new CardArgs(this, target, card, callBack);

            switch (card.CardClass)
            {
            case CardClass.Damage:
                OnAttack?.Invoke(this, args);
                break;

            case CardClass.Heal:
                this.HP += card.Amount;
                if (this.HP >= UnitData.HP)
                {
                    this.HP = UnitData.HP;
                }

                OnGetHeal?.Invoke(this, args);
                break;

            default:
                break;
            }
        }
        private void OnCollisionEnter2D(Collision2D other)
        {
            GameObject otherGameObject = other.gameObject;

            if ((1 << otherGameObject.layer & attackTargetLayer) == 0)
            {
                return; // return if the other game object is not in the layer
            }
            CombatEntity otherCombatEntity = otherGameObject.GetComponent <CombatEntity>();

            if (otherCombatEntity == null)
            {
                return; // return if the other game object does not have a `CombatEntity` component
            }
            // This method will be called on the other side (other `CombatEntity`), too.
            // Therefore, there is no need to call `GetAttacked` of the other one here.
            rigidBody.AddForce(other.relativeVelocity.normalized * settings.pushBackForce, ForceMode2D.Impulse);
            GetAttacked(otherCombatEntity.CurrentAttack);
            onAttack.Invoke(other, this, otherCombatEntity);
        }
Esempio n. 29
0
        public void Attack(Container target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            Destroyable destr;

            if ((destr = target.GetComponent <Destroyable>()) == null)
            {
                throw new ArgumentException("target have'nt Destroyable component");
            }

            if (OnAttack != null)
            {
                OnAttack.Invoke(new SessionChange()); //TODO
            }
            int attackPower = this.attackPower;

            destr.DeltaHealth(-attackPower);
        }
Esempio n. 30
0
        public void Attack(Container target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (target.Owner == Container.Owner)
            {
                throw new ArgumentException("One team players");
            }
            Destroyable destr;

            if ((destr = target.GetComponent <Destroyable>()) == null)
            {
                throw new ArgumentException("target have'nt Destroyable component");
            }
            if (OnAttack != null)
            {
                OnAttack.Invoke(new SessionChange("Attacks ", Container.ID));
            }
            destr.DeltaHealth(-attackPower);
        }