#I have absolutely no idea how to code this, or really how to word it

1 messages · Page 1 of 1 (latest)

hollow rover
#

Okay, so I'm writing a custom D&D character creator and manager (like, has a built in dice roller, with a manual input and the ability to click a skill and it rolls for you with all the modifiers and stuff), for funsies and to get more experience making complex data structures, and im in a bit of a design wall at the moment.

So, at the moment I am trying to think of how to make a system that allows your character to have multiple 'traits', basically things in the character creator that have a name, description, and something that modifies your character ( for example, granting proficiency in a skill, this "something" sometimes would be null, for things that cant be represented in the character sheet ( like rp abilities, conditional advantage on rolls and other such ) )

Im not good at wording design issues, so I will make a list of requirements.

1 - CC_Character has a single list of several 'trait' components
2 - every type of trait would need to be able to go into the same list, whether by inhereting from an abstract class or other programming wizardry
3 - the trait component must be able to modify CC_Character in a way that allows its modifications to be tracked, so changes can be reverted if you remove the trait from the character.
4 - handling for the fact some granted traits would require varying parameters
5 - must be JSON friendly

#

sorry if i worded it awfully, i can try to answer questions to clear things up

zealous widget
#

So when your thinking about how you would want to do this, what aspects of c#/composing code/unity etc. are a mystery to you? What about this specifically has you stuck

hollow rover
# zealous widget So when your thinking about how you would want to do this, what aspects of c#/co...

for example, if i make the trait component an abstract class, called like CC_Trait, with an abstract method called ModifyChar(CC_Character character), so every class that inherets from CC_Trait can have that same method and also be included in a List<CC_Trait> despite being different, i run into a design issue since a lot traits will need different parameters

like a variant of CC_Trait that grants you a skill proficiency would be ModifyChar(CC_Character character, CC_SkillEnum skill), but a trait variant that grants you a natural weapon would be ModifyChar(CC_Character character, CC_Weapon weapon)

#

which cant be done afaik bc of how abstract methods work

#

idk why this specific thing is giving me immense brain fog

zealous widget
#

Sorry to be a pain but would you mind making a super rough example scenario of a situation/context where that modifychar function would be run?

hollow rover
#

lets say the character creator is up and running, you are presented with a list of traits, you pick one, then every trait gets refreshed ( as in, removed from the character then readded, including new stuff ), a trait refresh would also happen if you remove something

#

the trait refresh would to be to avoid having to make a system where somehow every variable in CC_Character knows if it was modified by a trait or not, and which one it was changed by

#

i think my current best idea is to have one CC_Trait with an absolutely comically large constructor and list of parameters, and just have a shit ton of checks to make sure you cant, for example, make a trait ( through a JSON file ) that grants advantage in something without declaring what skill it is youre doing that to

zealous widget
#

So from how I'm reading this system, this would be my personal suggestion (might not be the best!)

Remove ModifyChar()'s responsibility to pass in the context completely. ModifyChar() provides the trait just the context of the character and it's the traits job to get the info needed to modify the character (eg. skillenum, weapon etc.) elsewhere and apply it in their implementation of ModifyChar().

In order to do this you may also need a seperate abstract function / logic step here where CC_Trait maybe has like a GenerateRandomValues() function that either the thing that creates it (the character character here i guess) calls it or its called from the constructor itself.

hollow rover
#

sorry but can you explain it a bit simpler (for some reason programming things like this COMPLETELY shut off my brain)

zealous widget
#

yeah give me a sec

zealous widget
# hollow rover for example, if i make the trait component an abstract class, called like ``CC_T...

Very, very primitive example but the idea here is wanting per type context in the abstract function params here defeats the purpose of abstract functions and the benefits of inheritance, You'd want the classes implementing the abstract function to handle the specific usecases in the implementations themselves

public abstract class Trait
{
    public abstract void ApplyTrait(RPGCharacter character);

    public abstract void RandomiseTraitValues();

    public Trait()
    {
        RandomiseTraitValues();
    }
}
public class SpeedTrait : Trait
{
    private float weightModifier;

    public override void ApplyTrait(RPGCharacter character)
    {
        character.WeightModifier = weightModifier;
    }

    public override void RandomiseTraitValues()
    {
        weightModifier = Random.Range(1f, 1.7f);
    }
}
hollow rover
#

my brain is for some reason completely overcomplicating this, bc like, idk theres still the issue of something like SpeedTrait would require completely different parameters in its constructor than something like SkillTrait

zealous widget
#

Right now, What is in charge of giving SkillTrait the info you want in that constructor param? (which im guessing is just some skill value)

hollow rover
#

SkillTrait would require a CC_SkillEnum and a CC_ProficiencyType

#

but something like SpeedTrait would require a speed struct

zealous widget
#

Might have misread my question

#

What is in charge of giving those values?

hollow rover
#

a JSON file

#

unless im still misreading

zealous widget
#

You click the dice roll button on the skill, it makes a new Trait, say SkillTrait. What gives that new SkillTrait a SkillEnum and ProficiencyType?

hollow rover
#

oh, clicking a dice roll button wouldnt be making the trait, the trait would be premade with a JSON file that is added to your character during character creation.

#

if ur unfamiliar i can explain how skills work in D&D

zealous widget
#

I just expected the json to be generated via code, not by hand

hollow rover
#

ohh, nah the JSON file is made manually, so users can add new content

zealous widget
#

Oh well

#

not sure if you know but you can just like make objects from json without the need for constructors or stuff

hollow rover
#

ohhh, right

zealous widget
#

and serializing/deserializing SpeedTrait would populate weightModifier correctly without any need for constructors

hollow rover
#

riiight