When it comes to such game projects they often contain item systems, and when it comes to such item systems one aspect of such systems is to have a class of item. That is that certain items are of low quality and as such they belong to a class often called common or something to that effect, and then there are items that are of the highest quality in the game and as such they belong to a class such as Epic. So then there is creating a system that can be used to set what the probability of a certain class of item occurring.
This item class module will then not be a whole item system then, let alone a full game prototype of any kind. However it is at least one little component of an item system that has to do with the probability of a certain class of item dropping. There is also the idea of having another set of probabilities for each item of a class also, but that might be a topic for another post that has to do with a more comprehensive over all system for dealing with items in a game.
To make sure that this item class system is working the way that I would want it to I will want to work out at least one if not more demos of the module. For this demo I have made just a very simple canvas project that creates a collection of bars that gives a graphical idea of how often certain item classes will happen over a given amount of item drops when I set the range values for each class in various different kinds of ways.
For example this example I just came up with some fixed static values for the various options that I give to the create method of the item probability module. For example I am setting the levelPer value to 1 with a number literal, but in an actual use case example of this in a game this levelPer value will be set by a players charterer level, or an upgrade option of some kind. I am also setting static values for the range and levelPer values for each item class also. In an actual project these values also might end up being static, or they might be generated by some component of the greater system that uses this. However all of that is a matter for another demo, or maybe a while other post for that matter. For now I will just be dealing with static values for these options and just play around with those to get a sense of what kinds of items to expect for various settings.
So then once I create the item classes object that is created and returned by calling the itemClass create method I will then want to create a bar object for each class. Each bar object will then have a description key, color, and a count variable that will be stepped in a loop where each index value will be a single call of the get random class method of this item probability module.
With this example up and running so far it would seem that this item probability module is working as expected. It might however be called for to work out at least maybe one or two additional demos at some point though as a way to just test out some more things that would be need to work on top of this. However much of that will end up having to do with the nature of the game that would use this, so maybe what really needs to happen is to make one or more simple game projects actually on top of this rather than just a simple demo.
So then for this demo of the module I worked out a very simple game where I just click a mine button and numbers for various types of ores will go up. This is the the first step forward to some kind of actual use case example of this module by making some additional components outside of the module. Some of the code that to do with additional logic that will compose an over all item system.
For this example I just have a collection of arrays for each item class, where each array contains a name of a resource and an additional value that has to do with setting the probability of that resource being the resource that is obtained on each manual click of a mine.