Example #1
0
    /// <summary>
    /// Совершает бросок на попадание
    /// </summary>
    public RollResultWithCriticals HitRoll()
    {
        attackCheck.CalculateResult();
        RollResultWithCriticals attackResult = attackCheck.Result as RollResultWithCriticals;

        return(attackResult);
    }
    private void PerformAttack(RaycastHit2D hit)
    {
        if (attackArea == null)
        {
            return;
        }

        Vector3    mouseWorldPos   = camera.ScreenToWorldPoint(Input.mousePosition);
        Vector3Int tilemapMousePos = UILayer.WorldToCell(mouseWorldPos);

        if (attackArea.AffectedCharacters.Contains(tilemapMousePos))
        {
            Character targetCharacter = (Character)attackArea.AffectedCharacters[tilemapMousePos];
            Attack    attack          = currentCharacter.PerformMainHandAttack(targetCharacter.ArmorClass);

            RollResultWithCriticals rollResult = attack.HitRoll();

            logEvent.Invoke(currentCharacter.name + " attacks " + targetCharacter.name);
            logEvent.Invoke($"Attack roll: {rollResult.Representation}");

            if (rollResult.CriticalSuccess || rollResult.Value >= targetCharacter.ArmorClass)
            {
                DamageRollResult damageResult = attack.DamageRoll();
                logEvent.Invoke($"Damage: {damageResult.Representation}");
                targetCharacter.TakeDamage(damageResult.Value);
                logEvent.Invoke($"{targetCharacter.name} takes {damageResult.Value} damage");
            }
            //else if ()
            //{
            //    //logEvent.Invoke("Hit value: " + rollResult.Value);
            //    int damage = attack.DamageRoll();
            //    targetCharacter.TakeDamage(damage);
            //    logEvent.Invoke(targetCharacter.name + " takes " + damage + " damage");
            //}
            else
            {
                logEvent.Invoke(currentCharacter.name + " misses");
            }
            //{
            //    //logEvent.Invoke("Hit value: " + rollResult.Value);

            //}

            ClearTiles(attackArea.AffectedTiles);
            ClearTilesFromHashtable(attackArea.AffectedCharacters);

            attackArea = null;
        }
    }