Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Useful discoveries #13

Open
AlexMog opened this issue Feb 21, 2021 · 1 comment
Open

Useful discoveries #13

AlexMog opened this issue Feb 21, 2021 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@AlexMog
Copy link
Owner

AlexMog commented Feb 21, 2021

Networking

Valheim uses Zone routing (messages are routed to a specific group of people in the same zone) or global routing (targets can be set to ensure messages are routed to the targeted client).
It's important to note that this routing is demanded on message sending process; For example, when you are talking in the game by not using /s command, it's the client itself that will define who can listen to his message. Of course, the routing part is still done by the server, but, it's the client who will define the target.
That makes it tricky to handle some RPCs that are not targeted directly to the server, that's why commands only work using the /s command right now, it's because /s targets also the server when the message is routed.
I will add hooks to the routing mechanism to be able to still listen to RPCs that are not directly targeted to the server, but it seems to mostly affect Chat messages because they didn't engage any alterations to the character or the environment (which should be validated by the server, event if this is still grey for now, it seems that most of the player's data is only handled by the client itself, which can complicate some event listening on the server part, the server is NOT fully authorative).

All the classes related to networking starts with a Z.

Network grouping of players (probably geographically) seems to be done through the classes ZDO* and the routing part is done mainly by the ZRoutedRpc class.
Network zones seems to be managed by ZDOMan.
The default zone ZOID.None represents the complete server.

NearBy Queries

Most calculations that are done to define which entities are nearby are mostly executed by bruteforcing all entities distances calculations. It is clearly not a good way to deal with it and explains why the game developers decided to limit the game to 10 players (event 5 players can be very complicated to compute...), that's why it's important to rework most of these methods by using GeoHash and GeoTrees instead of bruteforcing.

Character

Character class is the main class for all living creatures, this includes animals, monsters and players.
Humanoid inherits from Character and provide more methods to interact with humanoids
Player inherits from Humanoid and provide more methods to interact with players, they represents the player character

Building items

Most building items that have their own behaviors have their own class.
The Piece class represents a Piece of building the player can construct, like a wall.

Drop tables

Drop tables seems to use a classic approach of Weight system (each item has a weight associated with it, and by making some simple maths, its possible to define which ones have to be selected) for example, imagine the following drop table:

  • Item1, weight: 1
  • Item2, weight: 2
  • Item3, weight: 7

Item1 will have 1/10 chance of being selected, item2 2/10 chance and item3 7/10.

Game class

The Game class seems to represent the global state of the game. Managing game difficulty etc.

AI

MonsterAI is the class that manages monsters behavior

I am still investigating and retro-engineering the code, it can take me some time to complete this issue, so please be patient !

@AlexMog AlexMog added the documentation Improvements or additions to documentation label Feb 21, 2021
@AlexMog
Copy link
Owner Author

AlexMog commented Mar 4, 2021

Sometimes I ask myself "but, why did they do that ?!"... It's very clear that the developers who worked on Valheim have very-low development skill, which makes it even harder to work with their codes (because they didn't planify correctly some processes, didn't use correctly design patterns etc.), be careful when dealing with their codebase and do not hesitate to rework some parts !
(one of the many examples I've seen)
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant