Пример #1
0
 /// <summary>
 ///  为序列的某个部分进行划分 左小右大
 /// </summary>
 /// <param name="arr">序列</param>
 /// <param name="start">开始位置</param>
 /// <param name="end">结束位置</param>
 public static void QuickSort(List <ZombieController> enemyZombies, ZombieController zc, int start, int end)
 {
     if (start < end)
     {
         int s = start;
         int e = end;
         //临界值位置的标量
         bool isStart = true;
         while (s < e)
         {
             if (Pos.Distance(zc.zombie.battlePos, enemyZombies[s].zombie.battlePos) > Pos.Distance(zc.zombie.battlePos, enemyZombies[e].zombie.battlePos))
             {
                 Swap(enemyZombies, s, e);
                 //标量转换
                 isStart = !isStart;
             }
             //移动索引位置
             if (isStart)
             {
                 e--;
             }
             else
             {
                 s++;
             }
         }
         //将序列划分成了:
         //左边:start→(e-1)
         QuickSort(enemyZombies, zc, start, e - 1);
         //右边:s+1→end
         QuickSort(enemyZombies, zc, s + 1, end);
     }
 }
Пример #2
0
        private static bool InteractRangeSelector(Entity entity, Pos entityPos, Entity peer, Pos peerPos)
        {
            if (!entity.Has <Motion>())
            {
                return(false);
            }

            const int defaultRange  = 50;
            const int defaultDegree = 30;
            var       dir           = entity.Get <Motion>().Dir;
            var       ax            = Math.Cos(dir);
            var       ay            = Math.Sin(dir);
            var       sizeOfA       = Math.Sqrt(ax * ax + ay * ay);

            const double deltaRadian = defaultDegree * Math.PI / 180.0;
            const double epsilon     = 1.0;

            var dx      = peerPos.X - entityPos.X;
            var dy      = peerPos.Y - entityPos.Y;
            var sizeOfD = Math.Sqrt(dx * dx + dy * dy);

            if (Math.Abs(sizeOfD - 0) < epsilon)
            {
                return(true);
            }

            var cross       = ax * dx + ay * dy;
            var thetaRadian = Math.Acos(cross / (sizeOfA * sizeOfD));

            if (!(-deltaRadian <= thetaRadian && thetaRadian <= deltaRadian))
            {
                return(false);
            }

            var oppositeDistance = Pos.Distance(entityPos.X, entityPos.Y, peerPos.X, peerPos.Y);

            return(!(oppositeDistance > defaultRange));
        }
Пример #3
0
        private void RebuildViewOfEntity(Entity entity)
        {
            var currentPos = GetCurrentPos(entity);
            var viewRange  = entity.Has <Player>()
                                ? Math.Max(entity.Get <Player>().ViewRange, DefaultViewRange)
                                : 0;

            if (!_viewMap.ContainsKey(entity))
            {
                _viewMap.Add(entity, new HashSet <Entity>());
            }

            var observers = _viewMap[entity];

            foreach (var peer in _viewMap.Keys.Where(e => e.Has <Player>()))
            {
                if (peer == entity)
                {
                    continue;
                }

                var peerViewRange = Math.Max(peer.Get <Player>().ViewRange, DefaultViewRange);
                var peerPos       = GetCurrentPos(peer);
                var distance      = Pos.Distance(currentPos, peerPos);
                Logger.Write("{0} <-> {1} : {2}", currentPos, peerPos, distance);

                if (distance <= peerViewRange)
                {
                    if (!observers.Contains(peer))
                    {
                        observers.Add(peer);
                        SendSpawnMessage(peer, entity);
                    }
                }
                else
                {
                    if (observers.Contains(peer))
                    {
                        observers.Remove(peer);
                        SendDespawnMessage(peer, entity);
                    }
                }

                var peerObservers = _viewMap[peer];
                if (distance < viewRange)
                {
                    if (!peerObservers.Contains(entity))
                    {
                        peerObservers.Add(entity);
                        SendSpawnMessage(entity, peer);
                    }
                }
                else
                {
                    if (peerObservers.Contains(entity))
                    {
                        peerObservers.Remove(entity);
                        SendDespawnMessage(entity, peer);
                    }
                }
            }
        }
Пример #4
0
        public static FarmLocation GetBestLaserFarmLocation(bool jungle)
        {
            var bestEndPos   = new Vector2();
            var bestStartPos = new Vector2();
            var mMinionCount = 0;
            List <Obj_AI_Base> AllMinions;

            if (!jungle)
            {
                AllMinions = MinionManager.GetMinions(EMaxRange);
            }
            else
            {
                AllMinions = MinionManager.GetMinions(EMaxRange, MinionTypes.All, MinionTeam.Neutral);
            }

            var mMinionsList     = (from minions in AllMinions select minions.Position.To2D()).ToList <Vector2>();
            var possiblePosition = new List <Vector2>();

            possiblePosition.AddRange(mMinionsList);
            var Max = possiblePosition.Count;

            for (var i = 0; i < Max; i++)
            {
                for (var j = 0; j < Max; j++)
                {
                    if (possiblePosition[j] != possiblePosition[i])
                    {
                        possiblePosition.Add((possiblePosition[j] + possiblePosition[i]) / 2);
                    }
                }
            }

            foreach (var StartPositionMinion in AllMinions.Where(m => Utilities.Player.Distance(m) < ERange))
            {
                var StartPos = StartPositionMinion.Position.To2D();

                foreach (var Pos in possiblePosition)
                {
                    if (Pos.Distance(StartPos, true) <= LenghtE * LenghtE)
                    {
                        var EndPos = StartPos + LenghtE * (Pos - StartPos).Normalized();
                        var count  =
                            mMinionsList.Count(Pos2 => Pos2.Distance(StartPos, EndPos, true, true) <= 140 * 140);

                        if (count >= mMinionCount)
                        {
                            bestEndPos   = EndPos;
                            mMinionCount = count;
                            bestStartPos = StartPos;
                        }
                    }
                }
            }

            if ((!jungle && Utilities.SliderValue("e.clear.minhit") < mMinionCount) || (jungle && mMinionCount > 0))
            {
                return(new FarmLocation(bestStartPos, bestEndPos, mMinionCount));
            }
            else
            {
                return(new FarmLocation(bestStartPos, bestEndPos, 0));
            }
        } // Algorithm by Trus. Congratz bro
Пример #5
0
 public double GetDistance(Vertex vertex) => Pos.Distance(vertex.Pos);
Пример #6
0
        public virtual void UpdateInRange(ICollection allObjs, ArrayList objRemove)
        {
            // check someone exit
            ArrayList obExit = new ArrayList();

            foreach (ObjWithPosition ob in objectInRange)
            {
                if (objRemove.Contains(ob) || ob.mapID != mapID || Distance(ob) > Const.UPDATE_DISTANCE)
                {
                    obExit.Add(ob);
                }
            }
            foreach (ObjWithPosition ob in obExit)
            {
                objectInRange.Remove(ob);
                ob.objectInRange.Remove(this);

                if (IsType(TYPE.PLAYER))                 // send Exit Message
                {
                    ByteArrayBuilder b = new ByteArrayBuilder(false);
                    b.Add(ob.GUID);
                    (this as Character).Send(OP.SMSG_DESTROY_OBJECT, b);
                }

                if (ob.IsType(TYPE.PLAYER))
                {
                    ByteArrayBuilder b = new ByteArrayBuilder(false);
                    b.Add(GUID);
                    (ob as Character).Send(OP.SMSG_DESTROY_OBJECT, b);
                }
            }

            // check me join
            if (Pos.Distance(lastUpdatePos) < Const.UPDATE_DISTANCE / 10)
            {
                return;
            }
            if (IsType(TYPE.PLAYER))
            {
                Character c = this as Character;
                if (!c.InWorld())
                {
                    return;
                }
                gameServer.RefrencePosition(this);
            }

            lastUpdatePos = Pos;
            foreach (ObjWithPosition ob in allObjs)
            {
                if (ob.mapID != mapID || ob == this)
                {
                    continue;
                }
                if (obExit.Contains(ob) || objectInRange.Contains(ob) || Distance(ob) > Const.UPDATE_DISTANCE)
                {
                    continue;
                }

                if (ob.IsType(TYPE.PLAYER) && !(ob as Character).InWorld())
                {
                    continue;
                }

                if (CanSee(ob))
                {
                    objectInRange.Add(ob);

                    if (IsType(TYPE.PLAYER))                     // send ob Join Message
                    {
                        UpdateMask mask = new UpdateMask();
                        ob.BuildCreateMask(mask, false);
                        (this as Character).SendUpdate(ob.BuildUpdate(mask, UpdateType.All, false));

                        if (ob.IsType(TYPE.PLAYER))
                        {
                            (this as Character).SendCreateItems(ob as Character, CreateItemType.Other);
                        }
                    }
                }

                if (ob.CanSee(this))
                {
                    ob.objectInRange.Add(this);

                    if (ob.IsType(TYPE.PLAYER))                     // send ob Join Message
                    {
                        UpdateMask mask = new UpdateMask();
                        BuildCreateMask(mask, false);
                        (ob as Character).SendUpdate(BuildUpdate(mask, UpdateType.All, false));

                        if (IsType(TYPE.PLAYER))
                        {
                            (ob as Character).SendCreateItems(this as Character, CreateItemType.Other);
                        }
                    }
                }
            }
        }
Пример #7
0
 public float Distance(ObjWithPosition t)
 {
     return(Pos.Distance(t.Pos));
 }