/// <summary> /// Erzeugt eine neue Player-Instanz an der Default-Position. /// </summary> public Player() { Position = new Coordinate(0, new Index3(0, 0, 100), Vector3.Zero); Velocity = new Vector3(0, 0, 0); Inventory = new List<InventorySlot>(); Tools = new InventorySlot[TOOLCOUNT]; Radius = 0.75f; Angle = 0f; Height = 3.5f; Mass = 100; FlyMode = false; InventoryLimit = 1000; }
/// <summary> /// Deserialisiert den Player aus dem angegebenen BinaryReader. /// </summary> /// <param name="reader">Der BinaryWriter, mit dem gelesen wird.</param> /// <param name="definitionManager">Der aktuell verwendete <see cref="IDefinitionManager"/>.</param> public override void Deserialize(BinaryReader reader, IDefinitionManager definitionManager) { // Entity base.Deserialize(reader, definitionManager); // Radius Radius = reader.ReadSingle(); // Angle Angle = reader.ReadSingle(); // Height Height = reader.ReadSingle(); // Tilt Tilt = reader.ReadSingle(); // FlyMode FlyMode = reader.ReadBoolean(); // Inventory Limit // TODO: Noch nicht persistiert // Inventory int inventoryCount = reader.ReadInt32(); for (int i = 0; i < inventoryCount; i++) { string definitionName = reader.ReadString(); decimal amount = reader.ReadDecimal(); var definition = definitionManager.GetItemDefinitions().FirstOrDefault(d => d.GetType().FullName.Equals(definitionName)); if (definition != null) { InventorySlot slot = new InventorySlot(); slot.Definition = definition; slot.Amount = amount; Inventory.Add(slot); } } // Inventory Tools (Index auf Inventory) byte toolCount = reader.ReadByte(); for (byte i = 0; i < toolCount; i++) { byte index = reader.ReadByte(); string definitionType = reader.ReadString(); InventorySlot slot = Inventory.FirstOrDefault(s => s.Definition.GetType().FullName.Equals(definitionType)); if (slot != null) Tools[index] = slot; } }