예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override OrganismState CloneMutable()
        {
            var newInstance = new AnimalState(ID, AnimalSpecies, Generation, EnergyState, Radius);

            CopyStateInto(newInstance);

            return(newInstance);
        }
예제 #2
0
        /// <summary>
        ///  <para>
        ///   Used to determine if your creature is within range to attack another
        ///   target creature.
        ///  </para>
        ///  <para>
        ///   This method does not attempt to validate the position of the
        ///   organismState with respect to the current world state.  If you
        ///   pass a stale object in then you may get stale results.  Make sure
        ///   you use the LookFor method to get the most up-to-date results.
        ///  </para>
        /// </summary>
        /// <param name="targetOrganism">
        ///  OrganismState of the creature you're thinking of attacking.
        /// </param>
        /// <returns>
        ///  True if the creature is within range to attack, False otherwise.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///  Thrown if the targetOrganims parameter is null
        /// </exception>
        public Boolean WithinAttackingRange(AnimalState targetOrganism)
        {
            if (targetOrganism == null)
            {
                throw new ArgumentNullException("targetOrganism", "The argument 'targetOrganism' cannot be null");
            }

            return State.IsWithinRect(1, targetOrganism);
        }
예제 #3
0
        /// <summary>
        ///  <para>
        ///   Used to determine if your creature can attack another creature.
        ///   This will return true all the time for a Carnivore since they
        ///   can always attack.  
        ///  </para>
        ///  <para>
        ///   For Herbivores this will return true if they are hungry enough
        ///   to be aggressive.  Herbivores may also attack a creature in
        ///   the upcoming round if that creature attacked them in the
        ///   previous round.  The best place to attack a creature that is
        ///   attacking you is to handle the Attacked event.
        ///  </para>
        /// </summary>
        /// <param name="targetAnimal">
        ///  AnimalState for the creature you would like to attack.
        /// </param>
        /// <returns>
        ///  True if your creature can attack the target creature, False otherwise.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///  Thrown if the targetAnimal parameter is null.
        /// </exception>
        public Boolean CanAttack(AnimalState targetAnimal)
        {
            if (State.AnimalSpecies.IsCarnivore)
            {
                return true;
            }

            if (targetAnimal == null)
            {
                throw new ArgumentNullException("targetAnimal", "The argument 'targetAnimal' cannot be null");
            }

            // You can attack back if you were just attacked
            var wasAttacked = false;
            foreach (AttackedEventArgs attackEvent in State.OrganismEvents.AttackedEvents)
            {
                if (attackEvent.Attacker.ID != targetAnimal.ID) continue;
                wasAttacked = true;
                break;
            }

            return wasAttacked || State.EnergyState <= EnergyState.Hungry;
        }
예제 #4
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);
            }
        }
예제 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override OrganismState CloneMutable()
        {
            var newInstance = new AnimalState(ID, AnimalSpecies, Generation, EnergyState, Radius);
            CopyStateInto(newInstance);

            return newInstance;
        }
예제 #6
0
 /// <summary>
 ///  Creates a new set of event arguments that can be used to notify
 ///  a creature that another creature has completed an attack action
 ///  against them.
 /// </summary>
 /// <param name="attacker">The state of the attacking creature.</param>
 /// <internal/>
 public AttackedEventArgs(AnimalState attacker)
 {
     Attacker = attacker;
 }
예제 #7
0
 /// <summary>
 ///  Creates a new defend action to defend against a particular target
 ///  creature.
 /// </summary>
 /// <param name="organismID">Defending organism's ID</param>
 /// <param name="actionID">Creature Unique ID for action.</param>
 /// <param name="targetAnimal">The state representing the creature to defend against.</param>
 internal DefendAction(string organismID, int actionID, AnimalState targetAnimal)
     : base(organismID, actionID)
 {
     TargetAnimal = targetAnimal;
 }