コード例 #1
0
        protected virtual void CheckHurtables()
        {
            if (hitHurtables.Count > 0)
            {
                for (int i = 0; i < hitHurtables.Count; i++)
                {
                    IHurtable ih = hitHurtables[i].GetComponent <IHurtable>();
                    if (ignoreList.Contains(ih))
                    {
                        continue;
                    }
                    switch (hitInfo.forceRelation)
                    {
                    case HitboxForceRelation.ATTACKER:
                        ih.Hurt(directionOwner.position, directionOwner.forward, directionOwner.right, hitInfo);
                        break;

                    case HitboxForceRelation.HITBOX:
                        ih.Hurt(transform.position, transform.forward, transform.right, hitInfo);
                        break;

                    case HitboxForceRelation.WORLD:
                        ih.Hurt(transform.position, Vector3.forward, Vector3.right, hitInfo);
                        break;
                    }
                    ignoreList.Add(ih);
                    OnHurt?.Invoke(hitHurtables[i], hitInfo);
                }
            }
        }
コード例 #2
0
    /// <summary>
    /// Handles applying damage, knockback, and other effects when a player is hit
    /// </summary>
    /// <param name="origin"> Location the hit originated from </param>
    /// <param name="target"> Object hit </param>
    /// <param name="extraData"> Extra data to be passed on to other supporting functions </param>
    protected void Hit(Vector3 origin, Vector3 contactPoint, GameObject target, object extraData = null, bool activateTriggers = true)
    {
        IHurtable hurtable = (IHurtable)target.GetComponentInParent(typeof(IHurtable)); // Check if target is a player

        if (hurtable != null)
        {
            float damage = GetDamageDealt(origin, extraData);
            //Debug.Log("Damage is " + damage);
            if (target.CompareTag("Player"))
            {
                PlayerController targetPlayerController = target.GetComponent <PlayerController>(); // Check if target is a player
                OnHit(origin, contactPoint, targetPlayerController, extraData);                     // Activate OnHit effects and get damage dealt

                if (damage > 0)
                {
                    targetPlayerController.Hurt(player, damage);      // Hurt hit player
                }
                Knockback(origin, targetPlayerController, extraData); // Knockback hit player

                if (activateTriggers)
                {
                    player.OnHit.Invoke(origin, contactPoint - origin, targetPlayerController);
                }
            }
            else
            {
                hurtable.Hurt(player, damage);
            }
        }
        if (activateTriggers)
        {
            player.OnHit.Invoke(origin, contactPoint - origin, null);
        }
    }
コード例 #3
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        IHurtable hurtableEntity = collision.collider.GetComponent <IHurtable> ();

        if (hurtableEntity != null)
        {
            hurtableEntity.Hurt(damage);
        }
    }
コード例 #4
0
    public void OnTriggerEnter(Collider other)
    {
        IHurtable hurtableObject = other.GetComponent <IHurtable>();

        if (hurtableObject != null)
        {
            hurtableObject.Hurt(_settings.HurtValue);
        }

        Destroy(gameObject);
    }
コード例 #5
0
        public void ApplySkill(IHurtable hurtable, ProjectType projectType, RequiredTechType techType)
        {
            if (Random.Range(0f, 1f) > Accuracy)
            {
                OnSkillMissed(this);
            }
            else
            {
                double critical = 1;
                if (IsTriggerable == false)
                {
                    DebugLogger.LogWarningFormat("ActiveSkill::ApplySkill => Skill '{0}'의 쿨타임이 {1} 남아있는 상태에서 발동되려고 합니다.", Information.Name, RemainingCooldown);
                }
                if (UnityEngine.Random.Range(0, 1) > Information.CriticalProbability)
                {
                    critical += Information.CriticalRatio;
                }

                hurtable.Hurt((int)(CalculateDamage(projectType, techType) * critical));

                RemainingCooldown = DefaultCooldown;
            }
        }
コード例 #6
0
    private IEnumerator Attack(int index)
    {
        states [index] = EnemyState.Attack;
        Vector2 attackPoint   = targetPosition;
        Vector2 startPosition = motors [index].position;

        float duration = types[index].attackDuration;
        float timer    = 0;

        while (timer < duration)
        {
            if (states [index] == EnemyState.Attack)
            {
                motors [index].position = Vector2.Lerp(startPosition, attackPoint, timer / duration);
                timer += Clock.deltaTime;
                yield return(null);
            }
            else
            {
                yield break;
            }
        }

        foreach (Collider2D other in Physics2D.OverlapCircleAll(attackPoint, attackHitRadius, goodGuysLayerMask))
        {
            IHurtable hurtableThing = other.GetComponent <IHurtable> ();
            if (hurtableThing != null)
            {
                hurtableThing.Hurt(types [index].power);
            }
        }

        yield return(new WaitForSeconds(types [index].attackCooldown));

        states [index] = EnemyState.Charge;
    }
コード例 #7
0
 protected override void HurtHurtable(IHurtable ih)
 {
     ih.Hurt(BuildHurtInfo());
 }
コード例 #8
0
 protected virtual void HurtHurtable(IHurtable ih)
 {
     ih.Hurt(BuildHurtInfo());
 }