Mobile Buff/Debuff System

Hi there,

I am working on a mobile game and I want my consumable items to apply buffs/debuffs to the player.

I need the buff to have an effect on the player, and to do this I want to set a bool to true (playerIsFatigued for example). This Buff will then set a DateTime value to say when it expires and the bool will then be set to false once the buff has ran out.

My main problem is, I need to serialise these DateTime values, so that the player cannot just restart the game to remove the buff. I would also need to then set up some code to see how long the player was offline for, and then set a TimeSpan value of some sort to calculate how much longer the buff will last… This for each different DeBuff that I plan to add is a lot of work, is there anything simpler?

I have already tampered with a system like this, but it is quite troublesome and I was wondering if there was an easier way to go about doing it that doesn’t use DateTime? But I would still want to use real world time for this…

Thanks for the help, and if you have any questions just let me know, any suggestion is appreciated!

2 solutions, the first is to do all what u do, the second is to use the datetime of file saved(data file) : when player exit game, the data are saved, so the “file time modification” is modified.

First solution :

void LoadData() {
    DateTime DisconnectTime = (filesaved.DisconnectTime);
    TimeSpan timeBetween = DateTime.Now - DisconnectTime;
    //Check time -> remove buff if time of buff is out of time
}

Second solution :

void LoadData() {
    //GetFileInfos
    //GetDateTime in FileInfos
    TimeSpan timeBetween = DateTime.Now - (TimeOfFileInfos);
    //Same Things
}

//All codes examples for get a file infos, are in msdn website for C#