I've been working through how to keep the data from getting out of sync between the version of the game in memory and what's in the database, and I think I've found a solution using simple flags. The first flag already existed in previous versions of PRR. These were "returning" flags for each PC. The second is new with the campaign folder system and the increased amount of traveling between module that can occur. I think it also solves some odd behavior that I occasionally ran into when saving and loading.
This issue is that we need to know when to load the data from the database, so that we can get the most recent information from a previous module. At the same time, we need to keep from accidentally overwriting the most recent data that is in the memory of the saved game with the old data from the database.
The other option would be to set up a heartbeat or similar solution that continually flushes the database, but I don't like introducing this kind of overhead for a single-player or multi-player game.
A common scenario of how these flags works, might look like this (I'm using the handles of two of my friends, gothrus and Schuu for this example):
I start a new module.
- A flag gets set noting that I entered.
- All of my faction values get built.
gothrus enters the game.
- A flag gets set noting that he entered.
- All of his faction values get built.
gothrus logs out.
- Nothing happens.
gothrus logs back in.
- We see from the returning flag that he's been here before and do nothing.
We complete a quest and our reputation with x goes up by 5.
- Both of our faction values go up by 5 and get recorded on the database object.
gothrus logs out.
- Nothing happens.
gothrus logs back in.
- We see from the returning flag that he's been here before and do nothing.
Schuu logs in.
- A flag gets set noting that he entered.
- All of his faction values get built (is this based on the leader's faction standings?).
We load the next module.
- The database gets flushed before we unload.
- We set a flag noting that we're coming in from another module.
- In the second module, we see this flag and load the current data from the database
- We unset the transition flag.
We complete another quest in module 2.
- All three of our faction values go up by 5 and get recorded on the database object.
We save the game and log out.
- Nothing happens as the data is in the object.
I load the game next week.
- The database is not loaded because there is no transition flag, meaning the data is all there.
- Not data gets altered since the flag that I've been there before is set and all data is in memory.
Schuu logs in.
- Nothing happens.
gothrus logs in.
- Nothing happens.
We complete another quest in module 2.
- All three of our faction values go up by 5 and get recorded on the database object.
We transition back to module 1.
- The database gets flushed before we unload.
- We set a flag noting that we're coming in from another module.
- In the first module, we see this flag and load the current data from the database
- We unset the transition flag.
This requires the use of a function that will set this flag and flush the database before the standard SaveRosterLoadModule call.
Comments
After digging a bit deeper,
After digging a bit deeper, I realized that the module transition was going to cause some problems because there would be no PC objects for when you wanted to update those reputations. Because of the way the NDBE prepends the PC name and player name to the string name, there really isn't anything to iterate on to go through each pc. Even if there was, there is no PC object until we get to the onClientEnter section.
As a result, I set up a cheap timestamp builder and set a flag noting the last timestamps. Now, the last transition timestamp the PC participated in and the last transition timestamp that the campaign performed are compared when a player enters the module. If the player is behind (meaning some module transitions might have happened since the last time he logged on to the game) his data is updated.
I'll begin testing this week, but I'm hopeful that all of this should work as expected.
The only thing I have left in this is trying to figure out some way to let players who miss sessions and haven't gotten the faction they need to "catch up" to the rest of the party. More on that once I know everything else is working.