Ejemplo n.º 1
0
    public override ACTION_RESULT ActionUpdate()
    {
        if (player.dying)
        {
            Debug.Log("DON'T ATTACK PLAYER", Department.PLAYER, Color.ORANGE);
            return(ACTION_RESULT.AR_FAIL); //Player is dead, don't attack
        }

        if (state == BWA_STATE.PRE_APPLY && GetComponent <CompAnimation>().IsAnimOverXTime(apply_damage_point))
        {
            anim.SetClipDuration("WideAttack", (attack_duration / (1.0f - apply_damage_point)));

            state = BWA_STATE.POST_APPLY;

            int enemy_tile_x = move.GetCurrentTileX();
            int enemy_tile_y = move.GetCurrentTileY();

            movement_ctrl.GetPlayerPos(out int player_tile_x, out int player_tile_y);
            audio.PlayEvent("BossSwordSwing");

            switch (move.GetDirection())
            {
            case Movement_Action.Direction.DIR_WEST:
                if ((enemy_tile_x - 1 == player_tile_x || enemy_tile_x == player_tile_x) && (player_tile_y == enemy_tile_y || player_tile_y == enemy_tile_y - 1 || player_tile_y == enemy_tile_y + 1))
                {
                    characters_manager.GetDamage(damage);
                }
                break;

            case Movement_Action.Direction.DIR_EAST:
                if ((enemy_tile_x + 1 == player_tile_x || enemy_tile_x == player_tile_x) && (player_tile_y == enemy_tile_y || player_tile_y == enemy_tile_y - 1 || player_tile_y == enemy_tile_y + 1))
                {
                    characters_manager.GetDamage(damage);
                }
                break;

            case Movement_Action.Direction.DIR_NORTH:
                if ((enemy_tile_y - 1 == player_tile_y || enemy_tile_y == player_tile_y) && (player_tile_x == enemy_tile_x || player_tile_x == enemy_tile_x - 1 || player_tile_x == enemy_tile_x + 1))
                {
                    characters_manager.GetDamage(damage);
                }
                break;

            case Movement_Action.Direction.DIR_SOUTH:
                if ((enemy_tile_y + 1 == player_tile_y || enemy_tile_y == player_tile_y) && (player_tile_x == enemy_tile_x || player_tile_x == enemy_tile_x - 1 || player_tile_x == enemy_tile_x + 1))
                {
                    characters_manager.GetDamage(damage);
                }
                break;
            }
        }
        else if (state == BWA_STATE.POST_APPLY && anim.IsAnimationStopped("WideAttack"))
        {
            state = BWA_STATE.WAITING;
            return(ACTION_RESULT.AR_SUCCESS);
        }
        return(ACTION_RESULT.AR_IN_PROGRESS);
    }
    public override bool ActionStart()
    {
        interupt = false;

        /*CompAudio audio = GetComponent<CompAudio>();
         * audio.PlayEvent("Enemy2_Hurt");
         * audio.PlayEvent("SwordHit");*/
        move       = GetComponent <Movement_Action>();
        anim_comp  = GetComponent <CompAnimation>();
        audio_comp = GetComponent <CompAudio>();


        if (next_dmg_type == Enemy_BT.ENEMY_GET_DAMAGE_TYPE.DEFAULT)
        {
            int tile_x              = move.GetCurrentTileX();
            int tile_y              = move.GetCurrentTileY();
            int player_x            = tile_x;
            int player_y            = tile_y;
            MovementController temp = GetLinkedObject("player_obj").GetComponent <MovementController>();
            if (temp != null)
            {
                temp.GetPlayerPos(out int x, out int y);
                player_x = x;
                player_y = y;
            }

            int dif_x = player_x - tile_x;
            int dif_y = player_y - tile_y;

            Movement_Action.Direction dir = move.GetDirection();

            switch (dir)
            {
            case Movement_Action.Direction.DIR_EAST:
                if (dif_x < 0)
                {
                    animation_clip = "HitBack";
                    anim_comp.PlayAnimationNode("HitBack");
                }
                else if (dif_x > 0)
                {
                    animation_clip = "HitFront";
                    anim_comp.PlayAnimationNode("HitFront");
                }
                else if (dif_y < 0)
                {
                    animation_clip = "HitLeft";
                    anim_comp.PlayAnimationNode("HitLeft");
                }
                else if (dif_y > 0)
                {
                    animation_clip = "HitRight";
                    anim_comp.PlayAnimationNode("HitRight");
                }
                break;

            case Movement_Action.Direction.DIR_NORTH:
                if (dif_x < 0)
                {
                    animation_clip = "HitLeft";
                    anim_comp.PlayAnimationNode("HitLeft");
                }
                else if (dif_x > 0)
                {
                    animation_clip = "HitRight";
                    anim_comp.PlayAnimationNode("HitRight");
                }
                else if (dif_y < 0)
                {
                    animation_clip = "HitFront";
                    anim_comp.PlayAnimationNode("HitFront");
                }
                else if (dif_y > 0)
                {
                    animation_clip = "HitBack";
                    anim_comp.PlayAnimationNode("HitBack");
                }
                break;

            case Movement_Action.Direction.DIR_SOUTH:
                if (dif_x < 0)
                {
                    animation_clip = "HitRight";
                    anim_comp.PlayAnimationNode("HitRight");
                }
                else if (dif_x > 0)
                {
                    animation_clip = "HitLeft";
                    anim_comp.PlayAnimationNode("HitLeft");
                }
                else if (dif_y < 0)
                {
                    animation_clip = "HitBack";
                    anim_comp.PlayAnimationNode("HitBack");
                }
                else if (dif_y > 0)
                {
                    animation_clip = "HitFront";
                    anim_comp.PlayAnimationNode("HitFront");
                }
                break;

            case Movement_Action.Direction.DIR_WEST:
                if (dif_x < 0)
                {
                    animation_clip = "HitFront";
                    anim_comp.PlayAnimationNode("HitFront");
                }
                else if (dif_x > 0)
                {
                    animation_clip = "HitBack";
                    anim_comp.PlayAnimationNode("HitBack");
                }
                else if (dif_y < 0)
                {
                    animation_clip = "HitRight";
                    anim_comp.PlayAnimationNode("HitRight");
                }
                else if (dif_y > 0)
                {
                    animation_clip = "HitLeft";
                    anim_comp.PlayAnimationNode("HitLeft");
                }
                break;
            }
        }

        else if (next_dmg_type == Enemy_BT.ENEMY_GET_DAMAGE_TYPE.FIREWALL)
        {
            animation_clip = "HitFire";
            anim_comp.PlayAnimationNode("HitFire");
        }

        anim_comp.SetClipDuration(animation_clip, duration);
        //TODO_AI: Hurt audio
        //GetComponent<CompAudio>().PlayEvent("JaimeHurt");
        return(true);
    }