예제 #1
0
        /* DEPRECATED. Also was getting in the way of the overloaded constructor. And that's kinda annoying.
         * public Map(ContentManager c, SpriteBatch s, Vector2 screenBounds, Rectangle windowBounds, string spriteMap)
         * {
         *  Globals.Content = c;
         *  Globals.spriteBatch = s;
         *  Globals.screenBounds = screenBounds;
         *  Globals.windowBounds = windowBounds;
         *
         *  sprites = Globals.Content.Load<Texture2D>(spriteMap);
         *
         *  Globals.map = new List<List<Vector2>>();
         *  for (int y = 0; y < 20; y++)
         *  {
         *      List<Vector2> newRow = new List<Vector2>();
         *      for (int x = 0; x < 20; x++)
         *      {
         *          newRow.Add(new Vector2(10, 4));
         *      }
         *      Globals.map.Add(newRow);
         *  }
         *
         *  Globals.startPoint = Vector2.Zero; // Change this ASAP
         * }*/

        public Map(ContentManager c, SpriteBatch s, Vector2 screenBounds, Rectangle windowBounds, string spriteMap)
        {
            Globals.Content      = c;
            Globals.spriteBatch  = s;
            Globals.screenBounds = screenBounds;
            Globals.windowBounds = windowBounds;

            sprites = Globals.Content.Load <Texture2D>(spriteMap);

            Globals.map     = new List <List <Vector2> >();
            Globals.enemies = new List <Enemy>();

            XmlDocument reader        = new XmlDocument();
            XmlDocument overlayReader = new XmlDocument();
            string      filename      = "Maps/";

            if (Globals.fileOpen)
            {
                filename = "Saves/" + Globals.slotOpen + "/" + filename;
            }

            if (!File.Exists(filename + Globals.currentMap + "_new.xml"))
            {
                reader.Load(filename + Globals.currentMap + ".xml");
            }
            else
            {
                reader.Load(filename + Globals.currentMap + "_new.xml");
            }

            if (!File.Exists(filename + Globals.currentMap + "_events_new.xml"))
            {
                overlayReader.Load(filename + Globals.currentMap + "_events.xml");
            }
            else
            {
                overlayReader.Load(filename + Globals.currentMap + "_events_new.xml");
            }

            XmlNodeList mapx       = reader.GetElementsByTagName("mapx");
            XmlNodeList mapy       = reader.GetElementsByTagName("mapy");
            XmlNodeList tileset    = reader.GetElementsByTagName("tileset");
            XmlNodeList overlayset = overlayReader.GetElementsByTagName("overlayset");

            mapSize = new Vector2(Convert.ToInt32(mapx[0].InnerText), Convert.ToInt32(mapy[0].InnerText));
            fillEmptyMap(mapSize);
            fillEmptyOverlayMap(mapSize);
            fillEmptyPerms(mapSize);
            fillEmptyOverlayPerms(mapSize);
            fillEmptyEvents(mapSize);
            fillEmptyThrows(mapSize);

            foreach (XmlNode i in tileset)
            {
                int x     = Convert.ToInt32(i.Attributes["x"].Value);
                int y     = Convert.ToInt32(i.Attributes["y"].Value);
                int tilex = Convert.ToInt32(i.SelectSingleNode("tilex").InnerText);
                int tiley = Convert.ToInt32(i.SelectSingleNode("tiley").InnerText);
                Globals.Permissions perm = (Globals.Permissions)Enum.Parse(typeof(Globals.Permissions), i.SelectSingleNode("perms").InnerText);

                Globals.map[y][x]         = new Vector2(tilex, tiley);
                Globals.permissions[y][x] = perm;
            }

            foreach (XmlNode i in overlayset)
            {
                int x     = Convert.ToInt32(i.Attributes["x"].Value);
                int y     = Convert.ToInt32(i.Attributes["y"].Value);
                int tilex = Convert.ToInt32(i.SelectSingleNode("tilex").InnerText);
                int tiley = Convert.ToInt32(i.SelectSingleNode("tiley").InnerText);
                Globals.Permissions perm = (Globals.Permissions)Enum.Parse(typeof(Globals.Permissions), i.SelectSingleNode("perms").InnerText);

                if (i.SelectSingleNode("enemies") != null)
                {
                    XmlNodeList        enemies = i.SelectSingleNode("enemies").ChildNodes;
                    string             src     = "Paul";
                    Globals.SpriteFace sprFace = Globals.SpriteFace.Down;
                    foreach (XmlAttribute j in i.SelectSingleNode("enemies").Attributes)
                    {
                        if (j.Name == "src")
                        {
                            src = j.Value;
                        }
                        if (j.Name == "facing")
                        {
                            sprFace = (Globals.SpriteFace)Enum.Parse(typeof(Globals.SpriteFace), j.Value);
                        }
                    }

                    for (int j = 0; j < enemies.Count; j++)
                    {
                        Globals.battleEnemyTypes type = (Globals.battleEnemyTypes)Enum.Parse(typeof(Globals.battleEnemyTypes), enemies[j].InnerText);
                        if (j == 0)
                        {
                            Globals.enemies.Add(new Enemy(src, new Vector2(x, y), sprFace, type));
                        }
                        else
                        {
                            Globals.enemies[Globals.enemies.Count - 1].addEnemy(type);
                        }
                    }
                }

                string evnt = i.SelectSingleNode("event").InnerText;
                foreach (XmlAttribute j in i.SelectSingleNode("event").Attributes)
                {
                    if (j.Name == "throw")
                    {
                        Globals.eventThrows[y][x] = (Globals.EventThrow)Enum.Parse(typeof(Globals.EventThrow), j.Value);
                    }
                }
                Globals.overlayMap[y][x]   = new Vector2(tilex, tiley);
                Globals.overlayPerms[y][x] = perm;
                if (evnt != "nil")
                {
                    Globals.events[y][x] = evnt;
                }
            }
        }
예제 #2
0
        public static void modMapPerm(string mapName, Vector2 pos, Globals.Permissions newperm, bool overlay)
        {
            XmlDocument doc      = new XmlDocument();
            string      filename = "Maps/" + mapName;

            if (Globals.fileOpen)
            {
                filename = "Saves/" + Globals.slotOpen + "/" + filename;
            }
            if (overlay)
            {
                filename += "_events";
            }
            if (!File.Exists(filename + "_new.xml"))
            {
                FileInfo fi = new FileInfo(filename + ".xml");
                fi.CopyTo(filename + "_new.xml");
            }
            filename += "_new";
            doc.Load(filename + ".xml");

            XmlNodeList docset;

            if (!overlay)
            {
                docset = doc.GetElementsByTagName("tileset");
            }
            else
            {
                docset = doc.GetElementsByTagName("overlayset");
            }

            bool xFound, yFound;

            foreach (XmlNode i in docset)
            {
                xFound = false;
                yFound = false;
                foreach (XmlAttribute j in i.Attributes)
                {
                    if (j.Name == "x" && j.Value == Convert.ToInt32(pos.X).ToString())
                    {
                        xFound = true;
                    }
                    if (j.Name == "y" && j.Value == Convert.ToInt32(pos.Y).ToString())
                    {
                        yFound = true;
                    }
                }
                if (xFound && yFound)
                {
                    foreach (XmlNode j in i.ChildNodes)
                    {
                        if (j.Name == "perms")
                        {
                            j.InnerText = newperm.ToString();
                        }
                    }
                }
            }

            doc.Save(filename + ".xml");
        }
예제 #3
0
        public bool Parse(string script)
        {
            if (!Globals.sleep)
            {
                if (eoe)                         // Previous event ended, or none have started, read new event
                {
                    reader = new XmlDocument();
                    string filename = "Maps/" + script + ".xml";
                    if (Globals.fileOpen)
                    {
                        filename = "Saves/" + Globals.slotOpen + "/" + filename;
                    }
                    reader.Load(filename);
                    commands = reader.GetElementsByTagName("root");
                    t        = commands[0].FirstChild;

                    eoe  = false;
                    line = "";

                    Globals.fade = new Fade();

                    Globals.sleep = false;
                }

                if (advance)                    // Ready to advance, parse next line
                {
                    advance = false;
                    if (tStack.Count == 0 && commands[0].LastChild != t)
                    {
                        t = t.NextSibling;
                    }
                    else if (tStack.Count > 0 && tStack.Peek().LastChild != t)
                    {
                        t = t.NextSibling;
                    }
                    else if (tStack.Count > 0)
                    {
                        while (tStack.Count > 0 && tStack.Peek().LastChild == t)
                        {
                            t = tStack.Pop();
                        }
                        if (commands[0].LastChild == t)
                        {
                            eoe           = true;
                            Globals.pause = false;
                            return(false);
                        }
                        t = t.NextSibling;
                    }
                    else
                    {
                        eoe           = true;
                        Globals.pause = false;
                        return(false);
                    }

                    if (t.Name == "fadefrom")
                    {
                        Globals.fade.level = 1f;
                    }
                }
            }

            Globals.pause = false;

            if (t.Name == "if")
            {
                bool stack = true;

                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "has" && Globals.keyItems.ContainsKey(t.Attributes[i].Value) && !Globals.keyItems[t.Attributes[i].Value])
                    {
                        stack = false;
                    }
                    if (t.Attributes[i].Name == "flagged" && Globals.flags.ContainsKey(t.Attributes[i].Value) && !Globals.flags[t.Attributes[i].Value])
                    {
                        stack = false;
                    }
                }

                if (stack)
                {
                    tStack.Push(t);
                    t = t.FirstChild;
                }
            }
            if (t.Name == "nif")
            {
                bool stack = true;

                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "has" && Globals.keyItems.ContainsKey(t.Attributes[i].Value) && Globals.keyItems[t.Attributes[i].Value])
                    {
                        stack = false;
                    }
                    if (t.Attributes[i].Name == "flagged" && Globals.flags.ContainsKey(t.Attributes[i].Value) && Globals.flags[t.Attributes[i].Value])
                    {
                        stack = false;
                    }
                }

                if (stack)
                {
                    tStack.Push(t);
                    t = t.FirstChild;
                }
            }
            if (t.Name == "cutscene")
            {
                profile   = Globals.Content.Load <Texture2D>("Assets/full/" + Globals.currentPlayer);
                profileTo = Globals.Content.Load <Texture2D>("Assets/full/" + Globals.currentPlayer);
                speaker   = Globals.currentPlayer;
                ifTo      = false;
                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "speaker" && t.Attributes[i].Value != "this")
                    {
                        speaker = t.Attributes[i].Value;
                    }
                    if (t.Attributes[i].Name == "from" && t.Attributes[i].Value != "this")
                    {
                        profile = Globals.Content.Load <Texture2D>("Assets/full/" + t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "to")
                    {
                        ifTo = true;
                        if (t.Attributes[i].Value != "this")
                        {
                            profileTo = Globals.Content.Load <Texture2D>("Assets/full/" + t.Attributes[i].Value);
                        }
                    }
                    if (t.Attributes[i].Name == "audio")
                    {
                        dialogue = Globals.Content.Load <SoundEffect>("Audio/" + t.Attributes[i].Value);
                        lineInst = dialogue.CreateInstance();
                        lineInst.Stop();
                        lineInst.Play();
                    }
                }
                line          = t.InnerText;
                Globals.pause = true;
            }
            if (t.Name == "message")
            {
                profile = Globals.Content.Load <Texture2D>("Assets/pixel");
                speaker = "";
                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "from")
                    {
                        if (t.Attributes[i].Value != "this")
                        {
                            profile = Globals.Content.Load <Texture2D>("Assets/message/" + t.Attributes[i].Value);
                            speaker = t.Attributes[i].Value;
                        }
                        else
                        {
                            profile = Globals.Content.Load <Texture2D>("Assets/message/" + Globals.currentPlayer);
                            speaker = Globals.currentPlayer;
                        }
                    }
                }
                line          = t.InnerText;
                Globals.pause = true;
            }
            if (t.Name == "give")
            {
                if (Globals.keyItems.ContainsKey(t.InnerText))
                {
                    Globals.keyItems[t.InnerText] = !Globals.keyItems[t.InnerText];
                }
            }
            if (t.Name == "flag")
            {
                if (Globals.flags.ContainsKey(t.InnerText))
                {
                    Globals.flags[t.InnerText] = !Globals.flags[t.InnerText];
                }
            }
            if (t.Name == "warp")
            {
                Vector2 startPos = new Vector2();
                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "x")
                    {
                        startPos.X = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "y")
                    {
                        startPos.Y = Convert.ToInt32(t.Attributes[i].Value);
                    }
                }
                Map.changeMap(t.InnerText, startPos);
            }
            if (t.Name == "fadeto")
            {
                if (t.InnerText != "nil")
                {
                    Globals.fade.delay = Convert.ToInt32(t.InnerText);
                }
                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "r")
                    {
                        Globals.fade.color.R = Convert.ToByte(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "g")
                    {
                        Globals.fade.color.G = Convert.ToByte(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "b")
                    {
                        Globals.fade.color.B = Convert.ToByte(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "step")
                    {
                        Globals.fade.step = (float)double.Parse(t.Attributes[i].Value);
                    }
                }
                Globals.sleep = true;

                Globals.timer.Start();
                if (Globals.timer.ElapsedMilliseconds >= Globals.fade.delay)
                {
                    Globals.fade.stepUp();
                    Globals.timer.Restart();
                    if (Globals.fade.level >= 1.0f)
                    {
                        Globals.fade.level = 1.0f;
                        Globals.sleep      = false;
                        Globals.timer.Reset();
                    }
                }
            }
            if (t.Name == "fadefrom")
            {
                if (t.InnerText != "nil")
                {
                    Globals.fade.delay = Convert.ToInt32(t.InnerText);
                }
                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "r")
                    {
                        Globals.fade.color.R = Convert.ToByte(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "g")
                    {
                        Globals.fade.color.G = Convert.ToByte(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "b")
                    {
                        Globals.fade.color.B = Convert.ToByte(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "step")
                    {
                        Globals.fade.step = (float)double.Parse(t.Attributes[i].Value);
                    }
                }
                Globals.sleep = true;

                Globals.timer.Start();
                if (Globals.timer.ElapsedMilliseconds >= Globals.fade.delay)
                {
                    Globals.fade.stepDown();
                    Globals.timer.Restart();
                    if (Globals.fade.level <= 0f)
                    {
                        Globals.fade.level = 0f;
                        Globals.sleep      = false;
                        Globals.timer.Reset();
                    }
                }
            }
            if (t.Name == "shove")
            {
                if (t.InnerText == "up")
                {
                    Globals.spriteFace = Globals.SpriteFace.Up;
                    Globals.step       = Globals.spriteSrcUp.Count;
                    Globals.moving     = true;
                    Globals.timer.Start();
                }
                if (t.InnerText == "down")
                {
                    Globals.spriteFace = Globals.SpriteFace.Down;
                    Globals.step       = Globals.spriteSrcDown.Count;
                    Globals.moving     = true;
                    Globals.timer.Start();
                }
                if (t.InnerText == "left")
                {
                    Globals.spriteFace = Globals.SpriteFace.Left;
                    Globals.step       = Globals.spriteSrcLeft.Count;
                    Globals.moving     = true;
                    Globals.timer.Start();
                }
                if (t.InnerText == "right")
                {
                    Globals.spriteFace = Globals.SpriteFace.Right;
                    Globals.step       = Globals.spriteSrcRight.Count;
                    Globals.moving     = true;
                    Globals.timer.Start();
                }
            }
            if (t.Name == "retile")
            {
                string  mapName = Globals.currentMap;
                Vector2 pos     = Vector2.Zero;
                Vector2 newset  = Vector2.Zero;
                bool    overlay = false;
                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "x")
                    {
                        pos.X = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "y")
                    {
                        pos.Y = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "overlay" && t.Attributes[i].Value == "yes")
                    {
                        overlay = true;
                    }
                    if (t.Attributes[i].Name == "newx")
                    {
                        newset.X = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "newy")
                    {
                        newset.Y = Convert.ToInt32(t.Attributes[i].Value);
                    }
                }
                if (t.InnerText != "this")
                {
                    mapName = t.InnerText;
                }

                Map.modMapTile(mapName, pos, newset, overlay);

                if (mapName == Globals.currentMap && !overlay)
                {
                    Globals.map[Convert.ToInt32(pos.Y)][Convert.ToInt32(pos.X)] = newset;
                }
                else if (mapName == Globals.currentMap && overlay)
                {
                    Globals.overlayMap[Convert.ToInt32(pos.Y)][Convert.ToInt32(pos.X)] = newset;
                }
            }
            if (t.Name == "reperm")
            {
                string              mapName = Globals.currentMap;
                Vector2             pos     = Vector2.Zero;
                Globals.Permissions newperm = Globals.Permissions.Open;
                bool overlay = false;
                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "x")
                    {
                        pos.X = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "y")
                    {
                        pos.Y = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "overlay" && t.Attributes[i].Value == "yes")
                    {
                        overlay = true;
                    }
                    if (t.Attributes[i].Name == "perm")
                    {
                        newperm = (Globals.Permissions)Enum.Parse(typeof(Globals.Permissions), t.Attributes[i].Value);
                    }
                }
                if (t.InnerText != "this")
                {
                    mapName = t.InnerText;
                }

                Map.modMapPerm(mapName, pos, newperm, overlay);

                if (mapName == Globals.currentMap && !overlay)
                {
                    Globals.permissions[Convert.ToInt32(pos.Y)][Convert.ToInt32(pos.X)] = newperm;
                }
                else if (mapName == Globals.currentMap && overlay)
                {
                    Globals.overlayPerms[Convert.ToInt32(pos.Y)][Convert.ToInt32(pos.X)] = newperm;
                }
            }
            if (t.Name == "reevent")
            {
                string  mapName     = Globals.currentMap;
                Vector2 pos         = Vector2.Zero;
                string  thrower     = "None";
                string  eventscript = "nil";
                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "x")
                    {
                        pos.X = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "y")
                    {
                        pos.Y = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "throw")
                    {
                        thrower = t.Attributes[i].Value;
                    }
                    if (t.Attributes[i].Name == "script")
                    {
                        eventscript = t.Attributes[i].Value;
                    }
                }
                if (t.InnerText != "this")
                {
                    mapName = t.InnerText;
                }

                Map.modMapEvent(mapName, pos, thrower, eventscript);

                if (mapName == Globals.currentMap)
                {
                    Globals.eventThrows[Convert.ToInt32(pos.Y)][Convert.ToInt32(pos.X)] = (Globals.EventThrow)Enum.Parse(typeof(Globals.EventThrow), thrower);
                    Globals.events[Convert.ToInt32(pos.Y)][Convert.ToInt32(pos.X)]      = eventscript;
                }
            }
            if (t.Name == "reenemy")
            {
                string             mapName            = Globals.currentMap;
                Vector2            pos                = Vector2.Zero;
                string             src                = "Paul";
                Globals.SpriteFace facing             = Globals.SpriteFace.Down;
                List <Globals.battleEnemyTypes> types = new List <Globals.battleEnemyTypes>();
                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "x")
                    {
                        pos.X = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "y")
                    {
                        pos.Y = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "src")
                    {
                        src = t.Attributes[i].Value;
                    }
                    if (t.Attributes[i].Name == "facing")
                    {
                        facing = (Globals.SpriteFace)Enum.Parse(typeof(Globals.SpriteFace), t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "map" && t.Attributes[i].Value != "this")
                    {
                        mapName = t.Attributes[i].Value;
                    }
                }
                for (int i = 0; i < t.ChildNodes.Count; i++)
                {
                    types.Add((Globals.battleEnemyTypes)Enum.Parse(typeof(Globals.battleEnemyTypes), t.ChildNodes[i].InnerText));
                }

                Map.modMapEnemy(mapName, pos, src, facing, types);
            }
            if (t.Name == "remenemy")
            {
                string  mapName = Globals.currentMap;
                Vector2 pos     = Vector2.Zero;
                for (int i = 0; i < t.Attributes.Count; i++)
                {
                    if (t.Attributes[i].Name == "x")
                    {
                        pos.X = Convert.ToInt32(t.Attributes[i].Value);
                    }
                    if (t.Attributes[i].Name == "y")
                    {
                        pos.Y = Convert.ToInt32(t.Attributes[i].Value);
                    }
                }
                if (t.InnerText != "this")
                {
                    mapName = t.InnerText;
                }

                Map.modMapEnemy(mapName, pos);
            }

            advance = true;
            return(true);
        }