/// <summary> /// Initializes a new instance of the <see cref="CombatantCreature"/> class. /// </summary> /// <param name="creationMetadata">The metadata for this player.</param> /// <param name="baseAttackSpeed"> /// Optional. The base attack speed for this creature. /// Bounded between [<see cref="CombatConstants.MinimumCombatSpeed"/>, <see cref="CombatConstants.MaximumCombatSpeed"/>] inclusive. /// Defaults to <see cref="CombatConstants.DefaultAttackSpeed"/>. /// </param> /// <param name="baseDefenseSpeed"> /// Optional. The base defense speed for this creature. /// Bounded between [<see cref="CombatConstants.MinimumCombatSpeed"/>, <see cref="CombatConstants.MaximumCombatSpeed"/>] inclusive. /// Defaults to <see cref="CombatConstants.DefaultDefenseSpeed"/>. /// </param> protected CombatantCreature( ICreatureEntity creationMetadata, decimal baseAttackSpeed = CombatConstants.DefaultAttackSpeed, decimal baseDefenseSpeed = CombatConstants.DefaultDefenseSpeed) : base(creationMetadata) { // Normalize combat speeds. this.baseAttackSpeed = Math.Min(CombatConstants.MaximumCombatSpeed, Math.Max(CombatConstants.MinimumCombatSpeed, baseAttackSpeed)); this.baseDefenseSpeed = Math.Min(CombatConstants.MaximumCombatSpeed, Math.Max(CombatConstants.MinimumCombatSpeed, baseDefenseSpeed)); this.combatSessionDamageTakenMap = new ConcurrentDictionary <uint, uint>(); this.combatSessionAttackedBy = new HashSet <ICombatant>(); this.Skills = new Dictionary <SkillType, ISkill>(); this.Stats.Add(CreatureStat.AttackPoints, new Stat(CreatureStat.AttackPoints, 1, CombatConstants.DefaultMaximumAttackCredits)); this.Stats[CreatureStat.AttackPoints].Changed += this.RaiseStatChange; this.Stats.Add(CreatureStat.DefensePoints, new Stat(CreatureStat.DefensePoints, 2, CombatConstants.DefaultMaximumDefenseCredits)); this.Stats[CreatureStat.DefensePoints].Changed += this.RaiseStatChange; this.StatChanged += (ICreature creature, IStat statThatChanged, uint previousValue, byte previousPercent) => { if (statThatChanged.Type == CreatureStat.HitPoints && statThatChanged.Current == 0) { this.Death?.Invoke(this); } }; // TODO: need to set // combatant.StatChanged = 0; }
/// <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, ICreatureEntity playerMetadata, byte worldLightLevel, byte worldLightColor) : base(requestorId) { this.Client = client; this.CurrentWorldLightLevel = worldLightLevel; this.CurrentWorldLightColor = worldLightColor; this.PlayerMetadata = playerMetadata; }
/// <summary> /// Initializes a new instance of the <see cref="Creature"/> class. /// </summary> /// <param name="creationMetadata">The metadata for this player.</param> protected Creature(ICreatureEntity creationMetadata) { creationMetadata.ThrowIfNull(nameof(creationMetadata)); creationMetadata.Name.ThrowIfNullOrWhiteSpace(nameof(creationMetadata.Name)); if (creationMetadata.MaxHitpoints == 0) { throw new ArgumentException($"{nameof(creationMetadata.MaxHitpoints)} must be positive.", nameof(creationMetadata.MaxHitpoints)); } lock (Creature.IdLock) { this.Id = idCounter++; } this.Name = creationMetadata.Name; this.Article = creationMetadata.Article; this.CorpseTypeId = creationMetadata.Corpse; this.LastMovementCostModifier = 1; this.Outfit = new Outfit { Id = 0, ItemIdLookAlike = 0, }; this.Stats = new Dictionary <CreatureStat, IStat>(); this.creatureAwarenessMap = new Dictionary <ICreature, AwarenessLevel>(); this.Stats.Add(CreatureStat.HitPoints, new Stat(CreatureStat.HitPoints, creationMetadata.CurrentHitpoints == default ? creationMetadata.MaxHitpoints : creationMetadata.CurrentHitpoints, creationMetadata.MaxHitpoints)); this.Stats[CreatureStat.HitPoints].Changed += this.RaiseStatChange; this.Stats.Add(CreatureStat.CarryStrength, new Stat(CreatureStat.CarryStrength, 150, CreatureConstants.MaxCreatureCarryStrength)); this.Stats[CreatureStat.CarryStrength].Changed += this.RaiseStatChange; this.Stats.Add(CreatureStat.BaseSpeed, new Stat(CreatureStat.BaseSpeed, 70, CreatureConstants.MaxCreatureSpeed)); this.Stats[CreatureStat.BaseSpeed].Changed += this.RaiseStatChange; }