Search Unity

How to handle idle game storage which is shared between multiple resources?

Discussion in 'Game Design' started by JoeBeer, Jan 8, 2021.

  1. JoeBeer

    JoeBeer

    Joined:
    Jun 19, 2020
    Posts:
    2
    Hi,

    I'm relative new to Unity, C# and game development which is why I'm not familiar with the terms and couldn't find out if there are similar questions already asked in this forum. So feel free to point me to these questions if there are some.

    Background:
    I'm working on an idle game in which the player can produce four different resources. These resources share the same storage, e.g. if the max storage has a capacity of 500 and the player produced already 300 units of resource A, then a total space of 200 is left for all four types of resources.

    Since the resources should also be produced while the player is offline, I'm using a timestamp to calculate the resources produced if the player comes online. So I calculate every resource and add them to the storage after the player presses the collect button.

    My Problem:
    Scenario 1:
    Storage max = 500
    Storage used = 499
    Resource A produced = 100
    Resource B produced = 10
    Resource C produced = 50
    Resource D produced = 20

    Scenario 2:
    Storage max = 500
    Storage used = 10
    Resource A produced = 1500
    Resource B produced = 800
    Resource C produced = 2300
    Resource D produced = 400

    How can I decide how much of which resource type should be stored if I want to store the resource as equal as possible?
    Is this even a good approach to store the resources like this?
    How is this done in similar games?
    Are there frameworks for Unity to do this kind of things?
     
  2. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    Ideally one might imagine that you add them as they're created. You could get a similar effect by using proportions.
    100+10+50+20 = 180
    100/180 = 0.56 * (500-499) =0.56 ~=~1

    1500+800+2300+400=5000
    2300/5000 = 0.46 * 490 = 225.4 ~=~ 225

    I would sort them by largest value, then iteratively check if there's still more than one inventory spot available. If so I'd check if the proportional value is greater than 1: if not, round up to 1, but if so, round normally.
     
  3. JoeBeer

    JoeBeer

    Joined:
    Jun 19, 2020
    Posts:
    2
    EternalAmbiguity thanks for your answer.
    I did add another timestamp which is calculated by production per hour, maximum storage/storage left and the time the production is set, so I can have the time till the production is equal the maximum storage/storage left and stop adding more products to the storage.
     
    EternalAmbiguity likes this.