Пример #1
0
        /// <summary>
        /// Load the map.
        /// </summary>
        public static Map Load()
        {
            FileHandler handler = new FileHandler();
            //string path = Config.GetDataPath() + "world/" + Config.GetMapName();  TODO: REMOVE
            string path = Config.GetDataPath() + Config.GetWorldDirectory() + Config.GetMapName();
            BinaryReader bReader = new BinaryReader(File.Open(path, FileMode.Open));
            int sizex = bReader.ReadUInt16(); //Height
            int sizey = bReader.ReadUInt16(); //Width
            Map map = new Map(sizex, sizey);

            uint tileCount = bReader.ReadUInt32(); //Tile Count
            for (int i = 0; i < tileCount; i++) {
                ushort x = bReader.ReadUInt16(); //X position
                ushort y = bReader.ReadUInt16(); //Y position
                byte z = bReader.ReadByte(); //Z position
                ushort id = bReader.ReadUInt16(); //Tile ID
                byte itemCount = bReader.ReadByte();

                ushort[] mainTile = new ushort[itemCount + 1]; //Item count + ground
                mainTile[0] = id;
                //map.SetTile(x, y, z, new Tile(Item.CreateItem(id)));

                for (int j = 1; j <= itemCount; j++) {
                    ushort itemID = bReader.ReadUInt16();
                    mainTile[j] = itemID;
                }
                int hashCode = Position.HashCode(x, y);
                map.mainTiles[z].Add(hashCode, mainTile);
            }

            bReader.Close();
            return map;
        }
Пример #2
0
        public Map LoadMap(string mapPath)
        {
            // try {
            BinaryReader bReader = new BinaryReader(File.Open(mapPath, FileMode.Open));
            int sizex = bReader.ReadUInt16(); //Height
            int sizey = bReader.ReadUInt16(); //Width
            Map map = new Map(sizex, sizey);
            uint tileCount = bReader.ReadUInt32(); //Tile Count
            for (int i = 0; i < tileCount; i++) {
                ushort x = bReader.ReadUInt16(); //X position
                ushort y = bReader.ReadUInt16(); //Y position
                byte z = bReader.ReadByte(); //Z position
                ushort id = bReader.ReadUInt16(); //Tile ID

                map.SetTile(x, y, z, new Tile(Item.CreateItem(id)));
                byte itemCount = bReader.ReadByte();
                for (int j = 0; j < itemCount; j++) {
                    ushort itemID = bReader.ReadUInt16();
                    Item item = Item.CreateItem(itemID);
                    map.AddThing(item, new Position(x, y, z));
                }
            }

            bReader.Close();
                 //TODO: Remove this code
               map.SetTile(320, 320, 6, new Tile(Item.CreateItem("Grass")));
            return map;
            //} catch (Exception e) {
            //    lastError = e.ToString();
            //    return null;
            //}
        }
Пример #3
0
 public GameWorld(Map map)
 {
     gameMap = map;
     playersOnline = new Dictionary<string, Player>();
     creaturesOnline = new Dictionary<uint, Creature>();
     eventHandler = new EventHandler();
     eventHandler.World = this;
     eventHandler.Start();
     lockThis = new Object();
     chatSystem = new ChatSystem(map, playersOnline);
     pathFinder = new PathFinder(map);
     movingSystem = new MovingSystem(map, this);
     spellSystem = new SpellSystem(map);
 }
Пример #4
0
 /* /// <summary>
  /// This method returns a set of things that are in the
  /// spell's vicinity where the spell's vicinity is defined as
  /// the set of things that are either hit by the spell or for
  /// whom the spell effect is visible.
  /// </summary>
  /// <param name="map">A reference to the game map.</param>
  /// <returns>The things in this spell's vacinity.</returns>
  public ThingSet GetThingsInVicinity(Map map) {
      //TODO: Finish
      return map.GetThingsInVicinity(new Position(32097, 32217, 7));
  }*/
 public void CastSpell(Map map)
 {
 }
Пример #5
0
 public virtual void AppendNotifyOfDeath(Item corpse, Map gameMap)
 {
     if (CurrentHP == 0) {
         CreatureAttacking = null;
     }
 }
Пример #6
0
 /// <summary>
 /// Used to initialize the chat system.
 /// </summary>
 /// <param name="mapRef">A reference to the game map.</param>
 /// <param name="playersOnlineRef">A reference to the players online.</param>
 public ChatSystem(Map mapRef, Dictionary<string, Player> playersOnlineRef)
 {
     gameMap = mapRef;
     playersOnline = playersOnlineRef;
 }
Пример #7
0
 /// <summary>
 /// Constructs this spell system with the
 /// specified game map.
 /// </summary>
 /// <param name="gameMap"></param>
 public SpellSystem(Map gameMap)
 {
     map = gameMap;
 }
Пример #8
0
 public PathFinder(Map gameMapRef)
 {
     gameMap = gameMapRef;
 }
Пример #9
0
 /// <summary>
 /// Construct this object.
 /// </summary>
 /// <param name="gameMap">Reference to the game map.</param>
 public MovingSystem(Map gameMap, GameWorld gameWorld)
 {
     map = gameMap;
     world = gameWorld;
 }
Пример #10
0
 /// <summary>
 /// Adds the entire screen map.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="player"></param>
 public void AddScreenMap(Map map, Player player)
 {
     Position pos = player.CurrentPosition;
     netmsg.AddU16(0x0A); //Add screen map header
     netmsg.AddPosition(pos);
     AddFullMap(pos, map, player);
     netmsg.AddByte(0x00); //End of 0x0A header
     //netmsg.AddByte(0x00);
     //netmsg.AddByte(0x03);
 }
Пример #11
0
 public override void AppendNotifyOfDeath(Item corpse, Map gameMap)
 {
     AddLoot(corpse);
     gameMap.GetThingsInVicinity(CurrentPosition);
     //Give experience to all creatures who attacked
     foreach (AttackersInformation atkInfo in attackersInfoList) {
             if (atkInfo.Attacker.LogedIn) {
                 uint xp = FigureOutExperienceAmt(atkInfo.DamageByCreature, totalDamageDealt);
                 atkInfo.Attacker.AddExperienceGain(xp * Config.GetXPRate());
             }
     }
     if (IsSummon()) {
         Master.RemoveSummon(this);
     }
     World.AppendRemoveMonster(this);
 }
Пример #12
0
 public virtual void AddTeleport(Map gameMap)
 {
 }
Пример #13
0
        /// <summary>
        /// Adds the login bytes to the player's client.
        /// </summary>
        /// <param name="player">The player for whom to add the login bytes.</param>
        /// <param name="map">A reference to the map.</param>
        public void AddLoginBytes(Player player, Map map)
        {
            AddMOTD(Config.GetMOTD(), Config.GetMessageNumber());

            netmsg.AddU16(0x01); //Login header
            netmsg.AddU32(player.GetID()); //ID sent to the client

            AddScreenMap(map, player);

            AddEffect(MagicEffect.BLUEBALL, player.CurrentPosition);

            AddFullInventory(player);
            AddStats(player);

            AddStatusMessage(Config.GetWelcomeMessage());

            UpdateWorldLight(map.GetWorldLightLevel());
            UpdateCreatureLight(player, player.GetLightLevel());
        }
Пример #14
0
        /// <summary>
        /// Adds the map information as specified by the parameters.
        /// </summary>
        /// <param name="pos">Center of the map position.</param>
        /// <param name="width">Width of the map.</param>
        /// <param name="height">Height of the map.</param>
        /// <param name="map">A reference to the map.</param>
        /// <param name="player">The player for whom the 
        /// map information is sent.</param>
        private void AddMapInfo(Position pos, int width, int height, Map map, Player player)
        {
            potentialAddTiles.Clear();

            short startZ = 0, endZ = 0, zStep = 0;

            GetZIter(ref startZ, ref endZ, ref zStep, pos.z);

            for (short iterZ = startZ; iterZ != endZ + zStep; iterZ += zStep)
            {
                Position posTmp = new Position(pos.x, pos.y, (byte)iterZ);
                AddFloorInfo(posTmp, width, height, (short)(pos.z - iterZ), map, player);
            }

            //End sending map
            netmsg.SkipBytes(-1);
            netmsg.AddByte(0xFE);
        }
Пример #15
0
 /// <summary>
 /// Adds the map information as specified by the parameters.
 /// </summary>
 /// <param name="x">Center of map relative to client.</param>
 /// <param name="y">Center to map relative to client.</param>
 /// <param name="z">Center to map relative to client.</param>
 /// <param name="width">Width of map to send.</param>
 /// <param name="height">Height of map to send.</param>
 /// <param name="map">A reference to the gamemap.</param>
 /// <param name="player">The player for whom the
 /// map information is sent.</param>
 private void AddMapInfo(int x, int y, byte z, int width, int height, Map map, Player player)
 {
     AddMapInfo(new Position((ushort)x, (ushort)y, z), width, height, map, player);
 }
Пример #16
0
        /// <summary>
        /// Adds the entire map.
        /// </summary>
        /// <param name="pos">Map center position.</param>
        /// <param name="map">A reference to the map.</param>
        /// <param name="player">The player for whom 
        /// the map information is being sent.</param>
        private void AddFullMap(Position pos, Map map, Player player)
        {
            Position startPos = new Position();
            startPos.x = (ushort)(pos.x - 8);
            startPos.y = (ushort)(pos.y - 6);
            startPos.z = pos.z;

            AddMapInfo(startPos, 18, 14, map, player);
        }
Пример #17
0
        /// <summary>
        /// Adds the a z level of a map.
        /// </summary>
        /// <param name="pos">The floor's center position.</param>
        /// <param name="width">Floor weight to add.</param>
        /// <param name="height">Floor height to add.</param>
        /// <param name="offset">Floor offset relative to the player.</param>
        /// <param name="map">A reference to the map.</param>
        /// <param name="player">The player for whom the map information is sent.</param>
        private void AddFloorInfo(Position pos, int width, int height, short offset, Map map, Player player)
        {
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Tile tile =  map.GetTile(x + pos.x + offset, y + pos.y + offset, pos.z);

                    potentialAddTiles.Add(tile);

                    if (tile != null)
                    {
                        foreach (Tile potentialTile in potentialAddTiles)
                        {
                            AddMapTile(potentialTile, player);
                        }

                        potentialAddTiles.Clear();
                    }
                }
            }
        }
Пример #18
0
        /// <summary>
        /// Sends a message to move a player's client by one tile.
        /// </summary>
        /// <param name="direction">The direction to move.</param>
        /// <param name="oldPos">Player's old position.</param>
        /// <param name="newPos">Player's new position.</param>
        /// <param name="map">A reference to the map.</param>
        /// <param name="player">The player for whom the 
        /// map information is being sent.</param>
        public void AddScreenMoveByOne(Direction direction, Position oldPos, Position newPos, Map map, Player player)
        {
            // TODO: OPTIMIZE?
            ushort header = (ushort)(direction + 0x0B); //0x0B, 0x0C, 0x0D, 0x0E
            netmsg.AddU16(header);

            switch (direction)
            {
                case Direction.NORTH:
                    AddMapInfo(oldPos.x - 8, newPos.y - 6, newPos.z, 18, 1, map, player);
                    break;

                case Direction.EAST:
                    AddMapInfo(newPos.x + 9, newPos.y - 6, newPos.z, 1, 14, map, player);
                    break;

                case Direction.SOUTH:
                    AddMapInfo(oldPos.x - 8, newPos.y + 7, newPos.z, 18, 1, map, player);
                    break;

                case Direction.WEST:
                    AddMapInfo(newPos.x - 8, newPos.y - 6, newPos.z, 1, 14, map, player);
                    break;

                default:
                    throw new Exception("Invalid direction sent in AddScreenMoveByOne()");
            }

            netmsg.AddByte(0x00); //End of move
        }