ago1024 / WurmServerModLauncher

Wurm Unlimited Mod Launcher
59 stars 21 forks source link

Add ways to configure what action performers return when reusing existent WU action ID numbers. #37

Closed Joedobo27 closed 3 years ago

Joedobo27 commented 7 years ago

Action performers return true when there aren't any more custom actions to handle. This behaviour conflicts with reusing existent WU action IDs. It would be helpful if we could configure how the various behaviours from Behaviours.class interact with new action performers.

The question is:

ago1024 commented 7 years ago

I'm working on it

Joedobo27 commented 7 years ago

okay, I was going to try and help you but I'd probably just be in the way.

ago1024 commented 7 years ago

The default return value for standard actions (those defined by the server) is now "false". This will prevent unimplemented methods in the ActionPerformer from always cancelling server actions. The default for custom actions remains "true". Unimplemented methods will stop the action. This is not an issue since the action is most likely only used by the mod which defined it.

You can use the propagate() method to set the propagation of the action to the server and other mods and get the return value for the action method.

There are six flags for propate() which can be used in together. If conflicting options are supplied the later ones count:

Any unimplemented methods and the super.action() methods will call defaultPropagation() which does propagate(action, SERVER_PROPAGATION, ACTION_PERFORMER_PROPAGATION). I.E. the default will propagate to other mods, and the server and uses the default return value (false for standard actions, true for custom actions). You can implement defaultPropagation() and set other values to change the behaviour of unimplemented methods.

So some examples:

The propagate() method simply modifies the default values of the current action. Therefore it's possible to setup the propagation defaults anywhere in the action() method and then return true and false as needed.

Joedobo27 commented 7 years ago

Nice, It would have take me a week at least to make something similar in function but my work wouldn't have been so elegant. Thank you for doing this. One question, What happens if say player A tries to override an existent WU, so propagate(action, FINISH_ACTION, SERVER_PROPAGATION, NO_ACTION_PERFORMER_PROPAGATION)

And player b tries to add a new complimenting action that reuses the that same action ID, propagate(action, CONTINUE_ACTION, SERVER_PROPAGATION, ACTION_PERFORMER_PROPAGATION

Given these two uses will there be conflicts? Since we don't control the order is it possible that conflicting flags will cause problems? I not sure if it's even possible to make sure things that continue are executed before things that don't.

ago1024 commented 7 years ago

Sorry for the late reply. I though I had this answered already.

The execution order depends mostly on the order the mods are initialized, so mostly on the name of the mod. This is important with the NO_ACTION_PERFORMER_PROPAGATION. But I think this is mostly used for cases where the affected object is destroyed.

For conflicts between action performers managing the same action the rules are:

Joedobo27 commented 7 years ago

It seems fine so far. I was thinking if it's possible to always order mods so those that want to propagate (whether it be to server or to other action_performer) are done before those that do not. It's a hypothetical that probably doesn't need any attention.

ago1024 commented 7 years ago

The propagation is chosen when the action is performed and can very between each performing of the action. The order of the actions is determined when they are registered at server start. I would probably need to address this with a kind of dependency system where the processing order of the mods is set up.

I'm currently not sure if this is a big problem at all. This probably matters most if two actions would consume an item, like eating something. The order would determine which mod gets the cake. Or one would say "eww. You can't eat this" and the other "You eat the tasty rotten fish".

ago1024 commented 3 years ago

loading order and dependency system has been added in the meantime. #closing