ethanmoffat / EndlessClient

An open source client for Endless Online written in C#
MIT License
34 stars 16 forks source link

Unify characters into a single repository/provider #186

Open ethanmoffat opened 2 years ago

ethanmoffat commented 2 years ago

There isn't really any reason to keep MainCharacter in its own repository. It's convenient, but leads to a lot of code such as

if (id == _characterProvider.MainCharacter.ID)
{
...
}
else if (_currentMapStateProvider.Characters.Contains(id))
{
...
}
else
{
...
}

Which is pretty bloated when the operations are usually the same thing.

Instead, it would be better to store the ID of the main player in the PlayerInfoProvider and put all characters and their renderers in the same collection, without differentiating between "main player" and other logged-in players. Packets that are handled specifically for the main player can use the property in PlayerInfoProvider to find the right character.