Login | Register  
View Article

Current Articles | Categories | Search | Syndication

Saving game data to document database (RavenDb)

WheelMUD can now save custom gaming data to the document database (RavenDb). This makes it extremely easy to deal with changing requirements for custom gaming systems. There is no relational database schema to fight with. You can pass an object, and it's internal representation will saved as a JSON text document on disk.

I did run into some interesting caveats. You have to be careful in what you try to save. You won't be able to save objects that self-reference. The Thing class had a few properties that were of the Thing type. At first I just tried to decorate these with the JsonIgnore attribute. That didn't quite work in my case, because of how the inheritance chain was setup. I ultimately went with a generic class with all the stuff that I wanted to save. This is now the PlayerDocument class. It makes it very easy to deal with.

This is now working consistently. We have player settings saving to the SQLite database, and gaming data saving to the document database. I really like this hybrid approach as it makes the best use of these two technologies. No more trying to shoehorn a non-relational model onto non-relational data.

Here is the code in WheelMUD.ConnectionStates.CreationState that actually does the saving: 

 

// Save to the document database

using (var ravenSession = DalUtils.GetRavenSession())

{

    var bundle = new PlayerDocument

        {

            Behaviors = this.Session.Thing.BehaviorManager.ManagedBehaviors,

            DatabaseId = pb.PlayerData.ID,

            Name = newCharacter.Name,

            LastUpdatedDate = currentTime,

            Stats = this.Session.Thing.Stats,

            GameAttributes = this.Session.Thing.SecondaryStats,

            Skills = this.Session.Thing.Skills,

            SubThings = this.Session.Thing.SubThings

        };

 

    ravenSession.Store(bundle);

    ravenSession.SaveChanges();

}

 

posted @ Tuesday, May 24, 2011 12:18 PM by Fastalanasa

Previous Page | Next Page

COMMENTS

Only registered users may post comments.
Copyright 2007-2012 by WheelMUD  | Terms Of Use | Privacy Statement
Google Analytics Alternative