示例#1
0
    public void UnitAttackMode(FEUnit unit, Unit other, Cell sourceCell)
    {
        GameObject AttackPanel = GameObject.Find("Attack Panel");

        AttackPanel.SetActive(true);
        Button Melee  = GameObject.Find("Select Melee Attack").GetComponent <Button>();
        Button Ranged = GameObject.Find("Select Ranged Attack").GetComponent <Button>();
        Button Magic  = GameObject.Find("Select Magic Attack").GetComponent <Button>();
        //Melee.onClick
    }
示例#2
0
    /// <summary>
    /// Attacking unit calls Defend method on defending unit.
    /// </summary>
    protected void Defend(FEUnit other, int damage, AttackType attack)
    {
        MarkAsDefending(other);
        int DamageTaken = 0;

        switch (attack)
        {
        case AttackType.melee:
            if (this.MeleeDefense < UnityEngine.Random.Range(0, 50))
            {
                DamageTaken = 0;
            }
            else
            {
                DamageTaken = Mathf.Clamp(damage - Armor, 1, damage);
            }
            break;

        case AttackType.ranged:
            DamageTaken = Mathf.Clamp(damage - Armor, 1, damage);
            break;

        case AttackType.magic:
            DamageTaken = Mathf.Clamp(damage - Resistance, 1, damage);
            break;

        default: DamageTaken = 0; break;
        }
        HitPoints -= DamageTaken; //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.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();
        }
    }
示例#3
0
    /// <summary>
    /// Method deals damage to unit given as parameter.
    /// </summary>
    public void DealDamage(FEUnit other)
    {
        if (isMoving)
        {
            return;
        }
        if (ActionPoints == 0)
        {
            return;
        }
        if (!IsUnitAttackable(other, Cell))
        {
            return;
        }
        UnitAttackMode(this, other, Cell);

        MarkAsAttacking(other);
        ActionPoints--;
        switch (this.CurrentAttack)
        {
        case AttackType.melee:
            other.Defend(this, MeleeAttack, AttackType.melee); break;

        case AttackType.ranged:
            other.Defend(this, RangedAttack, AttackType.ranged); break;

        case AttackType.magic:
            other.Defend(this, RangedAttack, AttackType.ranged); break;

        default:
            other.Defend(this, RangedAttack, AttackType.ranged); break;
        }

        if (ActionPoints == 0)
        {
            SetState(new UnitStateMarkedAsFinished(this));
            MovementPoints = 0;
        }
    }