Unit.UseWeapon C# (CSharp) Method

UseWeapon() protected method

protected UseWeapon ( ) : void
return void
    protected override void UseWeapon()
    {
        base.UseWeapon();
    }

Usage Example

Example #1
0
    public static void Battle(Unit attacker, Unit recipient)
    {
        TurnScheduler turnScheduler = GameAssets.MyInstance.turnScheduler;

        bool hit  = new Random().Next(1, 100) <= attacker.stats[StatString.HIT_RATE].Value;
        bool crit = new Random().Next(1, 100) <= attacker.stats[StatString.CRIT_RATE].Value;

        if (!recipient.isDead())
        {
            if (hit)
            {
                // must take into account whether the main attack is magic or physical
                int attackDamage = CalculateBaseDamage(attacker, recipient);
                attackDamage = crit ? attackDamage * CritMultiplier : attackDamage;
                recipient.TakeDamage(attackDamage);
                attacker.UseWeapon();
                DamagePopUp.Create(recipient.transform.position, string.Format("- {0} HP", (int)attackDamage),
                                   PopupType.DAMAGE, crit);
            }
            else
            {
                DamagePopUp.Create(recipient.transform.position, "MISS!", PopupType.DAMAGE);
            }
        }

        bool killed = false;

        if (recipient.isDead())
        {
            turnScheduler.StartCoroutine(turnScheduler.RemoveUnit(recipient));
            killed = true;
        }
        else
        {
            recipient.UpdateUI();
        }

        // add exp
        if (hit)
        {
            int exp = Level.CalculateExp(recipient.level, attacker.level, killed);
            attacker.level.AddExp(exp);
        }

        attacker.UpdateUI();
    }
All Usage Examples Of Unit::UseWeapon