Exemple #1
0
    protected bool RangedAttack(unitScript unit, unitScript clickedUnit, bool initialAttack = true)
    {
        // Check LoS
        if (!canSee(unit, clickedUnit))
        {
            return(false);
        }

        if (hitShield(unit, clickedUnit))
        {
            return(true);
        }

        //Resolve Attack

        float roll        = UnityEngine.Random.Range(0.0f, 1.0f);
        float chanceToHit = rangedChanceToHit(unit, clickedUnit);

        print(roll + " " + chanceToHit);
        if (roll < chanceToHit)
        {
            clickedUnit.takeDamage(unit.getCurrentWeapon().damage);
        }
        else
        {
            clickedUnit.displayMiss();
        }
        unit.activateAttack();
        if (initialAttack && clickedUnit.getStrikeback() == false)
        {
            bool result;
            if (clickedUnit.getCurrentWeapon().type == WeaponType.melee)
            {
                result = MeleeAttack(clickedUnit, unit, false);
            }
            else if (clickedUnit.getCurrentWeapon().type == WeaponType.ranged)
            {
                result = RangedAttack(clickedUnit, unit, false);
            }
            else
            {
                result = false;
            }
            if (result)
            {
                clickedUnit.useStrikeback();
            }
        }
        return(true);
    }
Exemple #2
0
    protected bool MeleeAttack(unitScript unit, unitScript clickedUnit, bool initialAttack = true)
    {
        // Check attack can occur
        if (unit.getCurrentWeapon().type == WeaponType.ranged || unit == null || clickedUnit == null)
        {
            return(false);
        }

        float distance = Vector2.Distance(unit.GetComponent <GridItem>().getPos(), clickedUnit.GetComponent <GridItem>().getPos());

        if (!(unit.getCurrentWeapon().type == WeaponType.melee) || distance > ((MeleeWeapon)unit.getCurrentWeapon()).range)
        {
            return(false);
        }

        // Given it can roll the dice
        float roll = UnityEngine.Random.Range(0.0f, 1.0f);

        float chanceToHit = meleeChanceToHit(unit, clickedUnit);

        print(roll + " " + chanceToHit);
        if (roll < chanceToHit)
        {
            clickedUnit.takeDamage(unit.getStrength() + unit.getCurrentWeapon().damage);
        }
        else
        {
            clickedUnit.displayMiss();
        }
        unit.activateAttack();
        if (initialAttack && clickedUnit.getStrikeback() == false)
        {
            bool result = MeleeAttack(clickedUnit, unit, false);
            if (result)
            {
                clickedUnit.useStrikeback();
            }
        }
        return(true);
    }