Esempio n. 1
0
        public ChestKey CanOpenChest(MapChest chest)
        {
            ChestKey permission = chest.key;

            ItemRecord rec;

            switch (permission)             //note - it would be nice to be able to send the Item IDs of the keys in the welcome packet or something
            {
            case ChestKey.Normal:
                rec = (ItemRecord)World.Instance.EIF.Data.Find(_rec => ((ItemRecord)_rec).Name != null && ((ItemRecord)_rec).Name.ToLower() == "normal key");
                break;

            case ChestKey.Crystal:
                rec = (ItemRecord)World.Instance.EIF.Data.Find(_rec => ((ItemRecord)_rec).Name != null && ((ItemRecord)_rec).Name.ToLower() == "crystal key");
                break;

            case ChestKey.Silver:
                rec = (ItemRecord)World.Instance.EIF.Data.Find(_rec => ((ItemRecord)_rec).Name != null && ((ItemRecord)_rec).Name.ToLower() == "silver key");
                break;

            case ChestKey.Wraith:
                rec = (ItemRecord)World.Instance.EIF.Data.Find(_rec => ((ItemRecord)_rec).Name != null && ((ItemRecord)_rec).Name.ToLower() == "wraith key");
                break;

            default:
                return(permission);
            }

            if (rec != null && Inventory.FindIndex(_ii => _ii.id == rec.ID) >= 0)
            {
                permission = ChestKey.None;
            }
            else if (rec == null)             //show a warning saying that this chest is perma-locked. Non-standard pub files will cause this.
            {
                EODialog.Show(
                    string.Format("Unable to find key for {0} in EIF. This chest will never be opened!",
                                  Enum.GetName(typeof(ChestKey), permission)), "Warning", XNADialogButtons.Ok, EODialogStyle.SmallDialogSmallHeader);
            }

            return(permission);
        }
Esempio n. 2
0
		public ChestKey CanOpenChest(MapChest chest)
		{
			ChestKey permission = chest.key;

			ItemRecord rec;
			switch (permission) //note - it would be nice to be able to send the Item IDs of the keys in the welcome packet or something
			{
				case ChestKey.Normal:
					rec = (ItemRecord)World.Instance.EIF.Data.Find(_rec => _rec.Name != null && _rec.Name.ToLower() == "normal key");
					break;
				case ChestKey.Crystal:
					rec = (ItemRecord)World.Instance.EIF.Data.Find(_rec => _rec.Name != null && _rec.Name.ToLower() == "crystal key");
					break;
				case ChestKey.Silver:
					rec = (ItemRecord)World.Instance.EIF.Data.Find(_rec => _rec.Name != null && _rec.Name.ToLower() == "silver key");
					break;
				case ChestKey.Wraith:
					rec = (ItemRecord)World.Instance.EIF.Data.Find(_rec => _rec.Name != null && _rec.Name.ToLower() == "wraith key");
					break;
				default:
					return permission;
			}

			if (rec != null && Inventory.FindIndex(_ii => _ii.id == rec.ID) >= 0)
				permission = ChestKey.None;
			else if (rec == null) //show a warning saying that this chest is perma-locked. Non-standard pub files will cause this.
				EOMessageBox.Show(
					string.Format("Unable to find key for {0} in EIF. This chest will never be opened!",
						Enum.GetName(typeof(ChestKey), permission)), "Warning", XNADialogButtons.Ok, EOMessageBoxStyle.SmallDialogSmallHeader);

			return permission;
		}
Esempio n. 3
0
        private static void ProcessFiles(string src, string dst, bool singleFile)
        {
            string[] inFiles = singleFile ? new[] { src } : Directory.GetFiles(src, "*.emf");

            for (int map = 0; map < inFiles.Length; ++map)
            {
                MapFile EMF         = new MapFile(inFiles[map]);
                bool    changesMade = false;

                string lastPart = inFiles[map].Substring(inFiles[map].Contains('\\') ? inFiles[map].LastIndexOf('\\') + 1 : 0,
                                                         inFiles[map].Length - inFiles[map].LastIndexOf('\\') - 1);

                for (int i = EMF.TileRows.Count - 1; i >= 0; --i)
                {
                    TileRow tr = EMF.TileRows[i];
                    for (int j = tr.tiles.Count - 1; j >= 0; --j)
                    {
                        Tile tt = tr.tiles[j];
                        if (tt.x > EMF.Width || tr.y > EMF.Height)
                        {
                            Console.WriteLine("[MAP {3}] Tile {0}x{1} ({2}) is out of map bounds. Removing.", tt.x, tr.y, Enum.GetName(typeof(TileSpec), tt.spec), lastPart);
                            tr.tiles.RemoveAt(j);
                            changesMade = true;
                        }
                    }
                }

                for (int i = EMF.WarpRows.Count - 1; i >= 0; --i)
                {
                    WarpRow tr = EMF.WarpRows[i];
                    for (int j = tr.tiles.Count - 1; j >= 0; --j)
                    {
                        Warp tt = tr.tiles[j];
                        if (tt.x > EMF.Width || tr.y > EMF.Height)
                        {
                            Console.WriteLine("[MAP {2}] Warp {0}x{1} is out of map bounds. Removing.", tt.x, tr.y, lastPart);
                            tr.tiles.RemoveAt(j);
                            changesMade = true;
                        }
                    }
                }

                for (int i = EMF.NPCSpawns.Count - 1; i >= 0; --i)
                {
                    NPCSpawn  npc    = EMF.NPCSpawns[i];
                    NPCRecord npcRec = (NPCRecord)ENF.Data.Find(rec => ((NPCRecord)rec).ID == npc.id);
                    if (npc.id > ENF.Data.Count || npcRec == null)
                    {
                        Console.WriteLine("[MAP {0}] NPC Spawn {1}x{2} uses non-existent NPC #{3}. Removing.", lastPart, npc.x, npc.y, npc.id);
                        EMF.NPCSpawns.RemoveAt(i);
                        changesMade = true;
                        continue;
                    }

                    if (npc.x > EMF.Width || npc.y > EMF.Height)
                    {
                        Console.WriteLine("[MAP {0}] NPC Spawn {1}x{2} ({3}) is out of map bounds. Removing.", lastPart, npc.x, npc.y, npcRec.Name);
                        EMF.NPCSpawns.RemoveAt(i);
                        changesMade = true;
                        continue;
                    }

                    if (!CheckTile(EMF, npc.x, npc.y))
                    {
                        Console.WriteLine("[MAP {0}] NPC Spawn {1}x{2} ({3}) is invalid...", lastPart, npc.x, npc.y, npcRec.Name);
                        bool found = false;
                        for (int row = npc.y - 2; row < npc.y + 2; ++row)
                        {
                            if (found)
                            {
                                break;
                            }
                            for (int col = npc.x - 2; col < npc.x + 2; ++col)
                            {
                                if (found)
                                {
                                    break;
                                }
                                if (CheckTile(EMF, col, row))
                                {
                                    Console.WriteLine("[MAP {0}] Found valid spawn point. Continuing.", lastPart);
                                    found = true;
                                }
                            }
                        }

                        if (!found)
                        {
                            Console.WriteLine("[MAP {0}] NPC couldn't spawn anywhere valid! Removing.");
                            EMF.NPCSpawns.RemoveAt(i);
                            changesMade = true;
                        }
                    }
                }

                for (int i = EMF.Chests.Count - 1; i >= 0; --i)
                {
                    MapChest   chest = EMF.Chests[i];
                    ItemRecord rec   = EIF.GetItemRecordByID(chest.item);
                    if (chest.item > EIF.Data.Count || rec == null)
                    {
                        Console.WriteLine("[MAP {0}] Chest Spawn {1}x{2} uses non-existent Item #{3}. Removing.", lastPart, chest.x, chest.y, chest.item);
                        EMF.Chests.RemoveAt(i);
                        changesMade = true;
                        continue;
                    }

                    if (chest.x > EMF.Width || chest.y > EMF.Height ||
                        (EMF.TileLookup[chest.y, chest.x] ?? new Tile {
                        spec = TileSpec.Wall
                    }).spec != TileSpec.Chest)
                    {
                        Console.WriteLine("[MAP {0}] Chest Spawn {1}x{2} points to a non-chest. Removing.", lastPart, chest.x, chest.y);
                        EMF.Chests.RemoveAt(i);
                        changesMade = true;
                    }
                }

                if (!changesMade)
                {
                    Console.WriteLine("Map {0} processed without any errors. No changes made.", lastPart);
                    continue;
                }

                if (map == 0 && singleFile && inFiles.Length == 1)
                {
                    EMF.Save(dst);
                    break;
                }

                EMF.Save(Path.Combine(dst, lastPart));
            }
        }