private void LoadSectors() { try { int sectorcount = SectorCount; if (Block != null) { while (Block.Width / sectorcount < MapInfo.ViewRange && sectorcount != 1) { sectorcount--; } sectorWidth = Block.Width / sectorcount; if (sectorWidth < MapInfo.ViewRange) { sectorWidth = MapInfo.ViewRange; } sectorHeight = Block.Height / sectorcount; if (sectorHeight < MapInfo.ViewRange) { sectorHeight = MapInfo.ViewRange; } } for (int y = 0; y < sectorcount; y++) { for (int x = 0; x < sectorcount; x++) { sectors[y, x] = new Sector(x, y, this); } } } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, ex.ToString()); } }
public List<Sector> GetSurroundingSectors(Sector sector) { int x = sector.X; int y = sector.Y; List<Sector> toret = new List<Sector>(); for (int column = x - 1; column <= x + 1; ++column) { for (int row = y - 1; row <= y + 1; ++row) { if (column < 0 || row < 0 || column >= SectorCount || row >= SectorCount) { continue; } toret.Add(sectors[row, column]); } } return toret; }
public List<ZoneCharacter> GetCharactersInRegion(Sector sector) { return GetCharactersBySectors(GetSurroundingSectors(sector)); }
public List<Sector> GetSectorsOutOfRange(Sector oldsector, Sector newsector) { return new List<Sector>(oldsector.SurroundingSectors.Except(newsector.SurroundingSectors)); }
public void Transfer(MapObject obj, Sector to) { Objects.Remove(obj.MapObjectID); to.AddObject(obj); // we remove object first to the 'non display region' ZoneCharacter character = obj as ZoneCharacter; List<Sector> oldsectors = Map.GetSectorsOutOfRange(this, to); // The idea of this function // 1. Remove obj from map for players that are out of range // (IF PLAYER) 2. Remove objects that are out of range for obj // (IF PLAYER) 3. Spawn objects that are new in range for obj // 4. Spawn obj for all players in new range using (var removeObjPacket = Handler7.RemoveObject(obj)) // Make new packet to remove object from map for others { // Even nederlands: Kijken of we mensen kunnen vinden in range? foreach (var victimObject in Map.GetObjectsBySectors(oldsectors)) { if (victimObject is NPC) continue; // NPC's are for noobs. Can't despawn if (victimObject is ZoneCharacter) { // Remove obj for player ZoneCharacter victim = victimObject as ZoneCharacter; victim.Client.SendPacket(removeObjPacket); } if (character != null) { // Despawn victimObject for obj using (var removeVictimPacket = Handler7.RemoveObject(victimObject)) { character.Client.SendPacket(removeVictimPacket); } } } } //we remove all the drops out of the character's region if (character != null && character.Client != null) { foreach (var dropoutofrange in Map.GetDropsBySectors(oldsectors)) { using (var despawndrop = Handler6.RemoveDrop(dropoutofrange)) { character.Client.SendPacket(despawndrop); } } } //now we spawn the object to other objects in map List<Sector> newsectors = Map.GetSectorsNewInRange(this, to); List<MapObject> objects = Map.GetObjectsBySectors(newsectors); using (var packet = obj.Spawn()) { foreach (var mapObject in objects) { if (mapObject is NPC) continue; //we don't respawn NPCs if (mapObject is ZoneCharacter) { ZoneCharacter rangechar = mapObject as ZoneCharacter; // Send spawn packet of the object (can be both a character and mob) to mapObject (a player) rangechar.Client.SendPacket(packet); } if (character != null) { // Send spawn packet of mapObject to character using (var spawn = mapObject.Spawn()) { character.Client.SendPacket(spawn); } } } } if (character != null && character.Client != null) { using (var spawndrops = Handler7.ShowDrops(Map.GetDropsBySectors(newsectors))) { character.Client.SendPacket(spawndrops); } } }