public void Write() { lock (ArchList) { string dataDirectory = PPath.GetPath("Data\\Arcs\\arc.ric"); StreamWriter ArcWriter = new StreamWriter(dataDirectory, false, Encoding.UTF8); ArchList.ForEach((string s) => ArcWriter.WriteLine(s)); ArcWriter.Flush(); ArcWriter.Close(); } }
void Start() { PLogger.StartLogging(true); ArchManager = new PArchManager(); ArchManager.Read(); UserManager = new PUserManager(); UserManager.Read(); #region 初始化地图库 string MapDirectory = PPath.GetPath("Data\\Maps"); string[] MapFileNames = Directory.GetFiles(MapDirectory, "*.xml"); MapList = new List <PMap>(); foreach (string MapFileName in MapFileNames) { MapList.Add(new PMap(MapFileName)); } #endregion }
public void Read() { string dataDirectory = PPath.GetPath("Data\\Arcs\\arc.ric"); StreamReader ArcFileReader = new StreamReader(dataDirectory, Encoding.UTF8); string Line = string.Empty; while ((Line = ArcFileReader.ReadLine()) != null) { if (Line.Length > 0) { ArchList.Add(Line); } else { break; } } ArcFileReader.Close(); }
public void Write() { string dataDirectory = PPath.GetPath("Data\\User\\user.ric"); lock (this) { StreamWriter ArcWriter = new StreamWriter(dataDirectory, false, Encoding.UTF8); ArcWriter.WriteLine("Nickname " + Nickname); ArcWriter.WriteLine("Money " + Money); ArcWriter.WriteLine("ArchPoint " + ArchPoint); ArcWriter.WriteLine("ChooseGeneral " + ChooseGeneral); ArcWriter.WriteLine("Lucky " + Lucky); GeneralList.ForEach((string GeneralName) => { ArcWriter.WriteLine("General " + GeneralName); }); RecordList.ForEach((string Record) => { ArcWriter.WriteLine("Record " + Record); }); ArcWriter.Flush(); ArcWriter.Close(); } }
/// <summary> /// 启动Logger,清空原有日志文件 /// </summary> public static void StartLogging(bool Valid = true, string Path = "") { if (Valid) { IsValid = true; try { if (Writer != null) { Writer.Close(); } Writer = new StreamWriter(PPath.GetPath(Path.Equals(string.Empty) ? Config.LogFileName : Path), false, Encoding.UTF8) { AutoFlush = true }; Writer.WriteLine(PDebug.DebugHeader); } catch { IsValid = false; } } else { IsValid = false; } }
public void Read() { string dataDirectory = PPath.GetPath("Data\\User\\user.ric"); StreamReader ArcFileReader = new StreamReader(dataDirectory, Encoding.UTF8); string Line = string.Empty; while ((Line = ArcFileReader.ReadLine()) != null) { if (Line.Length > 0) { string[] LineData = Line.Split(' '); if (LineData.Length > 1) { string Key = LineData[0]; if (Key.Equals("Nickname")) { Nickname = LineData[1]; } else if (Key.Equals("Money")) { Money = Convert.ToInt32(LineData[1]); } else if (Key.Equals("ArchPoint")) { ArchPoint = Convert.ToInt32(LineData[1]); } else if (Key.Equals("ChooseGeneral")) { ChooseGeneral = Convert.ToInt32(LineData[1]); } else if (Key.Equals("Lucky")) { Lucky = Convert.ToInt32(LineData[1]); } else if (Key.Equals("General")) { GeneralList.Add(LineData[1]); } else if (Key.Equals("Record")) { /* * 记录格式: * Record <使用的武将> Win/Lose <模式> <从1号位起的每名武将> */ if (LineData[1].Contains("|")) { RecordList.Add(LineData[1]); } } } } else { break; } } ArcFileReader.Close(); if (ArchPoint < 0) { // 初始化文件 ArchPoint = (int)PMath.Sum(PSystem.ArchManager.ArchList.ConvertAll((string ArchName) => (double)PObject.ListInstance <PArchInfo>().Find((PArchInfo ArchInfo) => ArchInfo.Name.Equals(ArchName)).ArchPoint)); GeneralList = new List <string>() { "廉颇", "潘岳", "杨玉环", "陈圆圆", "王诩", "赵云", "时迁", "张三丰" }; Write(); } }
public PChooseGeneralTriggerInstaller() : base("选将") { TriggerList.Add(new PTrigger("选将") { IsLocked = true, Time = PTime.ChooseGeneralTime, Effect = (PGame Game) => { List <PGeneral> Generals = new List <PGeneral>(); #region 将卡的结算 List <PGeneral> AvailableGenerals = new List <PGeneral>(); AvailableGenerals = ListSubTypeInstances <PGeneral>().FindAll((PGeneral General) => !(General is P_Soldier) && General.CanBeChoose); Game.Traverse((PPlayer Player) => { if (!(Player.General is P_Soldier)) { AvailableGenerals.RemoveAll((PGeneral General) => General.Name.Equals(Player.General.Name)); } }); List <PAge> Ages = new List <PAge>() { PAge.Classic, PAge.Medieval, PAge.Renaissance, PAge.Industrial }; for (int i = 0; i < 8; ++i) { Generals.Add(new P_Soldier()); } Game.Traverse((PPlayer Player) => { // 现在不能主动选将 if (Player.IsUser && PNetworkManager.NetworkServer.ChooseManager.AskYesOrNo(Player, "是否使用点将卡?")) { PAge Age = Ages[PNetworkManager.NetworkServer.ChooseManager.Ask(Player, "选择时代", Ages.ConvertAll((PAge _Age) => _Age.Name).ToArray())]; List <PGeneral> PossibleGenerals = AvailableGenerals.FindAll((PGeneral General) => General.Age.Equals(Age)); PGeneral TargetGeneral = PossibleGenerals[PNetworkManager.NetworkServer.ChooseManager.Ask(Player, "点将", PossibleGenerals.ConvertAll((PGeneral General) => General.Name).ToArray())]; Generals[Player.Index] = TargetGeneral; PLogger.Log(Player.Index + "号玩家选择了" + TargetGeneral.Name); } }, Game.PlayerList[0]); // 去掉重复的将 AvailableGenerals.ForEach((PGeneral General) => { List <int> ChosenIndex = new List <int>(); for (int i = 0; i < 8; ++i) { if (Generals[i].Equals(General)) { ChosenIndex.Add(i); } } if (ChosenIndex.Count > 1) { PMath.Wash(ChosenIndex); for (int i = 1; i < ChosenIndex.Count; ++i) { Generals[ChosenIndex[i]] = new P_Soldier(); } } }); // 剩下的将随机 // 每个人有4个将可选 // 其中最多1个免费将 List <PGeneral> Selected = new List <PGeneral>(); for (int i = 0; i < Game.PlayerNumber; ++i) { if (Generals[i] is P_Soldier) { List <PGeneral> PossibleGenerals = new List <PGeneral>(); PMath.Wash(AvailableGenerals); bool NoFreeGeneral = true; foreach (PGeneral General in AvailableGenerals) { if (!Generals.Contains(General) && !Selected.Contains(General) && (NoFreeGeneral || General.Cost != 0)) { if (Game.PlayerList[i].IsAI || PNetworkManager.NetworkServer.ChooseManager.AskHaveGeneral(Game.PlayerList[i], General.Name)) { Selected.Add(General); PossibleGenerals.Add(General); if (General.Cost == 0) { NoFreeGeneral = false; } } } if (PossibleGenerals.Count >= 4) { break; } } if (PossibleGenerals.Count == 1) { Generals[i] = PossibleGenerals[0]; } else { if (Game.PlayerList[i].IsAI) { PMath.Wash(PossibleGenerals); Generals[i] = PossibleGenerals.Find((PGeneral _General) => _General.NewGeneral); if (Generals[i] == null) { Generals[i] = PossibleGenerals[0]; } } else { Generals[i] = PossibleGenerals[PNetworkManager.NetworkServer.ChooseManager.Ask(Game.PlayerList[i], "点将", PossibleGenerals.ConvertAll((PGeneral General) => General.Name).ToArray())]; } } } } #endregion #region 全AI模式下指定武将 if (Game.PlayerList.TrueForAll((PPlayer _Player) => _Player.IsAI)) { string dataDirectory = PPath.GetPath("Data\\User\\special.txt"); StreamReader ArcFileReader = new StreamReader(dataDirectory, Encoding.UTF8); string Line = string.Empty; while ((Line = ArcFileReader.ReadLine()) != null) { if (Line.Length > 0 && Line[0] != '#') { string[] LineData = Line.Split('|'); if (LineData.Length == Game.PlayerNumber) { for (int i = 0; i < Game.PlayerNumber; ++i) { PGeneral General = AvailableGenerals.Find((PGeneral _General) => _General.Name.Equals(LineData[i])); if (General != null) { Generals[i] = General; } } } break; } } ArcFileReader.Close(); } #endregion Game.Traverse((PPlayer Player) => { if (Player.General is P_Soldier) { Player.General = Generals[Player.Index]; } Player.Age = Player.General.Age; Player.Sex = Player.General.Sex; Player.General.SkillList.ForEach((PSkill Skill) => { Skill.TriggerList.ForEach((Func <PPlayer, PSkill, PTrigger> TriggerGenerator) => { Game.Monitor.AddTrigger(TriggerGenerator(Player, Skill)); }); }); PNetworkManager.NetworkServer.TellClients(new PRefreshGeneralOrder(Player)); }, Game.PlayerList[0]); } }); }