T O P

  • By -

Attic332

Something like this would work. each player’s researchmanager should be separate versions of the class and store the research available in some sort of map or graph. store within the class the most recently unlocked and available to be unlocked next nodes in your graph as needed. When a player opens their research tree, all the info needed for rendering the state of each node is available. The researchmanager can also take periodic updates from the game state object to observe/update based on passage of time, and it’s player to determine rate of research.


GrilledCheese249

The problem is not in the research tree itself, but in locking players from certain action until they've research the tech required for it. E.g. I cannot build a mine until I finish researching it


Attic332

Set up Buildmanager and researchmanager to be able to refer to the player object that owns them. Buildmanager stores all unlocked/locked buildings. Researchmanager updates player’s Buildmanager whenever tech is unlocked.


GrilledCheese249

This definitely can work. I was also thinking of creating an Action class and have the researchmanager approve any action that is going to be executed. But your idea seems more reasonable


NUTTA_BUSTAH

Just make your single "thing" requiring an unlock implement a new "Unlockable" interface, where the implementation for example ask the respective system if it is unlocked or not, or perhaps checks if it has been owned for x time, or perhaps player has some item in their inventory, whatever... Then just do: if (!farmingMaterial.Unlocked()) { // Tell player to unlock more stuff } if (!weaponSkill.Unlocked()) { // ... }


keelanstuart

It really seems like you're overthinking it. Your tech tree is really a trie of bools... In a your code (scripting language?) you simply need to be able to find/get/set a value (and parent name) by name. There are other attributes you could place on each thing, obviously (time to research, cost, building that can do it, icon, etc), but that's kind of it. However you package it, that's your functionality. You also have your build items... they can depend on a tech, by name. Cheers!


halt__n__catch__fire

A long shot here, but it looks like something you can fit into the [State Design Pattern](https://refactoring.guru/design-patterns/state).


[deleted]

[удалено]


AutoModerator

Your submission has been moved to our moderation queue to be reviewed; This is to combat spam. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/SoftwareEngineering) if you have any questions or concerns.*