/// <summary> /// 加载角色数据到存档中 /// </summary> /// <param name="DataJson"></param> public static void LoadActorData(string DataJson) { ActorAllData allData = JsonConvert.DeserializeObject <ActorAllData>(DataJson); int ActorID = 0; if (RuntimeConfig.EmptyActorId.Count == 0) { ActorID = (int)AccessTools.Method(typeof(DateFile), "GetNewActorId").Invoke(DateFile.instance, new object[] { }); } else { ActorID = RuntimeConfig.EmptyActorId.Pop(); } Characters.AddChar(ActorID, allData.ActorData); LifeRecords.AddRecords(ActorID, allData.LifeRecords.ToArray()); RuntimeConfig.TraverserLifeRecordFix.Add(ActorID, allData.LifeRecordFix); DateFile.instance.actorInjuryDate[ActorID] = allData.InjuryData; DateFile.instance.actorStudyDate[ActorID] = allData.StadyData; DateFile.instance.actorItemsDate[ActorID] = allData.ItemsData; DateFile.instance.actorEquipGongFas[ActorID] = allData.EquipGongFas; DateFile.instance.actorGongFas[ActorID] = allData.GongFas; DateFile.instance.actorLife[ActorID] = new Dictionary <int, List <int> >(); DateFile.instance.MoveOutPlace(ActorID); var place = DateFile.instance.GetActorAtPlace(DateFile.instance.mianActorId); DateFile.instance.MoveToPlace(place[0], place[1], ActorID, true); }
/// <summary> /// 导出人物数据 /// </summary> /// <param name="ActorID">导出的角色</param> /// <param name="DumpLifeRecord">是否导出记录</param> /// <param name="FixedActorName">是否导出生平中角色 ID 对应的名字</param> /// <param name="FileName">导出的名字</param> /// <returns></returns> public static string DumpActorData(int ActorID, bool DumpLifeRecord = true, bool FixedActorName = false, string FileName = "") { var Address = Path.Combine(ArchiveSystem.SaveGame.GetSavingRootDir(), $"Date_{SaveDateFile.instance.dateId}"); if (string.IsNullOrEmpty(FileName)) { FileName = DateFile.instance.GetActorName(ActorID); } Address = Path.Combine(Address, FileName + $"{ActorID}.json"); ActorAllData AllData = new ActorAllData(); AllData.LifeRecords = DumpLifeRecord ? (FixedActorName ? GetLifeRecords(ActorID) : DelLifeRecord(GetLifeRecords(ActorID), RecordType: 0)) : new List <LifeRecords.LifeRecord>(); AllData.LifeRecordFix = new Dictionary <int, string>(); AllData.InjuryData = DateFile.instance.actorInjuryDate[ActorID]; AllData.StadyData = DateFile.instance.actorStudyDate[ActorID]; AllData.ItemsData = DateFile.instance.actorItemsDate[ActorID]; AllData.EquipGongFas = DateFile.instance.actorEquipGongFas[ActorID]; AllData.GongFas = DateFile.instance.actorGongFas[ActorID]; AllData.ActorData = new Dictionary <int, string>(); foreach (var key in RuntimeConfig.ActorDataKeyUsed) { if (Characters.HasCharProperty(ActorID, key)) { AllData.ActorData[key] = Characters.GetCharProperty(ActorID, key); } } if (FixedActorName) { for (var i = 0; i < AllData.LifeRecords.Count; i++) { string text = DateFile.instance.actorMassageDate[AllData.LifeRecords[i].messageId][2]; var paramType = (text == "-1") ? new List <int>() : Enumerable.ToList(Enumerable.Select(text.Split('|'), int.Parse)); if (!paramType.Contains(0)) { continue; } object temp = AllData.LifeRecords[i]; for (int index = 0; index < paramType.Count; index++) { if (paramType[index] == 0) { var paramInfo = typeof(LifeRecords.LifeRecord).GetField("param" + index.ToString()); var value = (int)paramInfo.GetValue(temp); value = Math.Abs(value); paramInfo.SetValue(temp, -value); AllData.LifeRecordFix[-value] = DateFile.instance.GetActorName(value); } } AllData.LifeRecords[i] = (LifeRecords.LifeRecord)temp; } } var result = JsonConvert.SerializeObject(AllData); var file = File.CreateText(Address); file.Write(result); file.Flush(); file.Close(); return(result); }