/// <summary> /// Creates a new response with savegame. /// </summary> /// <param name="args">The response arguments.</param> /// <exception cref="ArgumentException">When the arguments have not a minimum length of 1.</exception> protected ResponseWithSavegame(string[] args) : base(args) { if (Args.Length < 1) throw new ArgumentException("The arguments must have a minimum length of 1.", "args"); _savegame = new Savegame(Args[0]); }
public SavegameDump(ISavegame savegame) { if (savegame == null) throw new ArgumentNullException(nameof(savegame)); Header = savegame.Header; Park = savegame.Park; GuestCount = savegame.GuestCount; }
public ISavegame <SavegameContent> Load() { var loadResult = _savegameStorage.Load <SavegameContent>(); if (loadResult.Success) { _savegame = loadResult.Savegame; } else { _logger.Warn("Failed to load Savegame. Creating new one."); _savegame = _savegameFactory.Create <SavegameContent>(); Save(); } return(_savegame); }
private void LoadFromSavegame(ISavegame sg) { Rank = sg.GetValue(SF.SgRank); Level = sg.GetValue(SF.SgLevel); Honor = sg.GetValue(SF.SgHonor); Strength = sg.GetValue(SF.SgAttrStaerke) + sg.GetValue(SF.SgAttrStaerkeBonus); Dexterity = sg.GetValue(SF.SgAttrBeweglichkeit) + sg.GetValue(SF.SgAttrBeweglichkeitBonus); Constitution = sg.GetValue(SF.SgAttrIntelligenz) + sg.GetValue(SF.SgAttrIntelligenzBonus); // mistake in Intelligence = sg.GetValue(SF.SgAttrAusdauer) + sg.GetValue(SF.SgAttrAusdauerBonus); // original source code Luck = sg.GetValue(SF.SgAttrWillenskraft) + sg.GetValue(SF.SgAttrWillenskraftBonus); int level = sg.GetValue(SF.SgLevel); int potionGain = sg.GetValue(SF.SgPotionGain); var charClass = (SfClass) sg.GetValue(SF.SgClass); int damageMin = sg.GetValue(SF.SgDamageMin); int damageMax = sg.GetValue(SF.SgDamageMax); Defense = Strength/2; Evasion = Dexterity/2; Resistance = Intelligence/2; CriticalHit = Math.Round(Luck*5/(double) (level*2), 2); if (CriticalHit < 0) CriticalHit = 0; else if (CriticalHit > 50) CriticalHit = 50; int tmpHealth = 0; for (int i = 0; i < 3; i++) { int potionType = sg.GetValue(SF.SgPotionType + i); if (potionType == 16) tmpHealth = potionGain; } double tmpDamageFactor; int tmpLifeFactor; switch (charClass) { case SfClass.Warrior: tmpDamageFactor = 1 + (double) Strength/10; tmpLifeFactor = 5; break; case SfClass.Mage: tmpDamageFactor = 1 + (double) Intelligence/10; tmpLifeFactor = 2; break; case SfClass.Scout: tmpDamageFactor = 1 + (double) Dexterity/10; tmpLifeFactor = 4; break; default: throw new ArgumentOutOfRangeException(); } DamageMin = (int) Math.Round(damageMin*tmpDamageFactor); DamageMax = (int) Math.Round(damageMax*tmpDamageFactor); HitPoints = (int) Math.Round((double) tmpLifeFactor*Constitution*(1 + level)* (tmpHealth > 0 ? 1 + tmpHealth*0.01 : 1)); Inventory = _itemProvider.CreateInventory(sg); }
public static string SerializeToString(ISavegame savegame) { if (savegame == null) throw new ArgumentNullException(nameof(savegame)); var settings = new JsonSerializerSettings { ContractResolver = new MiniJsonContractResolver(), Converters = new[] {new MiniJsonFloatConverter()} }; return string.Concat(savegame.Data.Select(d => JsonConvert.SerializeObject((d as DataWrapper).Data, settings) + "\r\n")); }
public static void SerializeToStream(ISavegame savegame, Stream stream, bool compress = true) { if (savegame == null) throw new ArgumentNullException(nameof(savegame)); if (stream == null) throw new ArgumentNullException(nameof(stream)); if (compress) using (var gZipStream = new GZipStream(stream, CompressionLevel.Optimal)) using (var streamWriter = new StreamWriter(gZipStream)) { streamWriter.Write(SerializeToString(savegame)); } else using (var streamWriter = new StreamWriter(stream)) { streamWriter.Write(SerializeToString(savegame)); } }
public static void SerializeToFile(ISavegame savegame, string path) { if (savegame == null) throw new ArgumentNullException(nameof(savegame)); if (path == null) throw new ArgumentNullException(nameof(path)); SerializeToStream(savegame, File.Open(path, FileMode.Create), Path.GetExtension(path) == ".park"); }