Exemple #1
0
 /// <summary>
 /// Starts attack resolution animation
 /// </summary>
 private void OnAttackResolved(object sender, AttackResolutionEvent args)
 {
     if (ShouldPlayAttackResolutionAnimation())
     {
         FileLogger.Trace("COMBAT VIEW", "Playing attack resolution of " + args.GetAttack().GetUnitType().GetName() + " vs " + args.GetTarget().GetUnitType().GetName());
         _attackResolutionView.gameObject.SetActive(true);
         _attackResolutionView.SetModel(args);
     }
     else
     {
         SkipAttackResolutionAnimation();
     }
 }
 public void SetModel(AttackResolutionEvent eventData)
 {
     _model = eventData;
     _defenderImage.material.mainTexture = SpriteCollectionManager.GetTextureByName(_model.GetTarget().GetUnitType().GetName());
     _attackerImage.material.mainTexture = SpriteCollectionManager.GetTextureByName(_model.GetAttack().GetUnitType().GetName());
     _attackerRoll.text          = "";
     _defenderRoll.text          = "";
     _hitOrMissMessage.text      = "";
     _damageRoll.text            = "";
     _defenderArmor.text         = "";
     _finalDamage.text           = "";
     _defenderQuantityField.text = "";
     _defenderHealthField.text   = "";
     StartCoroutine("UpdateView");
 }
 public void SetModel(AttackResolutionEvent eventData)
 {
     _model = eventData;
     _attackerNameField.text     = _model.GetAttack().GetUnitType().GetName();
     _defenderNameField.text     = _model.GetTarget().GetUnitType().GetName();
     _defenderImage.sprite       = SpriteCollectionManager.GetSpriteByName(_defenderNameField.text);
     _attackerImage.sprite       = SpriteCollectionManager.GetSpriteByName(_attackerNameField.text);
     _attack.text                = "";
     _attackerRoll.text          = "";
     _totalAttack.text           = "";
     _defense.text               = "";
     _defenderRoll.text          = "";
     _totalDefense.text          = "";
     _hitOrMissMessage.text      = "VS";
     _hitOrMissMessage.color     = Color.black;
     _damageRoll.text            = "";
     _defenderArmor.text         = "";
     _finalDamage.text           = "";
     _defenderQuantityField.text = "";
     _defenderHealthField.text   = "";
     StartCoroutine("UpdateView");
 }
Exemple #4
0
    /// <summary>
    /// Resolve an attack against the target unit stack
    /// </summary>
    /// <param name="target">Target unit stack</param>
    /// <param name="attackRollResult">Attack roll result representing the attack</param>
    /// <param name="useEstimates">Whether estimated results will be used or honest rolls will be made</param>
    /// <returns>Whether the attack was successfully resolved</returns>
    private bool ResolveAnAttackAgainstTarget(UnitStack target, AttackRollResult attackRollResult, bool useEstimates)
    {
        if (!IsValidAttackTarget(target, attackRollResult))
        {
            return(false);
        }

        int positiveDieRoll = CombatHelper.Instance.RollDie();
        int negativeDieRoll = CombatHelper.Instance.RollDie();
        int defenseRoll     = positiveDieRoll - negativeDieRoll;

        int defensiveSkill = CombatHelper.Instance.CalculateDefensiveSkill(attackRollResult.Attack, target);
        int shield         = CombatHelper.Instance.CalculateShieldValue(attackRollResult.Attack, target);

        AttackResolutionEvent data = new AttackResolutionEvent(attackRollResult, target, positiveDieRoll, negativeDieRoll, defensiveSkill, shield);
        int totalDefense           = defenseRoll + defensiveSkill + shield;

        int armor = CombatHelper.Instance.CalculateArmorValue(attackRollResult.Attack, target, attackRollResult.IsCritical);

        data.SetArmor(armor);

        int damage = 0;

        if (useEstimates)
        {
            damage = CombatHelper.Instance.EstimateAttackDamage(attackRollResult, target);
        }
        else
        {
            damage = CombatHelper.Instance.CalculateDamage(attackRollResult, target, totalDefense, armor);
        }
        data.SetDamage(damage);
        target.TakeDamage(damage);

        int totalAttack = attackRollResult.AttackRoll + attackRollResult.AttackSkill;

        if (useEstimates)
        {
            FileLogger.Trace("COMBAT", "Simulation: estimated damage = " + damage);
        }
        else
        {
            FileLogger.Trace("COMBAT", "Attack: " + totalAttack + ", defense: " + totalDefense + ", weapon damage: " + attackRollResult.FullDamage + ", armor: " + armor + ", resulting damage: " + damage);
        }

        bool deleted = false;

        for (int i = 0; i < _attackerRollResults.Count; i++)
        {
            if (_attackerRollResults[i].Contains(attackRollResult))
            {
                bool removed = _attackerRollResults[i].RemoveAttackRollResult(attackRollResult);
                if (!removed)
                {
                    FileLogger.Trace("COMBAT", "Failed to remove an attack roll result from a collection!");
                }
                if (_attackerRollResults[i].Count == 0)
                {
                    _attackerRollResults.RemoveAt(i);
                }
                deleted = true;
                break;
            }
        }

        if (!deleted)
        {
            for (int i = 0; i < _defenderRollResults.Count; i++)
            {
                if (_defenderRollResults[i].Contains(attackRollResult))
                {
                    bool removed = _defenderRollResults[i].RemoveAttackRollResult(attackRollResult);
                    if (!removed)
                    {
                        FileLogger.Trace("COMBAT", "Failed to remove an attack roll result from a collection!");
                    }
                    if (_defenderRollResults[i].Count == 0)
                    {
                        _defenderRollResults.RemoveAt(i);
                    }
                    break;
                }
            }
        }

        if (AttackResolved != null)
        {
            AttackResolved(this, data);
        }

        return(true);
    }