예제 #1
0
        public static bool LoadAllAreas()
        {
            try
            {
                Assembly gasm    = Assembly.GetExecutingAssembly();
                var      DBAreas = GameServer.Database.SelectAllObjects <DBArea>();
                foreach (DBArea thisArea in DBAreas)
                {
                    AbstractArea area = (AbstractArea)gasm.CreateInstance(thisArea.ClassType, false);
                    if (area == null)
                    {
                        foreach (Assembly asm in ScriptMgr.Scripts)
                        {
                            try
                            {
                                area = (AbstractArea)asm.CreateInstance(thisArea.ClassType, false);

                                if (area != null)
                                {
                                    break;
                                }
                            }
                            catch (Exception e)
                            {
                                if (log.IsErrorEnabled)
                                {
                                    log.Error("LoadAllAreas", e);
                                }
                            }
                        }

                        if (area == null)
                        {
                            log.Debug("area type " + thisArea.ClassType + " cannot be created, skipping");
                            continue;
                        }
                    }
                    area.LoadFromDatabase(thisArea);
                    area.Sound        = thisArea.Sound;
                    area.CanBroadcast = thisArea.CanBroadcast;
                    area.CheckLOS     = thisArea.CheckLOS;
                    Region region = WorldMgr.GetRegion(thisArea.Region);
                    if (region == null)
                    {
                        continue;
                    }
                    region.AddArea(area);
                    log.Info("Area added: " + thisArea.Description);
                }
                return(true);
            }
            catch (Exception ex)
            {
                log.Error("Loading all areas failed", ex);
                return(false);
            }
        }
예제 #2
0
        public void AddArea()
        {
            Region region     = WorldMgr.GetRegion(1);
            IArea  insertArea = region.AddArea(new Area.Circle(null, 1000, 1000, 0, 500));

            Assert.IsNotNull(insertArea);

            var areas = region.GetAreasOfSpot(501, 1000, 0);

            Assert.IsTrue(areas.Count > 0);

            bool found = false;

            foreach (IArea ar in areas)
            {
                if (ar == insertArea)
                {
                    found = true;
                    break;
                }
            }

            Assert.IsTrue(found);

            //
            areas = region.GetAreasOfSpot(1499, 1000, 2000);
            Assert.IsTrue(areas.Count > 0);

            found = false;
            foreach (IArea ar in areas)
            {
                if (ar == insertArea)
                {
                    found = true;
                    break;
                }
            }

            Assert.IsTrue(found);

            // Notify test
            notified = false;

            GamePlayer player = CreateMockGamePlayer();

            insertArea.RegisterPlayerEnter(new DOLEventHandler(NotifyTest));
            insertArea.OnPlayerEnter(player);

            Assert.IsTrue(notified);

            region.RemoveArea(insertArea);

            areas = region.GetAreasOfSpot(1499, 1000, 2000);
            Assert.IsTrue(areas.Count == 0);
        }