コード例 #1
0
ファイル: PlayerController.cs プロジェクト: wolfrug/ldjam42
    public IEnumerator Attack(EnemyController enemy)
    {
        Debug.Log("Player is Attacking " + enemy.gameObject.name);
        isMoving_ = true;
        ActiveEntity enemyStats = enemy.GetComponentInParent <ActiveEntity>();

        // Attempt attack!
        float attackRoll  = Random.Range(0f, 1f);
        int   damage      = playerStats_.damage_;
        int   armorPierce = playerStats_.armorPiercing_;

        // Critical hit?!
        if (enemyStats.AttemptCritical(attackRoll, playerStats_.criticalChance_))
        {
            damage     *= 2;
            armorPierce = (armorPierce + 1) * 2;
            enemyStats.AttemptDoDamage(damage, armorPierce);
            characterAnimator_.SetTrigger("Critical");
            enemy.characterAnimator_.SetTrigger("Stumble");
            player_Attack.Invoke(enemy, "Critical");
        }
        else
        {
            if (!enemyStats.AttemptDodge(attackRoll + playerStats_.attackRating_))
            {
                enemyStats.AttemptDoDamage(damage, armorPierce);
                characterAnimator_.SetTrigger("Swing");
                enemy.characterAnimator_.SetTrigger("Stumble");
                player_Attack.Invoke(enemy, "Hit");
            }
            else
            {
                characterAnimator_.SetTrigger("Swing");
                enemy.characterAnimator_.SetTrigger("Dodge");
                player_Attack.Invoke(enemy, "Dodge");
            }
        };
        if (enemyStats.health <= 0)
        {
            enemy.Die((playerObj_.transform.position - enemy.transform.position).normalized);
            PlayerManager.instance_.AddXP(enemyStats.reference_);
        }

        yield return(new WaitForSeconds(0.5f));

        EndTurn();
        isMoving_ = false;
    }
コード例 #2
0
    void OnTriggerEnter(Collider coll)
    {
        //Debug.Log("Collided with " + coll.gameObject.name);
        ActiveEntity entity = coll.gameObject.GetComponentInParent <ActiveEntity>();

        if (entity != null)
        {
            if (entity.health > 0)
            {
                entity.AttemptDoDamage(999, 999);
                if (entity.playerController_ != null)
                {
                    entity.playerController_.Die(Vector3.zero);
                }
                else if (entity.enemyController_ != null)
                {
                    entity.enemyController_.Die(Vector3.zero);
                }
            }
            ;
        }
    }