MMORooms and NPCs

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
Flying_Banana
Posts: 42
Joined: 04 May 2014, 07:03

MMORooms and NPCs

Postby Flying_Banana » 16 Jun 2015, 15:46

I am trying to reach a scalable solution to NPC AI in an mmorpg.

If I were to do it all on the server, then suppose I have 50 monsters per map, if the whole game consists of 50 maps, then I have 2500 instances of AI running. No matter how simple my AI is (even if I try to simplify 3D down to 2D), this is clearly not a scalable solution and server is probably going to suffer.

I've read that using SFS I can instead have special servers which join the game as special players who control NPC's AI. This is a lot more scalable as I can adjust how many servers I need based on the number of maps I have.

Working out the finer details, obviously such a server must control multiple NPCs at the same time for it to be efficient. It should control a whole Room (map) of monsters if not multiple rooms of them.

My concerns then arise from the following:
- If I use MMORoom, how can I let one such special server receive every critical message? (Player movements, actions, skills used, etc.) Do I have to forward the messages (can I even? Perhaps by keeping the special server-user as a room variable?) explicitly in my extensions when I deal with such data?
- Can a user be in multiple rooms at the same time?

I suppose the latter is a nice-to-have but not a huge problem since I can just make the maps sufficiently large.
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: MMORooms and NPCs

Postby Lapo » 16 Jun 2015, 21:51

Flying_Banana wrote:If I were to do it all on the server, then suppose I have 50 monsters per map, if the whole game consists of 50 maps, then I have 2500 instances of AI running. No matter how simple my AI is (even if I try to simplify 3D down to 2D), this is clearly not a scalable solution and server is probably going to suffer.

Well, I wouldn't be so sure about this.
2500 NPCs may tax performance but how badly depends on the complexity of the AI. Lots of complex pathfinding may require powerful hardware, other simple logic may generate a moderate load.

It depends on what you have in mind...

I've read that using SFS I can instead have special servers which join the game as special players who control NPC's AI. This is a lot more scalable as I can adjust how many servers I need based on the number of maps I have.

Yes, that's an option. You can write a Java app that runs multiple instances of the API connecting to the server and driving the NPC's AI.

Working out the finer details, obviously such a server must control multiple NPCs at the same time for it to be efficient. It should control ax whole Room (map) of monsters if not multiple rooms of them.

1-2 servers should be able to do all that.

My concerns then arise from the following:
- If I use MMORoom, how can I let one such special server receive every critical message? (Player movements, actions, skills used, etc.) Do I have to forward the messages (can I even? Perhaps by keeping the special server-user as a room variable?) explicitly in my extensions when I deal with such data?

Can't the AI work with only the proximity information?

In any case via Extension you can access all information you need or generate extra events for the AI players, just keep in mind that with very large maps it can get a bit intensive.

- Can a user be in multiple rooms at the same time?

Yes they can
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Flying_Banana
Posts: 42
Joined: 04 May 2014, 07:03

Re: MMORooms and NPCs

Postby Flying_Banana » 18 Jun 2015, 02:04

Thanks Lapo that's pretty insightful!

I've actually thought about both solutions. If I adapt everything on the server then I limit myself the complexity of the AI, and possibly the maps themselves (the maps most likely need to be easily reduced to 2D, in rectangles marking where map collision objects are). As I am using Unity as the client side, it seems there will be a lot of boilerplate work here. I think 2500 instances of 3D collision checking is definitely going to impact on the server!

So instead I think I should have instances of special AI clients made from Unity running the collision checks and controlling the AI, and simplify that client as much as possible (do collision checks without rendering, perhaps, and just rely on scripting!)

More about dedicated AI servers - I was thinking about each AI player would control more than one NPC, rather than multiple instances of SFS connections. Do you think this is a better approach? So instead of a User I can perhaps represent the mobs in NPCs and write some code so that the AI can control how they move? I think it is easier to coordinate monster AI. That is also why I want to have a single AI player receiving messages from the whole MMORoom.

Well it's true that we really only care about player actions around NPCs...well I can perform a simple rect check to see if a player is near an NPC perhaps? I feel like making a special user for each monster I need in the game is a little...messy. :)
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: MMORooms and NPCs

Postby Lapo » 19 Jun 2015, 08:39

Flying_Banana wrote:More about dedicated AI servers - I was thinking about each AI player would control more than one NPC, rather than multiple instances of SFS connections. Do you think this is a better approach? So instead of a User I can perhaps represent the mobs in NPCs and write some code so that the AI can control how they move? I think it is easier to coordinate monster AI. That is also why I want to have a single AI player receiving messages from the whole MMORoom.

I am not sure I can follow but you have two options essentially:
1) Each NPC uses a connection
OR
2) Use MMOItems to represent NPCs and transmit all events about them from SFS to AI-Server, elaborate the logic and send data back to SFS Extension.

A third way is to create your custom way of representing NPCs in the Room, using a system similar to #2
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Flying_Banana
Posts: 42
Joined: 04 May 2014, 07:03

Re: MMORooms and NPCs

Postby Flying_Banana » 21 Jun 2015, 03:53

Right, what I mean is to use MMOItem to represent NPCs. I forgot there is actually no NPC class in the current architecture!
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: MMORooms and NPCs

Postby Lapo » 21 Jun 2015, 17:03

Well, there's the User class which represent any user, socket connected or not.
You can determine which is which by reading the User session's type (DEFAULT for sockets, VOID for NPCs)
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 54 guests