Home Artists Posts Import Register

Content

I have thought of doing something different today, rather than showing an already finished thing, I'd show the "programming side" of it; If you would like to see more of these type of posts, do let me know.

One of the upcoming new features in the next version will be the possibility to invest in businesses, it is nothing too complex, most of the logic is both random and manually done, as I will show shortly...


I have started with defining what a business is:
Change can be either positive or negative, which affects whatever the business has lost or gained money on that day, the rate of success is determined by successRate (0 = Always in loss, 100 = always in gain).

investedGold is the amount of gold invested by the player, it can raise up if you are lucky or go down but it will never go below 0, you can lose the gold invested but you cannot go in debt.
potentialEarnings is the amount of gold a business can potentially earn each day, the more successful a business is, the more gold it can earn but also lose.

This is how it is shown in the editor (13 businesses in total, so no need for an ID or something to get a particular business as their index is already known).



Each new day the function UpdateBusinesses will be called, what it does is go through each business and first decide whatever said business will have a loss or a gain that day, for example, if the success rate was set to 100, no matter what the Random value would be, it would always be in gain, likewise if the success rate was set to 0, no matter what the Random value would be, it would be always in loss.

Once that is decided, if the invested gold is more than 0, it will calculate the gained/lost amount, otherwise there is no need to call the other function.

The other function decides, based on the change, the value you gain or lose: You can potentially gain the maximum possible earnings for that business but always lose no more than half of the potential earnings (or nothing if the potential earnings are only a gold).


This is the Interface part, it is mostly uncompleted because there is no interface yet.
I already know that there'll be two buttons: Invest and Withdraw so I made a method for both of them, which takes an index to know which business I am investing on or withdrawing from.


All this code is mostly incomplete: It misses the check for two feats I plan to add next, it misses the interface and all the graphic stuff I still have to do and of course I still need to test all that stuff I wrote which I cannot do before adding the merchant guild map/NPC, so it is likely I made a few mistakes here and there which I will find out only after testing it.

I plan to begin adding the rest between today and tomorrow, mainly the map/npc so I can begin testing what I have done so far and then the actual interface.

Files

Comments

No comments found for this post.