public void OnDamage(int enemy_atk)
    {
        var damage = PlayerService.getDamage(enemy_atk);

        //Debug.Log("EnemyController: OnDamage: damage: " + damage);

        EffectService.damage(damage, transform.position);

        // ダメージがゼロならエフェクト発生のみで終了
        if (damage == 0)
        {
            return;
        }

        // ダメージあればHP減少処理
        var remain = PlayerService.OnDamage(damage);

        //Debug.Log("EnemyController: OnDamage: hp_dead_line: " + hp_dead_line);
        //Debug.Log("EnemyController: OnDamage: remain: " + remain);

        if (remain <= hp_dead_line)
        {
            OnDead();
            //Debug.Log("PlayerController::OnDamage : state : " + state.ToString());
            return;
        }

        var voice_name_damage = SeService.getPlayerDamageVoice();

        //MessageBroker.Default.Publish<PlaySe>(new PlaySe{ name = voice_name_damage });
        PlaySE(voice_name_damage);

        //animator.radioBool("Damage");
        AnimationChange("Damage");
    }
/*
 *  public void DebugCapsule(Vector3 start, Vector3 end, float radius) {
 *      debug_capsule.Add(new DebugCapsuleEntity {
 *          enable = true,
 *          position = start,
 *          end = end,
 *          radius = radius,
 *          draw_color_alpha = 1f,
 *          remaining_time = debug_remaining_time_default,
 *      });
 *  }
 */
    public void Hit()
    {
        //Debug.Log("PlayerController.Hit()");

        var check_start_offset = 0.3f;

        var check_max_distance = 1.5f;

        var check_radius = 0.1f;

        RaycastHit rayHit = default(RaycastHit);

        Ray ray = new Ray(
            transform.position +
            new Vector3(0f, 0.5f, 0f) +
            transform.forward * -check_start_offset,
            transform.forward
            );

        int layer_mask = (1 << LayerMask.NameToLayer("Enemy"));
        //int layer_mask = LayerMask.NameToLayer("Enemy");
        bool onhit = false;

        if (enemy_target != null)
        {
            var ec = enemy_target.GetComponent <EnemyController>();
            check_max_distance = ec.attack_distance + check_start_offset;

            //DebugCapsule(check_start, check_end, check_radius);
            //DebugSphere(ray, check_radius, check_max_distance);

            if (Physics.SphereCast(ray, check_radius, out rayHit, check_max_distance, layer_mask))
            {
                Debug.Log("Physics.CheckCapsule hit");
                onhit = true;
            }
            else
            {
                Debug.Log("Physics.SphereCast not hit");
            }
        }

        if (onhit)
        {
            var se_name = SeService.getPlayerAttack(EquipService.rank(), EquipService.type());
            //MessageBroker.Default.Publish<PlaySe>(new PlaySe{ name = se_name });
            PlaySE(se_name);

            rayHit.transform.SendMessage("OnDamage", PlayerService.atk_total());
        }
        else
        {
            // miss
            if (enemy_target != null)
            {
                enemy_target.transform.SendMessage("OnMiss");
            }
        }
    }
Ejemplo n.º 3
0
    public void Hit()
    {
        //Debug.Log("PlayerController.Hit()");
        var check_start_offset = 0.3f;

        var check_max_distance = 1.5f;

        var check_radius = 0.1f;

        RaycastHit rayHit;

        Ray ray = new Ray(
            transform.position +
            new Vector3(0f, 0.5f, 0f) +
            transform.forward * -check_start_offset,
            transform.forward
            );


        int  layer_mask = (1 << LayerMask.NameToLayer("Player"));
        bool onhit      = false;

        if (Physics.SphereCast(ray, check_radius, out rayHit, check_max_distance, layer_mask))
        {
            //if (Physics.Raycast(ray, out rayHit, attack_distance, layer_mask)) {
            //Debug.Log("EnemyController.Hit: " + rayHit.transform.tag);
            if (rayHit.transform.tag == "Player")
            {
                onhit = true;
            }
            else
            if (rayHit.transform.tag == "PlayerDead")
            {
                DoIdleMode();
                return;
            }
        }

        if (onhit)
        {
            var se_name = SeService.getEnemyAttack(entity.rank);
            MessageBroker.Default.Publish <PlaySe>(new PlaySe {
                name = se_name
            });

            rayHit.transform.SendMessage("OnDamage", entity.atk);
            //Debug.Log("OnDamage: " + entity.atk);
        }
        else
        {
            // miss
            PlayerService.OnMiss();
            //Debug.Log("OnMiss");
        }
    }
    public void OnDead()
    {
        state             = State.Dead;
        character_control = false;
        nmAgent.ResetPath();

        var voice_name_dead = SeService.getPlayerDeadVoice();

        MessageBroker.Default.Publish <PlaySe>(new PlaySe {
            name = voice_name_dead
        });

        transform.tag = "PlayerDead";
        //animator.radioBool("Die");
        MessageBroker.Default.Publish <PlayerDead>(new PlayerDead {
        });
        //Debug.Log("Publish: PlayerDead");

        PlayerService.game_over();
        EffectService.nextRoomOff();
    }
    void OnAttack()
    {
/*
 *      if (!animator.GetBool("DoAttack")) {
 *          animator.SetBool("DoAttack", true);
 *      }
 */

        if (on_attack)
        {
            return;
        }
        on_attack = true;

        character_control = false;

        //Debug.Log("PlayerController.OnIdle()");
        //animator.radioBool("Attack");
        AnimationChange("Attack");
        //animator.SetBool("DoIdle", true);
        animator.Update(0);
        AnimatorClipInfo[] anim_clip_info = animator.GetCurrentAnimatorClipInfo(0);
        //Debug.Log("PlayerController : anim_clip_info[0].clip.length : " + (anim_clip_info[0].clip.length).ToString());

        int spd = PlayerService.spd_total();

        //Debug.Log("PlayerController : spd before : " + spd.ToString());

        spd = (max_attack_speed < spd) ? max_attack_speed : spd;
        spd = (spd < 1) ? 1 : spd;
        //Debug.Log("PlayerController : spd after : " + spd.ToString());

        float attack_spd = (((attack_speed * 1f) - (spd * 1f)) / (attack_speed * 1f)) * EquipService.attack_speed_adjust();

        //Debug.Log("PlayerController : attack_speed : " + attack_speed.ToString());
        //Debug.Log("PlayerController : spd : " + spd.ToString());
        //Debug.Log("PlayerController : (attack_speed - spd) / attack_speed : " + ((attack_speed - spd) / attack_speed).ToString());
        //Debug.Log("PlayerController : attack_spd : " + attack_spd.ToString());

        animator.SetFloat("AttackSpeed", attack_spd);

        //animator.Play("Idle2", 0, 0f);
        //Debug.Log("PlayerController::OnAttack() anim_clip_info[0].clip.length: " + anim_clip_info[0].clip.length.ToString());

        Observable.Timer(TimeSpan.FromSeconds(anim_clip_info[0].clip.length))
        .Subscribe(t => {
            //animator.radioBool("Idle");
            AnimationChange("Idle");
            character_control = true;
            on_attack         = false;
        });
        //.Subscribe(t => animator.SetBool("DoIdle", false));

/*
 *      animator.Play("Attack",
 *          nextFrameAction: () => {
 *              //Debug.Log("再生開始の次フレーム");
 *          },
 *          endAction: () => {
 *              //Debug.Log("アニメーション終了");
 *              animator.radioBool("Idle");
 *              character_control = true;
 *          });
 */
        var voice_name_attack = SeService.getPlayerAttackVoice();

        //MessageBroker.Default.Publish<PlaySe>(new PlaySe{ name = voice_name_attack });
        PlaySE(voice_name_attack);
    }