Пример #1
0
        /// <summary>
        ///     Gathers all of the events by specified type and then rolls the virtual dice to determine if any of the events in
        ///     the enumeration should trigger.
        /// </summary>
        /// <param name="sourceEntity">Entities which will be affected by event if triggered.</param>
        /// <param name="eventCategory">Event type the dice will be rolled against and attempted to trigger.</param>
        public void TriggerEventByType(IEntity sourceEntity, EventCategory eventCategory)
        {
            // Roll the dice here to determine if the event is triggered at all.
            var diceRoll = GameSimulationApp.Instance.Random.Next(100);

            if (diceRoll > 0)
            {
                return;
            }

            // Create a random event by type enumeration, event factory will randomly pick one for us based on the enum value.
            var randomEventProduct = _eventFactory.CreateRandomByType(eventCategory);

            // Check to make sure the event returned actually exists.
            if (randomEventProduct == null)
            {
                return;
            }

            // Invokes the event which will give it full control over simulation.
            ExecuteEvent(sourceEntity, randomEventProduct);
        }