/// <summary>
 ///  Initializes a new set of event arguments that can be used
 ///  in an event handler to notify the creature that an attack
 ///  has been completed.
 /// </summary>
 /// <param name="actionID">The ID of the action.</param>
 /// <param name="action">The action being completed.</param>
 /// <param name="killed">Whether the target was killed.</param>
 /// <param name="escaped">Whether the target escaped.</param>
 /// <param name="inflictedDamage">How much damage was inflicted.</param>
 /// <internal />
 public AttackCompletedEventArgs(int actionID, AttackAction action, Boolean killed, Boolean escaped, int inflictedDamage)
     : base(actionID, action)
 {
     this.inflictedDamage = inflictedDamage;
     this.escaped = escaped;
     this.killed = killed;
 }
Exemplo n.º 2
0
        ///<summary>
        ///</summary>
        ///<param name="attackAction"></param>
        ///<exception cref="ApplicationException"></exception>
        public void SetAttackAction(AttackAction attackAction)
        {
            if (IsImmutable)
            {
                throw new ApplicationException("PendingActions must be mutable to modify actions.");
            }

            AttackAction = attackAction;
        }
Exemplo n.º 3
0
        /// <summary>
        ///  <para>
        ///   Method used to command your creature to start attacking another
        ///   creature.  You can only attack one creature per round, and a single
        ///   call to BeginAttacking will only attack a target creature in the
        ///   upcoming tick.  Calling BeginAttacking multiple times in the same
        ///   turn will only result in your creature attacking the target specified
        ///   in the last call to BeginAttacking.
        ///  </para>
        ///  <para>
        ///   Attacking is asynchronous so you'll need to handle the AttackCompleted
        ///   event in order to get the status of your attack.  A single attack might
        ///   not kill a target enemy so you should detect if the enemy is still
        ///   alive and call BeginAttacking once per round until the target creature
        ///   is either dead or has escaped.
        ///  </para>
        /// </summary>
        /// <param name="targetAnimal">
        ///  The AnimalState object that represents the creature you want your creature to attack.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///  Thrown if the targetAnimal parameter is null.
        /// </exception>
        /// <exception cref="NotHungryException">
        ///  Thrown if the creature is not hungry enough to attack.
        /// </exception>
        public void BeginAttacking(AnimalState targetAnimal)
        {
            if (targetAnimal == null)
            {
                throw new ArgumentNullException("targetAnimal", "The argument 'targetAnimal' cannot be null");
            }

            if (!CanAttack(targetAnimal))
            {
                throw new NotHungryException();
            }

            var actionID = GetNextActionID();
            var action   = new AttackAction(ID, actionID, targetAnimal);

            lock (PendingActions)
            {
                PendingActions.SetAttackAction(action);
                InProgressActions.SetAttackAction(action);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///  <para>
        ///   Method used to command your creature to start attacking another
        ///   creature.  You can only attack one creature per round, and a single
        ///   call to BeginAttacking will only attack a target creature in the
        ///   upcoming tick.  Calling BeginAttacking multiple times in the same
        ///   turn will only result in your creature attacking the target specified
        ///   in the last call to BeginAttacking.
        ///  </para>
        ///  <para>
        ///   Attacking is asynchronous so you'll need to handle the AttackCompleted
        ///   event in order to get the status of your attack.  A single attack might
        ///   not kill a target enemy so you should detect if the enemy is still
        ///   alive and call BeginAttacking once per round until the target creature
        ///   is either dead or has escaped.
        ///  </para>
        /// </summary>
        /// <param name="targetAnimal">
        ///  The AnimalState object that represents the creature you want your creature to attack.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///  Thrown if the targetAnimal parameter is null.
        /// </exception>
        /// <exception cref="NotHungryException">
        ///  Thrown if the creature is not hungry enough to attack.
        /// </exception>
        public void BeginAttacking(AnimalState targetAnimal)
        {
            if (targetAnimal == null)
            {
                throw new ArgumentNullException("targetAnimal", "The argument 'targetAnimal' cannot be null");
            }

            if (!CanAttack(targetAnimal))
            {
                throw new NotHungryException();
            }

            var actionID = GetNextActionID();
            var action = new AttackAction(ID, actionID, targetAnimal);
            lock (PendingActions)
            {
                PendingActions.SetAttackAction(action);
                InProgressActions.SetAttackAction(action);
            }
        }