public void InitFromPlayer(Player player) { Id = player.Id; Name = player.Name; AvailableAttributePoints = player.AvailableAttributePoints; _levelBefore = player._levelBefore; Stats.Set(player.Stats); Inventory.Reset(); Inventory.AddInventory(player.Inventory); Position.Set(player.Position.X, player.Position.Y); CombatSkills.Clear(); foreach (int combatSkill in player.CombatSkills) { CombatSkills.Add(combatSkill); } MagicSkills.Clear(); foreach (int magicSkill in player.MagicSkills) { MagicSkills.Add(magicSkill); } CurrentAttackSkill = player.CurrentAttackSkill; EquippedWeapon = player.EquippedWeapon; for (int i = 0; i < player.EquippedItems.Length; i++) { EquippedItems[i] = player.EquippedItems[i]; } }
/* #pragma warning disable CA2227 // Collection properties should be read only * [JsonInclude, JsonPropertyName("SpellStrengths")] * public IDictionary<string, (bool, ushort)> StringKeyedSpells // Ugh, messy hack to work around System.Text.Json having crappy dictionary key support. * { * get => SpellStrengths.ToDictionary(x => x.Key.ToString(), x => x.Value); * set => SpellStrengths = value.ToDictionary(x => SpellId.Parse(x.Key), x => x.Value); * } #pragma warning restore CA2227 // Collection properties should be read only */ public MagicSkills DeepClone() { var clone = new MagicSkills() { SpellPoints = SpellPoints.DeepClone(), SpellClasses = SpellClasses, KnownSpells = KnownSpells.ToList(), SpellStrengths = SpellStrengths.ToDictionary(x => x.Key, x => x.Value) }; return(clone); }
public CharacterMagicEditor(object asset) : base(asset) { _magic = asset as MagicSkills ?? throw new ArgumentNullException(nameof(asset)); }