public void DeleteMe()
    {
        // Remove from region.
        _region.RemoveObject(this);

        // Broadcast NPC deletion.
        DeleteObject        delete  = new DeleteObject(this);
        List <RegionHolder> regions = _region.GetSurroundingRegions();

        for (int i = 0; i < regions.Count; i++)
        {
            List <WorldObject> objects = regions[i].GetObjects();
            for (int j = 0; j < objects.Count; j++)
            {
                WorldObject nearby = objects[j];
                if (nearby != null && nearby.IsPlayer())
                {
                    nearby.AsPlayer().ChannelSend(delete);
                }
            }
        }

        // Set region to null.
        _region = null;
    }
    public void SetLocation(float posX, float posY, float posZ, float heading)
    {
        _location.Update(posX, posY, posZ, heading);

        // When changing location test for appropriate region.
        RegionHolder testRegion = WorldManager.GetRegion(this);

        if (!testRegion.Equals(_region))
        {
            if (_region != null)
            {
                // Remove this object from the region.
                _region.RemoveObject(this);

                // Broadcast change to players left behind when teleporting.
                if (_isTeleporting)
                {
                    DeleteObject        deleteObject = new DeleteObject(this);
                    List <RegionHolder> regions      = _region.GetSurroundingRegions();
                    for (int i = 0; i < regions.Count; i++)
                    {
                        List <WorldObject> objects = regions[i].GetObjects();
                        for (int j = 0; j < objects.Count; j++)
                        {
                            WorldObject nearby = objects[j];
                            if (nearby == this)
                            {
                                continue;
                            }
                            if (nearby.IsPlayer())
                            {
                                nearby.AsPlayer().ChannelSend(deleteObject);
                            }
                        }
                    }
                }
            }

            // Assign new region.
            _region = testRegion;
            _region.AddObject(this);

            // Send visible NPC information.
            // TODO: Exclude known NPCs?
            if (IsPlayer())
            {
                List <WorldObject> objects = WorldManager.GetVisibleObjects(this);
                for (int i = 0; i < objects.Count; i++)
                {
                    WorldObject nearby = objects[i];
                    if (!nearby.IsNpc())
                    {
                        continue;
                    }
                    AsPlayer().ChannelSend(new NpcInformation(nearby.AsNpc()));
                }
            }
        }
    }
Exemple #3
0
    public override bool Equals(object obj)
    {
        if (obj == null || GetType() != obj.GetType())
        {
            return(false);
        }
        RegionHolder region = ((RegionHolder)obj);

        return(x == region.GetX() && y == region.GetY());
    }
    public void SetLocation(LocationHolder location)
    {
        this.location = location;

        // When changing location test for appropriate region.
        RegionHolder testRegion = WorldManager.GetRegion(this);

        if (!testRegion.Equals(region))
        {
            if (region != null)
            {
                // Remove this object from the region.
                region.RemoveObject(objectId);

                // Broadcast change to players left behind when teleporting.
                if (isTeleporting)
                {
                    DeleteObject deleteObject = new DeleteObject(this);
                    foreach (RegionHolder nearbyRegion in region.GetSurroundingRegions())
                    {
                        foreach (WorldObject obj in region.GetObjects())
                        {
                            if (obj == this)
                            {
                                continue;
                            }
                            if (obj.IsPlayer())
                            {
                                obj.AsPlayer().ChannelSend(deleteObject);
                            }
                        }
                    }
                }
            }

            // Assign new region.
            region = testRegion;
            region.AddObject(this);

            // Send visible NPC information.
            // TODO: Exclude known NPCs?
            if (IsPlayer())
            {
                foreach (WorldObject obj in WorldManager.GetVisibleObjects(this))
                {
                    if (!obj.IsNpc())
                    {
                        continue;
                    }
                    AsPlayer().ChannelSend(new NpcInformation(obj.AsNpc()));
                }
            }
        }
    }
Exemple #5
0
    public void SetSurroundingRegions(RegionHolder[] regions)
    {
        surroundingRegions = regions;

        // Make sure that this region is always first to improve bulk operations.
        for (int i = 0; i < surroundingRegions.Length; i++)
        {
            if (surroundingRegions[i] == this)
            {
                RegionHolder first = surroundingRegions[0];
                surroundingRegions[0] = this;
                surroundingRegions[i] = first;
                break;
            }
        }
    }
Exemple #6
0
    public void SetSurroundingRegions(List <RegionHolder> regions)
    {
        _surroundingRegions = regions;

        // Make sure that this region is always first to improve bulk operations.
        for (int i = 0; i < _surroundingRegions.Count; i++)
        {
            if (_surroundingRegions[i] == this)
            {
                RegionHolder first = _surroundingRegions[0];
                _surroundingRegions[0] = this;
                _surroundingRegions[i] = first;
                break;
            }
        }
    }
    public void DeleteMe()
    {
        // Remove from region.
        region.RemoveObject(objectId);

        // Broadcast NPC deletion.
        DeleteObject delete = new DeleteObject(this);

        foreach (RegionHolder nearbyRegion in region.GetSurroundingRegions())
        {
            foreach (WorldObject nearby in nearbyRegion.GetObjects())
            {
                if (nearby != null && nearby.IsPlayer())
                {
                    nearby.AsPlayer().ChannelSend(delete);
                }
            }
        }

        // Set region to null.
        region = null;
    }
    public static void Init()
    {
        Util.PrintSection("World");

        // Initialize regions.
        for (int x = 0; x < REGION_SIZE_X; x++)
        {
            REGIONS[x] = new RegionHolder[REGION_SIZE_Z];
            for (int z = 0; z < REGION_SIZE_Z; z++)
            {
                REGIONS[x][z] = new RegionHolder(x, z);
            }
        }

        // Set surrounding regions.
        for (int x = 0; x < REGION_SIZE_X; x++)
        {
            for (int z = 0; z < REGION_SIZE_Z; z++)
            {
                List <RegionHolder> surroundingRegions = new List <RegionHolder>(9);
                for (int sx = x - 1; sx <= (x + 1); sx++)
                {
                    for (int sz = z - 1; sz <= (z + 1); sz++)
                    {
                        if (((sx >= 0) && (sx < REGION_SIZE_X) && (sz >= 0) && (sz < REGION_SIZE_Z)))
                        {
                            surroundingRegions.Add(REGIONS[sx][sz]);
                        }
                    }
                }
                REGIONS[x][z].SetSurroundingRegions(surroundingRegions);
            }
        }

        LogManager.Log("WorldManager: Initialized " + REGION_SIZE_X + " by " + REGION_SIZE_Z + " regions.");
    }
    public static void Init()
    {
        Util.PrintSection("World");

        // Initialize regions.
        for (int x = 0; x < REGION_SIZE_X; x++)
        {
            REGIONS[x] = new RegionHolder[REGION_SIZE_Y];
            for (int y = 0; y < REGION_SIZE_Y; y++)
            {
                REGIONS[x][y] = new RegionHolder(x, y);
            }
        }

        // Set surrounding regions.
        for (int x = 0; x < REGION_SIZE_X; x++)
        {
            for (int y = 0; y < REGION_SIZE_Y; y++)
            {
                List <RegionHolder> surroundingRegions = new List <RegionHolder>();
                for (int sx = x - 1; sx <= (x + 1); sx++)
                {
                    for (int sy = y - 1; sy <= (y + 1); sy++)
                    {
                        if (((sx >= 0) && (sx < REGION_SIZE_X) && (sy >= 0) && (sy < REGION_SIZE_Y)))
                        {
                            surroundingRegions.Add(REGIONS[sx][sy]);
                        }
                    }
                }
                REGIONS[x][y].SetSurroundingRegions(surroundingRegions.ToArray());
            }
        }

        LogManager.Log("WorldManager: Initialized " + REGION_SIZE_X + " by " + REGION_SIZE_Y + " regions.");
    }