コード例 #1
0
    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;
        }
    }
コード例 #2
0
    /// <summary>
    /// Совершает бросок на урон
    /// </summary>
    /// <returns></returns>
    public DamageRollResult DamageRoll()
    {
        if (attackCheck.Result == null)
        {
            throw new Exception("Бросок атаки не совершён!");
        }

        //Если попадание было критическим - должны быть нанесены критические повреждения
        if ((attackCheck.Result as RollResultWithCriticals).CriticalSuccess)
        {
            damageDefinition.ValueCalculation = new DamageRoll(true);
        }

        damageDefinition.CalculateResult();
        DamageRollResult damageResult = damageDefinition.Result as DamageRollResult;

        return(damageResult);
    }