using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Xml; using UnityEngine; namespace HxGame.Data { //角色游戏模式 [Flags] public enum RoleMode { PK = 1 << 0, //PK ShiZu = 1 << 1, //氏族 Team = 1 << 2, //团队 LianJi = 1 << 3, //练级 ChengZhan = 1 << 4 //城战 } //使用模式 [Flags] public enum UseMode { UseRandom = 1 << 0, //能否使用随机卷 UseUnderground = 1 << 1, //能否使用地城 UseBack = 1 << 2, //能否使用回城 UseItem = 1 << 3, //能否使用药品 FuBen = 1 << 4, //是否副本地图 } //复活点类型 public enum ReliveType { Normal, //普通复活点 ChengZhan1, //城战复活点1 ChengZhan2, //城战复活点2 } //进入条件 public enum ConditionMode { GM, //GM Team, //组队 Clan, //氏族 Task, //任务 Activity, //活动 } [Serializable] public class MapConfig { //传送点 public class TeleportConfig { public Vector2Int pos; //传送坐标 public int nextMapId; //下级地图 public Vector2Int nextMapPos; //下级地图坐标 } //区域 public class AreaConfig { public Vector2Int pos; //中心点坐标 public int radius; //半径 } //复活点 public class ReliveConfig { public ReliveType reliveType; //复活点类型 public int mapId; //复活地图 public Vector2Int pos; //中心点坐标 public int radius; //半径 } //音效触发 public class AudioTriggerConfig { public Vector2Int pos; //中心点坐标 public int radius; //半径 public string name; //音效名称 } public class ConditionConfig { public ConditionMode mode; //进入条件 public int level; //进入等级 public int itemId; //消耗道具 public int money; //消耗货币 public int time; //消耗时间 } public string mapName; //地图名称 public int enterLv; //进入等级 public int returnMapId; //回城地图ID public Vector2Int returnMapCellPoint; //回城地图坐标 public RoleMode roleMode; //角色游戏模式 public UseMode useMode; //使用模式 public bool deadFall; //是否死亡掉落 public List teleportConfigs = new List(); public List relivesConfig = new List(); public List sellAreasConfig = new List(); public List audioTriggersConfig = new List(); public List conditionsConfig = new List(); public MapConfig() { roleMode = 0; useMode = 0; deadFall = false; } public void SaveXML(int mapId) { string path = PathUtil.GetXmlPath(mapId, "MapConfig"); string tmp = path.Substring(0, path.LastIndexOf('/')); if (!Directory.Exists(tmp)) Directory.CreateDirectory(tmp); if (File.Exists(path)) File.Delete(path); XmlDocument xml = new XmlDocument(); XmlDeclaration node = xml.CreateXmlDeclaration("1.0", "utf-8", "no"); xml.AppendChild(node); XmlElement Root = xml.CreateElement("config"); xml.AppendChild(Root); XmlElement Settings = xml.CreateElement("Settings");//节点Settings xml.DocumentElement.AppendChild(Settings); XmlElement Teleports = xml.CreateElement("Teleports"); xml.DocumentElement.AppendChild(Teleports); XmlElement ReliveAreas = xml.CreateElement("ReliveAreas"); xml.DocumentElement.AppendChild(ReliveAreas); XmlElement SellAreas = xml.CreateElement("SellAreas"); xml.DocumentElement.AppendChild(SellAreas); XmlElement AudioTriggers = xml.CreateElement("AudioTriggers"); xml.DocumentElement.AppendChild(AudioTriggers); XmlElement Conditions = xml.CreateElement("Conditions"); xml.DocumentElement.AppendChild(Conditions); SaveMapInfoConfig(mapId, Settings); SaveTeleports(xml, Teleports); SaveRelives(xml, ReliveAreas); SaveSellAreas(xml, SellAreas); SaveAudioTriggers(xml, AudioTriggers); SaveConditions(xml, Conditions); xml.Save(path); UIWindow.Instance.ShowMessage("保存地图配置成功"); } private void SaveMapInfoConfig(int mapId, XmlElement xmlSettings) { xmlSettings.SetAttribute("mapID", mapId.ToString()); xmlSettings.SetAttribute("mapName", mapName); xmlSettings.SetAttribute("enterLv", enterLv.ToString()); xmlSettings.SetAttribute("returnMapId", returnMapId.ToString()); xmlSettings.SetAttribute("returnMapCellPointX", returnMapCellPoint.x.ToString()); xmlSettings.SetAttribute("returnMapCellPointY", returnMapCellPoint.y.ToString()); xmlSettings.SetAttribute("roleMode", ((int)roleMode).ToString()); xmlSettings.SetAttribute("useMode", ((int)useMode).ToString()); xmlSettings.SetAttribute("deadFall", deadFall ? "1" : "0"); } private void SaveTeleports(XmlDocument xml, XmlElement xmlElement) { XmlElement child = null; for(int i=0; i