Esempio n. 1
0
        public void Partition(IEntity entity, Point2D location, int radius)
        {
            var candidate = new CollisionCandidate(entity, location, radius);

            var left   = (candidate.Position.X - candidate.Radius) / _capacity;
            var top    = (candidate.Position.Y - candidate.Radius) / _capacity;
            var right  = (candidate.Position.X + candidate.Radius) / _capacity;
            var bottom = (candidate.Position.Y + candidate.Radius) / _capacity;

            var cells = new int[]
            {
                left + top * _unit,
                right + top * _unit,
                left + bottom * _unit,
                right + bottom * _unit,
            };

            _inner[cells[0]].Add(candidate);
            if (cells[0] != cells[1])
            {
                _inner[cells[1]].Add(candidate);
            }
            if (cells[1] != cells[2])
            {
                _inner[cells[2]].Add(candidate);
            }
            if (cells[2] != cells[3])
            {
                _inner[cells[3]].Add(candidate);
            }
        }
Esempio n. 2
0
            public bool CollidesWith(CollisionCandidate other)
            {
                var length = (Position - other.Position).Length;

                return(length < Radius + other.Radius);
            }
Esempio n. 3
0
        private static void CheckSpellCollision()
        {
            if (ObjectCache.menuCache.cache["CheckSpellCollision"].GetValue <bool>() == false)
            {
                return;
            }

            foreach (KeyValuePair <int, Spell> entry in detectedSpells)
            {
                Spell spell           = entry.Value;
                var   collisionObject = spell.CheckSpellCollision();
                if (collisionObject != null)
                {
                    spell.predictedEndPos = spell.GetSpellProjection(collisionObject.ServerPosition.To2D());

                    if (spell.currentSpellPosition.Distance(collisionObject.ServerPosition) <
                        collisionObject.BoundingRadius + spell.radius)
                    {
                        if (!spell.info.hasEndExplosion || spell.spellType != SpellType.Circular)
                        {
                            DelayAction.Add(1, () => DeleteSpell(entry.Key));
                        }
                    }
                }
            }

            foreach (KeyValuePair <int, CollisionCandidate> entry in collisionObjs)
            {
                CollisionCandidate cand = entry.Value;

                var spellTime = cand.spellTime = EvadeUtils.TickCount - cand.startTick - cand.spellInfo.spellDelay;
                if (spellTime >= 0)
                {
                    cand.currentPos = cand.startPos +
                                      (cand.endPos - cand.startPos).Normalized() * cand.spellInfo.projectileSpeed *
                                      (cand.spellTime / 1000);
                }

                var collisionObj = cand.currentPos.To3D().CheckPositionCollision(cand.endPos.To3D(), cand.spellInfo, false);
                if (collisionObj != null)
                {
                    var data = cand.spellInfo.CopyData();
                    data.spellDelay = 0;

                    foreach (KeyValuePair <int, Spell> value in detectedSpells)
                    {
                        Spell spell = value.Value;

                        if (spell.spellType == SpellType.Line && spell.info.hasEndExplosion)
                        {
                            if (spell.info.spellName == cand.spellInfo.spellName)
                            {
                                DelayAction.Add(1, () => DeleteSpell(value.Key)); // delete the skillshot
                            }
                        }
                    }

                    CreateSpellData(cand.candidateHero, cand.startPos.To3D(), collisionObj.ServerPosition,
                                    data, null, 0, true, SpellType.Circular, false, true); // create the explosion

                    collisionObjs.Remove(cand.candidateId);
                    break;
                }

                DelayAction.Add((int)cand.endTime, () => collisionObjs.Remove(cand.candidateId));
            }
        }