public NpcName GetNpc(int id) { NpcName npc = CharacterNames.FirstOrDefault(c => c.Id == id); if (npc != null) { return(npc); } return(GetNewNpc(id)); }
/// <summary> /// Saves the XML document. /// </summary> public static void SaveXml() { using (XmlWriter writer = XmlWriter.Create(Paths.CreateOSPath("settings.xml"), XmlWriterSettings)) { writer.WriteStartDocument(); writer.WriteStartElement("Options"); writer.WriteStartElement("General"); writer.WriteElementString("AutoSave", AutoSave.ToString()); writer.WriteElementString("AutoSaveSpeed", AutoSaveSpeed.ToString()); writer.WriteElementString("AutoScroll", AutoScroll.ToString()); writer.WriteElementString("Music", Music.ToString()); writer.WriteElementString("NpcBar", NpcBar.ToString()); writer.WriteElementString("NpcDamage", NpcDamage.ToString()); writer.WriteElementString("NpcName", NpcName.ToString()); writer.WriteElementString("PlayerBar", PlayerBar.ToString()); writer.WriteElementString("PlayerDamage", PlayerDamage.ToString()); writer.WriteElementString("PlayerName", PlayerName.ToString()); writer.WriteElementString("SavedAccount", SavedAccount); writer.WriteElementString("SavedPassword", SavedPassword); writer.WriteElementString("Sound", Sound.ToString()); writer.WriteElementString("SpeechBubbles", SpeechBubbles.ToString()); writer.WriteElementString("Timestamps", Timestamps.ToString()); writer.WriteElementString("ActiveSkin", ActiveSkin); writer.WriteElementString("LastClientUpdateTime", LastClientUpdateTime.ToBinary().ToString()); writer.WriteElementString("LastGFXUpdateTime", LastGFXUpdateTime.ToBinary().ToString()); writer.WriteEndElement(); writer.WriteStartElement("ConnectionInfo"); writer.WriteElementString("Port", ConnectionPort.ToString()); writer.WriteElementString("Server", ConnectionIP); writer.WriteElementString("UpdateLink", UpdateAddress); writer.WriteElementString("SFXLink", SoundAddress); writer.WriteElementString("MusicLink", MusicAddress); writer.WriteEndElement(); writer.WriteStartElement("Editor"); writer.WriteElementString("MapGrid", MapGrid.ToString()); writer.WriteElementString("DisplayAttributes", DisplayAttributes.ToString()); writer.WriteElementString("DragAndPlace", DragAndPlace.ToString()); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); } }
private void RemoveNpc(NpcName npcName) { if (CurrentWorld != null) { try { NPC npc = CurrentWorld.NPCs.First(n => n.Name == npcName.Character); CurrentWorld.NPCs.Remove(npc); Points.Remove(npcName.Character); MessageBox.Show(string.Format("{1} ({0}) removed.", npcName.Character, npcName.Name), "NPC Removed"); } catch (InvalidOperationException) { MessageBox.Show(string.Format("{1} ({0}) was not on the map.", npcName.Character, npcName.Name), "NPC Doesn't Exist"); } } }
private void AddNpc(NpcName npc) { if (CurrentWorld != null) { if (!CurrentWorld.NPCs.Any(n => n.Name == npc.Character)) { var spawn = new Vector2Int32(CurrentWorld.SpawnX, CurrentWorld.SpawnY); CurrentWorld.NPCs.Add(new NPC { Home = spawn, IsHomeless = true, Name = npc.Character, Position = new Vector2(spawn.X * 16, spawn.Y * 16), SpriteId = npc.Id }); Points.Add(npc.Character); MessageBox.Show(string.Format("{1} ({0}) added to spawn.", npc.Character, npc.Name), "NPC Added"); } else { MessageBox.Show(string.Format("{1} ({0}) is already on the map.", npc.Character, npc.Name), "NPC Exists"); } } }