Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skill Handler Definitions #332

Open
exectails opened this issue Oct 14, 2024 · 1 comment
Open

Skill Handler Definitions #332

exectails opened this issue Oct 14, 2024 · 1 comment
Labels
enhancement This issue is about improving the quality of code or a feature. refactoring This issue relates to the refactoring of the code.

Comments

@exectails
Copy link
Member

Our skill handlers currently take only the information that we really need, such as the skill in use, the caster, and the target, but there are more parameters sent by the client that we might need inside a skill handler. One example is a direction, which, so far, we handled inside the packet handler, before the skill handler was called.

var direction = packet.GetDirection();
character.TurnTowards(direction);
skillHandler();

Now we finally encountered a skill that doesn't want the character to be pre-turned though, so we either have to semi-hardcode skill checks into the packet handlers, or we have to give control over this to the handlers, for which they need the direction parameter.

Since this might not be the last time we find a new parameter we need, and because we don't want to throw a dozens parameters at a skill handler, half of which may be unknowns, we should bite the bullet and redesign our skill handlers to take a usage parameters object that contains any additional information that might be required. Or rather one usage parameters object per skill type, so we don't end up with unused fields.

For this, we need to decide how we're going to change the skill handlers though. One option would be to only use that parameters object, but then we might end up with a pattern where we're constantly extracting information into variables for simpler use.

public class SomeSkill : IGroundSkillHandler
{
	public void Handle(GroundSkillArgs args)
	{
		var caster = args.Caster;
		var target = args.Target;
		var dir= args.Direction;
		
		character.TurnTowards(dir);

Another option might be to keep the current arguments, but add the object at the end for the remaining parameters. But that seems like a bit of a weird mix.

public class SomeSkill : IGroundSkillHandler
{
	public void Handle(Skill skill, ICombatEntity caster, Position originPos, Position farPos, ICombatEntity target, GroundSkillArgs args)
	{
		character.TurnTowards(args.Direction);

Not yet sure what the best strategy is here. If you have any thoughts, feel free to share them. Note that this affects not only the ground handlers though, but force and target handlers too, as they receive currently unused parameters as well.

@exectails exectails added enhancement This issue is about improving the quality of code or a feature. refactoring This issue relates to the refactoring of the code. labels Oct 14, 2024
@Terotrous
Copy link
Contributor

I certainly lean towards the first option of sending the args. While the refactoring will be a bit annoying it is probably cleaner in the long run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is about improving the quality of code or a feature. refactoring This issue relates to the refactoring of the code.
Projects
None yet
Development

No branches or pull requests

2 participants