Example #1
0
        private static IPlayerUnitEventHandler GetOrCreateEventHandler(playerunitevent nativeEvent)
        {
            if (!eventHandlers.TryGetValue(nativeEvent, out var handler))
            {
                handler = new NativePlayerUnitEventHandler(nativeEvent);
            }

            return(handler);
        }
Example #2
0
        /// <summary>
        /// Adds a custom event. Custom events act as filters to a native playerunitevent. They will automatically be bundled with any other events
        /// attached to that same playerunitevent. Useful when you want multiple events for something not covered by the default provided
        /// <see cref="PlayerUnitEvent"/>s.
        /// <para>For example, the custom event equivalent of <see cref="PlayerUnitEvent.UnitTypeKills"/> would be
        /// AddCustomEventFilter(<see cref="EVENT_PLAYER_UNIT_DEATH"/>, "SomeIdentifier", () => GetUnitTypeId(GetKillingUnit()))</para>
        /// </summary>
        /// <param name="wcEvent">The native WarCraft 3 event to base this custom event on</param>
        /// <param name="identifier">A unique identifier for this custom event</param>
        /// <param name="filterFunc">A function by which can be filtered</param>
        public static void AddCustomEventFilter(playerunitevent wcEvent, string identifier, Func <int> filterFunc)
        {
            var @event = customPlayerUnitEvents.FirstOrDefault(x => x.Identifier == identifier);

            if (@event == null)
            {
                customPlayerUnitEvents.Add(new CustomPlayerUnitEvent
                {
                    Identifier  = identifier,
                    NativeEvent = wcEvent,
                    Func        = filterFunc
                });
            }
            else
            {
                Console.WriteLine($"ERROR: Duplicate custom event definition using identifier {identifier}");
            }
        }
Example #3
0
 public NativePlayerUnitEventHandler(playerunitevent @event)
 {
     NativeEvent = @event;
     BaseActions = new List <Action>();
     Handlers    = new List <InternalHandler>();
 }