rwmt / Multiplayer

Zetrith's Multiplayer mod for RimWorld
MIT License
481 stars 96 forks source link

Psychic ritual syncing #482

Open SokyranTheDragon opened 2 months ago

SokyranTheDragon commented 2 months ago

I've decided to look into this over the past 2-3 days and have mostly finished it, however there's still a few things that are needed (so it's currently a draft). Things still needing work:

Info on psychic ritual session, dialog, and patches I've included:

A slight side note about dialogs with sessions (and styling station dialog) - perhaps we should make a single harmony patch to Widgets.ButtonTextWorker with a generalized way to use it? As it stands right now, we basically make two patches per session (prefix and postfix). Having a more generalized way to handle it may be useful in the future.

SokyranTheDragon commented 2 months ago

In case someone skimmed through the contents of the main message - this is a draft because we need to modify ritual prepatches to also work with psychic rituals, so assigning roles will be synced.

SokyranTheDragon commented 2 months ago

I've made a new commit with a few changes/additions.

First, a psychic ritual dialog desync was fixed by seeding the RNG when it may end up being used.

Second (and more importantly), the psychic rituals were synced further. I hope that everything should work now, unless I've missed something.

I have to admit - syncing was done it a rather crude and simple way. I've changed the code to apply the same prepatches for both rituals and psychic rituals (which means 2 patches are applied to those methods now).

This approach could be improved by changing PrepatcherPrefix to accept all subtypes (rather than just having an exact type match). This will reduce the amount of prepatches needed, but (without further changes) won't fully eliminate them - 2 of the patches rely on transforming the arguments, and I could not think of a clear and simple way to handle them. @Zetrith let me know if you'd like me to change this so the prefix will apply to all rituals (ignoring the 2 methods that need transforming arguments).

In any case, I've extracted the argument transformer writer and reader into their own methods, and I've made them generic methods that will handle both normal and psychic rituals.

A final addition was adding a sync worker for PawnPsychicRitualRoleSelectionWidget, as it's used by the synced methods.

SokyranTheDragon commented 2 months ago

I've also decided to mark this PR as ready for review (rather than a draft), as I believe it should be mostly complete (again, ignoring some minor changes to prepatches).

SokyranTheDragon commented 1 month ago

One thing I just had - should sessions for normal and psychic rituals be mutually exclusive? Thinking about it, it seems like it may be safer to do it that way, as this would avoid any issues where pawns are assigned to both a normal and psychic ritual at the same time.

Thoughts?