public BombService(IHubContext <UserHub> hubContext, IMapService mapService, IPlayerService playerService, IPlayerDeathMediator playerDeathMediator, IEnemyMovementService enemyMovementService) { bombs = new List <BombDTO>(); destructableObstacles = MapConstants.GetDestructableObstacles(); _hubContext = hubContext; this.mapService = mapService; _playerService = playerService; _playerDeathMediator = playerDeathMediator; _enemyMovementService = enemyMovementService; }
public MapService() { obstacleList = MapConstants.GetObstacleList(); }
/// <summary> /// /// </summary> /// <param name="minimapFrameProperty">UI.wz/UIWindow2.img/MiniMap</param> /// <param name="mapBoard"></param> /// <param name="device"></param> /// <param name="MapName">The map name. i.e The Hill North</param> /// <param name="StreetName">The street name. i.e Hidden street</param> /// <returns></returns> public static MinimapItem CreateMinimapFromProperty(WzSubProperty minimapFrameProperty, Board mapBoard, GraphicsDevice device, string MapName, string StreetName) { if (mapBoard.MiniMap == null) { return(null); } WzSubProperty maxMapProperty = (WzSubProperty)minimapFrameProperty["MaxMap"]; WzSubProperty miniMapProperty = (WzSubProperty)minimapFrameProperty["MinMap"]; WzSubProperty maxMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MaxMapMirror"]; // for Zero maps WzSubProperty miniMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MinMapMirror"]; // for Zero maps WzSubProperty useFrame; if (mapBoard.MapInfo.zeroSideOnly || MapConstants.IsZerosTemple(mapBoard.MapInfo.id)) // zero's temple { useFrame = maxMapMirrorProperty; } else { useFrame = maxMapProperty; } // Wz frames System.Drawing.Bitmap c = ((WzCanvasProperty)useFrame?["c"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap e = ((WzCanvasProperty)useFrame?["e"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap n = ((WzCanvasProperty)useFrame?["n"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap s = ((WzCanvasProperty)useFrame?["s"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap w = ((WzCanvasProperty)useFrame?["w"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap ne = ((WzCanvasProperty)useFrame?["ne"])?.GetLinkedWzCanvasBitmap(); // top right System.Drawing.Bitmap nw = ((WzCanvasProperty)useFrame?["nw"])?.GetLinkedWzCanvasBitmap(); // top left System.Drawing.Bitmap se = ((WzCanvasProperty)useFrame?["se"])?.GetLinkedWzCanvasBitmap(); // bottom right System.Drawing.Bitmap sw = ((WzCanvasProperty)useFrame?["sw"])?.GetLinkedWzCanvasBitmap(); // bottom left // Constants const float TOOLTIP_FONTSIZE = 10f; System.Drawing.Color color_bgFill = System.Drawing.Color.Transparent; System.Drawing.Color color_foreGround = System.Drawing.Color.White; string renderText = string.Format("{0}{1}{2}", StreetName, Environment.NewLine, MapName); // Map background image System.Drawing.Bitmap miniMapImage = mapBoard.MiniMap; // the original minimap image without UI frame overlay int effective_width = miniMapImage.Width + e.Width + w.Width; int effective_height = miniMapImage.Height + n.Height + s.Height; using (System.Drawing.Font font = new System.Drawing.Font(GLOBAL_FONT, TOOLTIP_FONTSIZE)) { // Get the width of the 'streetName' or 'mapName' System.Drawing.Graphics graphics_dummy = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)); // dummy image just to get the Graphics object for measuring string System.Drawing.SizeF tooltipSize = graphics_dummy.MeasureString(renderText, font); effective_width = Math.Max((int)tooltipSize.Width + nw.Width, effective_width); // set new width System.Drawing.Bitmap miniMapUIImage = new System.Drawing.Bitmap(effective_width, effective_height); int mapDrawPositionX = (effective_width / 2) - nw.Width; // map is on the center. The position relative to the UI using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(miniMapUIImage)) { // Frames and background UIFrameHelper.DrawUIFrame(graphics, color_bgFill, ne, nw, se, sw, e, w, n, s, null, effective_width, effective_height); graphics.DrawString( renderText, font, new System.Drawing.SolidBrush(color_foreGround), 50, 20); // Map mark if (Program.InfoManager.MapMarks.ContainsKey(mapBoard.MapInfo.mapMark)) { System.Drawing.Bitmap mapMark = Program.InfoManager.MapMarks[mapBoard.MapInfo.mapMark]; graphics.DrawImage(mapMark.ToImage(), 7, 17); } // Map image graphics.DrawImage(miniMapImage, mapDrawPositionX, // map is on the center n.Height); graphics.Flush(); } // Dots pixel System.Drawing.Bitmap bmp_DotPixel = new System.Drawing.Bitmap(2, 4); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp_DotPixel)) { graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Yellow), new System.Drawing.RectangleF(0, 0, bmp_DotPixel.Width, bmp_DotPixel.Height)); graphics.Flush(); } IDXObject dxObj_miniMapPixel = new DXObject(0, n.Height, bmp_DotPixel.ToTexture2D(device), 0); BaseDXDrawableItem item_pixelDot = new BaseDXDrawableItem(dxObj_miniMapPixel, false) { Position = new Point( mapDrawPositionX, // map is on the center 0) }; // Map Texture2D texturer_miniMap = miniMapUIImage.ToTexture2D(device); IDXObject dxObj = new DXObject(0, 0, texturer_miniMap, 0); MinimapItem item = new MinimapItem(dxObj, item_pixelDot); return(item); } }
/// <summary> /// /// </summary> /// <param name="minimapFrameProperty">UI.wz/UIWindow2.img/MiniMap</param> /// <param name="mapBoard"></param> /// <param name="device"></param> /// <param name="MapName">The map name. i.e The Hill North</param> /// <param name="StreetName">The street name. i.e Hidden street</param> /// <returns></returns> public static MinimapItem CreateMinimapFromProperty(WzSubProperty minimapFrameProperty, Board mapBoard, GraphicsDevice device, string MapName, string StreetName) { WzSubProperty maxMapProperty = (WzSubProperty)minimapFrameProperty["MaxMap"]; WzSubProperty miniMapProperty = (WzSubProperty)minimapFrameProperty["MinMap"]; WzSubProperty maxMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MaxMapMirror"]; // for Zero maps WzSubProperty miniMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MinMapMirror"]; // for Zero maps WzSubProperty useFrame; if (mapBoard.MapInfo.zeroSideOnly || MapConstants.IsZerosTemple(mapBoard.MapInfo.id)) // zero's temple { useFrame = maxMapMirrorProperty; } else { useFrame = maxMapProperty; } // Wz frames System.Drawing.Bitmap c = ((WzCanvasProperty)useFrame?["c"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap e = ((WzCanvasProperty)useFrame?["e"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap n = ((WzCanvasProperty)useFrame?["n"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap s = ((WzCanvasProperty)useFrame?["s"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap w = ((WzCanvasProperty)useFrame?["w"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap ne = ((WzCanvasProperty)useFrame?["ne"])?.GetLinkedWzCanvasBitmap(); // top right System.Drawing.Bitmap nw = ((WzCanvasProperty)useFrame?["nw"])?.GetLinkedWzCanvasBitmap(); // top left System.Drawing.Bitmap se = ((WzCanvasProperty)useFrame?["se"])?.GetLinkedWzCanvasBitmap(); // bottom right System.Drawing.Bitmap sw = ((WzCanvasProperty)useFrame?["sw"])?.GetLinkedWzCanvasBitmap(); // bottom left // Constants const string TOOLTIP_FONT = "Arial"; const float TOOLTIP_FONTSIZE = 10f; System.Drawing.Color color_bgFill = System.Drawing.Color.Transparent; System.Drawing.Color color_foreGround = System.Drawing.Color.White; // Dots pixel System.Drawing.Bitmap bmp_DotPixel = new System.Drawing.Bitmap(2, 4); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp_DotPixel)) { graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Yellow), new System.Drawing.RectangleF(0, 0, bmp_DotPixel.Width, bmp_DotPixel.Height)); graphics.Flush(); } IDXObject dxObj_miniMapPixel = new DXObject(0, n.Height, bmp_DotPixel.ToTexture2D(device), 0); BaseDXDrawableItem item_pixelDot = new BaseDXDrawableItem(dxObj_miniMapPixel, false); // Map background image System.Drawing.Bitmap miniMapImage = mapBoard.MiniMap; // the original minimap image without UI frame overlay int effective_width = miniMapImage.Width + e.Width + w.Width; int effective_height = miniMapImage.Height + n.Height + s.Height; using (System.Drawing.Font font = new System.Drawing.Font(TOOLTIP_FONT, TOOLTIP_FONTSIZE)) { System.Drawing.Bitmap miniMapUIImage = new System.Drawing.Bitmap(effective_width, effective_height); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(miniMapUIImage)) { // Frames and background UIFrameHelper.DrawUIFrame(graphics, color_bgFill, ne, nw, se, sw, e, w, n, s, null, effective_width, effective_height); graphics.DrawString( string.Format("{0}{1}{2}", StreetName, Environment.NewLine, MapName), font, new System.Drawing.SolidBrush(color_foreGround), 50, 20); // Map mark if (Program.InfoManager.MapMarks.ContainsKey(mapBoard.MapInfo.mapMark)) { System.Drawing.Bitmap mapMark = Program.InfoManager.MapMarks[mapBoard.MapInfo.mapMark]; graphics.DrawImage(mapMark.ToImage(), 7, 17); } // Map image graphics.DrawImage(miniMapImage, 10, n.Height); graphics.Flush(); } Texture2D texturer_miniMap = miniMapUIImage.ToTexture2D(device); IDXObject dxObj = new DXObject(0, 0, texturer_miniMap, 0); MinimapItem item = new MinimapItem(dxObj, item_pixelDot); return(item); } }
/// <summary> /// Draws the frame and the UI of the minimap. /// TODO: This whole thing needs to be dramatically simplified via further abstraction to keep it noob-proof :( /// </summary> /// <param name="minimapFrameProperty">UI.wz/UIWindow2.img/MiniMap</param> /// <param name="mapBoard"></param> /// <param name="device"></param> /// <param name="MapName">The map name. i.e The Hill North</param> /// <param name="StreetName">The street name. i.e Hidden street</param> /// <returns></returns> public static MinimapItem CreateMinimapFromProperty(WzSubProperty minimapFrameProperty, Board mapBoard, GraphicsDevice device, string MapName, string StreetName, WzDirectory SoundWZFile) { if (mapBoard.MiniMap == null) { return(null); } WzSubProperty maxMapProperty = (WzSubProperty)minimapFrameProperty["MaxMap"]; WzSubProperty miniMapProperty = (WzSubProperty)minimapFrameProperty["MinMap"]; WzSubProperty maxMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MaxMapMirror"]; // for Zero maps WzSubProperty miniMapMirrorProperty = (WzSubProperty)minimapFrameProperty["MinMapMirror"]; // for Zero maps WzSubProperty BtNpc = (WzSubProperty)minimapFrameProperty["BtNpc"]; // npc button WzSubProperty BtMin = (WzSubProperty)minimapFrameProperty["BtMin"]; // mininise button WzSubProperty BtMax = (WzSubProperty)minimapFrameProperty["BtMax"]; // maximise button WzSubProperty BtBig = (WzSubProperty)minimapFrameProperty["BtBig"]; // big button WzSubProperty BtMap = (WzSubProperty)minimapFrameProperty["BtMap"]; // world button WzSubProperty useFrame; if (mapBoard.MapInfo.zeroSideOnly || MapConstants.IsZerosTemple(mapBoard.MapInfo.id)) // zero's temple { useFrame = maxMapMirrorProperty; } else { useFrame = maxMapProperty; } // Wz frames System.Drawing.Bitmap c = ((WzCanvasProperty)useFrame?["c"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap e = ((WzCanvasProperty)useFrame?["e"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap n = ((WzCanvasProperty)useFrame?["n"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap s = ((WzCanvasProperty)useFrame?["s"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap w = ((WzCanvasProperty)useFrame?["w"])?.GetLinkedWzCanvasBitmap(); System.Drawing.Bitmap ne = ((WzCanvasProperty)useFrame?["ne"])?.GetLinkedWzCanvasBitmap(); // top right System.Drawing.Bitmap nw = ((WzCanvasProperty)useFrame?["nw"])?.GetLinkedWzCanvasBitmap(); // top left System.Drawing.Bitmap se = ((WzCanvasProperty)useFrame?["se"])?.GetLinkedWzCanvasBitmap(); // bottom right System.Drawing.Bitmap sw = ((WzCanvasProperty)useFrame?["sw"])?.GetLinkedWzCanvasBitmap(); // bottom left // Constants const float TOOLTIP_FONTSIZE = 10f; const int MAPMARK_IMAGE_ALIGN_LEFT = 7; // the number of pixels from the left to draw the map mark image const int MAP_IMAGE_PADDING = 2; // the number of pixels from the left to draw the minimap image System.Drawing.Color color_bgFill = System.Drawing.Color.Transparent; System.Drawing.Color color_foreGround = System.Drawing.Color.White; string renderText = string.Format("{0}{1}{2}", StreetName, Environment.NewLine, MapName); // Map background image System.Drawing.Bitmap miniMapImage = mapBoard.MiniMap; // the original minimap image without UI frame overlay int effective_width = miniMapImage.Width + e.Width + w.Width; int effective_height = miniMapImage.Height + n.Height + s.Height; using (System.Drawing.Font font = new System.Drawing.Font(GLOBAL_FONT, TOOLTIP_FONTSIZE)) { // Get the width of the 'streetName' or 'mapName' System.Drawing.Graphics graphics_dummy = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)); // dummy image just to get the Graphics object for measuring string System.Drawing.SizeF tooltipSize = graphics_dummy.MeasureString(renderText, font); effective_width = Math.Max((int)tooltipSize.Width + nw.Width, effective_width); // set new width int miniMapAlignXFromLeft = MAP_IMAGE_PADDING; if (effective_width > miniMapImage.Width) // if minimap is smaller in size than the (text + frame), minimap will be aligned to the center instead { miniMapAlignXFromLeft = (effective_width - miniMapImage.Width) / 2 /* - miniMapAlignXFromLeft*/; } System.Drawing.Bitmap miniMapUIImage = new System.Drawing.Bitmap(effective_width, effective_height); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(miniMapUIImage)) { // Frames and background UIFrameHelper.DrawUIFrame(graphics, color_bgFill, ne, nw, se, sw, e, w, n, s, null, effective_width, effective_height); // Map name + street name graphics.DrawString( renderText, font, new System.Drawing.SolidBrush(color_foreGround), 50, 20); // Map mark if (Program.InfoManager.MapMarks.ContainsKey(mapBoard.MapInfo.mapMark)) { System.Drawing.Bitmap mapMark = Program.InfoManager.MapMarks[mapBoard.MapInfo.mapMark]; graphics.DrawImage(mapMark.ToImage(), MAPMARK_IMAGE_ALIGN_LEFT, 17); } // Map image graphics.DrawImage(miniMapImage, miniMapAlignXFromLeft, // map is on the center n.Height); graphics.Flush(); } // Dots pixel System.Drawing.Bitmap bmp_DotPixel = new System.Drawing.Bitmap(2, 4); using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp_DotPixel)) { graphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Yellow), new System.Drawing.RectangleF(0, 0, bmp_DotPixel.Width, bmp_DotPixel.Height)); graphics.Flush(); } IDXObject dxObj_miniMapPixel = new DXObject(0, n.Height, bmp_DotPixel.ToTexture2D(device), 0); BaseDXDrawableItem item_pixelDot = new BaseDXDrawableItem(dxObj_miniMapPixel, false) { Position = new Point( miniMapAlignXFromLeft, // map is on the center 0) }; // Map Texture2D texturer_miniMap = miniMapUIImage.ToTexture2D(device); IDXObject dxObj = new DXObject(0, 0, texturer_miniMap, 0); MinimapItem minimapItem = new MinimapItem(dxObj, item_pixelDot); ////////////// Minimap buttons//////////////////// // This must be in order. // >>> If aligning from the left to the right. Items at the left must be at the top of the code // >>> If aligning from the right to the left. Items at the right must be at the top of the code with its (x position - parent width). // TODO: probably a wrapper class in the future, such as HorizontalAlignment and VerticalAlignment, or Grid/ StackPanel WzBinaryProperty BtMouseClickSoundProperty = (WzBinaryProperty)SoundWZFile["UI.img"]?["BtMouseClick"]; WzBinaryProperty BtMouseOverSoundProperty = (WzBinaryProperty)SoundWZFile["UI.img"]?["BtMouseOver"]; UIObject objUIBtMap = new UIObject(BtMap, BtMouseClickSoundProperty, BtMouseOverSoundProperty, false, new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device); objUIBtMap.X = effective_width - objUIBtMap.CanvasSnapshotWidth - 8; // render at the (width of minimap - obj width) UIObject objUIBtBig = new UIObject(BtBig, BtMouseClickSoundProperty, BtMouseOverSoundProperty, false, new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device); objUIBtBig.X = objUIBtMap.X - objUIBtBig.CanvasSnapshotWidth; // render at the (width of minimap - obj width) UIObject objUIBtMax = new UIObject(BtMax, BtMouseClickSoundProperty, BtMouseOverSoundProperty, false, new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device); objUIBtMax.X = objUIBtBig.X - objUIBtMax.CanvasSnapshotWidth; // render at the (width of minimap - obj width) UIObject objUIBtMin = new UIObject(BtMin, BtMouseClickSoundProperty, BtMouseOverSoundProperty, false, new Point(MAP_IMAGE_PADDING, MAP_IMAGE_PADDING), device); objUIBtMin.X = objUIBtMax.X - objUIBtMin.CanvasSnapshotWidth; // render at the (width of minimap - obj width) // BaseClickableUIObject objUINpc = new BaseClickableUIObject(BtNpc, false, new Point(objUIBtMap.CanvasSnapshotWidth + objUIBtBig.CanvasSnapshotWidth + objUIBtMax.CanvasSnapshotWidth + objUIBtMin.CanvasSnapshotWidth, MAP_IMAGE_PADDING), device); minimapItem.AddUIButtons(objUIBtMin); minimapItem.AddUIButtons(objUIBtMax); minimapItem.AddUIButtons(objUIBtBig); minimapItem.AddUIButtons(objUIBtMap); ////////////////////////////////////////////////// return(minimapItem); } }
public MapGeneratorAdapter() { mapGenerator = new MapGenerator(); obstacleList = MapConstants.GetObstacleList(); }