This repository has been archived on 2025-01-01. You can view files and clone it, but cannot push or open issues or pull requests.
ShiftOS_TheReturn/ShiftOS.Objects/Save.cs

163 lines
4.8 KiB
C#
Raw Normal View History

2017-02-26 14:51:11 -05:00
/*
2017-02-24 20:24:57 -05:00
* MIT License
*
* Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
using System;
using System.Collections.Generic;
2017-02-02 09:47:23 -05:00
using System.Dynamic;
using System.Linq;
using System.Threading;
namespace ShiftOS.Objects
{
//Better to store this stuff server-side so we can do some neat stuff with hacking...
public class Save
{
2017-06-02 11:38:38 -04:00
public bool MusicEnabled = true;
public bool SoundEnabled = true;
public int MusicVolume = 100;
[Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")]
public string Username { get; set; }
2017-06-10 10:17:10 -04:00
public bool IsSandbox = false;
2017-06-10 22:02:10 -04:00
public ulong Codepoints { get; set; }
public Dictionary<string, bool> Upgrades { get; set; }
public int StoryPosition { get; set; }
public string Language { get; set; }
public string MyShop { get; set; }
public List<string> CurrentLegions { get; set; }
public int MajorVersion { get; set; }
public int MinorVersion { get; set; }
public int Revision { get; set; }
2017-04-30 11:44:29 -04:00
public string UniteAuthToken { get; set; }
2017-03-06 12:01:16 -05:00
public bool IsPatreon { get; set; }
2017-04-09 10:00:16 -04:00
public UserClass Class { get; set; }
public double RawReputation { get; set; }
public Reputation Reputation
{
get
{
return (Reputation)((int)Math.Round(RawReputation));
}
}
2017-03-06 12:01:16 -05:00
public string Password { get; set; }
public bool PasswordHashed { get; set; }
public string SystemName { get; set; }
2017-02-02 09:47:23 -05:00
private dynamic _settings = new SettingsObject();
2017-02-26 14:51:11 -05:00
public int ShiftnetSubscription { get; set; }
2017-02-12 18:35:15 -05:00
public Guid ID { get; set; }
public bool IsMUDAdmin { get; set; }
2017-02-02 09:47:23 -05:00
public dynamic Settings
{
get
{
return _settings;
}
}
public int LastMonthPaid { get; set; }
2017-03-06 20:05:24 -05:00
public List<string> StoriesExperienced { get; set; }
public int CountUpgrades()
{
int count = 0;
foreach (var upg in Upgrades)
{
if (upg.Value == true)
count++;
}
return count;
}
2017-05-01 16:09:46 -04:00
public List<ClientSave> Users { get; set; }
2017-06-04 15:18:53 -04:00
/// <summary>
/// DO NOT MODIFY THIS. EVER. YOU WILL BREAK THE STORYLINE. Let the engine do it's job.
/// </summary>
public string PickupPoint { get; set; }
}
2017-02-02 09:47:23 -05:00
public class SettingsObject : DynamicObject
{
private Dictionary<string, object> _settings = null;
public SettingsObject()
{
_settings = new Dictionary<string, object>();
}
public override IEnumerable<string> GetDynamicMemberNames()
{
return _settings.Keys.ToArray();
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
if (_settings.ContainsKey(binder.Name))
{
result = _settings[binder.Name];
return true;
}
else
{
result = null;
return false;
}
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
2017-02-08 18:01:13 -05:00
try
2017-02-02 09:47:23 -05:00
{
2017-02-08 18:01:13 -05:00
if (_settings.ContainsKey(binder.Name))
{
_settings[binder.Name] = value;
}
else
{
_settings.Add(binder.Name, value);
}
2017-02-02 09:47:23 -05:00
}
2017-02-08 18:01:13 -05:00
catch
2017-02-02 09:47:23 -05:00
{
2017-02-08 18:01:13 -05:00
2017-02-02 09:47:23 -05:00
}
return true;
}
}
}