public void BuildingTakeDamage(MobHandler MH)
 {
     if (MH)
     {
         _health.TakeDamage(MH.gameObject, MH.Damage);
         Debug.Log(_health.CurrentHealth);
         Debug.Log(_health.MaxHealth);
         var p = (float)_health.CurrentHealth / _health.MaxHealth;
         Debug.Log(p);
         _renderer.material.SetFloat("_Health", p);
         MH.RemoveMob();
     }
 }
Beispiel #2
0
    public void HitTarget()
    {
        HealthHandler h = _target.GetComponent <HealthHandler>();

        h.TakeDamage(_owner.gameObject, _damage);
        if (h.CurrentHealth <= 0)
        {
            _target   = null;
            _tracking = false;
            delta     = 0f;
        }
        Destroy(gameObject);
    }
Beispiel #3
0
    public void DamageTarget(Collider2D collider)
    {
        if (collider == null || collider == weaponCollider)
        {
            return;
        }

        HealthHandler healthHandler = collider.GetComponent <HealthHandler>();

        if (!healthHandler)
        {
            return;
        }

        healthHandler.TakeDamage(weaponDamage);
    }
        public override void DoEffect(Transform startPoint, Transform target)
        {
            Vector3       forceVector   = (target.position - startPoint.position).normalized * force;
            HealthHandler healthHandler = target.transform.root.GetComponentInChildren <HealthHandler>();

            if (healthHandler)
            {
                healthHandler.TakeDamage(damage, forceVector);
            }
            RigidbodyHolder rigidbodyHolder = target.transform.root.GetComponentInChildren <RigidbodyHolder>();

            Rigidbody[] rigidbodies = null;
            if (rigidbodyHolder)
            {
                rigidbodies = rigidbodyHolder.AllRigs;
                foreach (Rigidbody rigidbody in rigidbodies)
                {
                    WilhelmPhysicsFunctions.AddForceWithMinWeight(rigidbody, forceVector, ForceMode.Impulse, 0f);
                }
            }
        }
Beispiel #5
0
    // Update is called once per frame
    public void Update()
    {
        var distance = (transform.position - killObject.transform.position).magnitude;

        if (distance < .25)
        {
            killObject.BuildingTakeDamage(this);
            return;
        }
        if (Structures.currentScan > scanIndex)
        {
            print("Repath!");
            _seeker.StartPath(transform.position, killObject.transform.position, OnPathComplete);
            scanIndex    = Structures.currentScan;
            targetAttack = null;
            status       = 0;
        }
        delta += Time.deltaTime;
        if (_animator != null)
        {
            _animator.SetFloat("X", _aiPath.velocity.x);
            _animator.SetFloat("Y", _aiPath.velocity.y);
        }
        switch (status)
        {
        case 0:
            if (!debounce)
            {
                debounce = true;

                if (delta >= 1f)
                {
                    delta = 0f;
                    GraphNode node1 = AstarPath.active.GetNearest(transform.position, NNConstraint.Default).node;
                    GraphNode node2 = AstarPath.active.GetNearest(killObject.transform.position, NNConstraint.Default).node;
                    if (!PathUtilities.IsPathPossible(node1, node2))
                    {
                        status = 1;
                    }
                }
                debounce = false;
            }
            break;

        case 1:
            if (!debounce)
            {
                debounce = true;
                if (_aiPath.velocity == Vector3.zero)
                {
                    if (targetAttack == null)
                    {
                        targetAttack = Structures.GetNearest(transform.position);

                        delta = 0f;
                    }
                    if (targetAttack != null && delta >= 1f)
                    {
                        HealthHandler _health = targetAttack.GetComponent <HealthHandler>();
                        _health.TakeDamage(gameObject, Damage);
                        delta = 0f;
                    }
                }
                debounce = false;
            }
            break;

        default:
            break;
        }
    }
Beispiel #6
0
 /// <summary>
 /// Take damage from Player
 /// </summary>
 /// <param name="val">damage values</param>
 public void TakeDamage(int val)
 {
     health.TakeDamage(val);
 }
Beispiel #7
0
    public void DealDamage(GameObject col)
    {
        if (col.layer == 9 || col.layer == 10)         //9 = Player / 10 = Enemy
        {
            //Save that a target has been hit
            targetsHit++;

            //Push the target back based on the received position
            //col.rigidbody.AddForce((col.transform.position - position).normalized * force, ForceMode.Impulse);

            //Grabs the targets HealthHandler and deal damage (if one exists)
            healthHandler = col.GetComponent <HealthHandler>();
            if (healthHandler != null)
            {
                totalDamage = damage + damageBonus;
                if (favoredTargetStatus != Lists.Status.None)
                {
                    if (healthHandler.afflictedStatus.Contains(favoredTargetStatus))
                    {
                        totalDamage *= GlobalVars.bonusDamageMultiplier;
                    }
                }
                healthHandler.TakeDamage(totalDamage);
                if (countCombo)
                {
                    ComboHandler.Instance.AddCombo();
                }

                if (applyStatus != Lists.Status.None)
                {
                    switch (applyStatus)
                    {
                    case Lists.Status.DOTed:
                        healthHandler.ApplyDot(totalDamage * 0.2f);
                        break;

                    case Lists.Status.Feared:
                        healthHandler.ApplyFear(statusDuration);
                        break;

                    case Lists.Status.Rooted:
                        healthHandler.ApplyRoot(statusDuration);
                        break;

                    case Lists.Status.Silenced:
                        healthHandler.ApplySilence(statusDuration);
                        break;

                    case Lists.Status.Slowed:
                        healthHandler.ApplySlow(statusDuration);
                        break;

                    case Lists.Status.Stunned:
                        break;
                    }
                }
            }

            //Checks for slow motion effect

            /*
             * if (slowMotion)
             * {
             *      if (targetsHit >= slowMotionReq)
             *              EffectsHandler.Call.SlowTime();
             * }
             *
             * //Checks for camera shaking
             * if (shakeCamera)
             *      EffectsHandler.ShakeCamera(shakeCameraIntensity);*/
        }
    }