public void loadCombatData(unitScript attacker, unitScript defender, float AttackerChanceToHit, float defenderChanceToHit)
    {
        Transform combatPanel = transform.Find("CombatPanel");
        Transform EnemyPanel  = combatPanel.Find("EnemyPanel");

        var targetText = EnemyPanel.Find("Target").GetComponent <UnityEngine.UI.Text>();

        targetText.text = defender.getName();

        var classText = EnemyPanel.Find("Class").GetComponent <UnityEngine.UI.Text>();

        classText.text = defender.getClass();

        var healthText = EnemyPanel.Find("Health").GetComponent <UnityEngine.UI.Text>();

        healthText.text = defender.getHealth().ToString() + " : " + defender.getMaxHealth().ToString();

        var strikeBack = EnemyPanel.Find("StrikeBack").GetComponent <Text>();

        strikeBack.text = (!defender.getStrikeback()).ToString();

        var strikebackChanceText = EnemyPanel.Find("ChanceText").GetComponent <Text>();
        var strikebackDamageText = EnemyPanel.Find("DamageText").GetComponent <Text>();

        var strikebackChance = EnemyPanel.Find("Chance").GetComponent <Text>();
        var strikebackDamage = EnemyPanel.Find("Damage").GetComponent <Text>();


        if (!defender.getStrikeback())
        {
            strikebackChance.enabled     = true;
            strikebackDamage.enabled     = true;
            strikebackChanceText.enabled = true;
            strikebackDamageText.enabled = true;

            strikebackChance.text = defenderChanceToHit.ToString();

            strikebackDamage.text = defender.getCurrentWeapon().damage.ToString();
        }
        else
        {
            strikebackChance.enabled     = false;
            strikebackDamage.enabled     = false;
            strikebackChanceText.enabled = false;
            strikebackDamageText.enabled = false;
        }
        int chance = (int)Mathf.Max(0, Mathf.Min(100, AttackerChanceToHit * 100));

        combatPanel.Find("ChanceToHit").GetComponent <UnityEngine.UI.Text>().text = (chance).ToString() + "%";
        combatPanel.Find("Damage").GetComponent <UnityEngine.UI.Text>().text      = unit.getCurrentWeapon().damage.ToString();
    }
Exemplo n.º 2
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);
    }
Exemplo n.º 3
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);
    }