Best way to pass desired info from one derived class to another?

Hey everybody,

So I have been struggling with the following design. I’m trying to make a quest generator in C#. Each Quest is a several QuestBlocks chained together. So I have a base class named QuestBlock. The derived classes of this are the quest block types, like Kill an NPC, Interact with Entity, Go to Location and so on.

What I want to be able to do is to access a previous QuestBlock and get info about what I can reuse in the current QuestBlock. For example if I have a Go to Location before the Talk to NPC, the talk QuestBlock could ask the Goto block about the location it used.

So here comes the design dilemma. I want to be able to custom design for each specific block what can be reused and what not. So I could have a function like PullInfo, that depending on the QuestBlock could deliver different classes such as Location, NPC or even Collections of these.

Now I tried to do it with a generic in the base class, but if I do a generic there, then I can’t really store the questblocks of a Quest inside a central list. Also, how could I, after calling the PullInfo function figure out what kind of info I got back?

Any help is welcome, and I’m sorry if this isn’t the right place to ask this kind of questions 🙂

submitted by /u/gogo199432
[link] [comments]

Leave a Reply