I'm stuck

posted in mousetails RPG
Published April 28, 2015
Advertisement
So, I was working on the ranged combat system, and now you can throw items one spot by default, and I can set weapons to a custom range. I also found a couple of bugs in the system that only updated the display when it needed to, which made a nice animation when the dagger was flying. What is a bit annoying is the fact that items can move 8 squares in one turn, but it takes multiple turns to go farther. Though this is realistic and a cool mechanic, it feels unnatural to me, especially since the default range is exactly 8 squares.

But now why I am stuck. I implemented a system where a callback function would be called when a flying object hit something. Normally, I just stop the item and do nothing, but for weapons I need to apply damage. I looked at how the original attack function was coded, and found that monsters and players have a reference to a "body" object that handles combat and other type-specific functionality. Body has a function "Attack", that attacks a other body object. This means that I can override it in subclasses for more advanced attacks. For my projectile impact function, I wanted to do something similar to the basic attack function, (Not necessarily the attack function of the thrower) except modify some stats based on size. I tried just calling the method as a static method and passing a dummy object as self, but apparently self has to actually be a instance of the class. I came up with 3 ways to solve this:

A) Make body subclass a dummy class, except the dummy class has a fully functional attack method that I can use when I don't want to create a full instance of the body class

B) Just use a instance of body with a dummy reference to a monster object, so I can feed it it's own values

C) Make the dummy class inherit from monster body, and override getstat() so I can custom morph the accuracy stat

D) Make all attacks static functions in the main class, and have subclasses only specify which ones they know how to do. This way, I have removed almost all code from the monster classes and it solves a side problem because I can now define then in a CSV, XML or JSON file. However, I feel all those static methods will be extremely ugly.

E) Same as D, but define loose functions instead of static methods

F) Anybody have any more ideas?

(Oops, 5 options)

If anybody can give my any advice how to do this, it would be greatly appreciated!

(Ps. I uploaded it to github, and I will post a code guide when I have solved this issue)
2 likes 2 comments

Comments

Aardvajk
If your code requires a body to do an attack, but you now need to do attacks without a body, I'd suggest your current modelling is wrong and you need to refactor. Never be afraid to rewrite as things evolve. Far better than hacking solutions that will bite you later on.
April 28, 2015 04:04 PM
sunandshadow

If a body could have the ability to spawn another body, then a player could spawn a projectile weapon or magic, then the projectile's body can collide with one or more enemies. It seems important to allow for projectile attacks that hit more than one enemy, though there are various ways you could do this. Also, players could spawn summons in the same way as projectiles.

April 28, 2015 10:57 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement