ModernUO icon indicating copy to clipboard operation
ModernUO copied to clipboard

EventSink Extension

Open 3HMonkey opened this issue 3 years ago • 4 comments

Some systems people plan to implement/migrate use events which cannot be found in EventSink anymore. For example:

  • EventSink.OnEnterRegion
  • EventSink.ResourceHarvestSuccess
  • EventSink.OnKilledBy
  • EventSink.CraftSuccess
  • EventSink.SkillGain
  • ...

3HMonkey avatar Apr 09 '21 09:04 3HMonkey

Those are from ServUO I believe. We can add them. I personally don't like event sinks because they are slow, but I guess that is a question for the shard admin more than anything.

At some point you could add event sinks for EVERYTHING because shard owners should track EVERYTHING. This isn't a good design pattern. 🤔 So I am not against it, but I can see how it can be abused.

kamronbatman avatar Apr 09 '21 16:04 kamronbatman

I am completely open for other approaches. For now I don’t have any idea how to catch events in custom systems without changing a lot of original scripts, so the impact is high. In my opinion RunUO, SunUO, ServUO and whatever life from a community and the scripts people created for others. In the end of the day I don’t have something in mind how to catch triggers :(

3HMonkey avatar Apr 09 '21 20:04 3HMonkey

This is exactly what Event bus pattern solves. The approach is very similar to RunUO/ModernUO EventSink, but instead of calling a static function in an event sink, you send a message:

bus.Publish(new MyMessage());

Then consume it on the client code like this:

bus.Subscribe<MyMessage>((m) => { Console.WriteLine("Message Received!"); });

Note that this way it is not needed to change distro code to communicate two custom systems, as long as they both know the MyMessage class (which could be outside of distro code), it will travel through the generic bus.

Regarding performance, since the bus decouples sending and deliverying messages by introducing async semantics, it is also possible to implement async delivery so that we don't get performance penalty.

ppardalj avatar Apr 17 '21 18:04 ppardalj

yeah that is exactly how to do it for disparate (and async) systems. For @3HMonkey's example, there wouldn't be much more use case than the current EventSink pattern. I do expect the engine of ModernUO itself to take on an ingestion system pattern eventually.

kamronbatman avatar Apr 17 '21 20:04 kamronbatman