示例#1
0
        public void GetCityBytes_WhenPlayersInRegionArentInOrder_ShouldSucceed(
            [Frozen] DefaultMultiObjectLock.Factory lockerFactory,
            IMultiObjectLock locker,
            IMiniMapRegionObject obj1,
            IMiniMapRegionObject obj2,
            MiniMapRegion miniMapRegion)
        {
            obj1.Hash.Returns(1);
            obj2.Hash.Returns(2);

            lockerFactory().Lock(Arg.Is <ILockable[]>(p => p.SequenceEqual(new[] { obj2, obj1 })))
            .Returns(locker);

            locker.When(p => p.SortLocks(Arg.Is <ILockable[]>(a => a.SequenceEqual(new[] { obj2, obj1 }))))
            .Do(args => Array.Sort((ILockable[])args[0], DefaultMultiObjectLock.CompareObject));

            locker.Do(Arg.Any <Func <bool> >()).Returns(callInfo =>
            {
                var action = callInfo.Arg <Func <bool> >();
                return(action());
            });

            miniMapRegion.Add(obj2);
            miniMapRegion.Add(obj1);

            miniMapRegion.GetCityBytes().Should().NotBeNull();
        }
示例#2
0
        public void Add(IMiniMapRegionObject obj)
        {
            MiniMapRegion miniMapRegion;

            if (TryGetMiniMapRegion(obj.PrimaryPosition.X, obj.PrimaryPosition.Y, out miniMapRegion))
            {
                miniMapRegion.Add(obj);
            }
        }
示例#3
0
        public void Update(IMiniMapRegionObject obj, uint origX, uint origY)
        {
            lock (objLock)
            {
                Position loc = obj.PrimaryPosition;
                if (loc.X != origX || loc.Y != origY)
                {
                    Remove(obj);
                    Add(obj);
                }

                MarkAsDirty();
            }
        }
示例#4
0
        public bool Add(IMiniMapRegionObject obj)
        {
            lock (objLock)
            {
                data.Add(obj);
                MarkAsDirty();
            }

            if (logger.IsTraceEnabled)
            {
                logger.Trace("Added city region obj: {0}", obj.ToString());
            }

            return(true);
        }
示例#5
0
        public void Remove(IMiniMapRegionObject obj)
        {
            lock (objLock)
            {
                var remove = data.Remove(obj);
                if (!remove)
                {
                    logger.Warn("Tried to remove nonexistant object from city region: {0}", obj.ToString());

                    throw new Exception("Tried to remove obj from wrong region");
                }

                logger.Trace("Removed city region obj: {0}", obj.ToString());

                MarkAsDirty();
            }
        }
示例#6
0
        public void Remove(ISimpleGameObject obj)
        {
            if (!obj.InWorld)
            {
                return;
            }

            var lockedRegions = LockMultitileRegions(obj.PrimaryPosition.X, obj.PrimaryPosition.Y, obj.Size);

            if (RemoveFromPrimaryRegionAndAllTiles(obj, obj.PrimaryPosition.X, obj.PrimaryPosition.Y))
            {
                obj.InWorld = false;

                DeregisterObjectEventListeners(obj);

                IMiniMapRegionObject miniMapRegionObject = obj as IMiniMapRegionObject;
                if (miniMapRegionObject != null)
                {
                    MiniMapRegions.Remove(miniMapRegionObject);
                }

                ushort regionId = regionLocator.GetRegionIndex(obj);
                channel.Post("/WORLD/" + regionId, () =>
                {
                    var packet = new Packet(Command.ObjectRemove);
                    packet.AddUInt16(regionId);
                    packet.AddUInt32(obj.GroupId);
                    packet.AddUInt32(obj.ObjectId);
                    return(packet);
                });
            }

            UnlockRegions(lockedRegions);

            // Raise event
            ObjectRemoved.Raise(this, new ObjectEvent(obj));
        }
示例#7
0
        public bool Add(ISimpleGameObject obj)
        {
            if (!AddToPrimaryRegionAndTiles(obj))
            {
                return(false);
            }

            // Keeps track of objects that exist in the map
            obj.InWorld = true;

            RegisterObjectEventListeners(obj);

            // Add appropriate objects to the minimap
            IMiniMapRegionObject miniMapRegionObject = obj as IMiniMapRegionObject;

            if (miniMapRegionObject != null)
            {
                MiniMapRegions.Add(miniMapRegionObject);
            }

            // Post to channel
            ushort regionId = regionLocator.GetRegionIndex(obj);

            channel.Post("/WORLD/" + regionId, () =>
            {
                var packet = new Packet(Command.ObjectAdd);
                packet.AddUInt16(regionId);
                PacketHelper.AddToPacket(obj, packet);
                return(packet);
            });

            // Raise event
            ObjectAdded.Raise(this, new ObjectEvent(obj));

            return(true);
        }
示例#8
0
        public void UpdateObjectRegion(IMiniMapRegionObject obj, uint origX, uint origY)
        {
            // TODO: Remove this at some point.. added this to check an existing issue
            var simpleObj = obj as ISimpleGameObject;

            if (simpleObj != null && !simpleObj.InWorld)
            {
                if (logger.IsTraceEnabled)
                {
                    logger.Trace("Removed update for obj that is not in world: groupId[{0}] objectId[{1}] type[{2}] currentX[{3}] currentY[{4}] origX[{5}] origY[{6}]",
                                 obj.MiniMapGroupId,
                                 obj.MiniMapObjectId,
                                 obj.MiniMapObjectType,
                                 obj.PrimaryPosition.X,
                                 obj.PrimaryPosition.Y,
                                 origX,
                                 origY);
                }

                throw new Exception("Received unexpected city region update for obj that is not in world");
            }

            ushort oldMiniMapRegionId = MiniMapRegion.GetRegionIndex(origX, origY);
            ushort newMiniMapRegionId = MiniMapRegion.GetRegionIndex(obj.PrimaryPosition.X, obj.PrimaryPosition.Y);

            if (oldMiniMapRegionId == newMiniMapRegionId)
            {
                if (logger.IsTraceEnabled)
                {
                    logger.Trace("Updated city region obj: groupId[{0}] objectId[{1}] type[{2}] regionId[{3}] currentX[{4}] currentY[{5}] origX[{6}] origY[{7}]",
                                 obj.MiniMapGroupId,
                                 obj.MiniMapObjectId,
                                 obj.MiniMapObjectType,
                                 oldMiniMapRegionId,
                                 obj.PrimaryPosition.X,
                                 obj.PrimaryPosition.Y,
                                 origX,
                                 origY);
                }

                miniMapRegions[oldMiniMapRegionId].Update(obj, origX, origY);
            }
            else
            {
                if (logger.IsTraceEnabled)
                {
                    logger.Trace("Moved city region obj: groupId[{0}] objectId[{1}] type[{2}] oldRegionId[{3}] newRegionId[{4}] currentX[{5}] currentY[{6}] origX[{7}] origY[{8}]",
                                 obj.MiniMapGroupId,
                                 obj.MiniMapObjectId,
                                 obj.MiniMapObjectType,
                                 oldMiniMapRegionId,
                                 newMiniMapRegionId,
                                 obj.PrimaryPosition.X,
                                 obj.PrimaryPosition.Y,
                                 origX,
                                 origY);
                }

                miniMapRegions[oldMiniMapRegionId].Remove(obj);
                miniMapRegions[newMiniMapRegionId].Add(obj);
            }
        }