Hi,
I'm doing a modular system for my multiplayer game to run actions on the server. So far it's working fine, an action is identified by a code on an enum, and it can run a callable to check conditions and then an other callable to actually do the action.
I do this by declaring these 2 variables :
var check: Callable = func(_player: Player) -> bool: return true
var action: Callable = func(_player: Player, _data: Variant) -> void: pass
and I then do this in my run method :
func run(data: Variant) -> void:
var player: Player = GameServer.get_current_player()
if player == null or player.party == null:
return
if check.call(player):
print("%s (%d) running action %s" % [player.label, player.id, Code.keys()[code]])
action.call(player, data)
else:
push_warning("%s (%d) could not run action %s" % [player.label, player.id, Code.keys()[code]])
It's ok but it's a bit cumbersome to register a new action, as I have to use lambdas to register them like this :
var validate_hand_action := Action.new()\
.with_check(func(player: Player) -> bool:
return player.state.current == StateManager.EState.RESHUFFLE)\
.with_action(func(player: Player, _data: Variant) -> void:
player.validate_hand())