Ejemplo n.º 1
0
        /// <summary>
        /// Adds the given Object to this Region in the next Region tick.
        /// </summary>
        /// <param name="region"></param>
        /// <param name="obj"></param>
        /// <param name="newPos"></param>
        public static void MoveObjectAndWait(this Region region, WorldObject obj, Vector3 newPos)
        {
            region.Start();             // make sure, Region is running
            Assert.IsTrue(region.Running);

            // We can't add something that we already have
            var obj2 = region.GetObject(obj.EntityId);

            Assert.IsNull(obj2, "Object {0} was already added to Region {1}", obj, region);

            region.Start();

            Message2 <WorldObject, Vector3> moveTask =
                new Message2 <WorldObject, Vector3>(obj, newPos);

            if (obj.Region != null)
            {
                obj.Region.RemoveObjectInstantly(obj);
            }

            moveTask.Callback = (worldObj, objLocation) => {
                if (worldObj is Character)
                {
                    var chr = (Character)worldObj;
                    chr.ResetInitialObjectKnowledge();
                    Assert.IsFalse(chr.KnowsOf(chr));
                }

                region.AddObjectInstantly(worldObj, ref objLocation);
                lock (moveTask)
                {
                    Monitor.PulseAll(moveTask);
                }

                Assert.IsTrue(region.Running);
            };
            region.AddMessage(moveTask);

            bool added = false;
            int  delay = region.GetWaitDelay();

            lock (moveTask)
            {
                Monitor.Wait(moveTask, delay);
                Assert.IsTrue(added, "Object {0} was not added to Region after " + delay + " milliseconds.", obj);
            }
            added = true;

            Assert.AreEqual(obj.Region, region);
        }