/// <summary> /// Helper function used to fire Attacked events. /// </summary> /// <param name="e">The attacked event arguments.</param> /// <param name="clearOnly">Only clear the action, don't fire the event.</param> private void OnAttacked(AttackedEventArgs e, bool clearOnly) { if (!clearOnly && Attacked != null) { Attacked(this, e); } }
/// <summary> /// Adds a new AttackEventArgs to the collection for a creature. /// When the creature executes the next tick, each of these will /// create an Attacked event that can be used to determine which /// of the one or more creatures attack in the previous tick. /// </summary> /// <param name="attackedEventArgs">Represents the creature doing the attacking</param> public void Add(AttackedEventArgs attackedEventArgs) { if (IsImmutable) { throw new ApplicationException("Object is immutable."); } InnerList.Add(attackedEventArgs); }
// Fired if we're being attacked private void MyAnimal_Attacked(object sender, AttackedEventArgs e) { if (e.Attacker.IsAlive) { AnimalState TheAttacker = e.Attacker; BeginDefending(TheAttacker); //defend against the attacker WriteTrace("Run away to some random point"); int X = OrganismRandom.Next(0, WorldWidth - 1); int Y = OrganismRandom.Next(0, WorldHeight - 1); BeginMoving(new MovementVector(new Point(X, Y), 10)); } }