tassaron / dnd-character

library for making Dungeons & Dragons 5e characters as serializable data
https://pypi.org/project/dnd-character/
Eclipse Public License 2.0
45 stars 17 forks source link

Multiclassing #25

Open TypicallyThomas opened 10 months ago

TypicallyThomas commented 10 months ago

Amazing library. Just reading the source code is teaching me a lot about Python I didn't know. I haven't had a full deep dive into the actual workings of the code, but unless I'm missing something, multiclassing isn't currently possible. Is this something you're thinking about? If not, I might be able to have a go at implementing such a feature through a pull request, but I can plainly see you're much better at it than me, so if it is something that interests you, might be worth implementing.

I ask cause I wanna build a program that tries literally every possible character and ranks them based on certain metrics, and so I wanna be able to try every possible multiclass as well. I realise it's quite a complex ask, though, so no sweat if you don't have time for such a massive addition.

tassaron commented 10 months ago

In theory I would like to implement multiclassing, but it would challenge a lot of assumptions made throughout the code.

The code treats "level" and "class" as if they are separate (albeit linked) concepts, but with multiclassing we would have to store class features for each level gained (e.g., at level 6 a character can gain the class features for a level 1 class) rather than assuming the class features based on the level. Hit dice also need to be stored per level in a similar fashion. Spellcasting stat needs to be stored per spell instead of per character (since you can use Int for one spell and Cha for another spell).

For me, it's a question of what API gets exposed to the user, and the API is poorly documented at the moment. I'm working on multi-page documentation (#24) which I'd like to finish first.

I will take a stab at this, and it will definitely happen someday, but it may take me a while to get to it.

How do you think leveling up should work with multiclassing?

from dnd_character.character import Character
from dnd_character.classes import CLASSES
char = Character(classs=CLASSES['ranger'], level=2)

This character would be a level 2 Ranger, and I'm not sure how they would gain a level of Rogue (for example (it's a popular multiclass, I think)).

I can think of some weird designs like this:

# continued from above snippet
char.multiclassing[3] = CLASSES['rogue']
char.level = 3

So then multiclassing would be a list of up to 20 _CLASS objects which could be used when leveling up. But this seems like an unintuitive design. I have to think about it. Feedback on this is highly appreciated!

I do appreciate pull requests, but it's a major change and probably wouldn't be worthwhile for you to spend so much time on it. The API needs to be decided first, either way.

tassaron commented 10 months ago

Another design could be treating the class as an attribute of the character which itself owns the level. E.g., character.rogue.level = 1; character.ranger.level = 2; assert character.level == 3 ... Not sure if setting character.level should be allowed anymore in that case.