Exemplo n.º 1
0
        /// <summary>
        ///  Helper function used to fire defend events.
        /// </summary>
        /// <param name="e">The defend event arguments.</param>
        /// <param name="clearOnly">Only clear the action, don't fire the event.</param>
        private void OnDefendCompleted(DefendCompletedEventArgs e, bool clearOnly)
        {
            if (InProgressActions.DefendAction != null &&
                e.ActionID == InProgressActions.DefendAction.ActionID)
            {
                InProgressActions.SetDefendAction(null);
            }

            if (!clearOnly && DefendCompleted != null)
            {
                DefendCompleted(this, e);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///  <para>
        ///   Method used to command a creature to begin defending against a specific
        ///   target creature.  You can only defend against one creature at a time,
        ///   so only the final call to BeginDefending will actually be used
        ///   in the upcoming turn.
        ///  </para>
        ///  <para>
        ///   Once your creature has finished defending, the DefendCompleted event will
        ///   be fired and your event handler will be called if you provided one.  You
        ///   can use this event to determine the results of your defense.
        ///  </para>
        /// </summary>
        /// <param name="targetAnimal">
        ///  The AnimalState that represents the animal you want to defend against.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///  Thrown if the targetAnimal parameter is null.
        /// </exception>
        public void BeginDefending(AnimalState targetAnimal)
        {
            if (targetAnimal == null)
            {
                throw new ArgumentNullException("targetAnimal", "The argument 'targetAnimal' cannot be null");
            }

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

            lock (PendingActions)
            {
                PendingActions.SetDefendAction(action);
                InProgressActions.SetDefendAction(action);
            }
        }