/// <summary> /// Initializes a new instance of the <see cref="LogInOperation"/> class. /// </summary> /// <param name="requestorId">The id of the creature requesting the action.</param> /// <param name="client">The client requesting the log in.</param> /// <param name="playerMetadata">The creation metadata of the player that is logging in.</param> /// <param name="worldLightLevel">The level of the world light to send to the player.</param> /// <param name="worldLightColor">The color of the world light to send to the player.</param> public LogInOperation(uint requestorId, IClient client, ICreatureCreationMetadata playerMetadata, byte worldLightLevel, byte worldLightColor) : base(requestorId) { this.Client = client; this.CurrentWorldLightLevel = worldLightLevel; this.CurrentWorldLightColor = worldLightColor; this.PlayerMetadata = playerMetadata; }
/// <summary> /// Creates a new implementation instance of <see cref="ICreature"/> depending on the chosen type. /// </summary> /// <param name="type">The type of creature to create.</param> /// <param name="creatureMetadata">The metadata to create the new creature.</param> /// <returns>A new instance of the chosen <see cref="ICreature"/> implementation.</returns> public ICreature Create(CreatureType type, ICreatureCreationMetadata creatureMetadata) { switch (type) { case CreatureType.NonPlayerCharacter: // if (creatureMetadata is NonPlayerCharacterMetadata npcMetadata) // { // return new NonPlayerCharacter( // npcMetadata.CreatureId, // npcMetadata.Name, // npcMetadata.MaxHitpoints, // npcMetadata.MaxManapoints, // npcMetadata.Corpse, // npcMetadata.Hitpoints, // npcMetadata.Manapoints); // } // throw new InvalidCastException($"{nameof(creatureMetadata)} must be castable to {nameof(NonPlayerCharacterMetadata)} when {type} is used."); case CreatureType.Player: if (creatureMetadata is PlayerCreationMetadata playerMetadata) { return(new Player( playerMetadata.Identifier, playerMetadata.Name, playerMetadata.MaxHitpoints, playerMetadata.MaxManapoints, playerMetadata.Corpse, playerMetadata.Hitpoints, playerMetadata.Manapoints)); } throw new InvalidCastException($"{nameof(creatureMetadata)} must be castable to {nameof(PlayerCreationMetadata)} when {type} is used."); case CreatureType.Monster: // Find the actual monster type to init with. var raceId = Convert.ToUInt16(creatureMetadata.Identifier); if (this.monsterTypeCatalog.TryGetValue(raceId, out IMonsterType monsterType)) { return(new Monster(monsterType, this.ItemFactory)); } throw new InvalidOperationException($"{nameof(creatureMetadata)} has an invalid race Id {creatureMetadata.Identifier}. No monster could be created."); } throw new NotSupportedException($"{nameof(CreatureFactory)} does not support creation of creatures with type {type}."); }