示例#1
0
        /// <summary>
        /// Initializes the Character.
        /// </summary>
        /// <param name="map">The Map to place the Character on.</param>
        /// <param name="skelManager">The SkeletonManager to use for the Character's skeletons.</param>
        public virtual void Initialize(Map map, SkeletonManager skelManager)
        {
            // HACK: This is quite a dirty way to do this
            _map = map;
            _interpolator.Teleport(Position);

            _characterSprite = CreateCharacterSprite(this, this, skelManager);

            CharacterSprite.SetSet(BodyInfo.Stand, BodyInfo.Size);
            CharacterSprite.SetBody(BodyInfo.Body);
        }
示例#2
0
        /// <summary>
        /// Handles when a map is changed and sets the new map to daw on the <see cref="MiniMapForm"/>.
        /// </summary>
        /// <param name="map">The map the user is on.</param>
        public void MapChanged(Map map)
        {
            // Show the map name in the form
            Text = "Mini Map: " + map.Name;

            // Assign the new map as a new grh
            ScaledMapGrh.SetGrh(GrhInfo.GetData("MiniMap", map.ID.ToString()));

            // Resize the form to match the new scaled map grh
            this.ClientSize = ScaledMapGrh.Size;
        }
        void RecvSetMap(IIPSocket conn, BitStream r)
        {
            var mapID = r.ReadMapID();

            // Create the new map
            var newMap = new Map(mapID, World.Camera, World);
            newMap.Load(ContentPaths.Build, false, _dynamicEntityFactory);

            // Clear quest requirements caches
            UserInfo.HasStartQuestRequirements.Clear();

            // Change maps
            World.Map = newMap;

            // Unload all map content from the previous map and from the new map loading
            GameplayScreen.ScreenManager.Content.Unload(ContentLevel.Map);

            // Change the screens, if needed
            GameplayScreen.ScreenManager.SetScreen<GameplayScreen>();
        }
示例#4
0
        /// <summary>
        /// Places a <see cref="MapGrh"/> on the map.
        /// </summary>
        /// <param name="map">The map to place the <see cref="MapGrh"/> on.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>.</param>
        /// <param name="screenPos">The screen position to place the <see cref="MapGrh"/>.</param>
        /// <param name="useTileMode">If TileMode should be used.</param>
        /// <param name="gd">The <see cref="GrhData"/> to place. Set to null to attempt to use the <see cref="GrhData"/> that is
        /// currently selected in the <see cref="GlobalState"/>.</param>
        /// <returns>The <see cref="MapGrh"/> instance that was added, or null if the the <see cref="MapGrh"/> could not be
        /// added for any reason.</returns>
        public static MapGrh PlaceMapGrh(Map map, ICamera2D camera, Vector2 screenPos, bool useTileMode, GrhData gd = null)
        {
            // Get the GrhData to place from the global state
            if (gd == null)
                gd = GlobalState.Instance.Map.GrhToPlace.GrhData;

            // Ensure we have a GrhData to place
            if (gd == null)
                return null;

            // Get the world position to place it
            var drawPos = camera.ToWorld(screenPos);
            drawPos = GridAligner.Instance.Align(drawPos, useTileMode).Round();

            // Cache some other values
            var selGrhGrhIndex = gd.GrhIndex;
            var isForeground = EditorSettings.Default.MapGrh_DefaultIsForeground;
            var depth = EditorSettings.Default.MapGrh_DefaultDepth;
            var drawPosArea = drawPos.ToRectangle(new Vector2(2), true);

            if (!useTileMode)
            {
                // Make sure the same MapGrh doesn't already exist at that position
                if (map.Spatial.Contains<MapGrh>(drawPosArea,
                    x =>
                    x.Grh.GrhData.GrhIndex == selGrhGrhIndex && x.IsForeground == isForeground &&
                    Math.Round(x.Position.QuickDistance(drawPos)) <= 1))
                    return null;
            }
            else
            {
                // Make sure the same MapGrh doesn't already exist at that position on the same layer
                if (map.Spatial.Contains<MapGrh>(drawPosArea,
                    x =>
                    x.Grh.GrhData.GrhIndex == selGrhGrhIndex && x.IsForeground == isForeground &&
                    Math.Round(x.Position.QuickDistance(drawPos)) <= 1))
                    return null;

                // In TileMode, do not allow ANY MapGrh at the same position and layer depth. And if it does exist, instead of aborting,
                // delete the existing one.
                var existingMapGrhs = map.Spatial.GetMany<MapGrh>(drawPosArea,
                    x =>
                    x.LayerDepth == depth && x.IsForeground == isForeground && Math.Round(x.Position.QuickDistance(drawPos)) <= 1);
                foreach (var toDelete in existingMapGrhs)
                {
                    Debug.Assert(toDelete != null);
                    if (log.IsDebugEnabled)
                        log.DebugFormat("TileMode caused MapGrh `{0}` to be overwritten.", toDelete);

                    map.RemoveMapGrh(toDelete);
                }

                Debug.Assert(
                    !map.Spatial.Contains<MapGrh>(drawPosArea,
                        x =>
                        x.LayerDepth == depth && x.IsForeground == isForeground &&
                        Math.Round(x.Position.QuickDistance(drawPos)) <= 1));
            }

            // Create the new MapGrh and add it to the map
            var g = new Grh(gd, AnimType.Loop, map.GetTime());
            var mg = new MapGrh(g, drawPos, isForeground) { LayerDepth = depth };
            map.AddMapGrh(mg);

            return mg;
        }
示例#5
0
        /// <summary>
        /// Places a <see cref="MapGrh"/> on the map.
        /// </summary>
        /// <param name="map">The map to place the <see cref="MapGrh"/> on.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>.</param>
        /// <param name="screenPos">The screen position to place the <see cref="MapGrh"/>.</param>
        /// <param name="useTileMode">If TileMode should be used.</param>
        /// <param name="gd">The <see cref="GrhData"/> to place. Set to null to attempt to use the <see cref="GrhData"/> that is
        /// currently selected in the <see cref="GlobalState"/>.</param>
        /// <returns>The <see cref="MapGrh"/> instance that was added, or null if the the <see cref="MapGrh"/> could not be
        /// added for any reason.</returns>
        public static MapGrh PlaceMapGrhAtScreenPos(Map map, ICamera2D camera, Vector2 screenPos, bool useTileMode, GrhData gd = null)
        {
            // Get the world position to place it
            var worldPos = camera.ToWorld(screenPos);

            return PlaceMapGrhAtWorldPos(map, worldPos, useTileMode, gd);
        }