Ejemplo n.º 1
0
    //For now this will just be hitting or missing (no crits).
    //Crits and detailed attack data should probably be stored as variables on the attack manager, or even into seperate 'attackData' classes that are per attack. s
    public static Result AttackRoll(Unit _attacker, Unit _defender, int _bonuses = 0)
    {
        ResetValues();

        attacker = _attacker;
        defender = _defender;

        attack  += attacker.unitInfo.currentAttack;
        bonuses += _bonuses;

        OnAttack(attacker, defender);

        DecideDefence(attacker, defender);

        //check conditions
        if (defender.unitInfo.flagging)
        {
            bonuses++;
        }

        //check focus
        if (attacker.focus != defender)
        {
            attacker.gameObject.GetComponent <UnitPopUpManager>().AddPopUpInfo("Astray");
            bonuses--;
            attacker.focus         = defender;
            attacker.focusSwitched = true;
        }
        else if (defender.focus != attacker)
        {
            attacker.gameObject.GetComponent <UnitPopUpManager>().AddPopUpInfo("Blindsiding");
            bonuses++;
        }

        //check for weight
        if (attacker.unitInfo.mainWeaponData.weight >= ItemData.Weight.medium)
        {
            attacker.UpdateBreath(-1, true);
            if (attacker.unitInfo.mainWeaponData.weight > ItemData.Weight.medium)
            {
                damage += (int)attacker.unitInfo.mainWeaponData.weight;
            }
        }

        AbilityCheck.CheckAbility(attack, defence, bonuses);

        attackRolled = true;

        //Work out criticals
        CriticalManager.Reset();

        if (autocrit)
        {
            AbilityCheck.crits = Mathf.Max(AbilityCheck.crits, 1);
        }

        for (int count = 0; count < AbilityCheck.crits; count++)
        {
            CriticalManager.AddCritical(attacker.mainWeapon);
        }

        //Resolve all pre-damage criticals.
        foreach (Critical c in CriticalManager.criticalChain)
        {
            if (c.AfterDamage() == false)
            {
                c.CriticalEffect();
            }
        }

        //Work out the result
        if (AbilityCheck.baseResult >= 0)
        {
            CombatLog.UpdateCombatLog(attacker.name + " attacks " + defender.name + " and scores a success.");
            return(Result.SUCCESS);
        }
        if (AbilityCheck.baseResult >= -9)
        {
            if (defenceType == DefenceType.DODGE)
            {
                defender.GetComponent <TacticsMovement>().Dodge(Result.PARTIAL);
                defender.gameObject.GetComponent <UnitPopUpManager>().AddPopUpInfo("dodged");
            }
            if (defender.focus != attacker)
            {
                defender.SetFocus(attacker);
            }
            CombatLog.UpdateCombatLog(attacker.name + " attacks " + defender.name + " and scores a partial.");
            return(Result.PARTIAL);
        }
        else
        {
            if (defenceType == DefenceType.DODGE)
            {
                defender.GetComponent <TacticsMovement>().Dodge(Result.FAIL);
                defender.gameObject.GetComponent <UnitPopUpManager>().AddPopUpInfo("evaded");
            }
            defender.gameObject.GetComponent <UnitPopUpManager>().AddPopUpInfo("miss");
            CombatLog.UpdateCombatLog(attacker.name + " attacks " + defender.name + " and scores a fail.");
            return(Result.FAIL);
        }
    }
Ejemplo n.º 2
0
    public static void DamageRoll(TacticsMovement attacker, Unit defender, Result attackResult)
    {
        damage     += attacker.unitInfo.currentDamage;
        resiliance += defender.unitInfo.currentToughness;
        if (!armourPierce)
        {
            resiliance += defender.unitInfo.currentArmour;
        }

        //Blocking
        if (defenceType == DefenceType.BLOCK)
        {
            blockDice = -1;
            defender.gameObject.GetComponent <UnitPopUpManager>().AddPopUpInfo("blocked");
        }
        if (defenceType == DefenceType.SHIELD)
        {
            blockDice = -2;
            defender.gameObject.GetComponent <UnitPopUpManager>().AddPopUpInfo("shielded");
        }

        AbilityCheck.CheckAbility(damage, resiliance, blockDice);
        int result = AbilityCheck.baseResult;

        //assumes all are 'fated' for now.
        if (result < -9)
        {
            defender.gameObject.GetComponent <UnitPopUpManager>().AddPopUpInfo("shrugged");
            return;
        }
        else if (result < 1)
        {
            OnGraze(attacker, defender); //Alert all that someone is grazed.
            defender.UpdateBreath(grazeDamage);
            struckAnimation = StruckAnimation.GRAZE;
        }
        else
        {
            OnWound(attacker, defender); //Alert all that someone is wounded.
            if (result > 9)
            {
                wounds = 3;
            }
            else if (result > 4)
            {
                wounds = 2;
            }
            else
            {
                wounds = 1;
            }
            defender.UpdateWounds(wounds, woundValueAdjustment);
            struckAnimation = StruckAnimation.WOUND;
        }

        //Resolve all post-damage criticals.
        foreach (Critical c in CriticalManager.criticalChain)
        {
            if (c.AfterDamage() == true)
            {
                c.CriticalEffect();
            }
        }

        switch (struckAnimation)
        {
        case StruckAnimation.SHIELD:
            defender.unitAnim.SetTrigger("shield");
            break;

        case StruckAnimation.BLOCK:
            defender.unitAnim.SetTrigger("block");
            break;

        case StruckAnimation.GRAZE:
            defender.unitAnim.SetTrigger("graze");
            break;

        case StruckAnimation.WOUND:
            defender.unitAnim.SetTrigger("wound");
            break;

        default:
            break;
        }

        if (defender.focus != attacker)
        {
            defender.SetFocus(attacker);
        }
    }