예제 #1
0
        public static BackgroundItem CreateBackgroundFromProperty(WzImageProperty source, int x, int y, int rx, int ry, int cx, int cy, int a, BackgroundType type, bool front, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List <WzObject> usedProps, bool flip)
        {
            source = WzInfoTools.GetRealProperty(source);

            if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
            {
                source = ((WzSubProperty)source).WzProperties[0];
            }

            if (source is WzCanvasProperty) //one-frame
            {
                WzVectorProperty origin = (WzVectorProperty)source["origin"];

                if (source.MSTag == null)
                {
                    source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).PngProperty.GetPNG(false));
                    usedProps.Add(source);
                }

                return(new BackgroundItem(cx, cy, rx, ry, type, a, front, new DXObject(x - origin.X.Value /* - mapCenterX*/, y - origin.Y.Value /* - mapCenterY*/, (Texture2D)source.MSTag), flip));
            }
            else if (source is WzSubProperty) //animooted
            {
                WzCanvasProperty frameProp;
                int             i      = 0;
                List <DXObject> frames = new List <DXObject>();

                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int?delay = InfoTool.GetOptionalInt(frameProp["delay"]);

                    if (delay == null)
                    {
                        delay = 100;
                    }

                    if (frameProp.MSTag == null)
                    {
                        frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.PngProperty.GetPNG(false));
                        usedProps.Add(frameProp);
                    }

                    WzVectorProperty origin = (WzVectorProperty)frameProp["origin"];
                    frames.Add(new DXObject(x - origin.X.Value /* - mapCenterX*/, y - origin.Y.Value /* - mapCenterY*/, (int)delay, (Texture2D)frameProp.MSTag));
                }

                return(new BackgroundItem(cx, cy, rx, ry, type, a, front, frames, flip));
            }
            else
            {
                throw new Exception("unsupported property type in map simulator");
            }
        }
예제 #2
0
 public void LoadTileSetList()
 {
     lock (hcsm.MultiBoard)
     {
         if (tileSetList.SelectedItem == null)
         {
             return;
         }
         tileImagesContainer.Controls.Clear();
         string selectedSetName = (string)tileSetList.SelectedItem;
         if (!Program.InfoManager.TileSets.ContainsKey(selectedSetName))
         {
             return;
         }
         WzImage tileSetImage = Program.InfoManager.TileSets[selectedSetName];
         int?    mag          = InfoTool.GetOptionalInt(tileSetImage["info"]["mag"]);
         foreach (WzSubProperty tCat in tileSetImage.WzProperties)
         {
             if (tCat.Name == "info")
             {
                 continue;
             }
             if (ApplicationSettings.randomTiles)
             {
                 WzCanvasProperty canvasProp = (WzCanvasProperty)tCat["0"];
                 if (canvasProp == null)
                 {
                     continue;
                 }
                 ImageViewer item        = tileImagesContainer.Add(canvasProp.GetLinkedWzCanvasBitmap(), tCat.Name, true);
                 TileInfo[]  randomInfos = new TileInfo[tCat.WzProperties.Count];
                 for (int i = 0; i < randomInfos.Length; i++)
                 {
                     randomInfos[i] = TileInfo.Get((string)tileSetList.SelectedItem, tCat.Name, tCat.WzProperties[i].Name, mag);
                 }
                 item.Tag        = randomInfos;
                 item.MouseDown += new MouseEventHandler(tileItem_Click);
                 item.MouseUp   += new MouseEventHandler(ImageViewer.item_MouseUp);
             }
             else
             {
                 foreach (WzCanvasProperty tile in tCat.WzProperties)
                 {
                     ImageViewer item = tileImagesContainer.Add(tile.GetLinkedWzCanvasBitmap(), tCat.Name + "/" + tile.Name, true);
                     item.Tag        = TileInfo.Get((string)tileSetList.SelectedItem, tCat.Name, tile.Name, mag);
                     item.MouseDown += new MouseEventHandler(tileItem_Click);
                     item.MouseUp   += new MouseEventHandler(ImageViewer.item_MouseUp);
                 }
             }
         }
     }
 }
예제 #3
0
        public void LoadLife(WzImage mapImage, Board mapBoard)
        {
            WzImageProperty lifeParent = mapImage["life"];

            if (lifeParent == null)
            {
                return;
            }
            foreach (WzSubProperty life in lifeParent.WzProperties)
            {
                string    id          = InfoTool.GetString(life["id"]);
                int       x           = InfoTool.GetInt(life["x"]);
                int       y           = InfoTool.GetInt(life["y"]);
                int       cy          = InfoTool.GetInt(life["cy"]);
                int?      mobTime     = InfoTool.GetOptionalInt(life["mobTime"]);
                int?      info        = InfoTool.GetOptionalInt(life["info"]);
                int?      team        = InfoTool.GetOptionalInt(life["team"]);
                int       rx0         = InfoTool.GetInt(life["rx0"]);
                int       rx1         = InfoTool.GetInt(life["rx1"]);
                MapleBool flip        = InfoTool.GetOptionalBool(life["f"]);
                MapleBool hide        = InfoTool.GetOptionalBool(life["hide"]);
                string    type        = InfoTool.GetString(life["type"]);
                string    limitedname = InfoTool.GetOptionalString(life["limitedname"]);

                switch (type)
                {
                case "m":
                    MobInfo mobInfo = MobInfo.Get(id);
                    if (mobInfo == null)
                    {
                        continue;
                    }
                    mapBoard.BoardItems.Mobs.Add((MobInstance)mobInfo.CreateInstance(mapBoard, x, cy, x - rx0, rx1 - x, cy - y, limitedname, mobTime, flip, hide, info, team));
                    break;

                case "n":
                    NpcInfo npcInfo = NpcInfo.Get(id);
                    if (npcInfo == null)
                    {
                        continue;
                    }
                    mapBoard.BoardItems.NPCs.Add((NpcInstance)npcInfo.CreateInstance(mapBoard, x, cy, x - rx0, rx1 - x, cy - y, limitedname, mobTime, flip, hide, info, team));
                    break;

                default:
                    throw new Exception("invalid life type " + type);
                }
            }
        }
예제 #4
0
        public static TileInfo GetWithDefaultNo(string tS, string u, string no, string defaultNo)
        {
            int?            mag          = InfoTool.GetOptionalInt(Program.InfoManager.TileSets[tS]["info"]["mag"]);
            WzImageProperty prop         = Program.InfoManager.TileSets[tS][u];
            WzImageProperty tileInfoProp = prop[no];

            if (tileInfoProp == null)
            {
                tileInfoProp = prop[defaultNo];
            }
            if (tileInfoProp.HCTag == null)
            {
                tileInfoProp.HCTag = TileInfo.Load((WzCanvasProperty)tileInfoProp, tS, u, no, mag);
            }
            return((TileInfo)tileInfoProp.HCTag);
        }
예제 #5
0
        public void LoadPortals(WzImage mapImage, Board mapBoard)
        {
            WzSubProperty portalParent = (WzSubProperty)mapImage["portal"];

            foreach (WzSubProperty portal in portalParent.WzProperties)
            {
                int       x                = InfoTool.GetInt(portal["x"]);
                int       y                = InfoTool.GetInt(portal["y"]);
                string    pt               = Program.InfoManager.PortalTypeById[InfoTool.GetInt(portal["pt"])];
                int       tm               = InfoTool.GetInt(portal["tm"]);
                string    tn               = InfoTool.GetString(portal["tn"]);
                string    pn               = InfoTool.GetString(portal["pn"]);
                string    image            = InfoTool.GetOptionalString(portal["image"]);
                string    script           = InfoTool.GetOptionalString(portal["script"]);
                int?      verticalImpact   = InfoTool.GetOptionalInt(portal["verticalImpact"]);
                int?      horizontalImpact = InfoTool.GetOptionalInt(portal["horizontalImpact"]);
                int?      hRange           = InfoTool.GetOptionalInt(portal["hRange"]);
                int?      vRange           = InfoTool.GetOptionalInt(portal["vRange"]);
                int?      delay            = InfoTool.GetOptionalInt(portal["delay"]);
                MapleBool hideTooltip      = InfoTool.GetOptionalBool(portal["hideTooltip"]);
                MapleBool onlyOnce         = InfoTool.GetOptionalBool(portal["onlyOnce"]);
                mapBoard.BoardItems.Portals.Add(PortalInfo.GetPortalInfoByType(pt).CreateInstance(mapBoard, x, y, pn, tn, tm, script, delay, hideTooltip, onlyOnce, horizontalImpact, verticalImpact, image, hRange, vRange));
            }
        }
예제 #6
0
        /// <summary>
        /// Load frames from WzSubProperty or WzCanvasProperty
        /// </summary>
        /// <param name="texturePool"></param>
        /// <param name="source"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="spineAni">Spine animation path</param>
        /// <returns></returns>
        private static List <IDXObject> LoadFrames(TexturePool texturePool, WzImageProperty source, int x, int y, GraphicsDevice device, ref List <WzObject> usedProps, string spineAni = null)
        {
            List <IDXObject> frames = new List <IDXObject>();

            source = WzInfoTools.GetRealProperty(source);

            if (source is WzSubProperty property1 && property1.WzProperties.Count == 1)
            {
                source = property1.WzProperties[0];
            }

            if (source is WzCanvasProperty property) //one-frame
            {
                bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, spineAni);
                if (!bLoadedSpine)
                {
                    string    canvasBitmapPath = property.FullPath;
                    Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath);
                    if (textureFromCache != null)
                    {
                        source.MSTag = textureFromCache;
                    }
                    else
                    {
                        source.MSTag = property.GetLinkedWzCanvasBitmap().ToTexture2D(device);

                        // add to cache
                        texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)source.MSTag);
                    }
                }
                usedProps.Add(source);

                if (source.MSTagSpine != null)
                {
                    WzSpineObject         spineObject = (WzSpineObject)source.MSTagSpine;
                    System.Drawing.PointF origin      = property.GetCanvasOriginPosition();

                    frames.Add(new DXSpineObject(spineObject, x, y, origin));
                }
                else if (source.MSTag != null)
                {
                    Texture2D             texture = (Texture2D)source.MSTag;
                    System.Drawing.PointF origin  = property.GetCanvasOriginPosition();

                    frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture));
                }
                else // fallback
                {
                    Texture2D             texture = Properties.Resources.placeholder.ToTexture2D(device);
                    System.Drawing.PointF origin  = property.GetCanvasOriginPosition();

                    frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture));
                }
            }
            else if (source is WzSubProperty) // animated
            {
                WzImageProperty _frameProp;
                int             i = 0;

                while ((_frameProp = WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    if (_frameProp is WzSubProperty) // issue with 867119250
                    {
                        frames.AddRange(LoadFrames(texturePool, _frameProp, x, y, device, ref usedProps, null));
                    }
                    else
                    {
                        WzCanvasProperty frameProp;

                        if (_frameProp is WzUOLProperty) // some could be UOL. Ex: 321100000 Mirror world: [Mirror World] Leafre
                        {
                            WzObject linkVal = ((WzUOLProperty)_frameProp).LinkValue;
                            if (linkVal is WzCanvasProperty linkCanvas)
                            {
                                frameProp = linkCanvas;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else
                        {
                            frameProp = (WzCanvasProperty)_frameProp;
                        }

                        int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100);

                        bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, spineAni);
                        if (!bLoadedSpine)
                        {
                            if (frameProp.MSTag == null)
                            {
                                string    canvasBitmapPath = frameProp.FullPath;
                                Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath);
                                if (textureFromCache != null)
                                {
                                    frameProp.MSTag = textureFromCache;
                                }
                                else
                                {
                                    frameProp.MSTag = frameProp.GetLinkedWzCanvasBitmap().ToTexture2D(device);

                                    // add to cache
                                    texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)frameProp.MSTag);
                                }
                            }
                        }
                        usedProps.Add(frameProp);

                        if (frameProp.MSTagSpine != null)
                        {
                            WzSpineObject         spineObject = (WzSpineObject)frameProp.MSTagSpine;
                            System.Drawing.PointF origin      = frameProp.GetCanvasOriginPosition();

                            frames.Add(new DXSpineObject(spineObject, x, y, origin, delay));
                        }
                        else if (frameProp.MSTag != null)
                        {
                            Texture2D             texture = (Texture2D)frameProp.MSTag;
                            System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                            frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay));
                        }
                        else
                        {
                            Texture2D             texture = Properties.Resources.placeholder.ToTexture2D(device);
                            System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                            frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay));
                        }
                    }
                }
            }
            return(frames);
        }
예제 #7
0
        public void LoadMisc(WzImage mapImage, Board mapBoard)
        {
            // All of the following properties are extremely esoteric features that only appear in a handful of maps.
            // They are implemented here for the sake of completeness, and being able to repack their maps without corruption.

            WzImageProperty clock    = mapImage["clock"];
            WzImageProperty ship     = mapImage["shipObj"];
            WzImageProperty area     = mapImage["area"];
            WzImageProperty healer   = mapImage["healer"];
            WzImageProperty pulley   = mapImage["pulley"];
            WzImageProperty BuffZone = mapImage["BuffZone"];
            WzImageProperty swimArea = mapImage["swimArea"];

            if (clock != null)
            {
                Clock clockInstance = new Clock(mapBoard, new Rectangle(InfoTool.GetInt(clock["x"]), InfoTool.GetInt(clock["y"]), InfoTool.GetInt(clock["width"]), InfoTool.GetInt(clock["height"])));
                mapBoard.BoardItems.Add(clockInstance, false);
            }
            if (ship != null)
            {
                string     objPath      = InfoTool.GetString(ship["shipObj"]);
                string[]   objPathParts = objPath.Split("/".ToCharArray());
                string     oS           = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]);
                string     l0           = objPathParts[objPathParts.Length - 3];
                string     l1           = objPathParts[objPathParts.Length - 2];
                string     l2           = objPathParts[objPathParts.Length - 1];
                ObjectInfo objInfo      = ObjectInfo.Get(oS, l0, l1, l2);
                ShipObject shipInstance = new ShipObject(objInfo, mapBoard,
                                                         InfoTool.GetInt(ship["x"]),
                                                         InfoTool.GetInt(ship["y"]),
                                                         InfoTool.GetOptionalInt(ship["z"]),
                                                         InfoTool.GetOptionalInt(ship["x0"]),
                                                         InfoTool.GetInt(ship["tMove"]),
                                                         InfoTool.GetInt(ship["shipKind"]),
                                                         InfoTool.GetBool(ship["f"]));
                mapBoard.BoardItems.Add(shipInstance, false);
            }
            if (area != null)
            {
                foreach (WzImageProperty prop in area.WzProperties)
                {
                    int  x1       = InfoTool.GetInt(prop["x1"]);
                    int  x2       = InfoTool.GetInt(prop["x2"]);
                    int  y1       = InfoTool.GetInt(prop["y1"]);
                    int  y2       = InfoTool.GetInt(prop["y2"]);
                    Area currArea = new Area(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), prop.Name);
                    mapBoard.BoardItems.Add(currArea, false);
                }
            }
            if (healer != null)
            {
                string     objPath        = InfoTool.GetString(healer["healer"]);
                string[]   objPathParts   = objPath.Split("/".ToCharArray());
                string     oS             = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]);
                string     l0             = objPathParts[objPathParts.Length - 3];
                string     l1             = objPathParts[objPathParts.Length - 2];
                string     l2             = objPathParts[objPathParts.Length - 1];
                ObjectInfo objInfo        = ObjectInfo.Get(oS, l0, l1, l2);
                Healer     healerInstance = new Healer(objInfo, mapBoard,
                                                       InfoTool.GetInt(healer["x"]),
                                                       InfoTool.GetInt(healer["yMin"]),
                                                       InfoTool.GetInt(healer["yMax"]),
                                                       InfoTool.GetInt(healer["healMin"]),
                                                       InfoTool.GetInt(healer["healMax"]),
                                                       InfoTool.GetInt(healer["fall"]),
                                                       InfoTool.GetInt(healer["rise"]));
                mapBoard.BoardItems.Add(healerInstance, false);
            }
            if (pulley != null)
            {
                string     objPath        = InfoTool.GetString(pulley["pulley"]);
                string[]   objPathParts   = objPath.Split("/".ToCharArray());
                string     oS             = WzInfoTools.RemoveExtension(objPathParts[objPathParts.Length - 4]);
                string     l0             = objPathParts[objPathParts.Length - 3];
                string     l1             = objPathParts[objPathParts.Length - 2];
                string     l2             = objPathParts[objPathParts.Length - 1];
                ObjectInfo objInfo        = ObjectInfo.Get(oS, l0, l1, l2);
                Pulley     pulleyInstance = new Pulley(objInfo, mapBoard,
                                                       InfoTool.GetInt(pulley["x"]),
                                                       InfoTool.GetInt(pulley["y"]));
                mapBoard.BoardItems.Add(pulleyInstance, false);
            }
            if (BuffZone != null)
            {
                foreach (WzImageProperty zone in BuffZone.WzProperties)
                {
                    int      x1       = InfoTool.GetInt(zone["x1"]);
                    int      x2       = InfoTool.GetInt(zone["x2"]);
                    int      y1       = InfoTool.GetInt(zone["y1"]);
                    int      y2       = InfoTool.GetInt(zone["y2"]);
                    int      id       = InfoTool.GetInt(zone["ItemID"]);
                    int      interval = InfoTool.GetInt(zone["Interval"]);
                    int      duration = InfoTool.GetInt(zone["Duration"]);
                    BuffZone currZone = new BuffZone(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), id, interval, duration, zone.Name);
                    mapBoard.BoardItems.Add(currZone, false);
                }
            }
            if (swimArea != null)
            {
                foreach (WzImageProperty prop in swimArea.WzProperties)
                {
                    int      x1       = InfoTool.GetInt(prop["x1"]);
                    int      x2       = InfoTool.GetInt(prop["x2"]);
                    int      y1       = InfoTool.GetInt(prop["y1"]);
                    int      y2       = InfoTool.GetInt(prop["y2"]);
                    SwimArea currArea = new SwimArea(mapBoard, new Rectangle(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs(x2 - x1), Math.Abs(y2 - y1)), prop.Name);
                    mapBoard.BoardItems.Add(currArea, false);
                }
            }
            // Some misc items are not implemented here; these are copied byte-to-byte from the original. See VerifyMapPropsKnown for details.
        }
예제 #8
0
        public void LoadFootholds(WzImage mapImage, Board mapBoard)
        {
            List <FootholdAnchor> anchors        = new List <FootholdAnchor>();
            WzSubProperty         footholdParent = (WzSubProperty)mapImage["foothold"];
            int            layer;
            FootholdAnchor a;
            FootholdAnchor b;
            Dictionary <int, FootholdLine> fhs = new Dictionary <int, FootholdLine>();

            foreach (WzSubProperty layerProp in footholdParent.WzProperties)
            {
                layer = int.Parse(layerProp.Name);
                Layer l = mapBoard.Layers[layer];
                foreach (WzSubProperty platProp in layerProp.WzProperties)
                {
                    int zM = int.Parse(platProp.Name);
                    l.zMList.Add(zM);
                    foreach (WzSubProperty fhProp in platProp.WzProperties)
                    {
                        a = new FootholdAnchor(mapBoard, InfoTool.GetInt(fhProp["x1"]), InfoTool.GetInt(fhProp["y1"]), layer, zM, false);
                        b = new FootholdAnchor(mapBoard, InfoTool.GetInt(fhProp["x2"]), InfoTool.GetInt(fhProp["y2"]), layer, zM, false);
                        int       num            = int.Parse(fhProp.Name);
                        int       next           = InfoTool.GetInt(fhProp["next"]);
                        int       prev           = InfoTool.GetInt(fhProp["prev"]);
                        MapleBool cantThrough    = InfoTool.GetOptionalBool(fhProp["cantThrough"]);
                        MapleBool forbidFallDown = InfoTool.GetOptionalBool(fhProp["forbidFallDown"]);
                        int?      piece          = InfoTool.GetOptionalInt(fhProp["piece"]);
                        int?      force          = InfoTool.GetOptionalInt(fhProp["force"]);
                        if (a.X != b.X || a.Y != b.Y)
                        {
                            FootholdLine fh = new FootholdLine(mapBoard, a, b, forbidFallDown, cantThrough, piece, force);
                            fh.num  = num;
                            fh.prev = prev;
                            fh.next = next;
                            mapBoard.BoardItems.FootholdLines.Add(fh);
                            fhs[num] = fh;
                            anchors.Add(a);
                            anchors.Add(b);
                        }
                    }
                }

                anchors.Sort(new Comparison <FootholdAnchor>(FootholdAnchor.FHAnchorSorter));
                for (int i = 0; i < anchors.Count - 1; i++)
                {
                    a = anchors[i];
                    b = anchors[i + 1];
                    if (a.X == b.X && a.Y == b.Y)
                    {
                        FootholdAnchor.MergeAnchors(a, b); // Transfer lines from b to a
                        anchors.RemoveAt(i + 1);           // Remove b
                        i--;                               // Fix index after we removed b
                    }
                }
                foreach (FootholdAnchor anchor in anchors)
                {
                    if (anchor.connectedLines.Count > 2)
                    {
                        foreach (FootholdLine line in anchor.connectedLines)
                        {
                            if (IsAnchorPrevOfFoothold(anchor, line))
                            {
                                if (fhs.ContainsKey(line.prev))
                                {
                                    line.prevOverride = fhs[line.prev];
                                }
                            }
                            else
                            {
                                if (fhs.ContainsKey(line.next))
                                {
                                    line.nextOverride = fhs[line.next];
                                }
                            }
                        }
                    }
                    mapBoard.BoardItems.FHAnchors.Add(anchor);
                }
                anchors.Clear();
            }
        }
예제 #9
0
        public static TileInfo Get(string tS, string u, string no)
        {
            int?mag = InfoTool.GetOptionalInt(Program.InfoManager.TileSets[tS]["info"]["mag"]);

            return(Get(tS, u, no, mag));
        }
        /// <summary>
        /// Load frames from WzSubProperty or WzCanvasProperty
        /// </summary>
        /// <param name="texturePool"></param>
        /// <param name="source"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="spineAni">Spine animation path</param>
        /// <returns></returns>
        private static List <IDXObject> LoadFrames(TexturePool texturePool, WzImageProperty source, int x, int y, GraphicsDevice device, ref List <WzObject> usedProps, string spineAni = null)
        {
            List <IDXObject> frames = new List <IDXObject>();

            source = WzInfoTools.GetRealProperty(source);

            if (source is WzSubProperty property1 && property1.WzProperties.Count == 1)
            {
                source = property1.WzProperties[0];
            }

            if (source is WzCanvasProperty property) //one-frame
            {
                bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, spineAni);
                if (!bLoadedSpine)
                {
                    string    canvasBitmapPath = property.FullPath;
                    Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath);
                    if (textureFromCache != null)
                    {
                        source.MSTag = textureFromCache;
                    }
                    else
                    {
                        source.MSTag = BoardItem.TextureFromBitmap(device, property.GetLinkedWzCanvasBitmap());

                        // add to cache
                        texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)source.MSTag);
                    }
                }
                usedProps.Add(source);

                if (source.MSTagSpine != null)
                {
                    WzSpineObject         spineObject = (WzSpineObject)source.MSTagSpine;
                    System.Drawing.PointF origin      = property.GetCanvasOriginPosition();

                    frames.Add(new DXSpineObject(spineObject, x, y, origin));
                }
                else if (source.MSTag != null)
                {
                    Texture2D             texture = (Texture2D)source.MSTag;
                    System.Drawing.PointF origin  = property.GetCanvasOriginPosition();

                    frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture));
                }
                else // fallback
                {
                    Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                    System.Drawing.PointF origin  = property.GetCanvasOriginPosition();

                    frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture));
                }
            }
            else if (source is WzSubProperty) // animated
            {
                WzCanvasProperty frameProp;
                int i = 0;

                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100);

                    bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, spineAni);
                    if (!bLoadedSpine)
                    {
                        if (frameProp.MSTag == null)
                        {
                            string    canvasBitmapPath = frameProp.FullPath;
                            Texture2D textureFromCache = texturePool.GetTexture(canvasBitmapPath);
                            if (textureFromCache != null)
                            {
                                frameProp.MSTag = textureFromCache;
                            }
                            else
                            {
                                frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap());

                                // add to cache
                                texturePool.AddTextureToPool(canvasBitmapPath, (Texture2D)frameProp.MSTag);
                            }
                        }
                    }
                    usedProps.Add(frameProp);

                    if (frameProp.MSTagSpine != null)
                    {
                        WzSpineObject         spineObject = (WzSpineObject)frameProp.MSTagSpine;
                        System.Drawing.PointF origin      = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXSpineObject(spineObject, x, y, origin, delay));
                    }
                    else if (frameProp.MSTag != null)
                    {
                        Texture2D             texture = (Texture2D)frameProp.MSTag;
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay));
                    }
                    else
                    {
                        Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXObject(x - (int)origin.X, y - (int)origin.Y, texture, delay));
                    }
                }
            }
            return(frames);
        }
        /// <summary>
        /// Map item
        /// </summary>
        /// <param name="source"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="mapCenterX"></param>
        /// <param name="mapCenterY"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="flip"></param>
        /// <returns></returns>
        public static MapItem CreateMapItemFromProperty(WzImageProperty source, int x, int y, Point mapCenter, GraphicsDevice device, ref List <WzObject> usedProps, bool flip)
        {
            source = WzInfoTools.GetRealProperty(source);

            if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
            {
                source = ((WzSubProperty)source).WzProperties[0];
            }

            if (source is WzCanvasProperty) //one-frame
            {
                bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, null);
                if (!bLoadedSpine)
                {
                    if (source.MSTag == null)
                    {
                        source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).GetLinkedWzCanvasBitmap());
                    }
                }
                usedProps.Add(source);

                if (source.MSTagSpine != null)
                {
                    WzSpineObject         spineObject = (WzSpineObject)source.MSTagSpine;
                    System.Drawing.PointF origin      = ((WzCanvasProperty)source).GetCanvasOriginPosition();

                    return(new MapItem(new DXSpineObject(spineObject, x + mapCenter.X, y + mapCenter.Y, origin), flip));
                }
                else if (source.MSTag != null)
                {
                    Texture2D             texture = (Texture2D)source.MSTag;
                    System.Drawing.PointF origin  = ((WzCanvasProperty)source).GetCanvasOriginPosition();

                    return(new MapItem(new DXObject(x - (int)origin.X + mapCenter.X, y - (int)origin.Y + mapCenter.Y, texture), flip));
                }
                else // fallback
                {
                    Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                    System.Drawing.PointF origin  = ((WzCanvasProperty)source).GetCanvasOriginPosition();

                    return(new MapItem(new DXObject(x - (int)origin.X + mapCenter.X, y - (int)origin.Y + mapCenter.Y, texture), flip));
                }
            }
            else if (source is WzSubProperty) // animated
            {
                WzCanvasProperty frameProp;
                int i = 0;
                List <IDXObject> frames = new List <IDXObject>();
                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100);

                    bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, null);
                    if (!bLoadedSpine)
                    {
                        if (frameProp.MSTag == null)
                        {
                            frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap());
                        }
                    }
                    usedProps.Add(frameProp);

                    if (frameProp.MSTagSpine != null)
                    {
                        WzSpineObject         spineObject = (WzSpineObject)frameProp.MSTagSpine;
                        System.Drawing.PointF origin      = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXSpineObject(spineObject, x + mapCenter.X, y + mapCenter.Y, origin, delay));
                    }
                    else if (frameProp.MSTag != null)
                    {
                        Texture2D             texture = (Texture2D)frameProp.MSTag;
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXObject(x - (int)origin.X + mapCenter.X, y - (int)origin.Y + mapCenter.Y, texture, delay));
                    }
                    else
                    {
                        Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();

                        frames.Add(new DXObject(x - (int)origin.X + mapCenter.X, y - (int)origin.Y + mapCenter.Y, texture, delay));
                    }
                }
                return(new MapItem(frames, flip));
            }
            else
            {
                throw new Exception("unsupported property type in map simulator");
            }
        }
        /// <summary>
        /// Background
        /// </summary>
        /// <param name="source"></param>
        /// <param name="bgInstance"></param>
        /// <param name="mapCenterX"></param>
        /// <param name="mapCenterY"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="flip"></param>
        /// <returns></returns>
        public static BackgroundItem CreateBackgroundFromProperty(WzImageProperty source, BackgroundInstance bgInstance, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List <WzObject> usedProps, bool flip)
        {
            source = WzInfoTools.GetRealProperty(source);
            if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
            {
                source = ((WzSubProperty)source).WzProperties[0];
            }

            if (source is WzCanvasProperty) //one-frame
            {
                bool bLoadedSpine = LoadSpineMapObjectItem(source, source, device, bgInstance.SpineAni);
                if (!bLoadedSpine)
                {
                    if (source.MSTag == null)
                    {
                        source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).GetLinkedWzCanvasBitmap());
                    }
                }
                usedProps.Add(source);

                if (source.MSTagSpine != null)
                {
                    WzSpineObject         spineObject = (WzSpineObject)source.MSTagSpine;
                    System.Drawing.PointF origin      = ((WzCanvasProperty)source).GetCanvasOriginPosition();
                    DXSpineObject         dxobj       = new DXSpineObject(spineObject, bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, origin);

                    return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, dxobj, flip, bgInstance.screenMode));
                }
                else if (source.MSTag != null)
                {
                    Texture2D             texture = (Texture2D)source.MSTag;
                    System.Drawing.PointF origin  = ((WzCanvasProperty)source).GetCanvasOriginPosition();
                    DXObject dxobj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture);

                    return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, dxobj, flip, bgInstance.screenMode));
                }
                else  // default fallback if all things fail
                {
                    Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                    System.Drawing.PointF origin  = ((WzCanvasProperty)source).GetCanvasOriginPosition();
                    DXObject dxobj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture);

                    return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, dxobj, flip, bgInstance.screenMode));
                }
            }
            else if (source is WzSubProperty) // animated
            {
                WzCanvasProperty frameProp;
                int i = 0;
                List <IDXObject> frames = new List <IDXObject>();
                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int delay = (int)InfoTool.GetOptionalInt(frameProp["delay"], 100);

                    bool bLoadedSpine = LoadSpineMapObjectItem((WzImageProperty)frameProp.Parent, frameProp, device, bgInstance.SpineAni);
                    if (!bLoadedSpine)
                    {
                        if (frameProp.MSTag == null)
                        {
                            frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap());
                        }
                    }
                    usedProps.Add(source);

                    if (frameProp.MSTagSpine != null)
                    {
                        WzSpineObject         spineObject = (WzSpineObject)frameProp.MSTagSpine;
                        System.Drawing.PointF origin      = frameProp.GetCanvasOriginPosition();
                        DXSpineObject         dxobj       = new DXSpineObject(spineObject, bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, origin, delay);

                        frames.Add(dxobj);
                    }
                    else if (frameProp.MSTag != null)
                    {
                        Texture2D             texture = (Texture2D)frameProp.MSTag;
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();
                        DXObject dxObj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture, delay);

                        frames.Add(dxObj);
                    }
                    else // default fallback if all things fail
                    {
                        Texture2D             texture = BoardItem.TextureFromBitmap(device, Properties.Resources.placeholder);
                        System.Drawing.PointF origin  = frameProp.GetCanvasOriginPosition();
                        DXObject dxObj = new DXObject(bgInstance.BaseX - (int)origin.X /* - mapCenterX*/, bgInstance.BaseY - (int)origin.Y /* - mapCenterY*/, texture, delay);

                        frames.Add(dxObj);
                    }
                }
                return(new BackgroundItem(bgInstance.cx, bgInstance.cy, bgInstance.rx, bgInstance.ry, bgInstance.type, bgInstance.a, bgInstance.front, frames, flip, bgInstance.screenMode));
            }
            else
            {
                throw new Exception("Unsupported property type in map simulator");
            }
        }
예제 #13
0
파일: MapLoader.cs 프로젝트: xnum/hasuite
        private static void LoadLife(WzImage mapImage, Board mapBoard)
        {
            IWzImageProperty lifeParent = mapImage["life"];

            if (lifeParent == null)
            {
                return;
            }
            foreach (WzSubProperty life in lifeParent.WzProperties)
            {
                string id = InfoTool.GetString(life["id"]);
                int    x  = InfoTool.GetInt(life["x"]);
                //int y = InfoTool.GetInt(life["y"]);
                int       cy          = InfoTool.GetInt(life["cy"]);
                int?      mobTime     = InfoTool.GetOptionalInt(life["mobTime"]);
                int?      info        = InfoTool.GetOptionalInt(life["info"]);
                int?      team        = InfoTool.GetOptionalInt(life["team"]);
                int       rx0         = InfoTool.GetInt(life["rx0"]);
                int       rx1         = InfoTool.GetInt(life["rx1"]);
                MapleBool flip        = InfoTool.GetOptionalBool(life["f"]);
                MapleBool hide        = InfoTool.GetOptionalBool(life["hide"]);
                string    type        = InfoTool.GetString(life["type"]);
                string    limitedname = InfoTool.GetOptionalString(life["limitedname"]);

                switch (type)
                {
                case "m":
                    WzImage mobImage = (WzImage)Program.WzManager["mob"][id + ".img"];
                    if (!mobImage.Parsed)
                    {
                        mobImage.ParseImage();
                    }
                    if (mobImage.HCTag == null)
                    {
                        mobImage.HCTag = MobInfo.Load(mobImage);
                    }
                    MobInfo mobInfo = (MobInfo)mobImage.HCTag;
                    //mapBoard.BoardItems.Mobs.Add((MobInstance)mobInfo.CreateInstance(mapBoard, x, cy, rx0, rx1, mobTime, flip, hide, false));
                    mapBoard.BoardItems.Mobs.Add((LifeInstance)mobInfo.CreateInstance(mapBoard, x, cy, rx0, rx1, limitedname, mobTime, flip, hide, info, team, false));
                    break;

                case "n":
                    WzImage npcImage = (WzImage)Program.WzManager["npc"][id + ".img"];
                    if (!npcImage.Parsed)
                    {
                        npcImage.ParseImage();
                    }
                    if (npcImage.HCTag == null)
                    {
                        npcImage.HCTag = NpcInfo.Load(npcImage);
                    }
                    NpcInfo npcInfo = (NpcInfo)npcImage.HCTag;
                    //mapBoard.BoardItems.NPCs.Add((NpcInstance)npcInfo.CreateInstance(mapBoard, x, cy, rx0, rx1, mobTime, flip, hide, false));
                    mapBoard.BoardItems.NPCs.Add((LifeInstance)npcInfo.CreateInstance(mapBoard, x, cy, rx0, rx1, limitedname, mobTime, flip, hide, info, team, false));
                    break;

                default:
                    throw new Exception("invalid life type " + type);
                }
            }
        }
        /// <summary>
        /// Background
        /// </summary>
        /// <param name="source"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="rx"></param>
        /// <param name="ry"></param>
        /// <param name="cx"></param>
        /// <param name="cy"></param>
        /// <param name="a"></param>
        /// <param name="type"></param>
        /// <param name="front"></param>
        /// <param name="mapCenterX"></param>
        /// <param name="mapCenterY"></param>
        /// <param name="device"></param>
        /// <param name="usedProps"></param>
        /// <param name="flip"></param>
        /// <returns></returns>
        public static BackgroundItem CreateBackgroundFromProperty(WzImageProperty source, int x, int y, int rx, int ry, int cx, int cy, int a, BackgroundType type, bool front, int mapCenterX, int mapCenterY, GraphicsDevice device, ref List <WzObject> usedProps, bool flip)
        {
            source = WzInfoTools.GetRealProperty(source);
            if (source is WzSubProperty && ((WzSubProperty)source).WzProperties.Count == 1)
            {
                source = ((WzSubProperty)source).WzProperties[0];
            }

            if (source is WzCanvasProperty) //one-frame
            {
                if (source.MSTag == null)
                {
                    source.MSTag = BoardItem.TextureFromBitmap(device, ((WzCanvasProperty)source).GetLinkedWzCanvasBitmap());
                    usedProps.Add(source);
                }

                Texture2D texture = (Texture2D)source.MSTag;
                if (texture != null)
                {
                    System.Drawing.PointF origin = ((WzCanvasProperty)source).GetCanvasOriginPosition();
                    DXObject dxobj = new DXObject(x - (int)origin.X /* - mapCenterX*/, y - (int)origin.Y /* - mapCenterY*/, texture);

                    return(new BackgroundItem(cx, cy, rx, ry, type, a, front, dxobj, flip));
                }
                else
                {
                    throw new Exception("Texture is null for the background property.");
                }
            }
            else if (source is WzSubProperty) //animooted
            {
                WzCanvasProperty frameProp;
                int             i      = 0;
                List <DXObject> frames = new List <DXObject>();
                while ((frameProp = (WzCanvasProperty)WzInfoTools.GetRealProperty(source[(i++).ToString()])) != null)
                {
                    int?delay = InfoTool.GetOptionalInt(frameProp["delay"]);
                    if (delay == null)
                    {
                        delay = 100;
                    }

                    if (frameProp.MSTag == null)
                    {
                        frameProp.MSTag = BoardItem.TextureFromBitmap(device, frameProp.GetLinkedWzCanvasBitmap());
                        usedProps.Add(frameProp);
                    }

                    Texture2D texture = (Texture2D)frameProp.MSTag;
                    if (texture != null)
                    {
                        System.Drawing.PointF origin = frameProp.GetCanvasOriginPosition();
                        frames.Add(new DXObject(x - (int)origin.X /* - mapCenterX*/, y - (int)origin.Y /* - mapCenterY*/, texture, (int)delay));
                    }
                    else
                    {
                        throw new Exception("Texture is null for the animation");
                    }
                }
                return(new BackgroundItem(cx, cy, rx, ry, type, a, front, frames, flip));
            }
            else
            {
                throw new Exception("Unsupported property type in map simulator");
            }
        }