Refinery System

(Google Translate)
Hello, I am back with the problem of the refinery system, but this time I will explain it with a drawing to see if it can be understood better.

I have Window 1 (main window) where the empty slots are, the player who clicks on any empty slot opens Window 2, where he can choose the material he wants to refine.

I more or less gave him context of the mechanics that I want to achieve, I can do it individually each slot with its respective material, but my idea is that if the player wants ALL the empty slots to be refining carbon, they can do it, or if they want two slot are copper and another two are diamond… and that is where my problem is, I don’t know how to make this “independent” system in a simple way.

I need help with the logic and the placement of the code, I’ve literally been trying something for 4 days but I can’t do it :stuck_out_tongue:

Please understand that I am “new” to this.

Example* :v

I am not sure what the problem is.

I could imagine the code looking a bit like this…

public class Refinery : MonoBehaviour {
  public class RefineryOperation {
    public Material material;
    public float timeLeft;
  }

  public List<RefinerySlot> slots = new();
 
  void Start() {
  
}

(note that you’d need to add null elements to the list at some point; a static array might be nicer to work with if the number of refinery slots is fixed)

To start refining a material, you would set the fields of one of the slots:

public void Refine(int index, Material material, float time) {
  slots[index] = new RefineryOperation();
  slots[index].material = material,
  slots[index].timeLeft = time
}

Then you’d count timeLeft down to zero and do something when the time hits zero.

(could be prettier, yes :p)

Perhaps you could show what you’ve tried doing so far? I don’t see any big problems here.

Break this into a few parts:

  • the presentation and interaction:
    ----> what the user sees onscreen
    ----> what the user can click (or drag) to cause something (“please refine this thing”)

  • the actual internal logic of doing the thing
    ----> accept the “intent” from above and do it
    ----> update the stored logic so that it can be seen by the user

  • any other effects such as a “poof” of smoke as it converts, or animation.

But start small (see below) and iterate, build upon success.

Also, keep in mind that inventories are VERY advanced!! Here are some notes to consider:

These things (inventories, shop systems, character customization, etc) are fairly tricky hairy beasts, definitely deep in advanced coding territory.

They contain elements of:

  • a database of items that you may possibly possess / equip
  • a database of the items that you actually possess / equip currently
  • perhaps another database of your “storage” area at home base?
  • persistence of this information to storage between game runs
  • presentation of the inventory to the user (may have to scale and grow, overlay parts, clothing, etc)
  • interaction with items in the inventory or on the character or in the home base storage area
  • interaction with the world to get items in and out
  • dependence on asset definition (images, etc.) for presentation

Just the design choices of an inventory system can have a lot of complicating confounding issues, such as:

  • can you have multiple items? Is there a limit?
  • if there is an item limit, what is it? Total count? Weight? Size? Something else?
  • are those items shown individually or do they stack?
  • are coins / gems stacked but other stuff isn’t stacked?
  • do items have detailed data shown (durability, rarity, damage, etc.)?
  • can users combine items to make new items? How? Limits? Results? Messages of success/failure?
  • can users substantially modify items with other things like spells, gems, sockets, etc.?
  • does a worn-out item (shovel) become something else (like a stick) when the item wears out fully?
  • etc.

Your best bet is probably to write down exactly what you want feature-wise. It may be useful to get very familiar with an existing game so you have an actual example of each feature in action.

Once you have decided a baseline design, fully work through two or three different inventory tutorials on Youtube, perhaps even for the game example you have chosen above.

Breaking down a large problem such as inventory:

If you want to see most of the steps involved, make a “micro inventory” in your game, something whereby the player can have (or not have) a single item, and display that item in the UI, and let the user select that item and do things with it (take, drop, use, wear, eat, sell, buy, etc.).

Everything you learn doing that “micro inventory” of one item will apply when you have any larger more complex inventory, and it will give you a feel for what you are dealing with.

1 Like

Basically you have 2 options : take the mats first then refine or refine and take the mats later. For your system I think it’s simpler if you take the mats immediately and eventually give them back if the slot is cancelled.

So, someone picks a slot, choose a mat, you remove the mats from the inventory and add them to the slot. You process the mats until cancelled or done.

1 Like

I literally want to copy the mechanics of the refinery system of the Game: ExoMiner (Mobile)

That’s excellent. Your first step should be to study that game and create a Game Design Document (GDD) specifying what you want.

https://www.nuclino.com/articles/write-game-design-document

Look to my first post above for how to think about it as you break it down.

After that, it’s just execution, one feature at a time, same way as always.