Exemplo n.º 1
0
    /// <summary>
    /// Attacking unit calls Defend method on defending unit.
    /// </summary>
    /// <remarks>
    /// Since this actually gets the final damage number, we should probably set floating text here.
    /// </remarks>
    protected virtual void Defend(Unit other, int damage)
    {
        MarkAsDefending(other);

        //int afflictedDamage = Mathf.Clamp(damage - DefenceFactor, 1, damage);
        //HitPoints -= afflictedDamage;

        HitPoints -= Mathf.Clamp(damage - DefenceFactor, 1, damage);  //Damage is calculated by subtracting attack factor of attacker and defence factor of defender. If result is below 1, it is set to 1.
                                                                      //This behaviour can be overridden in derived classes.

        // Update with Floating Combat Text here.
        // Note that is the damage after defense has been applied but can exceed the maximum hit points remaining. This way we'll know if someone hit very hard and overkilled their target.
        FloatingTextController.Instance.CreateFloatingText((damage - DefenceFactor).ToString(), Cell.transform, false);

        if (UnitAttacked != null)
        {
            UnitAttacked.Invoke(this, new AttackEventArgs(other, this, damage));
        }

        if (HitPoints <= 0)
        {
            if (UnitDestroyed != null)
            {
                UnitDestroyed.Invoke(this, new AttackEventArgs(other, this, damage));
            }
            OnDestroyed();
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Attacking unit calls Defend method on defending unit.
    /// </summary>
    public virtual void onDefend(Unit other, float damage)
    {
        foreach (modifier m in buffs)
        {
            m.onDefend(other);
        }
        MarkAsDefending(other);

        //defensive parameter parsing
        if (this.dynamicAttributes.shieldPoints > 0)
        {
            float shieldDamage = Math.Min(damage, this.dynamicAttributes.shieldPoints);
            damage -= shieldDamage;
            this.dynamicAttributes.shieldPoints -= shieldDamage;
        }
        this.dynamicAttributes.health -= damage;

        UpdateHpBar();

        if (UnitAttacked != null)
        {
            UnitAttacked.Invoke(this, new AttackEventArgs(other, this, damage));
        }
        //check if dying
        if (this.dynamicAttributes.health <= 0)
        {
            if (UnitDestroyed != null)
            {
                UnitDestroyed.Invoke(this, new AttackEventArgs(other, this, damage));
            }
            onDeath();
        }
    }
Exemplo n.º 3
0
    protected virtual void Defend(Unit other, int damage)
    {
        //Debug.Log(other.gameObject.tag+" ready to attack is: "+other.abilityReadyToFire);


        if (!other.abilityReadyToFire)
        {
            HitPoints -= Mathf.Clamp(damage - DefenceFactor, 1, damage);              //Damage is calculated by subtracting attack factor of attacker and defence factor of defender. If result is below 1, it is set to 1.
        }

        MarkAsDefending(other);


        if (UnitAttacked != null)
        {
            UnitAttacked.Invoke(this, new AttackEventArgs(other, this, damage));
        }

        if (HitPoints <= 0)
        {
            if (UnitDestroyed != null)
            {
                UnitDestroyed.Invoke(this, new AttackEventArgs(other, this, damage));
            }
            OnDestroyed();
        }
    }
Exemplo n.º 4
0
    // ------------------

    /// <summary>
    /// Attacking unit calls Defend method on defending unit.
    /// </summary>
    protected virtual void Defend(Unit other, int dealtDamage)
    {
        MarkAsDefending(other);
        int receivedDamage = (int)Mathf.Floor(dealtDamage / DefenceFactor);

        HitPoints -= receivedDamage;
        printDamage(receivedDamage + 1);
        if (other.Buffs.Find(b => b.Name == "Snake Venom") != null)
        {
            SnakeDot sndot = new SnakeDot();
            Buffs.Add(sndot);
        }
        if (UnitAttacked != null)
        {
            UnitAttacked.Invoke(this, new AttackEventArgs(other, this, receivedDamage));
        }

        if (HitPoints <= 0)
        {
            if (UnitDestroyed != null)
            {
                UnitDestroyed.Invoke(this, new AttackEventArgs(other, this, receivedDamage));
            }
            OnDestroyed();
        }
    }
Exemplo n.º 5
0
        /// <summary>
        /// Handler method for defending against an attack.
        /// </summary>
        /// <param name="aggressor">Unit that performed the attack</param>
        /// <param name="damage">Amount of damge that the attack caused</param>
        public void DefendHandler(Unit aggressor, int damage)
        {
            MarkAsDefending(aggressor);
            int damageTaken = Defend(aggressor, damage);

            HitPoints -= damageTaken;
            DefenceActionPerformed();

            UnitAttacked?.Invoke(this, new AttackEventArgs(aggressor, this, damage));
            if (HitPoints <= 0)
            {
                UnitDestroyed?.Invoke(this, new AttackEventArgs(aggressor, this, damage));
                OnDestroyed();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Attacking unit calls Defend method on defending unit.
        /// </summary>
        protected virtual void Defend(Unit other, int damage)
        {
            MarkAsDefending(other);
            // Damage is calculated by subtracting attack factor of attacker and defence factor of defender. If result is below 1, it is set to 1.
            // This behaviour can be overridden in derived classes.
            HitPoints -= MathUtil.Clamp(damage - DefenceFactor, 1, damage);

            UnitAttacked?.Invoke(this, new AttackEventArgs(other, this, damage));

            if (HitPoints <= 0)
            {
                UnitDestroyed?.Invoke(this, new AttackEventArgs(other, this, damage));
                OnDestroyed();
            }
        }
Exemplo n.º 7
0
    /// <summary>
    /// Attacking unit calls Defend method on defending unit.
    /// </summary>
    protected virtual void Defend(Unit other, int damage)
    {
        MarkAsDefending(other);
        int RealDamage = Mathf.Clamp((damage + ((int)(UnityEngine.Random.Range(1, 10)))) - (DefenceFactor + ((int)(UnityEngine.Random.Range(1, 10)))), -(DefenceFactor + 10), (damage + 10));

        //Damage is calculated by subtracting attack factor of attacker and defence factor of defender. If result is below 1, it is set to 1.
        //This behaviour can be overridden in derived classes.
        if (this is VillanoEscudo && (Cell.GetDistance(other.Cell) <= 1))
        {
            if (RealDamage < 0)
            {
                other.Defend(this, damage);
            }
            else
            {
                HitPoints -= RealDamage;
                StartCoroutine(Daño(RealDamage));
            }
        }
        else
        {
            if (!(RealDamage < 0))
            {
                HitPoints -= RealDamage;
                StartCoroutine(Daño(RealDamage));
            }
        }
        if (UnitAttacked != null)
        {
            UnitAttacked.Invoke(this, new AttackEventArgs(other, this, damage));
        }

        if (HitPoints <= 0)
        {
            if (UnitDestroyed != null)
            {
                UnitDestroyed.Invoke(this, new AttackEventArgs(other, this, damage));
            }
            OnDestroyed();
        }
    }
Exemplo n.º 8
0
    /// <summary>
    /// Attacking unit calls Defend method on defending unit.
    /// </summary>
    protected virtual void Defend(Unit other, int damage)
    {
        MarkAsDefending(other);
        HitPoints -= DamageCalculator(other, damage, 0, Cell.defenseValue);
        GameObject.Find("DamageSound").GetComponent <AudioSource>().Play();

        StartCoroutine("DamageFlash");

        //(55 * ((100 / (100 + 0 * 10))) / (10 - Math.Ceiling(10)))
        //HitPoints -= Mathf.Clamp(damage - DefenceFactor, 1, damage);  //Damage is calculated by subtracting attack factor of attacker and defence factor of defender. If result is below 1, it is set to 1.
        //This behaviour can be overridden in derived classes.
        if (UnitAttacked != null)
        {
            UnitAttacked.Invoke(this, new AttackEventArgs(other, this, damage));
        }

        if (HitPoints <= 0)
        {
            CellGrid grid     = GameObject.Find("CellGrid").GetComponent <CellGrid>();
            Player   myPlayer = grid.Players.Find(p => p.PlayerNumber.Equals(this.PlayerNumber));
            if (grid.Units.FindAll(u => u.PlayerNumber.Equals(this.PlayerNumber) && !(u is Building)).Count <= 1)
            {
                myPlayer.EliminatePlayer(false, other);
                grid.CheckForEndGame();
            }

            DestroyUnit(other, damage);

            return;
        }
        if (CanCounterAttack(other))
        {
            AttackFactor = (int)(DamageChart.damageValues[this.GetDamageType().ToString().ToUpper()][other.GetArmorType().ToString().ToUpper()] * damageMultiplier * other.armorMultiplier);
            //AttackFactor = DamageChart.damageValues[this.GetType().ToString()][other.GetType().ToString()];
            other.HitPoints -= other.DamageCalculator(this, AttackFactor, 0, 0);

            other.StartCoroutine("DamageFlash");
        }

        UpdateHpBar();
    }
Exemplo n.º 9
0
    /// <summary>
    /// Attacking unit calls Defend method on defending unit.
    /// </summary>
    protected virtual void Defend(Unit other, int damage)
    {
        if (UnityEngine.Random.Range(1, 20) + other.AttackBonus >= DefenseFactor)
        {
            MarkAsDefending(other);
            HitPoints -= damage;
            if (UnitAttacked != null)
            {
                UnitAttacked.Invoke(this, new AttackEventArgs(other, this, damage));
            }

            if (HitPoints <= 0)
            {
                if (UnitDestroyed != null)
                {
                    UnitDestroyed.Invoke(this, new AttackEventArgs(other, this, damage));
                }
                OnDestroyed();
            }
        }
    }
Exemplo n.º 10
0
    // Attacking unit calls Defend method on defending unit.
    public override void TakeDamage(Entity other, float damage)
    {
        Unit attacker = other as Unit;

        MarkAsDefending(this);
        HitPoints -= Mathf.Clamp(damage - Defense, 1, damage);  //Damage is calculated by subtracting attack factor of attacker and defence factor of defender. If result is below 1, it is set to 1.
        //This behaviour can be overridden in derived classes.
        if (UnitAttacked != null)
        {
            UnitAttacked.Invoke(this, new AttackEventArgs(attacker, this, damage));
        }

        if (HitPoints <= 0)
        {
            if (UnitDestroyed != null)
            {
                UnitDestroyed.Invoke(this, new AttackEventArgs(attacker, this, damage));
            }
            OnDestroyed();
        }
    }
Exemplo n.º 11
0
    /*
     * public IEnumerator Retaliate(Unit other)
     * {
     *  yield return new WaitForSeconds(0.5f);
     *  MarkAsAttacking(other);
     *  other.Defend(this, Atk);
     * }
     */

    /// <summary>
    /// Attacking unit calls Defend method on defending unit.
    /// </summary>
    protected virtual void Defend(Unit other, int damage)
    {
        MarkAsDefending(other);
        //Damage is calculated by subtracting attack factor of attacker and defence/resistance factor of target.
        //If result is below 1, it is set to 1. This behaviour can be overridden in derived classes.
        if (other.card.weapon.damageType == Weapon.DamageType.Physical)
        {
            var lastHP = HP;
            HP -= Mathf.Clamp(damage - Def, 0, damage);
            Debug.Log(other.card.name + " dealt " + (lastHP - HP) + " physical damage to " + card.name + ".");
            lastHP = HP;
        }
        else if (other.card.weapon.damageType == Weapon.DamageType.Magical)
        {
            var lastHP = HP;
            HP -= Mathf.Clamp(damage - Res, 0, damage);
            Debug.Log(other.card.name + " dealt " + (lastHP - HP) + " magical damage to " + card.name + ".");
            lastHP = HP;
        }

        if (UnitAttacked != null)
        {
            UnitAttacked.Invoke(this, new AttackEventArgs(other, this, damage));
        }

        if (HP <= 0)
        {
            if (UnitDestroyed != null)
            {
                Debug.Log(this.card.name + " has been defeated.");
            }
            UnitDestroyed.Invoke(this, new AttackEventArgs(other, this, damage));
            OnDestroyed();
        }
        if (HP > 0 && CounterPoints > 0 && (card.range == other.card.range))
        {
            //Debug.Log(name + CounterPoints + " " + other.CounterPoints);
            CounterAttack(other);
        }
    }
Exemplo n.º 12
0
    /// <summary>
    /// Attacking unit calls Defend method on defending unit.
    /// </summary>
    protected virtual void Defend(Unit other, int damage, bool isHp, bool isTrueDamage)
    {
        MarkAsDefending(other);
        if (isHp)
        {
            if (isTrueDamage)
            {
                HitPoints -= damage;
            }
            else
            {
                HitPoints -= Mathf.Clamp(damage - Armor, 1, damage); //Damage is calculated by subtracting attack factor of attacker and defence factor of defender. If result is below 1, it is set to 1.
                                                                     //This behaviour can be overridden in derived classes.
            }
        }
        else
        {
            Armor -= damage;
            if (Armor < 0)
            {
                Armor = 0;
            }
        }

        if (UnitAttacked != null)
        {
            UnitAttacked.Invoke(this, new AttackEventArgs(other, this, damage));
        }

        if (HitPoints <= 0)
        {
            if (UnitDestroyed != null)
            {
                UnitDestroyed.Invoke(this, new AttackEventArgs(other, this, damage));
            }
            OnDestroyed();
        }
    }
Exemplo n.º 13
0
        //Metoda obsługi obrony przed atakiem. Do rozkminienia
        public virtual void DefendHandler(Unit aggressor, int damage)
        {
            if (aggressor.GetComponent <Wizard>() != null)
            {
                speelsAnimator.SetBool("MagicShoot", true);
                StartCoroutine(SpeelsAnimatio());
            }
            if (aggressor.GetComponent <DistanceEntity>() != null)
            {
                speelsAnimator.SetBool("Arrow", true);
                StartCoroutine(SpeelsAnimatio());
            }

            scoreController = FindObjectOfType <ScoreController>();
            scoreController.UpgradeScore();
            StartCoroutine(AttackAnimation());
            MarkAsDefending(aggressor);
            if (Cell.Forest)
            {
                Random rand    = new Random();
                int    randInt = rand.Next(0, 100);
                if (ArmorPoints > 0 && !aggressor.ignorArmor)
                {
                    if (randInt >= DodgeHitPercentUnit)
                    {
                        ArmorPoints -= aggressor.AttackFactor;
                        UnitWithArmor(aggressor, damage);
                    }
                    else
                    {
                        audioManager.Play("Miss");
                        Debug.Log("Defence");
                    }
                }
                else
                {
                    if (randInt >= DodgeHitPercentUnit)
                    {
                        if (onDef)
                        {
                            UnitWithArmor(aggressor, damage);
                        }
                        else
                        {
                            int damageTaken = aggressor.AttackFactor;
                            HitPoints -= damageTaken;
                            Debug.Log("Obecne Zdrowie: " + HitPoints + " Zadane Obrazenia: " + damageTaken);
                            if (HitPoints <= 0)
                            {
                                if (UnitDestroyed != null)
                                {
                                    UnitDestroyed.Invoke(this, new AttackEventArgs(aggressor, this, damage));
                                }
                                OnDestroyed();
                            }
                        }
                    }
                    else
                    {
                        audioManager.Play("Miss");
                        Debug.Log("Defence");
                    }
                }
            }
            else
            {
                if (ArmorPoints > 0 && !aggressor.ignorArmor)
                {
                    ArmorPoints -= aggressor.AttackFactor;
                    UnitWithArmor(aggressor, damage);
                }
                else
                {
                    int damageTaken = aggressor.AttackFactor;
                    HitPoints -= damageTaken;
                    if (HitPoints <= 0)
                    {
                        if (UnitDestroyed != null)
                        {
                            UnitDestroyed.Invoke(this, new AttackEventArgs(aggressor, this, damage));
                        }
                        OnDestroyed();
                    }
                    Debug.Log("Obecne Zdrowie: " + HitPoints + " Zadane Obrazenia: " + damageTaken);
                }
            }
            DefenceActionPerformed();
            if (UnitAttacked != null)
            {
                UnitAttacked.Invoke(this, new AttackEventArgs(aggressor, this, damage));
            }
        }