Files
JJBB/Assets/Project/Script/Player/UserData/UserConfigData.cs
2024-08-23 15:49:34 +08:00

1808 lines
67 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/********************************************************************
created: 2014/02/13
created: 13:2:2014 19:12
filename: UserConfigData.cs
file ext: cs
author: 王迪
purpose: 客户端配置文件类
*********************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using Games.GlobeDefine;
using Games.Mission;
using Module.Log;
using UnityEngine;
#if UNITY_WP8
using UnityPort;
using System.Text;
using System.Xml.Serialization;
#endif
[Serializable]
public class UserConfigData
{
public static string DataPath
{
get { return Application.persistentDataPath + "/UserData/"; }
}
private static int AccountInfoMax = 5; // role info max
private static string AccountFileName = "Account.data";
private static Dictionary<string, string> m_accountMap;
private static string RoleInfoFileLast = ".RoleInfo";
private static Dictionary<string, List<LoginData.PlayerRoleData>> m_roleInfoMap;
private static string CurRoleInfoAccount = "";
//private static string ClientResVersionFileName = "ClientResVersion.data";
private static string FastReplyFileName = "FastReply.data";
private static List<string> m_FastReplyList;
private static string MissionClientName = "MissionClient.data";
private static Dictionary<string, List<CurOwnMission>> m_MissionClientData;
private static string AutoConfigFileName = "AutoConfig.data";
private static Dictionary<string, PlayerAuto> m_AutoConfigMap;
private static string SkillBarSetFileName = "SkillBarSet.data";
private static string FactionSkillBarSetFileName = "FactionSkillBarSet.data";
public static string AutoUseMedicFileName = "AutoMedic.data";
private static string RestaurantConfigFileName = "RestaurantConfig.data";
private static Dictionary<string, RestaurantConfigData> m_RestaurantConfigMap;
public static void ClearConfigData()
{
File.Delete(DataPath + AccountFileName);
File.Delete(DataPath + RoleInfoFileLast);
File.Delete(DataPath + FastReplyFileName);
File.Delete(DataPath + MissionClientName);
File.Delete(DataPath + AutoConfigFileName);
File.Delete(DataPath + SkillBarSetFileName);
File.Delete(DataPath + RestaurantConfigFileName);
File.Delete(DataPath + AutoUseMedicFileName);
}
public static int ClientResVersion
{
get
{
// var strVersionFilePath =
// UpdateHelper.Instance.LocalVersionPath + "/" + UpdateHelper.Instance.VersionFileName;
// if (!File.Exists(strVersionFilePath)) return 0;
//
// var fs = new FileStream(strVersionFilePath, FileMode.Open, FileAccess.Read);
// var sr = new StreamReader(fs);
//
// var strLine = sr.ReadLine();
//
// var retValue = 0;
// if (!int.TryParse(strLine, out retValue))
// {
// LogModule.ErrorLog("res version file format error :" + strLine);
// retValue = 0;
// }
//
// fs.Close();
//
// return retValue;
return 0;
}
}
// 将账号信息保存在TXT文件中
public static void AddAccountInfo(string account, string psw)
{
var accountMapOrg = GetAccountList();
var newAccountMap = new Dictionary<string, string>();
foreach (var oldPair in accountMapOrg)
if (oldPair.Key != account)
newAccountMap.Add(oldPair.Key, oldPair.Value);
newAccountMap.Add(account, psw);
if (newAccountMap.Count > AccountInfoMax)
{
string delKey = null;
foreach (var curKey in newAccountMap.Keys)
{
delKey = curKey;
break;
}
if (null != delKey)
{
newAccountMap.Remove(delKey);
RemoveRoleInfo(delKey);
}
}
if (!Directory.Exists(DataPath)) Directory.CreateDirectory(DataPath);
var fs = new FileStream(DataPath + AccountFileName, FileMode.Create);
var sw = new StreamWriter(fs);
foreach (var curPair in newAccountMap) sw.WriteLine(curPair.Key + '\t' + curPair.Value);
sw.Close();
fs.Close();
m_accountMap = newAccountMap;
}
// 从配置文件读取账号数据保存在Map中
public static Dictionary<string, string> GetAccountList()
{
if (m_accountMap != null) return m_accountMap;
m_accountMap = new Dictionary<string, string>();
var filePath = DataPath + AccountFileName;
if (!File.Exists(filePath)) return m_accountMap;
var fs = new FileStream(filePath, FileMode.Open);
var sr = new StreamReader(fs);
var strLine = sr.ReadLine();
while (strLine != null)
{
var codes = strLine.Split('\t');
if (codes.Length == 2)
{
if (m_accountMap.ContainsKey(codes[0]))
m_accountMap[codes[0]] = codes[1];
else
m_accountMap.Add(codes[0], codes[1]);
}
strLine = sr.ReadLine();
}
sr.Close();
fs.Close();
return m_accountMap;
}
#if UNITY_WP8
public class RoleElement : IXmlSerializable
{
public string type { get; set; }
public string level { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
if (null == reader)
{
return;
}
reader.Read();
reader.ReadStartElement("Type");
type = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("Level");
level = reader.ReadContentAsString();
reader.ReadEndElement();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteElementString("Type", type);
writer.WriteElementString("Level", level);
}
}
public class ServerElement : IXmlSerializable
{
public List<RoleElement> list { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
list = new List<RoleElement>();
while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "Role")
{
RoleElement element = new RoleElement();
element.ReadXml(reader);
list.Add(element);
reader.Read();
}
}
public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (RoleElement element in list)
{
writer.WriteStartElement("Role");
element.WriteXml(writer);
writer.WriteEndElement();
}
}
}
public class RoleInfo : IXmlSerializable
{
public Dictionary<string, ServerElement> dic { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
dic = new Dictionary<string, ServerElement>();
if (reader.MoveToContent() == XmlNodeType.Element && "RoleInfo" == reader.LocalName)
{
reader.Read();
while (reader.MoveToContent() == XmlNodeType.Element)
{
string name = reader.LocalName;
ServerElement elem = new ServerElement();
reader.Read();
elem.ReadXml(reader);
dic.Add(name, elem);
reader.Read();
}
}
}
public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (KeyValuePair<string, ServerElement> elem in dic)
{
writer.WriteStartElement(elem.Key);
elem.Value.WriteXml(writer);
writer.WriteEndElement();
}
}
}
#endif
// 将角色信息保存在XML文件中
public static void AddRoleInfo()
{
var account = PlayerPreferenceData.LastAccount;
var serverID = PlayerPreferenceData.LastServer.ToString();
m_roleInfoMap = GetRoleInfoList(account);
if (m_roleInfoMap.ContainsKey(serverID)) m_roleInfoMap.Remove(serverID);
m_roleInfoMap.Add(serverID, LoginData.loginRoleList);
if (!Directory.Exists(DataPath)) Directory.CreateDirectory(DataPath);
#if UNITY_WP8
RoleInfo roleInfo = new RoleInfo();
roleInfo.dic = new Dictionary<string, ServerElement>();
foreach (KeyValuePair<string, List<LoginData.PlayerRoleData>> iter in m_roleInfoMap)
{
ServerElement serverElem = new ServerElement();
serverElem.list = new List<RoleElement>();
string name = "Server" + iter.Key;
List<LoginData.PlayerRoleData> list = iter.Value;
foreach (LoginData.PlayerRoleData curRoleData in list)
{
RoleElement roleElem = new RoleElement();
roleElem.type = curRoleData.type.ToString();
roleElem.level = curRoleData.level.ToString();
serverElem.list.Add(roleElem);
}
roleInfo.dic.Add(name, serverElem);
}
XmlHelper.XmlSerializeToFile(roleInfo, DataPath + account + RoleInfoFileLast, new UTF8Encoding(false));
#else
var xml = new XmlDocument();
var root = xml.CreateElement("RoleInfo");
xml.AppendChild(root);
foreach (var keys in m_roleInfoMap.Keys)
{
var curServerElement = xml.CreateElement("Server" + keys);
root.AppendChild(curServerElement);
var curList = m_roleInfoMap[keys];
if (null != curList)
foreach (var curRoleData in curList)
{
var curRoleElement = xml.CreateElement("Role");
curServerElement.AppendChild(curRoleElement);
var curTypeElement = xml.CreateElement("Type");
curTypeElement.InnerText = curRoleData.type.ToString();
curRoleElement.AppendChild(curTypeElement);
curTypeElement = xml.CreateElement("Level");
curTypeElement.InnerText = curRoleData.level.ToString();
curRoleElement.AppendChild(curTypeElement);
}
}
xml.Save(DataPath + account + RoleInfoFileLast);
#endif
}
// 从配置文件读取角色数据保存在Map中
public static Dictionary<string, List<LoginData.PlayerRoleData>> GetRoleInfoList(string account)
{
if (null != m_roleInfoMap && CurRoleInfoAccount == account) return m_roleInfoMap;
m_roleInfoMap = new Dictionary<string, List<LoginData.PlayerRoleData>>();
#if UNITY_WP8
RoleInfo roleInfo =
XmlHelper.XmlDeserializeFromFile<RoleInfo>(DataPath + account + RoleInfoFileLast, new UTF8Encoding(false));
if (null == roleInfo)
{
return m_roleInfoMap;
}
foreach (KeyValuePair<string, ServerElement> iter in roleInfo.dic)
{
List<LoginData.PlayerRoleData> curList = new List<LoginData.PlayerRoleData>();
string serverID = iter.Key.Substring(6);
m_roleInfoMap.Add(serverID, curList);
foreach (RoleElement elem in iter.Value.list)
{
LoginData.PlayerRoleData curRoleData = new LoginData.PlayerRoleData(0, 0, null, 0, -1, -1, -1);
string typeValue = elem.type;
int.TryParse(typeValue, out curRoleData.type);
string roleLevel = elem.level;
int.TryParse(roleLevel, out curRoleData.level);
curList.Add(curRoleData);
}
}
#else
var xml = new XmlDocument();
try
{
xml.Load(DataPath + account + RoleInfoFileLast);
}
catch (Exception ex)
{
return m_roleInfoMap;
}
foreach (XmlElement elemServer in xml.FirstChild.ChildNodes)
{
var curList = new List<LoginData.PlayerRoleData>();
var serverID = elemServer.Name.Substring(6);
m_roleInfoMap.Add(serverID, curList);
foreach (XmlElement roleInfo in elemServer)
if (roleInfo.Name == "Role")
{
var curRoleData = new LoginData.PlayerRoleData(0, 0, null, 0, -1, -1, -1, 0, 0, 0);
foreach (XmlElement elemDetail in roleInfo)
if (elemDetail.Name == "Type")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curRoleData.type);
}
else if (elemDetail.Name == "Level")
{
var roleLevel = elemDetail.InnerText;
int.TryParse(roleLevel, out curRoleData.level);
}
curList.Add(curRoleData);
}
}
#endif
return m_roleInfoMap;
}
public static void RemoveRoleInfo(string account)
{
if (File.Exists(DataPath + account + RoleInfoFileLast)) File.Delete(DataPath + account + RoleInfoFileLast);
}
// 写入快速回复
public static void AddFastReplyInfo(List<string> textList)
{
var curList = GetFastReplyList();
curList.Clear();
foreach (var str in textList) curList.Add(str);
if (!Directory.Exists(DataPath)) Directory.CreateDirectory(DataPath);
var fs = new FileStream(DataPath + FastReplyFileName, FileMode.OpenOrCreate);
var sw = new StreamWriter(fs);
for (var i = 0; i < textList.Count; i++) sw.WriteLine(textList[i]);
sw.Close();
}
// 从配置文件读取快速回复
public static List<string> GetFastReplyList()
{
if (m_FastReplyList != null) return m_FastReplyList;
m_FastReplyList = new List<string>();
var filePath = DataPath + FastReplyFileName;
if (!File.Exists(filePath)) return m_FastReplyList;
var fs = new FileStream(filePath, FileMode.Open);
var sr = new StreamReader(fs);
var strLine = sr.ReadLine();
while (strLine != null)
{
m_FastReplyList.Add(strLine);
strLine = sr.ReadLine();
}
fs.Close();
return m_FastReplyList;
}
#if UNITY_WP8
public class MissionElement : IXmlSerializable
{
public string state { get; set; }
public string param0 { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
reader.Read();
reader.ReadStartElement("State");
state = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("Param0");
param0 = reader.ReadContentAsString();
reader.ReadEndElement();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteElementString("State", state);
writer.WriteElementString("Param0", param0);
}
}
public class PlayerGuidElement : IXmlSerializable
{
public Dictionary<string, MissionElement> dic { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
dic = new Dictionary<string, MissionElement>();
while (reader.MoveToContent() == XmlNodeType.Element)
{
string name = reader.LocalName;
MissionElement element = new MissionElement();
element.ReadXml(reader);
dic.Add(name, element);
reader.Read();
}
}
public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (KeyValuePair<string, MissionElement> iter in dic)
{
writer.WriteStartElement(iter.Key);
iter.Value.WriteXml(writer);
writer.WriteEndElement();
}
}
}
public class ClientMissionData : IXmlSerializable
{
public Dictionary<string, PlayerGuidElement> dic { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
dic = new Dictionary<string, PlayerGuidElement>();
if (reader.MoveToContent() == XmlNodeType.Element && "ClientMissionData" == reader.LocalName)
{
reader.Read();
while (reader.MoveToContent() == XmlNodeType.Element)
{
string name = reader.LocalName;
PlayerGuidElement elem = new PlayerGuidElement();
reader.Read();
elem.ReadXml(reader);
dic.Add(name, elem);
reader.Read();
}
}
}
public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (KeyValuePair<string, PlayerGuidElement> iter in dic)
{
writer.WriteStartElement(iter.Key);
iter.Value.WriteXml(writer);
writer.WriteEndElement();
}
}
}
#endif
// 将客户端任务 信息保存
public static void AddClientMission(string strGuid, CurOwnMission oClientMission)
{
m_MissionClientData = GetClientMissionData();
if (m_MissionClientData.ContainsKey(strGuid))
{
var bIsHaveCurMission = false;
for (var i = 0; i < m_MissionClientData[strGuid].Count; i++)
if (m_MissionClientData[strGuid][i].m_nMissionID == oClientMission.m_nMissionID)
{
bIsHaveCurMission = true;
m_MissionClientData[strGuid][i] = oClientMission;
break;
}
if (false == bIsHaveCurMission) m_MissionClientData[strGuid].Add(oClientMission);
}
else
{
var ClientMissionList = new List<CurOwnMission>();
ClientMissionList.Add(oClientMission);
m_MissionClientData.Add(strGuid, ClientMissionList);
}
if (!Directory.Exists(DataPath)) Directory.CreateDirectory(DataPath);
#if UNITY_WP8
ClientMissionData clientMissionData = new ClientMissionData();
clientMissionData.dic = new Dictionary<string, PlayerGuidElement>();
foreach (string keys in m_MissionClientData.Keys)
{
PlayerGuidElement playerGuidElem = new PlayerGuidElement();
playerGuidElem.dic = new Dictionary<string, MissionElement>();
string playerGuidName = "PlayerGuid" + keys;
foreach (Games.Mission.CurOwnMission oMission in m_MissionClientData[keys])
{
MissionElement missionElem = new MissionElement();
string missionName = "Mission" + oMission.m_nMissionID;
missionElem.state = oMission.m_yStatus.ToString();
missionElem.param0 = oMission.m_nParam[0].ToString();
playerGuidElem.dic.Add(missionName, missionElem);
}
clientMissionData.dic.Add(playerGuidName, playerGuidElem);
}
XmlHelper.XmlSerializeToFile(clientMissionData, DataPath + MissionClientName, new UTF8Encoding(false));
#else
var xml = new XmlDocument();
var root = xml.CreateElement("ClientMissionData");
xml.AppendChild(root);
foreach (var keys in m_MissionClientData.Keys)
{
var curUserElement = xml.CreateElement("PlayerGuid" + keys);
root.AppendChild(curUserElement);
foreach (var oMission in m_MissionClientData[keys])
{
var curMissionElement = xml.CreateElement("Mission" + oMission.m_nMissionID);
curUserElement.AppendChild(curMissionElement);
var curStateElement = xml.CreateElement("State");
curStateElement.InnerText = oMission.m_yStatus.ToString();
curMissionElement.AppendChild(curStateElement);
var curParam0Element = xml.CreateElement("Param0");
curParam0Element.InnerText = oMission.m_nParam[0]
+ "," + oMission.m_nParam[1]
+ "," + oMission.m_nParam[2]
+ "," + oMission.m_nParam[3]
+ "," + oMission.m_nParam[4]
+ "," + oMission.m_nParam[5]
+ "," + oMission.m_nParam[6]
+ "," + oMission.m_nParam[7];
curMissionElement.AppendChild(curParam0Element);
}
}
xml.Save(DataPath + MissionClientName);
#endif
}
// 删除 客户端任务
public static void DelClientMission(string strGuid, int nMissionID)
{
m_MissionClientData = GetClientMissionData();
if (!m_MissionClientData.ContainsKey(strGuid)) return;
var nIndex = -1;
for (var i = 0; i < m_MissionClientData[strGuid].Count; i++)
if (nMissionID == m_MissionClientData[strGuid][i].m_nMissionID)
{
nIndex = i;
break;
}
if (nIndex < 0 || nIndex >= m_MissionClientData[strGuid].Count) return;
// 删除
m_MissionClientData[strGuid].RemoveAt(nIndex);
if (m_MissionClientData[strGuid].Count <= 0) m_MissionClientData.Remove(strGuid);
if (!Directory.Exists(DataPath)) Directory.CreateDirectory(DataPath);
#if UNITY_WP8
ClientMissionData clientMissionData = new ClientMissionData();
clientMissionData.dic = new Dictionary<string, PlayerGuidElement>();
foreach (string keys in m_MissionClientData.Keys)
{
PlayerGuidElement playerGuidElem = new PlayerGuidElement();
playerGuidElem.dic = new Dictionary<string, MissionElement>();
string playerGuidName = "PlayerGuid" + keys;
foreach (Games.Mission.CurOwnMission oMission in m_MissionClientData[keys])
{
MissionElement missionElem = new MissionElement();
string missionName = "Mission" + oMission.m_nMissionID;
missionElem.state = oMission.m_yStatus.ToString();
missionElem.param0 = oMission.m_nParam[0].ToString()
+ "," + oMission.m_nParam[1].ToString()
+ "," + oMission.m_nParam[2].ToString()
+ "," + oMission.m_nParam[3].ToString()
+ "," + oMission.m_nParam[4].ToString()
+ "," + oMission.m_nParam[5].ToString()
+ "," + oMission.m_nParam[6].ToString()
+ "," + oMission.m_nParam[7].ToString();
playerGuidElem.dic.Add(missionName, missionElem);
}
clientMissionData.dic.Add(playerGuidName, playerGuidElem);
}
XmlHelper.XmlSerializeToFile(clientMissionData, DataPath + MissionClientName, new UTF8Encoding(false));
#else
var xml = new XmlDocument();
var root = xml.CreateElement("ClientMissionData");
xml.AppendChild(root);
foreach (var keys in m_MissionClientData.Keys)
{
var curUserElement = xml.CreateElement("PlayerGuid" + keys);
root.AppendChild(curUserElement);
foreach (var oMission in m_MissionClientData[keys])
{
var curMissionElement = xml.CreateElement("Mission" + oMission.m_nMissionID);
curUserElement.AppendChild(curMissionElement);
var curStateElement = xml.CreateElement("State");
curStateElement.InnerText = oMission.m_yStatus.ToString();
curMissionElement.AppendChild(curStateElement);
var curParam0Element = xml.CreateElement("Param0");
curParam0Element.InnerText = oMission.m_nParam[0].ToString();
curMissionElement.AppendChild(curParam0Element);
}
}
xml.Save(DataPath + MissionClientName);
#endif
}
// 从配置文件读取账号数据保存在Map中
public static Dictionary<string, List<CurOwnMission>> GetClientMissionData()
{
if (null != m_MissionClientData) return m_MissionClientData;
m_MissionClientData = new Dictionary<string, List<CurOwnMission>>();
#if UNITY_WP8
ClientMissionData clientMissionData =
XmlHelper.XmlDeserializeFromFile<ClientMissionData>(DataPath + MissionClientName, new UTF8Encoding(false));
if (null == clientMissionData)
{
return m_MissionClientData;
}
foreach (KeyValuePair<string, PlayerGuidElement> playerGuidIter in clientMissionData.dic)
{
List<Games.Mission.CurOwnMission> curMissionList = new List<Games.Mission.CurOwnMission>();
m_MissionClientData.Add(playerGuidIter.Key.Substring(10), curMissionList);
foreach (KeyValuePair<string, MissionElement> missionIter in playerGuidIter.Value.dic)
{
Games.Mission.CurOwnMission oMission = new Games.Mission.CurOwnMission();
oMission.CleanUp();
curMissionList.Add(oMission);
string strMissionID = missionIter.Key.Substring(7);
oMission.m_nMissionID = int.Parse(strMissionID);
string strState = missionIter.Value.state;
oMission.m_yStatus = byte.Parse(strState);
string strParam0 = missionIter.Value.param0;
string []strParam = strParam0.Split(',');
for(int index = 0; index < 8; index++)
{
oMission.m_nParam[index] = int.Parse(strParam[index]);
}
}
}
#else
var xml = new XmlDocument();
try
{
xml.Load(DataPath + MissionClientName);
}
catch (Exception ex)
{
return m_MissionClientData;
}
foreach (XmlElement curUserElement in xml.FirstChild.ChildNodes)
{
var curMissionList = new List<CurOwnMission>();
m_MissionClientData.Add(curUserElement.Name.Substring(10), curMissionList);
foreach (XmlElement curMissionElement in curUserElement)
{
var oMission = new CurOwnMission();
oMission.CleanUp();
curMissionList.Add(oMission);
var strMissionID = curMissionElement.Name.Substring(7);
oMission.m_nMissionID = int.Parse(strMissionID);
foreach (XmlElement curElement in curMissionElement)
if (curElement.Name == "State")
{
var strState = curElement.InnerText;
oMission.m_yStatus = byte.Parse(strState);
}
else if (curElement.Name == "Param0")
{
var strParam0 = curElement.InnerText;
var strParam = strParam0.Split(',');
for (var index = 0; index < strParam.Length; index++)
oMission.m_nParam[index] = int.Parse(strParam[index]);
}
}
}
#endif
return m_MissionClientData;
}
#if UNITY_WP8
public class AutoElement : IXmlSerializable
{
public string AutoPickUp { get; set; }
public string AutoTaem { get; set; }
public string AutoJoinTaem { get; set; }
public string AutoHpPercent { get; set; }
public string AutoHpID { get; set; }
public string AutoMpPercent { get; set; }
public string AutoMpID { get; set; }
public string AutoBuyDrug { get; set; }
public string AutoNotice { get; set; }
public string AutoIsSelectDrug { get; set; }
public string AutoEquipGuid { get; set; }
public string[] AutoSkillID = new string[(int)SKILLDEFINE.MAX_SKILLNUM];
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
reader.Read();
reader.ReadStartElement("AutoPickUp");
AutoPickUp = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("AutoTaem");
AutoTaem = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("AutoJoinTaem");
AutoJoinTaem = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("AutoHpPercent");
AutoHpPercent = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("AutoHpID");
AutoHpID = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("AutoMpPercent");
AutoMpPercent = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("AutoMpID");
AutoMpID = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("AutoBuyDrug");
AutoBuyDrug = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("AutoNotice");
AutoNotice = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("AutoIsSelectDrug");
AutoIsSelectDrug = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("AutoEquipGuid");
AutoEquipGuid = reader.ReadContentAsString();
reader.ReadEndElement();
for (int i = 0; i < (int)SKILLDEFINE.MAX_SKILLNUM; i++)
{
string Elementkeystr = string.Format("keyAutoSelSkillID{0}", i);
reader.ReadStartElement(Elementkeystr);
AutoSkillID[i] = reader.ReadContentAsString();
reader.ReadEndElement();
}
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteElementString("AutoPickUp", AutoPickUp);
writer.WriteElementString("AutoTaem", AutoTaem);
writer.WriteElementString("AutoJoinTaem", AutoJoinTaem);
writer.WriteElementString("AutoHpPercent", AutoHpPercent);
writer.WriteElementString("AutoHpID", AutoHpID);
writer.WriteElementString("AutoMpPercent", AutoMpPercent);
writer.WriteElementString("AutoMpID", AutoMpID);
writer.WriteElementString("AutoBuyDrug", AutoBuyDrug);
writer.WriteElementString("AutoNotice", AutoNotice);
writer.WriteElementString("AutoIsSelectDrug", AutoIsSelectDrug);
writer.WriteElementString("AutoEquipGuid", AutoEquipGuid);
for (int i = 0; i < (int)SKILLDEFINE.MAX_SKILLNUM; i++)
{
string Elementkeystr = string.Format("keyAutoSelSkillID{0}", i);
writer.WriteElementString(Elementkeystr, AutoSkillID[i]);
}
}
}
public class AutoInfo : IXmlSerializable
{
public Dictionary<string, AutoElement> dic { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
dic = new Dictionary<string, AutoElement>();
if (reader.MoveToContent() == XmlNodeType.Element && "AutoInfo" == reader.LocalName)
{
reader.Read();
while (reader.MoveToContent() == XmlNodeType.Element)
{
string name = reader.LocalName;
reader.Read();
if (reader.MoveToContent() == XmlNodeType.Element && "Auto" == reader.LocalName)
{
AutoElement elem = new AutoElement();
elem.ReadXml(reader);
dic.Add(name, elem);
reader.Read();
}
reader.Read();
}
}
}
public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (KeyValuePair<string, AutoElement> elem in dic)
{
writer.WriteStartElement(elem.Key);
writer.WriteStartElement("Auto");
elem.Value.WriteXml(writer);
writer.WriteEndElement();
writer.WriteEndElement();
}
}
}
#endif
// 将角色个人设置信息保存在XML文件中
public static void AddPlayerAuto(string sGUID, PlayerAuto curData)
{
m_AutoConfigMap = GetPlayerAutoList();
if (m_AutoConfigMap.ContainsKey(sGUID)) m_AutoConfigMap.Remove(sGUID);
m_AutoConfigMap.Add(sGUID, curData);
if (!Directory.Exists(DataPath)) Directory.CreateDirectory(DataPath);
#if UNITY_WP8
AutoInfo autoInfo = new AutoInfo();
autoInfo.dic = new Dictionary<string, AutoElement>();
foreach (string keys in m_AutoConfigMap.Keys)
{
string name = "GUID" + keys;
PlayerAuto curList = m_AutoConfigMap[keys];
if (curList != null)
{
AutoElement elem = new AutoElement();
elem.AutoPickUp = curList.AutoPickUp.ToString();
elem.AutoTaem = curList.AutoInviteTeamAccept.ToString();
elem.AutoJoinTaem = curList.AutoJoinTeamAccept.ToString();
elem.AutoHpPercent = curList.AutoHpPercent.ToString();
elem.AutoHpID = curList.AutoHpID.ToString();
elem.AutoMpPercent = curList.AutoMpPercent.ToString();
elem.AutoMpID = curList.AutoMpID.ToString();
elem.AutoBuyDrug = curList.AutoBuyDrug.ToString();
elem.AutoNotice = curList.AutoNotice.ToString();
elem.AutoIsSelectDrug = curList.AutoIsSelectDrug.ToString();
elem.AutoEquipGuid = curList.AutoEquipGuid.ToString();
for (int i = 0; i < (int)SKILLDEFINE.MAX_SKILLNUM; i++)
{
elem.AutoSkillID[i] = curList.AutoSkillID[i].ToString();
}
autoInfo.dic.Add(name, elem);
}
}
XmlHelper.XmlSerializeToFile(autoInfo, DataPath + AutoConfigFileName, new UTF8Encoding(false));
#else
var xml = new XmlDocument();
var root = xml.CreateElement("AutoInfo");
xml.AppendChild(root);
foreach (var keys in m_AutoConfigMap.Keys)
{
var curGUIDElement = xml.CreateElement("GUID" + keys);
root.AppendChild(curGUIDElement);
var curList = m_AutoConfigMap[keys];
if (null != curList)
//foreach (PlayerAuto curAutoData in curList)
{
var curAutoElement = xml.CreateElement("Auto");
curGUIDElement.AppendChild(curAutoElement);
// XmlElement curAutoOpenElement = xml.CreateElement("AutoOpen");
// curAutoOpenElement.InnerText = curList.AutoFightOpenToggle.ToString();
// curAutoElement.AppendChild(curAutoOpenElement);
var curAutoPickUpElement = xml.CreateElement("AutoPickUp");
curAutoPickUpElement.InnerText = curList.AutoPickUp.ToString();
curAutoElement.AppendChild(curAutoPickUpElement);
var curAutoTaemElement = xml.CreateElement("AutoTaem");
curAutoTaemElement.InnerText = curList.AutoInviteTeamAccept.ToString();
curAutoElement.AppendChild(curAutoTaemElement);
var curAutoJoinTaemElement = xml.CreateElement("AutoJoinTaem");
curAutoJoinTaemElement.InnerText = curList.AutoJoinTeamAccept.ToString();
curAutoElement.AppendChild(curAutoJoinTaemElement);
var curAutoHpPercentElement = xml.CreateElement("AutoHpPercent");
curAutoHpPercentElement.InnerText = curList.AutoHpPercent.ToString();
curAutoElement.AppendChild(curAutoHpPercentElement);
var curAutoHpIDElement = xml.CreateElement("AutoHpID");
curAutoHpIDElement.InnerText = curList.AutoHpID.ToString();
curAutoElement.AppendChild(curAutoHpIDElement);
var curAutoMpPercentElement = xml.CreateElement("AutoMpPercent");
curAutoMpPercentElement.InnerText = curList.AutoMpPercent.ToString();
curAutoElement.AppendChild(curAutoMpPercentElement);
var curAutoMpIDElement = xml.CreateElement("AutoMpID");
curAutoMpIDElement.InnerText = curList.AutoMpID.ToString();
curAutoElement.AppendChild(curAutoMpIDElement);
var curAutoBuyDrugElement = xml.CreateElement("AutoBuyDrug");
curAutoBuyDrugElement.InnerText = curList.AutoBuyDrug.ToString();
curAutoElement.AppendChild(curAutoBuyDrugElement);
// XmlElement curAutoRadiusElement = xml.CreateElement("AutoRadius");
// curAutoRadiusElement.InnerText = curList.AutoRadius.ToString();
// curAutoElement.AppendChild(curAutoRadiusElement);
var curAutoNoticeElement = xml.CreateElement("AutoNotice");
curAutoNoticeElement.InnerText = curList.AutoNotice.ToString();
curAutoElement.AppendChild(curAutoNoticeElement);
var curAutoIsSelectDrug = xml.CreateElement("AutoIsSelectDrug");
curAutoIsSelectDrug.InnerText = curList.AutoIsSelectDrug.ToString();
curAutoElement.AppendChild(curAutoIsSelectDrug);
var curAutoEquipGuid = xml.CreateElement("AutoEquipGuid");
curAutoEquipGuid.InnerText = curList.AutoEquipGuid.ToString();
curAutoElement.AppendChild(curAutoEquipGuid);
//for (int i = 0; i < (int)SKILLDEFINE.MAX_SKILLNUM; i++)
//{
// string Elementkeystr = string.Format("keyAutoSelSkillID{0}", i);
// XmlElement curkeyAutoSelSkillIDElement = xml.CreateElement(Elementkeystr);
// if (curList.AutoSkillID == null)
// {
// curkeyAutoSelSkillIDElement.InnerText = (-1).ToString();
// }
// else
// {
// curkeyAutoSelSkillIDElement.InnerText = curList.AutoSkillID[i].ToString();
// }
//
// curAutoElement.AppendChild(curkeyAutoSelSkillIDElement);
//}
}
}
xml.Save(DataPath + AutoConfigFileName);
#endif
}
// 从配置文件读取角色个人设置数据保存在Map中
public static Dictionary<string, PlayerAuto> GetPlayerAutoList()
{
if (null != m_AutoConfigMap) return m_AutoConfigMap;
m_AutoConfigMap = new Dictionary<string, PlayerAuto>();
#if UNITY_WP8
AutoInfo autoInfo =
XmlHelper.XmlDeserializeFromFile<AutoInfo>(DataPath + AutoConfigFileName, new UTF8Encoding(false));
if (null == autoInfo)
{
return m_AutoConfigMap;
}
foreach (KeyValuePair<string, AutoElement> iter in autoInfo.dic)
{
string guid = iter.Key.Substring(4);
AutoElement elem = iter.Value;
PlayerAuto curAutoData =
new PlayerAuto(0, false, false, 0, 0, false, 0, -1, -1, false, GlobeVar.INVALID_GUID,null);
int.TryParse(elem.AutoPickUp, out curAutoData.AutoPickUp);
int.TryParse(elem.AutoTaem, out curAutoData.AutoInviteTeamAccept);
int.TryParse(elem.AutoJoinTaem, out curAutoData.AutoJoinTeamAccept);
int.TryParse(elem.AutoHpPercent, out curAutoData.AutoHpPercent);
int.TryParse(elem.AutoHpID, out curAutoData.AutoHpID);
int.TryParse(elem.AutoMpPercent, out curAutoData.AutoMpPercent);
int.TryParse(elem.AutoMpID, out curAutoData.AutoMpID);
int.TryParse(elem.AutoBuyDrug, out curAutoData.AutoBuyDrug);
int.TryParse(elem.AutoNotice, out curAutoData.AutoNotice);
int.TryParse(elem.AutoIsSelectDrug, out curAutoData.AutoIsSelectDrug);
ulong.TryParse(elem.AutoEquipGuid, out curAutoData.AutoEquipGuid);
for (int i = 0; i < (int)SKILLDEFINE.MAX_SKILLNUM; i++)
{
int nValue = -1;
int.TryParse(elem.AutoSkillID[i], out nValue);
curAutoData.AutoSkillID[i] = nValue;
}
m_AutoConfigMap.Add(guid, curAutoData);
}
#else
var xml = new XmlDocument();
try
{
xml.Load(DataPath + AutoConfigFileName);
}
catch (Exception ex)
{
return m_AutoConfigMap;
}
foreach (XmlElement elemGUID in xml.FirstChild.ChildNodes)
{
//PlayerAuto curList;
var guid = elemGUID.Name.Substring(4);
//m_AutoConfigMap.Add(guid, curList);
foreach (XmlElement autoInfo in elemGUID)
if (autoInfo.Name == "Auto")
{
var curAutoData = new PlayerAuto(0, false, false, 0, 0, false, 0, -1, -1, false,
GlobeVar.INVALID_GUID);
foreach (XmlElement elemDetail in autoInfo)
if (elemDetail.Name == "AutoPickUp")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curAutoData.AutoPickUp);
}
else if (elemDetail.Name == "AutoTaem")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curAutoData.AutoInviteTeamAccept);
}
else if (elemDetail.Name == "AutoJoinTaem")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curAutoData.AutoJoinTeamAccept);
}
else if (elemDetail.Name == "AutoHpPercent")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curAutoData.AutoHpPercent);
}
else if (elemDetail.Name == "AutoHpID")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curAutoData.AutoHpID);
}
else if (elemDetail.Name == "AutoMpPercent")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curAutoData.AutoMpPercent);
}
else if (elemDetail.Name == "AutoMpID")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curAutoData.AutoMpID);
}
else if (elemDetail.Name == "AutoBuyDrug")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curAutoData.AutoBuyDrug);
}
// else if (elemDetail.Name == "AutoRadius")
// {
// string typeValue = elemDetail.InnerText;
// int.TryParse(typeValue, out curAutoData.AutoRadius);
// }
else if (elemDetail.Name == "AutoNotice")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curAutoData.AutoNotice);
}
else if (elemDetail.Name == "AutoIsSelectDrug")
{
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out curAutoData.AutoIsSelectDrug);
}
else if (elemDetail.Name == "AutoEquipGuid")
{
var typeValue = elemDetail.InnerText;
ulong.TryParse(typeValue, out curAutoData.AutoEquipGuid);
}
//else
//{
// for (int i = 0; i < (int)SKILLDEFINE.MAX_SKILLNUM; i++)
// {
// string Elementkeystr = string.Format("keyAutoSelSkillID{0}", i);
// if (elemDetail.Name == Elementkeystr)
// {
// int nValue = -1;
// //string typeValue = elemDetail.InnerText;
// //int.TryParse(typeValue, out nValue);
// //curAutoData.AutoSkillID[i] = nValue;
// }
// }
//}
// curList.Add(curAutoData);
m_AutoConfigMap.Add(guid, curAutoData);
}
}
#endif
return m_AutoConfigMap;
}
#if UNITY_WP8
public class RestaurantElement : IXmlSerializable
{
public string RestaurantFilterExp { get; set; }
public string RestaurantFilterCoin { get; set; }
public string RestaurantFilterMeterial { get; set; }
public string []RestaurantFilterLv = new string[RestaurantData.FoodLevelMax];
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
reader.Read();
reader.ReadStartElement("keyRestaurantFilterExp");
RestaurantFilterExp = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("keyRestaurantFilterCoin");
RestaurantFilterCoin = reader.ReadContentAsString();
reader.ReadEndElement();
reader.ReadStartElement("keyRestaurantFilterMeterial");
RestaurantFilterMeterial = reader.ReadContentAsString();
reader.ReadEndElement();
for (int i = 1; i <= RestaurantData.FoodLevelMax; i++)
{
string Elementkeystr = string.Format("keyRestaurantFilterLv{0}", i);
reader.ReadStartElement(Elementkeystr);
RestaurantFilterLv[i-1] = reader.ReadContentAsString();
reader.ReadEndElement();
}
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteElementString("keyRestaurantFilterExp", RestaurantFilterExp);
writer.WriteElementString("keyRestaurantFilterCoin", RestaurantFilterCoin);
writer.WriteElementString("keyRestaurantFilterMeterial", RestaurantFilterMeterial);
for (int i = 1; i <= RestaurantData.FoodLevelMax; i++)
{
string Elementkeystr = string.Format("keyRestaurantFilterLv{0}", i);
writer.WriteElementString(Elementkeystr, RestaurantFilterLv[i - 1]);
}
}
}
public class RestaurantConfigInfo : IXmlSerializable
{
public Dictionary<string, RestaurantElement> dic { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
dic = new Dictionary<string, RestaurantElement>();
if (reader.MoveToContent() == XmlNodeType.Element && "RestaurantInfo" == reader.LocalName)
{
reader.Read();
while (reader.MoveToContent() == XmlNodeType.Element)
{
string name = reader.LocalName;
reader.Read();
if (reader.MoveToContent() == XmlNodeType.Element && "Restaurant" == reader.LocalName)
{
RestaurantElement elem = new RestaurantElement();
elem.ReadXml(reader);
dic.Add(name, elem);
reader.Read();
}
reader.Read();
}
}
}
public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (KeyValuePair<string, RestaurantElement> elem in dic)
{
writer.WriteStartElement(elem.Key);
writer.WriteStartElement("Restaurant");
elem.Value.WriteXml(writer);
writer.WriteEndElement();
writer.WriteEndElement();
}
}
}
#endif
// 将角色个人设置信息保存在XML文件中
public static void AddRestaurantConfig(string sGUID, RestaurantConfigData curData)
{
m_RestaurantConfigMap = GetRestaurantConfigList();
if (null == m_RestaurantConfigMap) return;
if (m_RestaurantConfigMap.ContainsKey(sGUID)) m_RestaurantConfigMap.Remove(sGUID);
m_RestaurantConfigMap.Add(sGUID, curData);
if (!Directory.Exists(DataPath)) Directory.CreateDirectory(DataPath);
#if UNITY_WP8
RestaurantConfigInfo oRestaurantConfigInfo = new RestaurantConfigInfo();
oRestaurantConfigInfo.dic = new Dictionary<string, RestaurantElement>();
foreach (string keys in m_RestaurantConfigMap.Keys)
{
string name = "GUID" + keys;
RestaurantConfigData curList = m_RestaurantConfigMap[keys];
if (curList != null)
{
RestaurantElement elem = new RestaurantElement();
elem.RestaurantFilterExp = curList.RestaurantFilterExp.ToString();
elem.RestaurantFilterCoin = curList.RestaurantFilterCoin.ToString();
elem.RestaurantFilterMeterial = curList.RestaurantFilterMeterial.ToString();
for (int i = 0; i < RestaurantData.FoodLevelMax && i < elem.RestaurantFilterLv.Length; i++)
{
elem.RestaurantFilterLv[i] = curList.GetRestaurantFilterLv(i+1).ToString();
}
oRestaurantConfigInfo.dic.Add(name, elem);
}
}
XmlHelper.XmlSerializeToFile(oRestaurantConfigInfo, DataPath + RestaurantConfigFileName, new UTF8Encoding(false));
#else
var xml = new XmlDocument();
var root = xml.CreateElement("RestaurantInfo");
xml.AppendChild(root);
foreach (var keys in m_RestaurantConfigMap.Keys)
{
var curGUIDElement = xml.CreateElement("GUID" + keys);
root.AppendChild(curGUIDElement);
var curList = m_RestaurantConfigMap[keys];
if (null != curList)
{
var curRestaurantElement = xml.CreateElement("Restaurant");
curGUIDElement.AppendChild(curRestaurantElement);
var curRestaurantFilterExpElement = xml.CreateElement("keyRestaurantFilterExp");
curRestaurantFilterExpElement.InnerText = curList.RestaurantFilterExp.ToString();
curRestaurantElement.AppendChild(curRestaurantFilterExpElement);
var curRestaurantFilterCoinElement = xml.CreateElement("keyRestaurantFilterCoin");
curRestaurantFilterCoinElement.InnerText = curList.RestaurantFilterCoin.ToString();
curRestaurantElement.AppendChild(curRestaurantFilterCoinElement);
var curRestaurantFilterMeterialElement = xml.CreateElement("keyRestaurantFilterMeterial");
curRestaurantFilterMeterialElement.InnerText = curList.RestaurantFilterMeterial.ToString();
curRestaurantElement.AppendChild(curRestaurantFilterMeterialElement);
for (var i = 1; i <= RestaurantData.FoodLevelMax; i++)
{
var Elementkeystr = string.Format("keyRestaurantFilterLv{0}", i);
var curRestaurantFilterLvElement = xml.CreateElement(Elementkeystr);
curRestaurantFilterLvElement.InnerText = curList.GetRestaurantFilterLv(i).ToString();
curRestaurantElement.AppendChild(curRestaurantFilterLvElement);
}
}
}
xml.Save(DataPath + RestaurantConfigFileName);
#endif
}
// 从配置文件读取角色个人设置数据保存在Map中
public static Dictionary<string, RestaurantConfigData> GetRestaurantConfigList()
{
if (m_RestaurantConfigMap != null) return m_RestaurantConfigMap;
m_RestaurantConfigMap = new Dictionary<string, RestaurantConfigData>();
#if UNITY_WP8
RestaurantConfigInfo oRestaurantConfigInfo =
XmlHelper.XmlDeserializeFromFile<RestaurantConfigInfo>(DataPath + RestaurantConfigFileName, new UTF8Encoding(false));
if (null == oRestaurantConfigInfo)
{
return m_RestaurantConfigMap;
}
foreach (KeyValuePair<string, RestaurantElement> iter in oRestaurantConfigInfo.dic)
{
string guid = iter.Key.Substring(4);
RestaurantElement elem = iter.Value;
RestaurantConfigData curConfigData = new RestaurantConfigData();
int nValue = 1;
int.TryParse(elem.RestaurantFilterExp, out nValue);
curConfigData.RestaurantFilterExp = nValue;
nValue = 1;
int.TryParse(elem.RestaurantFilterCoin, out nValue);
curConfigData.RestaurantFilterCoin = nValue;
nValue = 1;
int.TryParse(elem.RestaurantFilterMeterial, out nValue);
curConfigData.RestaurantFilterMeterial = nValue;
for (int i = 0; i < RestaurantData.FoodLevelMax && i < elem.RestaurantFilterLv.Length; i++)
{
nValue = 1;
int.TryParse(elem.RestaurantFilterLv[i], out nValue);
curConfigData.SetRestaurantFilterLv(i + 1, nValue);
}
m_RestaurantConfigMap.Add(guid, curConfigData);
}
#else
var xml = new XmlDocument();
try
{
xml.Load(DataPath + RestaurantConfigFileName);
}
catch (Exception ex)
{
return m_RestaurantConfigMap;
}
foreach (XmlElement elemGUID in xml.FirstChild.ChildNodes)
{
var guid = elemGUID.Name.Substring(4);
foreach (XmlElement RestaurantElem in elemGUID)
if (RestaurantElem.Name == "Restaurant")
{
var curRrestaurantData = new RestaurantConfigData();
foreach (XmlElement elemDetail in RestaurantElem)
if (elemDetail.Name == "keyRestaurantFilterExp")
{
var nValue = 1;
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out nValue);
curRrestaurantData.RestaurantFilterExp = nValue;
}
else if (elemDetail.Name == "keyRestaurantFilterCoin")
{
var nValue = 1;
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out nValue);
curRrestaurantData.RestaurantFilterCoin = nValue;
}
else if (elemDetail.Name == "keyRestaurantFilterMeterial")
{
var nValue = 1;
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out nValue);
curRrestaurantData.RestaurantFilterMeterial = nValue;
}
else
{
for (var i = 1; i <= RestaurantData.FoodLevelMax; i++)
{
var Elementkeystr = string.Format("keyRestaurantFilterLv{0}", i);
if (elemDetail.Name == Elementkeystr)
{
var nValue = 1;
var typeValue = elemDetail.InnerText;
int.TryParse(typeValue, out nValue);
curRrestaurantData.SetRestaurantFilterLv(i, nValue);
}
}
}
m_RestaurantConfigMap.Add(guid, curRrestaurantData);
}
}
#endif
return m_RestaurantConfigMap;
}
#if UNITY_WP8
public class SkillIndexElement : IXmlSerializable
{
public string SkillIndex { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
reader.Read();
SkillIndex = reader.ReadContentAsString();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteElementString("SkillIndex", SkillIndex);
}
}
public class GUIDElement : IXmlSerializable
{
public List<SkillIndexElement> list { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
list = new List<SkillIndexElement>();
while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "SkillIndex")
{
SkillIndexElement elem = new SkillIndexElement();
elem.ReadXml(reader);
list.Add(elem);
reader.Read();
}
}
public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (SkillIndexElement elem in list)
{
elem.WriteXml(writer);
}
}
}
public class SkillBarSetInfo : IXmlSerializable
{
public Dictionary<string, GUIDElement> dic { get; set; }
public System.Xml.Schema.XmlSchema GetSchema() { return null; }
public void ReadXml(System.Xml.XmlReader reader)
{
dic = new Dictionary<string, GUIDElement>();
if (reader.MoveToContent() == XmlNodeType.Element && "SkillBarSetInfo" == reader.LocalName)
{
reader.Read();
while (reader.MoveToContent() == XmlNodeType.Element)
{
string name = reader.LocalName;
GUIDElement elem = new GUIDElement();
reader.Read();
elem.ReadXml(reader);
dic.Add(name, elem);
reader.Read();
}
}
}
public void WriteXml(System.Xml.XmlWriter writer)
{
foreach (KeyValuePair<string, GUIDElement> elem in dic)
{
writer.WriteStartElement(elem.Key);
elem.Value.WriteXml(writer);
writer.WriteEndElement();
}
}
}
#endif
public class FactionSkillSavePage
{
public const int FACTION_SKILL_NUM = 4;
public ulong RoleGuid;
public int[] SkillIdxs;
}
public static List<FactionSkillSavePage> _FactionSkillPages;
public static FactionSkillSavePage _FactionCurSkillPage;
// 将技能栏设置信息保存在XML文件中
public static void FactionSaveSkillPages()
{
if (_FactionSkillPages == null)
return;
if (!Directory.Exists(DataPath)) Directory.CreateDirectory(DataPath);
var xml = new XmlDocument();
var root = xml.CreateElement("FactionSkillBarSetInfo");
xml.AppendChild(root);
foreach (var factionSkillPage in _FactionSkillPages)
{
var curGUIDElement = xml.CreateElement("GUID" + factionSkillPage.RoleGuid);
root.AppendChild(curGUIDElement);
var _skillBarInfo = factionSkillPage.SkillIdxs;
if (null != _skillBarInfo)
for (var i = 0; i < _skillBarInfo.Length; i++)
{
var curAutoElement = xml.CreateElement("SkillIndex");
curAutoElement.InnerText = _skillBarInfo[i].ToString();
curGUIDElement.AppendChild(curAutoElement);
}
}
xml.Save(DataPath + FactionSkillBarSetFileName);
}
public static void FactionLoadAllSkillPage(string guid)
{
if (_FactionSkillPages != null)
return;
_FactionSkillPages = new List<FactionSkillSavePage>();
var xml = new XmlDocument();
try
{
xml.Load(DataPath + FactionSkillBarSetFileName);
}
catch (Exception ex)
{
return;
}
foreach (XmlElement elemPage in xml.FirstChild.ChildNodes)
{
var roleGuid = elemPage.Name.Substring(4);
var fationSkillPage = new FactionSkillSavePage();
fationSkillPage.RoleGuid = ulong.Parse(roleGuid);
fationSkillPage.SkillIdxs = new int[FactionSkillSavePage.FACTION_SKILL_NUM];
for (var i = 0; i < FactionSkillSavePage.FACTION_SKILL_NUM; i++) fationSkillPage.SkillIdxs[i] = -1;
var nCount = 0;
foreach (XmlElement _ownSkillElement in elemPage)
if (_ownSkillElement.Name == "SkillIndex")
if (nCount >= 0 && nCount < fationSkillPage.SkillIdxs.Length)
{
var typeValue = _ownSkillElement.InnerText;
fationSkillPage.SkillIdxs[nCount] = Convert.ToInt32(typeValue);
nCount++;
}
_FactionSkillPages.Add(fationSkillPage);
if (roleGuid == guid) _FactionCurSkillPage = fationSkillPage;
}
}
[Serializable]
public class SkillSavePage
{
public const int PAGE_SKILL_NUM = 4; //主界面技能是4个 门派挑战可以设置的技能是5个
public ulong RoleGuid;
public int PageIdx;
public string PageName;
public int IsUsing;
public int[] SkillIdxs;
//public SkillSavePage(SkillSavePage copyFrom)
//{
// this.RoleGuid = copyFrom.RoleGuid;
// this.PageIdx = copyFrom.PageIdx;
// this.PageName = copyFrom.PageName;
// this.IsUsing = copyFrom.IsUsing;
// this.SkillIdxs = copyFrom.SkillIdxs;
//}
}
public static List<SkillSavePage> _SkillPages;
public static SkillSavePage _CurSkillPage;
// 将技能栏设置信息保存在XML文件中
public static void SaveSkillPages()
{
if (_SkillPages == null)
return;
if (!Directory.Exists(DataPath)) Directory.CreateDirectory(DataPath);
// 将技能页存一份在到服务器
if (GameManager.gameManager.PlayerDataPool.ClientCustomDateManager != null)
GameManager.gameManager.PlayerDataPool.ClientCustomDateManager.SaveSkillPageData();
var xml = new XmlDocument();
var root = xml.CreateElement("SkillBarSetInfo");
xml.AppendChild(root);
foreach (var skillPage in _SkillPages)
{
var curGUIDElement = xml.CreateElement("GUID" + skillPage.RoleGuid);
curGUIDElement.SetAttribute("PageIdx", skillPage.PageIdx.ToString());
curGUIDElement.SetAttribute("PageName", skillPage.PageName);
if (skillPage.RoleGuid == GameManager.gameManager.PlayerDataPool.MainPlayerBaseAttr.Guid)
{
if (_CurSkillPage == skillPage)
curGUIDElement.SetAttribute("IsUsing", "1");
else
curGUIDElement.SetAttribute("IsUsing", "0");
}
else
{
curGUIDElement.SetAttribute("IsUsing", skillPage.IsUsing.ToString());
}
var _skillBarInfo = skillPage.SkillIdxs;
if (null != _skillBarInfo)
for (var i = 0; i < _skillBarInfo.Length; i++)
{
var curAutoElement = xml.CreateElement("SkillIndex");
curAutoElement.InnerText = _skillBarInfo[i].ToString();
curGUIDElement.AppendChild(curAutoElement);
}
root.AppendChild(curGUIDElement);
}
xml.Save(DataPath + SkillBarSetFileName);
}
public static void LoadAllSkillPage(string guid)
{
// 请求一次存于服务器的技能页
//if (GameManager.gameManager.PlayerDataPool.ClientCustomDateManager != null
// && GameManager.gameManager.PlayerDataPool.ClientCustomDateManager.HasRestoreSkillData == false)
// GameManager.gameManager.PlayerDataPool.ClientCustomDateManager.ReqClienCustomData();
if (_SkillPages != null)
return;
_SkillPages = new List<SkillSavePage>();
var xml = new XmlDocument();
try
{
xml.Load(DataPath + SkillBarSetFileName);
}
catch (Exception ex)
{
return;
}
foreach (XmlElement elemPage in xml.FirstChild.ChildNodes)
{
var roleGuid = elemPage.Name.Substring(4);
var pageIdx = elemPage.GetAttribute("PageIdx");
var pageName = elemPage.GetAttribute("PageName");
var isUsingStr = elemPage.GetAttribute("IsUsing");
var skillPage = new SkillSavePage();
skillPage.RoleGuid = ulong.Parse(roleGuid);
skillPage.PageIdx = int.Parse(pageIdx);
skillPage.PageName = pageName;
var isUsing = int.Parse(isUsingStr);
skillPage.IsUsing = isUsing;
skillPage.SkillIdxs = new int[SkillSavePage.PAGE_SKILL_NUM];
for (var i = 0; i < SkillSavePage.PAGE_SKILL_NUM; i++) skillPage.SkillIdxs[i] = -1;
var nCount = 0;
foreach (XmlElement _ownSkillElement in elemPage)
if (_ownSkillElement.Name == "SkillIndex")
if (nCount >= 0 && nCount < skillPage.SkillIdxs.Length)
{
var typeValue = _ownSkillElement.InnerText;
skillPage.SkillIdxs[nCount] = Convert.ToInt32(typeValue);
nCount++;
}
_SkillPages.Add(skillPage);
if (roleGuid == guid && isUsing > 0) _CurSkillPage = skillPage;
}
}
}