Devlog #52 - InboxSystem - new system , StoreSystem sell-store, FIXED, code refactoring, bug fixes, Market algorhythm balance , Global Market development.

 *****InboxSystem - totally new system but the idea was there, StoreSystem sellstore fixed - MarketSystem algorhythm more balanaced and refined, and GlobalMarket still in development****


InboxSystem - New system that I have had in mind since long time ago, but now its finally here! So the strucutre that I used for this fits perfectly in the already existing structure. Same as we had for snapshots,(who read the older devlogs hah) ,now i thought ok, we need a simple way of sending 'notifications' to a list, that is then presented as inbox. Essentialy, like the financialHistory, where each addMOney, and removeMoney, is just being added to the ledger ( which is a list on a worldManager), now we did the same. Its quite simple! But still i loved to think and improve it. 

lets get into it!


-Structure - first i created a list among all other lists that represent snapshots for chart values, assets and other. only this time, we call it inbox, 

  public List<InboxMessage> inboxMessages = new List<InboxMessage>();

Then, we create a method that basically just adds the value to this list, and InboxMessage is again a struct, that contains, subject, message, turnNumber...etc, as well as enums, like severtiy, or category, that in inbox can be filtered later, like , if its a building or company loosing money, it sends a warning..

public struct InboxMessage
{
    public string subject;
    public string message;

    public InboxSeverity severity;
   
    public InboxCategory category;

    public int turnNumber;

    public bool isRead;

    public bool isActive;

}

Then,

The system is fairly, simple, we create a static void within the inboxSystem, so now, each and every event that we want to have notification for, we just call upon this method in the inboxSystem. then this creates a new inboxMessage(struct)  and then sends it into the list at the begining. Thats it.




First verison of push message,


Then of course i couldn't leave it like that, because in a single ,for example storeSystem, there is 5-6 places for sure, that will need to send ntoifications, so if i wanna fix or change anything, i have to search among tousand lines. so then i said, ok lets go the refactoring clean route, and create method that will use switch case. 

With last code refactor, we have it like this, so the InboxStoreEvent calls the set rules wether it is info(severity) and category .


    
Then still, it could have been better, the reason was that severity and category are basically fixed, bacuse, for examle, lets say there is an event that a store in this case is in negative balance this day. so the severity is 'Warning'. So it means everytime that happens it will be warning, there is no reason to forward hard coded and long event. , so then refactored to this:

 private static void SendInboxEvent(InboxStoreEvent storeEvent, StoreState store, string cityName)
    {
        switch (storeEvent)
        {
            case InboxStoreEvent.Construction:

                InboxSystem.PushMessage(InboxSeverity.Info, InboxCategory.Construction,
                      subject: $"Store Construction is finished - {store.storeName}.",
                      message: $"{store.storeName} construction is finished in {cityName} and now it is type:{store.storeType}");

                break;

so now, the chances of mistake are minimal, but the organization and fixing changing etc, is way better, and the sendevent call, is simple:

            SendInboxEvent(InboxStoreEvent.NegativeBalance, store, cityName);

Thats it!

and why its way better then its separated in a method, look at this:

Oh and InboxStoreEvent, is also an enum that is within the storeSystem, it just helps to separate for the inboxSystem, it can be whatever we need, negativeBalance, finishedupgrading/construciton etc..




and when i need to change something, look, just go to region INBOX SYSTEM! hahah sexy.


And inUi, its simple, we use the same sidePanel slide, as we used for everything else, dashboard, changes upgrades... For example:




I know its basic, but it works! and it will be improved!! 




Also , you may wonder how it knows whether is read or not, or how it is deleted?? That is very interesting!!!!!

if you noticed in the message struct, we have 2 bools, one is isRead, simple, toogleRreadUnread switch method that changes (as everything else and then does writeback) 
but  deleting? 

Deleting would create same issues with indxes and lots of errors ,because you remove one message from the order in the list, and then everyhting goes to hell, basically.. 

So , same solution that i did for store sell (that will be shown later here) , and for every building construction, do you remember?? -  GHOST hahah yeah, so , when player says delete this message/notificaiton, the bool goes isActive = false, and message never shows, but its still there hahah.


______________________________________________________________________________



 StoreSystem -  sell store, this was the tricky one, becuase, first, what happens with trucks that are connected? also, with assets? - assets dont break the game, but player losses assets and doest get any money for it, and trucks..yeah. they crash the game..

So lets dig in!!! 


So in order not to crash the game, because trucks stay without index, destination, the easiet way was, when the store sale is initiated it has to restart the routes for all trucks that are connected to this store. How? It goes thhrough all trucks, and compares the index. If the destinationIndex store is == to storeIndex, and city as well, then reset those trucks. which is the same method as we had before if you remember, when we reset the truck to default settings, which is in the truckEdit in the logistics tab. 

    private static void ResetTrucksRoutesToThisStore(WorldManager wm, int storeIndex, int cityIndex)

Second, we get the store value, which is simple, 

public static StoreSaleValue GetStoreSaleValue(int cityIndex, int storeIndex)
    {
        var (wm, city, store, _) = GetWmCityCashStore(cityIndex, storeIndex);

        StoreSaleValue value = new StoreSaleValue();

        value.buildingValue = CalculateStoreSellingPrice((int)store.storeType);

        value.inventoryValue = CalculateStoreProductAssetsPrice(cityIndex, storeIndex);

        value.totalValue = value.buildingValue + value.inventoryValue;

Basically, it just calculates the StoreSellingPrice + all assets that re within the store. How? That is where the global market comes in* still in development. The products are added together to the main price, multiplied by amount of products and with reduced price, becase its a bulk sale? if that is the word, but the logic is there..at least for me haha, anyhow, and it is defined by the global market price. so yeah that is the difference, and tthe global market will be directly intertwined with the local market prices etc.. 


oh yes!! CRUCIAL to why the store is not really removed .removeAt() , is because if we remove the store from the store list, then all the other stores change places.. and then the trucks since they have index for those, they start delivering goods to wrong stores hahaha, and all crashes down. 



thank you!!!!


Comments

Popular posts from this blog

Devlog #47 - TaxSystem/FinanceSystem ,Update-FIx -LoanFixes-- TruckSystem Update - Upgrade/BuyNEwTruck - Costs Prices introduced / OfficeSystem CreateNewOffice, upgrade office - other Fixes

Devlog #46 - HubSystem - CreatNewHub added, HubBuild Ui + INdustrySystem Update - -INdustryTierData to be combined with the IndustryData and IndustryState struct -

Devlog #49-50 - Asset System-NEW system, *Game Design* -construction costs update - LoanSystem- fix-redesign-upgrade,Bug fixes-storeSystem,AutoAdvance Day, Market system, Truck System cost redesign, refactored, Ui bug fixes