Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed save data in Questing Foe to allow for custom foe ids #2535

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions Assets/Scripts/Game/Questing/Foe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public MobileTypes FoeType

public override Genders Gender
{
get { return ((int)foeType < 128) ? Genders.Male : humanoidGender; }
get { return DaggerfallEntity.IsClassEnemyId((int)foeType) ? humanoidGender : Genders.Male; }
}

public int SpawnCount
Expand Down Expand Up @@ -314,11 +314,40 @@ public struct SaveData_v1
public ItemData_v1[] itemQueue;
}

[fsObject("v2", typeof(SaveData_v1))]
public struct SaveData_v2
{
public int spawnCount;
public int foeId; // allows for custom foes
public Genders humanoidGender;
public bool injuredTrigger;
public bool restrained;
public int killCount;
public string displayName;
public string typeName;
public List<SpellReference> spellQueue;
public ItemData_v1[] itemQueue;

public SaveData_v2(SaveData_v1 v1)
{
spawnCount = v1.spawnCount;
foeId = (int)v1.foeType;
humanoidGender = v1.humanoidGender;
injuredTrigger = v1.injuredTrigger;
restrained = v1.restrained;
killCount = v1.killCount;
displayName = v1.displayName;
typeName = v1.typeName;
spellQueue = v1.spellQueue;
itemQueue = v1.itemQueue;
}
}

public override object GetSaveData()
{
SaveData_v1 data = new SaveData_v1();
SaveData_v2 data = new SaveData_v2();
data.spawnCount = spawnCount;
data.foeType = foeType;
data.foeId = (int)foeType;
data.humanoidGender = humanoidGender;
data.injuredTrigger = injuredTrigger;
data.restrained = restrained;
Expand All @@ -337,9 +366,19 @@ public override void RestoreSaveData(object dataIn)
if (dataIn == null)
return;

SaveData_v1 data = (SaveData_v1)dataIn;
SaveData_v2 data;

if (dataIn is SaveData_v1)
Copy link
Collaborator Author

@KABoissonneault KABoissonneault Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had expected the [fsObject("v2", typeof(SaveData_v1))] attribute on the struct to cause fsSerializer to migrate the struct automatically. This is not the case. I suspect the migration only happens if Foe.SaveData_v2 was the top-level struct being deserialized. In the normal case of loading a save with a pending quest, the save data is nested as a generic object in ResourceSaveData_v1.resourceSpecific.

So, I do the migration manually here

{
data = new SaveData_v2((SaveData_v1) dataIn);
}
else
{
data = (SaveData_v2)dataIn;
}

spawnCount = data.spawnCount;
foeType = data.foeType;
foeType = (MobileTypes)data.foeId;
humanoidGender = data.humanoidGender;
injuredTrigger = data.injuredTrigger;
restrained = data.restrained;
Expand Down