示例#1
0
    //**************************************************
    private void DealDamage(GameObject target, float damage)
    {
        // Hit nothing or environment
        if (!target || target.layer == LayerMask.NameToLayer("Environment"))
        {
            return;
        }

        // Make sure target was not already damaged
        if (!hitTargets.Contains(target))
        {
            // Save target (root gameobject)
            hitTargets.Add(target);

            HealthBase targetHealth = target.GetComponent <HealthBase>();
            if (targetHealth)
            {
                if (!targetHealth.IsDead())
                {
                    // Damage target & play hitsounds
                    if (weaponBase)
                    {
                        //weaponBase.PlayHitSounds(targetHealth.ReceiveDamage(damage));
                        bool lethalDmg = targetHealth.ReceiveDamage(damage);
                        if (hitTargets.Count == 1)
                        {
                            weaponBase.PlayHitSounds(lethalDmg); // Play hitsound only once
                        }
                    }
                }
            }
        }
    }
示例#2
0
    public override void Fire()
    {
        if (playerCamera == null)
        {
            playerCamera = GetComponentInParent <Camera>();
        }

        if (!scope.Scoped())
        {
            animator.SetTrigger("Hip Fire");
        }

        // Check for impact. If present, continue.
        RaycastHit hit;

        if (!Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, Mathf.Infinity))
        {
            return;
        }

        HealthBase enemy = hit.collider.GetComponentInParent <HealthBase>();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }

        IBleedable target = hit.collider.GetComponentInParent <IBleedable>();

        if (target != null)
        {
            target.Bleed(hit.point, hit.normal);
        }
    }
示例#3
0
    public GameObject GetClosestEnemy(Collider[] Arr)
    {
        GameObject tMin       = null;
        float      minDist    = Mathf.Infinity;
        Vector3    currentPos = transform.position;

        foreach (Collider t in Arr)
        {
            if (t.gameObject != null && t.gameObject.tag == character2)
            {
                //                print("closet enemy = "+ t.gameObject.name);
                HealthBase hb = t.gameObject.GetComponent <HealthBase>();
                if (hb && !hb.GetDeath)
                {
                    float dist = Vector3.Distance(t.transform.position, currentPos);
                    if (dist < minDist)
                    {
                        tMin    = t.gameObject;
                        minDist = dist;
                    }
                }
            }
        }
        return(tMin);
    }
    private void DoShot(StateController controller, Vector3 direction, Vector3 hitPoint,
                        Vector3 hitNormal = default, bool organic = false, Transform target = null)
    {
        GameObject muzzleFlash = EffectManager.Instance.EffectOneShot((int)EffectList.flash, Vector3.zero);

        muzzleFlash.transform.localPosition    = Vector3.zero;
        muzzleFlash.transform.localEulerAngles = Vector3.left * 90.0f;
        DestroyDelayed destroyDelayed = muzzleFlash.AddComponent <DestroyDelayed>();

        destroyDelayed.DelayTime = 0.5f; // 자동 파괴

        GameObject shotTracer = EffectManager.Instance.EffectOneShot((int)EffectList.tracer, Vector3.zero);
        Vector3    origin     = controller.enemyAnimation.gunMuzzle.position;

        shotTracer.transform.rotation = Quaternion.LookRotation(direction);

        if (target && !organic)
        {
            GameObject bulletHole = EffectManager.Instance.EffectOneShot((int)EffectList.bulletHole, hitPoint + 0.1f * hitNormal);
            bulletHole.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitNormal);
            GameObject instantSpark = EffectManager.Instance.EffectOneShot((int)EffectList.sparks, hitPoint);
        }
        else if (target && organic)                                       // 플레이어
        {
            HealthBase targetHealth = target.GetComponent <HealthBase>(); // 플레이어 생명력
            if (targetHealth)
            {
                targetHealth.TakeDamage(hitPoint, direction, controller.classStats.BulletDamage,
                                        target.GetComponent <Collider>(), controller.gameObject);
            }
        }

        SoundManager.Instance.PlayShotSound(controller.classID, controller.enemyAnimation.gunMuzzle.position, 2.0f);
    }
示例#5
0
    IEnumerator FuseExplode()
    {
        yield return(new WaitForSeconds(fuse));

        Collider[] colliders = Physics.OverlapSphere(transform.position, radius);
        foreach (Collider c in colliders)
        {
            Rigidbody rb = c.GetComponentInParent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(power, transform.position, radius, lift);
            }

            HealthBase health = c.GetComponentInParent <HealthBase>();
            if (health != null)
            {
                health.TakeDamage(damage);
            }
        }

        GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.LookRotation(Vector3.up));

        Destroy(explosion, 10);

        Destroy(gameObject);
    }
示例#6
0
    public virtual void Attack(HealthBase targetHealth)
    {
        if (nextTimeReady > Time.time)
        {
            return;
        }

        targetHealth.AddHealth(-baseDamage, this);
        nextTimeReady = Time.time + cooldown;
    }
示例#7
0
    //**************************************************
    private void DealDamage(GameObject target, float damage)
    {
        HealthBase targetHealth = target.GetComponent <HealthBase>();

        if (targetHealth)
        {
            if (!targetHealth.IsDead())
            {
                // Damage target & play hitsounds
                PlayHitSounds(targetHealth.ReceiveDamage(damage));
            }
        }
    }
示例#8
0
    /// <summary>
    /// 실제 사격을 위한 함수
    /// </summary>
    /// <param name="stateController">Enemy</param>
    /// <param name="direction">사격 방향</param>
    /// <param name="hitPoint">총알이 맞는 위치(타겟의 위치와는 다름)</param>
    /// <param name="hitNormal"></param>
    /// <param name="organic">Bullet Hole을 표시할지 말지를 결정</param>
    /// <param name="target">타겟</param>
    private void DoShot(StateController controller, Vector3 direction, Vector3 hitPoint,
                        Vector3 hitNormal = default, bool organic = false, Transform target = null)
    {
        // 총알 발사 이펙트 생성 및 세팅
        GameObject muzzleFlash = EffectManager.Instance.EffectOneShot((int)EffectList.flash, Vector3.zero);

        muzzleFlash.transform.SetParent(controller.enemyAnimation.gunMuzzle);
        muzzleFlash.transform.localPosition    = Vector3.zero;
        muzzleFlash.transform.localEulerAngles = Vector3.left * 90f;
        DestroyDelayed destroyDelayed = muzzleFlash.AddComponent <DestroyDelayed>();

        destroyDelayed.DelayTime = 0.5f; // 0.5초 뒤에 자동으로 삭제

        // 총아 궤적 이펙트 생성 및 세팅
        GameObject shotTracer = EffectManager.Instance.EffectOneShot((int)EffectList.tracer, Vector3.zero);

        shotTracer.transform.SetParent(controller.enemyAnimation.gunMuzzle);
        Vector3 origin = controller.enemyAnimation.gunMuzzle.position;

        shotTracer.transform.position = origin;
        shotTracer.transform.rotation = Quaternion.LookRotation(direction);

        // 피탄 구멍 생성 여부 체크
        if (target && !organic)
        {
            GameObject bulletHole = EffectManager.Instance.EffectOneShot((int)EffectList.bulletHole,
                                                                         hitPoint + 0.01f * hitNormal);
            bulletHole.transform.rotation = Quaternion.FromToRotation(Vector3.up, hitNormal);

            GameObject instantSpark = EffectManager.Instance.EffectOneShot((int)EffectList.shotEffect, hitPoint);
        }
        else if (target && organic)                                       // == player
        {
            HealthBase targetHealth = target.GetComponent <HealthBase>(); // playerHealth
            if (targetHealth)
            {
                targetHealth.TakeDamage(hitPoint, direction, controller.classStats.BulletDamage,
                                        target.GetComponent <Collider>(), controller.gameObject); // maybe floating text
            }
        }

        // (현재 Enemy가 가진 무기 종류에 따라 사운드 재생)
        SoundManager.Instance.PlayShotSound(controller.classID,
                                            controller.enemyAnimation.gunMuzzle.position, 2f);
    }
示例#9
0
    public override void Fire()
    {
        if (playerCamera == null)
        {
            playerCamera = GetComponentInParent <Camera>();
        }

        // Check for impact. If present, continue. Inaccurate when not scoped in
        RaycastHit hit;

        if (scope.Scoped())
        {
            if (!Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, Mathf.Infinity))
            {
                return;
            }
        }
        else
        {
            animator.SetTrigger("Hip Fire");
            Vector3 randomPos = new Vector3(Random.Range(0, playerCamera.pixelWidth), Random.Range(0, playerCamera.pixelHeight), 0);
            Ray     ray       = playerCamera.ScreenPointToRay(randomPos);
            if (!Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                return;
            }
        }

        HealthBase enemy = hit.collider.GetComponentInParent <HealthBase>();

        if (enemy != null)
        {
            enemy.TakeDamage(damage);
        }

        IBleedable target = hit.collider.GetComponentInParent <IBleedable>();

        if (target != null)
        {
            target.Bleed(hit.point, hit.normal);
        }
    }
示例#10
0
    //animation event
    public void BladeAttackEvent()
    {
        Ray        ray = new Ray(mc.transform.position, mc.transform.forward);
        RaycastHit hit;

        //Debug.DrawRay(ray.origin, ray.direction * skillDataInstance.range, Color.red, 1f);
        if (Physics.Raycast(ray, out hit, skillDataInstance.range, skillDataInstance.targetLayer))
        {
            PlayRandomSkillAudio(skillDataInstance.hitClips);
            HealthBase hpObj = hit.transform.GetComponent <HealthBase>();
            Character  cc    = hit.transform.GetComponent <Character>();
            if (hpObj)
            {
                hpObj.TakeDamage(skillDataInstance.damage);                     //could be another chatacter or block
                ShowHitEffect(hit.transform.position, Quaternion.LookRotation(mc.transform.forward));
            }

            if (cc)
            {
                cc.Cmm.AddForce(skillDataInstance.knockForce, mc.transform.forward);
            }
        }
    }
示例#11
0
 /// <summary>Register service method implementations with a service binder. Useful when customizing the service binding logic.
 /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
 /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static void BindService(grpc::ServiceBinderBase serviceBinder, HealthBase serviceImpl)
 {
     serviceBinder.AddMethod(__Method_Check, serviceImpl.Check);
     serviceBinder.AddMethod(__Method_Watch, serviceImpl.Watch);
 }
示例#12
0
     // creates service definition that can be registered with a server
 #pragma warning disable 0618
     public static ServerServiceDefinition BindService(HealthBase serviceImpl)
 #pragma warning restore 0618
     {
         return(ServerServiceDefinition.CreateBuilder(__ServiceName)
                .AddMethod(__Method_Check, serviceImpl.Check).Build());
     }
示例#13
0
 /// <summary>Register service method with a service binder with or without implementation. Useful when customizing the  service binding logic.
 /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
 /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static void BindService(grpc::ServiceBinderBase serviceBinder, HealthBase serviceImpl)
 {
     serviceBinder.AddMethod(__Method_Check, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::GrpcProtocol.HealthCheckRequest, global::GrpcProtocol.HealthCheckResponse>(serviceImpl.Check));
     serviceBinder.AddMethod(__Method_Watch, serviceImpl == null ? null : new grpc::ServerStreamingServerMethod <global::GrpcProtocol.HealthCheckRequest, global::GrpcProtocol.HealthCheckResponse>(serviceImpl.Watch));
 }
示例#14
0
 /// <summary>Register service method with a service binder with or without implementation. Useful when customizing the  service binding logic.
 /// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
 /// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
 /// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
 public static void BindService(grpc::ServiceBinderBase serviceBinder, HealthBase serviceImpl)
 {
     serviceBinder.AddMethod(__Method_Check, serviceImpl == null ? null : new grpc::UnaryServerMethod <global::Grpc.Health.V1.HealthCheckRequest, global::Grpc.Health.V1.HealthCheckResponse>(serviceImpl.Check));
 }
示例#15
0
    public virtual bool WithinRange(HealthBase targetHealth)
    {
        float distanceNoY = Vector3.Distance(new Vector3(this.transform.position.x, 0, this.transform.position.z), new Vector3(targetHealth.transform.position.x, 0, targetHealth.transform.position.z));

        return(distanceNoY < attackRange);
    }
 /// <summary>Creates service definition that can be registered with a server</summary>
 public static ServerServiceDefinition BindService(HealthBase serviceImpl)
 {
     return(ServerServiceDefinition.CreateBuilder()
            .AddMethod(__Method_Check, serviceImpl.Check).Build());
 }
示例#17
0
    private HealthBase _health;                //The health variable is used as the health database where the health is stored.

    /// <summary>
    /// In the start function the health variable is initialized.
    /// </summary>
    void Start()
    {
        _health = GetComponent <HealthBase>();
    }
示例#18
0
 private void Awake()
 {
     hbase = FindObjectOfType <HealthBase>();
     hbase.OnHealthPCTChanged += HandleHealthPCTChanged;
     hbase.OnMaxHealthChanged += HandleMaxHealthChanged;
 }