Exemplo n.º 1
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);
        }
    }
Exemplo n.º 2
0
 /// <summary>
 /// Do the actual hit.
 /// </summary>
 /// <param name="other">Other.</param>
 override protected bool DoHit(Collider2D other)
 {
     // Simple projectiles can hit only one thing
     if (!hasHitCharacter && enabled)
     {
         IHurtable hurtBox = (IHurtable)other.gameObject.GetComponent(typeof(IHurtable));
         // Got a hurt box and its not ourselves
         if (hurtBox != null && !hasHitCharacter && hurtBox.Mob != character)
         {
             if (projectile != null && destroyOnEnemyHit)
             {
                 projectile.DestroyProjectile(true);
             }
             damageInfo.Direction = transform.position - other.transform.position;
             hurtBox.Damage(damageInfo);
             if (!allowMultiHit)
             {
                 hasHitCharacter = true;
             }
             return(true);
         }
         else
         {
             if (projectile != null && destroyOnSceneryHit)
             {
                 projectile.DestroyProjectile(false);
             }
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 public void Damage(IHurtable target)
 {
     if (target.Tag == TargetTag)
     {
         target.GetHurt(damage);
     }
 }
Exemplo n.º 4
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);
                }
            }
        }
Exemplo n.º 5
0
    public override void OnHitTrigger(AttackObject attackObject, IHurtable entity)
    {
        base.OnHitTrigger(attackObject, entity);

        if (entity.GetEntity().Body.mIsKinematic || entity.GetEntity().abilityFlags.GetFlag(AbilityFlag.Heavy))
        {
            return;
        }

        if (entity.GetEntity() is Enemy enemy)
        {
            enemy.mEnemyState = EnemyState.Jumping;
        }

        if (entity.GetEntity() is Player player)
        {
            player.movementState = MovementState.Knockback;
        }

        Vector2 knockbackVector;

        if (entity.GetEntity().Body.mPS.pushesBottom)
        {
            knockbackVector = Vector2.right * attackObject.direction.x + Vector2.up * 0.5f;
        }
        else
        {
            knockbackVector = attackObject.direction;
        }

        entity.GetEntity().Body.mSpeed = knockbackVector.normalized * 500;
    }
Exemplo n.º 6
0
 /// <summary>
 /// Do the actual hit.
 /// </summary>
 /// <param name="other">Other.</param>
 override protected bool DoHit(Collider2D other)
 {
     if (character.Velocity.y < 0 || character.PreviousVelocity.y < 0)
     {
         if (base.DoHit(other))
         {
             DoBobble();
             StartCoroutine(ResetCollider());
             return(true);
         }
         return(false);
     }
     if (kickHidingEnemies)
     {
         IHurtable hurtBox = (IHurtable)other.gameObject.GetComponent(typeof(IHurtable));
         // Got a hurt box and its not ourselves
         if (hurtBox != null && !hasHitCharacter && hurtBox.Mob is Enemy && ((Enemy)hurtBox.Mob).State == EnemyState.HIDING)
         {
             damageInfo.Direction = transform.position - other.transform.position;
             hurtBox.Damage(damageInfo);
             hasHitCharacter = true;
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Kill the IHurtable which intersected with this bullet.
 /// </summary>
 /// <param name="i_Hurtable">IHurtable which intersected with this bullet.</param>
 public void Kill(IHurtable i_Hurtable)
 {
     i_Hurtable.GotHurt(this);
     if ((i_Hurtable is HurtableBullet) && (m_random.Next(100) < sr_chanceToBeDestroyedByBullet))
     {
         Destroy(0);
     }
 }
Exemplo n.º 8
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        IHurtable hurtableEntity = collision.collider.GetComponent <IHurtable> ();

        if (hurtableEntity != null)
        {
            hurtableEntity.Hurt(damage);
        }
    }
Exemplo n.º 9
0
 /// <summary>
 /// Acting for touching intersection.
 /// </summary>
 /// <param name="i_Touched">The touched object.</param>
 /// <param name="i_Toucher">The toucher object.</param>
 /// <param name="i_IntersectionPoints">All of the intersection points.</param>
 private void actForHurtableIntersection(IHurtable i_Touched, IHurtable i_Toucher, List <Vector2> i_IntersectionPoints)
 {
     if (i_Touched.HurtInCase.HasFlag(eHurtInCase.Touch))
     {
         if (i_Touched != i_Toucher)
         {
             i_Touched.GotHurt(i_Toucher, i_IntersectionPoints);
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Acting for attacker intersection.
 /// </summary>
 /// <param name="i_Attacker">The attacker object.</param>
 /// <param name="i_Hurtable">The object that will be hurt cause the attacker.</param>
 private void actForAttackerIntersection(IAttacker i_Attacker, IHurtable i_Hurtable)
 {
     if (i_Hurtable.HurtInCase.HasFlag(eHurtInCase.Attack))
     {
         if (i_Attacker.SelfTeam != i_Hurtable.SelfTeam)
         {
             i_Attacker.Kill(i_Hurtable);
         }
     }
 }
Exemplo n.º 11
0
    public override void OnHitTrigger(AttackObject attackObject, IHurtable entity)
    {
        base.OnHitTrigger(attackObject, entity);
        if (Random.Range(0, 100) > procChance)
        {
            return;
        }

        ((Player)owner).GainLife(attackObject.attack.GetDamage() * (lifeGainPercent / 100));
    }
Exemplo n.º 12
0
        protected override bool ShouldHurt(IHurtable ih)
        {
            EntityTeams thisTeam = (EntityTeams)team;

            // Entity is part of our team.
            if (thisTeam.HasFlag((EntityTeams)ih.GetTeam()))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 13
0
    public void OnTriggerEnter(Collider other)
    {
        IHurtable hurtableObject = other.GetComponent <IHurtable>();

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

        Destroy(gameObject);
    }
Exemplo n.º 14
0
    public override void OnHitTrigger(AttackObject attackObject, IHurtable entity)
    {
        base.OnHitTrigger(attackObject, entity);

        int random = Random.Range(0, 100);

        if (random <= procChance)
        {
            StatusEffect effect = ScriptableObject.Instantiate(statusEffect);
            effect.OnApplyEffect(owner);
        }
    }
 public static void Split(Projectile original, IHurtable hit)
 {
     /*
      * RangedAttack rattack = new RangedAttack(original.owner, 0.5f, 50, 0, 1, 0, original.projProto, Vector2.zero, new List<WeaponAbility>());
      * Projectile shot = new Projectile(original.projProto, rattack, original.direction + new Vector2(-0.5f, 0.5f));
      * shot.hitbox.mDealtWith.Add(hit);
      * shot.Spawn(original.Position);
      *
      * RangedAttack rattack2 = new RangedAttack(original.owner, 0.5f, 50, 0, 1, 0, original.projProto, Vector2.zero, new List<WeaponAbility>());
      * Projectile shot2 = new Projectile(original.projProto, rattack2, original.direction + new Vector2(0.5f, 0.5f));
      * shot2.hitbox.mDealtWith.Add(hit);
      * shot2.Spawn(original.Position);
      */
 }
Exemplo n.º 16
0
        /// <summary>
        /// Do the actual hit.
        /// </summary>
        /// <param name="other">Other.</param>
        override protected bool DoHit(Collider2D other)
        {
            // Simple projectiles can hit only one thing
            if (!hasHitCharacter && enabled)
            {
                IHurtable hurtBox = (IHurtable)other.gameObject.GetComponent(typeof(IHurtable));
                // Got a hurt box and its not ourselves
                if (hurtBox != null && !hasHitCharacter && hurtBox.Mob != character)
                {
                    if (projectile != null && destroyOnEnemyHit)
                    {
                        projectile.DestroyProjectile(true);
                    }
                    damageInfo.Direction = transform.position - other.transform.position;
                    hurtBox.Damage(damageInfo);
                    if (!allowMultiHit)
                    {
                        hasHitCharacter = true;
                    }
                    if (character is Character)
                    {
                        ((Character)character).HitEnemy(hurtBox.Mob, damageInfo);
                    }
                    return(true);
                }
                else
                {
                    if (hurtBox == null && projectile != null && destroyOnSceneryHit)
                    {
                        projectile.DestroyProjectile(false);
                    }
                    // TODO: Ideally this shouldn't be here but on something related to grappling hook projectile
                    if (projectile is GrapplingHookProjectile)
                    {
                        if (((GrapplingHookProjectile)projectile).shouldParent)
                        {
                            projectile.gameObject.transform.parent = other.gameObject.transform;
#if UNITY_EDITOR
                            if (other.gameObject.transform.lossyScale != Vector3.one)
                            {
                                Debug.LogWarning("Grapple with shouldParent==true requires that all the colliders it collides with have a GameObject scale of (1,1,1) due to Unity bug with parenting to non-uniform colliders. Instead of scaling your game objects set the size on the collider and leave the scale at (1,1,1).");
                            }
#endif
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 17
0
 public override void OnHealTrigger(IHurtable player, int heals)
 {
     base.OnHealTrigger(player, heals);
     foreach (Player ally in CrewManager.instance.players)
     {
         if (ally == null)
         {
             continue;
         }
         if (ally != player)
         {
             ally.GainLife(heals * (sharePercent / 100), true);
         }
     }
 }
        /// <summary>
        /// Checks for jumping on head.
        /// </summary>
        /// <returns><c>true</c>, if character is jumping on an enmies head.</returns>
        virtual protected bool CheckForJumpOnHead()
        {
            if (character.Velocity.y >= 0)
            {
                return(false);
            }
            IHurtable enemyHurtBox = CheckCollisions(RaycastType.FOOT);

            if (enemyHurtBox == null)
            {
                return(false);
            }
            this.enemyHurtBox = enemyHurtBox;
            waitingToJump     = true;
            return(true);
        }
Exemplo n.º 19
0
		/// <summary>
		/// Do the actual hit.
		/// </summary>
		/// <param name="other">Other.</param>
		/// <returns>true if a hit was done.</returns>
		virtual protected bool DoHit(Collider2D other)
		{
			IHurtable hurtBox = (IHurtable) other.gameObject.GetComponent(typeof(IHurtable));
			if (character == null) Debug.LogWarning("Tried to DoHit() but no character has been set");
			// Got a hurt box and its not ourselves
			if (hurtBox != null && !hasHitCharacter && hurtBox.Mob != character )
			{
				damageInfo.Direction = transform.position - other.transform.position;
				damageInfo.DamageCauser = character;
				hurtBox.Damage(damageInfo);
				if (character is Character) ((Character)character).HitEnemy(hurtBox.Mob, damageInfo);
				hasHitCharacter = true;
				return true;
			}
			return false;
		}
Exemplo n.º 20
0
 public void CheckDetection()
 {
     if (hitHurtables.Count > 0)
     {
         for (int i = 0; i < hitHurtables.Count; i++)
         {
             IHurtable ih = hitHurtables[i].GetComponent <IHurtable>();
             if (ignoreList.Contains(ih))
             {
                 continue;
             }
             ignoreList.Add(ih);
             OnDetect?.Invoke(hitHurtables[i]);
         }
         hitHurtables.Clear();
     }
 }
 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;
             }
             HurtHurtable(ih);
             ignoreList.Add(ih);
             OnHurt?.Invoke(hitHurtables[i], hitInfo);
         }
     }
 }
 /// <summary>
 /// Checks the given collisions type for enemies.
 /// </summary>
 /// <returns>Returns an IHurtable if found, or null if not found.</returns>
 virtual protected IHurtable CheckCollisions(RaycastType type)
 {
     for (int i = 0; i < character.Colliders.Length; i++)
     {
         if (character.Colliders[i].RaycastType == type)
         {
             for (int j = 0; j < character.CurrentCollisions[i].Length; j++)
             {
                 if (character.CurrentCollisions[i][j].collider != null &&
                     ((1 << character.CurrentCollisions[i][j].collider.gameObject.layer & enemyLayerMask) == enemyLayerMask))
                 {
                     IHurtable enemyHurtBox = (IHurtable)character.CurrentCollisions[i][j].collider.GetComponent(typeof(IHurtable));
                     if (enemyHurtBox != null)
                     {
                         return(enemyHurtBox);
                     }
                 }
             }
         }
     }
     return(null);
 }
        /// <summary>
        /// Checks for jumping on kicking.
        /// </summary>
        /// <returns><c>true</c>, if character is kicking an enemy.</returns>
        virtual protected bool CheckForKick()
        {
            IHurtable enemyHurtBox = null;

            if (!kickHidingEnemies)
            {
                return(false);
            }
            if (character.Velocity.x < 0)
            {
                enemyHurtBox = CheckCollisions(RaycastType.SIDE_LEFT);
                if (enemyHurtBox == null)
                {
                    return(false);
                }
                if (enemyHurtBox.Mob is Enemy && ((Enemy)enemyHurtBox.Mob).State == EnemyState.HIDING)
                {
                    this.enemyHurtBox = enemyHurtBox;
                    waitingToKick     = true;
                    return(true);
                }
            }
            else if (character.Velocity.x > 0)
            {
                enemyHurtBox = CheckCollisions(RaycastType.SIDE_RIGHT);
                if (enemyHurtBox == null)
                {
                    return(false);
                }
                if (enemyHurtBox.Mob is Enemy && ((Enemy)enemyHurtBox.Mob).State == EnemyState.HIDING)
                {
                    this.enemyHurtBox = enemyHurtBox;
                    waitingToKick     = true;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 24
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;
            }
        }
    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;
    }
Exemplo n.º 26
0
 public HitData(IHurtable other)
 {
     this.other = other;
 }
Exemplo n.º 27
0
 public virtual void OnHealTrigger(IHurtable player, int heals)
 {
 }
Exemplo n.º 28
0
 public virtual void OnHitTrigger(AttackObject attack, IHurtable entity)
 {
 }
 public void Initialize(GameObject owner, HurtboxGroup hurtboxGroup)
 {
     this.owner        = owner;
     this.hurtable     = owner.GetComponent <IHurtable>();
     this.hurtboxGroup = hurtboxGroup;
 }
Exemplo n.º 30
0
 protected override void HurtHurtable(IHurtable ih)
 {
     ih.Hurt(BuildHurtInfo());
 }