Esempio n. 1
0
    private bool IsBloodyAttack(XBoxComponent cruel, XBoxComponent hard)
    {
        XBoxRect        attackBox    = cruel.GetAttackBoxRect();
        List <XBoxRect> receiveBoxes = hard.GetReceiveDamageBoxesRect();

        if (attackBox == null || receiveBoxes == null)
        {
            return(false);
        }

        XBoxRect box = new XBoxRect();

        for (int i = 0; i < receiveBoxes.Count; i++)
        {
            XBoxRect lapBox = XBoxRect.Overlap(attackBox, receiveBoxes[i]);
            if (lapBox.Width >= 0)
            {
                if (box.Height < lapBox.Height)
                {
                    box.Copy(lapBox);
                }
            }
        }
        if (box.Width >= 0)
        {
            AddBloodyHeroes(cruel, hard, box);
            return(true);
        }

        return(false);
    }
Esempio n. 2
0
    private void HugEach(XBoxComponent human, XBoxComponent orc)
    {
        XBoxHugRect humanBox = human.GetHugBoxRect();
        XBoxHugRect orcBox   = orc.GetHugBoxRect();

        if (humanBox == null || orcBox == null)
        {
            return;
        }

        XBoxRect overlap = XBoxRect.Overlap(humanBox, orcBox);

        if (overlap != null && overlap.Width >= 0)
        {
            if (humanBox.HugType == orcBox.HugType || (humanBox.HugType != XHugType.Normal && orcBox.HugType != XHugType.Normal))
            {
                if (!_hugEachList.Contains(human))
                {
                    _hugEachList.Add(human);
                }
                if (!_hugEachList.Contains(orc))
                {
                    _hugEachList.Add(orc);
                }
            }
            else
            {
                XBoxComponent hc = humanBox.HugType > orcBox.HugType ? orc : human;
                if (!_hugBeEatenList.Contains(hc))
                {
                    _hugBeEatenList.Add(hc);
                }
            }
        }
    }
Esempio n. 3
0
    private bool _InternalWarningAttack(XBoxRect rectBox, XBoxComponent hard)
    {
        List <XBoxRect> receiveBoxes = hard.GetReceiveDamageBoxesRect();

        if (rectBox == null || receiveBoxes == null)
        {
            return(false);
        }

        for (int i = 0; i < receiveBoxes.Count; i++)
        {
            XBoxRect box = XBoxRect.Overlap(rectBox, receiveBoxes[i]);
            if (box.Width >= 0)
            {
                if (!_receiveWarningHeroes.Contains(hard))
                {
                    _receiveWarningHeroes.Add(hard);
                }

                return(true);
            }
        }

        return(false);
    }
Esempio n. 4
0
    private void CalBulletHit(XBoxComponent hero)
    {
        if (_bullets.Count > 0)
        {
            bool isHeroWarning = false;
            for (int i = 0; i < _bullets.Count; i++)
            {
                bool            addI  = false;
                List <XBoxRect> boxes = hero.GetReceiveDamageBoxesRect();
                for (int hurtBoxIndex = 0; hurtBoxIndex < boxes.Count; hurtBoxIndex++)
                {
                    if (XBoxRect.Overlap(boxes[hurtBoxIndex], _bullets[i].GetBulletHitBox()).Width >= 0)
                    {
                        AddBulletHero(_bullets[i], hero.Trans);
                        addI = true;
                        break;
                    }
                }

                if (!isHeroWarning)
                {
                    isHeroWarning = IsWarningAttack(_bullets[i], hero);
                }
                if (addI)
                {
                    continue;
                }

                for (int flexiHurtIndex = 0; flexiHurtIndex < _flexibleHurtBoxes.Count; flexiHurtIndex++)
                {
                    if (XBoxRect.Overlap(_flexibleHurtBoxes[flexiHurtIndex].GetFlexibleHurtBox(), _bullets[i].GetBulletHitBox()).Width >= 0)
                    {
                        AddBulletHero(_bullets[i], _flexibleHurtBoxes[flexiHurtIndex].Trans);
                        addI = true;
                        break;
                    }
                }

                if (addI)
                {
                    continue;
                }

                for (int index = 0; index < _bullets.Count; index++)
                {
                    if (index != i)
                    {
                        if (XBoxRect.Overlap(_bullets[i].GetBulletHitBox(), _bullets[index].GetBulletHitBox()).Width >= 0)
                        {
                            AddBulletHero(_bullets[i], _bullets[index].GetFlyEffectTrans());
                        }
                    }
                }
            }
        }
    }
Esempio n. 5
0
    private int LastTransMeet(XBoxComponent hc1, XBoxComponent hc2)
    {
        XBodyMoveRectBox rb1 = hc1.GetTransMoveBox();
        XBodyMoveRectBox rb2 = hc2.GetTransMoveBox();

        if (rb1 == null || rb2 == null)
        {
            return(-1);
        }

        XBoxRect box = XBoxRect.Overlap(rb1, rb2);

        return(box.Width);
    }
Esempio n. 6
0
    private XBoxExtraRect ExtraBoxMeet(XBoxExtraProperty property, XBoxRect box)
    {
        int meet = -1;

        if (_extraBoxesDic.ContainsKey(property))
        {
            for (int extraIndex = 0; extraIndex < _extraBoxesDic[property].Count; extraIndex++)
            {
                meet = XBoxRect.Overlap(box, _extraBoxesDic[property][extraIndex]).Width;
                if (meet >= 0)
                {
                    return(_extraBoxesDic[property][extraIndex]);
                }
            }
        }
        return(null);
    }
Esempio n. 7
0
    private void AddBloodyFlexiableBoxes(XBoxComponent attack)
    {
        XBoxRect attackBox = attack.GetAttackBoxRect();

        if (attackBox == null || _flexibleHurtBoxes.Count < 1)
        {
            return;
        }

        for (int i = 0; i < _flexibleHurtBoxes.Count; i++)
        {
            XBoxRect box = XBoxRect.Overlap(attackBox, _flexibleHurtBoxes[i].GetFlexibleHurtBox());
            if (box.Width >= 0)
            {
                AddBloodyHeroes(attack, _flexibleHurtBoxes[i].GetActiveId(), box);
            }
        }
    }
Esempio n. 8
0
    protected bool IsIntersect(Transform trans)
    {
        bool          hit = false;
        XBoxComponent hc  = trans.GetComponent <XBoxComponent>();

        if (hc != null && collider_ != null)
        {
            List <XBoxRect> hurtBoxes  = hc.GetReceiveDamageBoxesRect();
            XBoxRect        bulletRect = GetBoundingRect(transform, collider_);
            if (hurtBoxes != null && hurtBoxes.Count > 0 && bulletRect != null)
            {
                for (int i = 0; i < hurtBoxes.Count; i++)
                {
                    if (bulletRect.Overlap(hurtBoxes[i]) >= 0)
                    {
                        hit = true;
                        break;
                    }
                }
            }
        }
        else
        {
            Collider colid = trans.GetComponent <Collider>();

            if (colid != null)
            {
                if (collider_ != null)
                {
                    hit = colid.bounds.Intersects(collider_.bounds);
                }
                else
                {
                    hit = colid.bounds.Contains(transform.position);
                }
            }
        }
        return(hit);
    }
Esempio n. 9
0
    private bool AttackOnBullet(XBoxComponent hero)
    {
        XBoxRect attackBox = hero.GetAttackBoxRect();

        if (attackBox == null)
        {
            return(false);
        }

        if (_bullets.Count > 0)
        {
            for (int i = 0; i < _bullets.Count; i++)
            {
                XBoxRect lapBox = XBoxRect.Overlap(attackBox, _bullets[i].GetBulletHitBox());
                if (lapBox.Width >= 0)
                {
                    AddBloodyHeroes(hero, _bullets[i].gid, lapBox);
                    return(true);
                }
            }
        }
        return(false);
    }
Esempio n. 10
0
    private void HugYou(XBoxComponent me, XBoxComponent you)
    {
        if (_hugBeEatenList.Contains(me))
        {
            return;
        }

        XBoxRect hugBox = me.GetHugBoxRect();

        if (hugBox == null)
        {
            return;
        }
        List <XBoxRect> hurtBoxes = you.GetReceiveDamageBoxesRect();

        if (hurtBoxes == null)
        {
            return;
        }

        for (int i = 0; i < hurtBoxes.Count; i++)
        {
            XBoxRect overlap = XBoxRect.Overlap(hugBox, hurtBoxes[i]);
            if (overlap != null && overlap.Width >= 0)
            {
                if ((_hugHeroesDic.ContainsKey(me) && overlap.Width < _hugHeroesDic[me].Overlap) || !_hugHeroesDic.ContainsKey(me))
                {
                    XBoxOverlap lap = new XBoxOverlap();
                    lap.Hero          = you;
                    lap.Overlap       = overlap.Width;
                    _hugHeroesDic[me] = lap;
                }
                return;
            }
        }
    }
Esempio n. 11
0
    private void DealBodyMove()
    {
        int threshold = 300;

        while (threshold > 0)
        {
            for (int i = 0; i < _bodySortedHeroes.Count; i++)
            {
                for (int index = 0; index < _bodySortedHeroes.Count; index++)
                {
                    if (i < index)
                    {
                        int meet = XBoxRect.Overlap(_bodySortedHeroes[i].GetBodyMoveBox(), _bodySortedHeroes[index].GetBodyMoveBox()).Width;
                        if (meet >= 0)
                        {
                            XBoxRect extraI    = ExtraBoxMeet(XBoxExtraProperty.Wall, _bodySortedHeroes[i].GetBodyMoveBox());
                            XBoxRect extrIndex = ExtraBoxMeet(XBoxExtraProperty.Wall, _bodySortedHeroes[index].GetBodyMoveBox());
                            if (extraI != null && extrIndex != null && extrIndex == extraI)
                            {
                                meet = _bodySortedHeroes[i].GetBodyMoveBox().MinX < 0 ? _bodyMoveRuler : -_bodyMoveRuler;
                                if (_bodySortedHeroes[i].GetBodyMoveBox().MinY > _bodySortedHeroes[index].GetBodyMoveBox().MinY)
                                {
                                    _bodySortedHeroes[index].SetLastDeltaPos(meet, 0);
                                    _bodySortedHeroes[index].AdjustBodyMoveBox();
                                }
                                else
                                {
                                    _bodySortedHeroes[i].SetLastDeltaPos(meet, 0);
                                    _bodySortedHeroes[i].AdjustBodyMoveBox();
                                }
                            }
                            else
                            {
                                if (_bodySortedHeroes[i].GetBodyMoveBox().MinX < _bodySortedHeroes[index].GetBodyMoveBox().MinX)
                                {
                                    int move = Mathf.Min((int)(meet * 0.5), _bodyMoveRuler);
                                    _bodySortedHeroes[i].GetBodyMoveBox().MoveX     -= move;
                                    _bodySortedHeroes[index].GetBodyMoveBox().MoveX += move;
                                }
                                else
                                {
                                    int move = Mathf.Min((int)(meet * 0.5), _bodyMoveRuler);
                                    _bodySortedHeroes[index].GetBodyMoveBox().MoveX -= move;
                                    _bodySortedHeroes[i].GetBodyMoveBox().MoveX     += move;
                                }
                            }

                            _meetCache.AddCache(_bodySortedHeroes[i], _bodySortedHeroes[index]);
                        }
                    }
                }
            }

            CalMove(_meetCache.CacheList);

            bool stillMove = false;
            for (int i = 0; i < _bodySortedHeroes.Count; i++)
            {
                if (_bodySortedHeroes[i].GetBodyMoveBox().MoveX != 0 || _bodySortedHeroes[i].GetBodyMoveBox().MoveY != 0)
                {
                    int x = 0;
                    if (_bodySortedHeroes[i].GetBodyMoveBox().MoveX != 0)
                    {
                        x = _bodySortedHeroes[i].GetBodyMoveBox().MoveX > 0 ? _bodyMoveRuler : -_bodyMoveRuler;
                        x = GetRoundZero(x, _bodySortedHeroes[i].GetBodyMoveBox().MoveX);
                    }

                    int y = 0;
                    if (_bodySortedHeroes[i].GetBodyMoveBox().MoveY != 0)
                    {
                        y = _bodySortedHeroes[i].GetBodyMoveBox().MoveY > 0 ? _bodyMoveRuler : -_bodyMoveRuler;
                        y = GetRoundZero(y, _bodySortedHeroes[i].GetBodyMoveBox().MoveY);
                    }

                    if (_meetCache.GetCacheInCache(_bodySortedHeroes[i]) == null)
                    {
                        XBoxRect extra = ExtraBoxMeet(XBoxExtraProperty.Wall, _bodySortedHeroes[i].GetBodyMoveBox());
                        if (extra == null || (extra != null && (_bodySortedHeroes[i].GetBodyMoveBox().MinX - extra.MinX) * _bodySortedHeroes[i].GetBodyMoveBox().MoveX > 0))
                        {
                            _bodySortedHeroes[i].SetLastDeltaPos(x, y);
                            _bodySortedHeroes[i].AdjustBodyMoveBox();
                        }
                    }
                    BodyMoveStep(_bodySortedHeroes[i], x, y);
                    stillMove = true;
                }
            }
            _meetCache.Clear();
            if (stillMove)
            {
                threshold -= _bodyMoveRuler;
            }
            else
            {
                threshold = 0;
            }
        }
    }