Skip to content

Commit

Permalink
修改删除部分存储项
Browse files Browse the repository at this point in the history
  • Loading branch information
yueluowujiang committed May 9, 2019
1 parent ce52d64 commit 2bc94b2
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 113 deletions.
43 changes: 41 additions & 2 deletions WorldOfTheThreeKingdoms/GameGlobal/StaticMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,12 @@ public static void LoadFromString(Dictionary<int, int> list, string dataString)
char[] separator = new char[] { ' ', '\n', '\r', '\t' };
string[] strArray = dataString.Split(separator, StringSplitOptions.RemoveEmptyEntries);
list.Clear();
for (int i = 0; i < strArray.Length; i += 2)
if(strArray.Length>=2)
{
list.Add(int.Parse(strArray[i]), int.Parse(strArray[i + 1]));
for (int i = 0; i < strArray.Length; i += 2)
{
list.Add(int.Parse(strArray[i]), int.Parse(strArray[i + 1]));
}
}
}

Expand Down Expand Up @@ -557,6 +560,42 @@ public static string SaveToString(Dictionary<int, int> intList)
}
return builder.ToString();
}

public static string SaveToString(List<KeyValuePair<int, int>> List)
{
if (List == null)
{
return "";
}
StringBuilder builder = new StringBuilder();
foreach (KeyValuePair<int, int> num in List)
{
builder.Append(num.Key.ToString() + " " + num.Value.ToString() + " ");
}
return builder.ToString();
}
public static void LoadFromString(List<KeyValuePair<int, int>> list, string dataString)
{
char[] separator = new char[] { ' ', '\n', '\r', '\t' };
string[] strArray = dataString.Split(separator, StringSplitOptions.RemoveEmptyEntries);
list.Clear();
for (int i = 0; i < strArray.Length; i += 2)
{
list.Add(new KeyValuePair<int, int>(int.Parse(strArray[i]), int.Parse(strArray[i + 1])));
}
}
public static GameObjects.zainanlei LoadzainanfromString(string zainanstring)
{
char[] separator = new char[] { ' ', '\n', '\r', '\t' };
string[] strArray = zainanstring.Split(separator, StringSplitOptions.RemoveEmptyEntries);
GameObjects.zainanlei zainan = new GameObjects.zainanlei();
for (int i = 0; i < strArray.Length; i += 2)
{
zainan.zainanleixing = int.Parse(strArray[i]);
zainan.shengyutianshu = int.Parse(strArray[i + 1]);
}
return zainan;
}
}
}

6 changes: 3 additions & 3 deletions WorldOfTheThreeKingdoms/GameObjects/Architecture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void Init()
public bool DayLocationLoyaltyNoChange;
public float DayRateIncrementOfInternal;

[DataMember]
//[DataMember]
public Legion DefensiveLegion;
[DataMember]
public int DefensiveLegionID;
Expand Down Expand Up @@ -7576,7 +7576,7 @@ public Routeway GetConnectedRouteway(Architecture end)
}
return null;
}
[DataMember]
//[DataMember]
public PersonList ConvinceDestinationPersonList = new PersonList();
public PersonList GetConvinceDestinationPersonList(Faction faction)
{
Expand Down Expand Up @@ -14703,7 +14703,7 @@ public FreeText jianzhubiaoti
set;
}
*/
[DataMember]
//[DataMember]
public qizi jianzhuqizi
{
get;
Expand Down
4 changes: 1 addition & 3 deletions WorldOfTheThreeKingdoms/GameObjects/Faction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ public void Init()
public string SectionsString { get; set; }

public SectionList Sections = new SectionList();
[DataMember]
public Dictionary<Point, object> SpyMessageCloseList = new Dictionary<Point, object>();


public bool StopToControl;

public MilitaryKindTable TechniqueMilitaryKinds = new MilitaryKindTable();
Expand Down
81 changes: 47 additions & 34 deletions WorldOfTheThreeKingdoms/GameObjects/GameScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ public void ClearPersonWorkCache()
}

[DataMember]
private CaptiveList captiveData = new CaptiveList();
public CaptiveList captiveData = new CaptiveList();

public CaptiveList Captives
{
Expand Down Expand Up @@ -3232,7 +3232,7 @@ public List<string> ProcessScenarioData(bool fromScenario, bool editing = false)
}
}

if (this.captiveData != null)
if (this.captiveData != null && !editing)
{
foreach (Captive captive in this.captiveData)
{
Expand Down Expand Up @@ -3812,6 +3812,7 @@ void ClearTempDic()
CloseIds.Clear();
HatedIds.Clear();
MarriageGranterId.Clear();
PersonRelationIds.Clear();
}

private void alterTransportShipAdaptibility()
Expand Down Expand Up @@ -4584,8 +4585,10 @@ public bool SaveGameScenario(string LoadedFileName, bool saveMap, bool saveCommo
{
this.GameTime = 0;
}

this.GameTime += (int)DateTime.Now.Subtract(sessionStartTime).TotalSeconds;
if(!editing)
{
this.GameTime += (int)DateTime.Now.Subtract(sessionStartTime).TotalSeconds;
}
sessionStartTime = DateTime.Now;

List<string> errors = new List<string>();
Expand All @@ -4609,16 +4612,18 @@ public bool SaveGameScenario(string LoadedFileName, bool saveMap, bool saveCommo
this.Troops.GameObjects = this.Troops.GameObjects.OrderBy(x => x.ID).ToList();
this.TroopEvents.GameObjects = this.TroopEvents.GameObjects.OrderBy(x => x.ID).ToList();
this.DiplomaticRelations.DiplomaticRelations = this.DiplomaticRelations.DiplomaticRelations.OrderBy(x => x.Value.RelationFaction1ID).ToDictionary(x => x.Key, y => y.Value);
//this.FatherIds = this.FatherIds
//this.MotherIds = this.MotherIds
//this.SpouseIds = this.SpouseIds
//this.BrotherIds = this.BrotherIds
//this.SuoshuIds = this.SuoshuIds
//this.CloseIds = this.CloseIds
//this.HatedIds = this.HatedIds
//this.PersonRelationIds = this.PersonRelationIds
//try
//{
if(editing)
{
this.FatherIds = this.FatherIds.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
this.MotherIds = this.MotherIds.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
this.SpouseIds = this.SpouseIds.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
this.BrotherIds = this.BrotherIds.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
this.SuoshuIds = this.SuoshuIds.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
this.CloseIds = this.CloseIds.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
this.HatedIds = this.HatedIds.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
this.PersonRelationIds = this.PersonRelationIds.OrderBy(x => x.PersonID1).ToList();
}

if (!disposeMemory)
{
this.DisposeLotsOfMemory();
Expand Down Expand Up @@ -4944,26 +4949,23 @@ public bool SaveGameScenario(string LoadedFileName, bool saveMap, bool saveCommo
person.preferredTroopPersonsString = person.preferredTroopPersons.SaveToString();

person.TrainPolicyIDString = person.TrainPolicy == null ? -1 : person.TrainPolicy.ID;
}
}

captiveData = this.Captives;

PersonRelationIds.Clear();

foreach (Person p in this.Persons)
{
foreach (KeyValuePair<Person, int> pi in p.GetRelations())
{
var personIDRelation = new PersonIDRelation()
foreach (KeyValuePair<Person, int> pi in person.GetRelations())
{
PersonID1 = p.ID,
PersonID2 = pi.Key.ID,
Relation = pi.Value
};
PersonRelationIds.Add(personIDRelation);
var personIDRelation = new PersonIDRelation()
{
PersonID1 = person.ID,
PersonID2 = pi.Key.ID,
Relation = pi.Value
};
PersonRelationIds.Add(personIDRelation);
}
}
}
if(!editing)
{
captiveData = this.Captives;
}

if (saveMap)
{
Expand Down Expand Up @@ -5026,10 +5028,13 @@ public bool SaveGameScenario(string LoadedFileName, bool saveMap, bool saveCommo
}

this.CurrentPlayerID = ((this.CurrentPlayer != null) ? this.CurrentPlayer.ID : -1).ToString();
this.PlayerList = this.PlayerFactions.GameObjects.Select(ob => ob.ID).NullToEmptyList();
if(!editing)
{
this.PlayerList = this.PlayerFactions.GameObjects.Select(ob => ob.ID).NullToEmptyList();
this.PlayerInfo = this.GetPlayerInfo();
}
this.Factions.FactionQueue = this.Factions.SaveQueueToString();

this.PlayerInfo = this.GetPlayerInfo();

//row["JumpPosition"] = StaticMethods.SaveToString(new Point?(ScenarioMap.JumpPosition));

Expand Down Expand Up @@ -5107,8 +5112,16 @@ public bool SaveGameScenario(string LoadedFileName, bool saveMap, bool saveCommo
Time = time.ToSeasonDate(),
Title = scenarioClone.ScenarioTitle
};

SaveScenarioSaves(saves);
if(!editing)
{
SaveScenarioSaves(saves);
}
else
{
string saveDir = @"Save\";
string saveFile = saveDir + "Saves.json";
SimpleSerializer.SerializeJsonFile(saves, saveFile);
}
}
}

Expand Down
13 changes: 1 addition & 12 deletions WorldOfTheThreeKingdoms/GameObjects/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public int Karma

private Captive belongedCaptive;

[DataMember]
//[DataMember]
public Captive BelongedCaptive
{
get
Expand Down Expand Up @@ -11097,17 +11097,6 @@ public void SetRelation(Person p, int val)
}
}

//public void RemoveRelation(Person p)
//{
// foreach (KeyValuePair<Person, int> i in this.relations)
// {
// if (i.Key == p)
// {
// this.relations.Remove(p);
// }
// }
//}

public Dictionary<Person, int> GetAllRelations()
{
return new Dictionary<Person, int>(this.relations);
Expand Down
Loading

0 comments on commit 2bc94b2

Please sign in to comment.