public static GameRuntimeData LoadArchive(int fileIndex) { string sPath = GetArchiveFilePath(fileIndex); GameRuntimeData tagArchive = null; if (File.Exists(sPath)) { using (FileStream fs = File.OpenRead(sPath)) { byte[] buffer1 = new byte[sizeof(int)]; fs.Read(buffer1, 0, sizeof(int)); int dataLen = BitConverter.ToInt32(buffer1, 0); byte[] archiveData = new byte[dataLen]; fs.Read(archiveData, 0, dataLen); TDES tdesTool = new TDES(); tdesTool.Init(ConStr.DES_KEY); byte[] decryptData = tdesTool.Decrypt(archiveData); string txtData = System.Text.Encoding.Default.GetString(decryptData, 0, decryptData.Length); Hashtable hsData = txtData.hashtableFromJson(); tagArchive = Saveable.Facade.LoadRoot <GameRuntimeData>(hsData); fs.Close(); } } _instance = tagArchive;//记录单例 _instance.SaveIndex = fileIndex; _instance.InitAllRole(); return(tagArchive); }
//新建一个存档 public static GameRuntimeData CreateNew() { _instance = Saveable.Facade.CreateRoot <GameRuntimeData>(); _instance.SaveIndex = 100; // 不重要 var runtime = _instance; runtime.TeamLevel = 1; _instance.InitAllRole(); var player = runtime.GetRole(0); //主角入当前队伍 runtime.Team.Add(runtime.GetRole(0)); MapRuntimeData.Instance.Clear(); MapRuntimeData.Instance.AddToExploreTeam(player); #if JYX2_TEST //可自由实现新的语法 var content = File.ReadAllLines("CreateTeamDebug.txt"); //初始技能 foreach (var line in content) { if (string.IsNullOrEmpty(line.Trim())) { continue; } if (line.StartsWith("//")) { continue; } if (line.StartsWith("skills=")) //初始技能 { var tmp = line.Replace("skills=", "").Split('|'); foreach (var skill in tmp) { int skillId = int.Parse(skill.Split(',')[0]); string level = skill.Split(',')[1]; player.LearnMagic(skillId); var s = player.Wugongs.Find(p => p.Key == skillId); if (s != null) { s.Level = int.Parse(level); } } } else if (line.StartsWith("teammates=")) //初始队友 { var tmp = line.Replace("teammates=", "").Split('|'); foreach (var roleId in tmp) { int role = int.Parse(roleId); GameRuntimeData.Instance.JoinRoleToTeam(role); } } } #endif return(runtime); }
/// <summary> /// 标记一个事件为正在执行 /// </summary> /// <param name="runtime"></param> public void MarkAsExecuting(GameRuntimeData runtime) { if (this.Repeat == "MapOnce") { MapRuntimeData.Instance.KeyValues[this.Id] = "executing"; } else if (this.Repeat == "Once") { runtime.KeyValues[this.Id] = "executing"; } }
/// <summary> /// 标记一个事件为已完成 /// </summary> /// <param name="runtime"></param> public void MarkAsFinished(GameRuntimeData runtime) { if (runtime == null) { return; } if (this.Repeat == "MapOnce") { MapRuntimeData.Instance.KeyValues[this.Id] = "finished"; } else if (this.Repeat == "Once") { runtime.KeyValues[this.Id] = "finished"; } }
/// <summary> /// 判断一个事件是否已经完成了 /// </summary> /// <param name="runtime"></param> /// <returns></returns> public bool IsFinished(GameRuntimeData runtime) { if (runtime == null) { return(false); } //判断是否已经执行过了 if (this.Repeat == "MapOnce" && MapRuntimeData.Instance.KeyValues.ContainsKey(this.Id)) { return(true); } else if (this.Repeat == "Once" && runtime.KeyValues.ContainsKey(this.Id)) { return(true); } return(false); }