Jump to content
  • Advertisement
Miraz

Basics of MMO event / game loop wanted

This topic is 408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello !

I have been developing my MMO server for couple of years and i have re-wrote it couple of times as i have improved in coding in general. I'm using asynchronous socket whit google's protobuf, SRP authentication on login server, token transaction to correct game server and efficient stream cipher for encryption. Whole authentication process takes 400ms while database is on the AWS cloud.

 

For the question, i'm having hard time to understand correct way to handle game events. 

In example:
Player is wandering in the world and wants to talk to NPC to obtain quest.

  1. Player interacts NPC by sending NPC's id to server
  2. Server answers to client is that interaction possible (ie. wrong faction npc don't wanna talk to you) and server also send that particularly NPC data to client so we can build up simple questlog or text menu for user.

 

How this happens internally on the server side ? In my mind i'm thinking that every time player interacts with NPC it would popup event OnInteract/onAction on the NPC class and that class will forward correct data for correct client internally (check my "logic picture"). But im not sure is this correct way to do it. Also i'm thinking of should i queue these events and process them on each server frame/loop to have synchronized world ?

Do you have any example of such event manager and answer for my later game loop question or can you point me to the valid source of information ?

I'm happy to reply if you like to ask anything more specific.

Thank you in advance!

 

 

 

gamedev.jpg

Share this post


Link to post
Share on other sites
Advertisement

This can be as simple as you need. The client sends a request to speak to the NPC, the server responds either with a refusal, or with the data necessary for the client to display the interaction. It can also tell the NPC to stop moving or performing whatever other action it was currently performing. None of this is really MMO-specific, apart from needing to send messages about the process instead of just calling functions.

What makes you think that you need an event manager or queuing or any of this other stuff you mention?

Share this post


Link to post
Share on other sites
1 hour ago, Kylotan said:

This can be as simple as you need. The client sends a request to speak to the NPC, the server responds either with a refusal, or with the data necessary for the client to display the interaction. It can also tell the NPC to stop moving or performing whatever other action it was currently performing. None of this is really MMO-specific, apart from needing to send messages about the process instead of just calling functions.

What makes you think that you need an event manager or queuing or any of this other stuff you mention?

Main reason why im asking this is problem how i script my quests on the npc and how to implement that on the server side.
Yes i know i could write class for each quests and maybe have state machine on that npc which my player is interacting but is there any example of this ?

Share this post


Link to post
Share on other sites

A state machine for the NPCs sounds reasonable, although you'd probably want one copy for each player so that a player can't monopolise the NPC. Or you could just store some measure of quest progress for each quest a player is on, and deduce what the NPC should say based on that.

Most of this isn't related to the multi-player aspect because the client just displays dialog or whatever the same way that it would in a single player game; so, is the problem that you just don't know how to handle quests and dialogs at all? Or are there multiplayer specific problems you have?

Share this post


Link to post
Share on other sites
10 minutes ago, Kylotan said:

 

I'm probably just confused what i'm doing :D I have done quest system on single player game so yes this is multiplayer specific problem. For networking part i would like to understand how quest progress is implemented. Like if i kill critter i should call OnKill event and find out who killed the critter and handle quest progress on server side, that is why im asking for event manager specific question. 

Sorry about my english, i'm not native speaker :)

 

Edit. Should i ask this question from different sub-forum ?

Edited by Miraz

Share this post


Link to post
Share on other sites

For a multiplayer game, obviously the biggest change is that each player needs their own data on quest progress, or dialog progress, or whatever. But you don't need to change anything about how you handle quest progress when it comes to the logic. Remember that the gameplay should be on the server, and the client is just to display what is happening and to collect input from the player. You don't need to route everything through an "event manager".

Can you explain why you think your normal single-player approach would not work in multi-player?

Share this post


Link to post
Share on other sites

There aren't usually a huge amount of actions - and even if there were, why do you anticipate that being a problem?

I don't have any sample code I can give you for the entirety of MMO game logic, but if you have a specific problem that you can't solve, where your single player code doesn't work for some reason, I expect I can suggest something.

Share this post


Link to post
Share on other sites

Okey, thank you for information ! I will bookmark this topic and reply here if i get problems whit SP quest system !

Share this post


Link to post
Share on other sites

Typically, you'll run all world updates in a single thread, so that you don't need to implement locking. It's very uncommon for a full world/zone to be so complex as to overwhelm a single core, unless you also do physics simulation, which may need a multi-threaded implementation.

There is one difference to single player games! In a single-player game, you will have two entities that matter: The player, and the NPC. If the player says something to anger the NPC, the NPC may change its own state to "angry," start to attack, and so forth; this state can easily be kept on the NPC.

In a multi-player game, there are actually three things that matter: Each player, each NPC, and each relation between specific players and specific NPCs. This separate player/NPC relation is actually a different "thing," and you'd probably do best to keep it separate in the game, although you'd want to store these states keyed on the player in your database.

So, the scripting callback from the player talking to the NPC might contain five arguments:

def onInteraction(self, world, playerInteraction, playerRelation, player):
    if player.faction != self.faction:
        self.tell(player, "You are not my kind!")
    elif playerRelation.state == None:
        self.sendDialog(player, self.initialDialogTree)
    elif playerRelation.state == ON_FETCH_QUEST:
        if (playerInteraction.action == OFFER_ITEM and playerInteraction.item == SMALL_GRAY_ROCK):
            self.tell(player, "This is great! Here is your reward!")
            player.addInventory(FLAMING_SWORD_OF_FIRE, 1, self)
            player.removeInventory(SMALL_GRAY_ROCK, 1, self)
        elif ...

 

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!