Exemple #1
0
    public static void SolveAttack(IBattleEntity attacker, IBattleEntity defender, out BattleActionResult results)
    {
        results = new BattleActionResult();
        results.AttackerName = attacker.Name;
        results.DefenderName = defender.Name;

        results.DefenderStartHP = defender.HPTrait.HP;

        // 1. Solve chance to hit
        float attackerHitChance = 1.0f;

        if (URandom.value > attackerHitChance)
        {
            results.AttackerFlopped = true;
            return;
        }

        // 2. Solve defender's deflection
        float defenderAvoidChance = 0.0f;

        if (URandom.value <= defenderAvoidChance)
        {
            results.DefenderAvoided = true;
            return;
        }

        // 3. Crit check?
        float attackCriticalBonus = 0.0f;

        float attackerCritChance = 0.0f;

        if (URandom.value <= attackerCritChance)
        {
            attackCriticalBonus = 0.0f;
            results.Critical    = true;
        }

        // 4. Attack
        float attack = attacker.BattleTrait.Damage;

        attack *= (1 + attackCriticalBonus);
        float defense = 0.0f;

        int damageInflicted = (int)((attack * attack) / (attack + defense));

        results.AttackerDmgInflicted = damageInflicted;
        results.DefenderDmgTaken     = Mathf.Min(damageInflicted, defender.HPTrait.HP);
        results.DefenderDefeated     = damageInflicted >= defender.HPTrait.HP;

        attacker.ApplyBattleResults(results, BattleRole.Attacker);
        defender.ApplyBattleResults(results, BattleRole.Defender);
    }