예제 #1
0
        /// <summary>
        /// Spawns monster.
        /// </summary>
        /// <remarks>
        /// Parameters:
        /// - int    monsterId
        /// - string mapName
        /// - float  x
        /// - float  y
        /// - float  z
        /// </remarks>
        /// <param name="L"></param>
        /// <returns></returns>
        private int spawn(IntPtr L)
        {
            var monsterId = Melua.luaL_checkinteger(L, 1);
            var mapName   = Melua.luaL_checkstring(L, 2);
            var x         = (float)Melua.luaL_checknumber(L, 3);
            var y         = (float)Melua.luaL_checknumber(L, 4);
            var z         = (float)Melua.luaL_checknumber(L, 5);

            Melua.lua_pop(L, 5);

            var map = ChannelServer.Instance.World.GetMap(mapName);

            if (map == null)
            {
                return(Melua.melua_error(L, "Map '{0}' not found.", mapName));
            }

            var monster = new Monster(monsterId, NpcType.Monster);

            monster.Position = new Position(x, y, z);

            map.AddMonster(monster);

            return(0);
        }
예제 #2
0
        /// <summary>
        /// Warps player to given location.
        /// </summary>
        /// <remarks>
        /// Parameters:
        /// - string mapName
        /// - number x
        /// - number y
        /// - number z
        /// </remarks>
        /// <param name="L"></param>
        /// <returns></returns>
        private int warp(IntPtr L)
        {
            var conn = this.GetConnectionFromState(L);

            var mapName = Melua.luaL_checkstring(L, 1);
            var x       = (float)Melua.luaL_checknumber(L, 2);
            var y       = (float)Melua.luaL_checknumber(L, 3);
            var z       = (float)Melua.luaL_checknumber(L, 4);

            Melua.lua_pop(L, 4);

            try
            {
                conn.SelectedCharacter.Warp(mapName, x, y, z);
            }
            catch (ArgumentException ex)
            {
                Melua.lua_pushstring(L, ex.Message);
                Melua.lua_error(L);
            }

            return(0);
        }
예제 #3
0
        /// <summary>
        /// Adds NPC to world.
        /// </summary>
        /// <remarks>
        /// The parameter `dialogFunctionName` can be the name of a Lua
        /// function name, the name of a client-side dialog, or a
        /// localization key. A client-side dialog controls the NPC name
        /// and appearance, while a localization key will simply send the
        /// key in one message. A Lua function allows for completely
        /// custom dialog.
        ///
        /// Parameters:
        /// - int monsterId
        /// - string name / dictId
        /// - string mapName
        /// - number x
        /// - number y
        /// - number z
        /// - int    direction
        /// - string dialogFunctionName
        /// </remarks>
        /// <param name="L"></param>
        /// <returns></returns>
        private int addnpc(IntPtr L)
        {
            var monsterId = Melua.luaL_checkinteger(L, 1);
            var name      = Melua.luaL_checkstring(L, 2);
            var mapName   = Melua.luaL_checkstring(L, 3);
            var x         = (float)Melua.luaL_checknumber(L, 4);
            var y         = (float)Melua.luaL_checknumber(L, 5);
            var z         = (float)Melua.luaL_checknumber(L, 6);
            var direction = Melua.luaL_checkinteger(L, 7);
            var dialog    = Melua.luaL_checkstring(L, 8);

            Melua.lua_pop(L, 8);

            var map = ChannelServer.Instance.World.GetMap(mapName);

            if (map == null)
            {
                return(Melua.melua_error(L, "Map '{0}' not found.", mapName));
            }

            // Wrap name in localization code if applicable
            if (this.IsLocalizationKey(name))
            {
                name = this.WrapLocalizationKey(name);
            }

            var monster = new Monster(monsterId, NpcType.NPC);

            monster.Name       = name;
            monster.DialogName = dialog;
            monster.Position   = new Position(x, y, z);
            monster.Direction  = new Direction(direction);

            map.AddMonster(monster);

            return(0);
        }
예제 #4
0
        /// <summary>
        /// Adds warp to world.
        /// </summary>
        /// <remarks>
        /// Parameters:
        /// - string warpName
        /// - number direction
        /// - string fromMapName
        /// - number fromX
        /// - number fromY
        /// - number fromZ
        /// - string toMapName
        /// - number toX
        /// - number toY
        /// - number toZ
        /// </remarks>
        /// <param name="L"></param>
        /// <returns></returns>
        private int addwarp(IntPtr L)
        {
            var warpName    = Melua.luaL_checkstring(L, 1);
            var direction   = Melua.luaL_checknumber(L, 2);
            var fromMapName = Melua.luaL_checkstring(L, 3);
            var fromX       = (float)Melua.luaL_checknumber(L, 4);
            var fromY       = (float)Melua.luaL_checknumber(L, 5);
            var fromZ       = (float)Melua.luaL_checknumber(L, 6);
            var toMapName   = Melua.luaL_checkstring(L, 7);
            var toX         = (float)Melua.luaL_checknumber(L, 8);
            var toY         = (float)Melua.luaL_checknumber(L, 9);
            var toZ         = (float)Melua.luaL_checknumber(L, 10);

            Melua.lua_pop(L, 10);

            // Check "from" map data
            var fromMapData = ChannelServer.Instance.Data.MapDb.Find(fromMapName);

            if (fromMapData == null)
            {
                return(Melua.melua_error(L, "Map '{0}' not found in data.", fromMapName));
            }

            // Check map in world
            var map = ChannelServer.Instance.World.GetMap(fromMapData.Id);

            if (map == null)
            {
                return(Melua.melua_error(L, "Map '{0}' not found in world.", fromMapName));
            }

            // Check "to" map data
            var toMapData = ChannelServer.Instance.Data.MapDb.Find(toMapName);

            if (toMapData == null)
            {
                return(Melua.melua_error(L, "Map '{0}' not found in data.", toMapName));
            }

            // It would be pointless to check the "to map in world" here,
            // since the target map could easily be on an entirely different
            // server. *This* channel may not have that map.

            // Get name, preferably a localization key
            var name = toMapName;

            if (toMapData.LocalKey != "?")
            {
                name = this.WrapLocalizationKey(toMapData.LocalKey);
            }

            // Create a warping monster...
            var monster = new Monster(40001, NpcType.NPC);

            monster.Name         = name;
            monster.WarpName     = warpName;
            monster.Position     = new Position(fromX, fromY, fromZ);
            monster.Direction    = new Direction(direction);
            monster.WarpLocation = new Location(toMapData.Id, toX, toY, toZ);

            map.AddMonster(monster);

            return(0);
        }