Beispiel #1
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;
            //}
        }
Beispiel #2
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;
        }
Beispiel #3
0
        /// <summary>
        /// Execute the specified command.
        /// </summary>
        /// <param name="world">A reference to the game world.</param>
        /// <param name="gameMap">A reference to the game map.</param>
        /// <param name="msg">The creature's message.</param>
        public static void ExecuteCommand(GameWorld world, Map gameMap,
            string msg, Creature creature)
        {
            string[] parameters = Regex.Split(msg, " ");

            commands[parameters[0].ToLower()].CommandMethod.
                Invoke(new object[] { world, gameMap, parameters, creature });
        }
Beispiel #4
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);
 }
Beispiel #5
0
 public virtual void AppendNotifyOfDeath(Item corpse, Map gameMap)
 {
     if (CurrentHP == 0) {
         CreatureAttacking = null;
     }
 }
Beispiel #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;
 }
Beispiel #7
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);
 }
Beispiel #8
0
 public abstract void AddScreenMap(Map map, Player player);
Beispiel #9
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)
 {
 }
Beispiel #10
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);
 }
Beispiel #11
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);
        }
Beispiel #12
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();
             }
         }
     }
 }
Beispiel #13
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 override void AddScreenMoveByOne(Direction direction, Position oldPos,
            Position newPos, Map map, Player player)
        {
            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
        }
Beispiel #14
0
 /// <summary>
 /// Adds the entire screen map.
 /// </summary>
 /// <param name="map"></param>
 /// <param name="player"></param>
 public override 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);
 }
Beispiel #15
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 override 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());
 }
Beispiel #16
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, ref short skipTiles)
 {
     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);
             if (tile != null) {
                 if (skipTiles >= 0) {
                     netmsg.AddByte((byte)skipTiles);
                     netmsg.AddByte(0xFF);
                 }
                 skipTiles = 0;
                 AddMapTile(tile, player);
             } else {
                 skipTiles++;
                 if (skipTiles == 0xFF) {
                     netmsg.AddByte(0xFF);
                     netmsg.AddByte(0xFF);
                     skipTiles = -1;
                 }
             }
         }
     }
 }
Beispiel #17
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);
 }
Beispiel #18
0
 public void AddLoginBytes(Map map)
 {
     AddAffected();
     protocolS.AddLoginBytes(this, map);
 }
Beispiel #19
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)
        {
            short skipTiles = -1;

            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, ref skipTiles);
            }

             if (skipTiles >= 0)
            {
                netmsg.AddByte((byte)skipTiles);
                netmsg.AddByte(0xFF);
            }
        }
Beispiel #20
0
 /// <summary>
 /// Moves the player's screen by one.
 /// </summary>
 /// <param name="direction">The direction to move the screen.</param>
 /// <param name="oldPos">player's old position.</param>
 /// <param name="newPos">player's new position.</param>
 /// <param name="gameMap">A reference to the game map.</param>
 public override void AddScreenMoveByOne(Direction direction, Position oldPos, Position newPos,
     Map gameMap)
 {
     AddAffected();
     protocolS.AddScreenMoveByOne(direction, oldPos, newPos, gameMap, this);
 }
Beispiel #21
0
 public abstract void AddLoginBytes(Player player, Map map);
Beispiel #22
0
 public override void AddTeleport(Map gameMap)
 {
     AddAffected();
     protocolS.AddScreenMap(gameMap, this);
 }
Beispiel #23
0
 public abstract void AddScreenMoveByOne(Direction direction, Position oldPos,
     Position newPos, Map map, Player player);
Beispiel #24
0
 /// <summary>
 /// Notify that the player is dead and handle logging
 /// the player out of the game world.
 /// </summary>
 /// <param name="corpse">Items to add to corpse.</param>
 public override void AppendNotifyOfDeath(Item corpse, Map gameMap)
 {
     AddAnonymousChat(ChatAnonymous.WHITE, "You are dead.");
     DoDeathLoss();
     AddLootItems(corpse);
     World.AppendRemovePlayer(this, true);
     ResetStats();
 }
Beispiel #25
0
 /// <summary>
 /// Constructs this spell system with the
 /// specified game map.
 /// </summary>
 /// <param name="gameMap"></param>
 public SpellSystem(Map gameMap)
 {
     map = gameMap;
 }
Beispiel #26
0
 public override void AddLoginBytes(Player player, Map map)
 {
     netmsg.AddByte(0x0A);
     netmsg.AddU32(player.GetID());
     netmsg.AddByte(0x32);
     netmsg.AddByte(0x00);
     AddScreenMap(map, player);
     AddStats(player);
     UpdateWorldLight(map.GetWorldLightLevel());
     UpdateCreatureLight(player, player.SpellLightLevel);
     AddSkills(player);
     AddFullInventory(player);
 }
Beispiel #27
0
 public virtual void AddTeleport(Map gameMap)
 {
 }
Beispiel #28
0
 public override void AddScreenMap(Map map, Player player)
 {
     Position pos = player.CurrentPosition;
     netmsg.AddByte(0x64);
     netmsg.AddPosition(player.CurrentPosition);
     AddFullMap(pos, map, player);
 }
Beispiel #29
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;
 }
Beispiel #30
0
 public override void AddScreenMoveByOne(Direction direction, Position oldPos, Position newPos, Map map, Player player)
 {
     throw new NotImplementedException();
 }