How do you scale MVC/MVCS for many different game objects/behavior?

I made a post not to long ago seeking advice on how to organize a codebase and someone explained an adapted version of the MVC/MVCS architecture which I’ve been trying to use for my game.

From what I understand model represents the data and business logic, view displays the data to the player and sends commands (gui interactions?) to the controller, controller handles user input and interacts with the model and updates the view and it handles the networking, and lastly service is just business logic. Overall it seems to do a good job at separation of concerns/responsibilities.

The problem I have though is it doesn’t make sense how to actually implement things for example a shop system I might have a ShopModel, ShopView, ShopClientController, ShopServerController, and ShopService but where do I handle talk to NpcA and open ShopA or NpcB and open ShopB and each shop sells different things? Another example from my game is creating 20-30 varied tools it could be as simple as increasing speed while equipped or a spellbook with 4 different abilities.

2 Likes

Hello again!

What you’re talking about here would a controller concern if you’re designing it under MVC.

You feed the InteractionController the NPC Model and a Shop Model, and it’ll wire up the NPC.Interacted event to the Shop:Open() method, which would probably fire off a Shop.Opened event, which the ShopController would listen for and then open the ShopView.

If you want the controller to access shops at run time, you’ll typically do so via a ShopService, which it can query for anything it needs served to it or handled on the controllers behalf.

This is more of a data concern if I’m understanding you correctly. When you create a Spellbook via Spellbook.new() just pass in a configured table of all the details the book should implement, like make something as simple as

Spellbook.new({
    { Ability = "Fire", = Strength = 10, Duration = 50 },
    { Ability = "Speed", = Strength = 2, Duration = -1},
})

and internally the spellbook would just construct itself to set up those abilities, via a common language for instantiation and interaction.

For example,

local spellbook = Spellbook.new({
    { Ability = "Fire", = Strength = 10, Duration = 50 },
    { Ability = "Speed", = Strength = 2, Duration = -1},
})

spellbook.AbilitiyUsed:Connect(function(ability, strength, duration)
     print(ability, strength, duration)
end)

spellbook:UseAbility("Fire")
1 Like