Example #1
0
 public HitboxGroup(HitboxGroup other)
 {
     ID = other.ID;
     activeFramesStart = other.activeFramesStart;
     activeFramesEnd   = other.activeFramesEnd;
     attachToEntity    = other.attachToEntity;
     chargeLevelNeeded = other.chargeLevelNeeded;
     chargeLevelMax    = other.chargeLevelMax;
     if (other.hitboxHitInfo.GetType() == typeof(HitInfo))
     {
         hitboxHitInfo = new HitInfo((HitInfo)other.hitboxHitInfo);
     }
     boxes = new List <BoxDefinitionBase>();
 }
 protected virtual bool TryHitHurtbox(HitboxGroup hitboxGroup, int hitboxIndex, int hurtboxIndex, int hitboxGroupIndex, GameObject attacker)
 {
     // Owner was already hit by this ID group or is null, ignore it.
     if (hurtboxes[hurtboxIndex] == null || collidedIHurtables[hitboxGroup.ID].hitIHurtables.Contains(hurtboxes[hurtboxIndex].Owner))
     {
         return(false);
     }
     // Additional filtering.
     if (ShouldHurt(hitboxGroup, hitboxIndex, hurtboxes[hurtboxIndex]) == false)
     {
         return(false);
     }
     collidedIHurtables[hitboxGroup.ID].hitIHurtables.Add(hurtboxes[hurtboxIndex].Owner);
     collidedIHurtables[hitboxGroup.ID].hitboxGroups.Add(hitboxGroupIndex);
     HurtHurtbox(hitboxGroup, hitboxIndex, hurtboxes[hurtboxIndex], attacker);
     return(true);
 }
        public virtual bool CheckForCollision(int hitboxGroupIndex, HitboxGroup hitboxGroup, GameObject attacker, List <GameObject> ignoreList = null)
        {
            bool hurtboxHit = false;

            hurtboxes.Clear();
            for (int i = 0; i < hitboxGroup.boxes.Count; i++)
            {
                CheckBoxCollision(hitboxGroup, i);

                // This hitbox hit nothing.
                if (hurtboxes.Count == 0)
                {
                    continue;
                }

                // Hit thing(s). Check if we should actually hurt them.
                if (!collidedIHurtables.ContainsKey(hitboxGroup.ID))
                {
                    collidedIHurtables.Add(hitboxGroup.ID, new IDGroupCollisionInfo());
                }

                SortHitHurtboxes();

                for (int j = 0; j < hurtboxes.Count; j++)
                {
                    if (ignoreList != null && ignoreList.Contains(hurtboxes[j].Owner))
                    {
                        continue;
                    }
                    if (TryHitHurtbox(hitboxGroup, i, j, hitboxGroupIndex, attacker))
                    {
                        hurtboxHit = true;
                    }
                }
            }
            return(hurtboxHit);
        }
 protected virtual void CheckBoxCollision(HitboxGroup hitboxGroup, int boxIndex)
 {
 }
 protected virtual HurtInfoBase BuildHurtInfo(HitboxGroup hitboxGroup, int hitboxIndex, Hurtbox hurtbox, GameObject attacker)
 {
     return(new HurtInfoBase());
 }
        protected virtual void HurtHurtbox(HitboxGroup hitboxGroup, int hitboxIndex, Hurtbox hurtbox, GameObject attacker)
        {
            HitReactionBase reaction = hurtbox.Hurtable.Hurt(BuildHurtInfo(hitboxGroup, hitboxIndex, hurtbox, attacker));

            OnHitHurtbox?.Invoke(hitboxGroup, hitboxIndex, hurtbox, reaction);
        }
 /// <summary>
 /// Determines if this hurtbox should be hit.
 /// </summary>
 /// <param name="hitboxGroup">The hitbox group of the hitbox.</param>
 /// <param name="hitboxIndex">The index of the hitbox.</param>
 /// <param name="hurtbox">The hurtbox that was hit.</param>
 /// <returns>If the hurtbox should be hurt.</returns>
 protected virtual bool ShouldHurt(HitboxGroup hitboxGroup, int hitboxIndex, Hurtbox hurtbox)
 {
     return(true);
 }