Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5943157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:21:17+00:00 2026-05-22T16:21:17+00:00

I have a large abstract class that handles weapons in my game. Combat cycles

  • 0

I have a large abstract class that handles weapons in my game. Combat cycles through a list of basic functions:

OnBeforeSwing
OnSwing
OnHit || OnMiss

What I have in mind is moving all combat damage-related calculations to another folder that handles just that. Combat damage-related calculations.

I was wondering if it would be correct to do so by making the OnHit method an extension one, or what would be the best approach to accomplish this.

Also. Periodically there are portions of the OnHit code that are modified, the hit damage formula is large because it takes into account a lot of conditions like resistances, transformation spells, item bonuses, special properties and other, similar, game elements.

This ends with a 500 line OnHit function, which kind of horrifies me. Even with region directives it’s pretty hard to go through it without getting lost in the maze or even distracting yourself.

If I were to extend weapons with this function instead of just having the OnHit function, I could try to separate the different portions of the attack into other functions.

Then again, maybe I could to that by calling something like CombatSystem.HandleWeaponHit from the OnHit in the weapon class, and not use extension methods. It might be more appropriate.

Basically my question is if leaving it like this is really the best solution, or if I could (should?) move this part of the code into an extension method or a separate helper class that handles the damage model, and whether I should try and split the function into smaller “task” functions to improve readability.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:21:18+00:00Added an answer on May 22, 2026 at 4:21 pm

    I’m going to go out on a limb and suggest that your engine may not be abstracted enough. Mind you, I’m suggesting this without knowing anything else about your system aside from what you’ve told me in the OP.

    In similar systems that I’ve designed, there were Actions and Effects. These were base classes. Each specific action (a machine gun attack, a specific spell, and so on) was a class derived from Action. Actions had an list of one or more specific effects that could be applied to Targets. This was achieved using Dependency Injection.

    The combat engine didn’t do all the math itself. Essentially, it asked the Target to calculate its defense rating, then cycled through all the active Actions and asked them to determine if any of its Effects applied to the Target. If they applied, it asked the Action to apply its relevant Effects to the Target.

    Thus, the combat engine is small, and each Effect is very small, and easy to maintain.

    If your system is one huge monolithic structure, you might consider a similar architecture.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to make an abstract class that handles a pre-render of the
I have large video files (~100GB) that are local on my machine. I have
I have an abstract class A and several implementations of it. I expect this
I have a relatively large dataset of items (a few thousand items) that I
I've got a large, abstract, class InfoBase with lots of properties. Then there are
I have a base class in one assembly and a large number of generated
I have a large table that I want to map to a few entities.
I have a very large Form with many date fields that need to be
I have large images displayed in a grouped tableview. I would like the images
I have large database table, approximately 5GB, now I wan to getCurrentSnapshot of Database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.